Getting around the TSS with software task-switching
Posted: Wed Apr 01, 2009 12:14 pm
Ok, So I got my software task switching system perfect finally.. Now I have a problem though. Adding a stupid TSS so usermode can have interrupts... which, btw, is it possible to avoid the TSS altogether with usermode? Like, if a page-fault happened in usermode would that require the TSS? Cause I would be perfectly content using GPFs or the like instead of interrupts for syscalls... (infact, it seems more flexible to me)
Anyway though. My problem:
the INT0_STACK_BASE bit makes it so if an interrupt happens inside an interrupt, it will use a new stack.. I don't remember why, but reusing the old stack caused me some kind of problems before..
But on to my question.. how would I incorporate the TSS into this stub? The problem is the mov esp,eax. This is for my task-scheduler. It returns the programs stack address, so that all the variables can easily be popped off as if nothing happened.. If I had a TSS I would not be able to have this same functionality. I wouldn't be able to store the old stack address for the scheduler. How do I get around this problem?
Anyway though. My problem:
Code: Select all
int_template: ;compiled once but edited and used as a template
pusha
push ds
push es
push fs
push gs
mov ax, 0x08 ; Load the Kernel Data Segment descriptor!
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss,ax
mov ebx, esp ; move the stack to temporary location
mov eax,0
mov al,byte [int_level]
shl eax,12 ;align it to a page
or eax,INT0_STACK_BASE
inc byte [int_level]
mov esp,eax
push ebx ;push old stack value onto new stack
mov eax, int_catcher ;this stays constant
call eax ; A special call, preserves the 'eip' register
;Get the return value
pop esp ;throw away parameter
mov esp,eax ;The int_catcher returns the stack!
dec byte [int_level]
;pop eax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
end_template:
But on to my question.. how would I incorporate the TSS into this stub? The problem is the mov esp,eax. This is for my task-scheduler. It returns the programs stack address, so that all the variables can easily be popped off as if nothing happened.. If I had a TSS I would not be able to have this same functionality. I wouldn't be able to store the old stack address for the scheduler. How do I get around this problem?