(usermode is a lablel located somewhere near 0xc0004e50)
Code: Select all
void switch_to_usermode(){
//I replaced vars by constants hoping it might fix it
int data_segment = (4 * GDT_SELECTOR_MULTIPLIER) | RPL_USERMODE_MASK;//0x23
short data_seg16 = (short) data_segment;
int code_segment = (3 * GDT_SELECTOR_MULTIPLIER) | RPL_USERMODE_MASK;//0x1B
__asm{
cli
mov ax, data_seg16
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
mov ebx, 0x23
push ebx
push eax
pushf
pop eax
or eax, 0x200
push eax
mov ebx, 0x1B
push ebx
push usermode
iret
} usermode:
return;
}
My theorys are:
- It corrupting my stack pointer and that makes it pop a invalid value
- I have the push/pops in the wrong order
I have used the bochs debugger to check the registers but it is lacking a good way of examining the stack, but i do now EBX is being set correctly, FLAGS is being loaded into EAX and ES,DS,FS,GS are all being set correctly