Scheduling
Posted: Fri Mar 16, 2007 11:48 am
I am writing code for my scheduler. I had a scheduler earlier which could nicely multitask but all the task list was a static declaration. Now i have implemented a memory manager and now i keep the tasks in a linked list.
I need to know certain things about the scheduler:
This code as is easily understood saves the cpu regs in proc_fooler on timer interrupt and restores them back on 'iret'.
The C scheduler (_uirq0) changes the contents of _proc_fooler to the new task for switching to the new task.
The cpustate for the new task(including esp) is correctly set so that the task starts executing on iret when the contents of proc_fooler are changed to it.
My question is that is this whole code correct. Is there any part which could generate GPFs or stack faults. My old scheduler was working fine 90% of the cases.
Now when i am making a new sched i need to make it good. What change should i make to switch to a ring3 task?
Thanx
I need to know certain things about the scheduler:
Code: Select all
;struct CPU_state {
; unsigned long eax; 0
; unsigned long ebx; 4
; unsigned long ecx; 8
; unsigned long edx; 12
; unsigned long esi; 16
; unsigned long edi; 20
; unsigned int fs; 24
; unsigned int gs; 26
; unsigned int es; 28
; unsigned int ds; 30
; unsigned long esp; 32
; unsigned long ebp; 36
;};
extern _proc_fooler ;Intermediate low level current task state (struct CPU_state)
global _save_state_immediate
_save_state_immediate:
mov dword[_proc_fooler+00],eax
mov dword[_proc_fooler+04],ebx
mov dword[_proc_fooler+08],ecx
mov dword[_proc_fooler+12],edx
mov dword[_proc_fooler+16],esi
mov dword[_proc_fooler+20],edi
mov word[_proc_fooler+24],fs
mov word[_proc_fooler+28],gs
mov word[_proc_fooler+32],es
mov word[_proc_fooler+36],ds
mov dword[_proc_fooler+40],esp
mov dword[_proc_fooler+44],ebp
ret
global _load_state_immediate
_load_state_immediate:
mov eax,dword[_proc_fooler+00]
mov ebx,dword[_proc_fooler+04]
mov ecx,dword[_proc_fooler+08]
mov edx,dword[_proc_fooler+12]
mov esi,dword[_proc_fooler+16]
mov edi,dword[_proc_fooler+20]
mov fs,word[_proc_fooler+24]
mov gs,word[_proc_fooler+28]
mov es,word[_proc_fooler+32]
mov esp,dword[_proc_fooler+40]
mov ebp,dword[_proc_fooler+44]
mov ds,word[_proc_fooler+36]
ret
global _irq0
irq0:
call _save_state_immediate
push gs
push fs
push es
push ds
pusha
call _uirq0
popa
pop ds
pop es
pop fs
pop gs
call _load_state_immediate
iret
The C scheduler (_uirq0) changes the contents of _proc_fooler to the new task for switching to the new task.
The cpustate for the new task(including esp) is correctly set so that the task starts executing on iret when the contents of proc_fooler are changed to it.
My question is that is this whole code correct. Is there any part which could generate GPFs or stack faults. My old scheduler was working fine 90% of the cases.
Now when i am making a new sched i need to make it good. What change should i make to switch to a ring3 task?
Thanx