diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2022-03-25 09:22:20 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-25 09:22:20 +0800 |
| commit | 975e614b3c840e2f717adac1d1cb9cee4e5e561b (patch) | |
| tree | 6584ce5b0dbe27a466c95c81fac61b0d90f627bd /libpsn00b/libc | |
| parent | 05d44488bd5587786f4bd0286fc0f555c79aa46a (diff) | |
| parent | 45168ae43e29aa5930ee5a206475ae836078915f (diff) | |
| download | psn00bsdk-975e614b3c840e2f717adac1d1cb9cee4e5e561b.tar.gz | |
Merge pull request #46 from spicyjpeg/psxmdec
Critical ldscript fixes, initial MDEC support and CI updates
Diffstat (limited to 'libpsn00b/libc')
| -rw-r--r-- | libpsn00b/libc/abort.c | 28 | ||||
| -rw-r--r-- | libpsn00b/libc/c++-support.cxx | 53 | ||||
| -rw-r--r-- | libpsn00b/libc/putchar.s | 10 | ||||
| -rw-r--r-- | libpsn00b/libc/start.c | 23 |
4 files changed, 66 insertions, 48 deletions
diff --git a/libpsn00b/libc/abort.c b/libpsn00b/libc/abort.c index ca5ab1d..de4323d 100644 --- a/libpsn00b/libc/abort.c +++ b/libpsn00b/libc/abort.c @@ -1,9 +1,29 @@ + #include <stdio.h> -void abort() { +/* Standard abort */ +void abort() { printf("abort()\n"); - - while(1); -}
\ No newline at end of file + for (;;) + __asm__ volatile(""); +} + +/* Internal function used by assert() macro */ + +void _assert_abort(const char *file, int line, const char *expr) { + printf("%s:%d: assert(%s)\n", file, line, expr); + + for (;;) + __asm__ volatile(""); +} + +/* Pure virtual function call (C++) */ + +void __cxa_pure_virtual(void) { + printf("__cxa_pure_virtual()\n"); + + for (;;) + __asm__ volatile(""); +} diff --git a/libpsn00b/libc/c++-support.cxx b/libpsn00b/libc/c++-support.cxx index d169fdb..38354dd 100644 --- a/libpsn00b/libc/c++-support.cxx +++ b/libpsn00b/libc/c++-support.cxx @@ -1,39 +1,46 @@ -#include <assert.h> + #include <stdint.h> #include <stdlib.h> +#include <stdio.h> -extern "C" - -void __cxa_pure_virtual(void) { - /* Pure C++ virtual call; abort! */ - assert(false); -} +/* Default new/delete operators */ -void* operator new(size_t size) { - return malloc(size); +void *operator new(size_t size) noexcept { + return malloc(size); } -void* operator new[](size_t size) { - return malloc(size); +void *operator new[](size_t size) noexcept { + return malloc(size); } -void operator delete(void* ptr) { - free(ptr); +void operator delete(void *ptr) noexcept { + free(ptr); } -void operator delete[](void* ptr) { - free(ptr); +void operator delete[](void *ptr) noexcept { + free(ptr); } -/*- - * <https://en.cppreference.com/w/cpp/memory/new/operator_delete> +/* + * https://en.cppreference.com/w/cpp/memory/new/operator_delete * * Called if a user-defined replacement is provided, except that it's * unspecified whether other overloads or this overload is called when deleting - * objects of incomplete type and arrays of non-class and trivially-destructible - * class types. + * objects of incomplete type and arrays of non-class and trivially + * destructible class types. * - * A memory allocator can use the given size to be more efficient */ -void operator delete(void* ptr, unsigned int) { - free(ptr); -}
\ No newline at end of file + * A memory allocator can use the given size to be more efficient. + */ +void operator delete(void *ptr, size_t size) noexcept { + free(ptr); +} + +/* Placement new operators */ + +void *operator new(size_t size, void *ptr) noexcept { + return ptr; +} + +void *operator new[](size_t size, void *ptr) noexcept { + return ptr; +} diff --git a/libpsn00b/libc/putchar.s b/libpsn00b/libc/putchar.s deleted file mode 100644 index a3f6c57..0000000 --- a/libpsn00b/libc/putchar.s +++ /dev/null @@ -1,10 +0,0 @@ -.set noreorder -.section .text - -.global putchar -.type putchar, @function -putchar: - addiu $t2, $0, 0xa0 - jr $t2 - addiu $t1, $0, 0x3c -
\ No newline at end of file diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index f190794..fd6fe33 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -6,19 +6,20 @@ #include <stdint.h> #include <string.h> #include <stdlib.h> +#include <stddef.h> -#define KERNEL_ARG_STRING ((const char *) 0x80000180) -#define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) +#define KERNEL_ARG_STRING ((const char *) 0x80000180) +#define KERNEL_RETURN_VALUE ((volatile int *) 0x8000dffc) /* Argument parsing */ -int32_t __argc; -const char **__argv; +int __argc; +const char **__argv; #define ARGC_MAX 16 -static const char *_argv_buffer[ARGC_MAX]; -static char _arg_string_buffer[132]; +static const char *_argv_buffer[ARGC_MAX]; +static char _arg_string_buffer[132]; static void _parse_kernel_args() { // Copy the argument string from kernel memory into a private buffer (which @@ -61,10 +62,10 @@ extern uint8_t _end[]; // useful though to change the stack size and/or reinitialize the heap on // systems that have more than 2 MB of RAM (e.g. emulators, devkits, PS1-based // arcade boards). -void _mem_init(size_t ram_size, size_t stack_max_size) { - void *exe_end = _end + 4; - size_t exe_size = (size_t) exe_end - (size_t) __text_start; - size_t ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; +void _mem_init(int ram_size, int stack_max_size) { + void *exe_end = _end + 4; + int exe_size = (int) exe_end - (int) __text_start; + int ram_used = (0x10000 + exe_size + stack_max_size) & 0xfffffffc; InitHeap(exe_end, ram_size - ram_used); } @@ -74,7 +75,7 @@ void _mem_init(size_t ram_size, size_t stack_max_size) { extern void (*__CTOR_LIST__[])(void); extern void (*__DTOR_LIST__[])(void); -extern int32_t main(int32_t argc, const char* argv[]); +extern int main(int argc, const char* argv[]); // Even though _start() usually takes no arguments, this implementation allows // parent executables to pass args directly to child executables without having |
