aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/system/dynlink/main.c19
-rw-r--r--libpsn00b/include/assert.h22
-rw-r--r--libpsn00b/include/dlfcn.h7
-rw-r--r--libpsn00b/libc/abort.c14
-rw-r--r--libpsn00b/libc/c++-support.cxx22
-rw-r--r--libpsn00b/psxetc/dl.c6
m---------tools/mkpsxiso0
7 files changed, 58 insertions, 32 deletions
diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c
index 690371e..9b94b30 100644
--- a/examples/system/dynlink/main.c
+++ b/examples/system/dynlink/main.c
@@ -57,7 +57,7 @@
// call them. Placing this array in the .dummy section (as defined in the
// PSn00bSDK linker script) ensures it won't be stripped away until all
// functions are in place.
-const void *const DO_NOT_STRIP[] __attribute__((section(".dummy"))) = {
+void *DO_NOT_STRIP[] __attribute__((section(".dummy"))) = {
&rand,
&InitGeom,
&RotMatrix,
@@ -244,14 +244,18 @@ void load_dll(const char *filename) {
printf("DLL init() @ %08x, render() @ %08x\n", dll_api.init, dll_api.render);
// Unfortunately, due to how position-independent code works, function
- // pointers returned by DL_GetDLLSymbol() can't be called directly. We have
- // to use the DL_CALL() macro instead, which sets up register $t9 to ensure
- // the function can locate and reference the DLL's relocation table.
- DL_CALL(dll_api.init, &ctx);
-
+ // pointers returned by DL_GetDLLSymbol() can't be called without first
+ // initializing register $t9. We have to use the DL_PRE_CALL() macro, which
+ // sets up $t9 to ensure the function can locate and reference the DLL's
+ // relocation table.
+ DL_PRE_CALL(dll_api.init);
+ dll_api.init(&ctx);
}
int main(int argc, const char* argv[]) {
+ // Reference the dummy array to prevent it from being stripped.
+ void **dummy = DO_NOT_STRIP;
+
init_context(&ctx);
SHOW_STATUS("INITIALIZING CD\n");
@@ -289,7 +293,8 @@ int main(int argc, const char* argv[]) {
while (1) {
// Use the currently loaded DLL to render a frame.
- DL_CALL(dll_api.render, &ctx, last_buttons);
+ DL_PRE_CALL(dll_api.render);
+ dll_api.render(&ctx, last_buttons);
FntPrint(-1, "MAIN: DLL ADDR=%08x SIZE=%d\n", dll->ptr, dll->size);
FntPrint(-1, "MAIN: %d FUNCTIONS RESOLVED\n", resolve_counter);
diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h
index 3114b57..e27f2ed 100644
--- a/libpsn00b/include/assert.h
+++ b/libpsn00b/include/assert.h
@@ -1,6 +1,20 @@
-#ifndef _ASSERT_H
-#define _ASSERT_H
+/*
+ * PSn00bSDK assert macro
+ * (C) 2022 spicyjpeg - MPL licensed
+ */
-void assert(int e);
+#ifndef __ASSERT_H
+#define __ASSERT_H
-#endif \ No newline at end of file
+void _assert_abort(const char *file, int line, const char *expr);
+
+#ifdef DEBUG
+#define assert(expr) { \
+ if (!(expr)) \
+ _assert_abort(__FILE__, __LINE__, #expr); \
+}
+#else
+#define assert(x)
+#endif
+
+#endif
diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h
index 6874d06..5848a95 100644
--- a/libpsn00b/include/dlfcn.h
+++ b/libpsn00b/include/dlfcn.h
@@ -1,19 +1,18 @@
/*
* PSn00bSDK dynamic linker
- * (C) 2021 spicyjpeg - MPL licensed
+ * (C) 2021-2022 spicyjpeg - MPL licensed
*/
#ifndef __DLFCN_H
#define __DLFCN_H
-#include <sys/types.h>
+#include <stdint.h>
#include <elf.h>
/* Helper macro for setting $t9 before calling a function */
-#define DL_CALL(func, ...) { \
+#define DL_PRE_CALL(func) { \
__asm__ volatile("move $t9, %0;" :: "r"(func) : "$t9"); \
- func(__VA_ARGS__); \
}
/* Types */
diff --git a/libpsn00b/libc/abort.c b/libpsn00b/libc/abort.c
index ca5ab1d..1d07037 100644
--- a/libpsn00b/libc/abort.c
+++ b/libpsn00b/libc/abort.c
@@ -1,9 +1,15 @@
#include <stdio.h>
void abort() {
-
printf("abort()\n");
-
- while(1);
-} \ No newline at end of file
+ for (;;)
+ __asm__ volatile("");
+}
+
+void _assert_abort(const char *file, int line, const char *expr) {
+ printf("%s:%d: assert(%s)\n", file, line, expr);
+
+ for (;;)
+ __asm__ volatile("");
+}
diff --git a/libpsn00b/libc/c++-support.cxx b/libpsn00b/libc/c++-support.cxx
index d169fdb..d0c0f3a 100644
--- a/libpsn00b/libc/c++-support.cxx
+++ b/libpsn00b/libc/c++-support.cxx
@@ -1,28 +1,28 @@
-#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
+#include <stdio.h>
-extern "C"
+extern "C" void __cxa_pure_virtual(void) {
+ printf("__cxa_pure_virtual()\n");
-void __cxa_pure_virtual(void) {
- /* Pure C++ virtual call; abort! */
- assert(false);
+ for (;;)
+ __asm__ volatile("");
}
void* operator new(size_t size) {
- return malloc(size);
+ return malloc(size);
}
void* operator new[](size_t size) {
- return malloc(size);
+ return malloc(size);
}
void operator delete(void* ptr) {
- free(ptr);
+ free(ptr);
}
void operator delete[](void* ptr) {
- free(ptr);
+ free(ptr);
}
/*-
@@ -35,5 +35,5 @@ void operator delete[](void* ptr) {
*
* 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
+ free(ptr);
+}
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c
index cbdcb66..6d37605 100644
--- a/libpsn00b/psxetc/dl.c
+++ b/libpsn00b/psxetc/dl.c
@@ -587,7 +587,8 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) {
if (ctor_list) {
for (uint32_t i = ((uint32_t) ctor_list[0]); i >= 1; i--) {
void (*ctor)(void) = (void (*)(void)) ctor_list[i];
- DL_CALL(ctor);
+ DL_PRE_CALL(ctor);
+ ctor();
}
}
@@ -619,7 +620,8 @@ void DL_DestroyDLL(DLL *dll) {
if (dtor_list) {
for (uint32_t i = 0; i < ((uint32_t) dtor_list[0]); i++) {
void (*dtor)(void) = (void (*)(void)) dtor_list[i + 1];
- DL_CALL(dtor);
+ DL_PRE_CALL(dtor);
+ dtor();
}
}
}
diff --git a/tools/mkpsxiso b/tools/mkpsxiso
-Subproject 75b3da9701dc57e0f23a8c7414237198285ef6c
+Subproject f07f5e6002beccfa95e88a841a16b8ace456c61