Skip to content

Commit

Permalink
Match the rest of runtime and libc (#183)
Browse files Browse the repository at this point in the history
* Match the rest of libc

* Use ifndef __MWERKS__
  • Loading branch information
cadmic authored Sep 20, 2024
1 parent 944ed73 commit 40e9f6f
Show file tree
Hide file tree
Showing 17 changed files with 2,023 additions and 84 deletions.
80 changes: 40 additions & 40 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,58 +476,58 @@ def LinkedFor(*versions):
"runtime",
[*cflags_base, "-inline deferred"],
[
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "runtime/__mem.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "runtime/__va_arg.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "runtime/global_destructor_chain.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "runtime/runtime.c"),
Object(Linked, "runtime/__mem.c"),
Object(Linked, "runtime/__va_arg.c"),
Object(Linked, "runtime/global_destructor_chain.c"),
Object(Linked, "runtime/runtime.c"),
]
),
GenericLib(
"libc",
[*cflags_base, "-inline deferred"],
[*cflags_base, "-inline deferred", "-str pool,readonly"],
[
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/abort_exit.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/ansi_files.c"),
Object(NotLinked, "libc/ansi_fp.c", extra_cflags=["-inline noauto"]),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/buffer_io.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/critical_regions.ppc_eabi.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/ctype.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/direct_io.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/errno.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/mbstring.c"),
Object(NotLinked, "libc/mem.c"),
Object(NotLinked, "libc/mem_funcs.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/misc_io.c"),
Object(NotLinked, "libc/printf.c"),
Object(NotLinked, "libc/scanf.c"),
Object(NotLinked, "libc/string.c"),
Object(NotLinked, "libc/strtoul.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/uart_console_io.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/float.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/wchar_io.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/e_asin.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/e_pow.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/fminmaxdim.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/s_ceil.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/s_copysign.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/s_floor.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/s_frexp.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/s_ldexp.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/w_pow.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/hyperbolicsf.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/log10f.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/trigf.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/math_inlines.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "libc/common_float_tables.c"),
Object(Linked, "libc/abort_exit.c"),
Object(Linked, "libc/ansi_files.c"),
Object(Linked, "libc/ansi_fp.c", extra_cflags=["-inline noauto"]),
Object(Linked, "libc/buffer_io.c"),
Object(Linked, "libc/critical_regions.ppc_eabi.c"),
Object(Linked, "libc/ctype.c"),
Object(Linked, "libc/direct_io.c"),
Object(Linked, "libc/errno.c"),
Object(Linked, "libc/mbstring.c"),
Object(Linked, "libc/mem.c"),
Object(Linked, "libc/mem_funcs.c"),
Object(Linked, "libc/misc_io.c"),
Object(Linked, "libc/printf.c"),
Object(Linked, "libc/scanf.c"),
Object(Linked, "libc/string.c"),
Object(Linked, "libc/strtoul.c"),
Object(Linked, "libc/uart_console_io.c"),
Object(Linked, "libc/float.c"),
Object(Linked, "libc/wchar_io.c"),
Object(Linked, "libc/e_asin.c"),
Object(Linked, "libc/e_pow.c"),
Object(Linked, "libc/fminmaxdim.c"),
Object(Linked, "libc/s_ceil.c"),
Object(Linked, "libc/s_copysign.c"),
Object(Linked, "libc/s_floor.c"),
Object(Linked, "libc/s_frexp.c"),
Object(Linked, "libc/s_ldexp.c"),
Object(Linked, "libc/w_pow.c"),
Object(Linked, "libc/hyperbolicsf.c"),
Object(Linked, "libc/log10f.c"),
Object(Linked, "libc/trigf.c"),
Object(Linked, "libc/math_inlines.c"),
Object(Linked, "libc/common_float_tables.c"),
]
),
GenericLib(
"debugger",
cflags_base,
[
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "debugger/AmcExi2Stubs.c"),
Object(Linked, "debugger/AmcExi2Stubs.c"),
Object(NotLinked, "debugger/DebuggerDriver.c"),
Object(LinkedFor("mq-j", "mq-u", "ce-j", "ce-u"), "debugger/odenotstub.c"),
Object(Linked, "debugger/odenotstub.c"),
]
),
]
Expand Down
25 changes: 25 additions & 0 deletions libc/ansi_fp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef _ANSI_FP
#define _ANSI_FP

#define SIGDIGLEN 36

typedef struct decimal {
char sign;
char unk1;
short exp;
struct {
unsigned char length;
unsigned char text[36];
unsigned char unk41;
} sig;
} decimal;

typedef struct decform {
char style;
char unk1;
short digits;
} decform;

void __num2dec(const decform* f, double x, decimal* d);

#endif
3 changes: 0 additions & 3 deletions libc/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include "dolphin/types.h"

