From b7cb524c02a10dba4126a7414f9ec4749928ffec Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sat, 2 Dec 2017 15:32:36 -0500 Subject: [PATCH] rename menu syscall vector to system syscall vector add support for system boot syscall --- src/guest/bios/bios.c | 66 +++++++++++++++++++-------------------- src/guest/bios/bios.h | 1 + src/guest/bios/syscalls.c | 27 ++++++++++++++-- src/guest/bios/syscalls.h | 2 +- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/guest/bios/bios.c b/src/guest/bios/bios.c index e850ed5a..33a9c7d7 100644 --- a/src/guest/bios/bios.c +++ b/src/guest/bios/bios.c @@ -33,7 +33,7 @@ enum { VECTOR_FLASHROM = 0x0c0000b8, VECTOR_GDROM = 0x0c0000bc, VECTOR_GDROM2 = 0x0c0000c0, - VECTOR_MENU = 0x0c0000e0, + VECTOR_SYSTEM = 0x0c0000e0, }; /* address of syscall entrypoints */ @@ -43,7 +43,7 @@ enum { SYSCALL_FLASHROM = 0x0c003d00, SYSCALL_GDROM = 0x0c001000, SYSCALL_GDROM2 = 0x0c0010f0, - SYSCALL_MENU = 0x0c000800, + SYSCALL_SYSTEM = 0x0c000800, }; static uint32_t bios_local_time() { @@ -209,7 +209,34 @@ static void bios_validate_flash(struct bios *bios) { } } -static void bios_boot(struct bios *bios) { +static int bios_post_init(struct device *dev) { + struct bios *bios = (struct bios *)dev; + + bios_validate_flash(bios); + + bios_override_settings(bios); + +#if 0 + /* this code enables a "hybrid" hle mode. in this mode, syscalls are patched + to trap into their hle handlers, but the real bios can still be ran to + test if bugs exist in the syscall emulation or bootstrap emulation. note, + the boot rom does a bootstrap on startup which copies the boot rom into + system ram. due to this, the invalid instructions are written to the + original rom, not the system ram (or else, they would be overwritten by + the bootstrap process) */ + struct boot *boot = bios->dc->boot; + boot_rom_write(boot, SYSCALL_FONTROM - SH4_AREA3_BEGIN, 0x0, 0xffff); + boot_rom_write(boot, SYSCALL_SYSINFO - SH4_AREA3_BEGIN, 0x0, 0xffff); + boot_rom_write(boot, SYSCALL_FLASHROM - SH4_AREA3_BEGIN, 0x0, 0xffff); + boot_rom_write(boot, SYSCALL_GDROM - SH4_AREA3_BEGIN, 0x0, 0xffff); + boot_rom_write(boot, SYSCALL_GDROM2 - SH4_AREA3_BEGIN, 0x0, 0xffff); + boot_rom_write(boot, SYSCALL_SYSTEM - SH4_AREA3_BEGIN, 0x0, 0xffff); +#endif + + return 1; +} + +void bios_boot(struct bios *bios) { struct dreamcast *dc = bios->dc; struct flash *flash = dc->flash; struct gdrom *gd = dc->gdrom; @@ -289,40 +316,13 @@ static void bios_boot(struct bios *bios) { sh4_write32(dc->mem, VECTOR_FLASHROM, SYSCALL_FLASHROM); sh4_write32(dc->mem, VECTOR_GDROM, SYSCALL_GDROM); sh4_write32(dc->mem, VECTOR_GDROM2, SYSCALL_GDROM2); - sh4_write32(dc->mem, VECTOR_MENU, SYSCALL_MENU); + sh4_write32(dc->mem, VECTOR_SYSTEM, SYSCALL_SYSTEM); } /* start executing at license screen code inside of ip.bin */ ctx->pc = 0xac008300; } -static int bios_post_init(struct device *dev) { - struct bios *bios = (struct bios *)dev; - - bios_validate_flash(bios); - - bios_override_settings(bios); - -#if 0 - /* this code enables a "hybrid" hle mode. in this mode, syscalls are patched - to trap into their hle handlers, but the real bios can still be ran to - test if bugs exist in the syscall emulation or bootstrap emulation. note, - the boot rom does a bootstrap on startup which copies the boot rom into - system ram. due to this, the invalid instructions are written to the - original rom, not the system ram (or else, they would be overwritten by - the bootstrap process) */ - struct boot *boot = bios->dc->boot; - boot_rom_write(boot, SYSCALL_FONTROM - SH4_AREA3_BEGIN, 0x0, 0xffff); - boot_rom_write(boot, SYSCALL_SYSINFO - SH4_AREA3_BEGIN, 0x0, 0xffff); - boot_rom_write(boot, SYSCALL_FLASHROM - SH4_AREA3_BEGIN, 0x0, 0xffff); - boot_rom_write(boot, SYSCALL_GDROM - SH4_AREA3_BEGIN, 0x0, 0xffff); - boot_rom_write(boot, SYSCALL_GDROM2 - SH4_AREA3_BEGIN, 0x0, 0xffff); - boot_rom_write(boot, SYSCALL_MENU - SH4_AREA3_BEGIN, 0x0, 0xffff); -#endif - - return 1; -} - int bios_invalid_instr(struct bios *bios) { struct dreamcast *dc = bios->dc; struct sh4_context *ctx = &dc->sh4->ctx; @@ -355,8 +355,8 @@ int bios_invalid_instr(struct bios *bios) { bios_gdrom_vector(bios); break; - case SYSCALL_MENU: - bios_menu_vector(bios); + case SYSCALL_SYSTEM: + bios_system_vector(bios); break; default: diff --git a/src/guest/bios/bios.h b/src/guest/bios/bios.h index d1476838..d073b4e8 100644 --- a/src/guest/bios/bios.h +++ b/src/guest/bios/bios.h @@ -19,5 +19,6 @@ struct bios *bios_create(struct dreamcast *dc); void bios_destroy(struct bios *bios); int bios_invalid_instr(struct bios *bios); +void bios_boot(struct bios *bios); #endif diff --git a/src/guest/bios/syscalls.c b/src/guest/bios/syscalls.c index 4a97c2bc..e7a0ee66 100644 --- a/src/guest/bios/syscalls.c +++ b/src/guest/bios/syscalls.c @@ -14,18 +14,39 @@ #endif /* - * menu syscalls + * system syscalls */ -void bios_menu_vector(struct bios *bios) { +enum { + SYSTEM_BOOT = -3, + SYSTEM_UNKNOWN = -2, + SYSTEM_RESET1 = -1, + SYSTEM_SECURITY = 0, + SYSTEM_RESET2 = 1, + SYSTEM_CHKDISC = 2, + SYSTEM_RESET3 = 3, + SYSTEM_RESET4 = 4, +}; + +void bios_system_vector(struct bios *bios) { struct dreamcast *dc = bios->dc; struct sh4_context *ctx = &dc->sh4->ctx; uint32_t fn = ctx->r[4]; - LOG_SYSCALL("MENU 0x%x", fn); + LOG_SYSCALL("SYSTEM 0x%x", fn); /* nop, branch to the return address */ ctx->pc = ctx->pr; + + switch (fn) { + case SYSTEM_BOOT: + bios_boot(bios); + break; + + default: + LOG_WARNING("bios_system_vector unhandled fn=0x%x", fn); + break; + } } /* diff --git a/src/guest/bios/syscalls.h b/src/guest/bios/syscalls.h index bf8e5a15..11ac4061 100644 --- a/src/guest/bios/syscalls.h +++ b/src/guest/bios/syscalls.h @@ -7,6 +7,6 @@ void bios_fontrom_vector(struct bios *bios); void bios_sysinfo_vector(struct bios *bios); void bios_flashrom_vector(struct bios *bios); void bios_gdrom_vector(struct bios *bios); -void bios_menu_vector(struct bios *bios); +void bios_system_vector(struct bios *bios); #endif