Exec

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Exec

Post by System123 »

I have finally gotten my multitasking to work, and I have now implemented an Exec function that allows me to execute bin and com files. This will later be upgraded to run ELF files. At the moment I just need some advice.

When the exec function is called, I load the file to memory, then I create a new user task for the program. I now need to implement a way to kill the task and free the memory used by it when the program is finished running. My problem is how would I implement this. Would adding a system call in the program at the end be the easiest way? ie:

Code: Select all


...Program Code...

mov eax, 0x00 //System call to kill task
int 0x80

Or is there a better way to do this?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Hangin10
Member
Member
Posts: 162
Joined: Wed Feb 27, 2008 12:40 am

Re: Exec

Post by Hangin10 »

AFAIK, it's usually (always?) done like that, with that code probably ending the routine that called main.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Exec

Post by JamesM »

Almost - under UNIX that call is executed when main returns, or when exit() is called. It's a function called _exit() - exit() calls all functions registered with atexit(), then falls through to _exit() which calls your OS cleanup code.

so in your crt0.c you'd normally have:

Code: Select all

_exit(main(argc, argv, env));
Post Reply