Multitasking Headache

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

Multitasking Headache

Post by System123 »

Hi

I have been battling for about 6weeks now just trying to get my multitasking working. I tried James M's way but I had difficulty implementing it in Pascal, due to the way I set up Paging. So I came up with my own way of going about it. The problem now is that my system switches between my 3 tasks once each. Then it triple faults because some how the Eip gets pointed to the start of memory.

The way I have multitasking set up is using my TRegisters data type and then using my timer function to set the values on the stack. What I think is happening is that the tasks are overwriting each other on the stack, so I set up separate stacks for each task. The problem is that if I set the ESP to the new stack pointer in Pascal, the old value returns when the leave function is called. So my new stack never gets set.

Am I missing something? Has anyone performed multitasking in Pascal?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Multitasking Headache

Post by Brendan »

Hi,
System123 wrote:The problem is that if I set the ESP to the new stack pointer in Pascal, the old value returns when the leave function is called. So my new stack never gets set.
That shouldn't happen. When you spawn a new task, the new task starts executing new code that never returns (this code would kill the task instead of attempting to return to a caller that never existed).

For example (in assembly because I don't know Pascal):

Code: Select all

    mov eax,SPAWN_TASK        ;Kernel API function number
    mov ebx,myTask            ;Address to use for the new task's EIP
    mov ecx,myStack           ;Address to use for the new task's ESP
    CALL_KERNEL_API           ;Macro to access the kernel API

Code: Select all

myTask:
    <do something here>

    mov eax,TERMINATE_TASK    ;Kernel API function number
    CALL_KERNEL_API           ;Macro to access the kernel API

    <any code here won't be executed because the task will be terminated>
Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Re: Multitasking Headache

Post by Craze Frog »

Has anyone performed multitasking in Pascal?
Yes, but I couldn't make head nor tails of James M's multitasking tutorial. I simply set up the stack appropriately and iret to do the task switch.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Multitasking Headache

Post by jal »

System123 wrote:Am I missing something? Has anyone performed multitasking in Pascal?
You have been asking the very same questions in this thread, and you have been answered there already (especially about Pascal restoring the ESP). Now you act as if you didn't even read that thread. Please explain why you didn't reply to that thread if you didn't understand, and bother us again with the same old questions.
What I think is happening is that the tasks are overwriting each other on the stack, so I set up separate stacks for each task.
If you did not even understand right away why each process needs its own stack, I can see why you have been 'battling' for six weeks - you just don't have a clue. Why don't you go back to the basics before trying to write something that works???


JAL
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Multitasking Headache

Post by System123 »

jal wrote:If you did not even understand right away why each process needs its own stack, I can see why you have been 'battling' for six weeks - you just don't have a clue. Why don't you go back to the basics before trying to write something that works???
I got confused when going through the tutorial. Technically though the simplified multitasking I am writing it shouldn't make a difference if the tasks overwrite each others stacks as nothing will be pushed to the stack by my tasks. And my main kernel task had its own stack. James M's tutorial lost me as I had initiated my paging differently to him. And this made it confusing when trying to clone directories. I would rather battle for 6weeks than just take another persons code and copy paste it. So far I have written most of my Kernel with limited problems. As a noob I don't think I have been half as bad as certain other people who have been on here. Atleast I make use of the wiki and google before I post!

@Brendan: Thanks again for the response. I have located my problem now, It was that I hadn't put precautions in place in case the task tried to return.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Multitasking Headache

Post by jal »

System123 wrote:Technically though, the simplified multitasking I am writing it shouldn't make a difference if the tasks overwrite each others stacks as nothing will be pushed to the stack by my tasks.
I understand you are writing everything in Pascal, so you have no way of controlling the stack use by procedures (unless perhaps there are some keywords/parameters to control it).
I would rather battle for 6weeks than just take another persons code and copy paste it.
That, at least, is commendable.
As a noob I don't think I have been half as bad as certain other people who have been on here. Atleast I make use of the wiki and google before I post!
That is commendable too :). However, sometimes it is better to take a step back, and try to completely understand what you are trying to achieve, then try to program it into a working prototype. It seems you are in a 6-week try-and-error loop, seeing only the grass instead of the field...


JAL
Post Reply