Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
Ajay Dudani | 79d0d40 | 2010-04-21 12:38:45 -0700 | [diff] [blame] | 23 | |
| 24 | #define DSB .byte 0x4f, 0xf0, 0x7f, 0xf5 |
| 25 | #define ISB .byte 0x6f, 0xf0, 0x7f, 0xf5 |
| 26 | |
Ajay Dudani | c713ab8 | 2011-05-18 19:50:14 -0700 | [diff] [blame] | 27 | .section ".text.boot" |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 28 | .globl _start |
| 29 | _start: |
| 30 | b reset |
| 31 | b arm_undefined |
| 32 | b arm_syscall |
| 33 | b arm_prefetch_abort |
| 34 | b arm_data_abort |
| 35 | b arm_reserved |
| 36 | b arm_irq |
| 37 | b arm_fiq |
| 38 | |
| 39 | reset: |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 40 | |
| 41 | #ifdef ENABLE_TRUSTZONE |
| 42 | /*Add reference to TZ symbol so linker includes it in final image */ |
| 43 | ldr r7, =_binary_tzbsp_tzbsp_bin_start |
| 44 | #endif |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 45 | /* do some cpu setup */ |
| 46 | #if ARM_WITH_CP15 |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 47 | /* Read SCTLR */ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 48 | mrc p15, 0, r0, c1, c0, 0 |
| 49 | /* XXX this is currently for arm926, revist with armv6 cores */ |
| 50 | /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */ |
| 51 | bic r0, r0, #(1<<15| 1<<13 | 1<<12) |
| 52 | bic r0, r0, #(1<<2 | 1<<0) |
Deepa Dinamani | d7820fa | 2013-10-01 18:03:28 -0700 | [diff] [blame] | 53 | /* disable alignment faults */ |
| 54 | bic r0, r0, #(1<<1) |
Amol Jadi | ca4f4c9 | 2011-01-13 20:19:34 -0800 | [diff] [blame] | 55 | /* Write SCTLR */ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 56 | mcr p15, 0, r0, c1, c0, 0 |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 57 | #ifdef ENABLE_TRUSTZONE |
| 58 | /*nkazi: not needed ? Setting VBAR to location of new vector table : 0x80000 */ |
| 59 | ldr r0, =0x00080000 |
| 60 | mcr p15, 0, r0, c12, c0, 0 |
| 61 | #endif |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 62 | #endif |
| 63 | |
Brian Swetland | a8cf2b8 | 2009-01-01 03:29:51 -0800 | [diff] [blame] | 64 | #if WITH_CPU_EARLY_INIT |
| 65 | /* call platform/arch/etc specific init code */ |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 66 | #ifndef ENABLE_TRUSTZONE |
| 67 | /* Not needed when TrustZone is the first bootloader that runs.*/ |
Brian Swetland | a8cf2b8 | 2009-01-01 03:29:51 -0800 | [diff] [blame] | 68 | bl __cpu_early_init |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 69 | #endif |
Ajay Dudani | 083d0dd | 2010-07-08 13:16:13 -0700 | [diff] [blame] | 70 | /* declare return address as global to avoid using stack */ |
| 71 | .globl _cpu_early_init_complete |
| 72 | _cpu_early_init_complete: |
| 73 | |
Travis Geiselbrecht | c322611 | 2008-09-02 02:47:40 -0700 | [diff] [blame] | 74 | #endif |
| 75 | |
Chandan Uddaraju | 6cc1e3d | 2009-12-15 15:21:06 -0800 | [diff] [blame] | 76 | #if (!ENABLE_NANDWRITE) |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 77 | #if WITH_CPU_WARM_BOOT |
| 78 | ldr r0, warm_boot_tag |
| 79 | cmp r0, #1 |
| 80 | |
| 81 | /* if set, warm boot */ |
| 82 | ldreq pc, =BASE_ADDR |
| 83 | |
| 84 | mov r0, #1 |
| 85 | str r0, warm_boot_tag |
| 86 | #endif |
Chandan Uddaraju | 6cc1e3d | 2009-12-15 15:21:06 -0800 | [diff] [blame] | 87 | #endif |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 88 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 89 | /* see if we need to relocate */ |
| 90 | mov r0, pc |
| 91 | sub r0, r0, #(.Laddr - _start) |
| 92 | .Laddr: |
| 93 | ldr r1, =_start |
| 94 | cmp r0, r1 |
| 95 | beq .Lstack_setup |
| 96 | |
| 97 | /* we need to relocate ourselves to the proper spot */ |
| 98 | ldr r2, =__data_end |
| 99 | |
| 100 | .Lrelocate_loop: |
| 101 | ldr r3, [r0], #4 |
| 102 | str r3, [r1], #4 |
| 103 | cmp r1, r2 |
| 104 | bne .Lrelocate_loop |
| 105 | |
| 106 | /* we're relocated, jump to the right address */ |
| 107 | ldr r0, =.Lstack_setup |
| 108 | bx r0 |
| 109 | |
| 110 | .ltorg |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 111 | #if WITH_CPU_WARM_BOOT |
| 112 | warm_boot_tag: |
| 113 | .word 0 |
| 114 | #endif |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 115 | |
| 116 | .Lstack_setup: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 117 | /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */ |
| 118 | mrs r0, cpsr |
| 119 | bic r0, r0, #0x1f |
| 120 | |
| 121 | ldr r2, =abort_stack_top |
| 122 | orr r1, r0, #0x12 // irq |
| 123 | msr cpsr_c, r1 |
| 124 | ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */ |
| 125 | |
| 126 | orr r1, r0, #0x11 // fiq |
| 127 | msr cpsr_c, r1 |
| 128 | mov sp, r2 |
| 129 | |
| 130 | orr r1, r0, #0x17 // abort |
| 131 | msr cpsr_c, r1 |
| 132 | mov sp, r2 |
| 133 | |
| 134 | orr r1, r0, #0x1b // undefined |
| 135 | msr cpsr_c, r1 |
| 136 | mov sp, r2 |
| 137 | |
| 138 | orr r1, r0, #0x1f // system |
| 139 | msr cpsr_c, r1 |
| 140 | mov sp, r2 |
| 141 | |
| 142 | orr r1, r0, #0x13 // supervisor |
| 143 | msr cpsr_c, r1 |
| 144 | mov sp, r2 |
| 145 | |
| 146 | /* copy the initialized data segment out of rom if necessary */ |
| 147 | ldr r0, =__data_start_rom |
| 148 | ldr r1, =__data_start |
| 149 | ldr r2, =__data_end |
| 150 | |
| 151 | cmp r0, r1 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 152 | beq .L__do_bss |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 153 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 154 | .L__copy_loop: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 155 | cmp r1, r2 |
| 156 | ldrlt r3, [r0], #4 |
| 157 | strlt r3, [r1], #4 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 158 | blt .L__copy_loop |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 159 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 160 | .L__do_bss: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 161 | /* clear out the bss */ |
| 162 | ldr r0, =__bss_start |
| 163 | ldr r1, =_end |
| 164 | mov r2, #0 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 165 | .L__bss_loop: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 166 | cmp r0, r1 |
| 167 | strlt r2, [r0], #4 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 168 | blt .L__bss_loop |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 169 | |
Ajay Dudani | 79d0d40 | 2010-04-21 12:38:45 -0700 | [diff] [blame] | 170 | #ifdef ARM_CPU_CORTEX_A8 |
| 171 | DSB |
| 172 | ISB |
| 173 | #endif |
| 174 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 175 | bl kmain |
| 176 | b . |
| 177 | |
| 178 | .ltorg |
| 179 | |
| 180 | .bss |
| 181 | .align 2 |
| 182 | /* the abort stack is for unrecoverable errors. |
| 183 | * also note the initial working stack is set to here. |
| 184 | * when the threading system starts up it'll switch to a new |
| 185 | * dynamically allocated stack, so we don't need it for very long |
| 186 | */ |
| 187 | abort_stack: |
| 188 | .skip 1024 |
| 189 | abort_stack_top: |