ARM: 8319/1: advertise availability of v8 Crypto instructions
[deliverable/linux.git] / arch / arm / boot / compressed / head.S
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/boot/compressed/head.S
3 *
4 * Copyright (C) 1996-2002 Russell King
10c2df65 5 * Copyright (C) 2004 Hyok S. Choi (MPU support)
1da177e4
LT
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
1da177e4 11#include <linux/linkage.h>
424e5994 12#include <asm/assembler.h>
1da177e4 13
da94a829 14 .arch armv7-a
1da177e4
LT
15/*
16 * Debugging stuff
17 *
18 * Note that these macros must not contain any code which is not
19 * 100% relocatable. Any attempt to do so will result in a crash.
20 * Please select one of the following when turning on debugging.
21 */
22#ifdef DEBUG
5cd0c344 23
5cd0c344 24#if defined(CONFIG_DEBUG_ICEDCC)
7d95ded9 25
dfad549d 26#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
4e6d488a 27 .macro loadsp, rb, tmp
7d95ded9
TL
28 .endm
29 .macro writeb, ch, rb
30 mcr p14, 0, \ch, c0, c5, 0
31 .endm
c633c3cf 32#elif defined(CONFIG_CPU_XSCALE)
4e6d488a 33 .macro loadsp, rb, tmp
c633c3cf
JCPV
34 .endm
35 .macro writeb, ch, rb
36 mcr p14, 0, \ch, c8, c0, 0
37 .endm
7d95ded9 38#else
4e6d488a 39 .macro loadsp, rb, tmp
1da177e4 40 .endm
224b5be6 41 .macro writeb, ch, rb
41a9e680 42 mcr p14, 0, \ch, c1, c0, 0
1da177e4 43 .endm
7d95ded9
TL
44#endif
45
5cd0c344 46#else
224b5be6 47
4beba08b 48#include CONFIG_DEBUG_LL_INCLUDE
224b5be6 49
5cd0c344
RK
50 .macro writeb, ch, rb
51 senduart \ch, \rb
1da177e4 52 .endm
5cd0c344 53
224b5be6 54#if defined(CONFIG_ARCH_SA1100)
4e6d488a 55 .macro loadsp, rb, tmp
1da177e4 56 mov \rb, #0x80000000 @ physical base address
224b5be6 57#ifdef CONFIG_DEBUG_LL_SER3
1da177e4 58 add \rb, \rb, #0x00050000 @ Ser3
224b5be6 59#else
1da177e4 60 add \rb, \rb, #0x00010000 @ Ser1
224b5be6 61#endif
1da177e4 62 .endm
1da177e4 63#else
4e6d488a
TL
64 .macro loadsp, rb, tmp
65 addruart \rb, \tmp
224b5be6 66 .endm
1da177e4 67#endif
5cd0c344 68#endif
1da177e4
LT
69#endif
70
71 .macro kputc,val
72 mov r0, \val
73 bl putc
74 .endm
75
76 .macro kphex,val,len
77 mov r0, \val
78 mov r1, #\len
79 bl phex
80 .endm
81
82 .macro debug_reloc_start
83#ifdef DEBUG
84 kputc #'\n'
85 kphex r6, 8 /* processor id */
86 kputc #':'
87 kphex r7, 8 /* architecture id */
f12d0d7c 88#ifdef CONFIG_CPU_CP15
1da177e4
LT
89 kputc #':'
90 mrc p15, 0, r0, c1, c0
91 kphex r0, 8 /* control reg */
f12d0d7c 92#endif
1da177e4
LT
93 kputc #'\n'
94 kphex r5, 8 /* decompressed kernel start */
95 kputc #'-'
f4619025 96 kphex r9, 8 /* decompressed kernel end */
1da177e4
LT
97 kputc #'>'
98 kphex r4, 8 /* kernel execution address */
99 kputc #'\n'
100#endif
101 .endm
102
103 .macro debug_reloc_end
104#ifdef DEBUG
105 kphex r5, 8 /* end of kernel */
106 kputc #'\n'
107 mov r0, r4
108 bl memdump /* dump 256 bytes at start of kernel */
109#endif
110 .endm
111
112 .section ".start", #alloc, #execinstr
113/*
114 * sort out different calling conventions
115 */
116 .align
26e5ca93 117 .arm @ Always enter in ARM state
1da177e4
LT
118start:
119 .type start,#function
b11fe388 120 .rept 7
1da177e4
LT
121 mov r0, r0
122 .endr
b11fe388
NP
123 ARM( mov r0, r0 )
124 ARM( b 1f )
125 THUMB( adr r12, BSYM(1f) )
126 THUMB( bx r12 )
1da177e4 127
33656d56
NP
128 .word _magic_sig @ Magic numbers to help the loader
129 .word _magic_start @ absolute load/run zImage address
130 .word _magic_end @ zImage end address
9696fcae 131 .word 0x04030201 @ endianness flag
33656d56 132
26e5ca93 133 THUMB( .thumb )
424e5994 1341:
97bcb0fe 135 ARM_BE8( setend be ) @ go BE8 if compiled for BE8
424e5994
DM
136 mrs r9, cpsr
137#ifdef CONFIG_ARM_VIRT_EXT
138 bl __hyp_stub_install @ get into SVC mode, reversibly
139#endif
140 mov r7, r1 @ save architecture ID
f4619025 141 mov r8, r2 @ save atags pointer
1da177e4 142
1da177e4
LT
143 /*
144 * Booting from Angel - need to enter SVC mode and disable
145 * FIQs/IRQs (numeric definitions from angel arm.h source).
146 * We only do this if we were in user mode on entry.
147 */
148 mrs r2, cpsr @ get current mode
149 tst r2, #3 @ not user?
150 bne not_angel
151 mov r0, #0x17 @ angel_SWIreason_EnterSVC
0e056f20
CM
152 ARM( swi 0x123456 ) @ angel_SWI_ARM
153 THUMB( svc 0xab ) @ angel_SWI_THUMB
1da177e4 154not_angel:
424e5994
DM
155 safe_svcmode_maskall r0
156 msr spsr_cxsf, r9 @ Save the CPU boot mode in
157 @ SPSR
1da177e4
LT
158 /*
159 * Note that some cache flushing and other stuff may
160 * be needed here - is there an Angel SWI call for this?
161 */
162
163 /*
164 * some architecture specific code can be inserted
f4619025 165 * by the linker here, but it should preserve r7, r8, and r9.
1da177e4
LT
166 */
167
168 .text
6d7d0ae5 169
e69edc79 170#ifdef CONFIG_AUTO_ZRELADDR
0a6a78b8
RK
171 /*
172 * Find the start of physical memory. As we are executing
173 * without the MMU on, we are in the physical address space.
174 * We just need to get rid of any offset by aligning the
175 * address.
176 *
177 * This alignment is a balance between the requirements of
178 * different platforms - we have chosen 128MB to allow
179 * platforms which align the start of their physical memory
180 * to 128MB to use this feature, while allowing the zImage
181 * to be placed within the first 128MB of memory on other
182 * platforms. Increasing the alignment means we place
183 * stricter alignment requirements on the start of physical
184 * memory, but relaxing it means that we break people who
185 * are already placing their zImage in (eg) the top 64MB
186 * of this range.
187 */
bfa64c4a
DM
188 mov r4, pc
189 and r4, r4, #0xf8000000
0a6a78b8 190 /* Determine final kernel image address. */
e69edc79
EM
191 add r4, r4, #TEXT_OFFSET
192#else
9e84ed63 193 ldr r4, =zreladdr
e69edc79 194#endif
1da177e4 195
2874865c
NP
196 /*
197 * Set up a page table only if it won't overwrite ourself.
7d57909b 198 * That means r4 < pc || r4 - 16k page directory > &_end.
2874865c
NP
199 * Given that r4 > &_end is most unfrequent, we add a rough
200 * additional 1MB of room for a possible appended DTB.
201 */
202 mov r0, pc
203 cmp r0, r4
204 ldrcc r0, LC0+32
205 addcc r0, r0, pc
206 cmpcc r4, r0
207 orrcc r4, r4, #1 @ remember we skipped cache_on
208 blcs cache_on
6d7d0ae5
NP
209
210restart: adr r0, LC0
34cc1a8f 211 ldmia r0, {r1, r2, r3, r6, r10, r11, r12}
adcc2591 212 ldr sp, [r0, #28]
6d7d0ae5
NP
213
214 /*
215 * We might be running at a different address. We need
216 * to fix up various pointers.
217 */
218 sub r0, r0, r1 @ calculate the delta offset
6d7d0ae5 219 add r6, r6, r0 @ _edata
34cc1a8f
NP
220 add r10, r10, r0 @ inflated kernel size location
221
222 /*
223 * The kernel build system appends the size of the
224 * decompressed kernel at the end of the compressed data
225 * in little-endian form.
226 */
227 ldrb r9, [r10, #0]
228 ldrb lr, [r10, #1]
229 orr r9, r9, lr, lsl #8
230 ldrb lr, [r10, #2]
231 ldrb r10, [r10, #3]
232 orr r9, r9, lr, lsl #16
233 orr r9, r9, r10, lsl #24
1da177e4 234
6d7d0ae5
NP
235#ifndef CONFIG_ZBOOT_ROM
236 /* malloc space is above the relocated stack (64k max) */
237 add sp, sp, r0
238 add r10, sp, #0x10000
239#else
1da177e4 240 /*
6d7d0ae5
NP
241 * With ZBOOT_ROM the bss/stack is non relocatable,
242 * but someone could still run this code from RAM,
243 * in which case our reference is _edata.
1da177e4 244 */
6d7d0ae5
NP
245 mov r10, r6
246#endif
247
e2a6a3aa
JB
248 mov r5, #0 @ init dtb size to 0
249#ifdef CONFIG_ARM_APPENDED_DTB
250/*
251 * r0 = delta
252 * r2 = BSS start
253 * r3 = BSS end
2874865c 254 * r4 = final kernel address (possibly with LSB set)
e2a6a3aa
JB
255 * r5 = appended dtb size (still unknown)
256 * r6 = _edata
257 * r7 = architecture ID
258 * r8 = atags/device tree pointer
259 * r9 = size of decompressed image
260 * r10 = end of this image, including bss/stack/malloc space if non XIP
261 * r11 = GOT start
262 * r12 = GOT end
263 * sp = stack pointer
264 *
265 * if there are device trees (dtb) appended to zImage, advance r10 so that the
266 * dtb data will get relocated along with the kernel if necessary.
267 */
268
269 ldr lr, [r6, #0]
270#ifndef __ARMEB__
271 ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian
272#else
273 ldr r1, =0xd00dfeed
274#endif
275 cmp lr, r1
276 bne dtb_check_done @ not found
277
b90b9a38
NP
278#ifdef CONFIG_ARM_ATAG_DTB_COMPAT
279 /*
280 * OK... Let's do some funky business here.
281 * If we do have a DTB appended to zImage, and we do have
282 * an ATAG list around, we want the later to be translated
c2607f74
NP
283 * and folded into the former here. No GOT fixup has occurred
284 * yet, but none of the code we're about to call uses any
285 * global variable.
b90b9a38 286 */
c2607f74
NP
287
288 /* Get the initial DTB size */
289 ldr r5, [r6, #4]
290#ifndef __ARMEB__
291 /* convert to little endian */
292 eor r1, r5, r5, ror #16
293 bic r1, r1, #0x00ff0000
294 mov r5, r5, ror #8
295 eor r5, r5, r1, lsr #8
296#endif
297 /* 50% DTB growth should be good enough */
298 add r5, r5, r5, lsr #1
299 /* preserve 64-bit alignment */
300 add r5, r5, #7
301 bic r5, r5, #7
302 /* clamp to 32KB min and 1MB max */
303 cmp r5, #(1 << 15)
304 movlo r5, #(1 << 15)
305 cmp r5, #(1 << 20)
306 movhi r5, #(1 << 20)
307 /* temporarily relocate the stack past the DTB work space */
308 add sp, sp, r5
309
b90b9a38
NP
310 stmfd sp!, {r0-r3, ip, lr}
311 mov r0, r8
312 mov r1, r6
c2607f74 313 mov r2, r5
b90b9a38
NP
314 bl atags_to_fdt
315
316 /*
317 * If returned value is 1, there is no ATAG at the location
318 * pointed by r8. Try the typical 0x100 offset from start
319 * of RAM and hope for the best.
320 */
321 cmp r0, #1
531a6a94 322 sub r0, r4, #TEXT_OFFSET
2874865c 323 bic r0, r0, #1
531a6a94 324 add r0, r0, #0x100
b90b9a38 325 mov r1, r6
c2607f74 326 mov r2, r5
9c5fd9e8 327 bleq atags_to_fdt
b90b9a38
NP
328
329 ldmfd sp!, {r0-r3, ip, lr}
c2607f74 330 sub sp, sp, r5
b90b9a38
NP
331#endif
332
e2a6a3aa
JB
333 mov r8, r6 @ use the appended device tree
334
5ffb04f6
NP
335 /*
336 * Make sure that the DTB doesn't end up in the final
337 * kernel's .bss area. To do so, we adjust the decompressed
338 * kernel size to compensate if that .bss size is larger
339 * than the relocated code.
340 */
341 ldr r5, =_kernel_bss_size
342 adr r1, wont_overwrite
343 sub r1, r6, r1
344 subs r1, r5, r1
345 addhi r9, r9, r1
346
c2607f74 347 /* Get the current DTB size */
e2a6a3aa
JB
348 ldr r5, [r6, #4]
349#ifndef __ARMEB__
350 /* convert r5 (dtb size) to little endian */
351 eor r1, r5, r5, ror #16
352 bic r1, r1, #0x00ff0000
353 mov r5, r5, ror #8
354 eor r5, r5, r1, lsr #8
355#endif
356
357 /* preserve 64-bit alignment */
358 add r5, r5, #7
359 bic r5, r5, #7
360
361 /* relocate some pointers past the appended dtb */
362 add r6, r6, r5
363 add r10, r10, r5
364 add sp, sp, r5
365dtb_check_done:
366#endif
367
6d7d0ae5
NP
368/*
369 * Check to see if we will overwrite ourselves.
2874865c 370 * r4 = final kernel address (possibly with LSB set)
6d7d0ae5
NP
371 * r9 = size of decompressed image
372 * r10 = end of this image, including bss/stack/malloc space if non XIP
373 * We basically want:
ea9df3b1 374 * r4 - 16k page directory >= r10 -> OK
5ffb04f6 375 * r4 + image length <= address of wont_overwrite -> OK
2874865c 376 * Note: the possible LSB in r4 is harmless here.
6d7d0ae5 377 */
ea9df3b1 378 add r10, r10, #16384
6d7d0ae5
NP
379 cmp r4, r10
380 bhs wont_overwrite
381 add r10, r4, r9
5ffb04f6
NP
382 adr r9, wont_overwrite
383 cmp r10, r9
6d7d0ae5
NP
384 bls wont_overwrite
385
386/*
387 * Relocate ourselves past the end of the decompressed kernel.
6d7d0ae5
NP
388 * r6 = _edata
389 * r10 = end of the decompressed kernel
390 * Because we always copy ahead, we need to do it from the end and go
391 * backward in case the source and destination overlap.
392 */
adcc2591
NP
393 /*
394 * Bump to the next 256-byte boundary with the size of
395 * the relocation code added. This avoids overwriting
396 * ourself when the offset is small.
397 */
398 add r10, r10, #((reloc_code_end - restart + 256) & ~255)
6d7d0ae5
NP
399 bic r10, r10, #255
400
adcc2591
NP
401 /* Get start of code we want to copy and align it down. */
402 adr r5, restart
403 bic r5, r5, #31
404
424e5994
DM
405/* Relocate the hyp vector base if necessary */
406#ifdef CONFIG_ARM_VIRT_EXT
407 mrs r0, spsr
408 and r0, r0, #MODE_MASK
409 cmp r0, #HYP_MODE
410 bne 1f
411
412 bl __hyp_get_vectors
413 sub r0, r0, r5
414 add r0, r0, r10
415 bl __hyp_set_vectors
4161:
417#endif
418
6d7d0ae5
NP
419 sub r9, r6, r5 @ size to copy
420 add r9, r9, #31 @ rounded up to a multiple
421 bic r9, r9, #31 @ ... of 32 bytes
422 add r6, r9, r5
423 add r9, r9, r10
424
4251: ldmdb r6!, {r0 - r3, r10 - r12, lr}
426 cmp r6, r5
427 stmdb r9!, {r0 - r3, r10 - r12, lr}
428 bhi 1b
429
430 /* Preserve offset to relocated code. */
431 sub r6, r9, r6
432
7c2527f0
TL
433#ifndef CONFIG_ZBOOT_ROM
434 /* cache_clean_flush may use the stack, so relocate it */
435 add sp, sp, r6
436#endif
437
238962ac 438 bl cache_clean_flush
6d7d0ae5
NP
439
440 adr r0, BSYM(restart)
441 add r0, r0, r6
442 mov pc, r0
443
444wont_overwrite:
445/*
446 * If delta is zero, we are running at the address we were linked at.
447 * r0 = delta
448 * r2 = BSS start
449 * r3 = BSS end
2874865c 450 * r4 = kernel execution address (possibly with LSB set)
e2a6a3aa 451 * r5 = appended dtb size (0 if not present)
6d7d0ae5
NP
452 * r7 = architecture ID
453 * r8 = atags pointer
454 * r11 = GOT start
455 * r12 = GOT end
456 * sp = stack pointer
457 */
e2a6a3aa 458 orrs r1, r0, r5
6d7d0ae5 459 beq not_relocated
e2a6a3aa 460
98e12b5a 461 add r11, r11, r0
6d7d0ae5 462 add r12, r12, r0
1da177e4
LT
463
464#ifndef CONFIG_ZBOOT_ROM
465 /*
466 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
467 * we need to fix up pointers into the BSS region.
6d7d0ae5 468 * Note that the stack pointer has already been fixed up.
1da177e4
LT
469 */
470 add r2, r2, r0
471 add r3, r3, r0
1da177e4
LT
472
473 /*
474 * Relocate all entries in the GOT table.
e2a6a3aa 475 * Bump bss entries to _edata + dtb size
1da177e4 476 */
98e12b5a 4771: ldr r1, [r11, #0] @ relocate entries in the GOT
e2a6a3aa
JB
478 add r1, r1, r0 @ This fixes up C references
479 cmp r1, r2 @ if entry >= bss_start &&
480 cmphs r3, r1 @ bss_end > entry
481 addhi r1, r1, r5 @ entry += dtb size
482 str r1, [r11], #4 @ next entry
6d7d0ae5 483 cmp r11, r12
1da177e4 484 blo 1b
e2a6a3aa
JB
485
486 /* bump our bss pointers too */
487 add r2, r2, r5
488 add r3, r3, r5
489
1da177e4
LT
490#else
491
492 /*
493 * Relocate entries in the GOT table. We only relocate
494 * the entries that are outside the (relocated) BSS region.
495 */
98e12b5a 4961: ldr r1, [r11, #0] @ relocate entries in the GOT
1da177e4
LT
497 cmp r1, r2 @ entry < bss_start ||
498 cmphs r3, r1 @ _end < entry
499 addlo r1, r1, r0 @ table. This fixes up the
98e12b5a 500 str r1, [r11], #4 @ C references.
6d7d0ae5 501 cmp r11, r12
1da177e4
LT
502 blo 1b
503#endif
504
505not_relocated: mov r0, #0
5061: str r0, [r2], #4 @ clear bss
507 str r0, [r2], #4
508 str r0, [r2], #4
509 str r0, [r2], #4
510 cmp r2, r3
511 blo 1b
512
2874865c
NP
513 /*
514 * Did we skip the cache setup earlier?
515 * That is indicated by the LSB in r4.
516 * Do it now if so.
517 */
518 tst r4, #1
519 bic r4, r4, #1
520 blne cache_on
521
1da177e4 522/*
6d7d0ae5
NP
523 * The C runtime environment should now be setup sufficiently.
524 * Set up some pointers, and start decompressing.
525 * r4 = kernel execution address
526 * r7 = architecture ID
527 * r8 = atags pointer
1da177e4 528 */
6d7d0ae5
NP
529 mov r0, r4
530 mov r1, sp @ malloc space above stack
531 add r2, sp, #0x10000 @ 64k max
1da177e4
LT
532 mov r3, r7
533 bl decompress_kernel
1da177e4 534 bl cache_clean_flush
6d7d0ae5 535 bl cache_off
6d7d0ae5
NP
536 mov r1, r7 @ restore architecture number
537 mov r2, r8 @ restore atags pointer
424e5994
DM
538
539#ifdef CONFIG_ARM_VIRT_EXT
540 mrs r0, spsr @ Get saved CPU boot mode
541 and r0, r0, #MODE_MASK
542 cmp r0, #HYP_MODE @ if not booted in HYP mode...
543 bne __enter_kernel @ boot kernel directly
544
545 adr r12, .L__hyp_reentry_vectors_offset
546 ldr r0, [r12]
547 add r0, r0, r12
548
549 bl __hyp_set_vectors
550 __HVC(0) @ otherwise bounce to hyp mode
551
552 b . @ should never be reached
553
554 .align 2
555.L__hyp_reentry_vectors_offset: .long __hyp_reentry_vectors - .
556#else
557 b __enter_kernel
558#endif
1da177e4 559
88987ef9 560 .align 2
1da177e4
LT
561 .type LC0, #object
562LC0: .word LC0 @ r1
563 .word __bss_start @ r2
564 .word _end @ r3
6d7d0ae5 565 .word _edata @ r6
34cc1a8f 566 .word input_data_end - 4 @ r10 (inflated size location)
98e12b5a 567 .word _got_start @ r11
1da177e4 568 .word _got_end @ ip
8d7e4cc2 569 .word .L_user_stack_end @ sp
2874865c 570 .word _end - restart + 16384 + 1024*1024
1da177e4
LT
571 .size LC0, . - LC0
572
573#ifdef CONFIG_ARCH_RPC
574 .globl params
db7b2b4b 575params: ldr r0, =0x10000100 @ params_phys for RPC
1da177e4
LT
576 mov pc, lr
577 .ltorg
578 .align
579#endif
580
581/*
582 * Turn on the cache. We need to setup some page tables so that we
583 * can have both the I and D caches on.
584 *
585 * We place the page tables 16k down from the kernel execution address,
586 * and we hope that nothing else is using it. If we're using it, we
587 * will go pop!
588 *
589 * On entry,
590 * r4 = kernel execution address
1da177e4 591 * r7 = architecture number
f4619025 592 * r8 = atags pointer
1da177e4 593 * On exit,
21b2841d 594 * r0, r1, r2, r3, r9, r10, r12 corrupted
1da177e4 595 * This routine must preserve:
6d7d0ae5 596 * r4, r7, r8
1da177e4
LT
597 */
598 .align 5
599cache_on: mov r3, #8 @ cache_on function
600 b call_cache_fn
601
10c2df65
HC
602/*
603 * Initialize the highest priority protection region, PR7
604 * to cover all 32bit address and cacheable and bufferable.
605 */
606__armv4_mpu_cache_on:
607 mov r0, #0x3f @ 4G, the whole
608 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
609 mcr p15, 0, r0, c6, c7, 1
610
611 mov r0, #0x80 @ PR7
612 mcr p15, 0, r0, c2, c0, 0 @ D-cache on
613 mcr p15, 0, r0, c2, c0, 1 @ I-cache on
614 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
615
616 mov r0, #0xc000
617 mcr p15, 0, r0, c5, c0, 1 @ I-access permission
618 mcr p15, 0, r0, c5, c0, 0 @ D-access permission
619
620 mov r0, #0
621 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
622 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
623 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
624 mrc p15, 0, r0, c1, c0, 0 @ read control reg
625 @ ...I .... ..D. WC.M
626 orr r0, r0, #0x002d @ .... .... ..1. 11.1
627 orr r0, r0, #0x1000 @ ...1 .... .... ....
628
629 mcr p15, 0, r0, c1, c0, 0 @ write control reg
630
631 mov r0, #0
632 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
633 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
634 mov pc, lr
635
636__armv3_mpu_cache_on:
637 mov r0, #0x3f @ 4G, the whole
638 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
639
640 mov r0, #0x80 @ PR7
641 mcr p15, 0, r0, c2, c0, 0 @ cache on
642 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
643
644 mov r0, #0xc000
645 mcr p15, 0, r0, c5, c0, 0 @ access permission
646
647 mov r0, #0
648 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
4a8d57a5
UKK
649 /*
650 * ?? ARMv3 MMU does not allow reading the control register,
651 * does this really work on ARMv3 MPU?
652 */
10c2df65
HC
653 mrc p15, 0, r0, c1, c0, 0 @ read control reg
654 @ .... .... .... WC.M
655 orr r0, r0, #0x000d @ .... .... .... 11.1
4a8d57a5 656 /* ?? this overwrites the value constructed above? */
10c2df65
HC
657 mov r0, #0
658 mcr p15, 0, r0, c1, c0, 0 @ write control reg
659
4a8d57a5 660 /* ?? invalidate for the second time? */
10c2df65
HC
661 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
662 mov pc, lr
663
1fdc08ab
RK
664#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
665#define CB_BITS 0x08
666#else
667#define CB_BITS 0x0c
668#endif
669
1da177e4
LT
670__setup_mmu: sub r3, r4, #16384 @ Page directory size
671 bic r3, r3, #0xff @ Align the pointer
672 bic r3, r3, #0x3f00
673/*
674 * Initialise the page tables, turning on the cacheable and bufferable
675 * bits for the RAM area only.
676 */
677 mov r0, r3
f4619025
RK
678 mov r9, r0, lsr #18
679 mov r9, r9, lsl #18 @ start of RAM
680 add r10, r9, #0x10000000 @ a reasonable RAM size
1fdc08ab
RK
681 mov r1, #0x12 @ XN|U + section mapping
682 orr r1, r1, #3 << 10 @ AP=11
1da177e4 683 add r2, r3, #16384
265d5e48 6841: cmp r1, r9 @ if virt > start of RAM
1fdc08ab
RK
685 cmphs r10, r1 @ && end of RAM > virt
686 bic r1, r1, #0x1c @ clear XN|U + C + B
687 orrlo r1, r1, #0x10 @ Set XN|U for non-RAM
688 orrhs r1, r1, r6 @ set RAM section settings
1da177e4
LT
689 str r1, [r0], #4 @ 1:1 mapping
690 add r1, r1, #1048576
691 teq r0, r2
692 bne 1b
693/*
694 * If ever we are running from Flash, then we surely want the cache
695 * to be enabled also for our execution instance... We map 2MB of it
696 * so there is no map overlap problem for up to 1 MB compressed kernel.
697 * If the execution is in RAM then we would only be duplicating the above.
698 */
1fdc08ab 699 orr r1, r6, #0x04 @ ensure B is set for this
1da177e4 700 orr r1, r1, #3 << 10
bfa64c4a
DM
701 mov r2, pc
702 mov r2, r2, lsr #20
1da177e4
LT
703 orr r1, r1, r2, lsl #20
704 add r0, r3, r2, lsl #2
705 str r1, [r0], #4
706 add r1, r1, #1048576
707 str r1, [r0]
708 mov pc, lr
93ed3970 709ENDPROC(__setup_mmu)
1da177e4 710
5010192d
DM
711@ Enable unaligned access on v6, to allow better code generation
712@ for the decompressor C code:
713__armv6_mmu_cache_on:
714 mrc p15, 0, r0, c1, c0, 0 @ read SCTLR
715 bic r0, r0, #2 @ A (no unaligned access fault)
716 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
717 mcr p15, 0, r0, c1, c0, 0 @ write SCTLR
718 b __armv4_mmu_cache_on
719
af3e4fd3
MG
720__arm926ejs_mmu_cache_on:
721#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
722 mov r0, #4 @ put dcache in WT mode
723 mcr p15, 7, r0, c15, c0, 0
724#endif
725
c76b6b41 726__armv4_mmu_cache_on:
1da177e4 727 mov r12, lr
8bdca0ac 728#ifdef CONFIG_MMU
1fdc08ab 729 mov r6, #CB_BITS | 0x12 @ U
1da177e4
LT
730 bl __setup_mmu
731 mov r0, #0
732 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
733 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
734 mrc p15, 0, r0, c1, c0, 0 @ read control reg
735 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
736 orr r0, r0, #0x0030
457c2403 737 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
c76b6b41 738 bl __common_mmu_cache_on
1da177e4
LT
739 mov r0, #0
740 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
8bdca0ac 741#endif
1da177e4
LT
742 mov pc, r12
743
7d09e854
CM
744__armv7_mmu_cache_on:
745 mov r12, lr
8bdca0ac 746#ifdef CONFIG_MMU
7d09e854
CM
747 mrc p15, 0, r11, c0, c1, 4 @ read ID_MMFR0
748 tst r11, #0xf @ VMSA
1fdc08ab 749 movne r6, #CB_BITS | 0x02 @ !XN
7d09e854
CM
750 blne __setup_mmu
751 mov r0, #0
752 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
753 tst r11, #0xf @ VMSA
754 mcrne p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
8bdca0ac 755#endif
7d09e854 756 mrc p15, 0, r0, c1, c0, 0 @ read control reg
e1e5b7e4 757 bic r0, r0, #1 << 28 @ clear SCTLR.TRE
7d09e854
CM
758 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
759 orr r0, r0, #0x003c @ write buffer
5010192d
DM
760 bic r0, r0, #2 @ A (no unaligned access fault)
761 orr r0, r0, #1 << 22 @ U (v6 unaligned access model)
762 @ (needed for ARM1176)
8bdca0ac 763#ifdef CONFIG_MMU
457c2403 764 ARM_BE8( orr r0, r0, #1 << 25 ) @ big-endian page tables
dbece458 765 mrcne p15, 0, r6, c2, c0, 2 @ read ttb control reg
7d09e854 766 orrne r0, r0, #1 @ MMU enabled
1fdc08ab 767 movne r1, #0xfffffffd @ domain 0 = client
dbece458
WD
768 bic r6, r6, #1 << 31 @ 32-bit translation system
769 bic r6, r6, #3 << 0 @ use only ttbr0
7d09e854
CM
770 mcrne p15, 0, r3, c2, c0, 0 @ load page table pointer
771 mcrne p15, 0, r1, c3, c0, 0 @ load domain access control
dbece458 772 mcrne p15, 0, r6, c2, c0, 2 @ load ttb control
8bdca0ac 773#endif
d675d0bc 774 mcr p15, 0, r0, c7, c5, 4 @ ISB
7d09e854
CM
775 mcr p15, 0, r0, c1, c0, 0 @ load control register
776 mrc p15, 0, r0, c1, c0, 0 @ and read it back
777 mov r0, #0
778 mcr p15, 0, r0, c7, c5, 4 @ ISB
779 mov pc, r12
780
28853ac8
PZ
781__fa526_cache_on:
782 mov r12, lr
1fdc08ab 783 mov r6, #CB_BITS | 0x12 @ U
28853ac8
PZ
784 bl __setup_mmu
785 mov r0, #0
786 mcr p15, 0, r0, c7, c7, 0 @ Invalidate whole cache
787 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
788 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
789 mrc p15, 0, r0, c1, c0, 0 @ read control reg
790 orr r0, r0, #0x1000 @ I-cache enable
791 bl __common_mmu_cache_on
792 mov r0, #0
793 mcr p15, 0, r0, c8, c7, 0 @ flush UTLB
794 mov pc, r12
795
c76b6b41 796__common_mmu_cache_on:
0e056f20 797#ifndef CONFIG_THUMB2_KERNEL
1da177e4
LT
798#ifndef DEBUG
799 orr r0, r0, #0x000d @ Write buffer, mmu
800#endif
801 mov r1, #-1
802 mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
803 mcr p15, 0, r1, c3, c0, 0 @ load domain access control
2dc7667b
NP
804 b 1f
805 .align 5 @ cache line aligned
8061: mcr p15, 0, r0, c1, c0, 0 @ load control register
807 mrc p15, 0, r0, c1, c0, 0 @ and read it back to
808 sub pc, lr, r0, lsr #32 @ properly flush pipeline
0e056f20 809#endif
1da177e4 810
946a105e
DM
811#define PROC_ENTRY_SIZE (4*5)
812
1da177e4
LT
813/*
814 * Here follow the relocatable cache support functions for the
815 * various processors. This is a generic hook for locating an
816 * entry and jumping to an instruction at the specified offset
817 * from the start of the block. Please note this is all position
818 * independent code.
819 *
820 * r1 = corrupted
821 * r2 = corrupted
822 * r3 = block offset
98e12b5a 823 * r9 = corrupted
1da177e4
LT
824 * r12 = corrupted
825 */
826
827call_cache_fn: adr r12, proc_types
f12d0d7c 828#ifdef CONFIG_CPU_CP15
98e12b5a 829 mrc p15, 0, r9, c0, c0 @ get processor ID
f12d0d7c 830#else
98e12b5a 831 ldr r9, =CONFIG_PROCESSOR_ID
f12d0d7c 832#endif
1da177e4
LT
8331: ldr r1, [r12, #0] @ get value
834 ldr r2, [r12, #4] @ get mask
98e12b5a 835 eor r1, r1, r9 @ (real ^ match)
1da177e4 836 tst r1, r2 @ & mask
0e056f20
CM
837 ARM( addeq pc, r12, r3 ) @ call cache function
838 THUMB( addeq r12, r3 )
839 THUMB( moveq pc, r12 ) @ call cache function
946a105e 840 add r12, r12, #PROC_ENTRY_SIZE
1da177e4
LT
841 b 1b
842
843/*
844 * Table for cache operations. This is basically:
845 * - CPU ID match
846 * - CPU ID mask
847 * - 'cache on' method instruction
848 * - 'cache off' method instruction
849 * - 'cache flush' method instruction
850 *
851 * We match an entry using: ((real_id ^ match) & mask) == 0
852 *
853 * Writethrough caches generally only need 'on' and 'off'
854 * methods. Writeback caches _must_ have the flush method
855 * defined.
856 */
88987ef9 857 .align 2
1da177e4
LT
858 .type proc_types,#object
859proc_types:
ced2a3b8
M
860 .word 0x41000000 @ old ARM ID
861 .word 0xff00f000
1da177e4 862 mov pc, lr
0e056f20 863 THUMB( nop )
1da177e4 864 mov pc, lr
0e056f20 865 THUMB( nop )
1da177e4 866 mov pc, lr
0e056f20 867 THUMB( nop )
1da177e4
LT
868
869 .word 0x41007000 @ ARM7/710
870 .word 0xfff8fe00
4cdfc2ec
RK
871 mov pc, lr
872 THUMB( nop )
873 mov pc, lr
874 THUMB( nop )
1da177e4 875 mov pc, lr
0e056f20 876 THUMB( nop )
1da177e4
LT
877
878 .word 0x41807200 @ ARM720T (writethrough)
879 .word 0xffffff00
0e056f20
CM
880 W(b) __armv4_mmu_cache_on
881 W(b) __armv4_mmu_cache_off
1da177e4 882 mov pc, lr
0e056f20 883 THUMB( nop )
1da177e4 884
10c2df65
HC
885 .word 0x41007400 @ ARM74x
886 .word 0xff00ff00
0e056f20
CM
887 W(b) __armv3_mpu_cache_on
888 W(b) __armv3_mpu_cache_off
889 W(b) __armv3_mpu_cache_flush
10c2df65
HC
890
891 .word 0x41009400 @ ARM94x
892 .word 0xff00ff00
0e056f20
CM
893 W(b) __armv4_mpu_cache_on
894 W(b) __armv4_mpu_cache_off
895 W(b) __armv4_mpu_cache_flush
10c2df65 896
af3e4fd3
MG
897 .word 0x41069260 @ ARM926EJ-S (v5TEJ)
898 .word 0xff0ffff0
720c60e1
NP
899 W(b) __arm926ejs_mmu_cache_on
900 W(b) __armv4_mmu_cache_off
901 W(b) __armv5tej_mmu_cache_flush
10c2df65 902
1da177e4
LT
903 .word 0x00007000 @ ARM7 IDs
904 .word 0x0000f000
905 mov pc, lr
0e056f20 906 THUMB( nop )
1da177e4 907 mov pc, lr
0e056f20 908 THUMB( nop )
1da177e4 909 mov pc, lr
0e056f20 910 THUMB( nop )
1da177e4
LT
911
912 @ Everything from here on will be the new ID system.
913
914 .word 0x4401a100 @ sa110 / sa1100
915 .word 0xffffffe0
0e056f20
CM
916 W(b) __armv4_mmu_cache_on
917 W(b) __armv4_mmu_cache_off
918 W(b) __armv4_mmu_cache_flush
1da177e4
LT
919
920 .word 0x6901b110 @ sa1110
921 .word 0xfffffff0
0e056f20
CM
922 W(b) __armv4_mmu_cache_on
923 W(b) __armv4_mmu_cache_off
924 W(b) __armv4_mmu_cache_flush
1da177e4 925
4157d317
HZ
926 .word 0x56056900
927 .word 0xffffff00 @ PXA9xx
0e056f20
CM
928 W(b) __armv4_mmu_cache_on
929 W(b) __armv4_mmu_cache_off
930 W(b) __armv4_mmu_cache_flush
49cbe786
EM
931
932 .word 0x56158000 @ PXA168
933 .word 0xfffff000
0e056f20
CM
934 W(b) __armv4_mmu_cache_on
935 W(b) __armv4_mmu_cache_off
936 W(b) __armv5tej_mmu_cache_flush
49cbe786 937
2e2023fe
NP
938 .word 0x56050000 @ Feroceon
939 .word 0xff0f0000
0e056f20
CM
940 W(b) __armv4_mmu_cache_on
941 W(b) __armv4_mmu_cache_off
942 W(b) __armv5tej_mmu_cache_flush
3ebb5a2b 943
5587931c
JS
944#ifdef CONFIG_CPU_FEROCEON_OLD_ID
945 /* this conflicts with the standard ARMv5TE entry */
946 .long 0x41009260 @ Old Feroceon
947 .long 0xff00fff0
948 b __armv4_mmu_cache_on
949 b __armv4_mmu_cache_off
950 b __armv5tej_mmu_cache_flush
951#endif
952
28853ac8
PZ
953 .word 0x66015261 @ FA526
954 .word 0xff01fff1
0e056f20
CM
955 W(b) __fa526_cache_on
956 W(b) __armv4_mmu_cache_off
957 W(b) __fa526_cache_flush
28853ac8 958
1da177e4
LT
959 @ These match on the architecture ID
960
961 .word 0x00020000 @ ARMv4T
962 .word 0x000f0000
0e056f20
CM
963 W(b) __armv4_mmu_cache_on
964 W(b) __armv4_mmu_cache_off
965 W(b) __armv4_mmu_cache_flush
1da177e4
LT
966
967 .word 0x00050000 @ ARMv5TE
968 .word 0x000f0000
0e056f20
CM
969 W(b) __armv4_mmu_cache_on
970 W(b) __armv4_mmu_cache_off
971 W(b) __armv4_mmu_cache_flush
1da177e4
LT
972
973 .word 0x00060000 @ ARMv5TEJ
974 .word 0x000f0000
0e056f20
CM
975 W(b) __armv4_mmu_cache_on
976 W(b) __armv4_mmu_cache_off
75216859 977 W(b) __armv5tej_mmu_cache_flush
1da177e4 978
45a7b9cf 979 .word 0x0007b000 @ ARMv6
7d09e854 980 .word 0x000ff000
5010192d 981 W(b) __armv6_mmu_cache_on
0e056f20
CM
982 W(b) __armv4_mmu_cache_off
983 W(b) __armv6_mmu_cache_flush
1da177e4 984
7d09e854
CM
985 .word 0x000f0000 @ new CPU Id
986 .word 0x000f0000
0e056f20
CM
987 W(b) __armv7_mmu_cache_on
988 W(b) __armv7_mmu_cache_off
989 W(b) __armv7_mmu_cache_flush
7d09e854 990
1da177e4
LT
991 .word 0 @ unrecognised type
992 .word 0
993 mov pc, lr
0e056f20 994 THUMB( nop )
1da177e4 995 mov pc, lr
0e056f20 996 THUMB( nop )
1da177e4 997 mov pc, lr
0e056f20 998 THUMB( nop )
1da177e4
LT
999
1000 .size proc_types, . - proc_types
1001
946a105e
DM
1002 /*
1003 * If you get a "non-constant expression in ".if" statement"
1004 * error from the assembler on this line, check that you have
1005 * not accidentally written a "b" instruction where you should
1006 * have written W(b).
1007 */
1008 .if (. - proc_types) % PROC_ENTRY_SIZE != 0
1009 .error "The size of one or more proc_types entries is wrong."
1010 .endif
1011
1da177e4
LT
1012/*
1013 * Turn off the Cache and MMU. ARMv3 does not support
1014 * reading the control register, but ARMv4 does.
1015 *
21b2841d
UKK
1016 * On exit,
1017 * r0, r1, r2, r3, r9, r12 corrupted
1018 * This routine must preserve:
6d7d0ae5 1019 * r4, r7, r8
1da177e4
LT
1020 */
1021 .align 5
1022cache_off: mov r3, #12 @ cache_off function
1023 b call_cache_fn
1024
10c2df65
HC
1025__armv4_mpu_cache_off:
1026 mrc p15, 0, r0, c1, c0
1027 bic r0, r0, #0x000d
1028 mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
1029 mov r0, #0
1030 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
1031 mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
1032 mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
1033 mov pc, lr
1034
1035__armv3_mpu_cache_off:
1036 mrc p15, 0, r0, c1, c0
1037 bic r0, r0, #0x000d
1038 mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
1039 mov r0, #0
1040 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
1041 mov pc, lr
1042
c76b6b41 1043__armv4_mmu_cache_off:
8bdca0ac 1044#ifdef CONFIG_MMU
1da177e4
LT
1045 mrc p15, 0, r0, c1, c0
1046 bic r0, r0, #0x000d
1047 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1048 mov r0, #0
1049 mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
1050 mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
8bdca0ac 1051#endif
1da177e4
LT
1052 mov pc, lr
1053
7d09e854
CM
1054__armv7_mmu_cache_off:
1055 mrc p15, 0, r0, c1, c0
8bdca0ac 1056#ifdef CONFIG_MMU
7d09e854 1057 bic r0, r0, #0x000d
8bdca0ac
CM
1058#else
1059 bic r0, r0, #0x000c
1060#endif
7d09e854
CM
1061 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
1062 mov r12, lr
1063 bl __armv7_mmu_cache_flush
1064 mov r0, #0
8bdca0ac 1065#ifdef CONFIG_MMU
7d09e854 1066 mcr p15, 0, r0, c8, c7, 0 @ invalidate whole TLB
8bdca0ac 1067#endif
c30c2f99
CM
1068 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTC
1069 mcr p15, 0, r0, c7, c10, 4 @ DSB
1070 mcr p15, 0, r0, c7, c5, 4 @ ISB
7d09e854
CM
1071 mov pc, r12
1072
1da177e4
LT
1073/*
1074 * Clean and flush the cache to maintain consistency.
1075 *
1da177e4 1076 * On exit,
21b2841d 1077 * r1, r2, r3, r9, r10, r11, r12 corrupted
1da177e4 1078 * This routine must preserve:
6d7d0ae5 1079 * r4, r6, r7, r8
1da177e4
LT
1080 */
1081 .align 5
1082cache_clean_flush:
1083 mov r3, #16
1084 b call_cache_fn
1085
10c2df65 1086__armv4_mpu_cache_flush:
238962ac
WD
1087 tst r4, #1
1088 movne pc, lr
10c2df65
HC
1089 mov r2, #1
1090 mov r3, #0
1091 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
1092 mov r1, #7 << 5 @ 8 segments
10931: orr r3, r1, #63 << 26 @ 64 entries
10942: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
1095 subs r3, r3, #1 << 26
1096 bcs 2b @ entries 63 to 0
1097 subs r1, r1, #1 << 5
1098 bcs 1b @ segments 7 to 0
1099
1100 teq r2, #0
1101 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
1102 mcr p15, 0, ip, c7, c10, 4 @ drain WB
1103 mov pc, lr
1104
28853ac8 1105__fa526_cache_flush:
238962ac
WD
1106 tst r4, #1
1107 movne pc, lr
28853ac8
PZ
1108 mov r1, #0
1109 mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
1110 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1111 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1112 mov pc, lr
10c2df65 1113
c76b6b41 1114__armv6_mmu_cache_flush:
1da177e4 1115 mov r1, #0
238962ac
WD
1116 tst r4, #1
1117 mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
1da177e4 1118 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
238962ac 1119 mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
1da177e4
LT
1120 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1121 mov pc, lr
1122
7d09e854 1123__armv7_mmu_cache_flush:
238962ac
WD
1124 tst r4, #1
1125 bne iflush
7d09e854
CM
1126 mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
1127 tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
7d09e854 1128 mov r10, #0
c30c2f99 1129 beq hierarchical
7d09e854
CM
1130 mcr p15, 0, r10, c7, c14, 0 @ clean+invalidate D
1131 b iflush
1132hierarchical:
c30c2f99 1133 mcr p15, 0, r10, c7, c10, 5 @ DMB
0e056f20 1134 stmfd sp!, {r0-r7, r9-r11}
7d09e854
CM
1135 mrc p15, 1, r0, c0, c0, 1 @ read clidr
1136 ands r3, r0, #0x7000000 @ extract loc from clidr
1137 mov r3, r3, lsr #23 @ left align loc bit field
1138 beq finished @ if loc is 0, then no need to clean
1139 mov r10, #0 @ start clean at cache level 0
1140loop1:
1141 add r2, r10, r10, lsr #1 @ work out 3x current cache level
1142 mov r1, r0, lsr r2 @ extract cache type bits from clidr
1143 and r1, r1, #7 @ mask of the bits for current cache only
1144 cmp r1, #2 @ see what cache we have at this level
1145 blt skip @ skip if no cache, or just i-cache
1146 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
1147 mcr p15, 0, r10, c7, c5, 4 @ isb to sych the new cssr&csidr
1148 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
1149 and r2, r1, #7 @ extract the length of the cache lines
1150 add r2, r2, #4 @ add 4 (line length offset)
1151 ldr r4, =0x3ff
1152 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
000b5025 1153 clz r5, r4 @ find bit position of way size increment
7d09e854
CM
1154 ldr r7, =0x7fff
1155 ands r7, r7, r1, lsr #13 @ extract max number of the index size
1156loop2:
1157 mov r9, r4 @ create working copy of max way size
1158loop3:
0e056f20
CM
1159 ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
1160 ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
1161 THUMB( lsl r6, r9, r5 )
1162 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
1163 THUMB( lsl r6, r7, r2 )
1164 THUMB( orr r11, r11, r6 ) @ factor index number into r11
7d09e854
CM
1165 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
1166 subs r9, r9, #1 @ decrement the way
1167 bge loop3
1168 subs r7, r7, #1 @ decrement the index
1169 bge loop2
1170skip:
1171 add r10, r10, #2 @ increment cache number
1172 cmp r3, r10
1173 bgt loop1
1174finished:
0e056f20 1175 ldmfd sp!, {r0-r7, r9-r11}
7d09e854
CM
1176 mov r10, #0 @ swith back to cache level 0
1177 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
7d09e854 1178iflush:
c30c2f99 1179 mcr p15, 0, r10, c7, c10, 4 @ DSB
7d09e854 1180 mcr p15, 0, r10, c7, c5, 0 @ invalidate I+BTB
c30c2f99
CM
1181 mcr p15, 0, r10, c7, c10, 4 @ DSB
1182 mcr p15, 0, r10, c7, c5, 4 @ ISB
7d09e854
CM
1183 mov pc, lr
1184
15754bf9 1185__armv5tej_mmu_cache_flush:
238962ac
WD
1186 tst r4, #1
1187 movne pc, lr
15754bf9
NP
11881: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
1189 bne 1b
1190 mcr p15, 0, r0, c7, c5, 0 @ flush I cache
1191 mcr p15, 0, r0, c7, c10, 4 @ drain WB
1192 mov pc, lr
1193
c76b6b41 1194__armv4_mmu_cache_flush:
238962ac
WD
1195 tst r4, #1
1196 movne pc, lr
1da177e4
LT
1197 mov r2, #64*1024 @ default: 32K dcache size (*2)
1198 mov r11, #32 @ default: 32 byte line size
1199 mrc p15, 0, r3, c0, c0, 1 @ read cache type
98e12b5a 1200 teq r3, r9 @ cache ID register present?
1da177e4
LT
1201 beq no_cache_id
1202 mov r1, r3, lsr #18
1203 and r1, r1, #7
1204 mov r2, #1024
1205 mov r2, r2, lsl r1 @ base dcache size *2
1206 tst r3, #1 << 14 @ test M bit
1207 addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
1208 mov r3, r3, lsr #12
1209 and r3, r3, #3
1210 mov r11, #8
1211 mov r11, r11, lsl r3 @ cache line size in bytes
1212no_cache_id:
0e056f20
CM
1213 mov r1, pc
1214 bic r1, r1, #63 @ align to longest cache line
1da177e4 1215 add r2, r1, r2
0e056f20
CM
12161:
1217 ARM( ldr r3, [r1], r11 ) @ s/w flush D cache
1218 THUMB( ldr r3, [r1] ) @ s/w flush D cache
1219 THUMB( add r1, r1, r11 )
1da177e4
LT
1220 teq r1, r2
1221 bne 1b
1222
1223 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
1224 mcr p15, 0, r1, c7, c6, 0 @ flush D cache
1225 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1226 mov pc, lr
1227
c76b6b41 1228__armv3_mmu_cache_flush:
10c2df65 1229__armv3_mpu_cache_flush:
238962ac
WD
1230 tst r4, #1
1231 movne pc, lr
1da177e4 1232 mov r1, #0
63fa7187 1233 mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
1da177e4
LT
1234 mov pc, lr
1235
1236/*
1237 * Various debugging routines for printing hex characters and
1238 * memory, which again must be relocatable.
1239 */
1240#ifdef DEBUG
88987ef9 1241 .align 2
1da177e4
LT
1242 .type phexbuf,#object
1243phexbuf: .space 12
1244 .size phexbuf, . - phexbuf
1245
be6f9f00 1246@ phex corrupts {r0, r1, r2, r3}
1da177e4
LT
1247phex: adr r3, phexbuf
1248 mov r2, #0
1249 strb r2, [r3, r1]
12501: subs r1, r1, #1
1251 movmi r0, r3
1252 bmi puts
1253 and r2, r0, #15
1254 mov r0, r0, lsr #4
1255 cmp r2, #10
1256 addge r2, r2, #7
1257 add r2, r2, #'0'
1258 strb r2, [r3, r1]
1259 b 1b
1260
be6f9f00 1261@ puts corrupts {r0, r1, r2, r3}
4e6d488a 1262puts: loadsp r3, r1
1da177e4
LT
12631: ldrb r2, [r0], #1
1264 teq r2, #0
1265 moveq pc, lr
5cd0c344 12662: writeb r2, r3
1da177e4
LT
1267 mov r1, #0x00020000
12683: subs r1, r1, #1
1269 bne 3b
1270 teq r2, #'\n'
1271 moveq r2, #'\r'
1272 beq 2b
1273 teq r0, #0
1274 bne 1b
1275 mov pc, lr
be6f9f00 1276@ putc corrupts {r0, r1, r2, r3}
1da177e4
LT
1277putc:
1278 mov r2, r0
1279 mov r0, #0
4e6d488a 1280 loadsp r3, r1
1da177e4
LT
1281 b 2b
1282
be6f9f00 1283@ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
1da177e4
LT
1284memdump: mov r12, r0
1285 mov r10, lr
1286 mov r11, #0
12872: mov r0, r11, lsl #2
1288 add r0, r0, r12
1289 mov r1, #8
1290 bl phex
1291 mov r0, #':'
1292 bl putc
12931: mov r0, #' '
1294 bl putc
1295 ldr r0, [r12, r11, lsl #2]
1296 mov r1, #8
1297 bl phex
1298 and r0, r11, #7
1299 teq r0, #3
1300 moveq r0, #' '
1301 bleq putc
1302 and r0, r11, #7
1303 add r11, r11, #1
1304 teq r0, #7
1305 bne 1b
1306 mov r0, #'\n'
1307 bl putc
1308 cmp r11, #64
1309 blt 2b
1310 mov pc, r10
1311#endif
1312
92c83ff1 1313 .ltorg
424e5994
DM
1314
1315#ifdef CONFIG_ARM_VIRT_EXT
1316.align 5
1317__hyp_reentry_vectors:
1318 W(b) . @ reset
1319 W(b) . @ undef
1320 W(b) . @ svc
1321 W(b) . @ pabort
1322 W(b) . @ dabort
1323 W(b) __enter_kernel @ hyp
1324 W(b) . @ irq
1325 W(b) . @ fiq
1326#endif /* CONFIG_ARM_VIRT_EXT */
1327
1328__enter_kernel:
1329 mov r0, #0 @ must be 0
1330 ARM( mov pc, r4 ) @ call kernel
1331 THUMB( bx r4 ) @ entry point is always ARM
1332
adcc2591 1333reloc_code_end:
1da177e4
LT
1334
1335 .align
b0c4d4ee 1336 .section ".stack", "aw", %nobits
8d7e4cc2
NP
1337.L_user_stack: .space 4096
1338.L_user_stack_end:
This page took 0.7538 seconds and 5 git commands to generate.