diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-11-05 23:44:58 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-05 23:44:58 -0300 |
| commit | e70a8fbb992eb05d606406ae70974e56bcf912dc (patch) | |
| tree | dd94abeae41e75bb177bd7e4c3a04bc38262f20f /include/libc | |
| parent | 49f55ff0052340d29cffe2767fdc7d2ee5adb9f4 (diff) | |
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
Diffstat (limited to 'include/libc')
| -rw-r--r-- | include/libc/alloca.h | 7 | ||||
| -rw-r--r-- | include/libc/assert.h | 4 | ||||
| -rw-r--r-- | include/libc/math.h | 36 | ||||
| -rw-r--r-- | include/libc/stdarg.h | 46 | ||||
| -rw-r--r-- | include/libc/stdbool.h | 14 | ||||
| -rw-r--r-- | include/libc/stddef.h | 20 | ||||
| -rw-r--r-- | include/libc/stdint.h | 29 | ||||
| -rw-r--r-- | include/libc/stdlib.h | 25 |
8 files changed, 181 insertions, 0 deletions
diff --git a/include/libc/alloca.h b/include/libc/alloca.h new file mode 100644 index 000000000..4e8720f7e --- /dev/null +++ b/include/libc/alloca.h @@ -0,0 +1,7 @@ +#ifndef ALLOCA_H +#define ALLOCA_H + +void* alloca(u32); +#define alloca __builtin_alloca + +#endif diff --git a/include/libc/assert.h b/include/libc/assert.h new file mode 100644 index 000000000..1bc72e314 --- /dev/null +++ b/include/libc/assert.h @@ -0,0 +1,4 @@ +#ifndef ASSERT_H +#define ASSERT_H + +#endif diff --git a/include/libc/math.h b/include/libc/math.h new file mode 100644 index 000000000..c6756d959 --- /dev/null +++ b/include/libc/math.h @@ -0,0 +1,36 @@ +#ifndef MATH_H +#define MATH_H + +#include "PR/ultratypes.h" + +#define M_PI 3.14159265358979323846f +#define M_SQRT2 1.41421356237309504880f +#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */ +#define FLT_MAX 340282346638528859811704183484516925440.0f +#define SHT_MAX 32767.0f +#define SHT_MINV (1.0f / SHT_MAX) +#define DEGTORAD(x) ((x) * (M_PI / 180.0f)) + +typedef union { + f64 d; + struct { + u32 hi; + u32 lo; + } word; +} du; + +typedef union { + u32 i; + f32 f; +} fu; + +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/libc/stdarg.h b/include/libc/stdarg.h new file mode 100644 index 000000000..77b8b8866 --- /dev/null +++ b/include/libc/stdarg.h @@ -0,0 +1,46 @@ +#ifndef STDARG_H +#define STDARG_H + +#include "ultra64.h" + +// When building with GCC, use the official vaarg macros to avoid warnings +// and possibly bad codegen. +#ifdef __GNUC__ +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#else + +typedef char *va_list; +#define _FP 1 +#define _INT 0 +#define _STRUCT 2 + +#define _VA_FP_SAVE_AREA 0x10 +#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) +#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) + +#define __va_stack_arg(list, mode) \ + ( \ + ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ + _VA_ALIGN(sizeof(mode), 4)), \ + (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) + +#define __va_double_arg(list, mode) \ + ( \ + (((long)list & 0x1) /* 1 byte aligned? */ \ + ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ + : (((long)list & 0x2) /* 2 byte aligned? */ \ + ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ + : __va_stack_arg(list, mode)))) + +#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ + __builtin_alignof(mode) == sizeof(double)) \ + ? __va_double_arg(list, mode) \ + : __va_stack_arg(list, mode))))[-1] +#define va_end(__list) + +#endif /* __GNUC__ */ + +#endif /* STDARG_H */ diff --git a/include/libc/stdbool.h b/include/libc/stdbool.h new file mode 100644 index 000000000..d441054c1 --- /dev/null +++ b/include/libc/stdbool.h @@ -0,0 +1,14 @@ +#ifndef STDBOOL +#define STDBOOL + +#define __bool_true_false_are_defined 1 + +#ifndef __cplusplus + +#define bool u32 +#define false 0 +#define true 1 + +#endif /* __cplusplus */ + +#endif /* STDBOOL */ diff --git a/include/libc/stddef.h b/include/libc/stddef.h new file mode 100644 index 000000000..4f55e5725 --- /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/libc/stdint.h b/include/libc/stdint.h new file mode 100644 index 000000000..1696615a7 --- /dev/null +++ b/include/libc/stdint.h @@ -0,0 +1,29 @@ +#ifndef STDINT_H +#define STDINT_H + +#include "PR/ultratypes.h" + +typedef s32 intptr_t; +typedef u32 uintptr_t; + +#define INT8_MIN (-0x80) +#define INT16_MIN (-0x8000) +#define INT32_MIN (-0x80000000) +#define INT64_MIN (-0x8000000000000000) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffff + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffff +#define UINT64_MAX 0xffffffffffffffff + +#define INTPTR_MIN (-0x80000000) +#define INTPTR_MAX 0x7fffffff +#define UINTPTR_MAX 0xffffffff + + +#endif /* STDINT_H */ diff --git a/include/libc/stdlib.h b/include/libc/stdlib.h new file mode 100644 index 000000000..57d352a13 --- /dev/null +++ b/include/libc/stdlib.h @@ -0,0 +1,25 @@ +#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 int ssize_t; + +typedef long wchar_t; + +#endif /* STDLIB_H */ |
