diff options
| author | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-06-27 22:19:18 +0200 |
|---|---|---|
| committer | spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> | 2022-06-27 22:19:18 +0200 |
| commit | 578181ace1374e72cb93d69d2c201ce7a0a2300c (patch) | |
| tree | 8e91212c966bf95bd7c34901e56dad7f81b9af57 | |
| parent | ef776e728cfa67fbca38bb375152b336fa0b5200 (diff) | |
| download | psn00bsdk-578181ace1374e72cb93d69d2c201ce7a0a2300c.tar.gz | |
Add 8 MB RAM support and customizable _start stub
| -rw-r--r-- | libpsn00b/ldscripts/exe.ld | 6 | ||||
| -rw-r--r-- | libpsn00b/libc/_start.s | 18 | ||||
| -rw-r--r-- | libpsn00b/libc/start.c | 4 | ||||
| -rw-r--r-- | tools/util/elf2x.c | 44 |
4 files changed, 47 insertions, 25 deletions
diff --git a/libpsn00b/ldscripts/exe.ld b/libpsn00b/ldscripts/exe.ld index 583d76a..a8dfccf 100644 --- a/libpsn00b/ldscripts/exe.ld +++ b/libpsn00b/ldscripts/exe.ld @@ -6,6 +6,10 @@ * using $gp to reference them) is fully supported; the block is made up of * sections .sdata and .sbss. Note that GP-relative addressing is not * compatible with dynamic linking, as DLLs require GP to be unused. + * + * This linker script assumes main RAM is 8 MB to allow executables meant for + * devkits or arcade systems to be built, however the executable conversion + * tool (elf2x) will throw a warning if the size exceeds 2 MB. */ /*OUTPUT_FORMAT(elf32-littlemips)*/ @@ -15,7 +19,7 @@ ENTRY(_start) MEMORY { /* Mapped into KSEG0 */ KERNEL_RAM (rwx) : ORIGIN = 0x80000000, LENGTH = 0x010000 - APP_RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x1f0000 + APP_RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x7f0000 } SECTIONS { diff --git a/libpsn00b/libc/_start.s b/libpsn00b/libc/_start.s new file mode 100644 index 0000000..56075c8 --- /dev/null +++ b/libpsn00b/libc/_start.s @@ -0,0 +1,18 @@ +# PSn00bSDK _start() trampoline +# (C) 2022 spicyjpeg - MPL licensed +# +# This file provides a weak function that can be easily overridden to e.g. set +# $sp or perform additional initialization before the "real" _start() +# (_start_inner()) is called. + +.set noreorder +.section .text + +.global _start +.type _start, @function +.weak _start +_start: + la $gp, _gp + + j _start_inner + nop diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index fd6fe33..bfe9c9b 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -80,8 +80,8 @@ extern int main(int argc, const char* argv[]); // Even though _start() usually takes no arguments, this implementation allows // parent executables to pass args directly to child executables without having // to overwrite the arg strings in kernel RAM. -void _start(int32_t override_argc, const char **override_argv) { - __asm__ volatile("la $gp, _gp;"); +void _start_inner(int32_t override_argc, const char **override_argv) { + //__asm__ volatile("la $gp, _gp;"); // Clear BSS 4 bytes at a time. BSS is always aligned to 4 bytes by the // linker script. diff --git a/tools/util/elf2x.c b/tools/util/elf2x.c index 9a7c126..38ed60d 100644 --- a/tools/util/elf2x.c +++ b/tools/util/elf2x.c @@ -154,31 +154,31 @@ int main(int argc, char** argv) { } - exe_tsize = (exe_haddr-exe_taddr); - exe_tsize += prg_heads[head.prg_entry_count-1].p_filesz; + exe_tsize = (exe_haddr - exe_taddr); + exe_tsize += prg_heads[head.prg_entry_count - 1].p_filesz; - if( !quiet ) { - - printf( "pc:%08x t_addr:%08x t_size:%d\n", - head.prg_entry_addr, exe_taddr, exe_tsize ); - - } + if (!quiet) + printf( + "pc:%08x t_addr:%08x t_size:%d\n", + head.prg_entry_addr, + exe_taddr, + exe_tsize + ); // Check if load address is appropriate in main RAM locations - if( ( ( exe_taddr>>24 ) == 0x0 ) || ( ( exe_taddr>>24 ) == 0x80 ) || - ( ( exe_taddr>>24 ) == 0xA0 ) ) { - - if( ( exe_taddr&0x00ffffff ) < 65536 ) { - - printf( "Warning: Program text address overlaps kernel area!\n" ); - - } - - } - - - // Pad out the size to multiples of 2KB - exe_tsize = 2048*((exe_tsize+2047)/2048); + if ( + ((exe_taddr >= 0x00000000) && (exe_taddr < 0x00001000)) || + ((exe_taddr >= 0x80000000) && (exe_taddr < 0x80001000)) || + ((exe_taddr >= 0xa0000000) && (exe_taddr < 0xa0001000)) + ) + printf("WARNING: program text address overlaps kernel area!\n"); + + // Throw warning if executable is larger than 2MB + if (exe_tsize > 0x1f0000) + printf("WARNING: executable is larger than available RAM on a stock console!\n"); + + // Pad out the size to multiples of 2KB (CD sector size) + exe_tsize = ((exe_tsize + 2047) / 2048) * 2048; // Load the binary data binary = (unsigned char*)malloc( exe_tsize ); |
