text
stringlengths
1
7.76k
source
stringlengths
17
81
Load word lw rt, address 0x23 rs rt Offset 6 5 5 16 Load the 32-bit quantity (word) at address into register rt. Load word coprocessor 1 lwcl ft, address 0x31 rs rt Offset 6 5 5 16 Load the word at address into register ft in the floating-point unit. Load word left lwl rt, address 0x22 rs rt Offset 6 5 5 16 Load word r...
clipped_hennesy_Page_843_Chunk6201
B-68 Appendix B Assemblers, Linkers, and the SPIM Simulator Unaligned load halfword unsigned ulhu rdest, address pseudoinstruction Load the 16-bit quantity (halfword) at the possibly unaligned address into ­register rdest. The halfword is sign-extended by ulh, but not ulhu. Unaligned load word ulw rdest, address pseudo...
clipped_hennesy_Page_844_Chunk6202
Store word sw rt, address 0x2b rs rt Offset 6 5 5 16 Store the word from register rt at address. Store word coprocessor 1 swcl ft, address 0x31 rs ft Offset 6 5 5 16 Store the floating-point value in register ft of floating-point coprocessor at address. Store double coprocessor 1 sdcl ft, address 0x3d rs ft Offset 6 5 ...
clipped_hennesy_Page_845_Chunk6203
B-70 Appendix B Assemblers, Linkers, and the SPIM Simulator Unaligned store halfword ush rsrc, address pseudoinstruction Store the low halfword from register rsrc at the possibly unaligned address. Unaligned store word usw rsrc, address pseudoinstruction Store the word from register rsrc at the possibly unaligned addre...
clipped_hennesy_Page_846_Chunk6204
Move from lo mflo rd 0 0 rd 0 0x12 6 10 5 5 6 The multiply and divide unit produces its result in two additional registers, hi and lo. These instructions move values to and from these registers. The multiply, divide, and remainder pseudoinstructions that make this unit appear to operate on the general registers move th...
clipped_hennesy_Page_847_Chunk6205
B-72 Appendix B Assemblers, Linkers, and the SPIM Simulator Move double from coprocessor 1 mfc1.d rdest, frsrc1 pseudoinstruction Move floating-point registers frsrc1 and frsrc1 + 1 to CPU registers rdest and rdest + 1. Move to coprocessor 0 mtc0 rd, rt 0x10 4 rt rd 0 6 5 5 5 11 Move to coprocessor 1 mtc1 rd, fs 0x11 4...
clipped_hennesy_Page_848_Chunk6206
Move conditional on FP true movt rd, rs, cc 0 rs cc 1 rd 0 1 6 5 3 2 5 5 6 Move CPU register rs to register rd if FPU condition code flag number cc is 1. If cc is omitted from the instruction, condition code bit 0 is assumed. Floating-Point Instructions The MIPS has a floating-point coprocessor (numbered 1) that operat...
clipped_hennesy_Page_849_Chunk6207
B-74 Appendix B Assemblers, Linkers, and the SPIM Simulator Floating-point addition single add.s fd, fs, ft 0x11 0x10 ft fs fd 0 6 5 5 5 5 6 Compute the sum of the floating-point doubles (singles) in registers fs and ft and put it in register fd. Floating-point ceiling to word ceil.w.d fd, fs 0x11 0x11 0 fs fd 0xe 6 5 ...
clipped_hennesy_Page_850_Chunk6208
Compare the floating-point double (single) in register fs against the one in ft and set the floating-point condition flag cc to 1 if the first is less than or equal to the second. If cc is omitted, condition code flag 0 is assumed. Compare less than double c.lt.d cc fs, ft 0x11 0x11 ft fs cc 0 FC 0xc 6 5 5 5 3 2 2 4 Co...
clipped_hennesy_Page_851_Chunk6209
B-76 Appendix B Assemblers, Linkers, and the SPIM Simulator Convert double to integer cvt.w.d fd, fs 0x11 0x11 0 fs fd 0x24 6 5 5 5 5 6 Convert single to integer cvt.w.s fd, fs 0x11 0x10 0 fs fd 0x24 6 5 5 5 5 6 Convert the double or single precision floating-point number in register fs to an integer and put it in regi...
clipped_hennesy_Page_852_Chunk6210
Load floating-point single l.s fdest, address pseudoinstruction Load the floating-point double (single) at address into register fdest. Move floating-point double mov.d fd, fs 0x11 0x11 0 fs fd 6 6 5 5 5 5 6 Move floating-point single mov.s fd, fs 0x11 0x10 0 fs fd 6 6 5 5 5 5 6 Move the floating-point double (single) ...
clipped_hennesy_Page_853_Chunk6211
B-78 Appendix B Assemblers, Linkers, and the SPIM Simulator Move the floating-point double (single) from register fs to register fd if condi­tion code flag cc is 1. If cc is omitted, condition code flag 0 is assumed. Move conditional floating-point double not zero movn.d fd, fs, rt 0x11 0x11 rt fs fd 0x13 6 5 5 5 5 6 M...
clipped_hennesy_Page_854_Chunk6212
Negate single neg.s fd, fs 0x11 0x10 0 fs fd 7 6 5 5 5 5 6 Negate the floating-point double (single) in register fs and put it in register fd. Floating-point round to word round.w.d fd, fs 0x11 0x11 0 fs fd 0xc 6 5 5 5 5 6 round.w.s fd, fs 0x11 0x10 0 fs fd 0xc Round the floating-point double (single) value in register...
clipped_hennesy_Page_855_Chunk6213
B-80 Appendix B Assemblers, Linkers, and the SPIM Simulator Floating-point subtract single sub.s fd, fs, ft 0x11 0x10 ft fs fd 1 6 5 5 5 5 6 Compute the difference of the floating-point doubles (singles) in registers fs and ft and put it in register fd. Floating-point truncate to word trunc.w.d fd, fs 0x11 0x11 0 fs fd...
clipped_hennesy_Page_856_Chunk6214
B.11 Concluding Remarks Programming in assembly language requires a programmer to trade helpful fea- tures of high-level languages—such as data structures, type checking, and control constructs—for complete control over the instructions that a computer executes. External constraints on some applications, such as respon...
clipped_hennesy_Page_857_Chunk6215
B-82 Appendix B Assemblers, Linkers, and the SPIM Simulator B.12 Exercises B.1 [5] <§B.5> Section B.5 described how memory is partitioned on most MIPS systems. Propose another way of dividing memory that meets the same goals. B.2 [20] <§B.6> Rewrite the code for fact to use fewer instructions. B.3 [5] <§B.7> Is it ever...
clipped_hennesy_Page_858_Chunk6216
B.10 [10] <§§B.6, B.9> Using SPIM, write and test a recursive program for solv­ing the classic mathematical recreation, the Towers of Hanoi puzzle. (This will require the use of stack frames to support recursion.) The puzzle consists of three pegs (1, 2, and 3) and n disks (the number n can vary; typical values might b...
clipped_hennesy_Page_859_Chunk6217
1 INTRODUCTION A modern computer consists of one or more processors, some main memory, disks, printers, a keyboard, a mouse, a display, network interfaces, and various other input/output devices. All in all, a complex system.oo If every application pro- grammer had to understand how all these things work in detail, no ...
clipped_os_Page_1_Chunk6218
2 INTRODUCTION CHAP. 1 complete access to all the hardware and can execute any instruction the machine is capable of executing. The rest of the software runs in user mode, in which only a subset of the machine instructions is available. In particular, those instructions that affect control of the machine or do I/O )Inp...
clipped_os_Page_2_Chunk6219
SEC. 1.1 WHAT IS AN OPERATING SYSTEM? 3 system (such as the file system) run in user space. In such systems, it is difficult to draw a clear boundary. Everything running in kernel mode is clearly part of the operating system, but some programs running outside it are arguably also part of it, or at least closely associa...
clipped_os_Page_3_Chunk6220
4 INTRODUCTION CHAP. 1 providing application programmers (and application programs, naturally) a clean abstract set of resources instead of the messy hardware ones and managing these hardware resources. Depending on who is doing the talking, you might hear mostly about one function or the other. Let us now look at both...
clipped_os_Page_4_Chunk6221
SEC. 1.1 WHAT IS AN OPERATING SYSTEM? 5 Operating system Hardware Ugly interface Beautiful interface Application programs Figure 1-2. Operating systems turn ugly hardware into beautiful abstractions. It should be noted that the operating system’s real customers are the applica- tion programs (via the application progra...
clipped_os_Page_5_Chunk6222
6 INTRODUCTION CHAP. 1 few lines of printout might be from program 1, the next few from program 2, then some from program 3, and so forth. The result would be utter chaos. The operating system can bring order to the potential chaos by buffering all the output destined for the printer on the disk. When one program is fi...
clipped_os_Page_6_Chunk6223
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 7 run, we will look at successive generations of computers to see what their operat- ing systems were like. This mapping of operating system generations to computer generations is crude, but it does provide some structure where there would other- wise be none. The progression given...
clipped_os_Page_7_Chunk6224
8 INTRODUCTION CHAP. 1 straightforward mathematical and numerical calculations, such as grinding out tables of sines, cosines, and logarithms, or computing artillery trajectories. By the early 1950s, the routine had improved somewhat with the introduction of punched cards. It was now possible to write programs on cards...
clipped_os_Page_8_Chunk6225
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 9 1401 7094 1401 (a) (b) (c) (d) (e) (f) Card reader Tape drive Input tape Output tape System tape Printer Figure 1-3. An early batch system. (a) Programmers bring cards to 1401. (b) 1401 reads batch of jobs onto tape. (c) Operator carries input tape to 7094. (d) 7094 does computin...
clipped_os_Page_9_Chunk6226
10 INTRODUCTION CHAP. 1 $JOB, 10,7710802, MARVIN TANENBAUM $FORTRAN $LOAD $RUN $END Data for program FORTRAN program Figure 1-4. Structure of a typical FMS job. character-oriented, commercial computers, such as the 1401, which were widely used for tape sorting and printing by banks and insurance companies. Developing a...
clipped_os_Page_10_Chunk6227
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 11 was an immediate success, and the idea of a family of compatible computers was soon adopted by all the other major manufacturers. The descendants of these ma- chines are still in use at computer centers today. Now adays they are often used for managing huge databases (e.g., for ...
clipped_os_Page_11_Chunk6228
12 INTRODUCTION CHAP. 1 Job 3 Job 2 Job 1 Operating system Memory partitions Figure 1-5. A multiprogramming system with three jobs in memory. Another major feature present in third-generation operating systems was the ability to read jobs from cards onto the disk as soon as they were brought to the computer room. Then,...
clipped_os_Page_12_Chunk6229
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 13 of simultaneous timesharing users. Their model was the electricity system—when you need electric power, you just stick a plug in the wall, and within reason, as much power as you need will be there. The designers of this system, known as MULTICS (MULTiplexed Information and Comp...
clipped_os_Page_13_Chunk6230
14 INTRODUCTION CHAP. 1 and Saltzer, 1974). It also has an active Website, located at www.multicians.org, with much information about the system, its designers, and its users. Another major development during the third generation was the phenomenal growth of minicomputers, starting with the DEC PDP-1 in 1961. The PDP-1...
clipped_os_Page_14_Chunk6231
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 15 1.2.4 The Fourth Generation (1980–Present): Personal Computers With the development of LSI (Large Scale Integration) circuits—chips con- taining thousands of transistors on a square centimeter of silicon—the age of the personal computer dawned. In terms of architecture, personal...
clipped_os_Page_15_Chunk6232
16 INTRODUCTION CHAP. 1 attempt to sell CP/M to end users one at a time (at least initially). After all this transpired, Kildall died suddenly and unexpectedly from causes that have not been fully disclosed. By the time the successor to the IBM PC, the IBM PC/AT, came out in 1983 with the Intel 80286 CPU, MS-DOS was fi...
clipped_os_Page_16_Chunk6233
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 17 complete rewrite from scratch internally. It was a full 32-bit system. The lead de- signer for Windows NT was David Cutler, who was also one of the designers of the VAX VMS operating system, so some ideas from VMS are present in NT. In fact, so many ideas from VMS were present i...
clipped_os_Page_17_Chunk6234
18 INTRODUCTION CHAP. 1 x86-based computers, Linux is becoming a popular alternative to Windows for stu- dents and increasingly many corporate users. As an aside, throughout this book we will use the term x86 to refer to all mod- ern processors based on the family of instruction-set architectures that started with the ...
clipped_os_Page_18_Chunk6235
SEC. 1.2 HISTORY OF OPERATING SYSTEMS 19 differ in certain critical ways. Distributed systems, for example, often allow appli- cations to run on several processors at the same time, thus requiring more complex processor scheduling algorithms in order to optimize the amount of parallelism. Communication delays within th...
clipped_os_Page_19_Chunk6236
20 INTRODUCTION CHAP. 1 of the town (although not nearly as dominant as Symbian had been), but it did not take very long for Android, a Linux-based operating system released by Google in 2008, to overtake all its rivals. For phone manufacturers, Android had the advantage that it was open source and available under a pe...
clipped_os_Page_20_Chunk6237
SEC. 1.3 COMPUTER HARDWARE REVIEW 21 1.3.1 Processors The ‘‘brain’’ of the computer is the CPU. It fetches instructions from memory and executes them. The basic cycle of every CPU is to fetch the first instruction from memory, decode it to determine its type and operands, execute it, and then fetch, decode, and execute...
clipped_os_Page_21_Chunk6238
22 INTRODUCTION CHAP. 1 Pipelines cause compiler writers and operating system writers great headaches be- cause they expose the complexities of the underlying machine to them and they have to deal with them. Fetch unit Fetch unit Fetch unit Decode unit Decode unit Execute unit Execute unit Execute unit Execute unit Dec...
clipped_os_Page_22_Chunk6239
SEC. 1.3 COMPUTER HARDWARE REVIEW 23 of procedure call that has the additional property of switching from user mode to kernel mode. As a note on typography, we will use the lower-case Helvetica font to indicate system calls in running text, like this: read. It is worth noting that computers have traps other than the in...
clipped_os_Page_23_Chunk6240
24 INTRODUCTION CHAP. 1 time, it may inadvertently schedule two threads on the same CPU, with the other CPU completely idle. This choice is far less efficient than using one thread on each CPU. Beyond multithreading, many CPU chips now hav e four, eight, or more com- plete processors or cores on them. The multicore chi...
clipped_os_Page_24_Chunk6241
SEC. 1.3 COMPUTER HARDWARE REVIEW 25 Registers Cache Main memory Magnetic disk 1 nsec 2 nsec 10 nsec 10 msec <1 KB 4 MB 1-8 GB 1-4 TB Typical capacity Typical access time Figure 1-9. A typical memory hierarchy. The numbers are very rough approximations. typically 32 × 32 bits on a 32-bit CPU and 64 × 64 bits on a 64-bi...
clipped_os_Page_25_Chunk6242
26 INTRODUCTION CHAP. 1 Not every question is relevant to every caching situation. For caching lines of main memory in the CPU cache, a new item will generally be entered on every cache miss. The cache line to use is generally computed by using some of the high-order bits of the memory address referenced. For example, ...
clipped_os_Page_26_Chunk6243
SEC. 1.3 COMPUTER HARDWARE REVIEW 27 Flash memory is also commonly used as the storage medium in portable elec- tronic devices. It serves as film in digital cameras and as the disk in portable music players, to name just two uses. Flash memory is intermediate in speed between RAM and disk. Also, unlike disk memory, if ...
clipped_os_Page_27_Chunk6244
28 INTRODUCTION CHAP. 1 Information is written onto the disk in a series of concentric circles. At any giv en arm position, each of the heads can read an annular region called a track. Toget- her, all the tracks for a given arm position form a cylinder. Each track is divided into some number of sectors, typically 512 b...
clipped_os_Page_28_Chunk6245
SEC. 1.3 COMPUTER HARDWARE REVIEW 29 read sector 11,206 from disk 2. The controller then has to convert this linear sector number to a cylinder, sector, and head. This conversion may be complicated by the fact that outer cylinders have more sectors than inner ones and that some bad sec- tors have been remapped onto oth...
clipped_os_Page_29_Chunk6246
30 INTRODUCTION CHAP. 1 drivers while running and install them on the fly without the need to reboot. This way used to be rare but is becoming much more common now. Hot-pluggable devices, such as USB and IEEE 1394 devices (discussed below), always need dy- namically loaded drivers. Every controller has a small number o...
clipped_os_Page_30_Chunk6247
SEC. 1.3 COMPUTER HARDWARE REVIEW 31 puts the number of the device on the bus so the CPU can read it and know which device has just finished (many devices may be running at the same time). CPU Interrupt controller Disk controller Disk drive Current instruction Next instruction 1. Interrupt 3. Return 2. Dispatch to hand...
clipped_os_Page_31_Chunk6248
32 INTRODUCTION CHAP. 1 1.3.5 Buses The organization of Fig. 1-6 was used on minicomputers for years and also on the original IBM PC. However, as processors and memories got faster, the ability of a single bus (and certainly the IBM PC bus) to handle all the traffic was strained to the breaking point. Something had to ...
clipped_os_Page_32_Chunk6249
SEC. 1.3 COMPUTER HARDWARE REVIEW 33 a message through a single connection, known as a lane, much like a network packet. This is much simpler, because you do not have to ensure that all 32 bits arrive at the destination at exactly the same time. Parallelism is still used, because you can have multiple lanes in parallel...
clipped_os_Page_33_Chunk6250
34 INTRODUCTION CHAP. 1 I/O addresses 0x60 to 0x64, the floppy disk controller was interrupt 6 and used I/O addresses 0x3F0 to 0x3F7, and the printer was interrupt 7 and used I/O addresses 0x378 to 0x37A, and so on. So far, so good. The trouble came in when the user bought a sound card and a modem card and both happene...
clipped_os_Page_34_Chunk6251
SEC. 1.3 COMPUTER HARDWARE REVIEW 35 operating system loads them into the kernel. Then it initializes its tables, creates whatever background processes are needed, and starts up a login program or GUI. 1.4 THE OPERATING SYSTEM ZOO Operating systems have been around now for over half a century. During this time, quite a...
clipped_os_Page_35_Chunk6252
36 INTRODUCTION CHAP. 1 service. Internet providers run many server machines to support their customers and Websites use servers to store the Web pages and handle the incoming requests. Typical server operating systems are Solaris, FreeBSD, Linux and Windows Server 201x. 1.4.3 Multiprocessor Operating Systems An increa...
clipped_os_Page_36_Chunk6253
SEC. 1.4 THE OPERATING SYSTEM ZOO 37 1.4.6 Embedded Operating Systems Embedded systems run on the computers that control devices that are not gen- erally thought of as computers and which do not accept user-installed software. Typical examples are microwave ovens, TV sets, cars, DVD recorders, traditional phones, and M...
clipped_os_Page_37_Chunk6254
38 INTRODUCTION CHAP. 1 occur at a certain moment (or within a certain range), we have a hard real-time system. Many of these are found in industrial process control, avionics, military, and similar application areas. These systems must provide absolute guarantees that a certain action will occur by a certain time. A s...
clipped_os_Page_38_Chunk6255
SEC. 1.5 OPERATING SYSTEM CONCEPTS 39 an introduction. We will come back to each of them in great detail later in this book. To illustrate these concepts we will, from time to time, use examples, gener- ally drawn from UNIX. Similar examples typically exist in other systems as well, however, and we will study some of t...
clipped_os_Page_39_Chunk6256
40 INTRODUCTION CHAP. 1 typed a command requesting that a program be compiled. The shell must now cre- ate a new process that will run the compiler. When that process has finished the compilation, it executes a system call to terminate itself. If a process can create one or more other processes (referred to as child pr...
clipped_os_Page_40_Chunk6257
SEC. 1.5 OPERATING SYSTEM CONCEPTS 41 One UID, called the superuser (in UNIX), or Administrator (in Windows), has special power and may override many of the protection rules. In large in- stallations, only the system administrator knows the password needed to become superuser, but many of the ordinary users (especially...
clipped_os_Page_41_Chunk6258
42 INTRODUCTION CHAP. 1 nice, clean abstract model of device-independent files. System calls are obviously needed to create files, remove files, read files, and write files. Before a file can be read, it must be located on the disk and opened, and after being read it should be closed, so calls are provided to do these ...
clipped_os_Page_42_Chunk6259
SEC. 1.5 OPERATING SYSTEM CONCEPTS 43 access a child process, but mechanisms nearly always exist to allow files and direc- tories to be read by a wider group than just the owner. Every file within the directory hierarchy can be specified by giving its path name from the top of the directory hierarchy, the root director...
clipped_os_Page_43_Chunk6260
44 INTRODUCTION CHAP. 1 Root CD-ROM a b c d c d a b x y x y (a) (b) Figure 1-15. (a) Before mounting, the files on the CD-ROM are not accessible. (b) After mounting, they are part of the file hierarchy. Another important concept in UNIX is the special file. Special files are pro- vided in order to make I/O devices look...
clipped_os_Page_44_Chunk6261
SEC. 1.5 OPERATING SYSTEM CONCEPTS 45 1.5.4 Input/Output All computers have physical devices for acquiring input and producing output. After all, what good would a computer be if the users could not tell it what to do and could not get the results after it did the work requested? Many kinds of input and output devices ...
clipped_os_Page_45_Chunk6262
46 INTRODUCTION CHAP. 1 between a user sitting at his terminal and the operating system, unless the user is using a graphical user interface. Many shells exist, including sh, csh, ksh, and bash. All of them support the functionality described below, which derives from the orig- inal shell (sh). When any user logs in, a...
clipped_os_Page_46_Chunk6263
SEC. 1.5 OPERATING SYSTEM CONCEPTS 47 1.5.7 Ontogeny Recapitulates Phylogeny After Charles Darwin’s book On the Origin of the Species was published, the German zoologist Ernst Haeckel stated that ‘‘ontogeny recapitulates phylogeny.’’ By this he meant that the development of an embryo (ontogeny) repeats (i.e., reca- pit...
clipped_os_Page_47_Chunk6264
48 INTRODUCTION CHAP. 1 is not always crucial because network delays are so great that they tend to domi- nate. Thus the pendulum has already swung several cycles between direct execu- tion and interpretation and may yet swing again in the future. Large Memories Let us now examine some historical developments in hardwa...
clipped_os_Page_48_Chunk6265
SEC. 1.5 OPERATING SYSTEM CONCEPTS 49 hardware was added and multiprogramming became possible. Until this day, many embedded systems have no protection hardware and run just a single program. Now let us look at operating systems. The first mainframes initially had no protection hardware and no support for multiprogramm...
clipped_os_Page_49_Chunk6266
50 INTRODUCTION CHAP. 1 40 cm in diameter and 5 cm high. But it, too, had a single-level directory initially. When microcomputers came out, CP/M was initially the dominant operating sys- tem, and it, too, supported just one directory on the (floppy) disk. Virtual Memory Virtual memory (discussed in Chap. 3) gives the a...
clipped_os_Page_50_Chunk6267
SEC. 1.6 SYSTEM CALLS 51 mechanics of issuing a system call are highly machine dependent and often must be expressed in assembly code, a procedure library is provided to make it possible to make system calls from C programs and often from other languages as well. It is useful to keep the following in mind. Any single-C...
clipped_os_Page_51_Chunk6268
52 INTRODUCTION CHAP. 1 Return to caller 4 10 6 0 9 7 8 3 2 1 11 Dispatch Sys call handler Address 0xFFFFFFFF User space Kernel space (Operating system) Library procedure read User program calling read Trap to the kernel Put code for read in register Increment SP Call read Push fd Push &buffer Push nbytes 5 Figure 1-17...
clipped_os_Page_52_Chunk6269
SEC. 1.6 SYSTEM CALLS 53 does, the compiled code increments the stack pointer exactly enough to remove the parameters pushed before the call to read. The program is now free to do whatever it wants to do next. In step 9 above, we said ‘‘may be returned to the user-space library procedure’’ for good reason. The system c...
clipped_os_Page_53_Chunk6270
54 INTRODUCTION CHAP. 1 Process management Call Description pid = for k( ) Create a child process identical to the parent pid = waitpid(pid, &statloc, options) Wait for a child to terminate s = execve(name, argv, environp) Replace a process’ core image exit(status) Ter minate process execution and return status File ma...
clipped_os_Page_54_Chunk6271
SEC. 1.6 SYSTEM CALLS 55 the parent executes a waitpid system call, which just waits until the child terminates (any child if more than one exists). Waitpid can wait for a specific child, or for any old child by setting the first parameter to −1. When waitpid completes, the address pointed to by the second parameter, s...
clipped_os_Page_55_Chunk6272
56 INTRODUCTION CHAP. 1 The main program of cp (and main program of most other C programs) con- tains the declaration main(argc, argv, envp) where argc is a count of the number of items on the command line, including the program name. For the example above, argc is 3. The second parameter, argv, is a pointer to an arra...
clipped_os_Page_56_Chunk6273
SEC. 1.6 SYSTEM CALLS 57
clipped_os_Page_57_Chunk6274
58 INTRODUCTION CHAP. 1 a shared file means that changes that any member of the team makes are instantly visible to the other members—there is only one file. When copies are made of a file, subsequent changes made to one copy do not affect the others. To see how link works, consider the situation of Fig. 1-21(a). Here ...
clipped_os_Page_58_Chunk6275
SEC. 1.6 SYSTEM CALLS 59 By executing the mount system call, the USB file system can be attached to the root file system, as shown in Fig. 1-22. A typical statement in C to mount is mount("/dev/sdb0", "/mnt", 0); where the first parameter is the name of a block special file for USB drive 0, the second parameter is the ...
clipped_os_Page_59_Chunk6276
60 INTRODUCTION CHAP. 1 run. If the process is not prepared to handle a signal, then its arrival kills the proc- ess (hence the name of the call). POSIX defines a number of procedures for dealing with time. For example, time just returns the current time in seconds, with 0 corresponding to Jan. 1, 1970 at midnight (jus...
clipped_os_Page_60_Chunk6277
SEC. 1.6 SYSTEM CALLS 61 The number of Win32 API calls is extremely large, numbering in the thou- sands. Furthermore, while many of them do invoke system calls, a substantial num- ber are carried out entirely in user space. As a consequence, with Windows it is impossible to see what is a system call (i.e., performed by...
clipped_os_Page_61_Chunk6278
62 INTRODUCTION CHAP. 1 UNIX Win32 Description fork CreateProcess Create a new process waitpid WaitForSingleObject Can wait for a process to exit execve (none) CreateProcess = for k + execve exit ExitProcess Terminate execution open CreateFile Create a file or open an existing file close CloseHandle Close a file read R...
clipped_os_Page_62_Chunk6279
SEC. 1.7 OPERATING SYSTEM STRUCTURE 63 1.7.1 Monolithic Systems By far the most common organization, in the monolithic approach the entire operating system runs as a single program in kernel mode. The operating system is written as a collection of procedures, linked together into a single large executable binary progra...
clipped_os_Page_63_Chunk6280
64 INTRODUCTION CHAP. 1 Main procedure Service procedures Utility procedures Figure 1-24. A simple structuring model for a monolithic system. 1.7.2 Layered Systems A generalization of the approach of Fig. 1-24 is to organize the operating sys- tem as a hierarchy of layers, each one constructed upon the one below it. Th...
clipped_os_Page_64_Chunk6281
SEC. 1.7 OPERATING SYSTEM STRUCTURE 65 took care of making sure pages were brought into memory at the moment they were needed and removed when they were not needed. Layer 2 handled communication between each process and the operator con- sole (that is, the user). On top of this layer each process effectively had its ow...
clipped_os_Page_65_Chunk6282
66 INTRODUCTION CHAP. 1 course, since some bugs may be things like issuing an incorrect error message in a situation that rarely occurs. Nevertheless, operating systems are sufficiently buggy that computer manufacturers put reset buttons on them (often on the front panel), something the manufacturers of TV sets, stereo...
clipped_os_Page_66_Chunk6283
SEC. 1.7 OPERATING SYSTEM STRUCTURE 67 User mode Microkernel handles interrupts, processes, scheduling, interprocess communication Sys Clock FS Proc. Reinc. Other ... Servers Disk TTY Netw Print Other ... Drivers Shell Make ... Process User programs Other Figure 1-26. Simplified structure of the MINIX system. the kerne...
clipped_os_Page_67_Chunk6284
68 INTRODUCTION CHAP. 1 highest-priority process that is runnable. The mechanism—in the kernel—is to look for the highest-priority process and run it. The policy—assigning priorities to processes—can be done by user-mode processes. In this way, policy and mechan- ism can be decoupled and the kernel can be made smaller....
clipped_os_Page_68_Chunk6285
SEC. 1.7 OPERATING SYSTEM STRUCTURE 69 1.7.5 Virtual Machines The initial releases of OS/360 were strictly batch systems. Nevertheless, many 360 users wanted to be able to work interactively at a terminal, so various groups, both inside and outside IBM, decided to write timesharing systems for it. The of- ficial IBM ti...
clipped_os_Page_69_Chunk6286
70 INTRODUCTION CHAP. 1 transaction-processing operating systems, while others ran a single-user, interactive system called CMS (Conversational Monitor System) for interactive timesharing users. The latter was popular with programmers. When a CMS program executed a system call, the call was trapped to the oper- ating s...
clipped_os_Page_70_Chunk6287
SEC. 1.7 OPERATING SYSTEM STRUCTURE 71 ‘‘virtual machine monitor’’ requires more keystrokes than people are prepared to put up with now. Note that many authors use the terms interchangeably though. Type 1 hypervisor Host operating system (a) (b) ... Linux Windows Excel Word Mplayer Apollon Machine simulator Guest OS Gu...
clipped_os_Page_71_Chunk6288
72 INTRODUCTION CHAP. 1 The next step in improving performance was to add a kernel module to do some of the heavy lifting, as shown in Fig. 1-29(c). In practice now, all commer- cially available hypervisors, such as VMware Workstation, use this hybrid strategy (and have many other improvements as well). They are called...
clipped_os_Page_72_Chunk6289
SEC. 1.7 OPERATING SYSTEM STRUCTURE 73 1.7.6 Exokernels Rather than cloning the actual machine, as is done with virtual machines, an- other strategy is partitioning it, in other words, giving each user a subset of the re- sources. Thus one virtual machine might get disk blocks 0 to 1023, the next one might get blocks 1...
clipped_os_Page_73_Chunk6290
74 INTRODUCTION CHAP. 1 One feature C has that Java and Python do not is explicit pointers. A pointer is a variable that points to (i.e., contains the address of) a variable or data structure. Consider the statements char c1, c2, *p; c1 = ’c’; p = &c1; c2 = *p; which declare c1 and c2 to be character variables and p to...
clipped_os_Page_74_Chunk6291
SEC. 1.8 THE WORLD ACCORDING TO C 75 i = max(j, k+1) and get i = (j > k+1 ? j : k+1) to store the larger of j and k+1 in i. Headers can also contain conditional compila- tion, for example #ifdef X86 intel int ack(); #endif which compiles into a call to the function intel int ack if the macro X86 is defined and nothing ...
clipped_os_Page_75_Chunk6292
76 INTRODUCTION CHAP. 1 recompile them, thus reducing the number of compilations to the bare minimum. In large projects, creating the Makefile is error prone, so there are tools that do it automatically. Once all the .o files are ready, they are passed to a program called the linker to combine all of them into a single...
clipped_os_Page_76_Chunk6293
SEC. 1.8 THE WORLD ACCORDING TO C 77 and file systems. At run time the operating system may consist of multiple seg- ments, for the text (the program code), the data, and the stack. The text segment is normally immutable, not changing during execution. The data segment starts out at a certain size and initialized with ...
clipped_os_Page_77_Chunk6294
78 INTRODUCTION CHAP. 1 the past 5 to 10 years, just to give a flavor of what might be on the horizon. This introduction is certainly not comprehensive. It is based largely on papers that have been published in the top research conferences because these ideas have at least survived a rigorous peer review process in ord...
clipped_os_Page_78_Chunk6295
SEC. 1.10 OUTLINE OF THE REST OF THIS BOOK 79 some key abstractions, the most important of which are processes and threads, ad- dress spaces, and files. Accordingly the next three chapters are devoted to these critical topics. Chapter 2 is about processes and threads. It discusses their properties and how they communic...
clipped_os_Page_79_Chunk6296
80 INTRODUCTION CHAP. 1 Exp. Explicit Prefix Exp. Explicit Prefix 10−3 0.001 milli 103 1,000 Kilo 10−6 0.000001 micro 106 1,000,000 Mega 10−9 0.000000001 nano 109 1,000,000,000 Giga 10−12 0.000000000001 pico 1012 1,000,000,000,000 Tera 10−15 0.000000000000001 femto 1015 1,000,000,000,000,000 Peta 10−18 0.00000000000000...
clipped_os_Page_80_Chunk6297
SEC. 1.12 SUMMARY 81 The heart of any operating system is the set of system calls that it can handle. These tell what the operating system really does. For UNIX, we have looked at four groups of system calls. The first group of system calls relates to process crea- tion and termination. The second group is for reading ...
clipped_os_Page_81_Chunk6298
82 INTRODUCTION CHAP. 1 12. Which of the following instructions should be allowed only in kernel mode? (a) Disable all interrupts. (b) Read the time-of-day clock. (c) Set the time-of-day clock. (d) Change the memory map. 13. Consider a system that has two CPUs, each CPU having two threads (hyperthreading). Suppose thre...
clipped_os_Page_82_Chunk6299
CHAP. 1 PROBLEMS 83 where the lseek call makes a seek to byte 3 of the file. What does buffer contain after the read has completed? 24. Suppose that a 10-MB file is stored on a disk on the same track (track 50) in consecu- tive sectors. The disk arm is currently situated over track number 100. How long will it take to ...
clipped_os_Page_83_Chunk6300