Multitasking
Multitasking
Just a few questions on multitasking:
- Is there a set way to implement software multitasking or can I 'make it up'?
- Is it necessary to clone page directories for software multitasking?
Thanks
- Is there a set way to implement software multitasking or can I 'make it up'?
- Is it necessary to clone page directories for software multitasking?
Thanks
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
I prefer to call it context switching.
There are no fixed rules on implementing software based multitasking. You are only restricted by the design of the hardware
It boils down to somehow saving the context of one thread and switching to another. Personally I use the stack-based method on x86. Interesting registers are pushed onto the stack upon interrupt, current esp is saved, esp set to esp of next thread and then iret to restore next 'saved' context. (I use paging so page directory is also swapped)
Cloning of page directories is really dependent on your virtual memory design... ie. does each process have it's own address space or not?
There are no fixed rules on implementing software based multitasking. You are only restricted by the design of the hardware
It boils down to somehow saving the context of one thread and switching to another. Personally I use the stack-based method on x86. Interesting registers are pushed onto the stack upon interrupt, current esp is saved, esp set to esp of next thread and then iret to restore next 'saved' context. (I use paging so page directory is also swapped)
Cloning of page directories is really dependent on your virtual memory design... ie. does each process have it's own address space or not?
All your base are belong to us.
Re: Multitasking
Check how A2 (formerly BlueBottle) does it. It doesn't use any context switching for multitasking, instead ... just read it.
Re: Multitasking
Is it recommended to clone your page directory to give each task its own address space? And if I do clone my age directories what must be cloned? I know the Kernel Stack and Code areas but does anything else need to be? Also do I change the memory map of the cloned direcory ie: so virtual address 0xC0000000 which points to physical address 0x100000 in the one page directory will now point to 0x20000? So I don't overwrite code.
Just another question quick. How would the following C code be defined in Pascal? I have my paging working but the way it works is going to make my life hard in the end.
Thanks
Just another question quick. How would the following C code be defined in Pascal? I have my paging working but the way it works is going to make my life hard in the end.
Code: Select all
typedef struct page
{
u32int present : 1; // Page present in memory
u32int rw : 1; // Read-only if clear, readwrite if set
u32int user : 1; // Supervisor level only if clear
u32int accessed : 1; // Has the page been accessed since last refresh?
u32int dirty : 1; // Has the page been written to since last refresh?
u32int unused : 7; // Amalgamation of unused and reserved bits
u32int frame : 20; // Frame address (shifted right 12 bits)
} page_t;
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
System123 wrote:Just another question quick. How would the following C code be defined in Pascal? I have my paging working but the way it works is going to make my life hard in the end.ThanksCode: Select all
typedef struct page { u32int present : 1; // Page present in memory u32int rw : 1; // Read-only if clear, readwrite if set u32int user : 1; // Supervisor level only if clear u32int accessed : 1; // Has the page been accessed since last refresh? u32int dirty : 1; // Has the page been written to since last refresh? u32int unused : 7; // Amalgamation of unused and reserved bits u32int frame : 20; // Frame address (shifted right 12 bits) } page_t;
Code: Select all
Const
dwPresent = (1 Shl 0);
dwReadWrite = (1 Shl 1);
dwUser = (1 Shl 2);
etc
Type
PPage = ^TPage;
TPage = Record
Value : Dword;
End;
Function IsPagePresent(page : PPage) : Boolean
Begin
IsPagePresent = (page^.Value and dwPresent) <> 0;
End;
Procedure SetPagePresent(page : PPage, value : Boolean)
Begin
If (value) Then
page^.Value = page^.Value Or dwPresent;
Else
page^.Value = page^.Value And Not dwPresent;
End;
Re: Multitasking
Ok I am really battling with this. I am trying to setup the most basic multitasking system for now. I think the problem with mine arises either when I change esp, I think it changes back due to pascal. OR I am loading the wrong EIP. I really don't know where to go. I am trying to implement stack based switching. Is there another way of doing it, Not stack based??
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
There is the TSS-based (hardware-assisted) task switching, but the problem of changing stacks won't go away entirely.System123 wrote:Ok I am really battling with this. I am trying to setup the most basic multitasking system for now. I think the problem with mine arises either when I change esp, I think it changes back due to pascal. OR I am loading the wrong EIP. I really don't know where to go. I am trying to implement stack based switching. Is there another way of doing it, Not stack based??
Re: Multitasking
I would prefer to stay with software based switching. I think the problem is pascal. Pascal pushes the esp at the start of a procedure and then pops it off at the end. even though I have specified NOSTACKFRAME it still seems to be doing this. I might have to write my switching code in assembler. So I guess I will have to learn some more assembler.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
How would this be done in Pascal?
I know how to do everything except then part. What is a void variable?
Code: Select all
void move_stack(void *new_stack_start, u32int size)
Code: Select all
void *new_stack_start
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
A void pointer variable is an uncasted pointer to some data in memory.
"Sufficiently advanced stupidity is indistinguishable from malice."
Re: Multitasking
renamed using Pascal casing:How would this be done in Pascal?
Code: Select all
procedure MoveStack(NewStackStart: Pointer; Size: LongWord);
Re: Multitasking
Thanks. I thought it was something like that.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
Of course it does, it needs to remove the local variables of the stack.System123 wrote:I think the problem is pascal. Pascal pushes the esp at the start of a procedure and then pops it off at the end.
I don't know what compiler you are using, but in Borland Pascal there were various keywords for playing around with stackframes and the like. I remember 'interrupt;' and 'assembler;'.even though I have specified NOSTACKFRAME it still seems to be doing this.
Of course it must be done in assembler, there's no way to avoid that, regardless of the high level language you use.I might have to write my switching code in assembler.
JAL
Re: Multitasking
jal wrote:Of course it must be done in assembler, there's no way to avoid that, regardless of the high level language you use
Well I just did it in Pascal now. The Timer interrupt is handled with assembler. That I know I was referring to my scheduler code.
Only Problem I am having now is that the multitasker switched tasks 7 times then randomly page faults. I am trying to find the source of the fault, looks like it happens when I print to my screen, even though I have done that alot.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS
Re: Multitasking
Can someone please explain these two Bochs errors to me.
1:
2:
Thanks
Regards
System123
1:
Code: Select all
>>PANIC<< prefetch: getHostMemAddr vetoed direct read, pAddr=0x000b80a0
Code: Select all
00011919940i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00011924720i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00011929375i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
Regards
System123
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Currently - Busy with FAT12 driver and VFS