Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * relocate_kernel.S - put the kernel image in place to boot |
| 4 | */ |
| 5 | |
Dave Martin | e2ccba4 | 2013-11-25 14:54:47 +0100 | [diff] [blame] | 6 | #include <linux/linkage.h> |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 7 | #include <asm/assembler.h> |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 8 | #include <asm/kexec.h> |
| 9 | |
Dave Martin | e2ccba4 | 2013-11-25 14:54:47 +0100 | [diff] [blame] | 10 | .align 3 /* not needed for this code, but keeps fncpy() happy */ |
| 11 | |
| 12 | ENTRY(relocate_new_kernel) |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 13 | |
| 14 | ldr r0,kexec_indirection_page |
| 15 | ldr r1,kexec_start_address |
| 16 | |
Mika Westerberg | 8594a0c | 2010-05-10 09:24:53 +0100 | [diff] [blame] | 17 | /* |
| 18 | * If there is no indirection page (we are doing crashdumps) |
| 19 | * skip any relocation. |
| 20 | */ |
| 21 | cmp r0, #0 |
| 22 | beq 2f |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 23 | |
| 24 | 0: /* top, read another word for the indirection page */ |
| 25 | ldr r3, [r0],#4 |
| 26 | |
| 27 | /* Is it a destination page. Put destination address to r4 */ |
| 28 | tst r3,#1,0 |
| 29 | beq 1f |
| 30 | bic r4,r3,#1 |
| 31 | b 0b |
| 32 | 1: |
| 33 | /* Is it an indirection page */ |
| 34 | tst r3,#2,0 |
| 35 | beq 1f |
| 36 | bic r0,r3,#2 |
| 37 | b 0b |
| 38 | 1: |
| 39 | |
| 40 | /* are we done ? */ |
| 41 | tst r3,#4,0 |
| 42 | beq 1f |
| 43 | b 2f |
| 44 | |
| 45 | 1: |
| 46 | /* is it source ? */ |
| 47 | tst r3,#8,0 |
| 48 | beq 0b |
| 49 | bic r3,r3,#8 |
| 50 | mov r6,#1024 |
| 51 | 9: |
| 52 | ldr r5,[r3],#4 |
| 53 | str r5,[r4],#4 |
| 54 | subs r6,r6,#1 |
| 55 | bne 9b |
| 56 | b 0b |
| 57 | |
| 58 | 2: |
| 59 | /* Jump to relocated kernel */ |
| 60 | mov lr,r1 |
| 61 | mov r0,#0 |
| 62 | ldr r1,kexec_mach_type |
Richard Purdie | 4cd9d6f | 2008-01-02 00:56:46 +0100 | [diff] [blame] | 63 | ldr r2,kexec_boot_atags |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 64 | ARM( ret lr ) |
Will Deacon | 552e0c8 | 2011-08-26 16:32:57 +0100 | [diff] [blame] | 65 | THUMB( bx lr ) |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 66 | |
Dave Martin | bc8b57f | 2010-11-29 19:43:21 +0100 | [diff] [blame] | 67 | .align |
| 68 | |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 69 | .globl kexec_start_address |
| 70 | kexec_start_address: |
| 71 | .long 0x0 |
| 72 | |
| 73 | .globl kexec_indirection_page |
| 74 | kexec_indirection_page: |
| 75 | .long 0x0 |
| 76 | |
| 77 | .globl kexec_mach_type |
| 78 | kexec_mach_type: |
| 79 | .long 0x0 |
| 80 | |
Richard Purdie | 4cd9d6f | 2008-01-02 00:56:46 +0100 | [diff] [blame] | 81 | /* phy addr of the atags for the new kernel */ |
| 82 | .globl kexec_boot_atags |
| 83 | kexec_boot_atags: |
Mike Westerhof | 033b8ff | 2007-10-11 03:18:14 +0100 | [diff] [blame] | 84 | .long 0x0 |
| 85 | |
Dave Martin | e2ccba4 | 2013-11-25 14:54:47 +0100 | [diff] [blame] | 86 | ENDPROC(relocate_new_kernel) |
| 87 | |
Richard Purdie | c587e4a | 2007-02-06 21:29:00 +0100 | [diff] [blame] | 88 | relocate_new_kernel_end: |
| 89 | |
| 90 | .globl relocate_new_kernel_size |
| 91 | relocate_new_kernel_size: |
| 92 | .long relocate_new_kernel_end - relocate_new_kernel |
| 93 | |
| 94 | |