Skip to content

Commit e31aa45

Browse files
committed
powerpc: Use LOAD_REG_IMMEDIATE only for constants on 64-bit
Using LOAD_REG_IMMEDIATE to get the address of kernel symbols generates 5 instructions where LOAD_REG_ADDR can do it in one, and will generate R_PPC64_ADDR16_* relocations in the output when we get to making the kernel as a position-independent executable, which we'd rather not have to handle. This changes various bits of assembly code to use LOAD_REG_ADDR when we need to get the address of a symbol, or to use suitable position-independent code for cases where we can't access the TOC for various reasons, or if we're not running at the address we were linked at. It also cleans up a few minor things; there's no reason to save and restore SRR0/1 around RTAS calls, __mmu_off can get the return address from LR more conveniently than the caller can supply it in R4 (and we already assume elsewhere that EA == RA if the MMU is on in early boot), and enable_64b_mode was using 5 instructions where 2 would do. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 1f6a93e commit e31aa45

6 files changed

Lines changed: 110 additions & 126 deletions

File tree

‎arch/powerpc/include/asm/ppc_asm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ GLUE(.,name):
268268
* Loads the value of the constant expression 'expr' into register 'rn'
269269
* using immediate instructions only. Use this when it's important not
270270
* to reference other data (i.e. on ppc64 when the TOC pointer is not
271-
* valid).
271+
* valid) and when 'expr' is a constant or absolute address.
272272
*
273273
* LOAD_REG_ADDR(rn, name)
274274
* Loads the address of label 'name' into register 'rn'. Use this when

‎arch/powerpc/kernel/cpu_setup_ppc970.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ load_hids:
110110
isync
111111

112112
/* Save away cpu state */
113-
LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
113+
LOAD_REG_ADDR(r5,cpu_state_storage)
114114

115115
/* Save HID0,1,4 and 5 */
116116
mfspr r3,SPRN_HID0
@@ -134,7 +134,7 @@ _GLOBAL(__restore_cpu_ppc970)
134134
rldicl. r0,r0,4,63
135135
beqlr
136136

137-
LOAD_REG_IMMEDIATE(r5,cpu_state_storage)
137+
LOAD_REG_ADDR(r5,cpu_state_storage)
138138
/* Before accessing memory, we make sure rm_ci is clear */
139139
li r0,0
140140
mfspr r3,SPRN_HID4

‎arch/powerpc/kernel/entry_64.S‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,6 @@ _GLOBAL(enter_rtas)
690690
std r7,_DAR(r1)
691691
mfdsisr r8
692692
std r8,_DSISR(r1)
693-
mfsrr0 r9
694-
std r9,_SRR0(r1)
695-
mfsrr1 r10
696-
std r10,_SRR1(r1)
697693

698694
/* Temporary workaround to clear CR until RTAS can be modified to
699695
* ignore all bits.
@@ -754,21 +750,27 @@ _STATIC(rtas_return_loc)
754750
mfspr r4,SPRN_SPRG3 /* Get PACA */
755751
clrldi r4,r4,2 /* convert to realmode address */
756752

753+
bcl 20,31,$+4
754+
0: mflr r3
755+
ld r3,(1f-0b)(r3) /* get &.rtas_restore_regs */
756+
757757
mfmsr r6
758758
li r0,MSR_RI
759759
andc r6,r6,r0
760760
sync
761761
mtmsrd r6
762762

763763
ld r1,PACAR1(r4) /* Restore our SP */
764-
LOAD_REG_IMMEDIATE(r3,.rtas_restore_regs)
765764
ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
766765

767766
mtspr SPRN_SRR0,r3
768767
mtspr SPRN_SRR1,r4
769768
rfid
770769
b . /* prevent speculative execution */
771770

771+
.align 3
772+
1: .llong .rtas_restore_regs
773+
772774
_STATIC(rtas_restore_regs)
773775
/* relocation is on at this point */
774776
REST_GPR(2, r1) /* Restore the TOC */
@@ -788,10 +790,6 @@ _STATIC(rtas_restore_regs)
788790
mtdar r7
789791
ld r8,_DSISR(r1)
790792
mtdsisr r8
791-
ld r9,_SRR0(r1)
792-
mtsrr0 r9
793-
ld r10,_SRR1(r1)
794-
mtsrr1 r10
795793

796794
addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
797795
ld r0,16(r1) /* get return address */

0 commit comments

Comments
 (0)