SlideShare a Scribd company logo
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 
http://www.eng.auburn.edu/~xqin 
xqin@auburn.edu
Use System Call: sys_reboot() 
In src/sbin/reboot/reboot.c 
How to run the reboot program? 
Type “p /sbin/reboot”
Use System Call: sys_reboot() 
Another Example: In src/sbin/poweroff/poweroff.c 
How to run the poweroff program? 
Type “p /sbin/poweroff”
System Call: sys_reboot() 
In src/kern/include/syscall.h
5
Which function calls 
mips_syscall()? 
6 
exception.S 
mips_trap() 
mips_syscall() 
See cs161/kern/arch/mips/mips
Which function calls exception.S? 
• A user program 
7 
– 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
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 
kern/include/syscall.h
Step 1: Configuration 
• Configure the source code tree 
%cd ~/cs161/src 
%./configure 
• Configure a kernel named ASST2 
%cd ~/cs161/src/kern/conf 
%./config ASST2
Step 2: System Call Implementation 
• 2.1 Create a System Call Implementation File 
~/cs161/src/kern/userprog
Step 2.1: System Call Implementation 
• Example: getpid_syscall.c 
#include <types.h> 
#include <syscall.h> 
#include <thread.h> 
#include <curthread.h> 
/* Sample implementation of sys_getpid() */ 
int 
sys_getpid(pid_t *retval) 
{ 
*retval = curthread->t_pid; 
return 0; 
}
Step 2.1: System Call Implementation 
• Update struct thread in 
kern/include/thread.h by adding the 
following data item: 
pid_t t_pid;
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)
Step 2.3: Update Configuration File 
and Reconfigure the Project 
• 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);
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;
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
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
Step 3.1-1 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
Step 3.1-2 
Change source code name 
%cd getpidtest 
%mv forktest.c getpidtest.c
Step 3.1-3 
Modify getpidtest.c 
#include <unistd.h> 
#include <stdio.h> 
int main() { 
int mypid; 
mypid = getpid(); 
reboot(RB_REBOOT); 
return 0; 
}
Step 3.1-4 
Modify Makefile and depend.mk 
• Modify Makefile and depend.mk by replacing 
forktest with getpidtest
Step 3.1-5 
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
Step 3.1-6 
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.
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

More Related Content

PPTX
Project 2 how to modify OS/161
PDF
Project 2 How to modify os161: A Manual
DOCX
Oops practical file
PDF
Project 2 how to install and compile os161
DOCX
C++ file
PPTX
Project 2 - how to compile os161?
PPT
Functions in C++
PPTX
Functions in c
Project 2 how to modify OS/161
Project 2 How to modify os161: A Manual
Oops practical file
Project 2 how to install and compile os161
C++ file
Project 2 - how to compile os161?
Functions in C++
Functions in c

What's hot (20)

PPT
Removal Of Recursion
DOC
Practical Class 12th (c++programs+sql queries and output)
PPTX
PDF
VTU Data Structures Lab Manual
PPTX
Function C programming
PPTX
Basic c programming and explanation PPT1
PDF
Porting Motif Applications to Qt - Webinar
 
PPTX
Tail Recursion in data structure
PPTX
History of C Programming Language
PPT
Unit 4 Foc
PPTX
PDF
C++11 & C++14
PDF
C programming notes
PDF
C programming language
PDF
VTU DSA Lab Manual
PPT
C++ Function
PPT
Input and output in C++
PPTX
Function template
PPTX
C++ 11 Features
Removal Of Recursion
Practical Class 12th (c++programs+sql queries and output)
VTU Data Structures Lab Manual
Function C programming
Basic c programming and explanation PPT1
Porting Motif Applications to Qt - Webinar
 
Tail Recursion in data structure
History of C Programming Language
Unit 4 Foc
C++11 & C++14
C programming notes
C programming language
VTU DSA Lab Manual
C++ Function
Input and output in C++
Function template
C++ 11 Features
Ad

Similar to How to add system calls to OS/161 (20)

PPTX
Systemcall1
PPT
1. Von Neumann + Booting Sequence + System Calls.ppt
PDF
Os lab final
PDF
L03SystemCalls.pdf all about system call in os
PDF
System Calls - Introduction
PPTX
Comsats University Islamabad OS lab 03.pptx
PDF
Part 04 Creating a System Call in Linux
PPTX
System calls in operating sytems incluses operating sytem process
PDF
I was just curious what the code needed will be- and how I should go a.pdf
DOCX
Program Assignment Process ManagementObjective This program a.docx
PPTX
Linux kernel debugging
PPT
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
PPTX
System call
DOC
Linux project no 1
PPTX
Unit1 CSE316_System_Calls 2BBBBB4252.pptx
PDF
Linux Internals - Part II
PDF
N_Asm Assembly system calls (sol)
PPTX
Operating systems Lab program: to develop C program to implement process mana...
PPTX
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
PDF
Operating System Lecture Notes Mit 6828 Itebooks
Systemcall1
1. Von Neumann + Booting Sequence + System Calls.ppt
Os lab final
L03SystemCalls.pdf all about system call in os
System Calls - Introduction
Comsats University Islamabad OS lab 03.pptx
Part 04 Creating a System Call in Linux
System calls in operating sytems incluses operating sytem process
I was just curious what the code needed will be- and how I should go a.pdf
Program Assignment Process ManagementObjective This program a.docx
Linux kernel debugging
OPERATING SYSTEM SERVICES, OPERATING SYSTEM STRUCTURES
System call
Linux project no 1
Unit1 CSE316_System_Calls 2BBBBB4252.pptx
Linux Internals - Part II
N_Asm Assembly system calls (sol)
Operating systems Lab program: to develop C program to implement process mana...
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
Operating System Lecture Notes Mit 6828 Itebooks
Ad

