Skip to content

Commit

Permalink
Re-worked the complete loader code: Re-implemented the LiBounceOneChu…
Browse files Browse the repository at this point in the history
…nk and LiWaitOneChunk functions and replaced the whole earlier loader functions by one LiWaitOneChunk function. (LiBounceOneChunk is just for...good to know ;-))

Comment:
This corrects the loading behavior. I don't think this will increase/decrease the compatibility (might be) as the loader behavior was almost correct before too but this reduces our loader code size by a lot, makes the loader code a lot more understandable and a lot easier to port to other system menu versions. Also since we don't need to fear GCC overwriting some registers anymore, the code optimizations can be used again which i re-enabled now too.
  • Loading branch information
dimok789 committed Nov 7, 2015
1 parent c41df7c commit bf42d94
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 571 deletions.
20 changes: 10 additions & 10 deletions installer/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ static void InstallLoader(private_data_t *private_data)
/* Get our functions */
struct magic_t
{
const void* func; // our replacement function which is called
const void* call; // address where to place the jump to our function
uint orig_instr;
const void * repl_func; // our replacement function which is called
const void * repl_addr; // address where to place the jump to the our function
const unsigned int call_type; // call type, e.g. 0x48000000 for branch and 0x48000001 for bl
} *magic = (struct magic_t *)loader_magic;
int magic_len = loader_magic_len / sizeof(struct magic_t);

Expand All @@ -641,16 +641,16 @@ static void InstallLoader(private_data_t *private_data)
int i;
for (i = 0; i < magic_len; i ++)
{
int func_addr = (int)magic[i].func;
int call_addr = (int)magic[i].call;
// int orig_instr = (int)magic[i].orig_instr;
unsigned int repl_func = (unsigned int)magic[i].repl_func;
unsigned int repl_addr = (unsigned int)magic[i].repl_addr;
unsigned int call_type = magic[i].call_type;

// Install function hook only if needed
int jump_addr = func_addr - call_addr; // Compute jump length to jump from current instruction address to our function address
*((volatile uint32_t *)(0xC1000000 + call_addr)) = 0x48000001 | jump_addr; // Replace the instruction in the loader by the jump to our function
int jump_addr = (repl_func - repl_addr) & 0x03fffffc; // Compute jump length to jump from current instruction address to our function address
*((volatile uint32_t *)(0xC1000000 + repl_addr)) = call_type | jump_addr; // Replace the instruction in the loader by the jump to our function
// flush caches and invalidate instruction cache
DCFlushRange((void*)(0xC1000000 + call_addr), 4);
ICInvalidateRange((void*)(0xC1000000 + call_addr), 4);
DCFlushRange((void*)(0xC1000000 + repl_addr), 4);
ICInvalidateRange((void*)(0xC1000000 + repl_addr), 4);
}

}
Expand Down
6 changes: 3 additions & 3 deletions loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SFLAGS := -mgekko -mregnames
# so for now i reverted it as there is still enough space in payload
# adding it back in will give another 600 - 1000 bytes of space
# CFLAGS := -Os -nostdinc -nostdlib -Wall -x c -std=gnu99
CFLAGS := -O0 -nostdinc -nostdlib -Wall -x c -std=gnu99 \
CFLAGS := -Os -nostdinc -nostdlib -Wall -x c -std=gnu99 \
-ffreestanding \
-mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar \
-msdata=none -memb -ffunction-sections -fdata-sections \
Expand All @@ -56,8 +56,8 @@ build/loader%.magic.bin: build/loader%.elf $(BUILD_REQ)
$(OBJCOPY) -j .magic -O binary $< $@

build/loader%.elf: loader%.ld $(OBJ) $(BUILD_REQ)
$(LD) -T $< $(OBJ)
# $(LD) -T $< $(OBJ) -s -L"$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2" -lgcc
# $(LD) -T $< $(OBJ)
$(LD) -T $< $(OBJ) -s -L"$(DEVKITPPC)/lib/gcc/powerpc-eabi/4.8.2" -lgcc

build/%.o: %.c $(BUILD_REQ)
$(CC) -c $(CFLAGS) -o $@ $<
Expand Down
Loading

0 comments on commit bf42d94

Please sign in to comment.