triple fault when switching to usermode
Posted: Thu Jun 09, 2016 4:46 pm
Hi, I am following JamesM's tutorial.
My problem is, after switched to user mode and temporarily return to the kernel code, it triple faults.
After some debugging I found that it faults on a push instruction. If i try to execute push instruction in gdb, the eip changes to 0xe05b(I believes this behavior is triple fault)
I think it has something to do with user accessing memory belong to kernel, but i am not sure how to fix it
Btw, I didn't do move_stack as the tutorial suggests because I thought it was not necessary(Could this be a problem?).
main.c
usermode.asm
debugging:
My problem is, after switched to user mode and temporarily return to the kernel code, it triple faults.
After some debugging I found that it faults on a push instruction. If i try to execute push instruction in gdb, the eip changes to 0xe05b(I believes this behavior is triple fault)
I think it has something to do with user accessing memory belong to kernel, but i am not sure how to fix it
Btw, I didn't do move_stack as the tutorial suggests because I thought it was not necessary(Could this be a problem?).
main.c
Code: Select all
int main(struct multiboot *mboot_ptr, void * initial_stack)
{
initial_esp = initial_stack;
init_descriptor_tables();
init_video();
timer_install();
keyboard_install();
initialise_paging(0x80000000);
__asm__ __volatile__ ("sti");
// other stuff
initialise_syscalls();
switch_to_user_mode();
syscall_printf("printing from usermode \n");
return 0;
}
Code: Select all
[GLOBAL usermode]
usermode:
cli
mov ax, 0x23
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push 0x23
push eax
pushf
push 0x1B
push endlabel
iret
endlabel:
ret
Code: Select all
0x00100104 <+248>: call 0x10b6de <switch_to_user_mode>
0x00100109 <+253>: sub $0xc,%esp
=> 0x0010010c <+256>: push $0x10d104
0x00100111 <+261>: call 0x10b6eb <syscall_printf>
0x00100116 <+266>: add $0x10,%esp
0x00100119 <+269>: mov $0x0,%eax
0x0010011e <+274>: mov -0x4(%ebp),%ecx
0x00100121 <+277>: leave
0x00100122 <+278>: lea -0x4(%ecx),%esp
0x00100125 <+281>: ret
End of assembler dump.
(gdb) info reg
eax 0x6f0c 28428
ecx 0xf00 3840
edx 0x10d104 1102084
ebx 0x9500 38144
esp 0x6f14 0x6f14
ebp 0x6f28 0x6f28
esi 0x0 0
edi 0x152000 1384448
eip 0x10010c 0x10010c <main+256>
eflags 0x16 [ PF AF ]
cs 0x1b 27
ss 0x23 35
ds 0x23 35
es 0x23 35
fs 0x23 35
gs 0x23 35
(gdb) stepi
0x0000e05b in ?? ()
(gdb) info reg
eax 0x0 0
ecx 0x0 0
edx 0x663 1635
ebx 0x0 0
esp 0x0 0x0
ebp 0x0 0x0
esi 0x0 0
edi 0x0 0
eip 0xe05b 0xe05b
eflags 0x2 [ ]
cs 0xf000 61440
ss 0x0 0
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0