Problem with Ring 3 Tasks and TSS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Problem with Ring 3 Tasks and TSS

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
naiksidd_85
Member
Member
Posts: 76
Joined: Thu Jan 17, 2008 1:15 am

Post by naiksidd_85 »

I dont see any thing wrong with the code ..
I am using a similar code and it is working fine
Learning a lot these days THANKS to OSdev users
Post Reply