Process page fault handler

This commit is contained in:
Thomas Lovén 2018-03-06 10:28:35 +01:00
parent 4ecec1eec6
commit 28c82567a0
2 changed files with 22 additions and 0 deletions

View File

@ -21,10 +21,16 @@ struct process *sched_proc = 0;
struct process *_proc = 0; struct process *_proc = 0;
void procmm_init(struct process *p); void procmm_init(struct process *p);
registers *proc_pagefault(registers *r);
uint64_t next_pid = 1; uint64_t next_pid = 1;
struct process *new_process(void (*function)(void)) struct process *new_process(void (*function)(void))
{ {
if(next_pid == 1)
{
bind_interrupt(14, proc_pagefault);
}
struct process *proc = P2V(pmm_calloc()); struct process *proc = P2V(pmm_calloc());
proc->pid = next_pid++; proc->pid = next_pid++;
proc->stack_ptr = incptr(proc, PAGE_SIZE - sizeof(struct swtch_stack)); proc->stack_ptr = incptr(proc, PAGE_SIZE - sizeof(struct swtch_stack));

View File

@ -4,6 +4,7 @@
#include <stddef.h> #include <stddef.h>
#include <debug.h> #include <debug.h>
#include <memory.h> #include <memory.h>
#include <cpu.h>
void procmm_init(struct process *p) void procmm_init(struct process *p)
{ {
@ -22,3 +23,18 @@ uint64_t procmm_brk(struct process *p, void *addr)
} }
return p->brk; return p->brk;
} }
registers *proc_pagefault(registers *r)
{
if(!(r->rflags & (3<<12)))
{
debug_error("Page fault in kernel!\n");
debug("Interrupt number: %d Error code: %d\n", r->int_no, r->err_code);
debug_print_registers(r);
PANIC("Page fault in kernel\n");
}
PANIC("Page fault in process\n");
return r;
}