summaryrefslogtreecommitdiff
path: root/Source/Library/Userland/Start.cpp
blob: be4f81e57cf78249d316b111113604af70d311ae (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
#include <types.h>
#include <Binding/VirtualTerminal.class.h>

#include <Heap.class.h>

extern "C" void __cxa_pure_virtual() {}	//Required when using abstract classes
void *__dso_handle;		//Required when using global objects
extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; }

extern u32int start_ctors, end_ctors, start_dtors, end_dtors;

Heap heap;

VirtualTerminal invt(0), outvt(0);

int main(const Vector<String>& args);

extern "C" void start() {
	//Call static constructors
    for(u32int * call = &start_ctors; call < &end_ctors; call++) {
        ((void (*)(void))*call)();
    }

	heap.create(0x40000000, 0x00100000, 0x00004000);	//Initially create a 1M heap with 16ko index
	invt = VirtualTerminal::getIn(); outvt = VirtualTerminal::getOut();

	u32int argc = Process::get().argc();
	Vector<String> args(argc);
	for (u32int i = 0; i < argc; i++) args[i] = Process::get().argv(i);

	u32int r = main(args);

	//Call static destructors 
    for(u32int * call = &start_dtors; call < &end_dtors; call++) {
        ((void (*)(void))*call)();
    }

	asm volatile("int $66" : : "a"(r));
}

namespace Mem {
	void* alloc (u32int sz) { return heap.alloc(sz); }
	void free(void* ptr) { heap.free(ptr); }
	void* mkXchgSpace (u32int sz) { return alloc(sz); }
}