Page 1 of 1
Stack segment for kernel threads
Posted: Wed Aug 30, 2006 10:09 pm
by Candamir
I am implementing kernel threads in my scheduler, but they don't work - the scheduler sets every value correctly, but the thread simply won't get executed, instead the kernel keeps on executing and interrupts (keyboard) don't work anymore.
I think I found the problem: The stack segment. When no ring change occurs, ss and useresp aren't pushed/popped on/off the stack, right? So how can I set ss for a kernel thread?
Candamir
Re:Stack segment for kernel threads
Posted: Thu Aug 31, 2006 12:48 am
by JoeKayzA
Do you use a segmented or a flat memory model? This could make a difference. Assuming the latter:
When no ring change occurs, the stack segment and stack pointer are not changed during IRET. A kernel thread should use the kernel's data segment as its stack segment, and the thread's saved state resides at the top of the thread's stack, right? When you are executing the scheduler, SS is using the kernel data segment already (I guess, at least), so you change ESP to the next thread's stack top, restore the state and perform IRET, that should be all. No need to switch the stack segment explicitly, AFAICS.
cheers Joe
Re:Stack segment for kernel threads
Posted: Thu Aug 31, 2006 2:31 am
by distantvoices
Joe 's right here.
If you remain at ring0 you change ring0 stacks. Even an int XX or a HW IRQ doesn't affect the stack. STack (esp&ss) is only changed upon transition from lesser privileged segment to higher privileged ones and vice versa. say: ring3->ring0 causes the processor to pick esp0/ss0 pair from the system tss and work on these instead of the esp3/ss3 the thread is using.
HTH.
Re:Stack segment for kernel threads
Posted: Sat Sep 02, 2006 10:10 pm
by Candamir
Multitasking is driving me crazy!
I've now surely reworked the entire taskmanager and the entire interrupts code, but everything's still the same...
After the very first switch, kernel main() keeps executing (instead of the other thread), but interrupts don't happen anymore. The strange thing is that ISRs still happen, but IRQs won't happen anymore. This is strange because the EOI is sent and I also don't see anything wrong with the interrupt handler code in general.
I must admit that I'm pretty much out of ideas by now, so I'll attach the relevant part of the source, in hope someone could take a look at it...
Thanks
Candamir
Re:Stack segment for kernel threads
Posted: Sun Sep 03, 2006 12:46 am
by earlz
I also have that problem in my code(before I broke it trying to fix it..)and even if I do a sti right before I iret(and I know it gets to the iret) it for some reason has interrupts disabled, my only idea is to check your eflags pushed on the stack
Re:Stack segment for kernel threads
Posted: Sun Sep 03, 2006 1:40 am
by Candy
Jordan3 wrote:
I also have that problem in my code(before I broke it trying to fix it..)and even if I do a sti right before I iret(and I know it gets to the iret) it for some reason has interrupts disabled, my only idea is to check your eflags pushed on the stack
Your iret pops a new set of flags from the stack, sti doesn't work until one opcode AFTER it completes, and since you disable interrupts in that one...
Check the stack flags & 0x200. If that's 0, no irq's will be seen.
Re:Stack segment for kernel threads
Posted: Sun Sep 03, 2006 3:40 pm
by Candamir
Apparently I forgot to attach the code...
BTW, I set eflags to 0x206
Candamir