Skip to content

Commit

Permalink
Documented SELF loader relocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandro Sánchez Bach committed Jan 21, 2015
1 parent 06f8417 commit d761619
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions nucleus/loader/self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,22 @@ bool SELFLoader::load_prx(sys_prx_t* prx)
u32 value = 0;

switch (rel.type.ToLE()) {
case 1: // Patch 32-bit pointers
case R_PPC64_ADDR32:
value = (u32)prx->segments[rel.index_value].addr + rel.ptr;
nucleus.memory.write32(addr, value);
break;

case 4: // Patch lower 16-bits of pointers (by using the relocation's immediate value)
case R_PPC64_ADDR16_LO:
value = (u16)rel.ptr;
nucleus.memory.write16(addr, value);
break;

case 5: // Patch higher 16-bits of pointers (by using the base address of the segment
case R_PPC64_ADDR16_HI:
value = (u16)(prx->segments[rel.index_value].addr >> 16);
nucleus.memory.write16(addr, value);
break;

case 6: // Same (TODO: Is there any difference compared to flags == 5?)
case R_PPC64_ADDR16_HA:
value = (u16)(prx->segments[1].addr >> 16);
nucleus.memory.write16(addr, value);
break;
Expand Down
15 changes: 13 additions & 2 deletions nucleus/loader/self.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <string>

// Segment Types
enum
{
enum {
// Common segments
PT_LOAD = 0x1,
PT_DYNAMIC = 0x2,
Expand All @@ -28,6 +27,18 @@ enum
PT_SCE_PPURELA = 0x700000A4,
};

// Relocations
enum {
R_PPC64_NONE = 0, // Nothing
R_PPC64_ADDR32 = 1, // u32: (S + A)
R_PPC64_ADDR24 = 2, // u24: (S + A) >> 2
R_PPC64_ADDR16 = 3, // u16: (S + A)
R_PPC64_ADDR16_LO = 4, // u16: LO(S + A)
R_PPC64_ADDR16_HI = 5, // u16: HI(S + A)
R_PPC64_ADDR16_HA = 6, // u16: HA(S + A)
R_PPC64_ADDR14 = 7, // u14: (S + A) >> 2
};

// SELF structs
struct SceHeader
{
Expand Down

0 comments on commit d761619

Please sign in to comment.