Page 2 of 2
Re: Multi Tasking: User level task return problem
Posted: Sat Oct 04, 2008 9:08 am
by AJ
Hi,
No - when an interrupt occurs, the ring 3 SS and ESP, EFLAGS, EIP and CS are pushed on to a stack loaded from the TSS. That is, the SS0 and ESP0 are loaded. Because you don't set SS0, it points to your NULL segment - which is invalid. SS0 needs to point to a valid data segment descriptor.
Cheers,
Adam
Re: Multi Tasking: User level task return problem
Posted: Sat Oct 04, 2008 11:24 am
by PinkyNoBrain
Ok cool, i must have missed that bit from the manual. Ive ammended the code i posted before as to set ss0 to 0x10 which is my kernel data segment descriptor as follows:
Code: Select all
SysTSS[get_ProcessorNumber()].esp0 = CurrentProcess->KStackPointer;
SysTSS[get_ProcessorNumber()].cr3 = CurrentProcess->PageDirectoryAddress;
SysTSS[get_ProcessorNumber()].ss0 = 0x10;
write_cr3(CurrentProcess->PageDirectoryAddress);
asm ("movl %0, %%esp\n\t" : :"r"(CurrentProcess->KStackPointer));
asm("pop %ds\n\t");
asm("pop %es\n\t");
asm("pop %fs\n\t");
asm("pop %gs\n\t");
asm("popa\n\t");
asm("iret\n\t");
Unfortunatly im still getting this SS null error as before. I think i must be missing somewhere else that im supposed to set it aswell. Thanks for your patience everybody, your help is much appreciated
Chris
P.S I have recompiled bochs with debugging support(although im not very good at it) so if anyone requires any additional output just ask
Re: Multi Tasking: User level task return problem
Posted: Sun Oct 05, 2008 5:16 am
by Combuster
PinkyNoBrain wrote:P.S I have recompiled bochs with debugging support(although im not very good at it) so if anyone requires any additional output just ask
Try setting a breakpoint in userland code, then ask Bochs about the GDT and TSS information so you're sure they're all set correctly.
Some sample output (with annotations and things to check - comes from my kernel):
Code: Select all
<bochs:1> lb 0x400000 <- location of code in userspace, probably different in your case
<bochs:2> c
(...) <- at some point the simulation will break back to the debugger
<bochs:10> info tss
tr:s=0x80, base=0x10c000, valid=1 <- check these for sanity
ss:esp(0): 0x0010:0x00124000 <- apparently these are 0x0000:0x???????? in your case
ss:esp(1): 0x0000:0x00000000
ss:esp(2): 0x0000:0x00000000
(...) <- the rest is not really interesting
<bochs:11> info gdt 0 17 <- the GDT entries I use. info gdt will list them all(!), info gdt 0 8 will most likely suffice in your case
Global Descriptor Table (base=0x00106000, limit=2047):
GDT[0x00]=??? descriptor hi=0x00000000, lo=0x00000000
GDT[0x01]=Code segment, laddr=00000000, limit=fffff * 4Kbytes, Execute-Only, 32-bit
GDT[0x02]=Data segment, laddr=00000000, limit=fffff * 4Kbytes, Read/Write, Accessed
|----| -> ss(0) must be 0x02 (entry) * 8 = 0x10, matches with above
Apart from the 0x02 the rest of the line should be identical.
GDT[0x03]=Code segment, laddr=00000000, limit=fffff * 4Kbytes, Execute-Only, 32-bit
GDT[0x04]=Data segment, laddr=00000000, limit=fffff * 4Kbytes, Read/Write, Accessed
(...) <- more GDT entries
GDT[0x10]=32-Bit TSS (Busy) at 0x0010c000, length 0x02fff
|----| -> tss.s must be 0x10 (probably different in your case) * 8 = 0x80, matches with above
tss.base must match the offset mentioned here: 0x(00)10c000
should be busy, length should not be zero.
*makes a mental note to copy this to the wiki*
Re: Multi Tasking: User level task return problem
Posted: Sun Oct 05, 2008 11:46 am
by PinkyNoBrain
Hey everybody,
problem solved . Here is what i think was happening. I believe my original problem was being caused by my failure to set SS0 in the TSS, this was well spotted by Adam. Unfortunatly in my attempts to debug my code i some how disabled the call to the function that does loads the tss into the task register
so very imbarrisingly my later problems where all due to the tr not even pointing to my TSS. Thanks to combusters advice about bochs debugging i spotted this with info tss. Once i re-enabled the function call everything worked perfectly, i am getting a pagefault when my scheduling code gets called which doesnt appear with a supervisor task but ill get to the bottom of that. I am officialy marking this thread as solved
.
A
BIG thanks to everybody who gave me help and advice its very much appreciated,
Chris
Re: Multi Tasking: User level task return problem[SOLVED]
Posted: Mon Oct 06, 2008 2:52 am
by AJ
Good to hear it's working
Cheers,
Adam