blob: 7e662bdd5cb36e8422b6ac9ba10da8dde32cbcdf [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 */
Russell King6ebbf2c2014-06-30 16:29:12 +010013#include <asm/assembler.h>
Hyok S. Choi75d90832006-03-27 14:58:25 +010014
Greg Ungerer9c4c9f32008-03-05 06:50:07 +010015#define ATAG_CORE 0x54410001
16#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2)
David Brown31abdb742009-10-01 17:43:29 +010017#define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2)
Greg Ungerer9c4c9f32008-03-05 06:50:07 +010018
Grant Likely4c2896e2011-04-28 14:27:20 -060019#ifdef CONFIG_CPU_BIG_ENDIAN
20#define OF_DT_MAGIC 0xd00dfeed
21#else
22#define OF_DT_MAGIC 0xedfe0dd0 /* 0xd00dfeed in big-endian */
23#endif
24
Hyok S. Choi75d90832006-03-27 14:58:25 +010025/*
26 * Exception handling. Something went wrong and we can't proceed. We
27 * ought to tell the user, but since we don't have any guarantee that
28 * we're even running on the right architecture, we do virtually nothing.
29 *
30 * If CONFIG_DEBUG_LL is set we try to print out something about the error
31 * and hope for the best (useful if bootloader fails to pass a proper
32 * machine ID for example).
33 */
Russell King80924ac2010-10-04 17:45:25 +010034 __HEAD
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010035
36/* Determine validity of the r2 atags pointer. The heuristic requires
37 * that the pointer be aligned, in the first 16k of physical RAM and
Grant Likely4c2896e2011-04-28 14:27:20 -060038 * that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE
39 * is selected, then it will also accept a dtb pointer. Future revisions
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010040 * of this function may be more lenient with the physical address and
41 * may also be able to move the ATAGS block if necessary.
42 *
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010043 * Returns:
Grant Likely4c2896e2011-04-28 14:27:20 -060044 * r2 either valid atags pointer, valid dtb pointer, or zero
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010045 * r5, r6 corrupted
46 */
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010047__vet_atags:
48 tst r2, #0x3 @ aligned?
49 bne 1f
50
Grant Likely4c2896e2011-04-28 14:27:20 -060051 ldr r5, [r2, #0]
52#ifdef CONFIG_OF_FLATTREE
53 ldr r6, =OF_DT_MAGIC @ is it a DTB?
54 cmp r5, r6
55 beq 2f
56#endif
57 cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?
David Brown31abdb742009-10-01 17:43:29 +010058 cmpne r5, #ATAG_CORE_SIZE_EMPTY
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010059 bne 1f
60 ldr r5, [r2, #4]
61 ldr r6, =ATAG_CORE
62 cmp r5, r6
63 bne 1f
64
Russell King6ebbf2c2014-06-30 16:29:12 +0100652: ret lr @ atag/dtb pointer is ok
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010066
671: mov r2, #0
Russell King6ebbf2c2014-06-30 16:29:12 +010068 ret lr
Catalin Marinas93ed3972008-08-28 11:22:32 +010069ENDPROC(__vet_atags)
Russell King5085f3f2010-10-01 15:37:05 +010070
71/*
Russell King17bb5e22010-10-04 16:29:35 +010072 * The following fragment of code is executed with the MMU on in MMU mode,
73 * and uses absolute addresses; this is not position independent.
74 *
75 * r0 = cp#15 control register
76 * r1 = machine ID
Grant Likely4c2896e2011-04-28 14:27:20 -060077 * r2 = atags/dtb pointer
Russell King17bb5e22010-10-04 16:29:35 +010078 * r9 = processor ID
79 */
80 __INIT
81__mmap_switched:
82 adr r3, __mmap_switched_data
83
84 ldmia r3!, {r4, r5, r6, r7}
85 cmp r4, r5 @ Copy data segment if needed
861: cmpne r5, r6
87 ldrne fp, [r4], #4
88 strne fp, [r5], #4
89 bne 1b
90
91 mov fp, #0 @ Clear BSS (and zero fp)
921: cmp r6, r7
93 strcc fp, [r6],#4
94 bcc 1b
95
96 ARM( ldmia r3, {r4, r5, r6, r7, sp})
97 THUMB( ldmia r3, {r4, r5, r6, r7} )
98 THUMB( ldr sp, [r3, #16] )
99 str r9, [r4] @ Save processor ID
100 str r1, [r5] @ Save machine type
101 str r2, [r6] @ Save atags pointer
Uwe Kleine-Königb849a602012-01-16 10:34:31 +0100102 cmp r7, #0
Russell King0aeb3402014-04-13 19:43:26 +0100103 strne r0, [r7] @ Save control register values
Russell King17bb5e22010-10-04 16:29:35 +0100104 b start_kernel
105ENDPROC(__mmap_switched)
106
107 .align 2
108 .type __mmap_switched_data, %object
109__mmap_switched_data:
110 .long __data_loc @ r4
Russell Kinga0a55682010-10-18 22:34:47 +0100111 .long _sdata @ r5
Russell King17bb5e22010-10-04 16:29:35 +0100112 .long __bss_start @ r6
113 .long _end @ r7
114 .long processor_id @ r4
115 .long __machine_arch_type @ r5
116 .long __atags_pointer @ r6
Uwe Kleine-Königb849a602012-01-16 10:34:31 +0100117#ifdef CONFIG_CPU_CP15
Russell King17bb5e22010-10-04 16:29:35 +0100118 .long cr_alignment @ r7
Uwe Kleine-Königb849a602012-01-16 10:34:31 +0100119#else
120 .long 0 @ r7
121#endif
Russell King17bb5e22010-10-04 16:29:35 +0100122 .long init_thread_union + THREAD_START_SP @ sp
123 .size __mmap_switched_data, . - __mmap_switched_data
124
Russell King8d13b442019-02-14 09:49:24 -0500125 __FINIT
126 .text
127
Russell King17bb5e22010-10-04 16:29:35 +0100128/*
Russell King17bb5e22010-10-04 16:29:35 +0100129 * This provides a C-API version of __lookup_processor_type
130 */
131ENTRY(lookup_processor_type)
132 stmfd sp!, {r4 - r6, r9, lr}
133 mov r9, r0
134 bl __lookup_processor_type
135 mov r0, r5
136 ldmfd sp!, {r4 - r6, r9, pc}
137ENDPROC(lookup_processor_type)
138
139/*
Russell King5085f3f2010-10-01 15:37:05 +0100140 * Read processor ID register (CP#15, CR0), and look up in the linker-built
141 * supported processor list. Note that we can't use the absolute addresses
142 * for the __proc_info lists since we aren't running with the MMU on
143 * (and therefore, we are not in the correct address space). We have to
144 * calculate the offset.
145 *
146 * r9 = cpuid
147 * Returns:
148 * r3, r4, r6 corrupted
149 * r5 = proc_info pointer in physical address space
150 * r9 = cpuid (preserved)
151 */
Russell King5085f3f2010-10-01 15:37:05 +0100152__lookup_processor_type:
153 adr r3, __lookup_processor_type_data
154 ldmia r3, {r4 - r6}
155 sub r3, r3, r4 @ get offset between virt&phys
156 add r5, r5, r3 @ convert virt addresses to
157 add r6, r6, r3 @ physical address space
1581: ldmia r5, {r3, r4} @ value, mask
159 and r4, r4, r9 @ mask wanted bits
160 teq r3, r4
161 beq 2f
162 add r5, r5, #PROC_INFO_SZ @ sizeof(proc_info_list)
163 cmp r5, r6
164 blo 1b
165 mov r5, #0 @ unknown processor
Russell King6ebbf2c2014-06-30 16:29:12 +01001662: ret lr
Russell King5085f3f2010-10-01 15:37:05 +0100167ENDPROC(__lookup_processor_type)
168
169/*
170 * Look in <asm/procinfo.h> for information about the __proc_info structure.
171 */
172 .align 2
173 .type __lookup_processor_type_data, %object
174__lookup_processor_type_data:
175 .long .
176 .long __proc_info_begin
177 .long __proc_info_end
178 .size __lookup_processor_type_data, . - __lookup_processor_type_data
Russell Kingc083c662010-10-04 17:39:20 +0100179
Thomas Petazzonib3634572014-02-18 17:02:54 +0100180__error_lpae:
181#ifdef CONFIG_DEBUG_LL
182 adr r0, str_lpae
183 bl printascii
184 b __error
185str_lpae: .asciz "\nError: Kernel with LPAE support, but CPU does not support LPAE.\n"
186#else
187 b __error
188#endif
189 .align
190ENDPROC(__error_lpae)
191
Russell Kingc083c662010-10-04 17:39:20 +0100192__error_p:
193#ifdef CONFIG_DEBUG_LL
194 adr r0, str_p1
195 bl printascii
196 mov r0, r9
197 bl printhex8
198 adr r0, str_p2
199 bl printascii
200 b __error
201str_p1: .asciz "\nError: unrecognized/unsupported processor variant (0x"
202str_p2: .asciz ").\n"
203 .align
204#endif
205ENDPROC(__error_p)
206
207__error:
208#ifdef CONFIG_ARCH_RPC
209/*
210 * Turn the screen red on a error - RiscPC only.
211 */
212 mov r0, #0x02000000
213 mov r3, #0x11
214 orr r3, r3, r3, lsl #8
215 orr r3, r3, r3, lsl #16
216 str r3, [r0], #4
217 str r3, [r0], #4
218 str r3, [r0], #4
219 str r3, [r0], #4
220#endif
2211: mov r0, r0
222 b 1b
223ENDPROC(__error)