// eof.h
#define EOF -1L

extern const u8 __ctype_map[];
extern const u8 __lower_map[];
extern const u8 __upper_map[];
Expand Down
14 changes: 3 additions & 11 deletions libc/limits.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#ifndef _LIMITS_H_
#define _LIMITS_H_

#define SCHAR_MIN (-0x7F - 1)
#define SCHAR_MAX 0x7F
#define CHAR_MIN (-0x7F - 1)
#define CHAR_MAX 0x7F
#define UCHAR_MAX 0xFFU

#if defined(__MWERKS__) && __option(unsigned_char)
#define CHAR_MIN 0U
#define CHAR_MAX UCHAR_MAX
#else
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
#endif

#define SHRT_MIN (-0x7FFF - 1)
#define SHRT_MAX 0x7FFF
#define USHRT_MAX 0xFFFFU
Expand All @@ -21,7 +13,7 @@
#define INT_MAX 0x7FFFFFFF
#define UINT_MAX 0xFFFFFFFFU

#define LONG_MIN (-0x7FFFFFFFFFFFFFFFL - 1)
#define LONG_MIN (-0x7FFFFFFFL - 1)
#define LONG_MAX 0x7FFFFFFFL
#define ULONG_MAX 0xFFFFFFFFUL

Expand Down
10 changes: 0 additions & 10 deletions libc/mem_funcs.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#ifndef _MEM_FUNCS_H_
#define _MEM_FUNCS_H_

#include "macros.h"
#include "stddef.h"

#define __min_bytes_for_long_copy 32

INIT int memcmp(void*, const void*, size_t);
INIT void* memcpy(void* dst, const void* src, size_t n);
INIT void* memset(void* dst, int val, size_t n);
INIT void __fill_mem(void* dst, int val, size_t n);

void __copy_mem(void* dst, const void* src, unsigned long n);
void __move_mem(void* dst, const void* src, unsigned long n);
void __copy_longs_aligned(void* dst, const void* src, unsigned long n);
void __copy_longs_rev_aligned(void* dst, const void* src, unsigned long n);
void __copy_longs_unaligned(void* dst, const void* src, unsigned long n);
Expand Down
4 changes: 4 additions & 0 deletions libc/stdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ extern void __builtin_va_info(void*);

void* __va_arg(va_list v_list, unsigned char type);

#ifndef __MWERKS__
#define _var_arg_typeof(e) 0
#endif

#define va_start(ap, fmt) ((void)fmt, __builtin_va_info(&ap))
#define va_arg(ap, t) (*((t*)__va_arg(ap, _var_arg_typeof(t))))
#define va_end(ap) (void)0
Expand Down
26 changes: 15 additions & 11 deletions libc/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,27 @@ typedef struct {
#define EOF -1L

enum __ReadProcActions {
__GetChar,
__UngetChar,
__CheckForError
__GetAChar,
__UngetAChar,
__TestForError,
};

int __StringRead(void* str, int ch, int behavior);

#define _IONBF 0
#define _IOLBF 1
#define _IOFBF 2

int puts(const char* s);
int printf(const char*, ...);
size_t sprintf(char* s, const char* format, ...);
size_t vprintf(const char* format, va_list arg);
size_t vsprintf(char* s, const char* format, va_list arg);
size_t fread(const void*, size_t memb_size, size_t num_memb, FILE*);
extern FILE __files[3];

#define stdin (&__files[0])
#define stdout (&__files[1])
#define stderr (&__files[2])

int sprintf(char* s, const char* format, ...);
int vprintf(const char* format, va_list arg);
int vsprintf(char* s, const char* format, va_list arg);

size_t fwrite(const void*, size_t memb_size, size_t num_memb, FILE*);
int fseek(FILE* file, long offset, int mode);
size_t __fwrite(const void*, size_t, size_t, FILE*);

#endif // _STDIO
13 changes: 9 additions & 4 deletions libc/string.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#ifndef _STRING_H_
#define _STRING_H_

#include "mem_funcs.h"
#include "stddef.h"

char* strcpy(char* dst, const char* src);
char* strncpy(char* dst, const char* src, size_t num);
char* strncat(char* dest, const char* src, size_t n);
size_t strlen(const char* s);
char* strcpy(char* dest, const char* src);
char* strncpy(char* dest, const char* src, size_t num);
int strcmp(const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
char* strncat(char* dest, const char* src, size_t n);
char* strchr(const char* str, int chr);

void* memchr(const void* p, int val, size_t n);
int memcmp(const void* p1, const void* p2, size_t n);
void* memset(void* dst, int val, size_t n);
void* memcpy(void* dst, const void* src, size_t n);
void* memmove(void* dst, const void* src, size_t n);

#endif
Loading

0 comments on commit 40e9f6f

Please sign in to comment.