Software Multitasking
Software Multitasking
Hey everyone!
I have finally ported JamesM's multitasking code to my kernel. I can call fork() and create new tasks, but they all have the same EIP. If I want them each to start a new function, i.e. function1(), function2(), and function3(), do I just set the EIP value in the task structure to the location of the function and then switch to the task?
Thanks,
Michael
I have finally ported JamesM's multitasking code to my kernel. I can call fork() and create new tasks, but they all have the same EIP. If I want them each to start a new function, i.e. function1(), function2(), and function3(), do I just set the EIP value in the task structure to the location of the function and then switch to the task?
Thanks,
Michael
I to am quiet firmilar w/ his multi-tasking code...
Yes...
If you want to copy the fork code...
call it "start_task" and have it take a void *thread... then just assign the value of thread to the eip.
I don't have the exact syntax cause I am not at my home pc... but thats how ya do it, and it works for me!
Good Luck
-Rich
Yes...
If you want to copy the fork code...
call it "start_task" and have it take a void *thread... then just assign the value of thread to the eip.
I don't have the exact syntax cause I am not at my home pc... but thats how ya do it, and it works for me!
Good Luck
-Rich
Mouse Pad - Coming in the distant future...
Kernel: Indigo Kernel - v0.0.1
Thanks to JamesM and BrokenThorn for there tutorials!
Kernel: Indigo Kernel - v0.0.1
Thanks to JamesM and BrokenThorn for there tutorials!
Fork() returns zero if you are the child process, and nonzero (The PID of the child process) if you are the parent. So, a start_task function could read something like:
Pretty simple, really.
EDIT: I really should get round to writing the documentation for the multitasking code I just haven't had time so far!
Code: Select all
void start_task(void (*func)(void*), void *arg)
{
if (fork() == 0)
func(arg);
}
EDIT: I really should get round to writing the documentation for the multitasking code I just haven't had time so far!
I haven't released it to the public as yet, I was waiting until I'd written the accompanying tutorial. But *sigh* if you want it...
http://www.jamesmolloy.co.uk/downloads/ ... ing.tar.gz
Cheers,
JamesM
http://www.jamesmolloy.co.uk/downloads/ ... ing.tar.gz
Cheers,
JamesM
Wow... thats really a good idea... then you could just add the code to remove it from the scheduler right at the bottom... when ever func(arg) returns...JamesM wrote:Fork() returns zero if you are the child process, and nonzero (The PID of the child process) if you are the parent. So, a start_task function could read something like:
Pretty simple, really.Code: Select all
void start_task(void (*func)(void*), void *arg) { if (fork() == 0) func(arg); }
EDIT: I really should get round to writing the documentation for the multitasking code I just haven't had time so far!
-Rich
Mouse Pad - Coming in the distant future...
Kernel: Indigo Kernel - v0.0.1
Thanks to JamesM and BrokenThorn for there tutorials!
Kernel: Indigo Kernel - v0.0.1
Thanks to JamesM and BrokenThorn for there tutorials!
Yep,
Well right now, I'm not using the IRQ0/PIT scheduler. I just want to make sure that it will work. Whenever I call switch_task(), I get a page fault, so i still trying to debug this. I would post my ported code or bochs dump, but I'm not at home right now.
[Edit]: I already had to change some of the init_task() and fork() code because I was getting a page fault accessing the task structure. So I just identity mapped the structure with 0x7. [/Edit]
--Michael
Well right now, I'm not using the IRQ0/PIT scheduler. I just want to make sure that it will work. Whenever I call switch_task(), I get a page fault, so i still trying to debug this. I would post my ported code or bochs dump, but I'm not at home right now.
[Edit]: I already had to change some of the init_task() and fork() code because I was getting a page fault accessing the task structure. So I just identity mapped the structure with 0x7. [/Edit]
--Michael
I used this method now and it seems to be working If I create 3 seperate tasks, and place a loop in each task everything works ok, but when a task returns or finishes I get a page fault. Is this because the task isn't running anymore (and so, doesn't exisit?) and the scheduler wants switch to that task?astrocrep wrote:Wow... thats really a good idea... then you could just add the code to remove it from the scheduler right at the bottom... when ever func(arg) returns...JamesM wrote:Fork() returns zero if you are the child process, and nonzero (The PID of the child process) if you are the parent. So, a start_task function could read something like:
Pretty simple, really.Code: Select all
void start_task(void (*func)(void*), void *arg) { if (fork() == 0) func(arg); }
EDIT: I really should get round to writing the documentation for the multitasking code I just haven't had time so far!
-Rich
This is my task list:
Code: Select all
PID ESP EBP EIP PAGE
1 0x00000000 0x00000000 0x00000000 0x008100
2 0xdfffff74 0xdfffff9c 0x001000dc 0x008800
3 0xdfffff74 0xdfffff9c 0x00100106 0x008f00
Code: Select all
Page fault! ( present read-only ) at 0x0x12bd890 - EIP: 0xc00830b
How can I see if a task isn't running anymore?
(yes you're right.. I'm still a beginner, but I'm learning! )
btw. Thanks for the great tutorials JamesM, I'm really learning alot from it!
Hi,
That return address seems to be garbage, and so i reckon your task is finishing, returning, then the start_task function returns, and pops a garbage return address off the stack. Modify your function to look something like
That way you can have a function called kill_task that removes th current task from the ready queue. the for(;;); afterwards is so the task spins at the current location until the scheduler runs, so it doesn't return to a garbage stack.
Have fun!
James
That return address seems to be garbage, and so i reckon your task is finishing, returning, then the start_task function returns, and pops a garbage return address off the stack. Modify your function to look something like
Code: Select all
void start_task(void (*func)(void*), void *arg)
{
if (fork() == 0)
{
func(arg);
kill_task();
for(;;);
}
}
Have fun!
James
that looks like some mighty fine code you got there James, very portable, and easy to plug in your own scheduler.
can i ask how (if you've started) far you are into the documentation for it? i spent a good few hours exploring it and gave implementing it a go, however i have one tiny problem that may be either a bug (not likely) or a problem in my code.
anyway, when i set up current_directory and try to switch to it using the function defined in your paging code (and updated to have dir->physicalAddr), the computer just hangs. Does anyone know why this might be?
Again, very nice code though, im enjoying working with it immensly. looking forward to some documentation/companion tutorial.
Lukem
can i ask how (if you've started) far you are into the documentation for it? i spent a good few hours exploring it and gave implementing it a go, however i have one tiny problem that may be either a bug (not likely) or a problem in my code.
anyway, when i set up current_directory and try to switch to it using the function defined in your paging code (and updated to have dir->physicalAddr), the computer just hangs. Does anyone know why this might be?
Again, very nice code though, im enjoying working with it immensly. looking forward to some documentation/companion tutorial.
Lukem