CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

28
CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call

Transcript of CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

Page 1: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

CS 342302 OPERATING SYSTEMSNachos Project 1

Start-up and System call

Page 2: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

MOTIVATION

System calls are the interfaces that user programs can ask services from kernel.

How to add a new system call is very essential.

Page 3: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

OBJECTIVE

Be familiar with the Nachos environment. Design and implement new system calls in

this project.

Page 4: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

PLATFORM

Use Linux on our server. You could also build up your Linux

environment by yourself.

Page 5: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

LOGIN

Download pietty (http://ntu.csie.org/~piaip/pietty/)

Server IP : 140.114.71.238 PORT : 35568

需更改

Page 6: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

LOGIN

如出現以下畫面 選 “是 (Y)”

Page 7: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

LOGIN

Both the account name and the default password are “os”+your student number. (ex. os9862518)

After you login, you must change your password. (use passwd command)

$passwd

Page 8: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

BASIC COMMAND

NOTE : Some basic commands you have to know:for example :

$cd <directory> : enter directory $cd .. : go back to upper directory $cd ~ : enter home directory $ctrl + c : process termination

good place : 鳥哥的 Linux 私房菜 (http://linux.vbird.org/)

Page 9: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

COMPLETE YOUR NACHOS ENVIRONMENT Enter your home directory $ cd ~ We have already prepared for you

nachos-java.tar.gz , nachos-java.tar.gz Decompress it! $ tar zxvf nachos-java.tar.gz $ tar zxvf mips-x86.linux-xgcc.tgz Enter the nachos/test directory and execute

make. If there is no errors, your MIPS cross compiler environment is set correctly.

$ cd nachos/test $ make

Page 10: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

MAKE RESULT

Note: If there are errors when you make, contact TA please. Otherwise, you couldn’t complete this project

Page 11: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

EXECUTE NACHOS

Go back and enter the proj1 directory and execute make. It will create the directory named nachos. Finally, execute nachos to run Nachos, you will see some lines of messages when running.

$ cd .. $ cd proj1 $ make $ nachos

Page 12: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

RUNNING RESULT

If there is no error so far, your Nachos environment is set successfully.

Page 13: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

HOW TO MODIFY

Use vim on the server (suggested)Reference : http://www.study-area.org/tips/vim/

http://linux.vbird.org/linux_basic/0310vi.php

Or you can use the FTP software (ex. FileZilla) with SSH (port:22) to download and upload the file which have to be modify, then you can use your own editor in your operating system.

Page 14: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

BASIC REQUIREMENTIMPLEMENT & ADD THE FOLLOWING SYSTEM CALL:

int add(int op1, int op2); int pow(int op1, int op2); void print(char *msg);void print2(char *msg, int value); You only need to parse the parameter %d.

void exit(int status); In order to terminate user programs properly.

Page 15: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

RELATED CODE FOR USER PROCESSES

~/nachos/test/start.SStartup assembly code for every user program of Nachos.

~/nachos/test/syscall.hDefinitions of the system call prototypes

~/nachos/userprog/UserProcess.javaEncapsulates the state of a user process, including the handler for system calls and other exceptions.

Page 16: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

ADD YOUR SYSTEM CAL

Declare a new system call in test/syscall.h- Define a new system call ID

E.g., #define syscallAdd 13

- Declare the interface for Nachos system calls, which will

be called by the user program.

E.g., int add(int op1, int op2); Add the low level operation to support the

new declared system call in test/start.S E.g., SYSCALLSTUB(add, syscallAdd)

Page 17: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

handleSyscall in userprog/UserProcess.java

1. Define system call ID which you’ve defined in UserProcess.java

private static final int

syscallHalt = 0,

…..

2. Write your system call in the switch case

public int handleSyscall (int syscall, int a0, int a1, int a2, int a3)

{

switch (syscall) {

case syscallAdd:

return a0+a1;

…..

ADD YOUR SYSTEM CALL

Page 18: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

ADD YOUR PROGRAM

You have to run the following test program on your Nachos.

Page 19: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

ADD YOUR PROGRAM(CONT.)

If you call the test file “proj1.c”. First, put the file under /test, and modify the

file “Makefile”.TARGETS = halt sh matmult sort echo cat cp mv rm #chat chatserver

TARGETS = halt sh matmult sort echo cat cp mv rm proj1 #chat chatserver

then “make” again under the /test directory.

If appear “make: Nothing to be done for `all'.” $ make clean $ make

Page 20: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

RUN YOUR PROGRAM

In file ~/nachos/proj2 Then modify the line 12 of /proj2/nachos.conf

Kernel.shellProgram = halt.coff #sh.coffKernel.shellProgram = proj1.coff #sh.coff

“make” under /proj2. Enter “nachos” to run it.

Page 21: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

RESULT

Page 22: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

HINT

In system call “print” and “print2” may use the functions below:

readVirtualMemoryString();System.out.println();

try to know how to use it

Page 23: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

SUBMISSION & GRADING POLICY

Code correctness 65%Every system call is 13%

Readability 5% Report 30% Bonus 10%

Page 24: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

BONUS

Anything different from Basic Requirement Build your own nachos' environment

For example : Using Vmware, install Ubuntu, nachos, mips …etc.

Another system call For example : Create, open, write, read …etc.

Page 25: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

REPORT REQUIREMENT

Free but basically What problem have you met and how to solve it What have you learned from this project Your bonus part (if have, Explain it in detail) 報告越詳細分數越高

Page 26: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

DEADLINE

2009 / 10 / 21 ( 23:59 pm)

Page 27: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

OFFICE HOUR :

週一 (Mon) : 7:00pm~10:00pm 綜二 751

Page 28: CS 342302 OPERATING SYSTEMS Nachos Project 1 Start-up and System call.

REFERENCES

鳥哥的 Linux 私房菜 Linux 基本操作