summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-03-28 23:42:56 -0300
committerGitHub <noreply@github.com>2023-03-29 03:42:56 +0100
commitd66a21685f45d130f980e8a5ec7b08cfe189e40b (patch)
treef11b3b09dc5772e419fe08d3d0ead4e778def57f /include
parent6a5e64cc4c26398cc607bb02cdc12a056ddf42d1 (diff)
Initial repo setup (#1)
* git subrepo clone git@github.com:ethteck/splat.git tools/splat subrepo: subdir: "tools/splat" merged: "4fec014" upstream: origin: "git@github.com:ethteck/splat.git" branch: "master" commit: "4fec014" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * gitignore * decompress_baserom.py * Initial yaml * run flib * more yaml stuff * Builds an uncompressed ROM * setup ido download * git subrepo clone git@github.com:simonlindholm/asm-differ.git tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "ae40866" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "ae40866" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone git@github.com:simonlindholm/asm-processor.git tools/asm-processor subrepo: subdir: "tools/asm-processor" merged: "bbd86ea" upstream: origin: "git@github.com:simonlindholm/asm-processor.git" branch: "main" commit: "bbd86ea" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo clone (merge) git@github.com:EllipticEllipsis/fado.git tools/fado subrepo: subdir: "tools/fado" merged: "8d896ee" upstream: origin: "git@github.com:EllipticEllipsis/fado.git" branch: "master" commit: "8d896ee" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido in makefile * data and rodata * add automatic file splits * bootstrap most symbol_addrs * git subrepo clone --branch=irix git@github.com:hensldm/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "0d1e095" upstream: origin: "git@github.com:hensldm/ultralib.git" branch: "irix" commit: "0d1e095" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * setup ido building * various tooling * git subrepo pull tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "857b398" upstream: origin: "git@github.com:simonlindholm/asm-differ.git" branch: "main" commit: "857b398" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Change defines to match IDO * review * newlin * update gitignore * Windows error * D_01000000 * yeet settings.json * yeet * git subrepo clone git@github.com:decompals/ultralib.git lib/ultralib subrepo: subdir: "lib/ultralib" merged: "d03b2a3" upstream: origin: "git@github.com:decompals/ultralib.git" branch: "main" commit: "d03b2a3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * clangformat and clangtidy * Setup a bunch of headers * bootstrap boot and code functions and variables headers * global.h * update format.py includes * -D_MIPS_SZLONG=32 * format.py: --verbose * Update tools/decompress_baserom.py Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> * Add libc to global.h * review * yeet saved_regs * yeet headers * yeet _MSC_VER * more header cleanup * add readme licensing note --------- Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/alignment.h33
-rw-r--r--include/attributes.h39
-rw-r--r--include/global.h19
-rw-r--r--include/libc/assert.h23
-rw-r--r--include/libc/stdbool.h30
-rw-r--r--include/libc/stddef.h25
-rw-r--r--include/libc/stdint.h29
-rw-r--r--include/macro.inc87
-rw-r--r--include/macros.h18
-rw-r--r--include/other_types.h11
-rw-r--r--include/segment_symbols.h66
-rw-r--r--include/stack.h14
-rw-r--r--include/unk.h19
-rw-r--r--include/unknown_structs.h10
14 files changed, 423 insertions, 0 deletions
diff --git a/include/alignment.h b/include/alignment.h
new file mode 100644
index 0000000..9fb3b57
--- /dev/null
+++ b/include/alignment.h
@@ -0,0 +1,33 @@
+#ifndef ALIGNMENT_H
+#define ALIGNMENT_H
+
+#include "attributes.h"
+
+#define ALIGN4(val) (((val) + 3) & ~3)
+#define ALIGN8(val) (((val) + 7) & ~7)
+#define ALIGN16(val) (((val) + 0xF) & ~0xF)
+#define ALIGN32(val) (((val) + 0x1F) & ~0x1F)
+#define ALIGN64(val) (((val) + 0x3F) & ~0x3F)
+#define ALIGN128(val) (((val) + 0x7F) & ~0x7F)
+#define ALIGN256(val) (((val) + 0xFF) & ~0xFF)
+
+
+#ifndef ALIGNED8
+#define ALIGNED8 __attribute__ ((aligned (8)))
+#endif
+
+#ifndef ALIGNOF
+#ifdef __sgi /* IDO compiler */
+#define ALIGNOF(x) __builtin_alignof(x)
+#elif (__STDC_VERSION__ >= 201112L) /* C11 */
+#define ALIGNOF(x) _Alignof(x)
+#else /* __GNUC__ */
+#define ALIGNOF(x) __alignof__(x)
+#endif
+#endif
+
+#define ALIGN_MASK(n) (~((n) - 1))
+
+#define ALIGNOF_MASK(x) ALIGN_MASK(ALIGNOF(x))
+
+#endif
diff --git a/include/attributes.h b/include/attributes.h
new file mode 100644
index 0000000..c2045fa
--- /dev/null
+++ b/include/attributes.h
@@ -0,0 +1,39 @@
+#ifndef ATTRIBUTES_H
+#define ATTRIBUTES_H
+
+
+#if (!defined(__GNUC__) && !defined(__clang__)) || defined(M2CTX) || defined(__sgi)
+ #ifndef __attribute__
+ #define __attribute__(x)
+ #endif
+#endif
+
+
+#ifndef FALLTHROUGH
+ #if __STDC_VERSION__ >= 202000L
+ #define FALLTHROUGH [[fallthrough]]
+ #else
+ #define FALLTHROUGH __attribute__((fallthrough))
+ #endif
+#endif
+
+#ifndef NORETURN
+ #if __STDC_VERSION__ >= 202000L
+ #define NORETURN [[noreturn]]
+ #elif __STDC_VERSION__ >= 201112L
+ #define NORETURN _Noreturn
+ #else
+ #define NORETURN __attribute__((noreturn))
+ #endif
+#endif
+
+#ifndef UNUSED
+ #if __STDC_VERSION__ >= 202000L
+ #define UNUSED [[maybe_unused]]
+ #else
+ #define UNUSED __attribute__((unused))
+ #endif
+#endif
+
+
+#endif
diff --git a/include/global.h b/include/global.h
new file mode 100644
index 0000000..6d84d8a
--- /dev/null
+++ b/include/global.h
@@ -0,0 +1,19 @@
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+#include "ultra64.h"
+
+#include "libc/assert.h"
+#include "libc/stdbool.h"
+#include "libc/stddef.h"
+#include "libc/stdint.h"
+
+#include "attributes.h"
+#include "alignment.h"
+#include "other_types.h"
+#include "unk.h"
+#include "unknown_structs.h"
+
+#include "macros.h"
+
+#endif
diff --git a/include/libc/assert.h b/include/libc/assert.h
new file mode 100644
index 0000000..a9ecef0
--- /dev/null
+++ b/include/libc/assert.h
@@ -0,0 +1,23 @@
+#ifndef LIBC_ASSERT_H
+#define LIBC_ASSERT_H
+
+// Runtime assertions
+
+// TODO
+
+// Static/compile-time assertions
+
+#if __STDC_VERSION__ >= 201112L
+# define static_assert(cond, msg) _Static_assert(cond, msg)
+#else
+# ifndef GLUE
+# define GLUE(a, b) a##b
+# endif
+# ifndef GLUE2
+# define GLUE2(a, b) GLUE(a, b)
+# endif
+
+# define static_assert(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1]
+#endif
+
+#endif
diff --git a/include/libc/stdbool.h b/include/libc/stdbool.h
new file mode 100644
index 0000000..d3f951b
--- /dev/null
+++ b/include/libc/stdbool.h
@@ -0,0 +1,30 @@
+#ifndef LIBC_STDBOOL_H
+#define LIBC_STDBOOL_H
+
+#ifndef __bool_true_false_are_defined
+#define __bool_true_false_are_defined 1
+#endif
+
+#ifndef __cplusplus
+
+#if (__STDC_VERSION__ >= 199901L) && !defined(PERMUTER)
+#define bool _Bool
+#define false 0
+#define true 1
+#elif CC_CHECK
+// A way to enforce bools to not be treated the same as s32 by the host compiler
+// This has to be an ifdef because an enum-return-type doesn't match on `return (thing1) && (thing2);` patterns
+typedef enum bool {
+ false,
+ true
+} bool;
+#else
+typedef int bool;
+
+#define false 0
+#define true 1
+#endif
+
+#endif /* __cplusplus */
+
+#endif /* STDBOOL */
diff --git a/include/libc/stddef.h b/include/libc/stddef.h
new file mode 100644
index 0000000..8a48f55
--- /dev/null
+++ b/include/libc/stddef.h
@@ -0,0 +1,25 @@
+#ifndef LIBC_STDDEF_H
+#define LIBC_STDDEF_H
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#ifndef _PTRDIFF_T
+ #define _PTRDIFF_T
+ #if (_MIPS_SZLONG == 32)
+ typedef int ptrdiff_t;
+ #else
+ typedef long ptrdiff_t;
+ #endif
+#endif
+
+#ifndef offsetof
+#ifdef __GNUC__
+#define offsetof(structure, member) __builtin_offsetof(structure, member)
+#else
+#define offsetof(structure, member) ((size_t)&(((structure*)0)->member))
+#endif
+#endif
+
+#endif
diff --git a/include/libc/stdint.h b/include/libc/stdint.h
new file mode 100644
index 0000000..854fd25
--- /dev/null
+++ b/include/libc/stdint.h
@@ -0,0 +1,29 @@
+#ifndef LIBC_STDINT_H
+#define LIBC_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/macro.inc b/include/macro.inc
new file mode 100644
index 0000000..1ee4aa4
--- /dev/null
+++ b/include/macro.inc
@@ -0,0 +1,87 @@
+.macro glabel label
+ .global \label
+ .type \label, @function
+ \label:
+.endm
+
+.macro dlabel label
+ .global \label
+ \label:
+.endm
+
+.macro jlabel label
+ .global \label
+ .type \label, @function
+ \label:
+.endm
+
+# COP0 register aliases
+
+.set Index, $0
+.set Random, $1
+.set EntryLo0, $2
+.set EntryLo1, $3
+.set Context, $4
+.set PageMask, $5
+.set Wired, $6
+.set Reserved07, $7
+.set BadVaddr, $8
+.set Count, $9
+.set EntryHi, $10
+.set Compare, $11
+.set Status, $12
+.set Cause, $13
+.set EPC, $14
+.set PRevID, $15
+.set Config, $16
+.set LLAddr, $17
+.set WatchLo, $18
+.set WatchHi, $19
+.set XContext, $20
+.set Reserved21, $21
+.set Reserved22, $22
+.set Reserved23, $23
+.set Reserved24, $24
+.set Reserved25, $25
+.set PErr, $26
+.set CacheErr, $27
+.set TagLo, $28
+.set TagHi, $29
+.set ErrorEPC, $30
+.set Reserved31, $31
+
+
+# Float register aliases (o32 ABI, odd ones are rarely used)
+
+.set $fv0, $f0
+.set $fv0f, $f1
+.set $fv1, $f2
+.set $fv1f, $f3
+.set $ft0, $f4
+.set $ft0f, $f5
+.set $ft1, $f6
+.set $ft1f, $f7
+.set $ft2, $f8
+.set $ft2f, $f9
+.set $ft3, $f10
+.set $ft3f, $f11
+.set $fa0, $f12
+.set $fa0f, $f13
+.set $fa1, $f14
+.set $fa1f, $f15
+.set $ft4, $f16
+.set $ft4f, $f17
+.set $ft5, $f18
+.set $ft5f, $f19
+.set $fs0, $f20
+.set $fs0f, $f21
+.set $fs1, $f22
+.set $fs1f, $f23
+.set $fs2, $f24
+.set $fs2f, $f25
+.set $fs3, $f26
+.set $fs3f, $f27
+.set $fs4, $f28
+.set $fs4f, $f29
+.set $fs5, $f30
+.set $fs5f, $f31
diff --git a/include/macros.h b/include/macros.h
new file mode 100644
index 0000000..53755ad
--- /dev/null
+++ b/include/macros.h
@@ -0,0 +1,18 @@
+#ifndef MACROS_H
+#define MACROS_H
+
+#if defined(__GNUC__) || defined(__clang__)
+# define UNREACHABLE __builtin_unreachable()
+#else
+# define UNREACHABLE
+#endif
+
+#define SCREEN_WIDTH 320
+#define SCREEN_HEIGHT 240
+
+
+#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
+#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
+
+
+#endif
diff --git a/include/other_types.h b/include/other_types.h
new file mode 100644
index 0000000..f699ccb
--- /dev/null
+++ b/include/other_types.h
@@ -0,0 +1,11 @@
+#ifndef OTHER_TYPES_H
+#define OTHER_TYPES_H
+
+#include "ultra64.h"
+
+// Header for files that are well known, but don't have a proper header home yet
+
+typedef u32 romoffset_t;
+typedef void* TexturePtr;
+
+#endif
diff --git a/include/segment_symbols.h b/include/segment_symbols.h
new file mode 100644
index 0000000..e2950c0
--- /dev/null
+++ b/include/segment_symbols.h
@@ -0,0 +1,66 @@
+#ifndef SEGMENT_SYMBOLS_H
+#define SEGMENT_SYMBOLS_H
+
+#include "ultra64.h"
+#include "libc/stdint.h"
+#include "other_types.h"
+
+
+#define DECLARE_VRAM_SEGMENT(name) \
+ extern u32 name ## _VRAM[]; \
+ extern u32 name ## _VRAM_END[]
+
+#define DECLARE_ROM_SEGMENT(name) \
+ extern u32 name ## _ROM_START[]; \
+ extern u32 name ## _ROM_END[]
+
+#define DECLARE_DATA_SEGMENT(name) \
+ extern u32 name ## _DATA_START[]; \
+ extern u32 name ## _DATA_END[]; \
+ extern u32 name ## _DATA_SIZE[]
+
+#define DECLARE_BSS_SEGMENT(name) \
+ extern u32 name ## _BSS_START[]; \
+ extern u32 name ## _BSS_END[]
+
+#define DECLARE_SEGMENT(name) \
+ DECLARE_VRAM_SEGMENT(name); \
+ DECLARE_ROM_SEGMENT(name); \
+ DECLARE_DATA_SEGMENT(name); \
+ DECLARE_BSS_SEGMENT(name)
+
+#define SEGMENT_VRAM_START(segment) (segment ## _VRAM)
+#define SEGMENT_VRAM_END(segment) (segment ## _VRAM_END)
+#define SEGMENT_VRAM_SIZE(segment) ((uintptr_t)SEGMENT_VRAM_END(segment) - (uintptr_t)SEGMENT_VRAM_START(segment))
+
+#define SEGMENT_ROM_START(segment) ((romoffset_t)segment ## _ROM_START)
+#define SEGMENT_ROM_END(segment) ((romoffset_t)segment ## _ROM_END)
+#define SEGMENT_ROM_SIZE(segment) (SEGMENT_ROM_END(segment) - SEGMENT_ROM_START(segment))
+
+#define SEGMENT_DATA_SIZE_CONST(segment) ((romoffset_t)segment ## _DATA_SIZE)
+
+#define SEGMENT_BSS_START(segment) (segment ## _BSS_START)
+#define SEGMENT_BSS_END(segment) (segment ## _BSS_END)
+#define SEGMENT_BSS_SIZE(segment) ((uintptr_t)SEGMENT_BSS_END(segment) - (uintptr_t)SEGMENT_BSS_START(segment))
+
+
+DECLARE_SEGMENT(header);
+
+DECLARE_SEGMENT(ipl3);
+
+DECLARE_SEGMENT(entry);
+
+DECLARE_SEGMENT(boot);
+
+DECLARE_SEGMENT(dmadata);
+
+// DECLARE_SEGMENT();
+
+DECLARE_SEGMENT(code);
+
+
+// TODO: the rest of segments
+
+
+
+#endif
diff --git a/include/stack.h b/include/stack.h
new file mode 100644
index 0000000..eb127f3
--- /dev/null
+++ b/include/stack.h
@@ -0,0 +1,14 @@
+#ifndef STACK_H
+#define STACK_H
+
+#include "alignment.h"
+#include "ultra64.h"
+
+
+#define STACK(stack, size) \
+ u64 stack[ALIGN8(size) / sizeof(u64)]
+
+#define STACK_TOP(stack) \
+ ((u64*)((u8*)(stack) + sizeof(stack)))
+
+#endif
diff --git a/include/unk.h b/include/unk.h
new file mode 100644
index 0000000..c65730e
--- /dev/null
+++ b/include/unk.h
@@ -0,0 +1,19 @@
+#ifndef UNK_H
+#define UNK_H
+
+#include "ultra64.h"
+
+#define UNK_TYPE s32
+#define UNK_TYPE1 s8
+#define UNK_TYPE2 s16
+#define UNK_TYPE4 s32
+#define UNK_TYPE8 s64
+#define UNK_PTR void*
+#define UNK_RET UNK_TYPE
+#define UNK_ARGS
+#define UNK_FUN_ARG void(*)(void)
+//#define UNK_FUN_PTR(name) void(*name)(void)
+typedef UNK_RET (*UNK_FUN_PTR)(UNK_ARGS);
+#define UNK_SIZE 1
+
+#endif
diff --git a/include/unknown_structs.h b/include/unknown_structs.h
new file mode 100644
index 0000000..a10218f
--- /dev/null
+++ b/include/unknown_structs.h
@@ -0,0 +1,10 @@
+#ifndef UNKNOWN_STRUCTS_H
+#define UNKNOWN_STRUCTS_H
+
+#include "ultra64.h"
+#include "libc/stdint.h"
+#include "libc/stdbool.h"
+#include "unk.h"
+
+
+#endif