aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/fs.c2
-rw-r--r--kernel/syscall.c5
-rw-r--r--kernel/trampoline.S12
-rw-r--r--kernel/vm.c5
4 files changed, 22 insertions, 2 deletions
diff --git a/kernel/fs.c b/kernel/fs.c
index dea5864..c6bab15 100644
--- a/kernel/fs.c
+++ b/kernel/fs.c
@@ -194,7 +194,7 @@ static struct inode* iget(uint dev, uint inum);
// Allocate an inode on device dev.
// Mark it as allocated by giving it type type.
// Returns an unlocked but allocated and referenced inode,
-// or NULL if there is no free inode..
+// or NULL if there is no free inode.
struct inode*
ialloc(uint dev, short type)
{
diff --git a/kernel/syscall.c b/kernel/syscall.c
index ee94696..ed65409 100644
--- a/kernel/syscall.c
+++ b/kernel/syscall.c
@@ -79,6 +79,7 @@ argstr(int n, char *buf, int max)
return fetchstr(addr, buf, max);
}
+// Prototypes for the functions that handle system calls.
extern uint64 sys_fork(void);
extern uint64 sys_exit(void);
extern uint64 sys_wait(void);
@@ -101,6 +102,8 @@ extern uint64 sys_link(void);
extern uint64 sys_mkdir(void);
extern uint64 sys_close(void);
+// An array mapping syscall numbers from syscall.h
+// to the function that handles the system call.
static uint64 (*syscalls[])(void) = {
[SYS_fork] sys_fork,
[SYS_exit] sys_exit,
@@ -133,6 +136,8 @@ syscall(void)
num = p->trapframe->a7;
if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
+ // Use num to lookup the system call function for num, call it,
+ // and store its return value in p->trapframe->a0
p->trapframe->a0 = syscalls[num]();
} else {
printf("%d %s: unknown sys call %d\n",
diff --git a/kernel/trampoline.S b/kernel/trampoline.S
index 0aaa413..d7308cc 100644
--- a/kernel/trampoline.S
+++ b/kernel/trampoline.S
@@ -80,9 +80,18 @@ uservec:
# load the address of usertrap(), from p->trapframe->kernel_trap
ld t0, 16(a0)
- # load the kernel page table, from p->trapframe->kernel_satp
+
+ # fetch the kernel page table address, from p->trapframe->kernel_satp.
ld t1, 0(a0)
+
+ # wait for any previous memory operations to complete, so that
+ # they use the user page table.
+ sfence.vma zero, zero
+
+ # install the kernel page table.
csrw satp, t1
+
+ # flush now-stale user entries from the TLB.
sfence.vma zero, zero
# jump to usertrap(), which does not return
@@ -96,6 +105,7 @@ userret:
# a0: user page table, for satp.
# switch to the user page table.
+ sfence.vma zero, zero
csrw satp, a0
sfence.vma zero, zero
diff --git a/kernel/vm.c b/kernel/vm.c
index 284b72d..9f69783 100644
--- a/kernel/vm.c
+++ b/kernel/vm.c
@@ -61,7 +61,12 @@ kvminit(void)
void
kvminithart()
{
+ // wait for any previous writes to the page table memory to finish.
+ sfence_vma();
+
w_satp(MAKE_SATP(kernel_pagetable));
+
+ // flush stale entries from the TLB.
sfence_vma();
}