summaryrefslogtreecommitdiff
path: root/libpsx/src/setup.c
blob: d77f0629b3a90d8c3432b3569b4a6b698b50ff0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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();

}