Add `stddef.h` and libc headers cleanup (#396)

* Move headers to include/libc

* stddef

* move math.h

* General cleanup

* move fabs, sqrtf and sqrt to math.h

* move alloca and assert

* whoops
This commit is contained in:
Anghelo Carvajal 2021-11-05 23:44:58 -03:00 committed by GitHub
parent 49f55ff005
commit e70a8fbb99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 72 additions and 51 deletions

View File

@ -79,7 +79,7 @@ endif
# Check code syntax with host compiler # 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 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 CPP := cpp
ELF2ROM := tools/buildtools/elf2rom ELF2ROM := tools/buildtools/elf2rom
@ -92,7 +92,7 @@ ASFLAGS := -march=vr4300 -32 -Iinclude
MIPS_VERSION := -mips2 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. # 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) ifeq ($(shell getconf LONG_BIT), 32)
# Work around memory allocation bug in QEMU # Work around memory allocation bug in QEMU

View File

@ -1,4 +0,0 @@
#ifndef _ASSERT_H_
#define _ASSERT_H_
#endif

View File

@ -1,7 +1,7 @@
#ifndef _ULTRA64_CONVERT_H_ #ifndef _ULTRA64_CONVERT_H_
#define _ULTRA64_CONVERT_H_ #define _ULTRA64_CONVERT_H_
#include "stdint.h" #include "libc/stdint.h"
#define OS_CLOCK_RATE 62500000LL #define OS_CLOCK_RATE 62500000LL
#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) #define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4)

View File

@ -3,13 +3,6 @@
#include "z64.h" #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 bootproc(void);
void Idle_ThreadEntry(void* arg); void Idle_ThreadEntry(void* arg);
void ViConfig_UpdateVi(u32 arg0); void ViConfig_UpdateVi(u32 arg0);

View File

@ -1,6 +1,8 @@
#ifndef _ICHAIN_H_ #ifndef _ICHAIN_H_
#define _ICHAIN_H_ #define _ICHAIN_H_
#include "libc/stddef.h"
typedef struct { typedef struct {
u32 cont: 1; u32 cont: 1;
u32 type: 4; u32 type: 4;
@ -8,8 +10,6 @@ typedef struct {
s32 value: 16; s32 value: 16;
} InitChainEntry; } InitChainEntry;
#define OFFSETOF(structure, member) ((size_t)&(((structure*)0)->member))
typedef enum { typedef enum {
/* 0x0 */ ICHAINTYPE_U8, // sets byte /* 0x0 */ ICHAINTYPE_U8, // sets byte
/* 0x1 */ ICHAINTYPE_S8, /* 0x1 */ ICHAINTYPE_S8,
@ -38,7 +38,7 @@ typedef enum {
* * cont ----- ICHAIN_CONTINUE (or ICHAIN_STOP) to continue (or stop) parsing * * cont ----- ICHAIN_CONTINUE (or ICHAIN_STOP) to continue (or stop) parsing
*/ */
#define ICHAIN(type, member, value, cont) \ #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_U8(member, val, cont) ICHAIN(ICHAINTYPE_U8, member, val, cont)
#define ICHAIN_S8(member, val, cont) ICHAIN(ICHAINTYPE_S8, member, val, cont) #define ICHAIN_S8(member, val, cont) ICHAIN(ICHAINTYPE_S8, member, val, cont)

4
include/libc/assert.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef ASSERT_H
#define ASSERT_H
#endif

View File

@ -1,5 +1,5 @@
#ifndef _MATH_H_ #ifndef MATH_H
#define _MATH_H_ #define MATH_H
#include "PR/ultratypes.h" #include "PR/ultratypes.h"
@ -26,4 +26,11 @@ typedef union {
extern f32 __libm_qnan_f; 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 #endif

View File

@ -1,5 +1,5 @@
#ifndef _STDARG_H_ #ifndef STDARG_H
#define _STDARG_H_ #define STDARG_H
#include "ultra64.h" #include "ultra64.h"
@ -41,5 +41,6 @@ typedef char *va_list;
: __va_stack_arg(list, mode))))[-1] : __va_stack_arg(list, mode))))[-1]
#define va_end(__list) #define va_end(__list)
#endif #endif /* __GNUC__ */
#endif
#endif /* STDARG_H */

View File

@ -1,5 +1,5 @@
#ifndef _STDBOOL #ifndef STDBOOL
#define _STDBOOL #define STDBOOL
#define __bool_true_false_are_defined 1 #define __bool_true_false_are_defined 1
@ -11,4 +11,4 @@
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* _STDBOOL */ #endif /* STDBOOL */

20
include/libc/stddef.h Normal file
View File

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

View File

@ -1,7 +1,7 @@
#ifndef _STDINT_H_ #ifndef STDINT_H
#define _STDINT_H_ #define STDINT_H
#include "ultra64.h" #include "PR/ultratypes.h"
typedef s32 intptr_t; typedef s32 intptr_t;
typedef u32 uintptr_t; typedef u32 uintptr_t;
@ -26,4 +26,4 @@ typedef u32 uintptr_t;
#define UINTPTR_MAX 0xffffffff #define UINTPTR_MAX 0xffffffff
#endif /* _STDINT_H_ */ #endif /* STDINT_H */

