Re: Some questions - tasks, the stack
Posted: Tue Aug 02, 2011 6:31 am
You should save/restore general purpose and segment registers within interrupt handler. And I think you will have some problems with supporting user mode while using that task switching technique.
Look at my simplified example. Maybe it will be useful for you.
Initial stack frame for kernel thread:
Look at my simplified example. Maybe it will be useful for you.
Code: Select all
struc TS ; ThreadStructure
{
.pred dd ?
.next dd ?
.stackpointer dd ?
.activepriority dd ?
.priority dd ?
}
proc SwitchToNext ; cs=KCODE, ds=es=ss=KDATA
push fs
push gs
pushf
cli
; mov eax,[TSS.sp0]
mov [eax+TS.stackpointer],esp
mov eax,[eax+TS.next]
mov esp,[eax+TS.stackpointer]
mov [TSS.sp0],eax
popf
pop gs
pop fs
ret
proc IRQ0Handler
pusha
push ds
push es
mov al,20h
out 20h,al
push ss
pop ds ; ds <- KDATA
push ss
pop es ; es <- KDATA
mov eax,[TSS.sp0]
; dec,[eax+TS.activepriority]
; jnz @f
; mov ecx,[eax+TS.priority]
; mov [eax+TS.activepriority],ecx
; cmp eax,[eax+TS.next]
; je @f
call SwitchToNext
@@:
pop es
pop ds
popa
iret
Code: Select all
TS+16: PRIORITY
TS+12: PRIORITY
TS+08: TS-16
TS+04: ? ; undefined before InsertTSInRunQueue operation
TS+00: ? ; undefined before InsertTSInRunQueue operation
TS-04: START
TS-08: FS
TS-12: GS
TS-16: EFLAGS