sotn-decomp/include/bios.h
Jonathan Hohle 76d1584c89
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>
2024-05-17 08:45:26 +01:00

56 lines
3.4 KiB
C

#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