GPF on trying to go back to real mode
Posted: Sat Mar 22, 2008 6:05 pm
Good evening.
Im trying to go back from protected mode to (un)real
Problems arise immediately...
First of all; GDT is declared as such:
I load my real mode task
And finaly my 16 bit code with switcher
The long jump causes a General Protection Fault.
Is there something else I must do first?
Move the stack? Turn off paging?
Im trying to go back from protected mode to (un)real
Problems arise immediately...
First of all; GDT is declared as such:
Code: Select all
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); //CODE segment 0x08
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); //DATA segment 0x10
gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF); //User mode CODE 0x18
gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF); //User DATA 0x20
gdt_set_gate(5, 0, 0xFFFF, 0x9A, 0x00); //16 bit CODE 0x28
gdt_set_gate(6, 0, 0xFFFF, 0x92, 0x00); //16 bit DATA 0x30
gdt_set_gate(7, (int)&global_tss, sizeof(TSS_t), 0x89, 0x0F); //TSS 0x38
Code: Select all
current_directory->tables_physical[0] = current_directory->tables_physical[0xC0000000>>22]; //Identity map first mb
switch_page_directory(current_directory);
extern void switch_16bit();
extern void s16();
memcpy(0x7c00, &s16, 0x1000); //Copy 16 bit code to 0x7C00. It should be safe to use now, right?
switch_16bit();
Code: Select all
global switch_16bit
global s16
switch_16bit:
cli
mov al, 0xFF ; Mask all irqs
out 0x21, al
out 0xA1, al
jmp 0x7c00 ;Jump to the place s16 was loaded
s16:
pushad
jmp 0x28:$+2 //<---GPF HERE
[bits 16]
do_16_bitm:
mov ax, 0x30
mov ds, ax
mov ss, ax
jmp $
Is there something else I must do first?
Move the stack? Turn off paging?