[ARM] Allow r2 to be passed through the decompressor to the kernel

This is part of a patch from Marc Singer to allow r2 to be
passed to the kernel. Marc's original comments follow:

This revised R2 (atags pointer) patch incorporates comments from Nico
Pitre and Ben Dooks. It modifies the head.S files such that the R2
value set by the bootloader is conveyed to the kernel startup code.
The kernel head.S heuristically validates the pointer. It will set R2
to zero if it believes the pointer is invalid. Presently, it requires
that the ATAGS list reside in the first 16KiB of physical RAM.
Relaxing this contraint may be both desirable as well as tricky.

Signed-off-by: Marc Singer <elf@buici.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by Russell King and committed by Russell King f4619025 90303b10

+25 -21
+25 -21
arch/arm/boot/compressed/head.S
··· 84 kputc #'\n' 85 kphex r5, 8 /* decompressed kernel start */ 86 kputc #'-' 87 - kphex r8, 8 /* decompressed kernel end */ 88 kputc #'>' 89 kphex r4, 8 /* kernel execution address */ 90 kputc #'\n' ··· 116 .word start @ absolute load/run zImage address 117 .word _edata @ zImage end address 118 1: mov r7, r1 @ save architecture ID 119 - mov r8, #0 @ save r0 120 121 #ifndef __ARM_ARCH_2__ 122 /* ··· 144 145 /* 146 * some architecture specific code can be inserted 147 - * by the linker here, but it should preserve r7 and r8. 148 */ 149 150 .text ··· 249 * r5 = decompressed kernel start 250 * r6 = processor ID 251 * r7 = architecture ID 252 - * r8-r14 = unused 253 */ 254 add r1, r5, r0 @ end of decompressed kernel 255 adr r2, reloc_start 256 ldr r3, LC1 257 add r3, r2, r3 258 - 1: ldmia r2!, {r8 - r13} @ copy relocation code 259 - stmia r1!, {r8 - r13} 260 - ldmia r2!, {r8 - r13} 261 - stmia r1!, {r8 - r13} 262 cmp r2, r3 263 blo 1b 264 ··· 309 * r4 = kernel execution address 310 * r6 = processor ID 311 * r7 = architecture number 312 - * r8 = run-time address of "start" 313 * On exit, 314 - * r1, r2, r3, r8, r9, r12 corrupted 315 * This routine must preserve: 316 - * r4, r5, r6, r7 317 */ 318 .align 5 319 cache_on: mov r3, #8 @ cache_on function ··· 328 * bits for the RAM area only. 329 */ 330 mov r0, r3 331 - mov r8, r0, lsr #18 332 - mov r8, r8, lsl #18 @ start of RAM 333 - add r9, r8, #0x10000000 @ a reasonable RAM size 334 mov r1, #0x12 335 orr r1, r1, #3 << 10 336 add r2, r3, #16384 337 1: cmp r1, r8 @ if virt > start of RAM 338 orrhs r1, r1, #0x0c @ set cacheable, bufferable 339 - cmp r1, r9 @ if virt > end of RAM 340 bichs r1, r1, #0x0c @ clear cacheable, bufferable 341 str r1, [r0], #4 @ 1:1 mapping 342 add r1, r1, #1048576 ··· 405 * r5 = decompressed kernel start 406 * r6 = processor ID 407 * r7 = architecture ID 408 - * r8-r14 = unused 409 */ 410 .align 5 411 - reloc_start: add r8, r5, r0 412 debug_reloc_start 413 mov r1, r4 414 1: 415 .rept 4 416 - ldmia r5!, {r0, r2, r3, r9 - r13} @ relocate kernel 417 - stmia r1!, {r0, r2, r3, r9 - r13} 418 .endr 419 420 - cmp r5, r8 421 blo 1b 422 debug_reloc_end 423 424 call_kernel: bl cache_clean_flush 425 bl cache_off 426 - mov r0, #0 427 mov r1, r7 @ restore architecture number 428 mov pc, r4 @ call kernel 429 430 /*
··· 84 kputc #'\n' 85 kphex r5, 8 /* decompressed kernel start */ 86 kputc #'-' 87 + kphex r9, 8 /* decompressed kernel end */ 88 kputc #'>' 89 kphex r4, 8 /* kernel execution address */ 90 kputc #'\n' ··· 116 .word start @ absolute load/run zImage address 117 .word _edata @ zImage end address 118 1: mov r7, r1 @ save architecture ID 119 + mov r8, r2 @ save atags pointer 120 121 #ifndef __ARM_ARCH_2__ 122 /* ··· 144 145 /* 146 * some architecture specific code can be inserted 147 + * by the linker here, but it should preserve r7, r8, and r9. 148 */ 149 150 .text ··· 249 * r5 = decompressed kernel start 250 * r6 = processor ID 251 * r7 = architecture ID 252 + * r8 = atags pointer 253 + * r9-r14 = corrupted 254 */ 255 add r1, r5, r0 @ end of decompressed kernel 256 adr r2, reloc_start 257 ldr r3, LC1 258 add r3, r2, r3 259 + 1: ldmia r2!, {r9 - r14} @ copy relocation code 260 + stmia r1!, {r9 - r14} 261 + ldmia r2!, {r9 - r14} 262 + stmia r1!, {r9 - r14} 263 cmp r2, r3 264 blo 1b 265 ··· 308 * r4 = kernel execution address 309 * r6 = processor ID 310 * r7 = architecture number 311 + * r8 = atags pointer 312 + * r9 = run-time address of "start" (???) 313 * On exit, 314 + * r1, r2, r3, r9, r10, r12 corrupted 315 * This routine must preserve: 316 + * r4, r5, r6, r7, r8 317 */ 318 .align 5 319 cache_on: mov r3, #8 @ cache_on function ··· 326 * bits for the RAM area only. 327 */ 328 mov r0, r3 329 + mov r9, r0, lsr #18 330 + mov r9, r9, lsl #18 @ start of RAM 331 + add r10, r9, #0x10000000 @ a reasonable RAM size 332 mov r1, #0x12 333 orr r1, r1, #3 << 10 334 add r2, r3, #16384 335 1: cmp r1, r8 @ if virt > start of RAM 336 orrhs r1, r1, #0x0c @ set cacheable, bufferable 337 + cmp r1, r10 @ if virt > end of RAM 338 bichs r1, r1, #0x0c @ clear cacheable, bufferable 339 str r1, [r0], #4 @ 1:1 mapping 340 add r1, r1, #1048576 ··· 403 * r5 = decompressed kernel start 404 * r6 = processor ID 405 * r7 = architecture ID 406 + * r8 = atags pointer 407 + * r9-r14 = corrupted 408 */ 409 .align 5 410 + reloc_start: add r9, r5, r0 411 debug_reloc_start 412 mov r1, r4 413 1: 414 .rept 4 415 + ldmia r5!, {r0, r2, r3, r10 - r14} @ relocate kernel 416 + stmia r1!, {r0, r2, r3, r10 - r14} 417 .endr 418 419 + cmp r5, r9 420 blo 1b 421 debug_reloc_end 422 423 call_kernel: bl cache_clean_flush 424 bl cache_off 425 + mov r0, #0 @ must be zero 426 mov r1, r7 @ restore architecture number 427 + mov r2, r8 @ restore atags pointer 428 mov pc, r4 @ call kernel 429 430 /*