summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcadmic <cadmic24@gmail.com>2024-08-19 22:15:24 -0700
committerGitHub <noreply@github.com>2024-08-20 01:15:24 -0400
commitec70295357c198c48660e2ab5670c15ef6a661cf (patch)
tree0c46c5493c7538ced1e2d1ab6344251bd2673d31
parentaba1bb88a3ed369ab450345a65f0176ceb0e482c (diff)
Move non-libultra libc functions to src/libc/ (#2055)
* Move non-libultra libc functions to src/libc/ * Add explicit nops in delay slots * Don't rely on CPP expanding undefined macros to 0 * Delete old Makefile rules * Fix type of memset()
-rw-r--r--Makefile16
-rw-r--r--include/functions.h4
-rw-r--r--spec18
-rw-r--r--src/code/__osMalloc.c12
-rw-r--r--src/code/code_80069420.c2
-rw-r--r--src/code/z_camera.c2
-rw-r--r--src/code/z_lib.c2
-rw-r--r--src/code/z_quake.c2
-rw-r--r--src/code/z_view.c2
-rw-r--r--src/gcc_fix/missing_gcc_functions.c32
-rw-r--r--src/libc/absf.s15
-rw-r--r--src/libc/fmodf.c (renamed from src/code/fmodf.c)0
-rw-r--r--src/libc/memmove.c (renamed from src/code/__osMemmove.c)2
-rw-r--r--src/libc/memset.c (renamed from src/code/__osMemset.c)4
-rw-r--r--src/libc/sqrt.s15
-rw-r--r--src/libultra/libc/absf.c9
-rw-r--r--src/libultra/libc/sqrt.c9
-rw-r--r--tools/disasm/ntsc-1.2/files_code.csv8
-rw-r--r--tools/disasm/ntsc-1.2/functions.txt4
19 files changed, 65 insertions, 93 deletions
diff --git a/Makefile b/Makefile
index a97bb3b3c..4728b9665 100644
--- a/Makefile
+++ b/Makefile
@@ -426,13 +426,9 @@ $(BUILD_DIR)/src/code/fault_drawer.o: OPTFLAGS := -O2 -g3
$(BUILD_DIR)/src/code/ucode_disas.o: OPTFLAGS := -O2 -g3
ifeq ($(DEBUG),1)
-$(BUILD_DIR)/src/code/fmodf.o: OPTFLAGS := -g
-$(BUILD_DIR)/src/code/__osMemset.o: OPTFLAGS := -g
-$(BUILD_DIR)/src/code/__osMemmove.o: OPTFLAGS := -g
+$(BUILD_DIR)/src/libc/%.o: OPTFLAGS := -g
else
-$(BUILD_DIR)/src/code/fmodf.o: OPTFLAGS := -O2
-$(BUILD_DIR)/src/code/__osMemset.o: OPTFLAGS := -O2
-$(BUILD_DIR)/src/code/__osMemmove.o: OPTFLAGS := -O2
+$(BUILD_DIR)/src/libc/%.o: OPTFLAGS := -O2
endif
$(BUILD_DIR)/src/audio/%.o: OPTFLAGS := -O2
@@ -444,14 +440,6 @@ $(BUILD_DIR)/src/audio/general.o: CFLAGS += -signed
$(BUILD_DIR)/src/audio/sfx.o: CFLAGS += -use_readwrite_const
$(BUILD_DIR)/src/audio/sequence.o: CFLAGS += -use_readwrite_const
-ifeq ($(DEBUG),1)
-$(BUILD_DIR)/src/libultra/libc/absf.o: OPTFLAGS := -O2 -g3
-$(BUILD_DIR)/src/libultra/libc/sqrt.o: OPTFLAGS := -O2 -g3
-else
-$(BUILD_DIR)/src/libultra/libc/absf.o: OPTFLAGS := -O2
-$(BUILD_DIR)/src/libultra/libc/sqrt.o: OPTFLAGS := -O2
-endif
-
$(BUILD_DIR)/src/libultra/libc/ll.o: OPTFLAGS := -O1
$(BUILD_DIR)/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32
$(BUILD_DIR)/src/libultra/libc/llcvt.o: OPTFLAGS := -O1
diff --git a/include/functions.h b/include/functions.h
index d9ef5170c..6837b57d9 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -1740,8 +1740,8 @@ void guMtxF2L(MtxF* m1, Mtx* m2);
void* osViGetCurrentFramebuffer(void);
s32 __osSpSetPc(void* pc);
f32 absf(f32);
-void* __osMemset(void* dest, s32 val, size_t len);
-void* __osMemmove(void* dest, const void* src, size_t len);
+void* memset(void* dest, int val, size_t len);
+void* memmove(void* dest, const void* src, size_t len);
void Message_UpdateOcarinaMemoryGame(PlayState* play);
u8 Message_ShouldAdvance(PlayState* play);
void Message_CloseTextbox(PlayState*);
diff --git a/spec b/spec
index 9d2bc053a..b91d55a22 100644
--- a/spec
+++ b/spec
@@ -69,7 +69,7 @@ beginseg
#endif
include "$(BUILD_DIR)/src/libultra/os/unmaptlball.o"
include "$(BUILD_DIR)/src/libultra/io/epidma.o"
-#if OOT_DEBUG || COMPILER_GCC
+#if OOT_DEBUG || defined(COMPILER_GCC)
include "$(BUILD_DIR)/src/libultra/libc/string.o"
#endif
include "$(BUILD_DIR)/src/libultra/os/invalicache.o"
@@ -128,6 +128,8 @@ beginseg
include "$(BUILD_DIR)/src/libultra/os/setwatchlo.o"
include "$(BUILD_DIR)/data/rsp_boot.text.o"
#ifdef COMPILER_GCC
+ include "$(BUILD_DIR)/src/libc/memset.o"
+ include "$(BUILD_DIR)/src/libc/memmove.o"
include "$(BUILD_DIR)/src/gcc_fix/missing_gcc_functions.o"
#endif
endseg
@@ -577,7 +579,7 @@ beginseg
#if !OOT_DEBUG
include "$(BUILD_DIR)/src/libultra/libc/xprintf.o"
#endif
-#if !OOT_DEBUG && !COMPILER_GCC
+#if !OOT_DEBUG && !defined(COMPILER_GCC)
include "$(BUILD_DIR)/src/libultra/libc/string.o"
#endif
include "$(BUILD_DIR)/src/libultra/io/sp.o"
@@ -636,11 +638,13 @@ beginseg
include "$(BUILD_DIR)/src/libultra/libc/llcvt.o"
include "$(BUILD_DIR)/src/libultra/io/vigetcurrframebuf.o"
include "$(BUILD_DIR)/src/libultra/io/spsetpc.o"
- include "$(BUILD_DIR)/src/libultra/libc/sqrt.o"
- include "$(BUILD_DIR)/src/libultra/libc/absf.o"
- include "$(BUILD_DIR)/src/code/fmodf.o"
- include "$(BUILD_DIR)/src/code/__osMemset.o"
- include "$(BUILD_DIR)/src/code/__osMemmove.o"
+ include "$(BUILD_DIR)/src/libc/sqrt.o"
+ include "$(BUILD_DIR)/src/libc/absf.o"
+ include "$(BUILD_DIR)/src/libc/fmodf.o"
+#ifndef COMPILER_GCC
+ include "$(BUILD_DIR)/src/libc/memset.o"
+ include "$(BUILD_DIR)/src/libc/memmove.o"
+#endif
// For some reason, the data sections of z_message and z_game_over are
// placed near the rodata sections of other files, so we first build this
// combined object before the final link.
diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c
index 5c4a423d2..bcd0132db 100644
--- a/src/code/__osMalloc.c
+++ b/src/code/__osMalloc.c
@@ -25,15 +25,15 @@
#define FILL_ALLOC_BLOCK(arena, alloc, size) \
if ((arena)->flag & FILL_ALLOC_BLOCK_FLAG) \
- __osMemset(alloc, BLOCK_ALLOC_MAGIC, size)
+ memset(alloc, BLOCK_ALLOC_MAGIC, size)
#define FILL_FREE_BLOCK_HEADER(arena, node) \
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
- __osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
+ memset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
#define FILL_FREE_BLOCK_CONTENTS(arena, node) \
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
- __osMemset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
+ memset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
#define CHECK_FREE_BLOCK(arena, node) \
if ((arena)->flag & CHECK_FREE_BLOCK_FLAG) \
@@ -179,7 +179,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
if (size2 > (s32)sizeof(ArenaNode)) {
#if OOT_DEBUG
- __osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2);
+ memset(firstNode, BLOCK_UNINIT_MAGIC, size2);
#endif
firstNode->next = NULL;
firstNode->prev = NULL;
@@ -210,7 +210,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) {
iter = arena->head;
while (iter != NULL) {
next = NODE_GET_NEXT(iter);
- __osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
+ memset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
iter = next;
}
@@ -635,7 +635,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
node->next = newNext;
node->size = newSize;
- __osMemmove(node->next, next, sizeof(ArenaNode));
+ memmove(node->next, next, sizeof(ArenaNode));
} else {
// "Allocate a new memory block and move the contents"
osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n");
diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c
index 9a190edcf..a08567dd6 100644
--- a/src/code/code_80069420.c
+++ b/src/code/code_80069420.c
@@ -27,7 +27,7 @@ void* MemCpy(void* dest, const void* src, s32 len) {
/**
* memset: sets `len` bytes to `val` starting at address `dest`.
*
- * @see There are two other memsets in this codebase, Lib_MemSet(), __osMemset().
+ * @see There are two other memsets in this codebase, Lib_MemSet(), memset().
* This one is unused.
*
* @param dest address to start at
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 019a4a895..9597e7c19 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -7449,7 +7449,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));
if (sInitRegs) {
s32 i;
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index 5eba9346f..d5f59a2a8 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -16,7 +16,7 @@
* - the arguments are in a different order,
* - `val` is a `u8` instead of the standard `s32`.
*
- * @see There are two other memsets in this codebase, __osMemset(), MemSet()
+ * @see There are two other memsets in this codebase, memset(), MemSet()
*
* @param dest address to start at
* @param len number of bytes to write
diff --git a/src/code/z_quake.c b/src/code/z_quake.c
index 317d05347..4c318b938 100644
--- a/src/code/z_quake.c
+++ b/src/code/z_quake.c
@@ -170,7 +170,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->cam = camera;
req->camId = camera->camId;
diff --git a/src/code/z_view.c b/src/code/z_view.c
index 31563b959..780fd7f40 100644
--- a/src/code/z_view.c
+++ b/src/code/z_view.c
@@ -24,7 +24,7 @@ View* View_New(GraphicsContext* gfxCtx) {
View* view = SYSTEM_ARENA_MALLOC(sizeof(View), "../z_view.c", 285);
if (view != NULL) {
- __osMemset(view, 0, sizeof(View));
+ memset(view, 0, sizeof(View));
View_Init(view, gfxCtx);
}
diff --git a/src/gcc_fix/missing_gcc_functions.c b/src/gcc_fix/missing_gcc_functions.c
index b95556937..76bf8e9db 100644
--- a/src/gcc_fix/missing_gcc_functions.c
+++ b/src/gcc_fix/missing_gcc_functions.c
@@ -26,38 +26,6 @@ int memcmp(const void* s1, const void* s2, size_t n) {
return 0;
}
-void* memset(void* str, int c, size_t n) {
- u8* m = str;
- size_t i;
-
- for (i = 0; i < n; i++) {
- m[i] = c;
- }
-
- return str;
-}
-
-void* memmove(void* dest, const void* src, size_t len) {
- u8* d = dest;
- const u8* s = src;
-
- if (d == s) {
- return dest;
- }
- if (d < s) {
- while (len--) {
- *d++ = *s++;
- }
- } else {
- d += len - 1;
- s += len - 1;
- while (len--) {
- *d-- = *s--;
- }
- }
- return dest;
-}
-
// Conversions involving 64-bit integer types required by the O32 MIPS ABI.
// f32 -> u64, negative values become 0
diff --git a/src/libc/absf.s b/src/libc/absf.s
new file mode 100644
index 000000000..9df0c0a38
--- /dev/null
+++ b/src/libc/absf.s
@@ -0,0 +1,15 @@
+#include "ultra64/asm.h"
+
+#if OOT_DEBUG
+.set noreorder
+#endif
+
+.section .text
+
+.balign 16
+
+LEAF(absf)
+ abs.s $f0, $f12
+ jr $ra
+ nop
+END(absf)
diff --git a/src/code/fmodf.c b/src/libc/fmodf.c
index 4ebec43bd..4ebec43bd 100644
--- a/src/code/fmodf.c
+++ b/src/libc/fmodf.c
diff --git a/src/code/__osMemmove.c b/src/libc/memmove.c
index 892fee5ee..8ff5ec5f6 100644
--- a/src/code/__osMemmove.c
+++ b/src/libc/memmove.c
@@ -11,7 +11,7 @@
*
* @return dest
*/
-void* __osMemmove(void* dest, const void* src, size_t len) {
+void* memmove(void* dest, const void* src, size_t len) {
u8* d = dest;
const u8* s = src;
diff --git a/src/code/__osMemset.c b/src/libc/memset.c
index 703d3a8c1..ec699c7ce 100644
--- a/src/code/__osMemset.c
+++ b/src/libc/memset.c
@@ -6,12 +6,12 @@
* @see There are two other memsets in this codebase, Lib_MemSet(), MemSet()
*
* @param dest address to start at
- * @param val value to write (s32, but interpreted as u8)
+ * @param val value to write (int, but interpreted as u8)
* @param len number of bytes to write
*
* @return dest
*/
-void* __osMemset(void* dest, s32 val, size_t len) {
+void* memset(void* dest, int val, size_t len) {
u8* ptr = dest;
while (len--) {
diff --git a/src/libc/sqrt.s b/src/libc/sqrt.s
new file mode 100644
index 000000000..b4246ec86
--- /dev/null
+++ b/src/libc/sqrt.s
@@ -0,0 +1,15 @@
+#include "ultra64/asm.h"
+
+#if OOT_DEBUG
+.set noreorder
+#endif
+
+.section .text
+
+.balign 16
+
+LEAF(sqrt)
+ sqrt.d $f0, $f12
+ jr $ra
+ nop
+END(sqrt)
diff --git a/src/libultra/libc/absf.c b/src/libultra/libc/absf.c
deleted file mode 100644
index 73c99f460..000000000
--- a/src/libultra/libc/absf.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "global.h"
-
-float absf(float n) {
-#ifndef __GNUC__
- return fabsf(n);
-#else
- return __builtin_fabsf(n);
-#endif
-}
diff --git a/src/libultra/libc/sqrt.c b/src/libultra/libc/sqrt.c
deleted file mode 100644
index a9a4403a3..000000000
--- a/src/libultra/libc/sqrt.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "global.h"
-
-double sqrt(double f) {
-#ifndef __GNUC__
- return sqrt(f);
-#else
- return __builtin_sqrt(f);
-#endif
-}
diff --git a/tools/disasm/ntsc-1.2/files_code.csv b/tools/disasm/ntsc-1.2/files_code.csv
index 47a07ef54..1a5d6d05c 100644
--- a/tools/disasm/ntsc-1.2/files_code.csv
+++ b/tools/disasm/ntsc-1.2/files_code.csv
@@ -195,10 +195,10 @@ C4A80,800D6160,src/libultra/os/getcurrfaultedthread
C4A90,800D6170,src/libultra/libc/llcvt
C4CA0,800D6380,src/libultra/io/vigetcurrframebuf
C4CE0,800D63C0,src/libultra/io/spsetpc
-C4D20,800D6400,src/libultra/libc/sqrt
-C4D30,800D6410,src/code/fmodf
-C4D80,800D6460,src/code/__osMemset
-C4DB0,800D6490,src/code/__osMemmove
+C4D20,800D6400,src/libc/sqrt
+C4D30,800D6410,src/libc/fmodf
+C4D80,800D6460,src/libc/memset
+C4DB0,800D6490,src/libc/memset
C4E40,800D6520,src/code/z_message
D0620,800E1D00,src/code/z_game_over
D0B60,800E2240,src/code/z_construct
diff --git a/tools/disasm/ntsc-1.2/functions.txt b/tools/disasm/ntsc-1.2/functions.txt
index 9d28a6964..2a9b367e7 100644
--- a/tools/disasm/ntsc-1.2/functions.txt
+++ b/tools/disasm/ntsc-1.2/functions.txt
@@ -3054,8 +3054,8 @@ osViGetCurrentFramebuffer = 0x800D6380; // type:func
__osSpSetPc = 0x800D63C0; // type:func
sqrt = 0x800D6400; // type:func
fmodf = 0x800D6410; // type:func
-__osMemset = 0x800D6460; // type:func
-__osMemmove = 0x800D6490; // type:func
+memset = 0x800D6460; // type:func
+memmove = 0x800D6490; // type:func
Message_ResetOcarinaNoteState = 0x800D6520; // type:func
Message_UpdateOcarinaMemoryGame = 0x800D661C; // type:func
Message_ShouldAdvance = 0x800D6740; // type:func