Replace BIOS Trampolines (#1133)

This replaces several dozen BIOS trampolines from the extracted ASM to
"decompiled" source. These are modeled on the `INCLUDE_ASM` macro, but
generate the instructions necessary for each trampoline directly instead
of importing an extracted source file.

Because these trampolines never return, and GCC 2.6 doesnt appear to
have builtins for leaving off the return jump postamble, these will
likely need to remain assembly.

This also changes the `main.elf` target to depend on `main.ld`, and
undefined symbols files, allowing `make build` to regenerate those files
if necessary.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
This commit is contained in:
Jonathan Hohle 2024-05-17 00:45:26 -07:00 committed by GitHub
parent 2427123f20
commit 76d1584c89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
61 changed files with 280 additions and 60 deletions

View File

@ -159,7 +159,7 @@ main_dirs:
$(foreach dir,$(MAIN_ASM_DIRS) $(MAIN_SRC_DIRS),$(shell mkdir -p $(BUILD_DIR)/$(dir)))
$(MAIN_TARGET).exe: $(MAIN_TARGET).elf
$(OBJCOPY) -O binary $< $@
$(MAIN_TARGET).elf: $(MAIN_O_FILES)
$(MAIN_TARGET).elf: $(MAIN_O_FILES) $(BUILD_DIR)/main.ld $(CONFIG_DIR)/undefined_syms.$(VERSION).txt $(CONFIG_DIR)/undefined_syms_auto.$(VERSION).$(MAIN).txt
$(LD) $(LD_FLAGS) -o $@ \
-Map $(MAIN_TARGET).map \
-T $(BUILD_DIR)/main.ld \

View File

@ -58,60 +58,61 @@ segments:
- [0x1B4C, c, psxsdk/libgpu/font]
- [0x2554, c, psxsdk/libgpu/prim]
- [0x2C34, c, psxsdk/libgpu/sys]
- [0x5938, asm, psxsdk/libapi/c57]
- [0x5948, asm, psxsdk/libapi/c66]
- [0x5958, asm, psxsdk/libapi/c67]
- [0x5968, asm, psxsdk/libapi/c73]
- [0x5978, asm, psxsdk/libapi/c112]
- [0x5988, asm, psxsdk/libapi/a50]
- [0x5998, asm, psxsdk/libapi/a51]
- [0x59A8, asm, psxsdk/libapi/a52]
- [0x59B8, asm, psxsdk/libapi/a53]
- [0x59C8, asm, psxsdk/libapi/a54]
- [0x59D8, asm, psxsdk/libapi/a65]
- [0x59E8, asm, psxsdk/libapi/a66]
- [0x59F8, asm, psxsdk/libapi/a67]
- [0x5A08, asm, psxsdk/libapi/a69]
- [0x5A18, asm, psxsdk/libapi/a81]
- [0x5A28, asm, psxsdk/libapi/a91]
- [0x5938, c, psxsdk/libapi/c57]
- [0x5948, c, psxsdk/libapi/c66]
- [0x5958, c, psxsdk/libapi/c67]
- [0x5968, c, psxsdk/libapi/c73]
- [0x5978, c, psxsdk/libapi/c112]
- [0x5988, c, psxsdk/libapi/a50]
- [0x5998, c, psxsdk/libapi/a51]
- [0x59A8, c, psxsdk/libapi/a52]
- [0x59B8, c, psxsdk/libapi/a53]
- [0x59C8, c, psxsdk/libapi/a54]
- [0x59D8, c, psxsdk/libapi/a65]
- [0x59E8, c, psxsdk/libapi/a66]
- [0x59F8, c, psxsdk/libapi/a67]
- [0x5A08, c, psxsdk/libapi/a69]
- [0x5A18, c, psxsdk/libapi/a81]
- [0x5A28, c, psxsdk/libapi/a91]
- [0x5A38, c, psxsdk/libetc/pad]
- [0x5AD8, asm, psxsdk/libapi/a20]
- [0x5AE8, asm, psxsdk/libapi/a21]
- [0x5AF8, asm, psxsdk/libapi/a22]
- [0x5CEC, asm, psxsdk/libapi/l10]
- [0x5AD8, c, psxsdk/libapi/a20]
- [0x5AE8, c, psxsdk/libapi/a21]
- [0x5AF8, c, psxsdk/libapi/a22]
- [0x5B08, asm, psxsdk/libetc/vsync]
- [0x5CEC, c, psxsdk/libapi/l10]
- [0x5CFC, c, psxsdk/libetc/intr]
- [0x640C, asm, psxsdk/libapi/c114]
- [0x641C, asm, psxsdk/libapi/a23]
- [0x642C, asm, psxsdk/libapi/a24]
- [0x643C, asm, psxsdk/libapi/a25]
- [0x644C, asm, psxsdk/libapi/a36]
- [0x645C, asm, psxsdk/libapi/a37]
- [0x640C, c, psxsdk/libapi/c114]
- [0x641C, c, psxsdk/libapi/a23]
- [0x642C, c, psxsdk/libapi/a24]
- [0x643C, c, psxsdk/libapi/a25]
- [0x644C, c, psxsdk/libapi/a36]
- [0x645C, c, psxsdk/libapi/a37]
- [0x646C, c, psxsdk/libetc/intr_vb]
- [0x6594, c, psxsdk/libetc/intr_dma]
- [0x683C, c, psxsdk/libetc/vmode]
- [0x6864, asm, psxsdk/libc/a56]
- [0x6874, asm, psxsdk/libc/a63]
- [0x6884, asm, psxsdk/libc/c19]
- [0x6894, asm, psxsdk/libc/c21]
- [0x68A4, asm, psxsdk/libc/c25]
- [0x68B4, asm, psxsdk/libc/c27]
- [0x68C4, asm, psxsdk/libc/c42]
- [0x68D4, asm, psxsdk/libc/c43]
- [0x68E4, asm, psxsdk/libc/c47]
- [0x68F4, asm, psxsdk/libc/c48]
- [0x6904, asm, psxsdk/libc/c51]
- [0x6914, asm, psxsdk/libc/c52]
- [0x6924, asm, psxsdk/libc/c63]
- [0x6864, c, psxsdk/libc/a56]
- [0x6874, c, psxsdk/libc/a63]
- [0x6884, c, psxsdk/libc/c19]
- [0x6894, c, psxsdk/libc/c21]
- [0x68A4, c, psxsdk/libc/c25]
- [0x68B4, c, psxsdk/libc/c27]
- [0x68C4, c, psxsdk/libc/c42]
- [0x68D4, c, psxsdk/libc/c43]
- [0x68E4, c, psxsdk/libc/c47]
- [0x68F4, c, psxsdk/libc/c48]
- [0x6904, c, psxsdk/libc/c51]
- [0x6914, c, psxsdk/libc/c52]
- [0x6924, c, psxsdk/libc/c63]
- [0x6934, c, psxsdk/libc/sprintf]
- [0x7190, asm, psxsdk/libc/c46]
- [0x7190, c, psxsdk/libc/c46]
- [0x71A0, c, psxsdk/libc/memmove]
- [0x720C, asm, psxsdk/libcard/c171]
- [0x721C, asm, psxsdk/libcard/c172]
- [0x722C, asm, psxsdk/libcard/a74]
- [0x723C, asm, psxsdk/libcard/a75]
- [0x720C, c, psxsdk/libcard/c171]
- [0x721C, c, psxsdk/libcard/c172]
- [0x722C, c, psxsdk/libcard/a74]
- [0x723C, c, psxsdk/libcard/a75]
- [0x724C, c, psxsdk/libcard/card]
- [0x7284, asm, psxsdk/libcard/a78]
- [0x7294, asm, psxsdk/libcard/a80]
- [0x7284, c, psxsdk/libcard/a78]
- [0x7294, c, psxsdk/libcard/a80]
- [0x72A4, c, psxsdk/libgs/gs_007]
- [0x72DC, c, psxsdk/libapi/counter]
- [0x7454, c, psxsdk/libgs/gs_008]
@ -154,10 +155,10 @@ segments:
- [0x970C, c, psxsdk/libgte/fgo_06]
- [0x98AC, c, psxsdk/libgte/ratan]
- [0x9A2C, c, psxsdk/libgte/patchgte]
- [0x9ACC, asm, psxsdk/libapi/c68]
- [0x9ACC, c, psxsdk/libapi/c68]
- [0x9ADC, c, psxsdk/libcd/cdrom]
- [0x9B0C, c, psxsdk/libcd/event]
- [0x9C14, asm, psxsdk/libapi/a07]
- [0x9C14, c, psxsdk/libapi/a07]
- [0x9C24, c, psxsdk/libcd/sys]
- [0xA398, c, psxsdk/libcd/bios]
- [0xBA98, c, psxsdk/libcd/iso9660]
@ -224,13 +225,13 @@ segments:
- [0x12A0C, c, psxsdk/libsnd/vmanager]
- [0x1785C, c, psxsdk/libspu/s_i]
- [0x1787C, c, psxsdk/libspu/s_ini]
- [0x179C8, asm, psxsdk/libapi/a08]
- [0x179D8, asm, psxsdk/libapi/a12]
- [0x179C8, c, psxsdk/libapi/a08]
- [0x179D8, c, psxsdk/libapi/a12]
- [0x179E8, c, psxsdk/libspu/spu]
- [0x18B04, c, psxsdk/libspu/s_dcb]
- [0x18B28, c, psxsdk/libspu/s_q]
- [0x18BA4, asm, psxsdk/libapi/a09]
- [0x18BB4, asm, psxsdk/libapi/a13]
- [0x18BA4, c, psxsdk/libapi/a09]
- [0x18BB4, c, psxsdk/libapi/a13]
- [0x18BC4, c, psxsdk/libspu/s_m_init]
- [0x18C18, c, psxsdk/libspu/s_m_m]
- [0x191E0, c, psxsdk/libspu/s_m_wsa]
@ -241,7 +242,7 @@ segments:
- [0x19A18, c, psxsdk/libspu/s_m_util]
- [0x19B00, c, psxsdk/libspu/s_srmp]
- [0x1A4E0, c, psxsdk/libspu/s_crwa]
- [0x1A67C, asm, psxsdk/libapi/a10]
- [0x1A67C, c, psxsdk/libapi/a10]
- [0x1A68C, c, psxsdk/libspu/s_si]
- [0x1A7BC, c, psxsdk/libspu/s_sic]
- [0x1A800, c, psxsdk/libspu/s_cb]
@ -254,7 +255,7 @@ segments:
- [0x1B3F4, c, psxsdk/libspu/s_stm]
- [0x1B428, c, psxsdk/libspu/s_wp]
- [0x1B4B4, c, psxsdk/libspu/s_itc]
- [0x1B55C, asm, psxsdk/libapi/a11]
- [0x1B55C, c, psxsdk/libapi/a11]
- [0x1B56C, c, psxsdk/libspu/s_it]
- [0x1B5A8, c, psxsdk/libspu/s_sca]
- [0x1B93C, c, psxsdk/libspu/s_n2p]

55
include/bios.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef BIOS_H
#define BIOS_H
#include "common.h"
// Defines the syscall stub for various functions
#define BIOS_FUNCTION(name, section, id) \
__asm__( \
".pushsection .text\n" \
"\t.align\t2\n" \
"\t.globl\t" #name "\n" \
"\t.ent\t" #name "\n" \
"" #name " :\n" \
".set noat\n" \
".set noreorder\n" \
"\n" \
"glabel " #name "\n" \
"\taddiu $t2, $zero, " #section "\n" \
"\tjr $t2\n" \
"\t addiu $t1, $zero, " #id "\n" \
"\tnop\n" \
".size " #name ", . - " #name "\n" \
"\t.set reorder\n" \
"\t.set at\n" \
"\t.end\t" #name "\n" \
".popsection");
#define BIOS_A_FUNCTION(name, id) BIOS_FUNCTION(name, 0xA0, id)
#define BIOS_B_FUNCTION(name, id) BIOS_FUNCTION(name, 0xB0, id)
#define BIOS_C_FUNCTION(name, id) BIOS_FUNCTION(name, 0xC0, id)
#define SYSCALL(name, number) \
__asm__( \
".pushsection .text\n" \
"\t.align\t2\n" \
"\t.globl\t" #name "\n" \
"\t.ent\t" #name "\n" \
"" #name " :\n" \
".set noat\n" \
".set noreorder\n" \
"\n" \
"glabel " #name "\n" \
"\taddiu $a0, $zero, " #number "\n" \
"\tsyscall 0\n" \
"\tjr $ra\n" \
"\tnop\n" \
".size " #name ", . - " #name "\n" \
"\t.set reorder\n" \
"\t.set at\n" \
"\t.end\t" #name "\n" \
".popsection");
#endif // BIOS_H

View File

@ -15,7 +15,7 @@ struct EXEC {
unsigned long sp, fp, gp, ret, base;
};
extern void InitHeap(unsigned long*, unsigned long);
extern void InitHeap(void*, unsigned long);
extern long Load(char*, struct EXEC*);
extern long Exec(struct EXEC*, long, char**);
// GPU_cw

View File

@ -2,6 +2,8 @@ extern void exit();
extern void puts(char*);
// setjmp
extern char* strcat(char*, char*);
extern int strcmp(char*, char*);
extern int strncmp(char*, char*);
extern char* strcpy(char*, char*);
extern int strlen(char*);
extern void* memcpy(unsigned char*, unsigned char*, int);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(DeliverEvent, 0x7);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(OpenEvent, 0x8);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(CloseEvent, 0x9);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(WaitEvent, 0xA);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(TestEvent, 0xB);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(EnableEvent, 0xC);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(DisableEvent, 0xD);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(StopPAD, 0x14);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(PAD_init, 0x15);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(PAD_dr, 0x16);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(ReturnFromException, 0x17);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(ResetEntryInt, 0x18);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(HookEntryInt, 0x19);

View File

@ -0,0 +1,3 @@
#include "bios.h"
SYSCALL(EnterCriticalSection, 0x1);

View File

@ -0,0 +1,3 @@
#include "bios.h"
SYSCALL(ExitCriticalSection, 0x2);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(open, 0x32);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(lseek, 0x33);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(read, 0x34);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(write, 0x35);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(close, 0x36);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(format, 0x41);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(firstfile, 0x42);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(nextfile, 0x43);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(erase, 0x45);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(Krom2RawAdd, 0x51);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(ChangeClearPAD, 0x5B);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(_bu_init, 0x70);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(_96_remove, 0x72);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(InitHeap, 0x39);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(Load, 0x42);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(Exec, 0x43);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(FlushCache, 0x44);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(GPU_cw, 0x49);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_C_FUNCTION(ChangeClearRCnt, 0xA);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(exit, 0x38);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(puts, 0x3F);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(setjmp, 0x13);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(strcat, 0x15);

View File

@ -1,3 +1,3 @@
#include "common.h"
#include "bios.h"
INCLUDE_ASM("main/nonmatchings/psxsdk/libc/c23", strcmp);
BIOS_A_FUNCTION(strcmp, 0x17);

View File

@ -1,3 +1,3 @@
#include "common.h"
#include "bios.h"
INCLUDE_ASM("main/nonmatchings/psxsdk/libc/c24", strncmp);
BIOS_A_FUNCTION(strncmp, 0x18);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(strcpy, 0x19);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(strlen, 0x1B);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(memcpy, 0x2A);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(memset, 0x2B);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(memchr, 0x2E);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(rand, 0x2F);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(srand, 0x30);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(malloc, 0x33);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(free, 0x34);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(printf, 0x3F);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(InitCARD, 0x4A);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(StartCARD, 0x4B);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(_card_write, 0x4E);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_B_FUNCTION(_new_card, 0x50);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(_card_info, 0xAB);

View File

@ -0,0 +1,3 @@
#include "bios.h"
BIOS_A_FUNCTION(_card_load, 0xAC);