1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 3: Adding System Calls to OS/161 Dr. Xiao Qin Auburn University.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Drivers and the kernel1-1 Drivers and the kernel UNIX system has three layers: m The hardware m The operating system kernel m The user-level programs Kernel.
CSCC69: Operating Systems
BASIS Quick Start Guide by Andreas Schuh.  Introduction  Installing BASIS  Creating a New Project  Installing Your Project  Adding Executables 
RIVERSIDE RESEARCH INSTITUTE Helikaon Linux Debugger: A Stealthy Custom Debugger For Linux Jason Raber, Team Lead - Reverse Engineer.
CS201 – Makefile Tutorial. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc.
CSCC69: Operating Systems Tutorial 2 Some of the slides were borrowed from csc369 course, U of T, St George.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Specification and Implementation Separating the specification from implementation makes it easier to modify programs. Changes in the class’s implementation.
Project #2, Linux Kernel Modifications CS-502 Fall Programming Project #2 Linux Kernel Hacking CS-502 Operating Systems Fall 2006.
Minix Overview & System Call Implementation Sankara Narayanan. CSE 785 Computer Security, Syracuse University, NY Spring 2003 – 2004.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
Project #1, Linux Kernel Modifications CS-502 Fall Programming Project #1 Linux Kernel Hacking CS-502, Operating Systems Fall 2007.
CSE 451: Operating Systems Section 2 Interrupts, Syscalls, Virtual Machines, and Project 1.
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
System Calls 1.
Nachos Project 1 Start-up and System call
Separate Compilation. A key concept in programming  Two kinds of languages, compilation (C, Pascal, …) and interpretation (Lisp, …, Matlab, Phython,
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.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Introduction to Systems Programming (CS 0449) PalmOS Tools: Developer Studio & Cygwin.
System Calls: A Kernel Project Hunter Bell CS Fall
Active-HDL Interfaces Debugging C Code Course 10.
Active-HDL Interfaces Building VHPI Applications C Compilation Course 9.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Project 2: Initial Implementation Notes Tao Yang.
Allegro CL Certification Program Lisp Programming Series Level I Session Basic Lisp Development in the IDE.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Debugging Ensemble Productions CAMTA Meeting 11 th November 2010 John Murray.
Nachos Overview Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/09/18 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
AT91Bootstrap. Introduction Device initialization such as clock speed configuration, PIO settings, etc. Peripheral drivers such as PIO, PMC, SDRAMC, etc.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Makefiles1 MAKEFILES Purpose: contain UNIX commands and will run them in a specified sequence. Syntax Definition : { Section-name: {unix command #1} …
Bootable Programs Building an O/S. Basic Requirements of any O/S Respond to interrupts (all kinds) Preserve user environment Protect users and self from.
Kernel Exercise 5 Brandon Cline Stuart Fischer Rachel Langhans Brian Minter Adam Stasio.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
System calls for Process management Process creation, termination, waiting.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
January 9, 2001 Router Plugins (Crossbow) 1 Washington WASHINGTON UNIVERSITY IN ST LOUIS Exercises.
Tutorial for Modelsim 1 Installation Download the Modelsim Student Edition: Follow the.
COMP 3500 Introduction to Operating Systems Memory Management: Part 1 Dr. Xiao Qin Auburn University Slides.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Overview Dr. Xiao Qin Auburn University
1 COMP 3500 Introduction to Operating Systems Project 3 – Synchronization Overview Dr. Xiao Qin Auburn University
Spring 2007 Vmware and Linux kernel COMS W4118 Columbia University.
1 COMP 3500 Introduction to Operating Systems Project 2 – An Introduction to OS/161 Overview Dr. Xiao Qin Auburn University
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 4: Managing File System State Dr. Xiao Qin Auburn University.
1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 2: Details Dr. Xiao Qin Auburn University
Note: Some of the slides are repeated from Introduction to C++
TK1924 Program Design & Problem Solving Session 2011/2012
BASIS Quick Start Guide
Discussion on mp1.
Week 3-4 Control flow (review) Function definition Program Structures
Auburn University COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 5: Managing.
COMP Introduction to Operating Systems Project 1 – Installing CentOS
Auburn University COMP 3000 Object-Oriented Programming for Engineers and Scientists Structures Cont. Dr. Xiao Qin Auburn.
Advanced TAU Commander
Operation System Program 4
Separate Compilation.
Operation System Program 1
How & When The Kernel Runs
Functions Imran Rashid CTO at ManiWeber Technologies.
Presentation transcript:

1 COMP 3500 Introduction to Operating Systems Project 4 – Processes and System Calls Part 3: Adding System Calls to OS/161 Dr. Xiao Qin Auburn University

Use System Call: sys_reboot() Q1: Is this program an application or a part of the kernel? In src/sbin/reboot/reboot.c How to run the reboot program? Type “p /sbin/reboot” 2

Use System Call: sys_reboot() Another Example: In src/sbin/poweroff/poweroff.c How to run the poweroff program? Type “p /sbin/poweroff” 3

System Call: sys_reboot() In src/kern/include/syscall.h 4

5 In src/kern/arch/mips/mips/sys call.c

Which function calls mips_syscall()? 6 mips_syscall() mips_trap()exception.S See cs161/kern/arch/mips/mips

7 A user program –Loads a system call code into register $v0 –Loads the arguments into registers $a0,..., $a3 System calls that return values –Put their result in register $v0 Which function calls exception.S?

Using cs161-gdb to trace sys_reboot()? b sys_reboot type “p /sbin/reboot” at the OS161 menu prompt bt (back trace) 8

User-Level Interface for System Calls src/include/unistd.h This file contains the user-level interface definition of the system calls for OS/161 Note that the user-level interface defined in unistd.h is different from that of the kernel functions that you will define to implement these calls. You need to declare the kernel functions in src/kern/include/syscall.h 9

Step 1: Configuration Configure the source code tree %cd ~/cs161/src %./configure Configure a kernel named ASST2 %cd ~/cs161/src/kern/conf %./config ASST2 10

Step 2: System Call Implementation 2.1 Create a System Call Implementation File ~/cs161/src/kern/userprog 11

Step 2.1: System Call Implementation Example: getpid_syscall.c #include /* Sample implementation of sys_getpid() */ int sys_getpid(pid_t *retval) { *retval = curthread->t_pid; return 0; } 12

Step 2.1: System Call Implementation Update data structure struct thread in kern/include/thread.h by adding the following data item: pid_t t_pid; 13

Step 2.2: Update Configuration File and Reconfigure the Project Now you can update the configuration file (i.e., conf.kern ) located in src/kern/conf The following line should be added: file userprog/getpid_syscall.c Reconfigure the project (see Step 1 for details) 14

Step 2.3: Update the header file of system call functions in the kernel The prototype of sys_getpid may be included in the following file: ~/cs161/src/kern/include/syscall.h Add the following function prototype in the above file: int sys_getpid(pid_t *retval); 15

Step 2.4: Update the system call handler syscall.c The system call handler syscall.c is located in the following directory: ~/cs161/src/kern/arch/mips/mips Add the following segment in the switch-case statement of the mips_syscall() function in syscall.c case SYS_getpid: err = sys_getpid(&retval); break; 16

Step 2.5: Rebuild the OS/161 Kernel Follow the commands below to rebuild the kernel. %cd ~/cs161/src/kern/compile/ASST2 %make depend %make %make install 17

Step 3: Test System Calls Step 3.1 Create a User Program for the New System Call Step 3.2 Run the User Program in OS/161 18

Step Create a new directory using forktest as a template We place all the test programs in the following directory: ~/cs161/src/testbin Each test program and its associated files (e.g., Makefile) are organized in a dedicated directory. Create a new directory using forktest as a template %cd ~/cs161/src/testbin %cp –r forktest getpidtest 19

Step Change source code name %cd getpidtest %mv forktest.c getpidtest.c 20

Step Modify getpidtest.c #include int main() { int mypid; mypid = getpid(); reboot(RB_REBOOT); return 0; } 21

Step Modify Makefile and depend.mk Modify Makefile and depend.mk by replacing forktest with getpidtest 22

Step Compile getpidtest.c Compile getpidtest.c using cs161-gcc. This can be done through running Makefile as below. %make The make utility program compile getpidtest.c and generate an execute file called getpidtest 23

Step Copy the executable file to the root directory Copy the executable file getpidtest into ~/cs161/root/testbin %cp getpidtest ~/cs161/root/testbin/getpidtest The above executable file will be loaded by OS/161 through the p command in the main menu. 24

Step 3.2 Run the User Program in OS/161 You can follow the instructions below to run the testing program created in Step 3.1: %cd ~/cs161/root %./sys161 kernel In the menu prompt type: p /testbin/getpidtest 25

Reference A PDF file: Project 4 Adding System Calls.pdf 26