diff --git a/Makefile b/Makefile index 8b9d461d28..9741d456ce 100644 --- a/Makefile +++ b/Makefile @@ -207,6 +207,8 @@ $(shell mkdir -p build/baserom $(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(ASSET_BIN # directory flags build/src/boot/O2/%.o: OPTFLAGS := -O2 +build/src/boot/libc/%.o: OPTFLAGS := -O2 +build/src/boot/libm/%.o: OPTFLAGS := -O2 build/src/boot/libc64/%.o: OPTFLAGS := -O2 build/src/libultra/os/%.o: OPTFLAGS := -O1 diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 3f04c6ed3c..0e48d50dce 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -22,11 +22,14 @@ typedef volatile s64 vs64; typedef float f32; typedef double f64; +#if !defined(_SIZE_T) +#define _SIZE_T #if defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64) typedef unsigned long size_t; #else typedef unsigned int size_t; #endif +#endif #ifndef NULL #define NULL ((void*)0) diff --git a/include/functions.h b/include/functions.h index d83f61a359..53f6af07f6 100644 --- a/include/functions.h +++ b/include/functions.h @@ -65,12 +65,6 @@ void MtxConv_L2F(MtxF* mtx, Mtx* mf); s32 func_80086620(OSMesgQueue* param_1, PadMgr* param_2, OSContStatus* param_3); -f32 fmodf(f32 dividend, f32 divisor); -void* __osMemset(void* ptr, s32 val, size_t size); -s32 __osStrcmp(const char* str1, const char* str2); -char* __osStrcpy(char* dst, const char* src); -void* __osMemcpy(void* dst, void* src, size_t size); - // void EnItem00_SetObject(EnItem00* this, PlayState* play, f32* shadowOffset, f32* shadowScale); // void EnItem00_Init(Actor* thisx, PlayState* play); // void EnItem00_Destroy(Actor* thisx, PlayState* play); diff --git a/include/libc/math.h b/include/libc/math.h index 6e904dca83..25d9e5a937 100644 --- a/include/libc/math.h +++ b/include/libc/math.h @@ -17,4 +17,6 @@ float fabsf(float f); double sqrt(double d); #pragma intrinsic(sqrt) +float fmodf(float dividend, float divisor); + #endif diff --git a/include/libc/stddef.h b/include/libc/stddef.h index d753396146..3b4ed699c1 100644 --- a/include/libc/stddef.h +++ b/include/libc/stddef.h @@ -1,9 +1,16 @@ #ifndef LIBC_STDDEF_H #define LIBC_STDDEF_H -#include "PR/ultratypes.h" +#if !defined(_SIZE_T) +#define _SIZE_T +#if defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64) +typedef unsigned long size_t; +#else +typedef unsigned int size_t; +#endif +#endif -typedef s32 ptrdiff_t; +typedef signed long ptrdiff_t; #ifdef __GNUC__ #define offsetof(structure, member) __builtin_offsetof (structure, member) diff --git a/include/libc/string.h b/include/libc/string.h index 9c6a1cb087..4fb99e71ee 100644 --- a/include/libc/string.h +++ b/include/libc/string.h @@ -3,10 +3,13 @@ #include "libc/stddef.h" - const char* strchr(const char* s, int c); size_t strlen(const char* s); void* memcpy(void* s1, const void* s2, size_t n); +void* memset(void* ptr, int val, size_t size); +int strcmp(const char* str1, const char* str2); +char* strcpy(char* dst, const char* src); +void* memmove(void* dst, const void* src, size_t size); #endif diff --git a/spec b/spec index dbe71ed3bf..fc733befb9 100644 --- a/spec +++ b/spec @@ -237,11 +237,11 @@ beginseg include "build/src/libultra/os/sethwinterrupt.o" include "build/asm/boot/getwatchlo.text.o" include "build/asm/boot/setwatchlo.text.o" - include "build/src/boot/O2/fmodf.o" - include "build/src/boot/O2/__osMemset.o" - include "build/src/boot/O2/__osStrcmp.o" - include "build/src/boot/O2/__osStrcpy.o" - include "build/src/boot/O2/__osMemcpy.o" + include "build/src/boot/libm/fmodf.o" + include "build/src/boot/libc/memset.o" + include "build/src/boot/libc/strcmp.o" + include "build/src/boot/libc/strcpy.o" + include "build/src/boot/libc/memmove.o" include "build/src/boot/build.o" endseg diff --git a/src/boot/O2/__osMemset.c b/src/boot/O2/__osMemset.c deleted file mode 100644 index 0c4172e9fa..0000000000 --- a/src/boot/O2/__osMemset.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "global.h" - -void* __osMemset(void* ptr, s32 val, size_t size) { - u8* dst = ptr; - register s32 rem; - - for (rem = size--; rem != 0; rem = size--) { - *dst++ = val; - } - return ptr; -} diff --git a/src/boot/O2/__osMemcpy.c b/src/boot/libc/memmove.c similarity index 66% rename from src/boot/O2/__osMemcpy.c rename to src/boot/libc/memmove.c index 2e25b23f08..720de0facf 100644 --- a/src/boot/O2/__osMemcpy.c +++ b/src/boot/libc/memmove.c @@ -1,9 +1,9 @@ -#include "global.h" +#include "libc/string.h" -void* __osMemcpy(void* dst, void* src, size_t size) { - u8* _dst = dst; - u8* _src = src; - register s32 rem; +void* memmove(void* dst, const void* src, size_t size) { + unsigned char* _dst = dst; + const unsigned char* _src = src; + register size_t rem; if (_dst == _src) { return dst; diff --git a/src/boot/libc/memset.c b/src/boot/libc/memset.c new file mode 100644 index 0000000000..7e0b1c0ed1 --- /dev/null +++ b/src/boot/libc/memset.c @@ -0,0 +1,12 @@ +#include "libc/string.h" + +void* memset(void* ptr, int val, size_t size) { + unsigned char* dst = ptr; + register size_t rem; + + for (rem = size--; rem != 0; rem = size--) { + *dst++ = val; + } + + return ptr; +} diff --git a/src/boot/O2/__osStrcmp.c b/src/boot/libc/strcmp.c similarity index 56% rename from src/boot/O2/__osStrcmp.c rename to src/boot/libc/strcmp.c index 10bd2fa92b..d65e4411f7 100644 --- a/src/boot/O2/__osStrcmp.c +++ b/src/boot/libc/strcmp.c @@ -1,12 +1,13 @@ -#include "global.h" +#include "libc/string.h" -s32 __osStrcmp(const char* str1, const char* str2) { - char c1; - char c2; +int strcmp(const char* str1, const char* str2) { + unsigned char c1; + unsigned char c2; do { c1 = *str1++; c2 = *str2++; + if (c1 != c2) { return c1 - c2; } diff --git a/src/boot/O2/__osStrcpy.c b/src/boot/libc/strcpy.c similarity index 63% rename from src/boot/O2/__osStrcpy.c rename to src/boot/libc/strcpy.c index 86a98a804a..8166a47e0e 100644 --- a/src/boot/O2/__osStrcpy.c +++ b/src/boot/libc/strcpy.c @@ -1,6 +1,6 @@ -#include "global.h" +#include "libc/string.h" -char* __osStrcpy(char* dst, const char* src) { +char* strcpy(char* dst, const char* src) { char* _dst = dst; while (*src != '\0') { diff --git a/src/boot/libc64/__osMalloc.c b/src/boot/libc64/__osMalloc.c index 2c736740bf..5540089975 100644 --- a/src/boot/libc64/__osMalloc.c +++ b/src/boot/libc64/__osMalloc.c @@ -1,10 +1,10 @@ #include "libc64/os_malloc.h" #include "alignment.h" -#include "functions.h" // for __osMemcpy #include "libc/stdbool.h" #include "libc/stdint.h" -#include "macros.h" // for ARRAY_COUNT +#include "libc/string.h" +#include "macros.h" #define FILL_ALLOCBLOCK (1 << 0) #define FILL_FREEBLOCK (1 << 1) @@ -374,7 +374,7 @@ void* __osRealloc(Arena* arena, void* ptr, size_t newSize) { next2 = (void*)((uintptr_t)next + diff); node->next = next2; node->size = newSize; - __osMemcpy(next2, next, sizeof(ArenaNode)); + memmove(next2, next, sizeof(ArenaNode)); } else { // Create a new pointer and manually copy the data from the old pointer to the new one newPtr = __osMalloc(arena, newSize); diff --git a/src/boot/O2/fmodf.c b/src/boot/libm/fmodf.c similarity index 61% rename from src/boot/O2/fmodf.c rename to src/boot/libm/fmodf.c index 2f8aa74bfb..0c2df736dd 100644 --- a/src/boot/O2/fmodf.c +++ b/src/boot/libm/fmodf.c @@ -1,7 +1,7 @@ -#include "global.h" +#include "libc/math.h" -f32 fmodf(f32 dividend, f32 divisor) { - s32 quotient; +float fmodf(float dividend, float divisor) { + int quotient; if (divisor == 0.0f) { return 0.0f; diff --git a/src/code/cutscene_camera.c b/src/code/cutscene_camera.c index d5f3ef4a3b..53474bf889 100644 --- a/src/code/cutscene_camera.c +++ b/src/code/cutscene_camera.c @@ -1,4 +1,5 @@ #include "global.h" +#include "libc/string.h" static CutsceneCamera* sCurCsCamera; @@ -44,8 +45,8 @@ s32 CutsceneCamera_Init(Camera* camera, CutsceneCamera* csCamera) { sCurCsCamera = csCamera; - __osMemset(&csCamera->eyeInterp, 0, sizeof(CutsceneCameraInterp)); - __osMemset(&csCamera->atInterp, 0, sizeof(CutsceneCameraInterp)); + memset(&csCamera->eyeInterp, 0, sizeof(CutsceneCameraInterp)); + memset(&csCamera->atInterp, 0, sizeof(CutsceneCameraInterp)); csCamera->eyeInterp.type = csCamera->atInterp.type = CS_CAM_INTERP_OFF; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 0bfcafed06..5b58e939a8 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -6955,7 +6955,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, PlayState s16 curUID; s16 j; - __osMemset(camera, 0, sizeof(Camera)); + memset(camera, 0, sizeof(Camera)); camera->play = sCamPlayState = play; curUID = sCameraNextUID; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 98fdc84fb6..506d7d3589 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -65,6 +65,7 @@ Gfx* sSkyboxStarsDList; #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/gameplay_field_keep/gameplay_field_keep.h" #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" +#include "libc/string.h" // Data f32 sSandstormLerpScale = 0.0f; @@ -1298,7 +1299,7 @@ void Environment_UpdateLights(PlayState* play, EnvironmentContext* envCtx, Light AdjLightSettings spA4[4]; var_fs3 = 0.0f; - __osMemset(spA4, 0, sizeof(AdjLightSettings) * ARRAY_COUNT(spA4)); + memset(spA4, 0, sizeof(AdjLightSettings) * ARRAY_COUNT(spA4)); lightSettingsList = play->envCtx.lightSettingsList; if ((envCtx->lightSettingOverride != LIGHT_SETTING_OVERRIDE_NONE) && diff --git a/src/code/z_quake.c b/src/code/z_quake.c index 19db37c63c..9423983e1c 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -1,5 +1,6 @@ #include "prevent_bss_reordering.h" #include "global.h" +#include "libc/string.h" #include "z64quake.h" #include "z64view.h" @@ -174,7 +175,7 @@ QuakeRequest* Quake_RequestImpl(Camera* camera, u32 type) { s16 index = Quake_GetFreeIndex(); QuakeRequest* req = &sQuakeRequests[index]; - __osMemset(req, 0, sizeof(QuakeRequest)); + memset(req, 0, sizeof(QuakeRequest)); req->camera = camera; req->camId = camera->camId; diff --git a/src/libultra/voice/voicecrc.c b/src/libultra/voice/voicecrc.c index 36ffc4373a..58e405fbdb 100644 --- a/src/libultra/voice/voicecrc.c +++ b/src/libultra/voice/voicecrc.c @@ -4,6 +4,8 @@ * * For general information about CRC, see the crc.c file (that's a lot of c's!). */ + +#include "ultra64.h" #include "libc/stddef.h" #define VOICE_CRC_LENGTH 8 diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index a4fbcd21be..5ceabe10f3 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -239,10 +239,10 @@ 0x80096810 : "getwatchlo", 0x80096820 : "setwatchlo", 0x80096830 : "fmodf", - 0x80096880 : "__osMemset", - 0x800968B0 : "__osStrcmp", - 0x800968F0 : "__osStrcpy", - 0x80096930 : "__osMemcpy", + 0x80096880 : "memset", + 0x800968B0 : "strcmp", + 0x800968F0 : "strcpy", + 0x80096930 : "memmove", # .data section 0x800969C0 : "rspboot", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index d956be2d4d..11341ea5bd 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -480,10 +480,10 @@ 0x80096810:("__osGetWatchLo",), 0x80096820:("__osSetWatchLo",), 0x80096830:("fmodf",), - 0x80096880:("__osMemset",), - 0x800968B0:("__osStrcmp",), - 0x800968F0:("__osStrcpy",), - 0x80096930:("__osMemcpy",), + 0x80096880:("memset",), + 0x800968B0:("strcmp",), + 0x800968F0:("strcpy",), + 0x80096930:("memmove",), 0x800A5AC0:("EnAObj_Init",), 0x800A5B6C:("EnAObj_Destroy",), 0x800A5B98:("EnAObj_Idle",), diff --git a/tools/sizes/boot_functions.csv b/tools/sizes/boot_functions.csv index ef0ac1e974..2f01be07b3 100644 --- a/tools/sizes/boot_functions.csv +++ b/tools/sizes/boot_functions.csv @@ -477,7 +477,7 @@ asm/non_matchings/boot/sethwinterrupt/__osSetHWIntrRoutine.s,__osSetHWIntrRoutin asm/non_matchings/boot/getwatchlo/__osGetWatchLo.s,__osGetWatchLo,0x80096810,0x4 asm/non_matchings/boot/setwatchlo/__osSetWatchLo.s,__osSetWatchLo,0x80096820,0x4 asm/non_matchings/boot/fmodf/fmodf.s,fmodf,0x80096830,0x14 -asm/non_matchings/boot/__osMemset/__osMemset.s,__osMemset,0x80096880,0xC -asm/non_matchings/boot/__osStrcmp/__osStrcmp.s,__osStrcmp,0x800968B0,0x10 -asm/non_matchings/boot/__osStrcpy/__osStrcpy.s,__osStrcpy,0x800968F0,0x10 -asm/non_matchings/boot/__osMemcpy/__osMemcpy.s,__osMemcpy,0x80096930,0x24 +asm/non_matchings/boot/memset/memset.s,memset,0x80096880,0xC +asm/non_matchings/boot/strcmp/strcmp.s,strcmp,0x800968B0,0x10 +asm/non_matchings/boot/strcpy/strcpy.s,strcpy,0x800968F0,0x10 +asm/non_matchings/boot/memmove/memmove.s,memmove,0x80096930,0x24