• 沒有找到結果。

Nachos Introduction & Project 1

N/A
N/A
Protected

Academic year: 2022

Share "Nachos Introduction & Project 1"

Copied!
29
0
0

加載中.... (立即查看全文)

全文

(1)

Nachos Introduction & Project 1

Speaker: Chien-Chung Ho 2010/10/07

(2)

Outline

Overview

Installing Nachos

Project 1

Submission

(3)

Outline

Overview

Installing Nachos

Project 1

Submission

(4)

Nachos Basics

Not Another Completely Heuristic Operating System

http://www.cs.washington.edu/homes/tom/nachos/

Purposes

Teach monolithic kernel design and implementation

Do experiments

Facts

Real hardware is difficult to handle

May break if handled wrong

Approaches

Use a virtual MIPS machine

Provide basic OS elements

(5)

The Architecture of Nachos

Nachos

User Thread 1 User Thread 2 User Thread 3

Nachos Kernel

(Threads, File System, …)

Simulated MIPS Machine (CPU, Memory, Devices, …)

(6)

Nachos 4.0

Nachos simulates MIPS architecture on the host system (Unix / Linux / Windows / MacOS X)

User programs need a cross-complier (target MIPS)

Nachos appears as a single threaded process to the host operating system

(7)

Nachos 4.0 (Cont’d)

A skeletal OS

Threads

User‐level processes

Virtual memory

Interrupt‐driven I/O devices

2 execution modes

Nachos kernel

Executes when

Nachos starts up

A user‐program causes a hardware trap (page fault, system call, etc.)

MIPS simulator is initialized and started by Nachos kernel

(8)

Source Tree

Root directory

C++ introduction to teach how to write C++

Root directory of Nachos’s source code

File system Nachos’s library MIPS machine

In/Out message queues

Nachos’s sample user programs Threads

User programs’ interfaces

The tool to convert user programs from MIPS’s COFF into Nachos’s NOFF format (NOFF: Nachos Object File Format)

Building directories for different systems (platform-dependent)

Source code of Nachos kernel and MIPS simulator

(9)

System Start-Up Flowchart

./nachos  start

code/threads/main.cc  main

Create kernel object Initialize the system Invoke user programs

System halts and terminates

Load user programs Run user programs

Create “main” thread

Create & initialize MIPS machine Initialize the ready queue, scheduler, console and timer

Start up interrupt handing Run some system testing

(10)

System Start-Up

main(int argc, char **argv) //* code/threads/main.cc

Parse parameters

E.g., >nachos –x a.out, where –x a.out is a parameter.

Create and initialize nachos kernel

Create kernel object

kernel = new Kernel(argc, argv);

Initialize the system

kernel‐>Initialize(); //* code/threads/kernel.cc Kernel::Initialize()

Run some tests if requested

E.g., kernel‐>ThreadSelfTest(); to test threads

Run a user program if any. Otherwise terminate Nachos

(11)

How to Run a User Program

If we specify “‐x” as Nachos’s parameter, it means that we want to run a user program:

Create an address space to run a user program

AddrSpace *space = new AddrSpace; // in code/userprog/addrspace.cc

Create address translation table (page table) and set up the translation from program memory to physical memory.

By default, the mapping is 1 to 1 since we are only uniprogramming->have a single unsegmented page table.

Load the whole user program into MIPS machine’s main memory

space‐>Load(userProgName); // AddrSpace::Load()

Execute the user program

space‐>Execute(); // AddrSpace::Execute()

Jump to run the user program

kernel‐>machine‐>Run();

(12)

System Call Procedure

(13)

Related Code for User Processes

code/test/start.S

Start-up assembly code for every user program of Nachos

code/userprog/syscall.h

Definitions of system call prototypes

code/userprog/exception.cc

The handler for system calls and other exceptions are here

(14)

Starting of a User Program

code/test/start.S

Define what is needed for a user program

Starting point

User program’s system call functions

Startup assembly code of every user program of Nachos

Initialize and run a C user program by jumping to its main()

(15)

The Process of a System Call in a User Program

The user program (defined in code/test/start.S)

Stores the system codes in Register 2

Stores the arguments in Register 4 ,5, 6, and 7

