Organize `libc` and `libm` files (#1499)

* memmove

* strcpy

* strcmp

* memset

* fmodf

* fix some missing includes

* Remove libc header dependencies on libultra

* fix

* review
This commit is contained in:
Anghelo Carvajal 2023-11-27 23:01:14 -03:00 committed by GitHub
parent 2fdcdd91b3
commit 7649cd309a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 77 additions and 59 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -17,4 +17,6 @@ float fabsf(float f);
double sqrt(double d);
#pragma intrinsic(sqrt)
float fmodf(float dividend, float divisor);
#endif

View File

@ -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)

View File

@ -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

10
spec
View File

@ -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

View File

@ -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;
}

View File

@ -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;

12
src/boot/libc/memset.c Normal file
View File

@ -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;
}

View File

@ -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;
}

View File

@ -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') {

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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) &&

View File

@ -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;

View File

@ -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

View File

@ -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",

View File

@ -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",),

View File

@ -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

1 asm/non_matchings/boot/boot_main/bootproc.s bootproc 0x80080060 0x3C
477 asm/non_matchings/boot/getwatchlo/__osGetWatchLo.s __osGetWatchLo 0x80096810 0x4
478 asm/non_matchings/boot/setwatchlo/__osSetWatchLo.s __osSetWatchLo 0x80096820 0x4
479 asm/non_matchings/boot/fmodf/fmodf.s fmodf 0x80096830 0x14
480 asm/non_matchings/boot/__osMemset/__osMemset.s asm/non_matchings/boot/memset/memset.s __osMemset memset 0x80096880 0xC
481 asm/non_matchings/boot/__osStrcmp/__osStrcmp.s asm/non_matchings/boot/strcmp/strcmp.s __osStrcmp strcmp 0x800968B0 0x10
482 asm/non_matchings/boot/__osStrcpy/__osStrcpy.s asm/non_matchings/boot/strcpy/strcpy.s __osStrcpy strcpy 0x800968F0 0x10
483 asm/non_matchings/boot/__osMemcpy/__osMemcpy.s asm/non_matchings/boot/memmove/memmove.s __osMemcpy memmove 0x80096930 0x24