^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * relocate_kernel.S - put the kernel image in place to boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * 2005.9.17 kogiidena@eggplant.ddo.jp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * LANDISK/sh4 is supported. Maybe, SH archtecture works well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * 2009-03-18 Magnus Damm - Added Kexec Jump support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) .globl relocate_new_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) relocate_new_kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* r4 = indirection_page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* r5 = reboot_code_buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* r6 = start_address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) mov.l 10f, r0 /* PAGE_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) add r5, r0 /* setup new stack at end of control page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* save r15->r8 to new stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) mov.l r15, @-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) mov r0, r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) mov.l r14, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) mov.l r13, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) mov.l r12, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) mov.l r11, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) mov.l r10, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) mov.l r9, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) mov.l r8, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* save other random registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) sts.l macl, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) sts.l mach, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) stc.l gbr, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) stc.l ssr, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) stc.l sr, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) sts.l pr, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) stc.l spc, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* switch to bank1 and save r7->r0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) mov.l 12f, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) stc sr, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) or r9, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ldc r8, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mov.l r7, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mov.l r6, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) mov.l r5, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) mov.l r4, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) mov.l r3, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) mov.l r2, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) mov.l r1, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) mov.l r0, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* switch to bank0 and save r7->r0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) mov.l 12f, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) not r9, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) stc sr, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) and r9, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ldc r8, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) mov.l r7, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) mov.l r6, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) mov.l r5, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) mov.l r4, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) mov.l r3, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) mov.l r2, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) mov.l r1, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) mov.l r0, @-r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mov.l r4, @-r15 /* save indirection page again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) bsr swap_pages /* swap pages before jumping to new kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mova 11f, r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mov.l r15, @r0 /* save pointer to stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) jsr @r6 /* hand over control to new kernel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) mov.l 11f, r15 /* get pointer to stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) mov.l @r15+, r4 /* restore r4 to get indirection page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) bsr swap_pages /* swap pages back to previous state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* make sure bank0 is active and restore r0->r7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) mov.l 12f, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) not r9, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) stc sr, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) and r9, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ldc r8, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) mov.l @r15+, r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) mov.l @r15+, r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mov.l @r15+, r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) mov.l @r15+, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) mov.l @r15+, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) mov.l @r15+, r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mov.l @r15+, r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) mov.l @r15+, r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* switch to bank1 and restore r0->r7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) mov.l 12f, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) stc sr, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) or r9, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ldc r8, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) mov.l @r15+, r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mov.l @r15+, r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) mov.l @r15+, r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mov.l @r15+, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) mov.l @r15+, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) mov.l @r15+, r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) mov.l @r15+, r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) mov.l @r15+, r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* switch back to bank0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) mov.l 12f, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) not r9, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) stc sr, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) and r9, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ldc r8, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* restore other random registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ldc.l @r15+, spc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) lds.l @r15+, pr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ldc.l @r15+, sr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ldc.l @r15+, ssr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ldc.l @r15+, gbr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) lds.l @r15+, mach
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) lds.l @r15+, macl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* restore r8->r15 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) mov.l @r15+, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) mov.l @r15+, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) mov.l @r15+, r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) mov.l @r15+, r11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mov.l @r15+, r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mov.l @r15+, r13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mov.l @r15+, r14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) mov.l @r15+, r15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) rts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) swap_pages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) bra 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) mov r4,r0 /* cmd = indirection_page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) mov.l @r4+,r0 /* cmd = *ind++ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 1: /* addr = cmd & 0xfffffff0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) mov r0,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) mov #-16,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) and r1,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* if(cmd & IND_DESTINATION) dst = addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) tst #1,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) bt 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) bra 0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) mov r2,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 2: /* else if(cmd & IND_INDIRECTION) ind = addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) tst #2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) bt 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) bra 0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mov r2,r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 3: /* else if(cmd & IND_DONE) return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) tst #4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) bt 4f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) rts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 4: /* else if(cmd & IND_SOURCE) memcpy(dst,addr,PAGE_SIZE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) tst #8,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) bt 0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) mov.l 10f,r3 /* PAGE_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) shlr2 r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) shlr2 r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dt r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* regular kexec just overwrites the destination page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * with the contents of the source page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * for the kexec jump case we need to swap the contents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * of the pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * to keep it simple swap the contents for both cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) mov.l @(0, r2), r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) mov.l @(0, r5), r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) mov.l r8, @(0, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mov.l r1, @(0, r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) mov.l @(4, r2), r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) mov.l @(4, r5), r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) mov.l r8, @(4, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) mov.l r1, @(4, r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) mov.l @(8, r2), r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) mov.l @(8, r5), r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) mov.l r8, @(8, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) mov.l r1, @(8, r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) mov.l @(12, r2), r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) mov.l @(12, r5), r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) mov.l r8, @(12, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mov.l r1, @(12, r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) add #16,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) add #16,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) bf 5b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) bra 0b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .align 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .long PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .long 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .long 0x20000000 ! RB=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) relocate_new_kernel_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .globl relocate_new_kernel_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) relocate_new_kernel_size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .long relocate_new_kernel_end - relocate_new_kernel