More from Xiao Qin (20)

PPTX
How to apply for internship positions?
PPTX
How to write research papers? Version 5.0
PDF
Making a competitive nsf career proposal: Part 2 Worksheet
PDF
Making a competitive nsf career proposal: Part 1 Tips
PPTX
Auburn csse faculty orientation
PPTX
Auburn CSSE graduate student orientation
PPTX
CSSE Graduate Programs Committee: Progress Report
PPTX
Understanding what our customer wants-slideshare
PPTX
OS/161 Overview
PPTX
Surviving a group project
PDF
P#1 stream of praise
PPTX
Data center specific thermal and energy saving techniques
PPTX
How to do research?
PPT
COMP2710 Software Construction: header files
PPT
COMP2710: Software Construction - Linked list exercises
PPTX
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
PPTX
Thermal modeling and management of cluster storage systems xunfei jiang 2014
PPTX
Reliability Analysis for an Energy-Aware RAID System
PPTX
Why Major in Computer Science and Software Engineering at Auburn University?
PPTX
IPCCC 2012 Conference Program Overview
How to apply for internship positions?
How to write research papers? Version 5.0
Making a competitive nsf career proposal: Part 2 Worksheet
Making a competitive nsf career proposal: Part 1 Tips
Auburn csse faculty orientation
Auburn CSSE graduate student orientation
CSSE Graduate Programs Committee: Progress Report
Understanding what our customer wants-slideshare
OS/161 Overview
Surviving a group project
P#1 stream of praise
Data center specific thermal and energy saving techniques
How to do research?
COMP2710 Software Construction: header files
COMP2710: Software Construction - Linked list exercises
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...
Thermal modeling and management of cluster storage systems xunfei jiang 2014
Reliability Analysis for an Energy-Aware RAID System
Why Major in Computer Science and Software Engineering at Auburn University?
IPCCC 2012 Conference Program Overview

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Week 4 Term 3 Study Techniques revisited.pptx
O7-L3 Supply Chain Operations - ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
PPH.pptx obstetrics and gynecology in nursing
01-Introduction-to-Information-Management.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
RMMM.pdf make it easy to upload and study
Supply Chain Operations Speaking Notes -ICLT Program

How to add system calls to OS/161

  • 1. 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 http://www.eng.auburn.edu/~xqin xqin@auburn.edu
  • 2. Use System Call: sys_reboot() In src/sbin/reboot/reboot.c How to run the reboot program? Type “p /sbin/reboot”
  • 3. Use System Call: sys_reboot() Another Example: In src/sbin/poweroff/poweroff.c How to run the poweroff program? Type “p /sbin/poweroff”
  • 4. System Call: sys_reboot() In src/kern/include/syscall.h
  • 5. 5
  • 6. Which function calls mips_syscall()? 6 exception.S mips_trap() mips_syscall() See cs161/kern/arch/mips/mips
  • 7. Which function calls exception.S? • A user program 7 – 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
  • 8. Using cs161-gdb to trace sys_reboot()? b sys_reboot type “p /sbin/reboot” at the OS161 menu prompt bt (back trace) 8
  • 9. 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 kern/include/syscall.h
  • 10. Step 1: Configuration • Configure the source code tree %cd ~/cs161/src %./configure • Configure a kernel named ASST2 %cd ~/cs161/src/kern/conf %./config ASST2
  • 11. Step 2: System Call Implementation • 2.1 Create a System Call Implementation File ~/cs161/src/kern/userprog
  • 12. Step 2.1: System Call Implementation • Example: getpid_syscall.c #include <types.h> #include <syscall.h> #include <thread.h> #include <curthread.h> /* Sample implementation of sys_getpid() */ int sys_getpid(pid_t *retval) { *retval = curthread->t_pid; return 0; }
  • 13. Step 2.1: System Call Implementation • Update struct thread in kern/include/thread.h by adding the following data item: pid_t t_pid;
  • 14. 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)
  • 15. Step 2.3: Update Configuration File and Reconfigure the Project • 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);
  • 16. 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;
  • 17. 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
  • 18. 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
  • 19. Step 3.1-1 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
  • 20. Step 3.1-2 Change source code name %cd getpidtest %mv forktest.c getpidtest.c
  • 21. Step 3.1-3 Modify getpidtest.c #include <unistd.h> #include <stdio.h> int main() { int mypid; mypid = getpid(); reboot(RB_REBOOT); return 0; }
  • 22. Step 3.1-4 Modify Makefile and depend.mk • Modify Makefile and depend.mk by replacing forktest with getpidtest
  • 23. Step 3.1-5 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
  • 24. Step 3.1-6 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.
  • 25. 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

Editor's Notes

  • #7: mips_trap() and mips_syscall() can be found in cs161/kern/arch/mips/mips