problem of SWITCH TO USER MODE solved :-)
Posted: Fri Aug 08, 2008 2:15 am
first : sorry for my poor english ...
following is the code of PL0--->PL3
run it in bochs , panic " iret: AR byte indicated non code segment"
following code is the initialization of GDT
please help me to check the problem. about " iret: AR byte indicated non code segment" ..
i just want PL0-->PL3 and then do nothing to decrease complexity
thank you everymuch. ...
following is the code of PL0--->PL3
Code: Select all
#define switch_to_user_mode()\
__asm____volatile__("movl $0x23, %%eax\n\t" \
"movw %%ax, %%ds\n\t" \
"movw %%ax, %%es\n\t" \
"movw %%ax, %%fs\n\t" \
"movw %%ax, %%gs\n\t" \
"mov %%eax, %%esp\n\t"\
"pushl $0x23\n\t" \
"pushl %%esp\n\t" \
"pushfl \n\t" \
"pushl $0x1b\n\t" \
"pushl $1f\n\t" \
"iret\n\t" \
"1: "\
:::ax)
following code is the initialization of GDT
Code: Select all
#define load_gdtr(n)\
__asm__("lgdt (%%eax)\n\t"\
::"a" (n));
void init_gdt(void)
{
gdt_ptr.limit=(sizeof(gdt_entry_t))*5-1;
gdt_ptr.base=(u32int)&gdt_entries;
set_gdt_gate(0,0,0,0,0);
set_gdt_gate(1, 0, 0xffFFffff, 0x9A, 0xCF); // Code segment 0x08
set_gdt_gate(2, 0, 0xffFFffff, 0x92, 0xCF); // Data segment 0x10
set_gdt_gate(3, 0, 0xffFFffff, 0xFA, 0xcF); // User mode code segment 0x1b 0001 1011
set_gdt_gate(4, 0, 0xffFFffff, 0xF2, 0xcF); // User mode data segment 0x23 0020 0011
load_gdtr((u32int)&gdt_ptr);
}
void set_gdt_gate(u32int num, u32int base, u32int limit, u8int access, u8int gran)
{
gdt_entries[num].base_low=(base&0xffff);
gdt_entries[num].base_middle=((base>>16)&0xff);
gdt_entries[num].base_high=((base>>24)&0xff);
gdt_entries[num].limit_low=(limit&0xffff);
gdt_entries[num].granularity=((limit>>16)&0x0f);
gdt_entries[num].granularity|=(gran&0xf0);
gdt_entries[num].access=access;
}
i just want PL0-->PL3 and then do nothing to decrease complexity
thank you everymuch. ...