Page 1 of 1

Problem with Ring 3 Tasks and TSS

Posted: Tue Feb 19, 2008 1:06 pm
by gzaloprgm
Hi! I'm having problems running tasks, when I try to run a test function (void test(){while(1);}) in Ring 3, it makes a general protection fault, and in bochs log it says the following:
fetch_raw_descriptor: LDT: index (4027)804 > limit (2F)

I think it's a problem with setting GDT gates. My code:

Code: Select all

void init_gdt(){
gp.limit = (sizeof(struct gdt_entry) * 6) - 1;

gp.base = (unsigned int) gdt;
gdt_set_gate(0, 0, 0, 0, 0);
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);


gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);


gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);

gdt_set_gate(5, (unsigned long) &global_tss, sizeof( TSS_t ), 0x89, 0x0F );
global_tss.esp0 = (unsigned int) (&ring3stack + 1024);

global_tss.ss0 = 0x10;

global_tss.ldt = 0;
gdt_flush();
__asm__ __volatile__ ( "ltr %%ax" : : "a" ( 5 * sizeof( struct gdt_entry ) ) );
}
ring3stack is an array of 1024 chars.

My CreateUserThread function uses cs 0x18 | 3, ds,es,fs,gs,ss 0x20 | 3, eflags 0x3202;

What am I doing wrong?

Thanks, Gonzalo

Posted: Tue Feb 19, 2008 2:01 pm
by Combuster
There's a wrong segment value being loaded at some point. You should be able to get the exact location from the error handler. A stab at the dark would be that you have a bad stackframe when you get to an IRET.

Posted: Fri Feb 22, 2008 3:59 am
by naiksidd_85
I dont see any thing wrong with the code ..
I am using a similar code and it is working fine