blob: 9b42b88bfba0d3ad5a71aa38bcd668e59d4620f0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/boot/compressed/head.S
3 *
4 * Copyright (C) 1996-2002 Russell King
Hyok S. Choi10c2df62006-03-27 10:21:34 +01005 * Copyright (C) 2004 Hyok S. Choi (MPU support)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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 */
11#include <linux/config.h>
12#include <linux/linkage.h>
13
14/*
15 * Debugging stuff
16 *
17 * Note that these macros must not contain any code which is not
18 * 100% relocatable. Any attempt to do so will result in a crash.
19 * Please select one of the following when turning on debugging.
20 */
21#ifdef DEBUG
Russell King5cd0c342005-05-03 12:18:46 +010022
Russell King5cd0c342005-05-03 12:18:46 +010023#if defined(CONFIG_DEBUG_ICEDCC)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 .macro loadsp, rb
25 .endm
Russell King224b5be2005-11-16 14:59:51 +000026 .macro writeb, ch, rb
Russell King5cd0c342005-05-03 12:18:46 +010027 mcr p14, 0, \ch, c0, c1, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 .endm
Russell King5cd0c342005-05-03 12:18:46 +010029#else
Russell King224b5be2005-11-16 14:59:51 +000030
31#include <asm/arch/debug-macro.S>
32
Russell King5cd0c342005-05-03 12:18:46 +010033 .macro writeb, ch, rb
34 senduart \ch, \rb
35 .endm
36
Russell King224b5be2005-11-16 14:59:51 +000037#if defined(CONFIG_ARCH_SA1100)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 .macro loadsp, rb
39 mov \rb, #0x80000000 @ physical base address
Russell King224b5be2005-11-16 14:59:51 +000040#ifdef CONFIG_DEBUG_LL_SER3
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 add \rb, \rb, #0x00050000 @ Ser3
Russell King224b5be2005-11-16 14:59:51 +000042#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 add \rb, \rb, #0x00010000 @ Ser1
Russell King224b5be2005-11-16 14:59:51 +000044#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#elif defined(CONFIG_ARCH_IOP331)
47 .macro loadsp, rb
48 mov \rb, #0xff000000
49 orr \rb, \rb, #0x00ff0000
50 orr \rb, \rb, #0x0000f700 @ location of the UART
51 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#elif defined(CONFIG_ARCH_S3C2410)
Russell King5cd0c342005-05-03 12:18:46 +010053 .macro loadsp, rb
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 mov \rb, #0x50000000
55 add \rb, \rb, #0x4000 * CONFIG_S3C2410_LOWLEVEL_UART_PORT
56 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#else
Russell King224b5be2005-11-16 14:59:51 +000058 .macro loadsp, rb
59 addruart \rb
60 .endm
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#endif
62#endif
Russell King5cd0c342005-05-03 12:18:46 +010063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 .macro kputc,val
66 mov r0, \val
67 bl putc
68 .endm
69
70 .macro kphex,val,len
71 mov r0, \val
72 mov r1, #\len
73 bl phex
74 .endm
75
76 .macro debug_reloc_start
77#ifdef DEBUG
78 kputc #'\n'
79 kphex r6, 8 /* processor id */
80 kputc #':'
81 kphex r7, 8 /* architecture id */
82 kputc #':'
83 mrc p15, 0, r0, c1, c0
84 kphex r0, 8 /* control reg */
85 kputc #'\n'
86 kphex r5, 8 /* decompressed kernel start */
87 kputc #'-'
Russell Kingf4619022006-01-12 17:17:57 +000088 kphex r9, 8 /* decompressed kernel end */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 kputc #'>'
90 kphex r4, 8 /* kernel execution address */
91 kputc #'\n'
92#endif
93 .endm
94
95 .macro debug_reloc_end
96#ifdef DEBUG
97 kphex r5, 8 /* end of kernel */
98 kputc #'\n'
99 mov r0, r4
100 bl memdump /* dump 256 bytes at start of kernel */
101#endif
102 .endm
103
104 .section ".start", #alloc, #execinstr
105/*
106 * sort out different calling conventions
107 */
108 .align
109start:
110 .type start,#function
111 .rept 8
112 mov r0, r0
113 .endr
114
115 b 1f
116 .word 0x016f2818 @ Magic numbers to help the loader
117 .word start @ absolute load/run zImage address
118 .word _edata @ zImage end address
1191: mov r7, r1 @ save architecture ID
Russell Kingf4619022006-01-12 17:17:57 +0000120 mov r8, r2 @ save atags pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122#ifndef __ARM_ARCH_2__
123 /*
124 * Booting from Angel - need to enter SVC mode and disable
125 * FIQs/IRQs (numeric definitions from angel arm.h source).
126 * We only do this if we were in user mode on entry.
127 */
128 mrs r2, cpsr @ get current mode
129 tst r2, #3 @ not user?
130 bne not_angel
131 mov r0, #0x17 @ angel_SWIreason_EnterSVC
132 swi 0x123456 @ angel_SWI_ARM
133not_angel:
134 mrs r2, cpsr @ turn off interrupts to
135 orr r2, r2, #0xc0 @ prevent angel from running
136 msr cpsr_c, r2
137#else
138 teqp pc, #0x0c000003 @ turn off interrupts
139#endif
140
141 /*
142 * Note that some cache flushing and other stuff may
143 * be needed here - is there an Angel SWI call for this?
144 */
145
146 /*
147 * some architecture specific code can be inserted
Russell Kingf4619022006-01-12 17:17:57 +0000148 * by the linker here, but it should preserve r7, r8, and r9.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 */
150
151 .text
152 adr r0, LC0
153 ldmia r0, {r1, r2, r3, r4, r5, r6, ip, sp}
154 subs r0, r0, r1 @ calculate the delta offset
155
156 @ if delta is zero, we are
157 beq not_relocated @ running at the address we
158 @ were linked at.
159
160 /*
161 * We're running at a different address. We need to fix
162 * up various pointers:
163 * r5 - zImage base address
164 * r6 - GOT start
165 * ip - GOT end
166 */
167 add r5, r5, r0
168 add r6, r6, r0
169 add ip, ip, r0
170
171#ifndef CONFIG_ZBOOT_ROM
172 /*
173 * If we're running fully PIC === CONFIG_ZBOOT_ROM = n,
174 * we need to fix up pointers into the BSS region.
175 * r2 - BSS start
176 * r3 - BSS end
177 * sp - stack pointer
178 */
179 add r2, r2, r0
180 add r3, r3, r0
181 add sp, sp, r0
182
183 /*
184 * Relocate all entries in the GOT table.
185 */
1861: ldr r1, [r6, #0] @ relocate entries in the GOT
187 add r1, r1, r0 @ table. This fixes up the
188 str r1, [r6], #4 @ C references.
189 cmp r6, ip
190 blo 1b
191#else
192
193 /*
194 * Relocate entries in the GOT table. We only relocate
195 * the entries that are outside the (relocated) BSS region.
196 */
1971: ldr r1, [r6, #0] @ relocate entries in the GOT
198 cmp r1, r2 @ entry < bss_start ||
199 cmphs r3, r1 @ _end < entry
200 addlo r1, r1, r0 @ table. This fixes up the
201 str r1, [r6], #4 @ C references.
202 cmp r6, ip
203 blo 1b
204#endif
205
206not_relocated: mov r0, #0
2071: str r0, [r2], #4 @ clear bss
208 str r0, [r2], #4
209 str r0, [r2], #4
210 str r0, [r2], #4
211 cmp r2, r3
212 blo 1b
213
214 /*
215 * The C runtime environment should now be setup
216 * sufficiently. Turn the cache on, set up some
217 * pointers, and start decompressing.
218 */
219 bl cache_on
220
221 mov r1, sp @ malloc space above stack
222 add r2, sp, #0x10000 @ 64k max
223
224/*
225 * Check to see if we will overwrite ourselves.
226 * r4 = final kernel address
227 * r5 = start of this image
228 * r2 = end of malloc space (and therefore this image)
229 * We basically want:
230 * r4 >= r2 -> OK
231 * r4 + image length <= r5 -> OK
232 */
233 cmp r4, r2
234 bhs wont_overwrite
235 add r0, r4, #4096*1024 @ 4MB largest kernel size
236 cmp r0, r5
237 bls wont_overwrite
238
239 mov r5, r2 @ decompress after malloc space
240 mov r0, r5
241 mov r3, r7
242 bl decompress_kernel
243
244 add r0, r0, #127
245 bic r0, r0, #127 @ align the kernel length
246/*
247 * r0 = decompressed kernel length
248 * r1-r3 = unused
249 * r4 = kernel execution address
250 * r5 = decompressed kernel start
251 * r6 = processor ID
252 * r7 = architecture ID
Russell Kingf4619022006-01-12 17:17:57 +0000253 * r8 = atags pointer
254 * r9-r14 = corrupted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 */
256 add r1, r5, r0 @ end of decompressed kernel
257 adr r2, reloc_start
258 ldr r3, LC1
259 add r3, r2, r3
Russell Kingf4619022006-01-12 17:17:57 +00002601: ldmia r2!, {r9 - r14} @ copy relocation code
261 stmia r1!, {r9 - r14}
262 ldmia r2!, {r9 - r14}
263 stmia r1!, {r9 - r14}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 cmp r2, r3
265 blo 1b
266
267 bl cache_clean_flush
268 add pc, r5, r0 @ call relocation code
269
270/*
271 * We're not in danger of overwriting ourselves. Do this the simple way.
272 *
273 * r4 = kernel execution address
274 * r7 = architecture ID
275 */
276wont_overwrite: mov r0, r4
277 mov r3, r7
278 bl decompress_kernel
279 b call_kernel
280
281 .type LC0, #object
282LC0: .word LC0 @ r1
283 .word __bss_start @ r2
284 .word _end @ r3
285 .word zreladdr @ r4
286 .word _start @ r5
287 .word _got_start @ r6
288 .word _got_end @ ip
289 .word user_stack+4096 @ sp
290LC1: .word reloc_end - reloc_start
291 .size LC0, . - LC0
292
293#ifdef CONFIG_ARCH_RPC
294 .globl params
295params: ldr r0, =params_phys
296 mov pc, lr
297 .ltorg
298 .align
299#endif
300
301/*
302 * Turn on the cache. We need to setup some page tables so that we
303 * can have both the I and D caches on.
304 *
305 * We place the page tables 16k down from the kernel execution address,
306 * and we hope that nothing else is using it. If we're using it, we
307 * will go pop!
308 *
309 * On entry,
310 * r4 = kernel execution address
311 * r6 = processor ID
312 * r7 = architecture number
Russell Kingf4619022006-01-12 17:17:57 +0000313 * r8 = atags pointer
314 * r9 = run-time address of "start" (???)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 * On exit,
Russell Kingf4619022006-01-12 17:17:57 +0000316 * r1, r2, r3, r9, r10, r12 corrupted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 * This routine must preserve:
Russell Kingf4619022006-01-12 17:17:57 +0000318 * r4, r5, r6, r7, r8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 */
320 .align 5
321cache_on: mov r3, #8 @ cache_on function
322 b call_cache_fn
323
Hyok S. Choi10c2df62006-03-27 10:21:34 +0100324/*
325 * Initialize the highest priority protection region, PR7
326 * to cover all 32bit address and cacheable and bufferable.
327 */
328__armv4_mpu_cache_on:
329 mov r0, #0x3f @ 4G, the whole
330 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
331 mcr p15, 0, r0, c6, c7, 1
332
333 mov r0, #0x80 @ PR7
334 mcr p15, 0, r0, c2, c0, 0 @ D-cache on
335 mcr p15, 0, r0, c2, c0, 1 @ I-cache on
336 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
337
338 mov r0, #0xc000
339 mcr p15, 0, r0, c5, c0, 1 @ I-access permission
340 mcr p15, 0, r0, c5, c0, 0 @ D-access permission
341
342 mov r0, #0
343 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
344 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
345 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
346 mrc p15, 0, r0, c1, c0, 0 @ read control reg
347 @ ...I .... ..D. WC.M
348 orr r0, r0, #0x002d @ .... .... ..1. 11.1
349 orr r0, r0, #0x1000 @ ...1 .... .... ....
350
351 mcr p15, 0, r0, c1, c0, 0 @ write control reg
352
353 mov r0, #0
354 mcr p15, 0, r0, c7, c5, 0 @ flush(inval) I-Cache
355 mcr p15, 0, r0, c7, c6, 0 @ flush(inval) D-Cache
356 mov pc, lr
357
358__armv3_mpu_cache_on:
359 mov r0, #0x3f @ 4G, the whole
360 mcr p15, 0, r0, c6, c7, 0 @ PR7 Area Setting
361
362 mov r0, #0x80 @ PR7
363 mcr p15, 0, r0, c2, c0, 0 @ cache on
364 mcr p15, 0, r0, c3, c0, 0 @ write-buffer on
365
366 mov r0, #0xc000
367 mcr p15, 0, r0, c5, c0, 0 @ access permission
368
369 mov r0, #0
370 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
371 mrc p15, 0, r0, c1, c0, 0 @ read control reg
372 @ .... .... .... WC.M
373 orr r0, r0, #0x000d @ .... .... .... 11.1
374 mov r0, #0
375 mcr p15, 0, r0, c1, c0, 0 @ write control reg
376
377 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
378 mov pc, lr
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380__setup_mmu: sub r3, r4, #16384 @ Page directory size
381 bic r3, r3, #0xff @ Align the pointer
382 bic r3, r3, #0x3f00
383/*
384 * Initialise the page tables, turning on the cacheable and bufferable
385 * bits for the RAM area only.
386 */
387 mov r0, r3
Russell Kingf4619022006-01-12 17:17:57 +0000388 mov r9, r0, lsr #18
389 mov r9, r9, lsl #18 @ start of RAM
390 add r10, r9, #0x10000000 @ a reasonable RAM size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 mov r1, #0x12
392 orr r1, r1, #3 << 10
393 add r2, r3, #16384
Nicolas Pitre265d5e42006-01-18 22:38:51 +00003941: cmp r1, r9 @ if virt > start of RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 orrhs r1, r1, #0x0c @ set cacheable, bufferable
Russell Kingf4619022006-01-12 17:17:57 +0000396 cmp r1, r10 @ if virt > end of RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 bichs r1, r1, #0x0c @ clear cacheable, bufferable
398 str r1, [r0], #4 @ 1:1 mapping
399 add r1, r1, #1048576
400 teq r0, r2
401 bne 1b
402/*
403 * If ever we are running from Flash, then we surely want the cache
404 * to be enabled also for our execution instance... We map 2MB of it
405 * so there is no map overlap problem for up to 1 MB compressed kernel.
406 * If the execution is in RAM then we would only be duplicating the above.
407 */
408 mov r1, #0x1e
409 orr r1, r1, #3 << 10
410 mov r2, pc, lsr #20
411 orr r1, r1, r2, lsl #20
412 add r0, r3, r2, lsl #2
413 str r1, [r0], #4
414 add r1, r1, #1048576
415 str r1, [r0]
416 mov pc, lr
417
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000418__armv4_mmu_cache_on:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 mov r12, lr
420 bl __setup_mmu
421 mov r0, #0
422 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
423 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
424 mrc p15, 0, r0, c1, c0, 0 @ read control reg
425 orr r0, r0, #0x5000 @ I-cache enable, RR cache replacement
426 orr r0, r0, #0x0030
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000427 bl __common_mmu_cache_on
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 mov r0, #0
429 mcr p15, 0, r0, c8, c7, 0 @ flush I,D TLBs
430 mov pc, r12
431
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000432__arm6_mmu_cache_on:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 mov r12, lr
434 bl __setup_mmu
435 mov r0, #0
436 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
437 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
438 mov r0, #0x30
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000439 bl __common_mmu_cache_on
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 mov r0, #0
441 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
442 mov pc, r12
443
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000444__common_mmu_cache_on:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#ifndef DEBUG
446 orr r0, r0, #0x000d @ Write buffer, mmu
447#endif
448 mov r1, #-1
449 mcr p15, 0, r3, c2, c0, 0 @ load page table pointer
450 mcr p15, 0, r1, c3, c0, 0 @ load domain access control
Nicolas Pitre2dc76672006-07-01 21:29:32 +0100451 b 1f
452 .align 5 @ cache line aligned
4531: mcr p15, 0, r0, c1, c0, 0 @ load control register
454 mrc p15, 0, r0, c1, c0, 0 @ and read it back to
455 sub pc, lr, r0, lsr #32 @ properly flush pipeline
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457/*
458 * All code following this line is relocatable. It is relocated by
459 * the above code to the end of the decompressed kernel image and
460 * executed there. During this time, we have no stacks.
461 *
462 * r0 = decompressed kernel length
463 * r1-r3 = unused
464 * r4 = kernel execution address
465 * r5 = decompressed kernel start
466 * r6 = processor ID
467 * r7 = architecture ID
Russell Kingf4619022006-01-12 17:17:57 +0000468 * r8 = atags pointer
469 * r9-r14 = corrupted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 */
471 .align 5
Russell Kingf4619022006-01-12 17:17:57 +0000472reloc_start: add r9, r5, r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 debug_reloc_start
474 mov r1, r4
4751:
476 .rept 4
Russell Kingf4619022006-01-12 17:17:57 +0000477 ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel
478 stmia r1!, {r0, r2, r3, r10 - r14}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .endr
480
Russell Kingf4619022006-01-12 17:17:57 +0000481 cmp r5, r9
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 blo 1b
483 debug_reloc_end
484
485call_kernel: bl cache_clean_flush
486 bl cache_off
Russell Kingf4619022006-01-12 17:17:57 +0000487 mov r0, #0 @ must be zero
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 mov r1, r7 @ restore architecture number
Russell Kingf4619022006-01-12 17:17:57 +0000489 mov r2, r8 @ restore atags pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 mov pc, r4 @ call kernel
491
492/*
493 * Here follow the relocatable cache support functions for the
494 * various processors. This is a generic hook for locating an
495 * entry and jumping to an instruction at the specified offset
496 * from the start of the block. Please note this is all position
497 * independent code.
498 *
499 * r1 = corrupted
500 * r2 = corrupted
501 * r3 = block offset
502 * r6 = corrupted
503 * r12 = corrupted
504 */
505
506call_cache_fn: adr r12, proc_types
507 mrc p15, 0, r6, c0, c0 @ get processor ID
5081: ldr r1, [r12, #0] @ get value
509 ldr r2, [r12, #4] @ get mask
510 eor r1, r1, r6 @ (real ^ match)
511 tst r1, r2 @ & mask
512 addeq pc, r12, r3 @ call cache function
513 add r12, r12, #4*5
514 b 1b
515
516/*
517 * Table for cache operations. This is basically:
518 * - CPU ID match
519 * - CPU ID mask
520 * - 'cache on' method instruction
521 * - 'cache off' method instruction
522 * - 'cache flush' method instruction
523 *
524 * We match an entry using: ((real_id ^ match) & mask) == 0
525 *
526 * Writethrough caches generally only need 'on' and 'off'
527 * methods. Writeback caches _must_ have the flush method
528 * defined.
529 */
530 .type proc_types,#object
531proc_types:
532 .word 0x41560600 @ ARM6/610
533 .word 0xffffffe0
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000534 b __arm6_mmu_cache_off @ works, but slow
535 b __arm6_mmu_cache_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 mov pc, lr
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000537@ b __arm6_mmu_cache_on @ untested
538@ b __arm6_mmu_cache_off
539@ b __armv3_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 .word 0x00000000 @ old ARM ID
542 .word 0x0000f000
543 mov pc, lr
544 mov pc, lr
545 mov pc, lr
546
547 .word 0x41007000 @ ARM7/710
548 .word 0xfff8fe00
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000549 b __arm7_mmu_cache_off
550 b __arm7_mmu_cache_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 mov pc, lr
552
553 .word 0x41807200 @ ARM720T (writethrough)
554 .word 0xffffff00
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000555 b __armv4_mmu_cache_on
556 b __armv4_mmu_cache_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 mov pc, lr
558
Hyok S. Choi10c2df62006-03-27 10:21:34 +0100559 .word 0x41007400 @ ARM74x
560 .word 0xff00ff00
561 b __armv3_mpu_cache_on
562 b __armv3_mpu_cache_off
563 b __armv3_mpu_cache_flush
564
565 .word 0x41009400 @ ARM94x
566 .word 0xff00ff00
567 b __armv4_mpu_cache_on
568 b __armv4_mpu_cache_off
569 b __armv4_mpu_cache_flush
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .word 0x00007000 @ ARM7 IDs
572 .word 0x0000f000
573 mov pc, lr
574 mov pc, lr
575 mov pc, lr
576
577 @ Everything from here on will be the new ID system.
578
579 .word 0x4401a100 @ sa110 / sa1100
580 .word 0xffffffe0
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000581 b __armv4_mmu_cache_on
582 b __armv4_mmu_cache_off
583 b __armv4_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 .word 0x6901b110 @ sa1110
586 .word 0xfffffff0
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000587 b __armv4_mmu_cache_on
588 b __armv4_mmu_cache_off
589 b __armv4_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 @ These match on the architecture ID
592
593 .word 0x00020000 @ ARMv4T
594 .word 0x000f0000
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000595 b __armv4_mmu_cache_on
596 b __armv4_mmu_cache_off
597 b __armv4_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 .word 0x00050000 @ ARMv5TE
600 .word 0x000f0000
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000601 b __armv4_mmu_cache_on
602 b __armv4_mmu_cache_off
603 b __armv4_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 .word 0x00060000 @ ARMv5TEJ
606 .word 0x000f0000
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000607 b __armv4_mmu_cache_on
608 b __armv4_mmu_cache_off
609 b __armv4_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Catalin Marinas45a7b9c2006-06-18 16:21:50 +0100611 .word 0x0007b000 @ ARMv6
612 .word 0x0007f000
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000613 b __armv4_mmu_cache_on
614 b __armv4_mmu_cache_off
615 b __armv6_mmu_cache_flush
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 .word 0 @ unrecognised type
618 .word 0
619 mov pc, lr
620 mov pc, lr
621 mov pc, lr
622
623 .size proc_types, . - proc_types
624
625/*
626 * Turn off the Cache and MMU. ARMv3 does not support
627 * reading the control register, but ARMv4 does.
628 *
629 * On entry, r6 = processor ID
630 * On exit, r0, r1, r2, r3, r12 corrupted
631 * This routine must preserve: r4, r6, r7
632 */
633 .align 5
634cache_off: mov r3, #12 @ cache_off function
635 b call_cache_fn
636
Hyok S. Choi10c2df62006-03-27 10:21:34 +0100637__armv4_mpu_cache_off:
638 mrc p15, 0, r0, c1, c0
639 bic r0, r0, #0x000d
640 mcr p15, 0, r0, c1, c0 @ turn MPU and cache off
641 mov r0, #0
642 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
643 mcr p15, 0, r0, c7, c6, 0 @ flush D-Cache
644 mcr p15, 0, r0, c7, c5, 0 @ flush I-Cache
645 mov pc, lr
646
647__armv3_mpu_cache_off:
648 mrc p15, 0, r0, c1, c0
649 bic r0, r0, #0x000d
650 mcr p15, 0, r0, c1, c0, 0 @ turn MPU and cache off
651 mov r0, #0
652 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
653 mov pc, lr
654
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000655__armv4_mmu_cache_off:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 mrc p15, 0, r0, c1, c0
657 bic r0, r0, #0x000d
658 mcr p15, 0, r0, c1, c0 @ turn MMU and cache off
659 mov r0, #0
660 mcr p15, 0, r0, c7, c7 @ invalidate whole cache v4
661 mcr p15, 0, r0, c8, c7 @ invalidate whole TLB v4
662 mov pc, lr
663
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000664__arm6_mmu_cache_off:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 mov r0, #0x00000030 @ ARM6 control reg.
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000666 b __armv3_mmu_cache_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000668__arm7_mmu_cache_off:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 mov r0, #0x00000070 @ ARM7 control reg.
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000670 b __armv3_mmu_cache_off
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000672__armv3_mmu_cache_off:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 mcr p15, 0, r0, c1, c0, 0 @ turn MMU and cache off
674 mov r0, #0
675 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
676 mcr p15, 0, r0, c5, c0, 0 @ invalidate whole TLB v3
677 mov pc, lr
678
679/*
680 * Clean and flush the cache to maintain consistency.
681 *
682 * On entry,
683 * r6 = processor ID
684 * On exit,
685 * r1, r2, r3, r11, r12 corrupted
686 * This routine must preserve:
687 * r0, r4, r5, r6, r7
688 */
689 .align 5
690cache_clean_flush:
691 mov r3, #16
692 b call_cache_fn
693
Hyok S. Choi10c2df62006-03-27 10:21:34 +0100694__armv4_mpu_cache_flush:
695 mov r2, #1
696 mov r3, #0
697 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
698 mov r1, #7 << 5 @ 8 segments
6991: orr r3, r1, #63 << 26 @ 64 entries
7002: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
701 subs r3, r3, #1 << 26
702 bcs 2b @ entries 63 to 0
703 subs r1, r1, #1 << 5
704 bcs 1b @ segments 7 to 0
705
706 teq r2, #0
707 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
708 mcr p15, 0, ip, c7, c10, 4 @ drain WB
709 mov pc, lr
710
711
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000712__armv6_mmu_cache_flush:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 mov r1, #0
714 mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D
715 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
716 mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
717 mcr p15, 0, r1, c7, c10, 4 @ drain WB
718 mov pc, lr
719
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000720__armv4_mmu_cache_flush:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 mov r2, #64*1024 @ default: 32K dcache size (*2)
722 mov r11, #32 @ default: 32 byte line size
723 mrc p15, 0, r3, c0, c0, 1 @ read cache type
724 teq r3, r6 @ cache ID register present?
725 beq no_cache_id
726 mov r1, r3, lsr #18
727 and r1, r1, #7
728 mov r2, #1024
729 mov r2, r2, lsl r1 @ base dcache size *2
730 tst r3, #1 << 14 @ test M bit
731 addne r2, r2, r2, lsr #1 @ +1/2 size if M == 1
732 mov r3, r3, lsr #12
733 and r3, r3, #3
734 mov r11, #8
735 mov r11, r11, lsl r3 @ cache line size in bytes
736no_cache_id:
737 bic r1, pc, #63 @ align to longest cache line
738 add r2, r1, r2
7391: ldr r3, [r1], r11 @ s/w flush D cache
740 teq r1, r2
741 bne 1b
742
743 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
744 mcr p15, 0, r1, c7, c6, 0 @ flush D cache
745 mcr p15, 0, r1, c7, c10, 4 @ drain WB
746 mov pc, lr
747
Hyok S. Choic76b6b42006-03-24 09:53:18 +0000748__armv3_mmu_cache_flush:
Hyok S. Choi10c2df62006-03-27 10:21:34 +0100749__armv3_mpu_cache_flush:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 mov r1, #0
751 mcr p15, 0, r0, c7, c0, 0 @ invalidate whole cache v3
752 mov pc, lr
753
754/*
755 * Various debugging routines for printing hex characters and
756 * memory, which again must be relocatable.
757 */
758#ifdef DEBUG
759 .type phexbuf,#object
760phexbuf: .space 12
761 .size phexbuf, . - phexbuf
762
763phex: adr r3, phexbuf
764 mov r2, #0
765 strb r2, [r3, r1]
7661: subs r1, r1, #1
767 movmi r0, r3
768 bmi puts
769 and r2, r0, #15
770 mov r0, r0, lsr #4
771 cmp r2, #10
772 addge r2, r2, #7
773 add r2, r2, #'0'
774 strb r2, [r3, r1]
775 b 1b
776
777puts: loadsp r3
7781: ldrb r2, [r0], #1
779 teq r2, #0
780 moveq pc, lr
Russell King5cd0c342005-05-03 12:18:46 +01007812: writeb r2, r3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 mov r1, #0x00020000
7833: subs r1, r1, #1
784 bne 3b
785 teq r2, #'\n'
786 moveq r2, #'\r'
787 beq 2b
788 teq r0, #0
789 bne 1b
790 mov pc, lr
791putc:
792 mov r2, r0
793 mov r0, #0
794 loadsp r3
795 b 2b
796
797memdump: mov r12, r0
798 mov r10, lr
799 mov r11, #0
8002: mov r0, r11, lsl #2
801 add r0, r0, r12
802 mov r1, #8
803 bl phex
804 mov r0, #':'
805 bl putc
8061: mov r0, #' '
807 bl putc
808 ldr r0, [r12, r11, lsl #2]
809 mov r1, #8
810 bl phex
811 and r0, r11, #7
812 teq r0, #3
813 moveq r0, #' '
814 bleq putc
815 and r0, r11, #7
816 add r11, r11, #1
817 teq r0, #7
818 bne 1b
819 mov r0, #'\n'
820 bl putc
821 cmp r11, #64
822 blt 2b
823 mov pc, r10
824#endif
825
826reloc_end:
827
828 .align
829 .section ".stack", "w"
830user_stack: .space 4096