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
Stack segment for kernel threads
Re:Stack segment for kernel threads
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
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
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Stack segment for kernel threads
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.
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.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:Stack segment for kernel threads
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
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
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
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...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
Check the stack flags & 0x200. If that's 0, no irq's will be seen.
Re:Stack segment for kernel threads
Apparently I forgot to attach the code...
BTW, I set eflags to 0x206
Candamir
BTW, I set eflags to 0x206
Candamir