Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/kernel/head-common.S |
| 3 | * |
| 4 | * Copyright (C) 1994-2002 Russell King |
| 5 | * Copyright (c) 2003 ARM Limited |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
Greg Ungerer | 9c4c9f3 | 2008-03-05 06:50:07 +0100 | [diff] [blame] | 14 | #define ATAG_CORE 0x54410001 |
| 15 | #define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2) |
David Brown | 31abdb74 | 2009-10-01 17:43:29 +0100 | [diff] [blame] | 16 | #define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2) |
Greg Ungerer | 9c4c9f3 | 2008-03-05 06:50:07 +0100 | [diff] [blame] | 17 | |
Catalin Marinas | 88987ef | 2009-07-24 12:32:52 +0100 | [diff] [blame] | 18 | .align 2 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 19 | .type __switch_data, %object |
| 20 | __switch_data: |
| 21 | .long __mmap_switched |
| 22 | .long __data_loc @ r4 |
Russell King | 37efe64 | 2008-12-01 11:53:07 +0000 | [diff] [blame] | 23 | .long _data @ r5 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 24 | .long __bss_start @ r6 |
| 25 | .long _end @ r7 |
| 26 | .long processor_id @ r4 |
| 27 | .long __machine_arch_type @ r5 |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 28 | .long __atags_pointer @ r6 |
| 29 | .long cr_alignment @ r7 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 30 | .long init_thread_union + THREAD_START_SP @ sp |
| 31 | |
| 32 | /* |
| 33 | * The following fragment of code is executed with the MMU on in MMU mode, |
| 34 | * and uses absolute addresses; this is not position independent. |
| 35 | * |
| 36 | * r0 = cp#15 control register |
| 37 | * r1 = machine ID |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 38 | * r2 = atags pointer |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 39 | * r9 = processor ID |
| 40 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 41 | __mmap_switched: |
| 42 | adr r3, __switch_data + 4 |
| 43 | |
| 44 | ldmia r3!, {r4, r5, r6, r7} |
| 45 | cmp r4, r5 @ Copy data segment if needed |
| 46 | 1: cmpne r5, r6 |
| 47 | ldrne fp, [r4], #4 |
| 48 | strne fp, [r5], #4 |
| 49 | bne 1b |
| 50 | |
| 51 | mov fp, #0 @ Clear BSS (and zero fp) |
| 52 | 1: cmp r6, r7 |
| 53 | strcc fp, [r6],#4 |
| 54 | bcc 1b |
| 55 | |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 56 | ARM( ldmia r3, {r4, r5, r6, r7, sp}) |
| 57 | THUMB( ldmia r3, {r4, r5, r6, r7} ) |
| 58 | THUMB( ldr sp, [r3, #16] ) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 59 | str r9, [r4] @ Save processor ID |
| 60 | str r1, [r5] @ Save machine type |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 61 | str r2, [r6] @ Save atags pointer |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 62 | bic r4, r0, #CR_A @ Clear 'A' bit |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 63 | stmia r7, {r0, r4} @ Save control register values |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 64 | b start_kernel |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 65 | ENDPROC(__mmap_switched) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Exception handling. Something went wrong and we can't proceed. We |
| 69 | * ought to tell the user, but since we don't have any guarantee that |
| 70 | * we're even running on the right architecture, we do virtually nothing. |
| 71 | * |
| 72 | * If CONFIG_DEBUG_LL is set we try to print out something about the error |
| 73 | * and hope for the best (useful if bootloader fails to pass a proper |
| 74 | * machine ID for example). |
| 75 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 76 | __error_p: |
| 77 | #ifdef CONFIG_DEBUG_LL |
| 78 | adr r0, str_p1 |
| 79 | bl printascii |
Lennert Buytenhek | 84081bd | 2008-03-28 21:11:47 +0100 | [diff] [blame] | 80 | mov r0, r9 |
| 81 | bl printhex8 |
| 82 | adr r0, str_p2 |
| 83 | bl printascii |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 84 | b __error |
Lennert Buytenhek | 84081bd | 2008-03-28 21:11:47 +0100 | [diff] [blame] | 85 | str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x" |
| 86 | str_p2: .asciz ").\n" |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 87 | .align |
| 88 | #endif |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 89 | ENDPROC(__error_p) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 90 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 91 | __error_a: |
| 92 | #ifdef CONFIG_DEBUG_LL |
| 93 | mov r4, r1 @ preserve machine ID |
| 94 | adr r0, str_a1 |
| 95 | bl printascii |
| 96 | mov r0, r4 |
| 97 | bl printhex8 |
| 98 | adr r0, str_a2 |
| 99 | bl printascii |
| 100 | adr r3, 3f |
| 101 | ldmia r3, {r4, r5, r6} @ get machine desc list |
| 102 | sub r4, r3, r4 @ get offset between virt&phys |
| 103 | add r5, r5, r4 @ convert virt addresses to |
| 104 | add r6, r6, r4 @ physical address space |
| 105 | 1: ldr r0, [r5, #MACHINFO_TYPE] @ get machine type |
| 106 | bl printhex8 |
| 107 | mov r0, #'\t' |
| 108 | bl printch |
| 109 | ldr r0, [r5, #MACHINFO_NAME] @ get machine name |
| 110 | add r0, r0, r4 |
| 111 | bl printascii |
| 112 | mov r0, #'\n' |
| 113 | bl printch |
| 114 | add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc |
| 115 | cmp r5, r6 |
| 116 | blo 1b |
| 117 | adr r0, str_a3 |
| 118 | bl printascii |
| 119 | b __error |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 120 | ENDPROC(__error_a) |
| 121 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 122 | str_a1: .asciz "\nError: unrecognized/unsupported machine ID (r1 = 0x" |
| 123 | str_a2: .asciz ").\n\nAvailable machine support:\n\nID (hex)\tNAME\n" |
| 124 | str_a3: .asciz "\nPlease check your kernel config and/or bootloader.\n" |
| 125 | .align |
| 126 | #endif |
| 127 | |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 128 | __error: |
| 129 | #ifdef CONFIG_ARCH_RPC |
| 130 | /* |
| 131 | * Turn the screen red on a error - RiscPC only. |
| 132 | */ |
| 133 | mov r0, #0x02000000 |
| 134 | mov r3, #0x11 |
| 135 | orr r3, r3, r3, lsl #8 |
| 136 | orr r3, r3, r3, lsl #16 |
| 137 | str r3, [r0], #4 |
| 138 | str r3, [r0], #4 |
| 139 | str r3, [r0], #4 |
| 140 | str r3, [r0], #4 |
| 141 | #endif |
| 142 | 1: mov r0, r0 |
| 143 | b 1b |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 144 | ENDPROC(__error) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 145 | |
| 146 | |
| 147 | /* |
| 148 | * Read processor ID register (CP#15, CR0), and look up in the linker-built |
| 149 | * supported processor list. Note that we can't use the absolute addresses |
| 150 | * for the __proc_info lists since we aren't running with the MMU on |
| 151 | * (and therefore, we are not in the correct address space). We have to |
| 152 | * calculate the offset. |
| 153 | * |
| 154 | * r9 = cpuid |
| 155 | * Returns: |
| 156 | * r3, r4, r6 corrupted |
| 157 | * r5 = proc_info pointer in physical address space |
| 158 | * r9 = cpuid (preserved) |
| 159 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 160 | __lookup_processor_type: |
| 161 | adr r3, 3f |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 162 | ldmia r3, {r5 - r7} |
| 163 | add r3, r3, #8 |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 164 | sub r3, r3, r7 @ get offset between virt&phys |
| 165 | add r5, r5, r3 @ convert virt addresses to |
| 166 | add r6, r6, r3 @ physical address space |
| 167 | 1: ldmia r5, {r3, r4} @ value, mask |
| 168 | and r4, r4, r9 @ mask wanted bits |
| 169 | teq r3, r4 |
| 170 | beq 2f |
| 171 | add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list) |
| 172 | cmp r5, r6 |
| 173 | blo 1b |
| 174 | mov r5, #0 @ unknown processor |
| 175 | 2: mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 176 | ENDPROC(__lookup_processor_type) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * This provides a C-API version of the above function. |
| 180 | */ |
| 181 | ENTRY(lookup_processor_type) |
| 182 | stmfd sp!, {r4 - r7, r9, lr} |
| 183 | mov r9, r0 |
| 184 | bl __lookup_processor_type |
| 185 | mov r0, r5 |
| 186 | ldmfd sp!, {r4 - r7, r9, pc} |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 187 | ENDPROC(lookup_processor_type) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 188 | |
| 189 | /* |
Russell King | 4baa992 | 2008-08-02 10:55:55 +0100 | [diff] [blame] | 190 | * Look in <asm/procinfo.h> and arch/arm/kernel/arch.[ch] for |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 191 | * more information about the __proc_info and __arch_info structures. |
| 192 | */ |
Catalin Marinas | 88987ef | 2009-07-24 12:32:52 +0100 | [diff] [blame] | 193 | .align 2 |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 194 | 3: .long __proc_info_begin |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 195 | .long __proc_info_end |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 196 | 4: .long . |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 197 | .long __arch_info_begin |
| 198 | .long __arch_info_end |
| 199 | |
| 200 | /* |
| 201 | * Lookup machine architecture in the linker-build list of architectures. |
| 202 | * Note that we can't use the absolute addresses for the __arch_info |
| 203 | * lists since we aren't running with the MMU on (and therefore, we are |
| 204 | * not in the correct address space). We have to calculate the offset. |
| 205 | * |
| 206 | * r1 = machine architecture number |
| 207 | * Returns: |
| 208 | * r3, r4, r6 corrupted |
| 209 | * r5 = mach_info pointer in physical address space |
| 210 | */ |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 211 | __lookup_machine_type: |
Catalin Marinas | b86040a | 2009-07-24 12:32:54 +0100 | [diff] [blame] | 212 | adr r3, 4b |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 213 | ldmia r3, {r4, r5, r6} |
| 214 | sub r3, r3, r4 @ get offset between virt&phys |
| 215 | add r5, r5, r3 @ convert virt addresses to |
| 216 | add r6, r6, r3 @ physical address space |
| 217 | 1: ldr r3, [r5, #MACHINFO_TYPE] @ get machine type |
| 218 | teq r3, r1 @ matches loader number? |
| 219 | beq 2f @ found |
| 220 | add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc |
| 221 | cmp r5, r6 |
| 222 | blo 1b |
| 223 | mov r5, #0 @ unknown machine |
| 224 | 2: mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 225 | ENDPROC(__lookup_machine_type) |
Hyok S. Choi | 75d9083 | 2006-03-27 14:58:25 +0100 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * This provides a C-API version of the above function. |
| 229 | */ |
| 230 | ENTRY(lookup_machine_type) |
| 231 | stmfd sp!, {r4 - r6, lr} |
| 232 | mov r1, r0 |
| 233 | bl __lookup_machine_type |
| 234 | mov r0, r5 |
| 235 | ldmfd sp!, {r4 - r6, pc} |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 236 | ENDPROC(lookup_machine_type) |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 237 | |
| 238 | /* Determine validity of the r2 atags pointer. The heuristic requires |
| 239 | * that the pointer be aligned, in the first 16k of physical RAM and |
| 240 | * that the ATAG_CORE marker is first and present. Future revisions |
| 241 | * of this function may be more lenient with the physical address and |
| 242 | * may also be able to move the ATAGS block if necessary. |
| 243 | * |
| 244 | * r8 = machinfo |
| 245 | * |
| 246 | * Returns: |
| 247 | * r2 either valid atags pointer, or zero |
| 248 | * r5, r6 corrupted |
| 249 | */ |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 250 | __vet_atags: |
| 251 | tst r2, #0x3 @ aligned? |
| 252 | bne 1f |
| 253 | |
| 254 | ldr r5, [r2, #0] @ is first tag ATAG_CORE? |
David Brown | 31abdb74 | 2009-10-01 17:43:29 +0100 | [diff] [blame] | 255 | cmp r5, #ATAG_CORE_SIZE |
| 256 | cmpne r5, #ATAG_CORE_SIZE_EMPTY |
Bill Gatliff | 9d20fdd | 2007-05-31 22:02:22 +0100 | [diff] [blame] | 257 | bne 1f |
| 258 | ldr r5, [r2, #4] |
| 259 | ldr r6, =ATAG_CORE |
| 260 | cmp r5, r6 |
| 261 | bne 1f |
| 262 | |
| 263 | mov pc, lr @ atag pointer is ok |
| 264 | |
| 265 | 1: mov r2, #0 |
| 266 | mov pc, lr |
Catalin Marinas | 93ed397 | 2008-08-28 11:22:32 +0100 | [diff] [blame] | 267 | ENDPROC(__vet_atags) |