//ˇQ¨lURL
//http://wiki.monaos.org/pukiwiki.php?%B5%C4%CF%C0%2Fstatic%CA%D1%BF%F4%A4%CE%BD%E9%B4%FC%B2%BD
#include <stdio.h>
#include "typedefs.h"

typedef void (*PFV)(void);

#ifdef __cplusplus
extern "C" {
#endif
extern PFV	__CTOR_LIST__[];
extern PFV	__DTOR_LIST__[];
#ifdef __cplusplus
}
#endif

extern "C" int _main(int,char*[],char*[]);

static void __finit(const PFV *list) {
	DWORD	cnt;

	cnt = (DWORD)list[0];
	list++;
	list = (PFV *)((((DWORD)list) + 3) & (~3));		// align bug?
	if (cnt == -1) {
		while(*list != NULL) {
			(**list++)();
		}
	}
	else {
		while(cnt) {
			cnt--;
			(**list++)();
		}
	}
}

extern "C" int user_start(void) {
	int		r;

	//memmng_initialize(0xC0000000, 8 * 1024 * 1024);
	//__fsio_initialize();
	//makearg();
	__finit(__CTOR_LIST__);
	r = _main(0, 0, 0);
	__finit(__DTOR_LIST__);
	//free(__argv);
	//memmng_deinitialize();
	//syscall_kill();
	return(r);
}