diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 10:32:23 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 10:32:23 +0100 |
| commit | 7c24e9a9b02b04dcaf9507acb94091ea70a2c02d (patch) | |
| tree | c28d0748652ad4b4222309e46e6cfc82c0906220 /libpsx/src/setup.c | |
| parent | a2b7b6bb1cc2f4a3258b7b2dbc92399d151f864d (diff) | |
| download | psxsdk-7c24e9a9b02b04dcaf9507acb94091ea70a2c02d.tar.gz | |
Imported pristine psxsdk-20190410 from official repo
Diffstat (limited to 'libpsx/src/setup.c')
| -rw-r--r-- | libpsx/src/setup.c | 50 |
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(); + +} |
