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?
Multitasking Headache
Multitasking Headache
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking Headache
Hi,
For example (in assembly because I don't know Pascal):
Cheers,
Brendan
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).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.
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>
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.
-
- Member
- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Multitasking Headache
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.Has anyone performed multitasking in Pascal?
Re: Multitasking Headache
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.System123 wrote:Am I missing something? Has anyone performed multitasking in Pascal?
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???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.
JAL
Re: Multitasking Headache
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!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???
@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
Currently - Busy with FAT12 driver and VFS
Re: Multitasking Headache
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).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.
That, at least, is commendable.I would rather battle for 6weeks than just take another persons code and copy paste it.
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...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!
JAL