syscall lab nits
This commit is contained in:
		
							parent
							
								
									0c3125b9eb
								
							
						
					
					
						commit
						0c10cbe829
					
				
					 3 changed files with 25 additions and 25 deletions
				
			
		|  | @ -138,9 +138,7 @@ syscall(void) | ||||||
| 
 | 
 | ||||||
|   num = p->tf->a7; |   num = p->tf->a7; | ||||||
|   if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { |   if(num > 0 && num < NELEM(syscalls) && syscalls[num]) { | ||||||
|     //printf("%d: syscall %d\n", p->pid, num);
 |  | ||||||
|     p->tf->a0 = syscalls[num](); |     p->tf->a0 = syscalls[num](); | ||||||
|     //printf("%d: syscall %d -> %d\n", p->pid, num, p->tf->a0);
 |  | ||||||
|   } else { |   } else { | ||||||
|     printf("%d %s: unknown sys call %d\n", |     printf("%d %s: unknown sys call %d\n", | ||||||
|             p->pid, p->name, num); |             p->pid, p->name, num); | ||||||
|  |  | ||||||
|  | @ -12,9 +12,9 @@ and switching between threads of execution.  In particular, you will | ||||||
| implement new system calls (<tt>sigalarm</tt> and <tt>sigreturn</tt>) | implement new system calls (<tt>sigalarm</tt> and <tt>sigreturn</tt>) | ||||||
| and switching between threads of a user-level thread package. | and switching between threads of a user-level thread package. | ||||||
| 
 | 
 | ||||||
| <h2>RISC-V assembly</h2> | <h2>Warmup: RISC-V assembly</h2> | ||||||
| 
 | 
 | ||||||
| <p>For this lab it will be important to understand RISC-V assembly. | <p>For this lab it will be important to understand a bit of RISC-V assembly. | ||||||
| 
 | 
 | ||||||
| <p>Add a file user/call.c with the following content, modify the | <p>Add a file user/call.c with the following content, modify the | ||||||
|   Makefile to add the program to the user programs, and compile (make |   Makefile to add the program to the user programs, and compile (make | ||||||
|  | @ -40,21 +40,22 @@ void main(void) { | ||||||
| } | } | ||||||
| </pre> | </pre> | ||||||
| 
 | 
 | ||||||
| <p>Read through call.asm and understand it.  The instruction manual | <p>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 |   for RISC-V is in the doc directory (doc/riscv-spec-v2.2.pdf).  Here | ||||||
|   are some questions that you should answer for yourself: |   are some questions that you should answer for yourself: | ||||||
| 
 | 
 | ||||||
|   <ul> |   <ul> | ||||||
|     <li>Which registers contain arguments to functions?  Which |     <li>Which registers contain arguments to functions?  Which | ||||||
|     register holds 13 in the call to <tt>printf</tt>?  Which register |     register holds 13 in the call to <tt>printf</tt>?  Which register | ||||||
|     holds the second one? Which register holds the second one?  Etc. |     holds the second argument? Which register holds the third one?  Etc. | ||||||
| 
 | 
 | ||||||
|     <li>Where is the function call to <tt>f</tt> and <tt>g</tt> |     <li>Where is the function call to <tt>f</tt> from main? Where | ||||||
|       in <tt>main</tt>?  (Hint: compiler may inline functions.) |         is the call to <tt>g</tt>? | ||||||
|  |         (Hint: the compiler may inline functions.) | ||||||
| 
 | 
 | ||||||
|     <li>At what address is the function <tt>printf</tt> located? |     <li>At what address is the function <tt>printf</tt> located? | ||||||
| 
 | 
 | ||||||
|     <li>What value is in the register <tt>ra</tt> in the <tt>jalr</tt> |     <li>What value is in the register <tt>ra</tt> just after the <tt>jalr</tt> | ||||||
|     to <tt>printf</tt> in <tt>main</tt>? |     to <tt>printf</tt> in <tt>main</tt>? | ||||||
|   </ul> |   </ul> | ||||||
| 
 | 
 | ||||||
|  | @ -87,9 +88,9 @@ print its output.) | ||||||
| 
 | 
 | ||||||
| <p> Hint: modify the syscall() function in kernel/syscall.c. | <p> Hint: modify the syscall() function in kernel/syscall.c. | ||||||
| 
 | 
 | ||||||
| <p>Run the programs you wrote in the lab and inspect the system call | <p>Run the xv6 programs you wrote in earlier labs and inspect the system call | ||||||
|   trace.  Are there many system calls?  Which systems calls correspond |   trace.  Are there many system calls?  Which system calls correspond | ||||||
|   to code in the applications you wrote above? |   to code in the applications you wrote? | ||||||
|      |      | ||||||
| <p>Optional: print the system call arguments. | <p>Optional: print the system call arguments. | ||||||
| 
 | 
 | ||||||
|  | @ -109,14 +110,14 @@ to handle page faults in the application, for example. | ||||||
| You should add a new <tt>sigalarm(interval, handler)</tt> system call. | You should add a new <tt>sigalarm(interval, handler)</tt> system call. | ||||||
| If an application calls <tt>sigalarm(n, fn)</tt>, then after every | If an application calls <tt>sigalarm(n, fn)</tt>, then after every | ||||||
| <tt>n</tt> "ticks" of CPU time that the program consumes, the kernel | <tt>n</tt> "ticks" of CPU time that the program consumes, the kernel | ||||||
| will cause application function | should cause application function | ||||||
| <tt>fn</tt> to be called. When <tt>fn</tt> returns, the application | <tt>fn</tt> to be called. When <tt>fn</tt> 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 | time in xv6, determined by how often a hardware timer generates | ||||||
| interrupts. | interrupts. | ||||||
| 
 | 
 | ||||||
| <p> | <p> | ||||||
| You should put the following example program in <tt>user/alarmtest.c</tt>: | You should put the following test program in <tt>user/alarmtest.c</tt>: | ||||||
| 
 | 
 | ||||||
| <b>XXX Insert the final program here; maybe just give the code in the repo</b> | <b>XXX Insert the final program here; maybe just give the code in the repo</b> | ||||||
| <pre> | <pre> | ||||||
|  | @ -211,15 +212,16 @@ alarmtest starting | ||||||
| <tt>alarmtest.c</tt> by 10x.) | <tt>alarmtest.c</tt> by 10x.) | ||||||
| 
 | 
 | ||||||
