triple fault after context switch
Posted: Mon Aug 08, 2016 11:01 pm
So, after my kernel setup all the memory management and file system stuff, I decided to load a usermode entry program(flat binary, not elf) from hard disk and run it under user mode.
This is how I do it in detail
In kernel mode, load a program called "userentry.bin", which is basically a program that loops infinitely
In load_program:
The yield system call will then call the scheduler function, which finds next function to run, which has to be the process created in load_program().
Then scheduler does a context switch to the program, and the program does start running.
However, a triple fault occur after 1 second.
I've tried to set breakpoints on the interrupt or exception handler, but the kernel always triple fault before any exception/interrupt happens
I also tried to insert a int 0x80 instruction into the program, and it will immediately triple fault and reset the machine.
I understand that my way of loading a process is kind of weird because I did not even create a separate address space for the new program, but i'm just experimenting running a few programs concurrently in user mode
I suspect that the context I manually created for the process leads to the triple fault..
Can someone explain what's going on ??
my os code is here for reference: https://github.com/szhou42/osdev/tree/master/src
Any help would be appreciated! Thanks!
This is how I do it in detail
In kernel mode, load a program called "userentry.bin", which is basically a program that loops infinitely
Code: Select all
load_program("userentry.bin");
Code: Select all
vfs_node_t * program = file_open(filename, 0);
if(!program) {
printf("Fail to open %s, does it even exist?\n", filename);
return;
}
uint32_t size = vfs_get_file_size(program);
char * program_code = kcalloc(size, 1);
vfs_read(program, 0, size, program_code);
// create a process, all the context registers are zeroed out by calloc(), set eip to the start of program code, also set IF flag
pcb_t * p1 = kcalloc(sizeof(pcb_t), 1);
memcpy(p1, current_process, sizeof(pcb_t));
p1->regs.eip = (uint32_t)program_code;
p1->regs.eflags = 0x200; // enable interrupt
// Insert the process into process list
p1->self = list_insert_front(process_list, p1);
// call yield via a system call, but actually we're still in kernel mode..
asm volatile("mov $1, %eax");
asm volatile("int $0x80");
Then scheduler does a context switch to the program, and the program does start running.
However, a triple fault occur after 1 second.
I've tried to set breakpoints on the interrupt or exception handler, but the kernel always triple fault before any exception/interrupt happens
I also tried to insert a int 0x80 instruction into the program, and it will immediately triple fault and reset the machine.
I understand that my way of loading a process is kind of weird because I did not even create a separate address space for the new program, but i'm just experimenting running a few programs concurrently in user mode
I suspect that the context I manually created for the process leads to the triple fault..
Can someone explain what's going on ??
my os code is here for reference: https://github.com/szhou42/osdev/tree/master/src
Any help would be appreciated! Thanks!