Nachos Project 1 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Nachos Project 1

Description:

System call implementation (10/6 due) Be familiar with Nachos ... set next program counter for brach execution */ kernel- machine- WriteRegister(NextPCReg, ... – PowerPoint PPT presentation

Number of Views:211
Avg rating:3.0/5.0
Slides: 20
Provided by: mllCsie
Category:
Tags: brach | nachos | project

less

Transcript and Presenter's Notes

Title: Nachos Project 1


1
Nachos Project 1
  • Lecturer Hao-Hua Chu
  • TA Chun-Po Wang (Artoo)
  • Date 2008/09/19

2
Projects of this course
  • System call implementation (10/6 due)
  • Be familiar with Nachos
  • Implement various system calls for user programs
  • CPU Scheduling (10/20 due)
  • Implement priority scheduling to replace the FCFS
    scheduling
  • Multiprogramming (11/24 due)
  • To make multiple programs coexist in memory and
    implement paging mechanism
  • File Systems? (12/15 due)
  • Disks? (1/5 due)

3
Project 1
  • Implement System Calls
  • Print(char msg)
  • PrintNum(int n)

4
Summary
  • Motivation Objective
  • Introduction of Nachos
  • User-level processes
  • System calls
  • Related source files
  • Requirement
  • Submission

5
Motivation Objective
  • System calls are the interfaces that user
    programs can ask services from kernel
  • Eg. We cannot access hardwares like the monitor
    directly, so we need some means to print text on
    the screen
  • File I/O, Process Control, etc.

6
Motivation Objective (cont.)
  • Be familiar with Nachos
  • How to build
  • How to run
  • How to modify
  • For the first two questions, please read the
    slide Nachos Overview

7
Introduction of Nachos
  • User-level processes
  • How a user program is loaded and run?
  • System calls
  • How a system call is called?
  • How to implement one?
  • Related source files
  • Which files do we need to trace and modify?

8
Nachos startup
9
Nachos system calls
10
Exception
  • Transfer control from user mode to the Nachos
    kernel
  • System call
  • Divide by zero
  • Access invalid memory address
  • etc.

11
Implementation
  • We use the system call Add() as an example
  • code/test/add
  • Add(42,23) returns 65
  • Define the system call code in code/userprog/sysca
    ll.h
  • define SC_Add 43
  • Declare the interface for user programs in
    code/userprog/syscall.h
  • int Add(int op1, int op2)

12
Implementation (cont.)
  • Implement the system call function body for user
    program
  • This function must put the corresponding system
    call code to the register, then run MIPS
    instruction syscall
  • When the MIPS machine in Nachos see this command,
    it will run the corresponding system call
  • So, the function body is implemented in MIPS
    assembly code/test/start.S

code/test/start.S .globl Add .ent Add Add
addiu 2,0,SC_Add syscall j 31
.end Add
13
Implementation (cont.)
  • Implement the real stuff in ExceptionHandler() in
    code/userprog/execption.cc
  • syscall would raise an exception, and kernel
    use ExceptionHandler() to handle it
  • The arguments of the system call is in register
    47 of the MIPS machine, and we should put the
    return value to register 2
  • We need to increment register PC before we return
  • This is the only file you need to send in this
    project
  • Because the implementation in other files would
    be the same

14
Implementation (cont.)
case SC_Add DEBUG(dbgSys, "Add " ltlt
kernel-gtmachine-gtReadRegister(4) ltlt " "
ltlt kernel-gtmachine-gtReadRegister(5) ltlt "\n")
int result // SysAdd(a,b) returns ab
result SysAdd((int)kernel-gtmachine-gtReadRegister
(4), (int)kernel-gtmachine-gtReadReg
ister(5)) DEBUG(dbgSys, "Add returning with
" ltlt result ltlt "\n") kernel-gtmachine-gtWriteRe
gister(2, (int)result) / Modify return
point / / set previous program
counter (debugging only)/
kernel-gtmachine-gtWriteRegister(PrevPCReg,
kernel-gtmachine-gtReadRegister(PCReg))
/ set program counter to next instruction
(all Instructions are 4 byte wide)/
kernel-gtmachine-gtWriteRegister(PCReg,
kernel-gtmachine-gtReadRegister(PCReg) 4)
/ set next program counter for brach execution
/ kernel-gtmachine-gtWriteRegister(NextPCReg,
kernel-gtmachine-gtReadRegister(PCReg)4
) return
15
Requirement
  • Implement following system calls
  • Print(char msg) // Print a string on the screen
  • PrintNum(int n) // Print a number on the screen
  • Write a 2-page report
  • Dont just paste your code, Ill read it myself
  • State the problem you have encountered and how
    you solve it
  • Or anything else
  • If your project submission cant compile and
    execute on Linux in Workstation Room 217, we will
    consider it as fail.
  • Please contact me to apply a workstation account
    if you need it.

16
The tools you need
  • Read a string from the memory of MIPS machine
  • Registers only store numbers, so a string is sent
    by its address
  • Use kernel-gtmachine-gtReadMem() to read data
    from an address
  • You can assume that the string would be
    terminated by \0
  • Print characters to screen
  • Use kernel-gtsynchConsoleOut-gtPutChar()
  • DO NOT USE cout, printf, or something like that!
    Let Nachos do its work!
  • Convert a number to a string
  • You can use sprintf() in stdio.h

17
Test files
  • We supply a test file print.c on our webpage
  • To build it, you need to modify
    code/test/Makefile, or download it from our
    webpage
  • Type make under code/test/ to compile it
  • Type ../build.linux/nachos x print to run
  • The output would be simple enough for you to
    verify it D

18
Submission
  • Two people in one group (Write down the name and
    student ID of all members in the report)
  • The file you need to send
  • A report in .pdf or .doc
  • exception.cc
  • Send your files
  • Tar your files to an archieve namedos_hw1_bXXXXX
    XXX_bOOOOOOOO.tar.gz
  • E-mail to artoo_at_csie.ntu.edu.tw with following
    titleos_hw1 bXXXXXXXX_bOOOOOOOO

tar zcvf os_hw1_bXXXXXXXX_bOOOOOOOO.tar.gz
report.doc exception.cc
19
Submission (cont.)
  • Deadline 10/6 2400
  • Delayed submission would have penalty!
  • DO NOT COPY!!Protect your code well!!
Write a Comment
User Comments (0)
About PowerShow.com