ExceptionHandler in code/userprog/exception.cc

Fetches system call number in Register 2.

Is the entry point into the Nachos kernel from user programs

Syscall

exceptions

Adds new exception handler’s switch case in switch … case section

The system call codes are executed

PC increases (PCReg)

(16)

Outline

Overview

Installing Nachos

Project 1

Submission

(17)

Nachos Development Environment

Tools: gcc/g++, patch, wget,…

Nachos source code

MIPS cross compiler

Translator coff2noff

Setting path of the toolchain and Makefiles

(18)

Installation Guide

Installing Nachos on Linux in workstation R217

http://newslab.csie.ntu.edu.tw/course/OS2010/files/nachos/217(64-bit).htm

Installation on X86 32‐bit machine

http://newslab.csie.ntu.edu.tw/course/OS2006/files/nachos/217.htm

Make sure your project can be executed on workstations in R217 (64-bit)

(19)

Outline

Overview

Installing Nachos

Project 1

Submission

(20)

Declare a System Call

Declare a new system call in code/userprog/syscall.h

Define a new system call ID

E.g., #define SC_Add 42

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 code/test/start.S

(21)

From an Exception Handler to a Specific System call

In ExceptionHandler in code/userprog/execption.cc

(22)

An Example of System Call

In code/userprog/ksyscall.h int SysAdd(int op1, int op2) {

return op1 + op2;

}

(23)

Test Program

Put your test.c in code/test/

int main() {

int j, k = 0;

j=OSAdd(20, 10);

/*System call print: The return value of OSAdd(10,20) is 30*/

k=OSSub(j,15);

/*System call print: The return value of OSSub(30,15) is 15 */

OSAdd(j,k);

/*System call print: The return value of OSAdd(30,15) is 45*/

Halt();

/* not reached */

}

(24)

Makefile

For example: We want to compile a user program called test.c

You can edit code/test/Makefile to add a new compiling rule for it (Output file is test in the following example)

Type “make” to compile it

(25)

Results

(26)

Outline

Overview

Installing Nachos

Project 1

Submission

(27)

Submission

2 members in a team

Email your team member list to ntuos2010@gmail.com

Subject: [OS分組] 王小明 R12345678、張小美 R98765432

Deadline: 2010/10/20 21:00

For the delayed submission, deduct two points for each day

Check your team number ## in website after 10/11 17:00

Upload your team project to the FTP

ftp server: 140.112.28.113 /os2010 /2010os

Pack the “NachOS‐4.0/code” and your report in a file named by

“OSPJ1_Group##.tar.gz”

The report is limited within 2 A4 pages

Grading: code 70% and report 30%. Please highlight your bonus

(28)

Note

Do not copy homework

Keep your code secret

On any quetsions

Write email to ask TAs

黃柏鈞: b91048@csie.ntu.edu.tw

何建忠: r99922110@csie.ntu.edu.tw 陳煒栩: wish520angela@hotmail.com 鄭聖威: r99922123@csie.ntu.edu.tw

Come to R438 during TA hours

(29)

Thank You!

參考文獻

相關文件

• Last data pointer stores the memory address of the operand for the last non-control instruction. Last instruction pointer stored the address of the last

z Given user preferences and constraints on resource or utility, develop strategies to find the optimal adaptation operator(s) satisfying the constraints..

– Each time a file is opened, the content of the directory entry of the file is moved into the table.. • File Handle (file descriptor, file control block): an index into the table

The Matlab fprintf function uses single quotes to define the format string. The fprintf function

The FX 3S /FX 3G /FX 3GC /FX 3U /FX 3UC PLC outputs transistor signals from the main unit and also outputs pulses from the high-speed output special adapter and the

To proceed, we construct a t-motive M S for this purpose, so that it has the GP property and its “periods”Ψ S (θ) from rigid analytic trivialization generate also the field K S ,

A=fscanf(fid , format, size) reads data from the file specified by file identifier fid , converts it according to the specified format string, and returns it in matrix A..

JRE (Java Runtime Environment): for users, JVM + basic libraries JDK (Java Development Kit): JRE + compilers + ... —jdk-6u12-windows-i586-p.exe or other platform