81
OS-Design / Re: FreeBasic: Software Multitasking
« am: 15. May 2009, 07:44 »
Hm, ich hab das Multitasking-Zeug mal neu geschrieben, nach einem Tut das ich auf google code gefunden habe. Der Kernel sorgt dafür, das zwei Tasks vorbereitet werden, erlaubt IRQs und geht in eine Endlosschleife.
Das Problem ist: Sobald der erste Task aktiviert wird, kriege ich einen GPF.
Screenshot: http://darkinsanity.freehoster.ch/FROST_V0.2.0a.PNG
Den Code dazu gibts hier: http://darkinsanity.freehoster.ch/FROST_V0.2.0a_unstable.zip
Ein paar Auszüge:
Das Problem ist: Sobald der erste Task aktiviert wird, kriege ich einen GPF.
Screenshot: http://darkinsanity.freehoster.ch/FROST_V0.2.0a.PNG
Den Code dazu gibts hier: http://darkinsanity.freehoster.ch/FROST_V0.2.0a_unstable.zip
Ein paar Auszüge:
Code: [Auswählen]
type TaskType
ID as USHORT '// the ID of the task
stack as UINTEGER '// the stack of the task
eip as UINTEGER
status as BYTE '// the status of the task (blocked, ready, active...)
end type
dim shared Tasks(100) as TaskType
function Multitasking_scheduler (stack as UINTEGER) as UINTEGER
Tasks(currentPID).stack = stack
currentPID += 1
if currentPID > AllTasks then currentPID = 1
return Tasks(currentPID).stack
end function
sub Multitasking_Switch naked
dim tempstack as UINTEGER
asm
pusha
push ds
push es
push fs
push gs
mov eax, &h10
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov eax, esp
mov [tempstack], eax
end asm
tempstack = Multitasking_scheduler(tempstack)
asm
mov eax, [tempstack]
mov esp, eax
mov al, &h20
out &h20, al
pop gs
pop fs
pop es
pop ds
popa
iret
end asm
end sub
Code: [Auswählen]
sub Task_Create (ID as USHORT, address as any ptr)
if Tasks(ID).status <> TASK_EMPTY then return '// place not free
dim stack as UINTEGER
dim kernelstack as UINTEGER
asm cli '// we donŽt want to be interrupted
stack = cast(UINTEGER, malloc(4096) + 4096) '// allocate space for 4kb stack
print "Allocated Stack: ";
print stack
asm
mov eax, esp '// get the stackpointer in eax
mov [kernelstack], eax '// save the kernelstack-pointer
mov eax, [stack] '// load the new stack into eax
mov esp, eax '// get the new stack to esp
mov eax, &h202
push eax
mov eax, &h08
push eax
push [address]
mov eax, &h0
push eax
push eax
push eax
push eax
push eax
push eax
push eax
push eax
mov eax, &h10
push eax
push eax
push eax
push eax
end asm
Tasks(ID).status = TASK_READY
Tasks(ID).stack = stack
Tasks(ID).eip = cast(UINTEGER, address)
AllTasks += 1
asm sti
end sub