powerpc/module64: Use symbolic instructions names.
To increase readability/maintainability, replace hard coded instructions values by symbolic names. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> [mpe: Fix R_PPC64_ENTRY case, the addi reads from r2 not r12] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:
parent
4eb4516ead
commit
a2b6f26c26
|
@ -133,20 +133,27 @@ struct ppc64_stub_entry
|
||||||
* the stub, but it's significantly shorter to put these values at the
|
* the stub, but it's significantly shorter to put these values at the
|
||||||
* end of the stub code, and patch the stub address (32-bits relative
|
* end of the stub code, and patch the stub address (32-bits relative
|
||||||
* to the TOC ptr, r2) into the stub.
|
* to the TOC ptr, r2) into the stub.
|
||||||
|
*
|
||||||
|
* addis r11,r2, <high>
|
||||||
|
* addi r11,r11, <low>
|
||||||
|
* std r2,R2_STACK_OFFSET(r1)
|
||||||
|
* ld r12,32(r11)
|
||||||
|
* ld r2,40(r11)
|
||||||
|
* mtctr r12
|
||||||
|
* bctr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static u32 ppc64_stub_insns[] = {
|
static u32 ppc64_stub_insns[] = {
|
||||||
0x3d620000, /* addis r11,r2, <high> */
|
PPC_INST_ADDIS | __PPC_RT(R11) | __PPC_RA(R2),
|
||||||
0x396b0000, /* addi r11,r11, <low> */
|
PPC_INST_ADDI | __PPC_RT(R11) | __PPC_RA(R11),
|
||||||
/* Save current r2 value in magic place on the stack. */
|
/* Save current r2 value in magic place on the stack. */
|
||||||
0xf8410000|R2_STACK_OFFSET, /* std r2,R2_STACK_OFFSET(r1) */
|
PPC_INST_STD | __PPC_RS(R2) | __PPC_RA(R1) | R2_STACK_OFFSET,
|
||||||
0xe98b0020, /* ld r12,32(r11) */
|
PPC_INST_LD | __PPC_RT(R12) | __PPC_RA(R11) | 32,
|
||||||
#ifdef PPC64_ELF_ABI_v1
|
#ifdef PPC64_ELF_ABI_v1
|
||||||
/* Set up new r2 from function descriptor */
|
/* Set up new r2 from function descriptor */
|
||||||
0xe84b0028, /* ld r2,40(r11) */
|
PPC_INST_LD | __PPC_RT(R2) | __PPC_RA(R11) | 40,
|
||||||
#endif
|
#endif
|
||||||
0x7d8903a6, /* mtctr r12 */
|
PPC_INST_MTCTR | __PPC_RS(R12),
|
||||||
0x4e800420 /* bctr */
|
PPC_INST_BCTR,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef CONFIG_DYNAMIC_FTRACE
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
||||||
|
@ -704,18 +711,21 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
|
||||||
* ld r2, ...(r12)
|
* ld r2, ...(r12)
|
||||||
* add r2, r2, r12
|
* add r2, r2, r12
|
||||||
*/
|
*/
|
||||||
if ((((uint32_t *)location)[0] & ~0xfffc)
|
if ((((uint32_t *)location)[0] & ~0xfffc) !=
|
||||||
!= 0xe84c0000)
|
(PPC_INST_LD | __PPC_RT(R2) | __PPC_RA(R12)))
|
||||||
break;
|
break;
|
||||||
if (((uint32_t *)location)[1] != 0x7c426214)
|
if (((uint32_t *)location)[1] !=
|
||||||
|
(PPC_INST_ADD | __PPC_RT(R2) | __PPC_RA(R2) | __PPC_RB(R12)))
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* If found, replace it with:
|
* If found, replace it with:
|
||||||
* addis r2, r12, (.TOC.-func)@ha
|
* addis r2, r12, (.TOC.-func)@ha
|
||||||
* addi r2, r2, (.TOC.-func)@l
|
* addi r2, r2, (.TOC.-func)@l
|
||||||
*/
|
*/
|
||||||
((uint32_t *)location)[0] = 0x3c4c0000 + PPC_HA(value);
|
((uint32_t *)location)[0] = PPC_INST_ADDIS | __PPC_RT(R2) |
|
||||||
((uint32_t *)location)[1] = 0x38420000 + PPC_LO(value);
|
__PPC_RA(R12) | PPC_HA(value);
|
||||||
|
((uint32_t *)location)[1] = PPC_INST_ADDI | __PPC_RT(R2) |
|
||||||
|
__PPC_RA(R2) | PPC_LO(value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_PPC64_REL16_HA:
|
case R_PPC64_REL16_HA:
|
||||||
|
@ -769,12 +779,19 @@ static unsigned long create_ftrace_stub(const Elf64_Shdr *sechdrs,
|
||||||
{
|
{
|
||||||
struct ppc64_stub_entry *entry;
|
struct ppc64_stub_entry *entry;
|
||||||
unsigned int i, num_stubs;
|
unsigned int i, num_stubs;
|
||||||
|
/*
|
||||||
|
* ld r12,PACATOC(r13)
|
||||||
|
* addis r12,r12,<high>
|
||||||
|
* addi r12,r12,<low>
|
||||||
|
* mtctr r12
|
||||||
|
* bctr
|
||||||
|
*/
|
||||||
static u32 stub_insns[] = {
|
static u32 stub_insns[] = {
|
||||||
0xe98d0000 | PACATOC, /* ld r12,PACATOC(r13) */
|
PPC_INST_LD | __PPC_RT(R12) | __PPC_RA(R13) | PACATOC,
|
||||||
0x3d8c0000, /* addis r12,r12,<high> */
|
PPC_INST_ADDIS | __PPC_RT(R12) | __PPC_RA(R12),
|
||||||
0x398c0000, /* addi r12,r12,<low> */
|
PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12),
|
||||||
0x7d8903a6, /* mtctr r12 */
|
PPC_INST_MTCTR | __PPC_RS(R12),
|
||||||
0x4e800420, /* bctr */
|
PPC_INST_BCTR,
|
||||||
};
|
};
|
||||||
long reladdr;
|
long reladdr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue