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