View File

@ -1,27 +1,25 @@
#ifndef _STDLIB_H_ #ifndef STDLIB_H
#define _STDLIB_H_ #define STDLIB_H
#include "libc/stddef.h"
typedef struct { typedef struct {
/* 0x0 */ int quot; /* 0x0 */ int quot;
/* 0x4 */ int rem; /* 0x4 */ int rem;
} div_t; } div_t;
typedef struct { typedef struct {
/* 0x0 */ long quot; /* 0x0 */ long quot;
/* 0x4 */ long rem; /* 0x4 */ long rem;
} ldiv_t; } ldiv_t;
typedef struct { typedef struct {
/* 0x0 */ long long quot; /* 0x0 */ long long quot;
/* 0x8 */ long long rem; /* 0x8 */ long long rem;
} lldiv_t; } lldiv_t;
typedef unsigned long size_t;
typedef int ssize_t; typedef int ssize_t;
typedef long wchar_t; typedef long wchar_t;
#endif #endif /* STDLIB_H */

View File

@ -1,7 +1,7 @@
#ifndef _MACROS_H_ #ifndef _MACROS_H_
#define _MACROS_H_ #define _MACROS_H_
#include "stdint.h" #include "libc/stdint.h"
#include "convert.h" #include "convert.h"
#include "z64.h" #include "z64.h"

View File

@ -1,7 +1,7 @@
#ifndef _OS_H_ #ifndef _OS_H_
#define _OS_H_ #define _OS_H_
#include "stdlib.h" #include "libc/stdlib.h"
#include "ultra64/thread.h" #include "ultra64/thread.h"
#include "ultra64/message.h" #include "ultra64/message.h"

View File

@ -3,7 +3,7 @@
// TODO should be in libultra/os // TODO should be in libultra/os
#include "stdarg.h" #include "libc/stdarg.h"
#include "os.h" #include "os.h"
#include "os_internal.h" #include "os_internal.h"
#include "ultraerror.h" #include "ultraerror.h"

View File

@ -1,6 +1,7 @@
#ifndef _XSTDIO_H_ #ifndef _XSTDIO_H_
#define _XSTDIO_H_ #define _XSTDIO_H_
#include "stdarg.h"
#include "libc/stdarg.h"
typedef struct { typedef struct {
/* 0x0 */ union { /* 0x0 */ union {

View File

@ -1,16 +1,17 @@
#ifndef _Z64_H_ #ifndef _Z64_H_
#define _Z64_H_ #define _Z64_H_
#include "stdarg.h" #include "libc/math.h"
#include "stdbool.h" #include "libc/stdarg.h"
#include "stdint.h" #include "libc/stdbool.h"
#include "libc/stddef.h"
#include "libc/stdint.h"
#include "libc/stdlib.h"
#include "ultra64.h" #include "ultra64.h"
#include "io/controller.h" #include "io/controller.h"
#include "osint.h" #include "osint.h"
#include "math.h"
#include "os.h" #include "os.h"
#include "stdlib.h"
#include "xstdio.h" #include "xstdio.h"
#include "bgm.h" #include "bgm.h"

View File

@ -1,4 +1,4 @@
#include "math.h" #include "libc/math.h"
#include "macros.h" #include "macros.h"
// A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9 // A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9

View File

@ -1,4 +1,4 @@
#include "math.h" #include "libc/math.h"
#include "macros.h" #include "macros.h"
// A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9 // A slightly tweaked form of the coefficients of the Maclaurin series of sine up to x^9

View File

@ -1,4 +1,4 @@
#include "math.h" #include "libc/math.h"
static s16 sintable[0x400] = { static s16 sintable[0x400] = {
0x0000, 0x0032, 0x0064, 0x0096, 0x00C9, 0x00FB, 0x012D, 0x0160, 0x0192, 0x01C4, 0x01F7, 0x0229, 0x025B, 0x028E, 0x0000, 0x0032, 0x0064, 0x0096, 0x00C9, 0x00FB, 0x012D, 0x0160, 0x0192, 0x01C4, 0x01F7, 0x0229, 0x025B, 0x028E,

View File

@ -1,6 +1,6 @@
#include "PR/ultratypes.h" #include "PR/ultratypes.h"
#include "osint.h" #include "osint.h"
#include "stdint.h" #include "libc/stdint.h"
#include "global.h" #include "global.h"
uintptr_t osVirtualToPhysical(void* virtualAddress) { uintptr_t osVirtualToPhysical(void* virtualAddress) {

View File

@ -5,7 +5,7 @@
*/ */
#include "z_select.h" #include "z_select.h"
#include "alloca.h" #include "libc/alloca.h"
#include "overlays/gamestates/ovl_title/z_title.h" #include "overlays/gamestates/ovl_title/z_title.h"
void Select_LoadTitle(SelectContext* this) { void Select_LoadTitle(SelectContext* this) {