blob: 1c3c6ea5f9e7e3bb7b7ce5a880a039489200d200 [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)
16
Hyok S. Choi75d90832006-03-27 14:58:25 +010017 .type __switch_data, %object
18__switch_data:
19 .long __mmap_switched
20 .long __data_loc @ r4
21 .long __data_start @ r5
22 .long __bss_start @ r6
23 .long _end @ r7
24 .long processor_id @ r4
25 .long __machine_arch_type @ r5
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010026 .long __atags_pointer @ r6
27 .long cr_alignment @ r7
Hyok S. Choi75d90832006-03-27 14:58:25 +010028 .long init_thread_union + THREAD_START_SP @ sp
29
30/*
31 * The following fragment of code is executed with the MMU on in MMU mode,
32 * and uses absolute addresses; this is not position independent.
33 *
34 * r0 = cp#15 control register
35 * r1 = machine ID
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010036 * r2 = atags pointer
Hyok S. Choi75d90832006-03-27 14:58:25 +010037 * r9 = processor ID
38 */
39 .type __mmap_switched, %function
40__mmap_switched:
41 adr r3, __switch_data + 4
42
43 ldmia r3!, {r4, r5, r6, r7}
44 cmp r4, r5 @ Copy data segment if needed
451: cmpne r5, r6
46 ldrne fp, [r4], #4
47 strne fp, [r5], #4
48 bne 1b
49
50 mov fp, #0 @ Clear BSS (and zero fp)
511: cmp r6, r7
52 strcc fp, [r6],#4
53 bcc 1b
54
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010055 ldmia r3, {r4, r5, r6, r7, sp}
Hyok S. Choi75d90832006-03-27 14:58:25 +010056 str r9, [r4] @ Save processor ID
57 str r1, [r5] @ Save machine type
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010058 str r2, [r6] @ Save atags pointer
Hyok S. Choi75d90832006-03-27 14:58:25 +010059 bic r4, r0, #CR_A @ Clear 'A' bit
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010060 stmia r7, {r0, r4} @ Save control register values
Hyok S. Choi75d90832006-03-27 14:58:25 +010061 b start_kernel
62
63/*
64 * Exception handling. Something went wrong and we can't proceed. We
65 * ought to tell the user, but since we don't have any guarantee that
66 * we're even running on the right architecture, we do virtually nothing.
67 *
68 * If CONFIG_DEBUG_LL is set we try to print out something about the error
69 * and hope for the best (useful if bootloader fails to pass a proper
70 * machine ID for example).
71 */
72
73 .type __error_p, %function
74__error_p:
75#ifdef CONFIG_DEBUG_LL
76 adr r0, str_p1
77 bl printascii
Lennert Buytenhek84081bd2008-03-28 21:11:47 +010078 mov r0, r9
79 bl printhex8
80 adr r0, str_p2
81 bl printascii
Hyok S. Choi75d90832006-03-27 14:58:25 +010082 b __error
Lennert Buytenhek84081bd2008-03-28 21:11:47 +010083str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
84str_p2: .asciz ").\n"
Hyok S. Choi75d90832006-03-27 14:58:25 +010085 .align
86#endif
87
88 .type __error_a, %function
89__error_a:
90#ifdef CONFIG_DEBUG_LL
91 mov r4, r1 @ preserve machine ID
92 adr r0, str_a1
93 bl printascii
94 mov r0, r4
95 bl printhex8
96 adr r0, str_a2
97 bl printascii
98 adr r3, 3f
99 ldmia r3, {r4, r5, r6} @ get machine desc list
100 sub r4, r3, r4 @ get offset between virt&phys
101 add r5, r5, r4 @ convert virt addresses to
102 add r6, r6, r4 @ physical address space
1031: ldr r0, [r5, #MACHINFO_TYPE] @ get machine type
104 bl printhex8
105 mov r0, #'\t'
106 bl printch
107 ldr r0, [r5, #MACHINFO_NAME] @ get machine name
108 add r0, r0, r4
109 bl printascii
110 mov r0, #'\n'
111 bl printch
112 add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc
113 cmp r5, r6
114 blo 1b
115 adr r0, str_a3
116 bl printascii
117 b __error
118str_a1: .asciz "\nError: unrecognized/unsupported machine ID (r1 = 0x"
119str_a2: .asciz ").\n\nAvailable machine support:\n\nID (hex)\tNAME\n"
120str_a3: .asciz "\nPlease check your kernel config and/or bootloader.\n"
121 .align
122#endif
123
124 .type __error, %function
125__error:
126#ifdef CONFIG_ARCH_RPC
127/*
128 * Turn the screen red on a error - RiscPC only.
129 */
130 mov r0, #0x02000000
131 mov r3, #0x11
132 orr r3, r3, r3, lsl #8
133 orr r3, r3, r3, lsl #16
134 str r3, [r0], #4
135 str r3, [r0], #4
136 str r3, [r0], #4
137 str r3, [r0], #4
138#endif
1391: mov r0, r0
140 b 1b
141
142
143/*
144 * Read processor ID register (CP#15, CR0), and look up in the linker-built
145 * supported processor list. Note that we can't use the absolute addresses
146 * for the __proc_info lists since we aren't running with the MMU on
147 * (and therefore, we are not in the correct address space). We have to
148 * calculate the offset.
149 *
150 * r9 = cpuid
151 * Returns:
152 * r3, r4, r6 corrupted
153 * r5 = proc_info pointer in physical address space
154 * r9 = cpuid (preserved)
155 */
156 .type __lookup_processor_type, %function
157__lookup_processor_type:
158 adr r3, 3f
159 ldmda r3, {r5 - r7}
160 sub r3, r3, r7 @ get offset between virt&phys
161 add r5, r5, r3 @ convert virt addresses to
162 add r6, r6, r3 @ physical address space
1631: ldmia r5, {r3, r4} @ value, mask
164 and r4, r4, r9 @ mask wanted bits
165 teq r3, r4
166 beq 2f
167 add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
168 cmp r5, r6
169 blo 1b
170 mov r5, #0 @ unknown processor
1712: mov pc, lr
172
173/*
174 * This provides a C-API version of the above function.
175 */
176ENTRY(lookup_processor_type)
177 stmfd sp!, {r4 - r7, r9, lr}
178 mov r9, r0
179 bl __lookup_processor_type
180 mov r0, r5
181 ldmfd sp!, {r4 - r7, r9, pc}
182
183/*
Russell King4baa9922008-08-02 10:55:55 +0100184 * Look in <asm/procinfo.h> and arch/arm/kernel/arch.[ch] for
Hyok S. Choi75d90832006-03-27 14:58:25 +0100185 * more information about the __proc_info and __arch_info structures.
186 */
187 .long __proc_info_begin
188 .long __proc_info_end
1893: .long .
190 .long __arch_info_begin
191 .long __arch_info_end
192
193/*
194 * Lookup machine architecture in the linker-build list of architectures.
195 * Note that we can't use the absolute addresses for the __arch_info
196 * lists since we aren't running with the MMU on (and therefore, we are
197 * not in the correct address space). We have to calculate the offset.
198 *
199 * r1 = machine architecture number
200 * Returns:
201 * r3, r4, r6 corrupted
202 * r5 = mach_info pointer in physical address space
203 */
204 .type __lookup_machine_type, %function
205__lookup_machine_type:
206 adr r3, 3b
207 ldmia r3, {r4, r5, r6}
208 sub r3, r3, r4 @ get offset between virt&phys
209 add r5, r5, r3 @ convert virt addresses to
210 add r6, r6, r3 @ physical address space
2111: ldr r3, [r5, #MACHINFO_TYPE] @ get machine type
212 teq r3, r1 @ matches loader number?
213 beq 2f @ found
214 add r5, r5, #SIZEOF_MACHINE_DESC @ next machine_desc
215 cmp r5, r6
216 blo 1b
217 mov r5, #0 @ unknown machine
2182: mov pc, lr
219
220/*
221 * This provides a C-API version of the above function.
222 */
223ENTRY(lookup_machine_type)
224 stmfd sp!, {r4 - r6, lr}
225 mov r1, r0
226 bl __lookup_machine_type
227 mov r0, r5
228 ldmfd sp!, {r4 - r6, pc}
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100229
230/* Determine validity of the r2 atags pointer. The heuristic requires
231 * that the pointer be aligned, in the first 16k of physical RAM and
232 * that the ATAG_CORE marker is first and present. Future revisions
233 * of this function may be more lenient with the physical address and
234 * may also be able to move the ATAGS block if necessary.
235 *
236 * r8 = machinfo
237 *
238 * Returns:
239 * r2 either valid atags pointer, or zero
240 * r5, r6 corrupted
241 */
242
243 .type __vet_atags, %function
244__vet_atags:
245 tst r2, #0x3 @ aligned?
246 bne 1f
247
248 ldr r5, [r2, #0] @ is first tag ATAG_CORE?
249 subs r5, r5, #ATAG_CORE_SIZE
250 bne 1f
251 ldr r5, [r2, #4]
252 ldr r6, =ATAG_CORE
253 cmp r5, r6
254 bne 1f
255
256 mov pc, lr @ atag pointer is ok
257
2581: mov r2, #0
259 mov pc, lr