^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) Paul Mackerras 1997.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Adapted for 64 bit LE PowerPC by Andrew Tauferner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "ppc_asm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) RELA = 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) RELACOUNT = 0x6ffffff9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) .data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* A procedure descriptor used when booting this as a COFF file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * When making COFF, this comes first in the link and we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * linked at 0x500000.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .globl _zimage_start_opd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) _zimage_start_opd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .long 0x500000, 0, 0, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) b _zimage_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifdef __powerpc64__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .balign 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) p_start: .8byte _start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) p_etext: .8byte _etext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) p_bss_start: .8byte __bss_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) p_end: .8byte _end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) p_toc: .8byte __toc_start + 0x8000 - p_base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) p_dyn: .8byte __dynamic_start - p_base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) p_rela: .8byte __rela_dyn_start - p_base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) p_prom: .8byte 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .weak _platform_stack_top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) p_pstack: .8byte _platform_stack_top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) p_start: .long _start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) p_etext: .long _etext
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) p_bss_start: .long __bss_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) p_end: .long _end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .weak _platform_stack_top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) p_pstack: .long _platform_stack_top
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .weak _zimage_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) _zimage_start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .globl _zimage_start_lib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) _zimage_start_lib:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Work out the offset between the address we were linked at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) and the address where we're running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) bl .+4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) p_base: mflr r10 /* r10 now points to runtime addr of p_base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifndef __powerpc64__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* grab the link address of the dynamic section in r11 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) addis r11,r10,(_GLOBAL_OFFSET_TABLE_-p_base)@ha
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) lwz r11,(_GLOBAL_OFFSET_TABLE_-p_base)@l(r11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) cmpwi r11,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) beq 3f /* if not linked -pie */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* get the runtime address of the dynamic section in r12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .weak __dynamic_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) addis r12,r10,(__dynamic_start-p_base)@ha
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) addi r12,r12,(__dynamic_start-p_base)@l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) subf r11,r11,r12 /* runtime - linktime offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* The dynamic section contains a series of tagged entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * We need the RELA and RELACOUNT entries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) li r9,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) li r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 9: lwz r8,0(r12) /* get tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cmpwi r8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) beq 10f /* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) cmpwi r8,RELA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) bne 11f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) lwz r9,4(r12) /* get RELA pointer in r9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) b 12f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 11: addis r8,r8,(-RELACOUNT)@ha
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) cmpwi r8,RELACOUNT@l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) bne 12f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) lwz r0,4(r12) /* get RELACOUNT value in r0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 12: addi r12,r12,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) b 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* The relocation section contains a list of relocations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * We now do the R_PPC_RELATIVE ones, which point to words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * which need to be initialized with addend + offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * The R_PPC_RELATIVE ones come first and there are RELACOUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * of them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 10: /* skip relocation if we don't have both */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) cmpwi r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) beq 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) cmpwi r9,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) beq 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) add r9,r9,r11 /* Relocate RELA pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) mtctr r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) 2: lbz r0,4+3(r9) /* ELF32_R_INFO(reloc->r_info) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) cmpwi r0,22 /* R_PPC_RELATIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) bne 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) lwz r12,0(r9) /* reloc->r_offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) lwz r0,8(r9) /* reloc->r_addend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) add r0,r0,r11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) stwx r0,r11,r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) addi r9,r9,12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) bdnz 2b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* Do a cache flush for our text, in case the loader didn't */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 3: lwz r9,p_start-p_base(r10) /* note: these are relocated now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) lwz r8,p_etext-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 4: dcbf r0,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) icbi r0,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) addi r9,r9,0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) cmplw cr0,r9,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) blt 4b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) isync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Clear the BSS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) lwz r9,p_bss_start-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) lwz r8,p_end-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) li r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 5: stw r0,0(r9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) addi r9,r9,4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cmplw cr0,r9,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) blt 5b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Possibly set up a custom stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) lwz r8,p_pstack-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) cmpwi r8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) beq 6f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) lwz r1,0(r8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) li r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) stwu r0,-16(r1) /* establish a stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #else /* __powerpc64__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* Save the prom pointer at p_prom. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) std r5,(p_prom-p_base)(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Set r2 to the TOC. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ld r2,(p_toc-p_base)(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) add r2,r2,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Grab the link address of the dynamic section in r11. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ld r11,-32768(r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) cmpwi r11,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) beq 3f /* if not linked -pie then no dynamic section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ld r11,(p_dyn-p_base)(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) add r11,r11,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ld r9,(p_rela-p_base)(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) add r9,r9,r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) li r13,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) li r8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 9: ld r12,0(r11) /* get tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) cmpdi r12,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) beq 12f /* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) cmpdi r12,RELA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) bne 10f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ld r13,8(r11) /* get RELA pointer in r13 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) b 11f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 10: addis r12,r12,(-RELACOUNT)@ha
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cmpdi r12,RELACOUNT@l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) bne 11f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ld r8,8(r11) /* get RELACOUNT value in r8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 11: addi r11,r11,16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) b 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cmpdi r13,0 /* check we have both RELA and RELACOUNT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cmpdi cr1,r8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) beq 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) beq cr1,3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* Calcuate the runtime offset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) subf r13,r13,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* Run through the list of relocations and process the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * R_PPC64_RELATIVE ones. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) mtctr r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 13: ld r0,8(r9) /* ELF64_R_TYPE(reloc->r_info) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) cmpdi r0,22 /* R_PPC64_RELATIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) bne 3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) ld r12,0(r9) /* reloc->r_offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ld r0,16(r9) /* reloc->r_addend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) add r0,r0,r13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) stdx r0,r13,r12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) addi r9,r9,24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bdnz 13b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* Do a cache flush for our text, in case the loader didn't */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 3: ld r9,p_start-p_base(r10) /* note: these are relocated now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ld r8,p_etext-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 4: dcbf r0,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) icbi r0,r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) addi r9,r9,0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) cmpld cr0,r9,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) blt 4b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) isync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Clear the BSS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ld r9,p_bss_start-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ld r8,p_end-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) li r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 5: std r0,0(r9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) addi r9,r9,8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) cmpld cr0,r9,r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) blt 5b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* Possibly set up a custom stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ld r8,p_pstack-p_base(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) cmpdi r8,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) beq 6f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ld r1,0(r8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) li r0,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) stdu r0,-112(r1) /* establish a stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #endif /* __powerpc64__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* Call platform_init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bl platform_init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Call start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) b start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #ifdef __powerpc64__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define PROM_FRAME_SIZE 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #define SAVE_GPR(n, base) std n,8*(n)(base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #define REST_GPR(n, base) ld n,8*(n)(base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define SAVE_2GPRS(n, base) SAVE_GPR(n, base); SAVE_GPR(n+1, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) #define SAVE_4GPRS(n, base) SAVE_2GPRS(n, base); SAVE_2GPRS(n+2, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define SAVE_8GPRS(n, base) SAVE_4GPRS(n, base); SAVE_4GPRS(n+4, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define SAVE_10GPRS(n, base) SAVE_8GPRS(n, base); SAVE_2GPRS(n+8, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define REST_2GPRS(n, base) REST_GPR(n, base); REST_GPR(n+1, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define REST_4GPRS(n, base) REST_2GPRS(n, base); REST_2GPRS(n+2, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define REST_8GPRS(n, base) REST_4GPRS(n, base); REST_4GPRS(n+4, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define REST_10GPRS(n, base) REST_8GPRS(n, base); REST_2GPRS(n+8, base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* prom handles the jump into and return from firmware. The prom args pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) is loaded in r3. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .globl prom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) prom:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) mflr r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) std r0,16(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) SAVE_GPR(2, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) SAVE_GPR(13, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) SAVE_8GPRS(14, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) SAVE_10GPRS(22, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) mfcr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) std r10,8*32(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) mfmsr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) std r10,8*33(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* remove MSR_LE from msr but keep MSR_SF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) mfmsr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) rldicr r10,r10,0,62
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) mtsrr1 r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Load FW address, set LR to label 1, and jump to FW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bl 0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 0: mflr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) addi r11,r10,(1f-0b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) mtlr r11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ld r10,(p_prom-0b)(r10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) mtsrr0 r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) rfid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 1: /* Return from OF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) FIXUP_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Restore registers and return. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) rldicl r1,r1,0,32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Restore the MSR (back to 64 bits) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ld r10,8*(33)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) mtmsr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) isync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Restore other registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) REST_GPR(2, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) REST_GPR(13, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) REST_8GPRS(14, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) REST_10GPRS(22, r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ld r10,8*32(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) mtcr r10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) addi r1,r1,PROM_FRAME_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ld r0,16(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) mtlr r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #endif