Problem with Ring 3 Tasks and TSS
Posted: Tue Feb 19, 2008 1:06 pm
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:
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
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 ) ) );
}
My CreateUserThread function uses cs 0x18 | 3, ds,es,fs,gs,ss 0x20 | 3, eflags 0x3202;
What am I doing wrong?
Thanks, Gonzalo