diff options
author | Eugene Surovegin <ebs@ebshome.net> | 2013-09-20 14:42:20 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-10-11 01:53:22 -0400 |
commit | fed8393ef9f779e51c3e0c844e549e0bbc8d6dd4 (patch) | |
tree | 97b12fd4468947716e744d74354a223061d26d68 | |
parent | dbd0c5d5296f291a5c3affee4fbdde254632ffca (diff) |
powerpc: Make kernel module helper endian-safe.
Signed-off-by: Eugene Surovegin <surovegin@google.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r-- | arch/powerpc/kernel/module_64.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index 6ee59a0eb268..a102f4412392 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c | |||
@@ -62,6 +62,16 @@ struct ppc64_stub_entry | |||
62 | r2) into the stub. */ | 62 | r2) into the stub. */ |
63 | static struct ppc64_stub_entry ppc64_stub = | 63 | static struct ppc64_stub_entry ppc64_stub = |
64 | { .jump = { | 64 | { .jump = { |
65 | #ifdef __LITTLE_ENDIAN__ | ||
66 | 0x00, 0x00, 0x82, 0x3d, /* addis r12,r2, <high> */ | ||
67 | 0x00, 0x00, 0x8c, 0x39, /* addi r12,r12, <low> */ | ||
68 | /* Save current r2 value in magic place on the stack. */ | ||
69 | 0x28, 0x00, 0x41, 0xf8, /* std r2,40(r1) */ | ||
70 | 0x20, 0x00, 0x6c, 0xe9, /* ld r11,32(r12) */ | ||
71 | 0x28, 0x00, 0x4c, 0xe8, /* ld r2,40(r12) */ | ||
72 | 0xa6, 0x03, 0x69, 0x7d, /* mtctr r11 */ | ||
73 | 0x20, 0x04, 0x80, 0x4e /* bctr */ | ||
74 | #else | ||
65 | 0x3d, 0x82, 0x00, 0x00, /* addis r12,r2, <high> */ | 75 | 0x3d, 0x82, 0x00, 0x00, /* addis r12,r2, <high> */ |
66 | 0x39, 0x8c, 0x00, 0x00, /* addi r12,r12, <low> */ | 76 | 0x39, 0x8c, 0x00, 0x00, /* addi r12,r12, <low> */ |
67 | /* Save current r2 value in magic place on the stack. */ | 77 | /* Save current r2 value in magic place on the stack. */ |
@@ -70,6 +80,7 @@ static struct ppc64_stub_entry ppc64_stub = | |||
70 | 0xe8, 0x4c, 0x00, 0x28, /* ld r2,40(r12) */ | 80 | 0xe8, 0x4c, 0x00, 0x28, /* ld r2,40(r12) */ |
71 | 0x7d, 0x69, 0x03, 0xa6, /* mtctr r11 */ | 81 | 0x7d, 0x69, 0x03, 0xa6, /* mtctr r11 */ |
72 | 0x4e, 0x80, 0x04, 0x20 /* bctr */ | 82 | 0x4e, 0x80, 0x04, 0x20 /* bctr */ |
83 | #endif | ||
73 | } }; | 84 | } }; |
74 | 85 | ||
75 | /* Count how many different 24-bit relocations (different symbol, | 86 | /* Count how many different 24-bit relocations (different symbol, |
@@ -269,8 +280,13 @@ static inline int create_stub(Elf64_Shdr *sechdrs, | |||
269 | 280 | ||
270 | *entry = ppc64_stub; | 281 | *entry = ppc64_stub; |
271 | 282 | ||
283 | #ifdef __LITTLE_ENDIAN__ | ||
284 | loc1 = (Elf64_Half *)&entry->jump[0]; | ||
285 | loc2 = (Elf64_Half *)&entry->jump[4]; | ||
286 | #else | ||
272 | loc1 = (Elf64_Half *)&entry->jump[2]; | 287 | loc1 = (Elf64_Half *)&entry->jump[2]; |
273 | loc2 = (Elf64_Half *)&entry->jump[6]; | 288 | loc2 = (Elf64_Half *)&entry->jump[6]; |
289 | #endif | ||
274 | 290 | ||
275 | /* Stub uses address relative to r2. */ | 291 | /* Stub uses address relative to r2. */ |
276 | reladdr = (unsigned long)entry - my_r2(sechdrs, me); | 292 | reladdr = (unsigned long)entry - my_r2(sechdrs, me); |