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 | */ |
| 23 | .text |
| 24 | .globl _start |
| 25 | _start: |
| 26 | b reset |
| 27 | b arm_undefined |
| 28 | b arm_syscall |
| 29 | b arm_prefetch_abort |
| 30 | b arm_data_abort |
| 31 | b arm_reserved |
| 32 | b arm_irq |
| 33 | b arm_fiq |
| 34 | |
| 35 | reset: |
| 36 | /* do some cpu setup */ |
| 37 | #if ARM_WITH_CP15 |
| 38 | mrc p15, 0, r0, c1, c0, 0 |
| 39 | /* XXX this is currently for arm926, revist with armv6 cores */ |
| 40 | /* new thumb behavior, low exception vectors, i/d cache disable, mmu disabled */ |
| 41 | bic r0, r0, #(1<<15| 1<<13 | 1<<12) |
| 42 | bic r0, r0, #(1<<2 | 1<<0) |
| 43 | /* enable alignment faults */ |
| 44 | orr r0, r0, #(1<<1) |
| 45 | mcr p15, 0, r0, c1, c0, 0 |
| 46 | #endif |
| 47 | |
Brian Swetland | a8cf2b8 | 2009-01-01 03:29:51 -0800 | [diff] [blame] | 48 | #if WITH_CPU_EARLY_INIT |
| 49 | /* call platform/arch/etc specific init code */ |
| 50 | bl __cpu_early_init |
Travis Geiselbrecht | c322611 | 2008-09-02 02:47:40 -0700 | [diff] [blame] | 51 | #endif |
| 52 | |
Chandan Uddaraju | 6cc1e3d | 2009-12-15 15:21:06 -0800 | [diff] [blame] | 53 | #if (!ENABLE_NANDWRITE) |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 54 | #if WITH_CPU_WARM_BOOT |
| 55 | ldr r0, warm_boot_tag |
| 56 | cmp r0, #1 |
| 57 | |
| 58 | /* if set, warm boot */ |
| 59 | ldreq pc, =BASE_ADDR |
| 60 | |
| 61 | mov r0, #1 |
| 62 | str r0, warm_boot_tag |
| 63 | #endif |
Chandan Uddaraju | 6cc1e3d | 2009-12-15 15:21:06 -0800 | [diff] [blame] | 64 | #endif |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 65 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 66 | /* see if we need to relocate */ |
| 67 | mov r0, pc |
| 68 | sub r0, r0, #(.Laddr - _start) |
| 69 | .Laddr: |
| 70 | ldr r1, =_start |
| 71 | cmp r0, r1 |
| 72 | beq .Lstack_setup |
| 73 | |
| 74 | /* we need to relocate ourselves to the proper spot */ |
| 75 | ldr r2, =__data_end |
| 76 | |
| 77 | .Lrelocate_loop: |
| 78 | ldr r3, [r0], #4 |
| 79 | str r3, [r1], #4 |
| 80 | cmp r1, r2 |
| 81 | bne .Lrelocate_loop |
| 82 | |
| 83 | /* we're relocated, jump to the right address */ |
| 84 | ldr r0, =.Lstack_setup |
| 85 | bx r0 |
| 86 | |
| 87 | .ltorg |
Harry Yang | 953ff70 | 2009-12-03 21:49:00 -0800 | [diff] [blame] | 88 | #if WITH_CPU_WARM_BOOT |
| 89 | warm_boot_tag: |
| 90 | .word 0 |
| 91 | #endif |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 92 | |
| 93 | .Lstack_setup: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 94 | /* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */ |
| 95 | mrs r0, cpsr |
| 96 | bic r0, r0, #0x1f |
| 97 | |
| 98 | ldr r2, =abort_stack_top |
| 99 | orr r1, r0, #0x12 // irq |
| 100 | msr cpsr_c, r1 |
| 101 | ldr r13, =irq_save_spot /* save a pointer to a temporary dumping spot used during irq delivery */ |
| 102 | |
| 103 | orr r1, r0, #0x11 // fiq |
| 104 | msr cpsr_c, r1 |
| 105 | mov sp, r2 |
| 106 | |
| 107 | orr r1, r0, #0x17 // abort |
| 108 | msr cpsr_c, r1 |
| 109 | mov sp, r2 |
| 110 | |
| 111 | orr r1, r0, #0x1b // undefined |
| 112 | msr cpsr_c, r1 |
| 113 | mov sp, r2 |
| 114 | |
| 115 | orr r1, r0, #0x1f // system |
| 116 | msr cpsr_c, r1 |
| 117 | mov sp, r2 |
| 118 | |
| 119 | orr r1, r0, #0x13 // supervisor |
| 120 | msr cpsr_c, r1 |
| 121 | mov sp, r2 |
| 122 | |
| 123 | /* copy the initialized data segment out of rom if necessary */ |
| 124 | ldr r0, =__data_start_rom |
| 125 | ldr r1, =__data_start |
| 126 | ldr r2, =__data_end |
| 127 | |
| 128 | cmp r0, r1 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 129 | beq .L__do_bss |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 130 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 131 | .L__copy_loop: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 132 | cmp r1, r2 |
| 133 | ldrlt r3, [r0], #4 |
| 134 | strlt r3, [r1], #4 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 135 | blt .L__copy_loop |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 136 | |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 137 | .L__do_bss: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 138 | /* clear out the bss */ |
| 139 | ldr r0, =__bss_start |
| 140 | ldr r1, =_end |
| 141 | mov r2, #0 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 142 | .L__bss_loop: |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 143 | cmp r0, r1 |
| 144 | strlt r2, [r0], #4 |
Travis Geiselbrecht | 887061f | 2008-09-05 01:47:07 -0700 | [diff] [blame] | 145 | blt .L__bss_loop |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 146 | |
| 147 | bl kmain |
| 148 | b . |
| 149 | |
| 150 | .ltorg |
| 151 | |
| 152 | .bss |
| 153 | .align 2 |
| 154 | /* the abort stack is for unrecoverable errors. |
| 155 | * also note the initial working stack is set to here. |
| 156 | * when the threading system starts up it'll switch to a new |
| 157 | * dynamically allocated stack, so we don't need it for very long |
| 158 | */ |
| 159 | abort_stack: |
| 160 | .skip 1024 |
| 161 | abort_stack_top: |