blob: 6ad24d2cb14b8729e246b789eeb5bd80a462d1bc [file] [log] [blame]
Hyok S. Choi75d90832006-03-27 14:58:25 +01001/*
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 Ungerer9c4c9f32008-03-05 06:50:07 +010014#define ATAG_CORE 0x54410001
15#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)
David Brown31abdb72009-10-01 17:43:29 +010016#define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)
Greg Ungerer9c4c9f32008-03-05 06:50:07 +010017
Catalin Marinas88987ef2009-07-24 12:32:52 +010018 .align 2
Hyok S. Choi75d90832006-03-27 14:58:25 +010019 .type __switch_data, %object
20__switch_data:
21 .long __mmap_switched
22 .long __data_loc @ r4
Russell King37efe642008-12-01 11:53:07 +000023 .long _data @ r5
Hyok S. Choi75d90832006-03-27 14:58:25 +010024 .long __bss_start @ r6
25 .long _end @ r7
26 .long processor_id @ r4
27 .long __machine_arch_type @ r5
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010028 .long __atags_pointer @ r6
29 .long cr_alignment @ r7
Hyok S. Choi75d90832006-03-27 14:58:25 +010030 .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 Gatliff9d20fdd2007-05-31 22:02:22 +010038 * r2 = atags pointer
Hyok S. Choi75d90832006-03-27 14:58:25 +010039 * r9 = processor ID
40 */
Hyok S. Choi75d90832006-03-27 14:58:25 +010041__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
461: 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)
521: cmp r6, r7
53 strcc fp, [r6],#4
54 bcc 1b
55
Catalin Marinasb86040a2009-07-24 12:32:54 +010056 ARM( ldmia r3, {r4, r5, r6, r7, sp})
57 THUMB( ldmia r3, {r4, r5, r6, r7} )
58 THUMB( ldr sp, [r3, #16] )
Hyok S. Choi75d90832006-03-27 14:58:25 +010059 str r9, [r4] @ Save processor ID
60 str r1, [r5] @ Save machine type
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010061 str r2, [r6] @ Save atags pointer
Hyok S. Choi75d90832006-03-27 14:58:25 +010062 bic r4, r0, #CR_A @ Clear 'A' bit
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010063 stmia r7, {r0, r4} @ Save control register values
Hyok S. Choi75d90832006-03-27 14:58:25 +010064 b start_kernel
Catalin Marinas93ed3972008-08-28 11:22:32 +010065ENDPROC(__mmap_switched)
Hyok S. Choi75d90832006-03-27 14:58:25 +010066
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. Choi75d90832006-03-27 14:58:25 +010076__error_p:
77#ifdef CONFIG_DEBUG_LL
78 adr r0, str_p1
79 bl printascii
Lennert Buytenhek84081bd2008-03-28 21:11:47 +010080 mov r0, r9
81 bl printhex8
82 adr r0, str_p2
83 bl printascii
Hyok S. Choi75d90832006-03-27 14:58:25 +010084 b __error
Lennert Buytenhek84081bd2008-03-28 21:11:47 +010085str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
86str_p2: .asciz ").\n"
Hyok S. Choi75d90832006-03-27 14:58:25 +010087 .align
88#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +010089ENDPROC(__error_p)
Hyok S. Choi75d90832006-03-27 14:58:25 +010090
Hyok S. Choi75d90832006-03-27 14:58:25 +010091__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
Nicolas Pitre158bc5a2009-11-07 07:35:06 +0100100 adr r3, 4f
Hyok S. Choi75d90832006-03-27 14:58:25 +0100101 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
1051: 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 Marinas93ed3972008-08-28 11:22:32 +0100120ENDPROC(__error_a)
121
Hyok S. Choi75d90832006-03-27 14:58:25 +0100122str_a1: .asciz "\nError: unrecognized/unsupported machine ID (r1 = 0x"
123str_a2: .asciz ").\n\nAvailable machine support:\n\nID (hex)\tNAME\n"
124str_a3: .asciz "\nPlease check your kernel config and/or bootloader.\n"
125 .align
126#endif
127
Hyok S. Choi75d90832006-03-27 14:58:25 +0100128__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
1421: mov r0, r0
143 b 1b
Catalin Marinas93ed3972008-08-28 11:22:32 +0100144ENDPROC(__error)
Hyok S. Choi75d90832006-03-27 14:58:25 +0100145
146
147/*
Russell King5085f3f2010-10-01 15:37:05 +0100148 * This provides a C-API version of __lookup_processor_type
Hyok S. Choi75d90832006-03-27 14:58:25 +0100149 */
150ENTRY(lookup_processor_type)
Russell King5085f3f2010-10-01 15:37:05 +0100151 stmfd sp!, {r4 - r6, r9, lr}
Hyok S. Choi75d90832006-03-27 14:58:25 +0100152 mov r9, r0
153 bl __lookup_processor_type
154 mov r0, r5
Russell King5085f3f2010-10-01 15:37:05 +0100155 ldmfd sp!, {r4 - r6, r9, pc}
Catalin Marinas93ed3972008-08-28 11:22:32 +0100156ENDPROC(lookup_processor_type)
Hyok S. Choi75d90832006-03-27 14:58:25 +0100157
158/*
Russell King4baa9922008-08-02 10:55:55 +0100159 * Look in <asm/procinfo.h> and arch/arm/kernel/arch.[ch] for
Hyok S. Choi75d90832006-03-27 14:58:25 +0100160 * more information about the __proc_info and __arch_info structures.
161 */
Catalin Marinas88987ef2009-07-24 12:32:52 +0100162 .align 2
Catalin Marinasb86040a2009-07-24 12:32:54 +01001634: .long .
Hyok S. Choi75d90832006-03-27 14:58:25 +0100164 .long __arch_info_begin
165 .long __arch_info_end
166
167/*
168 * Lookup machine architecture in the linker-build list of architectures.
169 * Note that we can't use the absolute addresses for the __arch_info
170 * lists since we aren't running with the MMU on (and therefore, we are
171 * not in the correct address space). We have to calculate the offset.
172 *
173 * r1 = machine architecture number
174 * Returns:
175 * r3, r4, r6 corrupted
176 * r5 = mach_info pointer in physical address space
177 */
Hyok S. Choi75d90832006-03-27 14:58:25 +0100178__lookup_machine_type:
Catalin Marinasb86040a2009-07-24 12:32:54 +0100179 adr r3, 4b
Hyok S. Choi75d90832006-03-27 14:58:25 +0100180 ldmia r3, {r4, r5, r6}
181 sub r3, r3, r4 @ get offset between virt&phys
182 add r5, r5, r3 @ convert virt addresses to
183 add r6, r6, r3 @ physical address space
1841: ldr r3, [r5, #MACHINFO_TYPE] @ get machine type
185 teq r3, r1 @ matches loader number?
186 beq 2f @ found
187 add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc
188 cmp r5, r6
189 blo 1b
190 mov r5, #0 @ unknown machine
1912: mov pc, lr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100192ENDPROC(__lookup_machine_type)
Hyok S. Choi75d90832006-03-27 14:58:25 +0100193
194/*
195 * This provides a C-API version of the above function.
196 */
197ENTRY(lookup_machine_type)
198 stmfd sp!, {r4 - r6, lr}
199 mov r1, r0
200 bl __lookup_machine_type
201 mov r0, r5
202 ldmfd sp!, {r4 - r6, pc}
Catalin Marinas93ed3972008-08-28 11:22:32 +0100203ENDPROC(lookup_machine_type)
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100204
205/* Determine validity of the r2 atags pointer. The heuristic requires
206 * that the pointer be aligned, in the first 16k of physical RAM and
207 * that the ATAG_CORE marker is first and present. Future revisions
208 * of this function may be more lenient with the physical address and
209 * may also be able to move the ATAGS block if necessary.
210 *
211 * r8 = machinfo
212 *
213 * Returns:
214 * r2 either valid atags pointer, or zero
215 * r5, r6 corrupted
216 */
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100217__vet_atags:
218 tst r2, #0x3 @ aligned?
219 bne 1f
220
221 ldr r5, [r2, #0] @ is first tag ATAG_CORE?
David Brown31abdb72009-10-01 17:43:29 +0100222 cmp r5, #ATAG_CORE_SIZE
223 cmpne r5, #ATAG_CORE_SIZE_EMPTY
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100224 bne 1f
225 ldr r5, [r2, #4]
226 ldr r6, =ATAG_CORE
227 cmp r5, r6
228 bne 1f
229
230 mov pc, lr @ atag pointer is ok
231
2321: mov r2, #0
233 mov pc, lr
Catalin Marinas93ed3972008-08-28 11:22:32 +0100234ENDPROC(__vet_atags)
Russell King5085f3f2010-10-01 15:37:05 +0100235
236/*
237 * Read processor ID register (CP#15, CR0), and look up in the linker-built
238 * supported processor list. Note that we can't use the absolute addresses
239 * for the __proc_info lists since we aren't running with the MMU on
240 * (and therefore, we are not in the correct address space). We have to
241 * calculate the offset.
242 *
243 * r9 = cpuid
244 * Returns:
245 * r3, r4, r6 corrupted
246 * r5 = proc_info pointer in physical address space
247 * r9 = cpuid (preserved)
248 */
249 __CPUINIT
250__lookup_processor_type:
251 adr r3, __lookup_processor_type_data
252 ldmia r3, {r4 - r6}
253 sub r3, r3, r4 @ get offset between virt&phys
254 add r5, r5, r3 @ convert virt addresses to
255 add r6, r6, r3 @ physical address space
2561: ldmia r5, {r3, r4} @ value, mask
257 and r4, r4, r9 @ mask wanted bits
258 teq r3, r4
259 beq 2f
260 add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
261 cmp r5, r6
262 blo 1b
263 mov r5, #0 @ unknown processor
2642: mov pc, lr
265ENDPROC(__lookup_processor_type)
266
267/*
268 * Look in <asm/procinfo.h> for information about the __proc_info structure.
269 */
270 .align 2
271 .type __lookup_processor_type_data, %object
272__lookup_processor_type_data:
273 .long .
274 .long __proc_info_begin
275 .long __proc_info_end
276 .size __lookup_processor_type_data, . - __lookup_processor_type_data