Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libultra/libc cleanup #1757

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions include/PR/os_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@

#include "stdarg.h"


void bcopy(void* __src, void* __dest, int __n);
int bcmp(void* __s1, void* __s2, int __n);
#ifdef __GNUC__
void bzero(void* begin, unsigned int length);
int bcmp(const void* __s1, const void* __s2, unsigned int __n);
void bcopy(const void* __src, void* __dest, unsigned int __n);
#else
void bzero(void* begin, int length);
int bcmp(const void* __s1, const void* __s2, int __n);
void bcopy(const void* __src, void* __dest, int __n);
#endif

void osSyncPrintf(const char* fmt, ...);

Expand Down
50 changes: 28 additions & 22 deletions include/PR/xstdio.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
#ifndef PR_XSTDIO_H
#define PR_XSTDIO_H

#include "ultratypes.h"
#include "stdarg.h"

// IDO doesn't support long double types, improve portability for compilers supporting them
#ifdef __sgi
#define LONG_DOUBLE_TYPE double
#else
#define LONG_DOUBLE_TYPE long double
#endif

typedef struct {
/* 0x0 */ union {
/* 0x0 */ s64 ll;
/* 0x0 */ f64 ld;
/* 0x00 */ union {
long long ll;
LONG_DOUBLE_TYPE ld;
} v;
/* 0x8 */ char* s;
/* 0xC */ s32 n0;
/* 0x10 */ s32 nz0;
/* 0x14 */ s32 n1;
/* 0x18 */ s32 nz1;
/* 0x1C */ s32 n2;
/* 0x20 */ s32 nz2;
/* 0x24 */ s32 prec;
/* 0x28 */ s32 width;
/* 0x08 */ char* s;
/* 0x0C */ int n0;
/* 0x10 */ int nz0;
/* 0x14 */ int n1;
/* 0x18 */ int nz1;
/* 0x1C */ int n2;
/* 0x20 */ int nz2;
/* 0x24 */ int prec;
/* 0x28 */ int width;
/* 0x2C */ size_t nchar;
/* 0x30 */ u32 flags;
/* 0x34 */ u8 qual;
/* 0x30 */ unsigned int flags;
/* 0x34 */ char qual;
} _Pft;

typedef void* (*PrintCallback)(void*, const char*, size_t);

#define FLAGS_SPACE 1
#define FLAGS_PLUS 2
#define FLAGS_MINUS 4
#define FLAGS_HASH 8
#define FLAGS_ZERO 16
#define FLAGS_SPACE (1 << 0)
#define FLAGS_PLUS (1 << 1)
#define FLAGS_MINUS (1 << 2)
#define FLAGS_HASH (1 << 3)
#define FLAGS_ZERO (1 << 4)

int _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap);
void _Litob(_Pft* args, u8 type);
void _Ldtob(_Pft* args, u8 type);
void _Litob(_Pft* args, char code);
void _Ldtob(_Pft* args, char code);

#endif
4 changes: 2 additions & 2 deletions include/libc/alloca.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef LIBC_ALLOCA_H
#define LIBC_ALLOCA_H

void* alloca(u32);
#define alloca __builtin_alloca
void* alloca(size_t);
#define alloca(size) __builtin_alloca(size)

#endif
4 changes: 4 additions & 0 deletions include/libc/stddef.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef LIBC_STDDEF_H
#define LIBC_STDDEF_H

#ifndef NULL
#define NULL ((void*)0)
#endif

#if !defined(_SIZE_T)
#define _SIZE_T
#if defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64)
Expand Down
2 changes: 1 addition & 1 deletion include/libc/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "stddef.h"

const char* strchr(const char* s, int c);
char* strchr(const char* s, int c);
size_t strlen(const char* s);
void* memcpy(void* s1, const void* s2, size_t n);

Expand Down
1 change: 0 additions & 1 deletion src/libultra/libc/ldiv.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "ultra64.h"
#include "stdlib.h"

ldiv_t ldiv(long numer, long denom) {
Expand Down
2 changes: 1 addition & 1 deletion src/libultra/libc/ll.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ultra64.h"
// IDO Compiler Intrinsics for 64-bit arithmetic

long long __ull_rshift(unsigned long long left, unsigned long long right) {
return left >> right;
Expand Down
2 changes: 1 addition & 1 deletion src/libultra/libc/llcvt.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ultra64.h"
// IDO Compiler Intrinsics for 64-bit conversion

long long __d_to_ll(double d) {
return d;
Expand Down
12 changes: 5 additions & 7 deletions src/libultra/libc/string.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "ultra64.h"
#include "stdlib.h"
#include "string.h"

const char* strchr(const char* s, int c) {
char* strchr(const char* s, int c) {
const unsigned char ch = c;

while (*s != ch) {
Expand All @@ -12,7 +10,7 @@ const char* strchr(const char* s, int c) {
s++;
}

return s;
return (char*)s;
}

size_t strlen(const char* s) {
Expand All @@ -26,8 +24,8 @@ size_t strlen(const char* s) {
}

void* memcpy(void* s1, const void* s2, size_t n) {
unsigned char* su1 = (unsigned char*)s1;
const unsigned char* su2 = (const unsigned char*)s2;
char* su1 = (char*)s1;
const char* su2 = (const char*)s2;

while (n > 0) {
*su1 = *su2;
Expand All @@ -36,5 +34,5 @@ void* memcpy(void* s1, const void* s2, size_t n) {
n--;
}

return s1;
return (void*)s1;
}
Loading