DOC PREVIEW
Princeton COS 217 - Operating Systems

This preview shows page 1-2-3-4-5 out of 15 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 15 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Copyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Operating Systems Page 187 November 18, 1997 Operating Systems • Operating systems manage processes and resources • Processes are executing instances of programs • State vector: registers, program counter, memory mgmt registers, etc.codedataSVprocess 3codedataSVprocess 1codedataSVprocess 2state vector: information necessary to start, stop, and restart the processmay be the same or different programsuser-level processesoperating system, “kernel”bare machineassembly & high-level languagesmachine language & system callsmachine languageCopyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Privileged Instructions Page 188 November 18, 1997 Privileged Instructions • Machines have two kinds of instructions 1. “normal” instructions, e.g., add , sub , etc.2. “privileged” instructions, e.g.,initiate I/Oswitch state vectors or contexts load/save from protected memoryetc. • Operating systems hide privileged instructions and provide virtual instructions to access and manipulate virtual resources , e.g., I/O to and from disc files • Virtual instructions are system calls • Operating systems interpret virtual instructionsCopyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Processor Modes Page 189 November 18, 1997 Processor Modes • Machine level typically has 2 modes, e.g., “user” mode and “kernel” mode • User mode processor executes “normal” instructions in the user’s program upon encountering a “privileged” instruction, processor switches to kernel mode, and the operating system performs a service • Kernel mode processor executes both normal and privileged instructions • User-to-kernel switch saves the information necessary to continue the execution of the user process • Another view Operating system is a process that runs in kernel mode.Copyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Virtual Resources Page 190 November 18, 1997 Virtual Resources • OS provides a high-level representation of low-level resources • For example, low-level disks are presented as file systemssimple to use file systemtree-structured, hierarchical directoriesnamed filesfiles are sequences of bytesnetwork k disk drives different capacities, speeds access via cylinder, sector, track fixed I/O format and transfer rulesauthentication error correction and handlingUNIX Operating SystemCopyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: System Calls Page 191 November 18, 1997 System Calls • Virtual instructions are often presented as a set of system calls • Typical implementations (in order of prevalence) single privileged instruction with parametersinterpret to other privileged instructionsjump to fixed locations • Parameters are passed in a machine-dependent manner in fixed registersin fixed memory locationsin an argument block, with the block’s address in a registerin-line with the system callon the stackcombination of the above • System calls return results in registers, memory, etc., and an error indicationCopyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: System Calls, cont’d Page 192 November 18, 1997 System Calls, cont’d • System call mechanism is tailored to the machine architecture system calls on the SPARC use a trap instruction ta 0 trap always; a trap value of 0 indicates a system callparameters are in registers %g1 , %o0 — %o5 and on the stack • System call interface often designed to accommodate high-level languages system calls are accessed by a library of procedurese.g., on UNIX, system calls are packaged as a library of C functions • Typical UNIX system call nread = read(fd, buffer, n); returns the number of bytes read from the file fd , or -1 if an error occurswhat about EOF?Copyright  1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Implementing System Calls as Functions Page 193 November 18, 1997 Implementing System Calls as Functions • In the caller mov fd,%o0mov buffer,%o1mov n,%o2call _read; nopmov %o0,nread • Implementation of read _read:set 3,%g1 /* 3 indicates READ system call */ta 0 bcc L1; nopset _errno,%g1 /* sets errno to the error code */st %o0,[%g1]set -1,%o0 /* return -1 to indicate an error */L1: retl; nopoperating systemsets the C bit if an error occurredstores an error code in %o0; see /usr/include/sys/errno.hnote that read is a leaf function• UNIX has ~150 system callssee “man 2 intro” and /usr/include/syscall.hCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: Exceptions and Interrupts Page 194November 18, 1997Exceptions and Interrupts• Operating systems also field exceptions and interrupts•Exceptions (a.k.a. traps): caused by execution of an instructione.g., divide by 0, illegal address, memory protection violation, illegal opcode• Exceptions are like implicit system callsoperating systems can pass control to user processes to handle exceptions (e.g., “signals”)operating systems have ways to process exceptions by defaulte.g., segmentation fault and core dump•Interrupts: caused by “external” activity unrelated to the user processe.g., I/O completion, clock tick, etc.• Interrupts are like transparent system callsnormally user processes cannot detect interrupts, nor need to deal with themCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: SPARC Traps Page 195November 18, 1997SPARC Traps• A trap instructionenters kernel modedisables other trapsdecrements CWPsaves PC, nPC in %r17, %r18sets PC to TBR, nPC to TBR + 4• Hardware trap codes1 reset2 access exception3 illegal instruction...• Software trap codessets TBR to trap number + 128• There are conditional traps just like conditional branches• There are separate floating point trapsCopyright 1995 D. Hanson, K. Li & J.P. Singh Computer Science 217: System Calls for Input/Output Page 196November 18, 1997System Calls for Input/Output• Associating/disassociating files with file descriptorsint open(char *filename, int flags, int mode)int close(int fd)• Reading/writing from file descriptorsint read(int fd, char *buf, int nbytes)int write(int fd, char *buf, int nbytes)• Another version of cp source destination (see src/cp1.c)#include <sys/file.h>main(int argc, char *argv[]) {int count, src, dst;char buf[4096];if (argc != 3)error("usage: %s source


View Full Document

Princeton COS 217 - Operating Systems

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Operating Systems
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Operating Systems and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Operating Systems 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?