2019-04-29 10:44:48

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH 2/3] powerpc/module32: Use symbolic instructions names.

To increase readability/maintainability, replace hard coded
instructions values by symbolic names.

Signed-off-by: Christophe Leroy <[email protected]>
---
arch/powerpc/kernel/module_32.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
index 88d83771f462..c5197f856c75 100644
--- a/arch/powerpc/kernel/module_32.c
+++ b/arch/powerpc/kernel/module_32.c
@@ -170,10 +170,14 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
return 0;
}

+ /* lis r12,sym@ha */
+#define ENTRY_JMP0(sym) (PPC_INST_ADDIS | __PPC_RT(R12) | PPC_HA(sym))
+ /* addi r12,r12,sym@l */
+#define ENTRY_JMP1(sym) (PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12) | PPC_LO(sym))
+
static inline int entry_matches(struct ppc_plt_entry *entry, Elf32_Addr val)
{
- if (entry->jump[0] == 0x3d800000 + ((val + 0x8000) >> 16)
- && entry->jump[1] == 0x398c0000 + (val & 0xffff))
+ if (entry->jump[0] == ENTRY_JMP0(val) && entry->jump[1] == ENTRY_JMP1(val))
return 1;
return 0;
}
@@ -200,10 +204,10 @@ static uint32_t do_plt_call(void *location,
entry++;
}

- entry->jump[0] = 0x3d800000+((val+0x8000)>>16); /* lis r12,sym@ha */
- entry->jump[1] = 0x398c0000 + (val&0xffff); /* addi r12,r12,sym@l*/
- entry->jump[2] = 0x7d8903a6; /* mtctr r12 */
- entry->jump[3] = 0x4e800420; /* bctr */
+ entry->jump[0] = ENTRY_JMP0(val);
+ entry->jump[1] = ENTRY_JMP1(val);
+ entry->jump[2] = PPC_INST_MTCTR | __PPC_RS(R12);
+ entry->jump[3] = PPC_INST_BCTR;

pr_debug("Initialized plt for 0x%x at %p\n", val, entry);
return (uint32_t)entry;
--
2.13.3


2019-04-29 11:56:34

by Segher Boessenkool

[permalink] [raw]
Subject: Re: [PATCH 2/3] powerpc/module32: Use symbolic instructions names.

On Mon, Apr 29, 2019 at 10:43:27AM +0000, Christophe Leroy wrote:
> To increase readability/maintainability, replace hard coded
> instructions values by symbolic names.

> + /* lis r12,sym@ha */
> +#define ENTRY_JMP0(sym) (PPC_INST_ADDIS | __PPC_RT(R12) | PPC_HA(sym))
> + /* addi r12,r12,sym@l */
> +#define ENTRY_JMP1(sym) (PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12) | PPC_LO(sym))

Those aren't "jump" instructions though, as the name suggests... And you
only have names for the first two of the four insns. ("2" and "3" were
still available ;-) )

> - entry->jump[0] = 0x3d800000+((val+0x8000)>>16); /* lis r12,sym@ha */
> - entry->jump[1] = 0x398c0000 + (val&0xffff); /* addi r12,r12,sym@l*/
> - entry->jump[2] = 0x7d8903a6; /* mtctr r12 */
> - entry->jump[3] = 0x4e800420; /* bctr */
> + entry->jump[0] = ENTRY_JMP0(val);
> + entry->jump[1] = ENTRY_JMP1(val);
> + entry->jump[2] = PPC_INST_MTCTR | __PPC_RS(R12);
> + entry->jump[3] = PPC_INST_BCTR;

Deleting the comment here is not an improvement imo.


Segher

2019-05-02 07:26:01

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH 2/3] powerpc/module32: Use symbolic instructions names.



Le 29/04/2019 à 13:54, Segher Boessenkool a écrit :
> On Mon, Apr 29, 2019 at 10:43:27AM +0000, Christophe Leroy wrote:
>> To increase readability/maintainability, replace hard coded
>> instructions values by symbolic names.
>
>> + /* lis r12,sym@ha */
>> +#define ENTRY_JMP0(sym) (PPC_INST_ADDIS | __PPC_RT(R12) | PPC_HA(sym))
>> + /* addi r12,r12,sym@l */
>> +#define ENTRY_JMP1(sym) (PPC_INST_ADDI | __PPC_RT(R12) | __PPC_RA(R12) | PPC_LO(sym))
>
> Those aren't "jump" instructions though, as the name suggests... And you
> only have names for the first two of the four insns. ("2" and "3" were
> still available ;-) )

Well, the idea was to say they are defining the jump destination.
Anyway, as they are used only once, let's put it directly in.

>
>> - entry->jump[0] = 0x3d800000+((val+0x8000)>>16); /* lis r12,sym@ha */
>> - entry->jump[1] = 0x398c0000 + (val&0xffff); /* addi r12,r12,sym@l*/
>> - entry->jump[2] = 0x7d8903a6; /* mtctr r12 */
>> - entry->jump[3] = 0x4e800420; /* bctr */
>> + entry->jump[0] = ENTRY_JMP0(val);
>> + entry->jump[1] = ENTRY_JMP1(val);
>> + entry->jump[2] = PPC_INST_MTCTR | __PPC_RS(R12);
>> + entry->jump[3] = PPC_INST_BCTR;
>
> Deleting the comment here is not an improvement imo.

Ok, I'll leave them in as I did for module64

Christophe

>
>
> Segher
>