summaryrefslogtreecommitdiff
path: root/libpsx/src/setup.c
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-01-31 10:32:23 +0100
commit7c24e9a9b02b04dcaf9507acb94091ea70a2c02d (patch)
treec28d0748652ad4b4222309e46e6cfc82c0906220 /libpsx/src/setup.c
parenta2b7b6bb1cc2f4a3258b7b2dbc92399d151f864d (diff)
downloadpsxsdk-7c24e9a9b02b04dcaf9507acb94091ea70a2c02d.tar.gz
Imported pristine psxsdk-20190410 from official repo
Diffstat (limited to 'libpsx/src/setup.c')
-rw-r--r--libpsx/src/setup.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/libpsx/src/setup.c b/libpsx/src/setup.c
new file mode 100644
index 0000000..d77f062
--- /dev/null
+++ b/libpsx/src/setup.c
@@ -0,0 +1,50 @@
+#include <psx.h>
+#include <stdio.h>
+#include "memory.h"
+
+extern int __bss_start[];
+extern int __bss_end[];
+
+extern void *__ctor_list;
+extern void *__ctor_end;
+
+
+// Function to call static constructors (for C++, etc.)
+static void call_ctors(void)
+{
+ dprintf("Calling static constructors...\n");
+
+ void **p = &__ctor_end - 1;
+
+ for(--p; *p != NULL && (int)*p != -1 && p > &__ctor_list; p--)
+ {
+ dprintf("Constructor address = %x\n", (unsigned int)*p);
+ (*(void (**)())p)();
+ }
+
+ dprintf("Finished calling static constructors\n");
+}
+
+void psxsdk_setup()
+{
+ unsigned int x;
+
+ printf("Initializing PSXSDK... \n");
+
+ dprintf("Clearing BSS space...\n");
+
+// Clear BSS space
+ for(x = (unsigned int)__bss_start; x < (unsigned int)__bss_end; x++)
+ *((unsigned char*)x) = 0;
+
+ dprintf("BSS space cleared.\n");
+
+// Setup memory allocation functions
+ malloc_setup();
+
+ dprintf("Finished setting up memory allocation functions.\n");
+
+// Call static constructors
+ call_ctors();
+
+}