I'm developing a very minimal version of my os called MAgola. It's a single-tasking os instead of my multitasking os, Agola.
I want to execute my elf application, then return the system using _exit syscall like calling a C function. However I can't return to os using _exit. System strolls out from its address space and I get an invalid opcode fault as usual.
I use newlib and my crt0 is:
Code: Select all
void _start()
{
int argc;
char** argv;
unsigned int argv_p;
asm volatile ("movl %%edi, %0" : "=r"(argc));
asm volatile ("movl %%esi, %0" : "=r"(argv_p));
argv = (char**) argv_p;
_init_signal();
_init();
exit(main(argc, argv));
}
Code: Select all
int _exit(int code)
{
_fini();
return syscall_exit(code);
}
How can I return to the system correctly using _exit in single-tasking? I think my elf loader is correct as I use its really similar version in Agola and it works flawlessly.
Thanks in advance.