From 0c10cbe829787a2745b0f7e3ad46f200b0b94d34 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Fri, 2 Aug 2019 11:55:26 -0400 Subject: [PATCH] syscall lab nits --- kernel/syscall.c | 2 -- labs/syscall.html | 40 +++++++++++++++++++++------------------- labs/xv6.html | 8 ++++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index 197bca1..97974d6 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -138,9 +138,7 @@ syscall(void) num = p->tf->a7; if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { - //printf("%d: syscall %d\n", p->pid, num); p->tf->a0 = syscalls[num](); - //printf("%d: syscall %d -> %d\n", p->pid, num, p->tf->a0); } else { printf("%d %s: unknown sys call %d\n", p->pid, p->name, num); diff --git a/labs/syscall.html b/labs/syscall.html index d465f35..72ef19b 100644 --- a/labs/syscall.html +++ b/labs/syscall.html @@ -12,9 +12,9 @@ and switching between threads of execution. In particular, you will implement new system calls (sigalarm and sigreturn) and switching between threads of a user-level thread package. -

RISC-V assembly

+

Warmup: RISC-V assembly

-

For this lab it will be important to understand RISC-V assembly. +

For this lab it will be important to understand a bit of RISC-V assembly.

Add a file user/call.c with the following content, modify the Makefile to add the program to the user programs, and compile (make @@ -40,21 +40,22 @@ void main(void) { } -

Read through call.asm and understand it. The instruction manual +

Read through user/call.asm and understand it. The instruction manual for RISC-V is in the doc directory (doc/riscv-spec-v2.2.pdf). Here are some questions that you should answer for yourself:

@@ -87,9 +88,9 @@ print its output.)

Hint: modify the syscall() function in kernel/syscall.c. -

Run the programs you wrote in the lab and inspect the system call - trace. Are there many system calls? Which systems calls correspond - to code in the applications you wrote above? +

Run the xv6 programs you wrote in earlier labs and inspect the system call + trace. Are there many system calls? Which system calls correspond + to code in the applications you wrote?

Optional: print the system call arguments. @@ -109,14 +110,14 @@ to handle page faults in the application, for example. You should add a new sigalarm(interval, handler) system call. If an application calls sigalarm(n, fn), then after every n "ticks" of CPU time that the program consumes, the kernel -will cause application function +should cause application function fn to be called. When fn returns, the application -will resume where it left off. A tick is a fairly arbitrary unit of +should resume where it left off. A tick is a fairly arbitrary unit of time in xv6, determined by how often a hardware timer generates interrupts.

-You should put the following example program in user/alarmtest.c: +You should put the following test program in user/alarmtest.c: XXX Insert the final program here; maybe just give the code in the repo

@@ -211,15 +212,16 @@ alarmtest starting
 alarmtest.c by 10x.)
 
 

The main challenge will be to arrange that the handler is invoked - when the process's alarm interval expires. In your usertrap, when a - process's alarm interval expires, you'll want to cause it to execute - its handler. How can you do that? You will need to understand in - details how system calls work (i.e., the code in kernel/trampoline.S + when the process's alarm interval expires. You'll need to modify + usertrap() in kernel/trap.c so that when a + process's alarm interval expires, the process executes + the handler. How can you do that? You will need to understand in + detail how system calls work (i.e., the code in kernel/trampoline.S and kernel/trap.c). Which register contains the address where - systems calls return to? + system calls return to?

Your solution will be few lines of code, but it will be tricky to - write the right lines of code. Common failure scenarios are: the + write the right lines of code. The most common failure scenario is that the user program crashes or doesn't terminate. You can see the assembly code for the alarmtest program in alarmtest.asm, which will be handy for debugging. diff --git a/labs/xv6.html b/labs/xv6.html index 8dc7786..13d581e 100644 --- a/labs/xv6.html +++ b/labs/xv6.html @@ -82,16 +82,16 @@ initial file system. You just ran one of them: ls.

sleep

-

Implement the UNIX program sleep, which sleeps for a user-specified - number of ticks. +

Implement the UNIX program sleep for xv6; your sleep should pause + for a user-specified number of ticks.

Some hints: