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