1 User-Level Processes Needed to test the system call you implement The “Noff” format file required –Look at the Makefile in test MIPS “syscall” instruction.

Slides:



Advertisements
Similar presentations
Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Advertisements

Christo Wilson Project 2: User Programs in Pintos
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
Chapter 7 Process Environment Chien-Chung Shen CIS, UD
Chapter 3 Memory Management. 3.1 From Programs To Address Space 3 steps to run the programs of an application – A Compiler translates the source code.
The Environment of a UNIX Process. Introduction How is main() called? How are arguments passed? Memory layout? Memory allocation? Environment variables.
Introducing User Programs into Nachos SPARC HW OS Kernel (Solaris) MIPS sim Nachos User Programs Syscalls Machine instructions MIPS instr Nachos calls.
Discussion Week 5 TA: Kyle Dewey. Overview HW 3.10 and 6.2 review Binary formats System call execution in NACHOS Memory management in NACHOS I/O in NACHOS.
CSCC69: Operating Systems Tutorial 2 Some of the slides were borrowed from csc369 course, U of T, St George.
Memory Management (II)
TTIT61 Nachos - short introduction Gert Jervan IDA/SaS/ESLAB.
Unix Process Environment. main Function A C program starts execution with a function called main. The prototype for the main function is: int main (int.
CSE 451 Section 4 Project 2 Design Considerations.
Advanced Programming in the UNIX Environment Hop Lee.
7/3/20151 Announcement (No deadline extension for the rest of quarter) Project 2 final deadline is Tuesday midnight May 19 Project 0 resubmission for autograding.
MIPS Instruction Set Advantages
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
System Calls 1.
Nachos Instructional OS: Part 2
Welcome to the World of Nachos CPS 110 Spring 2004 Discussion Session 1.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Nachos Instructional OS: Part 2
Nachos Assignment#1 System calls implementation. What are system calls? Enable you to interact with OS kernel. A switch from User Mode to Kernel Mode.
1-1 NET+OS Software Group Flash API Multiple flash memory bank support New Flash API introduction Detailed Flash API Function presentation Supporting.
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
1 CSE 451 Section 2: Interrupts, Syscalls, Virtual Machines, and Project 1.
Project 2: Initial Implementation Notes Tao Yang.
Nachos Project Assignment 2 CPU scheduling
CPSC 230 Computers and Programming I Spring 2003 Dr. Lynn Lambert.
Nachos Overview 2011 级 OS 课程设计 2013 秋. to get your hands dirty Read and analyze Build observe.
Nachos Project 4 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/25.
CSCI 211 Intro Computer Organization –Consists of gates for logic And Or Not –Processor –Memory –I/O interface.
Nachos Tutorial Courtesy: University of Waterloo.
Nachos Instructional OS CS 270, Tao Yang, Spring 2011.
Kirk Scott Computer Science The University of Alaska Anchorage 1.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
MIPS I/O and Interrupt.
Nachos Overview Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/09/18 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
Processes and Virtual Memory
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
Computer Organization Rabie A. Ramadan Lecture 3.
Genesis: From Raw Hardware to Processes Andy Wang Operating Systems COP 4610 / CGS 5765.
Nachos Instructional OS: Part 2
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
CSE120 Discussion 5 Xinxin Jin. Where Are We?  Now we have finished some thread mechanisms to support Nachos kernel  Next, we want to enable user-level.
Nachos Project Assignment 3 Memory Management
User-Written Functions
MIPS Instruction Set Advantages
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
Introduction to Operating Systems
Discussions on HW2 Objectives
Discussions on HW2 Objectives
How & When The Kernel Runs
Nachos Project Assignment 2 CPU scheduling
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Chapter 4 The Von Neumann Model
Presentation transcript:

1 User-Level Processes Needed to test the system call you implement The “Noff” format file required –Look at the Makefile in test MIPS “syscall” instruction invokes the routine RaiseException

2 How does it work?

3 How does it work? (cont.)

4 Related Nachos Codes test/start.s – Startup assembly code for every user program of Nachos. syscall.h –Definitions of the system call prototypes exception.cc –The handler for system calls and other exceptions is here.

5 Directories of Nachos Main directories –filesys –machine –network –threads –userprog Test programs –test

6 Related Files Major –test/start.s The code that starts the program execution –userprog/syscall.h Defines the system call constants –userprog/execption.cc The system call handler Minor –machine/machine.h Register definitions –test/halt.c Test user program –filesys/filesys.h File system definitions –filesys/filesys.cc Stub implementation –filesys/openfile.h –filesys/openfile.cc

7 Some Public Variables for the Kernel register: an array of 40 registers –Declared in machine/machine.h mainMemory: memory is byte- addressable and organized into 128-byte pages –Declared in machine/machine.h

8 Starting of a User Program test/start.s –Define what is needed for a user program. starting point system call startup assembly code of every user program of Nachos –Initialize and run a C program by jumping to location 0.

9 Exception Types Execution errors System calls …

10 The Progress of a System Call in a User Program The user program is responsible for –storing of the system codes in Register 2 –storing of the arguments in Register 4,5, 6, and 7. ExceptionHandler fetches the number for the system call in Register 2. Execute the corresponding codes for the system call. Increase the PC. –See the register definitions in machine.h

11 Declaring of System Call userprog/syscall.h –system call codes Ex: #define SC_Exit1 –Interface for Nachos system calls Ex: void Exit(int status);

12 The Entry Point into the Nachos Kernel ExceptionHandler –userprog/execption.cc Entry point into the Nachos kernel from user programs. –syscall –exceptions

13 The Entry Point into the Nachos Kernel (cont.) The code for the system call is placed in Register 2. arg –arg1 is in Register 4. –arg2 is in Register 5. –arg3 is in Register 6. –arg4 is in Register 7. The return value is in Register 2. Note –If you are handling a system call, don't forget to increment the pc before return to the user program.

14 Getting or Setting of the Data in a Register The function body is in machine/machine.cc. Kernel  machine  ReadRegister(x) –x is the register number. –The return type is the integer type. Kernel  machine  WriteRegister(x,y) –x is the register number. –y is the value.

15 Example: system call add(arg1,arg2) Retrieve the two arguments by –op1=(int)kernel  machine  ReadRegister(4) –op2=(int)kernel  machine  ReadRegister(5) Set the return value by –Kernel  machine  WriteRegister(2, (int)result)

16 Example: system call add(arg1,arg2) (cont.) Modify the return point by –Setting the previous PC (for debugging) kernel  machine  WriteRegister( PrevPCReg, kernel  machine  ReadRegister(PCReg)); –Setting the PC to the next instruction (all instructions are 4 byte wide) kernel  machine  WriteRegister( PCReg, kernel  machine  ReadRegister(PCReg) + 4); –Setting the next PC for a branch execution kernel->machine->WriteRegister( NextPCReg, kernel->machine->ReadRegister(PCReg)+4);

17 How If an Argument is an Char Array? Retrieve the logical address with –kernel->machine->ReadRegister(?) Retrieve the data with –kernel->machine->ReadMem(int x, int y, int *z) It is declared in ~/code/machine/machine.h and implemented in ~/code/machine/translate.cc. x is the virtual address to read from. y is the number of bytes to read (1, 2, or 4). z is the place to write the result.

18 kernel->machine->ReadMem Translate a virtual address into a physical address by –Translate(int virtAddr, int* physAddr, int size, bool writing) virtAddr: the virtual address to translate physAddr: the place to store the physical address size: the amount of memory being read or written writing: if TRUE, check the "read-only" bit in the TLB

19 Run Your Program Normal mode: –”./nachos –x../test/XXX” Debugger mode: –”./nachos –d../test/XXX”

20 Example Exit() void ExceptionHandler(ExceptionType which) { int type = machine->ReadRegister(2); if ((which == SyscallException) && (type == SC_Halt)) { DEBUG('a', "Shutdown, initiated by user program.\n"); interrupt->Halt(); }if ((which == SyscallException) && (type == SC_Exit)) { /* newly added system call EXIT */ //get the first argument int a4 = machine->ReadRegister(4); printf("\n\n\tNEW SYSCALL: you are in EXIT.\n\n\tThe return value you passed is --> %d\n\n\t The current thread will terminate...\n\n\n", a4); currentThread->Finish(); } else { printf("Unexpected user mode exception %d %d\n", which, type); ASSERT(FALSE); } }