* same with xv6
[mascara-docs.git] / i386 / standford / 2004 / src / lab5 / lib / pgfault.c
blobcd9eedadbb1c8c03e4b967ccb79c1948e32c104e
1 // User-level page fault handler support.
2 // We use an assembly language wrapper around a C function.
3 // The assembly wrapper is in pfentry.S.
5 #include <inc/lib.h>
8 // Assembly language pgfault entrypoint defined in lib/pgfaultentry.S.
9 extern void _pgfault_entry(void);
11 // Pointer to currently installed C-language pgfault handler.
12 void (*_pgfault_handler)(u_int, u_int);
15 // Set the page fault handler function.
16 // If there isn't one yet, _pgfault_handler will be 0.
17 // The first time we register a handler, we need to
18 // allocate an exception stack and tell the kernel to
19 // call _asm_pgfault_handler on it.
21 void
22 set_pgfault_handler(void (*fn)(u_int va, u_int err))
24 int r;
26 if (_pgfault_handler == 0) {
27 // Your code here:
28 // map one page of exception stack with top at UXSTACKTOP
29 // register assembly pgfault entrypoint with JOS kernel
30 panic("set_pgfault_handler not implemented");
33 // Save handler pointer for assembly to call.
34 _pgfault_handler = fn;