diff --git a/Makefile b/Makefile index 6b62c2e645..b202b95c02 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ endif # Check code syntax with host compiler CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -Wno-int-conversion -Wno-unused-but-set-variable -Wno-unused-label -CC_CHECK := gcc -fno-builtin -fsyntax-only -funsigned-char -fdiagnostics-color -std=gnu90 -D _LANGUAGE_C -D NON_MATCHING $(IINC) -include stdarg.h $(CHECK_WARNINGS) +CC_CHECK := gcc -fno-builtin -fsyntax-only -funsigned-char -fdiagnostics-color -std=gnu89 -D _LANGUAGE_C -D NON_MATCHING $(IINC) -nostdinc $(CHECK_WARNINGS) CPP := cpp ELF2ROM := tools/buildtools/elf2rom @@ -92,7 +92,7 @@ ASFLAGS := -march=vr4300 -32 -Iinclude MIPS_VERSION := -mips2 # we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff. -CFLAGS += -G 0 -non_shared -Xfullwarn -Xcpluscomm $(IINC) -Wab,-r4300_mul -woff 624,649,838,712 +CFLAGS += -G 0 -non_shared -Xfullwarn -Xcpluscomm $(IINC) -nostdinc -Wab,-r4300_mul -woff 624,649,838,712 ifeq ($(shell getconf LONG_BIT), 32) # Work around memory allocation bug in QEMU diff --git a/include/assert.h b/include/assert.h deleted file mode 100644 index 04831e48f1..0000000000 --- a/include/assert.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef _ASSERT_H_ -#define _ASSERT_H_ - -#endif diff --git a/include/convert.h b/include/convert.h index 456e4b1982..c453e18e3a 100644 --- a/include/convert.h +++ b/include/convert.h @@ -1,7 +1,7 @@ #ifndef _ULTRA64_CONVERT_H_ #define _ULTRA64_CONVERT_H_ -#include "stdint.h" +#include "libc/stdint.h" #define OS_CLOCK_RATE 62500000LL #define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) diff --git a/include/functions.h b/include/functions.h index 1cacc5fed2..ad01b7a82c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3,13 +3,6 @@ #include "z64.h" -float fabsf(float f); -#pragma intrinsic(fabsf) -float sqrtf(float f); -#pragma intrinsic(sqrtf) -double sqrt(double d); -#pragma intrinsic(sqrt) - void bootproc(void); void Idle_ThreadEntry(void* arg); void ViConfig_UpdateVi(u32 arg0); diff --git a/include/ichain.h b/include/ichain.h index 8b11121911..f9131545c2 100644 --- a/include/ichain.h +++ b/include/ichain.h @@ -1,6 +1,8 @@ #ifndef _ICHAIN_H_ #define _ICHAIN_H_ +#include "libc/stddef.h" + typedef struct { u32 cont: 1; u32 type: 4; @@ -8,8 +10,6 @@ typedef struct { s32 value: 16; } InitChainEntry; -#define OFFSETOF(structure, member) ((size_t)&(((structure*)0)->member)) - typedef enum { /* 0x0 */ ICHAINTYPE_U8, // sets byte /* 0x1 */ ICHAINTYPE_S8, @@ -38,7 +38,7 @@ typedef enum { * * cont ----- ICHAIN_CONTINUE (or ICHAIN_STOP) to continue (or stop) parsing */ #define ICHAIN(type, member, value, cont) \ - { cont, type, OFFSETOF(Actor, member), value } + { cont, type, offsetof(Actor, member), value } #define ICHAIN_U8(member, val, cont) ICHAIN(ICHAINTYPE_U8, member, val, cont) #define ICHAIN_S8(member, val, cont) ICHAIN(ICHAINTYPE_S8, member, val, cont) diff --git a/include/alloca.h b/include/libc/alloca.h similarity index 100% rename from include/alloca.h rename to include/libc/alloca.h diff --git a/include/libc/assert.h b/include/libc/assert.h new file mode 100644 index 0000000000..1bc72e3144 --- /dev/null +++ b/include/libc/assert.h @@ -0,0 +1,4 @@ +#ifndef ASSERT_H +#define ASSERT_H + +#endif diff --git a/include/math.h b/include/libc/math.h similarity index 74% rename from include/math.h rename to include/libc/math.h index 20fa352faa..c6756d959f 100644 --- a/include/math.h +++ b/include/libc/math.h @@ -1,5 +1,5 @@ -#ifndef _MATH_H_ -#define _MATH_H_ +#ifndef MATH_H +#define MATH_H #include "PR/ultratypes.h" @@ -26,4 +26,11 @@ typedef union { extern f32 __libm_qnan_f; +float fabsf(float f); +#pragma intrinsic(fabsf) +float sqrtf(float f); +#pragma intrinsic(sqrtf) +double sqrt(double d); +#pragma intrinsic(sqrt) + #endif diff --git a/include/stdarg.h b/include/libc/stdarg.h similarity index 96% rename from include/stdarg.h rename to include/libc/stdarg.h index 26a67e5801..77b8b8866c 100644 --- a/include/stdarg.h +++ b/include/libc/stdarg.h @@ -1,5 +1,5 @@ -#ifndef _STDARG_H_ -#define _STDARG_H_ +#ifndef STDARG_H +#define STDARG_H #include "ultra64.h" @@ -41,5 +41,6 @@ typedef char *va_list; : __va_stack_arg(list, mode))))[-1] #define va_end(__list) -#endif -#endif +#endif /* __GNUC__ */ + +#endif /* STDARG_H */ diff --git a/include/stdbool.h b/include/libc/stdbool.h similarity index 72% rename from include/stdbool.h rename to include/libc/stdbool.h index 519806b310..d441054c1d 100644 --- a/include/stdbool.h +++ b/include/libc/stdbool.h @@ -1,5 +1,5 @@ -#ifndef _STDBOOL -#define _STDBOOL +#ifndef STDBOOL +#define STDBOOL #define __bool_true_false_are_defined 1 @@ -11,4 +11,4 @@ #endif /* __cplusplus */ -#endif /* _STDBOOL */ +#endif /* STDBOOL */ diff --git a/include/libc/stddef.h b/include/libc/stddef.h new file mode 100644 index 0000000000..4f55e5725e --- /dev/null +++ b/include/libc/stddef.h @@ -0,0 +1,20 @@ +#ifndef STDDEF_H +#define STDDEF_H + +#include "PR/ultratypes.h" + +typedef u32 size_t; + +typedef s32 ptrdiff_t; + +#ifndef NULL +#define NULL (void*)0 +#endif + +#ifdef __GNUC__ +#define offsetof(structure, member) __builtin_offsetof (structure, member) +#else +#define offsetof(structure, member) ((size_t)&(((structure*)0)->member)) +#endif + +#endif /* STDDEF_H */ diff --git a/include/stdint.h b/include/libc/stdint.h similarity index 86% rename from include/stdint.h rename to include/libc/stdint.h index 67e9e68622..1696615a7c 100644 --- a/include/stdint.h +++ b/include/libc/stdint.h @@ -1,7 +1,7 @@ -#ifndef _STDINT_H_ -#define _STDINT_H_ +#ifndef STDINT_H +#define STDINT_H -#include "ultra64.h" +#include "PR/ultratypes.h" typedef s32 intptr_t; typedef u32 uintptr_t; @@ -26,4 +26,4 @@ typedef u32 uintptr_t; #define UINTPTR_MAX 0xffffffff -#endif /* _STDINT_H_ */ +#endif /* STDINT_H */ diff --git a/include/stdlib.h b/include/libc/stdlib.h similarity index 77% rename from include/stdlib.h rename to include/libc/stdlib.h index a7b44961a9..57d352a13c 100644 --- a/include/stdlib.h +++ b/include/libc/stdlib.h @@ -1,27 +1,25 @@ -#ifndef _STDLIB_H_ -#define _STDLIB_H_ +#ifndef STDLIB_H +#define STDLIB_H + +#include "libc/stddef.h" typedef struct { /* 0x0 */ int quot; /* 0x4 */ int rem; } div_t; - typedef struct { /* 0x0 */ long quot; /* 0x4 */ long rem; } ldiv_t; - typedef struct { /* 0x0 */ long long quot; /* 0x8 */ long long rem; } lldiv_t; -typedef unsigned long size_t; - typedef int ssize_t; typedef long wchar_t; -#endif +#endif /* STDLIB_H */ diff --git a/include/macros.h b/include/macros.h index 7dd84fc8ee..2cff3c814d 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,7 +1,7 @@ #ifndef _MACROS_H_ #define _MACROS_H_ -#include "stdint.h" +#include "libc/stdint.h" #include "convert.h" #include "z64.h" diff --git a/include/os.h b/include/os.h index f892398748..e9a5da37dc 100644 --- a/include/os.h +++ b/include/os.h @@ -1,7 +1,7 @@ #ifndef _OS_H_ #define _OS_H_ -#include "stdlib.h" +#include "libc/stdlib.h" #include "ultra64/thread.h" #include "ultra64/message.h" diff --git a/include/osint.h b/include/osint.h index f4da044c60..71781ab6da 100644 --- a/include/osint.h +++ b/include/osint.h @@ -3,7 +3,7 @@ // TODO should be in libultra/os -#include "stdarg.h" +#include "libc/stdarg.h" #include "os.h" #include "os_internal.h" #include "ultraerror.h" diff --git a/include/xstdio.h b/include/xstdio.h index bb297e5900..102a25ee4c 100644 --- a/include/xstdio.h +++ b/include/xstdio.h @@ -1,6 +1,7 @@ #ifndef _XSTDIO_H_ #define _XSTDIO_H_ -#include "stdarg.h" + +#include "libc/stdarg.h" typedef struct { /* 0x0 */ union { diff --git a/include/z64.h b/include/z64.h index 6def660e08..99f05d653e 100644 --- a/include/z64.h +++ b/include/z64.h @@ -1,16 +1,17 @@ #ifndef _Z64_H_ #define _Z64_H_ -#include "stdarg.h" -#include "stdbool.h" -#include "stdint.h" +#include "libc/math.h" +#include "libc/stdarg.h" +#include "libc/stdbool.h" +#include "libc/stddef.h" +#include "libc/stdint.h" +#include "libc/stdlib.h" #include "ultra64.h" #include "io/controller.h" #include "osint.h" -#include "math.h" #include "os.h" -#include "stdlib.h" #include "xstdio.h" #include "bgm.h" diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c index 72d154d700..b71ba72341 100644 --- a/src/libultra/gu/cosf.c +++ b/src/libultra/gu/cosf.c @@ -1,4 +1,4 @@ -#include "math.h" +#include "libc/math.h" #include "macros.h" // A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9 diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c index 5f3455ec54..746d141a4a 100644 --- a/src/libultra/gu/sinf.c +++ b/src/libultra/gu/sinf.c @@ -1,4 +1,4 @@ -#include "math.h" +#include "libc/math.h" #include "macros.h" // A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9 diff --git a/src/libultra/gu/sins.c b/src/libultra/gu/sins.c index 69b3b7e391..39bc7ce0c1 100644 --- a/src/libultra/gu/sins.c +++ b/src/libultra/gu/sins.c @@ -1,4 +1,4 @@ -#include "math.h" +#include "libc/math.h" static s16 sintable[0x400] = { 0x0000, 0x0032, 0x0064, 0x0096, 0x00C9, 0x00FB, 0x012D, 0x0160, 0x0192, 0x01C4, 0x01F7, 0x0229, 0x025B, 0x028E, diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c index 40d2864798..6bdb2ccb3d 100644 --- a/src/libultra/os/virtualtophysical.c +++ b/src/libultra/os/virtualtophysical.c @@ -1,6 +1,6 @@ #include "PR/ultratypes.h" #include "osint.h" -#include "stdint.h" +#include "libc/stdint.h" #include "global.h" uintptr_t osVirtualToPhysical(void* virtualAddress) { diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index d58f7ac856..550bbbc8e0 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -5,7 +5,7 @@ */ #include "z_select.h" -#include "alloca.h" +#include "libc/alloca.h" #include "overlays/gamestates/ovl_title/z_title.h" void Select_LoadTitle(SelectContext* this) {