From e96f18d4e720663f79c6a7dc74c19b3c7f83ea5f Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Thu, 9 Nov 2023 15:08:21 -0800 Subject: Small boot cleanup (#1475) --- include/carthandle.h | 8 ++++++++ include/variables.h | 1 - spec | 4 ++-- src/boot/O2/sprintf.c | 30 ++++++++++++++++++++++++++++++ src/boot/boot_main.c | 2 +- src/boot/carthandle.c | 3 +++ src/boot/viconfig.c | 2 +- src/boot/z_std_dma.c | 2 ++ src/libultra/libc/sprintf.c | 30 ------------------------------ tools/disasm/files.txt | 2 +- 10 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 include/carthandle.h create mode 100644 src/boot/O2/sprintf.c create mode 100644 src/boot/carthandle.c delete mode 100644 src/libultra/libc/sprintf.c diff --git a/include/carthandle.h b/include/carthandle.h new file mode 100644 index 000000000..72d0821e5 --- /dev/null +++ b/include/carthandle.h @@ -0,0 +1,8 @@ +#ifndef CARTHANDLE_H +#define CARTHANDLE_H + +#include "ultra64.h" + +extern OSPiHandle* gCartHandle; + +#endif diff --git a/include/variables.h b/include/variables.h index 2b088fa0c..7b1313415 100644 --- a/include/variables.h +++ b/include/variables.h @@ -10,7 +10,6 @@ extern u16 gFramebuffer1[SCREEN_HEIGHT][SCREEN_WIDTH]; // at 0x80000500 extern u8 D_80025D00[]; // data -extern OSPiHandle* gCartHandle; extern size_t gDmaMgrDmaBuffSize; extern vs32 gIrqMgrResetStatus; extern volatile OSTime sIrqMgrResetTime; diff --git a/spec b/spec index 9a2a66908..1344fcade 100644 --- a/spec +++ b/spec @@ -17,7 +17,7 @@ beginseg include "build/data/boot/rspboot.data.o" include "build/src/boot/idle.o" include "build/src/boot/viconfig.o" - include "build/data/boot/viconfig.data.o" + include "build/src/boot/carthandle.o" include "build/src/boot/z_std_dma.o" include "build/src/boot/yaz0.o" include "build/src/boot/irqmgr.o" @@ -42,7 +42,7 @@ beginseg include "build/src/boot/O2/system_malloc.o" include "build/src/boot/O2/rand.o" include "build/src/boot/O2/__osMalloc.o" - include "build/src/libultra/libc/sprintf.o" + include "build/src/boot/O2/sprintf.o" include "build/src/boot/O2/printutils.o" include "build/src/boot/O2/sleep.o" include "build/asm/boot/setcause.text.o" diff --git a/src/boot/O2/sprintf.c b/src/boot/O2/sprintf.c new file mode 100644 index 000000000..773b982ff --- /dev/null +++ b/src/boot/O2/sprintf.c @@ -0,0 +1,30 @@ +#include "ultra64.h" +#include "libc/stdlib.h" +#include "libc/string.h" + +void* proutSprintf(void* dst, const char* fmt, size_t size) { + return (void*)((uintptr_t)memcpy(dst, fmt, size) + size); +} + +int vsprintf(char* dst, char* fmt, va_list args) { + int ans = _Printf(proutSprintf, dst, fmt, args); + if (ans > -1) { + dst[ans] = 0; + } + return ans; +} + +int sprintf(char* dst, const char* fmt, ...) { + int ans; + va_list args; + va_start(args, fmt); + + ans = _Printf(&proutSprintf, dst, fmt, args); + if (ans > -1) { + dst[ans] = 0; + } + + va_end(args); + + return ans; +} diff --git a/src/boot/boot_main.c b/src/boot/boot_main.c index cc2097f0f..0f95871ea 100644 --- a/src/boot/boot_main.c +++ b/src/boot/boot_main.c @@ -1,5 +1,5 @@ #include "prevent_bss_reordering.h" -#include "global.h" +#include "carthandle.h" #include "idle.h" #include "stack.h" #include "stackcheck.h" diff --git a/src/boot/carthandle.c b/src/boot/carthandle.c new file mode 100644 index 000000000..9a4cf542d --- /dev/null +++ b/src/boot/carthandle.c @@ -0,0 +1,3 @@ +#include "carthandle.h" + +OSPiHandle* gCartHandle = NULL; diff --git a/src/boot/viconfig.c b/src/boot/viconfig.c index ccba4e932..1b9f1135c 100644 --- a/src/boot/viconfig.c +++ b/src/boot/viconfig.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "libc/stdbool.h" #include "idle.h" void ViConfig_UpdateVi(u32 black) { diff --git a/src/boot/z_std_dma.c b/src/boot/z_std_dma.c index ac4992264..5b5265629 100644 --- a/src/boot/z_std_dma.c +++ b/src/boot/z_std_dma.c @@ -1,8 +1,10 @@ #include "prevent_bss_reordering.h" #include "global.h" +#include "carthandle.h" #include "fault.h" #include "stack.h" #include "stackcheck.h" +#include "z64dma.h" #include "z64thread.h" size_t gDmaMgrDmaBuffSize = 0x2000; diff --git a/src/libultra/libc/sprintf.c b/src/libultra/libc/sprintf.c deleted file mode 100644 index 773b982ff..000000000 --- a/src/libultra/libc/sprintf.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "ultra64.h" -#include "libc/stdlib.h" -#include "libc/string.h" - -void* proutSprintf(void* dst, const char* fmt, size_t size) { - return (void*)((uintptr_t)memcpy(dst, fmt, size) + size); -} - -int vsprintf(char* dst, char* fmt, va_list args) { - int ans = _Printf(proutSprintf, dst, fmt, args); - if (ans > -1) { - dst[ans] = 0; - } - return ans; -} - -int sprintf(char* dst, const char* fmt, ...) { - int ans; - va_list args; - va_start(args, fmt); - - ans = _Printf(&proutSprintf, dst, fmt, args); - if (ans > -1) { - dst[ans] = 0; - } - - va_end(args); - - return ans; -} diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index 23539f5f0..e170e97e3 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -247,7 +247,7 @@ # .data section 0x800969C0 : "rspboot", 0x80096B20 : "idle", - 0x80096B40 : "viconfig", + 0x80096B40 : "carthandle", 0x80096B50 : "z_std_dma", 0x80096B60 : "irqmgr", 0x80096B80 : "fault", -- cgit v1.2.3