| <p>The main challenge will be to arrange that the handler is invoked | <p>The main challenge will be to arrange that the handler is invoked | ||||||
|   when the process's alarm interval expires.  In your usertrap, when a |   when the process's alarm interval expires.  You'll need to modify | ||||||
|   process's alarm interval expires, you'll want to cause it to execute |   usertrap() in kernel/trap.c so that when a | ||||||
|   its handler. How can you do that?  You will need to understand in |   process's alarm interval expires, the process executes | ||||||
|   details how system calls work (i.e., the code in kernel/trampoline.S |   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 |   and kernel/trap.c). Which register contains the address where | ||||||
|   systems calls return to? |   system calls return to? | ||||||
| 
 | 
 | ||||||
| <p>Your solution will be few lines of code, but it will be tricky to | <p>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 |   user program crashes or doesn't terminate.  You can see the assembly | ||||||
|   code for the alarmtest program in alarmtest.asm, which will be handy |   code for the alarmtest program in alarmtest.asm, which will be handy | ||||||
|   for debugging. |   for debugging. | ||||||
|  |  | ||||||
|  | @ -82,16 +82,16 @@ initial file system.  You just ran one of them: <tt>ls</tt>. | ||||||
| 
 | 
 | ||||||
| <h2>sleep</h2> | <h2>sleep</h2> | ||||||
| 
 | 
 | ||||||
| <p>Implement the UNIX program sleep, which sleeps for a user-specified | <p>Implement the UNIX program sleep for xv6; your sleep should pause | ||||||
|   number of ticks. |   for a user-specified number of ticks. | ||||||
| 
 | 
 | ||||||
| <p>Some hints: | <p>Some hints: | ||||||
|   <ul> |   <ul> | ||||||
|     <li>Look at some of the other programs in <tt>user/</tt> to see |     <li>Look at some of the other programs in <tt>user/</tt> to see | ||||||
|     how you can obtain the arguments passed to a program.  If the user |     how you can obtain the command-line arguments passed to a program.  If the user | ||||||
|     forgets to pass an argument, sleep should print an error message. |     forgets to pass an argument, sleep should print an error message. | ||||||
| 
 | 
 | ||||||
|     <li>The argument is passed as a string; you can convert it to an |     <li>The command-line argument is passed as a string; you can convert it to an | ||||||
|       integer using <tt>atoi</tt> (see user/ulib.c). |       integer using <tt>atoi</tt> (see user/ulib.c). | ||||||
| 
 | 
 | ||||||
|     <li>Use the system call <tt>sleep</tt> (see user/usys.S and kernel/sysproc.c). |     <li>Use the system call <tt>sleep</tt> (see user/usys.S and kernel/sysproc.c). | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Robert Morris
						Robert Morris