summaryrefslogtreecommitdiff
path: root/src/user/lib/libc/start.c
blob: 3f51fdb988ef444ac40c4ce1b39e245472ce460f (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
#include <tce/syscall.h>

#include <stdio.h>

extern int main(int argc, char **argv);

extern size_t start_ctors, end_ctors, start_dtors, end_dtors;

void __tce_libc_start(char **args) {
	// setup stdio
	term.fd = 0;
	__tce_libc_fsetup(&term);

	// call C++ static constructors
	size_t *call;
	for (call = &start_ctors; call < &end_ctors; call++) {
		((void(*)(void))*call)();
	}
	
	// call main
	char **lastarg = args;
	while (*lastarg) lastarg++;
	int ret = main((lastarg - args), args);

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

	process_exit(ret);
}