├── v6.pdf ├── lionc.pdf ├── Original Files ├── ch12.tex ├── lionc.dvi ├── lionc.evn ├── lionc.odd ├── lionc.pdf ├── Readme ├── title.aux ├── preface.aux ├── lionc.aux ├── ch11.aux ├── ch21.aux ├── ch14.aux ├── ch26.aux ├── ch16.aux ├── ch10.aux ├── title.tex ├── ch23.aux ├── ch9.aux ├── ch6.aux ├── ch15.aux ├── ch19.aux ├── ch1.aux ├── fig23_3.tex ├── ch4.aux ├── ch12.aux ├── ch22.aux ├── fig23_2.tex ├── ch5.aux ├── fig23_1.tex ├── fig23_4.tex ├── ch7.aux ├── ch17.aux ├── ch2.aux ├── ch8.aux ├── ch25.aux ├── ch20.aux ├── ch3.aux ├── ch24.aux ├── lionc.tex ├── ch18.aux ├── ch13.aux ├── ch21.tex ├── ch16.tex ├── ch26.tex ├── preface.tex ├── ch11.tex ├── lionc.log ├── ch15.tex ├── ch1.tex ├── ch10.tex ├── ch14.tex ├── ch9.tex ├── ch17.tex └── ch23.tex └── README.md /v6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/v6.pdf -------------------------------------------------------------------------------- /lionc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/lionc.pdf -------------------------------------------------------------------------------- /Original Files/ch12.tex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/Original Files/ch12.tex -------------------------------------------------------------------------------- /Original Files/lionc.dvi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/Original Files/lionc.dvi -------------------------------------------------------------------------------- /Original Files/lionc.evn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/Original Files/lionc.evn -------------------------------------------------------------------------------- /Original Files/lionc.odd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/Original Files/lionc.odd -------------------------------------------------------------------------------- /Original Files/lionc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horsebrain/LionsCommentary/HEAD/Original Files/lionc.pdf -------------------------------------------------------------------------------- /Original Files/Readme: -------------------------------------------------------------------------------- 1 | See title.tex for details of this document. 2 | 3 | To print, run the document through LaTeX twice: 4 | 5 | % latex lionc.tex 6 | % latex lionc.tex 7 | 8 | Then use the appropriate dvi converter, e.g 9 | 10 | % dvips lionc.dvi 11 | 12 | 13 | Please post typographical/other changes to this document 14 | to alt.folklore.computers as context diffs (i.e diff -c) 15 | with the Subject line of `Leo's Patches blah blah'. 16 | -------------------------------------------------------------------------------- /Original Files/title.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \global\@namedef{cp@title}{ 3 | \setcounter{page}{2} 4 | \setcounter{equation}{0} 5 | \setcounter{enumi}{0} 6 | \setcounter{enumii}{0} 7 | \setcounter{enumiii}{0} 8 | \setcounter{enumiv}{0} 9 | \setcounter{footnote}{0} 10 | \setcounter{mpfootnote}{0} 11 | \setcounter{part}{0} 12 | \setcounter{section}{0} 13 | \setcounter{subsection}{0} 14 | \setcounter{subsubsection}{0} 15 | \setcounter{paragraph}{0} 16 | \setcounter{subparagraph}{0} 17 | \setcounter{figure}{0} 18 | \setcounter{table}{0} 19 | } 20 | -------------------------------------------------------------------------------- /Original Files/preface.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \global\@namedef{cp@preface}{ 3 | \setcounter{page}{7} 4 | \setcounter{equation}{0} 5 | \setcounter{enumi}{0} 6 | \setcounter{enumii}{0} 7 | \setcounter{enumiii}{0} 8 | \setcounter{enumiv}{0} 9 | \setcounter{footnote}{0} 10 | \setcounter{mpfootnote}{0} 11 | \setcounter{part}{0} 12 | \setcounter{section}{0} 13 | \setcounter{subsection}{0} 14 | \setcounter{subsubsection}{0} 15 | \setcounter{paragraph}{0} 16 | \setcounter{subparagraph}{0} 17 | \setcounter{figure}{0} 18 | \setcounter{table}{0} 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lions Commentary 2 | 3 | A recompile of the "John Lions Commentary on the 6th edition Unix OS" book, along with the readily available source code. Grabbed from (http://v6.cuzuco.com/). 4 | 5 | It's not perfect but it's the best I could do in the time that I have. This is much more cleaner to look at and print than the currently available PDF version. 6 | 7 | Using MiKTeX (https://miktex.org/) through TexStudio. (https://sourceforge.net/projects/texstudio/) 8 | 9 | 10 | This is all readily available online, no copyright infringement intended, I simply recompiled the book from the available .tex files. 11 | 12 | -------------------------------------------------------------------------------- /Original Files/lionc.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@input{title.aux} 3 | \@input{preface.aux} 4 | \@input{ch1.aux} 5 | \@input{ch2.aux} 6 | \@input{ch3.aux} 7 | \@input{ch4.aux} 8 | \@input{ch5.aux} 9 | \@input{ch6.aux} 10 | \@input{ch7.aux} 11 | \@input{ch8.aux} 12 | \@input{ch9.aux} 13 | \@input{ch10.aux} 14 | \@input{ch11.aux} 15 | \@input{ch12.aux} 16 | \@input{ch13.aux} 17 | \@input{ch14.aux} 18 | \@input{ch15.aux} 19 | \@input{ch16.aux} 20 | \@input{ch17.aux} 21 | \@input{ch18.aux} 22 | \@input{ch19.aux} 23 | \@input{ch20.aux} 24 | \@input{ch21.aux} 25 | \@input{ch22.aux} 26 | \@input{ch23.aux} 27 | \@input{ch24.aux} 28 | \@input{ch25.aux} 29 | \@input{ch26.aux} 30 | -------------------------------------------------------------------------------- /Original Files/ch11.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {11}Clock Interrupts}{48}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.1}clock (3725)}{48}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {11.2}timeout (3845)}{49}} 5 | \global\@namedef{cp@ch11}{ 6 | \setcounter{page}{50} 7 | \setcounter{equation}{0} 8 | \setcounter{enumi}{0} 9 | \setcounter{enumii}{0} 10 | \setcounter{enumiii}{0} 11 | \setcounter{enumiv}{0} 12 | \setcounter{footnote}{0} 13 | \setcounter{mpfootnote}{0} 14 | \setcounter{part}{0} 15 | \setcounter{section}{11} 16 | \setcounter{subsection}{2} 17 | \setcounter{subsubsection}{0} 18 | \setcounter{paragraph}{0} 19 | \setcounter{subparagraph}{0} 20 | \setcounter{figure}{0} 21 | \setcounter{table}{0} 22 | } 23 | -------------------------------------------------------------------------------- /Original Files/ch21.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {21}Pipes}{87}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {21.1}pipe (7723)}{87}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {21.2}readp (7758)}{87}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {21.3}writep (7805)}{87}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {21.4}plock (7862)}{87}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {21.5}prele (7882)}{87}} 8 | \global\@namedef{cp@ch21}{ 9 | \setcounter{page}{88} 10 | \setcounter{equation}{0} 11 | \setcounter{enumi}{0} 12 | \setcounter{enumii}{0} 13 | \setcounter{enumiii}{0} 14 | \setcounter{enumiv}{0} 15 | \setcounter{footnote}{0} 16 | \setcounter{mpfootnote}{0} 17 | \setcounter{part}{0} 18 | \setcounter{section}{21} 19 | \setcounter{subsection}{5} 20 | \setcounter{subsubsection}{0} 21 | \setcounter{paragraph}{0} 22 | \setcounter{subparagraph}{0} 23 | \setcounter{figure}{0} 24 | \setcounter{table}{0} 25 | } 26 | -------------------------------------------------------------------------------- /Original Files/ch14.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {14}Program Swapping}{60}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {14.1}Text Segments}{60}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {14.2}sched (1940)}{60}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {14.3}xswap (4368)}{61}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {14.4}xalloc (4433)}{61}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {14.5}xfree (4398)}{62}} 8 | \global\@namedef{cp@ch14}{ 9 | \setcounter{page}{63} 10 | \setcounter{equation}{0} 11 | \setcounter{enumi}{0} 12 | \setcounter{enumii}{0} 13 | \setcounter{enumiii}{0} 14 | \setcounter{enumiv}{0} 15 | \setcounter{footnote}{0} 16 | \setcounter{mpfootnote}{0} 17 | \setcounter{part}{0} 18 | \setcounter{section}{14} 19 | \setcounter{subsection}{5} 20 | \setcounter{subsubsection}{0} 21 | \setcounter{paragraph}{0} 22 | \setcounter{subparagraph}{0} 23 | \setcounter{figure}{0} 24 | \setcounter{table}{0} 25 | } 26 | -------------------------------------------------------------------------------- /Original Files/ch26.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {26}Suggested Exercises}{106}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {26.1}Section One}{106}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {26.2}Section Two}{106}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {26.3}Section Three}{107}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {26.4}Section Four}{107}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {26.5}General}{107}} 8 | \global\@namedef{cp@ch26}{ 9 | \setcounter{page}{108} 10 | \setcounter{equation}{0} 11 | \setcounter{enumi}{0} 12 | \setcounter{enumii}{0} 13 | \setcounter{enumiii}{0} 14 | \setcounter{enumiv}{0} 15 | \setcounter{footnote}{0} 16 | \setcounter{mpfootnote}{0} 17 | \setcounter{part}{0} 18 | \setcounter{section}{26} 19 | \setcounter{subsection}{5} 20 | \setcounter{subsubsection}{0} 21 | \setcounter{paragraph}{0} 22 | \setcounter{subparagraph}{0} 23 | \setcounter{figure}{0} 24 | \setcounter{table}{0} 25 | } 26 | -------------------------------------------------------------------------------- /Original Files/ch16.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {16}The RK Disk Driver}{66}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.1}The file `rk.c'}{66}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.2}rkstrategy (5389)}{67}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.3}rkaddr (5420)}{67}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.4}devstart (5096)}{67}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.5}rkintr (5451)}{67}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {16.6}iodone (5018)}{67}} 9 | \global\@namedef{cp@ch16}{ 10 | \setcounter{page}{68} 11 | \setcounter{equation}{0} 12 | \setcounter{enumi}{0} 13 | \setcounter{enumii}{0} 14 | \setcounter{enumiii}{0} 15 | \setcounter{enumiv}{0} 16 | \setcounter{footnote}{0} 17 | \setcounter{mpfootnote}{0} 18 | \setcounter{part}{0} 19 | \setcounter{section}{16} 20 | \setcounter{subsection}{6} 21 | \setcounter{subsubsection}{0} 22 | \setcounter{paragraph}{0} 23 | \setcounter{subparagraph}{0} 24 | \setcounter{figure}{0} 25 | \setcounter{table}{0} 26 | } 27 | -------------------------------------------------------------------------------- /Original Files/ch10.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {10}The Assembler ``Trap'' Routine}{45}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.1}Sources of Traps and Interrupts}{45}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.2}fuibyte (0814), fuiword (0844)}{45}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.3}Interrupts}{46}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.4}call (0776)}{46}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.5}User Program Traps}{46}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {10.6}The Kernel Stack}{47}} 9 | \global\@namedef{cp@ch10}{ 10 | \setcounter{page}{48} 11 | \setcounter{equation}{0} 12 | \setcounter{enumi}{0} 13 | \setcounter{enumii}{0} 14 | \setcounter{enumiii}{0} 15 | \setcounter{enumiv}{0} 16 | \setcounter{footnote}{0} 17 | \setcounter{mpfootnote}{0} 18 | \setcounter{part}{0} 19 | \setcounter{section}{10} 20 | \setcounter{subsection}{6} 21 | \setcounter{subsubsection}{0} 22 | \setcounter{paragraph}{0} 23 | \setcounter{subparagraph}{0} 24 | \setcounter{figure}{0} 25 | \setcounter{table}{0} 26 | } 27 | -------------------------------------------------------------------------------- /Original Files/title.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file title.tex, version 1.3, 15 May 1994 3 | % 4 | \begin{center} 5 | {\Huge \bf A COMMENTARY ON THE\\ 6 | \medskip 7 | SIXTH EDITION \\ 8 | \bigskip 9 | \smallskip 10 | UNIX OPERATING SYSTEM } 11 | \end{center} 12 | 13 | \vspace{5cm} 14 | 15 | \begin{center} 16 | {\LARGE J. Lions. \\ 17 | Department of Computer Science \\ 18 | \medskip 19 | The University of New South Wales} 20 | \end{center} 21 | 22 | \vspace{8cm} 23 | 24 | \noindent This booklet has been produced for students at the 25 | University of New South Wales taking courses 6.602B and 6.657G. 26 | It is intended as a companion to, and commentary on, 27 | the booklet {\sl UNIX Operating System Source Code, Level Six}. 28 | 29 | \medskip 30 | \noindent The UNIX Software System was written by K. Thompson and 31 | D. Ritchie of Bell Laboratories, Murray Hill, NJ. It has been made 32 | available under a license from the Western Electric Company. 33 | 34 | \medskip 35 | \noindent This document may contain information covered by one or more 36 | licenses, copyrights and non-disclosure agreements. Circulation of 37 | this document is restricted to holders of a license for the UNIX 38 | Software System from Western Electric. All other circulation or 39 | reproduction is prohibited. 40 | 41 | \medskip 42 | \begin{center} 43 | \copyright~~Copyright 1977 J. Lions 44 | \end{center} 45 | -------------------------------------------------------------------------------- /Original Files/ch23.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {23}Character Handling}{92}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.1}cinit (8234)}{93}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.2}getc (0930)}{93}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.3}putc (0967)}{93}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.4}Character Sets}{94}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.5}Control Characters}{94}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.6}Graphic Characters}{94}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.7}Graphic Character Sets}{94}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.8}maptab (8117)}{95}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {23.9}partab (7947)}{95}} 12 | \global\@namedef{cp@ch23}{ 13 | \setcounter{page}{96} 14 | \setcounter{equation}{0} 15 | \setcounter{enumi}{0} 16 | \setcounter{enumii}{0} 17 | \setcounter{enumiii}{0} 18 | \setcounter{enumiv}{0} 19 | \setcounter{footnote}{0} 20 | \setcounter{mpfootnote}{0} 21 | \setcounter{part}{0} 22 | \setcounter{section}{23} 23 | \setcounter{subsection}{9} 24 | \setcounter{subsubsection}{0} 25 | \setcounter{paragraph}{0} 26 | \setcounter{subparagraph}{0} 27 | \setcounter{figure}{0} 28 | \setcounter{table}{0} 29 | } 30 | -------------------------------------------------------------------------------- /Original Files/ch9.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {9}Hardware Interrupts and Traps}{42}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.1}Hardware Interrupts}{42}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.2}The Interrupt Vector}{42}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.3}Interrupt Handlers}{42}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.4}Priorities}{43}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.5}Interrupt Priorities}{43}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.6}Rules for Interrupt Handlers}{43}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.7}Traps}{43}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.8}Assembly Language `trap'}{44}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {9.9}Return}{44}} 12 | \global\@namedef{cp@ch9}{ 13 | \setcounter{page}{45} 14 | \setcounter{equation}{0} 15 | \setcounter{enumi}{0} 16 | \setcounter{enumii}{0} 17 | \setcounter{enumiii}{0} 18 | \setcounter{enumiv}{0} 19 | \setcounter{footnote}{0} 20 | \setcounter{mpfootnote}{0} 21 | \setcounter{part}{0} 22 | \setcounter{section}{9} 23 | \setcounter{subsection}{9} 24 | \setcounter{subsubsection}{0} 25 | \setcounter{paragraph}{0} 26 | \setcounter{subparagraph}{0} 27 | \setcounter{figure}{0} 28 | \setcounter{table}{0} 29 | } 30 | -------------------------------------------------------------------------------- /Original Files/ch6.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {6}Getting Started}{28}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.1}Operator Actions}{28}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.2}start (0612)}{28}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.3}main (1550)}{29}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.4}Processes}{30}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.5}Initialisation of proc[0]}{30}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.6}The story continues ...}{30}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.7}sched (1940)}{31}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.8}sleep (2066)}{31}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.9}swtch (2178)}{31}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {6.10}main revisited}{32}} 13 | \global\@namedef{cp@ch6}{ 14 | \setcounter{page}{33} 15 | \setcounter{equation}{0} 16 | \setcounter{enumi}{0} 17 | \setcounter{enumii}{0} 18 | \setcounter{enumiii}{0} 19 | \setcounter{enumiv}{0} 20 | \setcounter{footnote}{0} 21 | \setcounter{mpfootnote}{0} 22 | \setcounter{part}{0} 23 | \setcounter{section}{6} 24 | \setcounter{subsection}{10} 25 | \setcounter{subsubsection}{0} 26 | \setcounter{paragraph}{0} 27 | \setcounter{subparagraph}{0} 28 | \setcounter{figure}{0} 29 | \setcounter{table}{0} 30 | } 31 | -------------------------------------------------------------------------------- /Original Files/ch15.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {15}Introduction to Basic I/O}{63}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.1}The File `buf.h'}{63}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.2}devtab (4551)}{63}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.3}The File `conf.h'}{63}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.4}The File `conf.c'}{63}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.5}System Generation}{63}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.6}swap (5196)}{63}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.7}Race Conditions}{64}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.8}Reentrancy}{65}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.9}For the Uninitiated}{65}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {15.10}Additional Reading}{65}} 13 | \global\@namedef{cp@ch15}{ 14 | \setcounter{page}{66} 15 | \setcounter{equation}{0} 16 | \setcounter{enumi}{0} 17 | \setcounter{enumii}{0} 18 | \setcounter{enumiii}{0} 19 | \setcounter{enumiv}{0} 20 | \setcounter{footnote}{0} 21 | \setcounter{mpfootnote}{0} 22 | \setcounter{part}{0} 23 | \setcounter{section}{15} 24 | \setcounter{subsection}{10} 25 | \setcounter{subsubsection}{0} 26 | \setcounter{paragraph}{0} 27 | \setcounter{subparagraph}{0} 28 | \setcounter{figure}{0} 29 | \setcounter{table}{0} 30 | } 31 | -------------------------------------------------------------------------------- /Original Files/ch19.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {19}File Directories and Directory Files}{77}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.1}The Directory Data Structure}{77}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.2}Directory Files}{77}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.3}namei (7518)}{77}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.4}Some Comments}{78}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.5}link (5909)}{79}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.6}wdir (7477)}{79}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.7}maknode (7455)}{79}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.8}unlink (3510)}{79}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.9}mknod (5952)}{80}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {19.10}access (6746)}{80}} 13 | \global\@namedef{cp@ch19}{ 14 | \setcounter{page}{81} 15 | \setcounter{equation}{0} 16 | \setcounter{enumi}{0} 17 | \setcounter{enumii}{0} 18 | \setcounter{enumiii}{0} 19 | \setcounter{enumiv}{0} 20 | \setcounter{footnote}{0} 21 | \setcounter{mpfootnote}{0} 22 | \setcounter{part}{0} 23 | \setcounter{section}{19} 24 | \setcounter{subsection}{10} 25 | \setcounter{subsubsection}{0} 26 | \setcounter{paragraph}{0} 27 | \setcounter{subparagraph}{0} 28 | \setcounter{figure}{0} 29 | \setcounter{table}{0} 30 | } 31 | -------------------------------------------------------------------------------- /Original Files/ch1.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {1}Introduction}{1}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.1}The UNIX Operating System}{1}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.2}Utilities}{1}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.3}Other Documentation}{1}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.4}UNIX Programmer's Manual}{1}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.5}UNIX Documents}{2}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.6}UNIX Operating System Source Code}{2}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.7}Source Code Selections}{3}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.8}Source Code Files}{3}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.9}Use of these notes}{3}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {1.10}A Note on Programming Standards}{3}} 13 | \global\@namedef{cp@ch1}{ 14 | \setcounter{page}{4} 15 | \setcounter{equation}{0} 16 | \setcounter{enumi}{0} 17 | \setcounter{enumii}{0} 18 | \setcounter{enumiii}{0} 19 | \setcounter{enumiv}{0} 20 | \setcounter{footnote}{0} 21 | \setcounter{mpfootnote}{0} 22 | \setcounter{part}{0} 23 | \setcounter{section}{1} 24 | \setcounter{subsection}{10} 25 | \setcounter{subsubsection}{0} 26 | \setcounter{paragraph}{0} 27 | \setcounter{subparagraph}{0} 28 | \setcounter{figure}{0} 29 | \setcounter{table}{0} 30 | } 31 | -------------------------------------------------------------------------------- /Original Files/fig23_3.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file fig23_3.tex, version 1.2, 15 May 1994 3 | % 4 | \vspace{0.6cm} 5 | \setlength{\unitlength}{0.0109in}% 6 | \begin{picture}(245,155)(40,525) 7 | \thicklines 8 | \put(185,540){\framebox(25,140){}} 9 | \put(195,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm g}}} 10 | \put(195,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm h}}} 11 | \put(195,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm i}}} 12 | \put(195,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm j}}} 13 | \put(195,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm k}}} 14 | \put(195,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm l}}} 15 | \put(240,540){\framebox(25,140){}} 16 | \put(250,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm n}}} 17 | \put(250,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm o}}} 18 | \put(250,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm p}}} 19 | \put(250,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm q}}} 20 | \put(250,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm r}}} 21 | \put(247,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm m}}} 22 | \put( 40,540){\framebox(60,60){}} 23 | \put(195,670){\vector( 1, 0){ 45}} 24 | \put( 90,550){\line( 0,-1){ 25}} 25 | \put( 90,525){\line( 1, 0){195}} 26 | \put(285,525){\line( 0, 1){ 25}} 27 | \put(285,550){\vector(-1, 0){ 20}} 28 | \put( 90,570){\line( 1, 0){ 50}} 29 | \put(140,570){\line( 0, 1){ 85}} 30 | \put(140,655){\vector( 1, 0){ 45}} 31 | \put( 49,564){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm head}}} 32 | \put( 49,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm tail}}} 33 | \put( 48,584){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm 12}}} 34 | \end{picture} 35 | \vspace{0.4cm} 36 | \begin{center} 37 | {\large \bf Figure 23.3} 38 | \end{center} 39 | \vspace{0.2cm} 40 | -------------------------------------------------------------------------------- /Original Files/ch4.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {4}An Overview}{18}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.1}Variable Allocation}{18}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.2}Global Variables}{18}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.3}The `C' Preprocessor}{18}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.4}Section One}{18}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.5}The First Group of `.h' Files}{19}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.6}Assembly Language Files}{19}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.7}Other Files in Section One}{19}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.8}Section Two}{19}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.9}Section Three}{20}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.10}Section Four}{20}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {4.11}Section Five}{21}} 14 | \global\@namedef{cp@ch4}{ 15 | \setcounter{page}{22} 16 | \setcounter{equation}{0} 17 | \setcounter{enumi}{0} 18 | \setcounter{enumii}{0} 19 | \setcounter{enumiii}{0} 20 | \setcounter{enumiv}{0} 21 | \setcounter{footnote}{0} 22 | \setcounter{mpfootnote}{0} 23 | \setcounter{part}{0} 24 | \setcounter{section}{4} 25 | \setcounter{subsection}{11} 26 | \setcounter{subsubsection}{0} 27 | \setcounter{paragraph}{0} 28 | \setcounter{subparagraph}{0} 29 | \setcounter{figure}{0} 30 | \setcounter{table}{0} 31 | } 32 | -------------------------------------------------------------------------------- /Original Files/ch12.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {12}Traps and System Calls}{50}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.1}trap (2693)}{50}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.2}Kernel Mode Traps}{50}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.3}User Mode Traps}{50}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.4}System Calls}{51}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.5}System Call Handlers}{52}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.6}The File `sysl.c'}{52}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.7}exec (3020)}{52}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.8}fork (3322)}{53}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.9}sbreak (3354)}{53}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.10}The Files `sys2.c' and `sys3.c'}{53}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {12.11}The File `sys4.c'}{53}} 14 | \global\@namedef{cp@ch12}{ 15 | \setcounter{page}{54} 16 | \setcounter{equation}{0} 17 | \setcounter{enumi}{0} 18 | \setcounter{enumii}{0} 19 | \setcounter{enumiii}{0} 20 | \setcounter{enumiv}{0} 21 | \setcounter{footnote}{0} 22 | \setcounter{mpfootnote}{0} 23 | \setcounter{part}{0} 24 | \setcounter{section}{12} 25 | \setcounter{subsection}{11} 26 | \setcounter{subsubsection}{0} 27 | \setcounter{paragraph}{0} 28 | \setcounter{subparagraph}{0} 29 | \setcounter{figure}{0} 30 | \setcounter{table}{0} 31 | } 32 | -------------------------------------------------------------------------------- /Original Files/ch22.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {22}Character Oriented Special Files}{88}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.1}LP11 Line Printer Driver}{88}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.2}lpopen (8850)}{88}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.3}Notes}{88}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.4}lpoutput (8986)}{89}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.5}lpstart (8967)}{89}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.6}lpinit(8976)}{89}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.7}lpwrite (8870)}{89}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.8}Discussion}{90}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.9}lpcanon (8879)}{90}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.10}For idle readers: A suggestion}{91}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {22.11}PC-11 Paper Tape Reader/Punch Driver}{91}} 14 | \global\@namedef{cp@ch22}{ 15 | \setcounter{page}{92} 16 | \setcounter{equation}{0} 17 | \setcounter{enumi}{0} 18 | \setcounter{enumii}{0} 19 | \setcounter{enumiii}{0} 20 | \setcounter{enumiv}{0} 21 | \setcounter{footnote}{0} 22 | \setcounter{mpfootnote}{0} 23 | \setcounter{part}{0} 24 | \setcounter{section}{22} 25 | \setcounter{subsection}{11} 26 | \setcounter{subsubsection}{0} 27 | \setcounter{paragraph}{0} 28 | \setcounter{subparagraph}{0} 29 | \setcounter{figure}{0} 30 | \setcounter{table}{0} 31 | } 32 | -------------------------------------------------------------------------------- /Original Files/fig23_2.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file fig23_2.tex, version 1.2, 15 May 1994 3 | % 4 | \vspace{0.6cm} 5 | \setlength{\unitlength}{0.0109in}% 6 | \begin{picture}(245,155)(40,525) 7 | \thicklines 8 | \put(185,540){\framebox(25,140){}} 9 | \put(195,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm g}}} 10 | \put(195,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm h}}} 11 | \put(195,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm i}}} 12 | \put(195,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm j}}} 13 | \put(195,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm k}}} 14 | \put(195,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm l}}} 15 | \put(240,540){\framebox(25,140){}} 16 | \put(250,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm n}}} 17 | \put(250,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm o}}} 18 | \put(250,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm p}}} 19 | \put(250,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm q}}} 20 | \put(250,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm r}}} 21 | \put(247,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm m}}} 22 | \put( 40,540){\framebox(60,60){}} 23 | \put( 90,570){\vector( 3,-1){ 40.500}} 24 | \put(130,540){\framebox(25,140){}} 25 | \put(140,670){\vector( 1, 0){ 45}} 26 | \put(195,670){\vector( 1, 0){ 45}} 27 | \put( 90,550){\line( 0,-1){ 25}} 28 | \put( 90,525){\line( 1, 0){195}} 29 | \put(285,525){\line( 0, 1){ 25}} 30 | \put(285,550){\vector(-1, 0){ 20}} 31 | \put( 49,564){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm head}}} 32 | \put( 49,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm tail}}} 33 | \put(140,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm f}}} 34 | \put( 48,584){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm 13}}} 35 | \end{picture} 36 | \vspace{0.4cm} 37 | \begin{center} 38 | {\large \bf Figure 23.2} 39 | \end{center} 40 | \vspace{0.2cm} 41 | -------------------------------------------------------------------------------- /Original Files/ch5.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {5}Two Files}{22}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.1}The File `malloc.c'}{22}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.2}Rules for List Maintenance}{22}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.3}malloc (2528)}{23}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.4}mfree (2556)}{23}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.5}In conclusion ...}{24}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.6}The File `prf.c'}{24}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.7}printf (2340)}{24}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.8}printn (2369)}{25}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.9}putchar (2386)}{25}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.10}panic (2419)}{26}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.11}prdev (2433), deverror (2447)}{26}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {5.12}Included Files}{26}} 15 | \global\@namedef{cp@ch5}{ 16 | \setcounter{page}{28} 17 | \setcounter{equation}{0} 18 | \setcounter{enumi}{0} 19 | \setcounter{enumii}{0} 20 | \setcounter{enumiii}{0} 21 | \setcounter{enumiv}{0} 22 | \setcounter{footnote}{0} 23 | \setcounter{mpfootnote}{0} 24 | \setcounter{part}{0} 25 | \setcounter{section}{5} 26 | \setcounter{subsection}{12} 27 | \setcounter{subsubsection}{0} 28 | \setcounter{paragraph}{0} 29 | \setcounter{subparagraph}{0} 30 | \setcounter{figure}{0} 31 | \setcounter{table}{0} 32 | } 33 | -------------------------------------------------------------------------------- /Original Files/fig23_1.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file fig23_1.tex, version 1.2, 15 May 1994 3 | % 4 | \vspace{0.6cm} 5 | \setlength{\unitlength}{0.0109in}% 6 | \begin{picture}(245,155)(40,525) 7 | \thicklines 8 | \put(185,540){\framebox(25,140){}} 9 | \put(195,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm g}}} 10 | \put(195,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm h}}} 11 | \put(195,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm i}}} 12 | \put(195,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm j}}} 13 | \put(195,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm k}}} 14 | \put(195,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm l}}} 15 | \put(240,540){\framebox(25,140){}} 16 | \put(250,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm n}}} 17 | \put(250,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm o}}} 18 | \put(250,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm p}}} 19 | \put(250,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm q}}} 20 | \put(250,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm r}}} 21 | \put(247,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm m}}} 22 | \put( 40,540){\framebox(60,60){}} 23 | \put( 90,570){\vector( 1, 0){ 40}} 24 | \put(130,540){\framebox(25,140){}} 25 | \put(140,670){\vector( 1, 0){ 45}} 26 | \put(195,670){\vector( 1, 0){ 45}} 27 | \put( 90,550){\line( 0,-1){ 25}} 28 | \put( 90,525){\line( 1, 0){195}} 29 | \put(285,525){\line( 0, 1){ 25}} 30 | \put(285,550){\vector(-1, 0){ 20}} 31 | \put( 48,584){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm 14}}} 32 | \put( 49,564){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm head}}} 33 | \put( 49,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm tail}}} 34 | \put(140,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm e}}} 35 | \put(140,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm f}}} 36 | \end{picture} 37 | \vspace{0.4cm} 38 | \begin{center} 39 | {\large \bf Figure 23.1} 40 | \end{center} 41 | \vspace{0.2cm} 42 | -------------------------------------------------------------------------------- /Original Files/fig23_4.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file fig23_4.tex, version 1.2, 15 May 1994 3 | % 4 | \vspace{0.6cm} 5 | \setlength{\unitlength}{0.0109in}% 6 | \begin{picture}(305,155)(60,525) 7 | \thicklines 8 | \put(185,540){\framebox(25,140){}} 9 | \put(195,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm g}}} 10 | \put(195,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm h}}} 11 | \put(195,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm i}}} 12 | \put(195,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm j}}} 13 | \put(195,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm k}}} 14 | \put(195,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm l}}} 15 | \put(240,540){\framebox(25,140){}} 16 | \put(250,629){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm n}}} 17 | \put(250,608){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm o}}} 18 | \put(250,587){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm p}}} 19 | \put(250,566){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm q}}} 20 | \put(250,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm r}}} 21 | \put(247,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm m}}} 22 | \put( 40,540){\framebox(60,60){}} 23 | \put(195,670){\vector( 1, 0){ 45}} 24 | \put( 90,570){\line( 1, 0){ 50}} 25 | \put(140,570){\line( 0, 1){ 85}} 26 | \put(140,655){\vector( 1, 0){ 45}} 27 | \put(295,540){\framebox(25,140){}} 28 | \put(250,670){\vector( 1, 0){ 45}} 29 | \put( 90,550){\line( 0,-1){ 25}} 30 | \put( 90,525){\line( 1, 0){255}} 31 | \put(345,525){\line( 0, 1){130}} 32 | \put(345,655){\vector(-1, 0){ 25}} 33 | \put( 49,564){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm head}}} 34 | \put( 49,545){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm tail}}} 35 | \put(305,650){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm s}}} 36 | \put( 48,584){\makebox(0,0)[lb]{\raisebox{0pt}[0pt][0pt]{\twlrm 13}}} 37 | \end{picture} 38 | \vspace{0.4cm} 39 | \begin{center} 40 | {\large \bf Figure 23.4} 41 | \end{center} 42 | \vspace{0.2cm} 43 | -------------------------------------------------------------------------------- /Original Files/ch7.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {7}Processes}{33}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.1}The Process}{33}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.2}The proc Structure (0358)}{33}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.3}The user Structure (0413)}{34}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.4}The Per Process Data Area}{34}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.5}The Segments}{34}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.6}Execution of an Image}{35}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.7}Kernel Mode Execution}{35}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.8}User Mode Execution}{35}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.9}An Example}{35}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.10}Setting the Segmentation Registers}{36}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.11}estabur (1650)}{36}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.12}sureg (1739)}{36}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {7.13}newproc (1826)}{37}} 16 | \global\@namedef{cp@ch7}{ 17 | \setcounter{page}{38} 18 | \setcounter{equation}{0} 19 | \setcounter{enumi}{0} 20 | \setcounter{enumii}{0} 21 | \setcounter{enumiii}{0} 22 | \setcounter{enumiv}{0} 23 | \setcounter{footnote}{0} 24 | \setcounter{mpfootnote}{0} 25 | \setcounter{part}{0} 26 | \setcounter{section}{7} 27 | \setcounter{subsection}{13} 28 | \setcounter{subsubsection}{0} 29 | \setcounter{paragraph}{0} 30 | \setcounter{subparagraph}{0} 31 | \setcounter{figure}{0} 32 | \setcounter{table}{0} 33 | } 34 | -------------------------------------------------------------------------------- /Original Files/ch17.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {17}Buffer Manipulation}{68}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.1}Flags}{68}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.2}A Cache-like Memory}{68}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.3}clrbuf (5038)}{68}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.4}incore (4899)}{68}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.5}getblk (4921)}{68}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.6}brelse (4869)}{69}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.7}binit (5055)}{69}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.8}bread (4754)}{69}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.9}breada (4773)}{70}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.10}bwrite (4809)}{70}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.11}bawrite (4856)}{70}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.12}bdwrite (4836)}{70}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.13}bflush (5229)}{70}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {17.14}physio (5259)}{70}} 17 | \global\@namedef{cp@ch17}{ 18 | \setcounter{page}{71} 19 | \setcounter{equation}{0} 20 | \setcounter{enumi}{0} 21 | \setcounter{enumii}{0} 22 | \setcounter{enumiii}{0} 23 | \setcounter{enumiv}{0} 24 | \setcounter{footnote}{0} 25 | \setcounter{mpfootnote}{0} 26 | \setcounter{part}{0} 27 | \setcounter{section}{17} 28 | \setcounter{subsection}{14} 29 | \setcounter{subsubsection}{0} 30 | \setcounter{paragraph}{0} 31 | \setcounter{subparagraph}{0} 32 | \setcounter{figure}{0} 33 | \setcounter{table}{0} 34 | } 35 | -------------------------------------------------------------------------------- /Original Files/ch2.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {2}Fundamentals}{4}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.1}The Processor}{4}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.2}Processor Status Word}{4}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.3}General Registers}{4}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.4}Instruction Set}{4}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.5}Addressing Modes}{6}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.6}Unix Assembler}{7}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.7}Memory Management}{7}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.8}Segmentation Registers.}{7}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.9}Page Description Register}{8}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.10}Memory Allocation}{8}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.11}Memory Management Status Registers}{8}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.12}``i'' and ``d'' Spaces}{8}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.13}Initial Conditions}{8}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {2.14}Special Device Registers}{8}} 17 | \global\@namedef{cp@ch2}{ 18 | \setcounter{page}{10} 19 | \setcounter{equation}{0} 20 | \setcounter{enumi}{0} 21 | \setcounter{enumii}{0} 22 | \setcounter{enumiii}{0} 23 | \setcounter{enumiv}{0} 24 | \setcounter{footnote}{0} 25 | \setcounter{mpfootnote}{0} 26 | \setcounter{part}{0} 27 | \setcounter{section}{2} 28 | \setcounter{subsection}{14} 29 | \setcounter{subsubsection}{0} 30 | \setcounter{paragraph}{0} 31 | \setcounter{subparagraph}{0} 32 | \setcounter{figure}{0} 33 | \setcounter{table}{0} 34 | } 35 | -------------------------------------------------------------------------------- /Original Files/ch8.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {8}Process Management}{38}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.1}Process Switching}{38}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.2}Interrupts}{38}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.3}Program Swapping}{38}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.4}Jobs}{38}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.5}Assembler Procedures}{38}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.6}savu (0725)}{38}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.7}retu (0740)}{39}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.8}aretu (0734)}{39}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.9}swtch (2178)}{39}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.10}setpri (2156)}{39}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.11}sleep (2066)}{40}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.12}wakeup (2113)}{40}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.13}setrun (2134)}{40}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.14}expand (2268)}{40}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.15}swtch revisited}{41}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {8.16}Critical Sections}{41}} 19 | \global\@namedef{cp@ch8}{ 20 | \setcounter{page}{42} 21 | \setcounter{equation}{0} 22 | \setcounter{enumi}{0} 23 | \setcounter{enumii}{0} 24 | \setcounter{enumiii}{0} 25 | \setcounter{enumiv}{0} 26 | \setcounter{footnote}{0} 27 | \setcounter{mpfootnote}{0} 28 | \setcounter{part}{0} 29 | \setcounter{section}{8} 30 | \setcounter{subsection}{16} 31 | \setcounter{subsubsection}{0} 32 | \setcounter{paragraph}{0} 33 | \setcounter{subparagraph}{0} 34 | \setcounter{figure}{0} 35 | \setcounter{table}{0} 36 | } 37 | -------------------------------------------------------------------------------- /Original Files/ch25.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {25}The File ``tty.c''}{101}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.1}flushtty (8252)}{101}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.2}wflushtty (8217)}{101}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.3}Character Input}{101}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.4}ttread (8535)}{101}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.5}canon (8274)}{101}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.6}Notes}{102}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.7}ttyinput (8333)}{102}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.8}Character Output -- ttwrite (8550)}{103}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.9}ttstart}{103}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.10}ttrstrt (8486)}{103}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.11}ttyoutput (8373)}{103}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.12}Terminals with a restricted character set}{103}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.13}A. The test for 'TTLOWAT' (Line 8074)}{104}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.14}B. Inactive Terminals}{104}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {25.15}Well, that's all, folks ...}{105}} 18 | \global\@namedef{cp@ch25}{ 19 | \setcounter{page}{106} 20 | \setcounter{equation}{0} 21 | \setcounter{enumi}{0} 22 | \setcounter{enumii}{0} 23 | \setcounter{enumiii}{0} 24 | \setcounter{enumiv}{0} 25 | \setcounter{footnote}{0} 26 | \setcounter{mpfootnote}{0} 27 | \setcounter{part}{0} 28 | \setcounter{section}{25} 29 | \setcounter{subsection}{15} 30 | \setcounter{subsubsection}{0} 31 | \setcounter{paragraph}{0} 32 | \setcounter{subparagraph}{0} 33 | \setcounter{figure}{0} 34 | \setcounter{table}{0} 35 | } 36 | -------------------------------------------------------------------------------- /Original Files/ch20.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {20}File Systems}{81}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.1}The `Super Block' (5561)}{81}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.2}The 'mount' table (0272)}{81}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.3}iinit (6922)}{81}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.4}Mounting}{82}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.5}smount (6086)}{82}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.6}Notes}{82}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.7}iget (7276)}{82}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.8}getfs (7167)}{83}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.9}update (7201)}{83}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.10}sumount (6144)}{84}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.11}Resource Allocation}{84}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.12}alloc (6965)}{84}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.13}itrunc (7414)}{84}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.14}free (7000)}{85}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.15}iput (7344)}{85}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.16}ifree (7134)}{85}} 19 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {20.17}iupdat (7374)}{85}} 20 | \global\@namedef{cp@ch20}{ 21 | \setcounter{page}{87} 22 | \setcounter{equation}{0} 23 | \setcounter{enumi}{0} 24 | \setcounter{enumii}{0} 25 | \setcounter{enumiii}{0} 26 | \setcounter{enumiv}{0} 27 | \setcounter{footnote}{0} 28 | \setcounter{mpfootnote}{0} 29 | \setcounter{part}{0} 30 | \setcounter{section}{20} 31 | \setcounter{subsection}{17} 32 | \setcounter{subsubsection}{0} 33 | \setcounter{paragraph}{0} 34 | \setcounter{subparagraph}{0} 35 | \setcounter{figure}{0} 36 | \setcounter{table}{0} 37 | } 38 | -------------------------------------------------------------------------------- /Original Files/ch3.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {3}Reading ``C'' Programs}{10}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.1}Some Selected Examples}{10}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.2}Example 1}{10}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.3}Example 2}{10}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.4}Example 3}{10}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.5}Example 4}{11}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.6}Example 5}{12}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.7}Example 6}{13}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.8}Example 7}{13}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.9}Example 8}{13}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.10}Example 9}{14}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.11}Example 10}{14}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.12}Example 11}{14}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.13}Example 12}{15}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.14}Example 13}{15}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.15}Example 14}{15}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.16}Example 15}{15}} 19 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.17}Example 16}{16}} 20 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {3.18}Example 17}{16}} 21 | \global\@namedef{cp@ch3}{ 22 | \setcounter{page}{18} 23 | \setcounter{equation}{0} 24 | \setcounter{enumi}{0} 25 | \setcounter{enumii}{0} 26 | \setcounter{enumiii}{0} 27 | \setcounter{enumiv}{0} 28 | \setcounter{footnote}{0} 29 | \setcounter{mpfootnote}{0} 30 | \setcounter{part}{0} 31 | \setcounter{section}{3} 32 | \setcounter{subsection}{18} 33 | \setcounter{subsubsection}{0} 34 | \setcounter{paragraph}{0} 35 | \setcounter{subparagraph}{0} 36 | \setcounter{figure}{0} 37 | \setcounter{table}{0} 38 | } 39 | -------------------------------------------------------------------------------- /Original Files/ch24.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {24}Interactive Terminals}{96}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.1}The 'tty' Structure (7926)}{96}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.2} Interactive Terminals}{96}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.3}Initialisation}{97}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.4}stty (8183)}{97}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.5}sgtty (8201)}{97}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.6}klsgtty (8090)}{97}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.7}tysty (8577)}{97}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.8}The DL11/KL11 Terminal Device Handler}{97}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.9}Device Registers}{98}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.10}UNIBUS Addresses}{98}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.11}Software Considerations}{98}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.12}Interrupt Vector Addresses}{98}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.13}Source Code}{98}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.14}klopen (8023)}{99}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.15}klclose (8055)}{99}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.16}klxint (8070)}{99}} 19 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {24.17}klrint (8078)}{99}} 20 | \global\@namedef{cp@ch24}{ 21 | \setcounter{page}{101} 22 | \setcounter{equation}{0} 23 | \setcounter{enumi}{0} 24 | \setcounter{enumii}{0} 25 | \setcounter{enumiii}{0} 26 | \setcounter{enumiv}{0} 27 | \setcounter{footnote}{0} 28 | \setcounter{mpfootnote}{0} 29 | \setcounter{part}{0} 30 | \setcounter{section}{24} 31 | \setcounter{subsection}{17} 32 | \setcounter{subsubsection}{0} 33 | \setcounter{paragraph}{0} 34 | \setcounter{subparagraph}{0} 35 | \setcounter{figure}{0} 36 | \setcounter{table}{0} 37 | } 38 | -------------------------------------------------------------------------------- /Original Files/lionc.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file lionc.tex, version 1.3, 18 May 1994 3 | % 4 | \documentstyle[twoside,fancyheadings]{article} 5 | \font\twlrm = cmr10 scaled \magstep1 6 | 7 | % Set the page dimensions 8 | 9 | \setlength{\textwidth}{16.6cm} 10 | \setlength{\oddsidemargin}{-0.25cm} 11 | \setlength{\evensidemargin}{-0.25cm} 12 | \setlength{\textheight}{24.1cm} 13 | \setlength{\topmargin}{-1.3cm} 14 | \setlength{\columnsep}{1cm} 15 | 16 | % Shut LaTeX up about overful hboxes 17 | 18 | \tolerance=1000 19 | \hfuzz=15pt 20 | 21 | \begin{document} 22 | 23 | % I don't feel like typing much.... 24 | 25 | \newcommand{\bc}{\begin{center}} 26 | \newcommand{\ec}{\end{center}} 27 | \newcommand{\bd}{\begin{description}} 28 | \newcommand{\ed}{\end{description}} 29 | \newcommand{\be}{\begin{enumerate}} 30 | \newcommand{\ee}{\end{enumerate}} 31 | \newcommand{\bi}{\begin{itemize}} 32 | \newcommand{\ei}{\end{itemize}} 33 | \newcommand{\bt}{\begin{tabbing}} 34 | \newcommand{\et}{\end{tabbing}} 35 | \newcommand{\se}[1]{\section{#1}} 36 | \newcommand{\sbs}[1]{\subsection{#1}} 37 | \newcommand{\ssb}[1]{\subsubsection{#1}} 38 | 39 | % Set up the headings for the document 40 | 41 | \setlength{\headrulewidth}{0cm} 42 | \renewcommand{\sectionmark}[1]{\markboth{#1}{}} 43 | \renewcommand{\subsectionmark}[1]{\markright{#1}} 44 | \rhead[{\it UNIX 6th Edition Commentary}]{\it \leftmark} 45 | \lhead[{\it \leftmark}]{\it UNIX 6th Edition Commentary} 46 | \chead{} 47 | \lfoot[{\thepage}]{} 48 | \cfoot{} 49 | \rfoot[]{\thepage} 50 | 51 | % Give the title page 52 | 53 | \pagestyle{empty} 54 | \include{title} 55 | 56 | \cleardoublepage % Blank page for two-up printing 57 | 58 | \pagestyle{fancy} 59 | \twocolumn 60 | \pagenumbering{roman} 61 | 62 | % Now the table of contents 63 | 64 | \tableofcontents 65 | \cleardoublepage % Blank page for two-up printing 66 | 67 | % And the preface 68 | 69 | \include{preface} 70 | \cleardoublepage % Blank page for two-up printing 71 | \pagenumbering{arabic} 72 | \setcounter{section}{0} 73 | 74 | % Then do the chapters 75 | 76 | \include{ch1} 77 | \include{ch2} 78 | \include{ch3} 79 | \include{ch4} 80 | \include{ch5} 81 | \include{ch6} 82 | \include{ch7} 83 | \include{ch8} 84 | \include{ch9} 85 | \include{ch10} 86 | \include{ch11} 87 | \include{ch12} 88 | \include{ch13} 89 | \include{ch14} 90 | \include{ch15} 91 | \include{ch16} 92 | \include{ch17} 93 | \include{ch18} 94 | \include{ch19} 95 | \include{ch20} 96 | \include{ch21} 97 | \include{ch22} 98 | \include{ch23} 99 | \include{ch24} 100 | \include{ch25} 101 | \include{ch26} 102 | \end{document} 103 | -------------------------------------------------------------------------------- /Original Files/ch18.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {18}File Access and Control}{71}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.1}File Characteristics}{71}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.2}System Calls}{71}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.3}Control Tables}{71}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.4}file (5507)}{71}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.5}inode (5659)}{72}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.6}Resources Required}{72}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.7}Opening a File}{72}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.8}creat (5781)}{72}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.9}openl (5804)}{72}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.10}open (5763)}{73}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.11}openl revisited}{73}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.12}close (5846)}{73}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.13}closef (6643)}{73}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.14}iput (7344)}{73}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.15}Deletion of Files}{73}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.16}Reading and Writing}{74}} 19 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.17}rdwr (5731)}{74}} 20 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.18}readi (6221)}{75}} 21 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.19}writei}{75}} 22 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.20}iomove (6364)}{75}} 23 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.21}bmap (6415)}{75}} 24 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {18.22}Leftovers}{76}} 25 | \global\@namedef{cp@ch18}{ 26 | \setcounter{page}{77} 27 | \setcounter{equation}{0} 28 | \setcounter{enumi}{0} 29 | \setcounter{enumii}{0} 30 | \setcounter{enumiii}{0} 31 | \setcounter{enumiv}{0} 32 | \setcounter{footnote}{0} 33 | \setcounter{mpfootnote}{0} 34 | \setcounter{part}{0} 35 | \setcounter{section}{18} 36 | \setcounter{subsection}{22} 37 | \setcounter{subsubsection}{0} 38 | \setcounter{paragraph}{0} 39 | \setcounter{subparagraph}{0} 40 | \setcounter{figure}{0} 41 | \setcounter{table}{0} 42 | } 43 | -------------------------------------------------------------------------------- /Original Files/ch13.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \@writefile{toc}{\string\contentsline\space {section}{\string\numberline\space {13}Software Interrupts}{54}} 3 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.1}Anticipation}{54}} 4 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.2}Causation}{54}} 5 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.3}Effect}{54}} 6 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.4}Tracing}{54}} 7 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.5}Procedures}{54}} 8 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.6}A. Anticipation}{55}} 9 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.7}B. Causation}{55}} 10 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.8}C. Effect}{55}} 11 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.9}D. Tracing}{55}} 12 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.10}ssig (3614)}{55}} 13 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.11}kill (3630)}{55}} 14 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.12}signal (3949)}{55}} 15 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.13}psignal (3963)}{55}} 16 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.14}issig (3991)}{56}} 17 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.15}psig (4043)}{56}} 18 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.16}core (4094)}{56}} 19 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.17}grow (4136)}{56}} 20 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.18}exit (3219)}{57}} 21 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.19}rexit (3205)}{57}} 22 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.20}wait (3270)}{57}} 23 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.21}Tracing}{57}} 24 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.22}stop (4016)}{58}} 25 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.23}wait (3270) (continued)}{58}} 26 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.24}ptrace (4164)}{58}} 27 | \@writefile{toc}{\string\contentsline\space {subsection}{\string\numberline\space {13.25}procxmt (4204)}{59}} 28 | \global\@namedef{cp@ch13}{ 29 | \setcounter{page}{60} 30 | \setcounter{equation}{0} 31 | \setcounter{enumi}{0} 32 | \setcounter{enumii}{0} 33 | \setcounter{enumiii}{0} 34 | \setcounter{enumiv}{0} 35 | \setcounter{footnote}{0} 36 | \setcounter{mpfootnote}{0} 37 | \setcounter{part}{0} 38 | \setcounter{section}{13} 39 | \setcounter{subsection}{25} 40 | \setcounter{subsubsection}{0} 41 | \setcounter{paragraph}{0} 42 | \setcounter{subparagraph}{0} 43 | \setcounter{figure}{0} 44 | \setcounter{table}{0} 45 | } 46 | -------------------------------------------------------------------------------- /Original Files/ch21.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch21.tex, version 1.3, 15 May 1994 3 | % 4 | \se{Pipes} 5 | 6 | A ``pipe'' is a FIFO character list, 7 | which is managed by UNIX as yet another 8 | variety of file. 9 | 10 | 11 | One group of processes may ``write'' into 12 | a ``pipe'' and another group may ``read'' 13 | from the same ``pipe''. Hence ``pipe''s may 14 | be, and are used, primarily for interprocess communication. 15 | 16 | By exploiting the concept of a 17 | ``filter'', which is a program which 18 | reads an input file and transforms it 19 | into an output file, and by using 20 | ``pipes'' to link two or more programs of 21 | this type together, UNIX offers its 22 | users a surprisingly comprehensive and 23 | sophisticated set of facilities. 24 | 25 | 26 | \sbs{pipe (7723)} 27 | 28 | A ``pipe'' is created as a result of a 29 | system call on the ``pipe'' procedure. 30 | 31 | \bd 32 | \item[7728:] Allocate an ``inode'' for the root device; 33 | 34 | \item[7731:] Allocate a ``file'' table entry; 35 | 36 | \item[7736:] Remember the ``file'' table entry 37 | as ``r'' and allocate a second 38 | ``file'' table entry; 39 | 40 | \item[7744:] Return user file identifications 41 | in R0 and R1; 42 | 43 | \item[7746:] Complete the entries in the 44 | ``file'' array and the ``inode'' 45 | entry. 46 | \ed 47 | 48 | 49 | \sbs{readp (7758)} 50 | 51 | ``pipes'' are different from other files 52 | in that two separate offsets into the 53 | file are kept -- one for ``read'' operations 54 | and one for ``write'' operations. 55 | The ``write'' offset is actually the same 56 | as the file size. 57 | 58 | \bd 59 | \item[7763:] the parameter passed to ``readp'' 60 | is a pointer to a ``file'' array 61 | entry, from which an ``inode'' 62 | pointer can be extracted; 63 | 64 | \item[7768:] ``plock'' (7862) ensures that only 65 | one operation takes place at a 66 | time: either ``read'' or ``write''; 67 | 68 | \item[7776:] If a process wishing to write to 69 | a ``pipe'' has been blocked because 70 | the pipe was ``full'' (or rather 71 | because the valid part of the 72 | file had reached the file limit), 73 | it will have signified its predicament by setting the ``IWRITE'' 74 | flag in ``ip-$>$i\_mode''; 75 | 76 | \item[7786:] Release the lock before going to 77 | sleep; 78 | 79 | \item[7787:] ``i\_count'' is the number of file 80 | table entries pointing at the 81 | ``inode''. If this is less than 82 | two, then the group of ``writers'' 83 | must be extinct; 84 | 85 | \item[7789:] A process waiting for input will 86 | raise the ``IREAD'' flag. Since a 87 | pipe cannot be full and empty 88 | simultaneously, no more than one 89 | of the flaqs ``IWRITE'' or ``IREAD'' 90 | should be set at any one time; 91 | 92 | \item[7799:] ``prele'' unlocks the file and 93 | ``wakes up'' any process waiting 94 | for the pipe. 95 | \ed 96 | 97 | \sbs{writep (7805)} 98 | 99 | The structure of this procedure echoes 100 | that of ``readp'' in many respects. 101 | 102 | \bd 103 | \item[7828:] Note that a ``writer'', which finds 104 | that there are no more ``readers'' 105 | left, receives a ``signal'' just in 106 | case he is not monitoring the 107 | result of his ``write'' operation. 108 | 109 | (A ``reader'' in the analogous 110 | situation receives a zero character count as the result of the 111 | read, and this is the standard 112 | end-of-file indication.) 113 | 114 | \item[7835:] The ``pipe'' size is not allowed to 115 | grow beyond ``PIPSIZ'' characters. 116 | As long as ``PIPSIZ'' (7715) is no 117 | greater than 4096, the file will 118 | not be converted to a ``large'' 119 | file. This is highly desirable 120 | from the viewpoint of access 121 | efficiency. 122 | 123 | (Note that ``PIPSIZ'' limits the 124 | ``write'' offset pointer value. If 125 | the ``read'' offset pointer is not 126 | far behind, the true content of 127 | the ``pipe'' may be quite small). 128 | \ed 129 | 130 | 131 | 132 | \sbs{plock (7862)} 133 | 134 | Lock the ``inode'' after waiting if 135 | necessary. This procedure is called by 136 | ``readp'' (7768) and ``writep'' (7815). 137 | 138 | 139 | \sbs{prele (7882)} 140 | 141 | Unlock the ``inode'' and ``wake'' 142 | any waiting processes. This procedure is called 143 | by several others (especially ``iput''), 144 | in addition to ``readp'' and ``writep''. 145 | -------------------------------------------------------------------------------- /Original Files/ch16.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch16.tex, version 1.3, 16 May 1994 3 | % 4 | \se{The RK Disk Driver} 5 | 6 | The RK disk storage system employs a 7 | removable disk cartridge containing a 8 | single disk, which is mounted inside a 9 | drive with moving read/write heads. 10 | 11 | The device designated RK11-D consists 12 | of a disk controller together with a 13 | single drive. Additional drives, designated RK05, up to a total of seven, may 14 | be added to a single RK11-D. 15 | 16 | A requirement for more than eight 17 | drives would require an additional controller with a different set of UNIBUS 18 | addresses. Also the code in the file 19 | ``rk.c'' would have to be modified to 20 | handle the case of two or more controllers. This case is most unlikely 21 | because requirements for large amounts 22 | of on-line disk storage will be more 23 | economically provided otherwise e.g. 24 | by the RP04 disk system. 25 | 26 | 27 | \begin{center} 28 | \begin{tabbing} 29 | Cartridge \= capacity: \= 1,228,800 words\\ 30 | \> (4800 512 byte records)\\ 31 | Surfaces/cartridge: \> \> 2\\ 32 | Tracks/surface: \> \>200 (plus 3 spare)\\ 33 | Sectors/Track: \> \> 12\\ 34 | Words/Sector: \> \> 256\\ 35 | Recording density: \> \> 2040 bpi maximum\\ 36 | Rotation speed: \> \> 1500 rpm\\ 37 | Half revolution: \> \> 20 msecs\\ 38 | Track positioning:\\ 39 | \> 10 msecs (one track)\\ 40 | \> 50 msecs (average)\\ 41 | \> 85 msecs (worst case)\\ 42 | Interrupt Vector Address: 220\\ 43 | Priority Level: \> \> 5\\ 44 | \end{tabbing} 45 | \end{center} 46 | 47 | \begin{tabular}{lll} 48 | \multicolumn{3}{c}{\bf Unibus Register Addresses}\\ 49 | Drive Status & RKDS & 777400 \\ 50 | Error & RKER & 777402 \\ 51 | Control Status & RKCS & 777404 \\ 52 | Word Count & RKWC & 777406 \\ 53 | Current bus address & RKBA & 777410 \\ 54 | Disk address & RKDA & 777412 \\ 55 | Data Buffer & RKDB & 777416 \\ 56 | \end{tabular} 57 | 58 | \begin{center} 59 | Table 16.1 RK Vital Statistics 60 | \end{center} 61 | 62 | The average total access time is 70 63 | milllseconds. With multi-drive subsystems, 64 | seeking by one drive may be overlapped with reading or writing by 65 | another drive. However this feature is 66 | not used by UNIX because of bugs which 67 | existed at one time in the hardware 68 | controller. 69 | 70 | 71 | In initiating a data transfer, RKDA, 72 | RRBA and RKC are set, and then RKCS is 73 | set. Upon completion, status information is available in RKCS, RRER and 74 | RKDS. When an error occurs, UNIX simply 75 | calls ``deverror'' (2447) to display RKER 76 | and RKDS on the system console, without 77 | any attempt at analysis. An operation 78 | is repeated up to ten times before an 79 | error is reported by the device driver. 80 | 81 | 82 | The register formats which are 83 | described fully in the ``PDP11 Peripherals Handbook'' are reflected in the 84 | program code at several points. The 85 | following summaries suffice to describe 86 | the features used by UNIX: 87 | 88 | \begin{tabular}{ll} 89 | \multicolumn{2}{c}{\bf Control Status Register (RKCS)}\\ \hline 90 | \multicolumn{1}{c}{bit} & \multicolumn{1}{c}{description} 91 | \\ 92 | 15 & Set when any bit of RKER (the\\ 93 | & Error Register) is set;\\ 94 | \\ 95 | 7 & Set when the control is no\\ 96 | & longer engaged in actively\\ 97 | & executing a function and is ready\\ 98 | & to accept a command;\\ 99 | \\ 100 | 6 & When set, the control will issue\\ 101 | & an interrupt to vector address\\ 102 | & 220 upon operation completion or\\ 103 | & error;\\ 104 | \\ 105 | 5--4 & Memory Extension. The two most\\ 106 | & significant bits of the 13 bit\\ 107 | & physical bus address. (The other\\ 108 | & 16 bits are recorded in RKBA.);\\ 109 | \\ 110 | 3--1 & Function to be performed:\\ 111 | \\ 112 | & CONTROL RESET: 000\\ 113 | & WRITE: 001\\ 114 | & READ: 010\\ 115 | & etc.,\\ 116 | \\ 117 | 0 & Initiate the function designated\\ 118 | & by bits 1 to 3 when set. (write\\ 119 | & only);\\ 120 | \\ 121 | \multicolumn{2}{c}{\bf Word Count Register (RKWC)}\\ \hline 122 | \end{tabular} 123 | 124 | Contains the twos complement of the 125 | number of words to be transferred. 126 | 127 | \bigskip 128 | 129 | \begin{tabular}{ll} 130 | \multicolumn{2}{c}{\bf Disk Address Register (RKDA)}\\ \hline 131 | \multicolumn{1}{c}{bit} & \multicolumn{1}{c}{description} 132 | \\ 133 | 15--13 & Drive number (0 to 7)\\ 134 | 12--5 & Cylinder number (0 to 199)\\ 135 | 4 & Surface number (0,1)\\ 136 | 3-0 & Sector address (0 to 11)\\ 137 | \end{tabular} 138 | 139 | 140 | \sbs{The file `rk.c'} 141 | 142 | This file contains the code which is 143 | specific to the RK disk system, i.e. 144 | which is the RK ``device driver''. 145 | 146 | 147 | \sbs{rkstrategy (5389)} 148 | 149 | The strategy routine is called, e.g. 150 | from ``swap'' (5212), to handle both read 151 | and write requests. 152 | 153 | \bd 154 | \item[5397:] The test and call on ``mapalloc'' 155 | here is a ``no-op'' except on the 156 | PDP11/70 system; 157 | 158 | \item[5399:] The code from here to line 5402 159 | appears to be unnecessarily devious! See the discussion of 160 | ``rkaddr'' below. If the block 161 | number is too large, set the 162 | ``B\_ERROR'' flag and report ``completion''; 163 | 164 | \item[5407:] Link the buffer into a FIFO list 165 | for the controller. The list is 166 | singly linked, uses the ``av\_forw'' 167 | pointer of the ``buf'' structures, 168 | and has head and tail pointers in 169 | ``rktab''. Interrupts from disk 170 | devices may not be allowed after 171 | the first step; 172 | 173 | \item[5414:] If the RK controller is not 174 | currently active, wake it up via 175 | a call on ``rkstart'' (5440), which 176 | checks that there is something to 177 | do (5444), flags the controller 178 | as busy (5446) and calls 179 | ``devstart'' (5447), passing as 180 | parameters: 181 | 182 | \bi 183 | \item a pointer to the first enqueued 184 | buffer header; 185 | 186 | \item the address of the RKDA disk 187 | address register. (The value 188 | passed is in effect 0177412. See 189 | lines 5363, 5382.); 190 | 191 | \item a ``disk address'' computed by 192 | ``rkaddr''; 193 | 194 | \item zero (not really important in our 195 | discussion, and may be ignored). 196 | 197 | \ei 198 | \ed 199 | 200 | 201 | \sbs{rkaddr (5420)} 202 | 203 | The code in this procedure incorporates 204 | a special feature for files which 205 | extend over more than one disk drive. 206 | This feature is described in the UPM 207 | Section ``RK(IV)''. Its usefulness seems 208 | to be restricted. 209 | 210 | The value returned by ``rkaddr'' is formatted for direct transmission to the 211 | control register, RKDA. 212 | 213 | 214 | \sbs{devstart (5096)} 215 | 216 | This procedure when called for the RK 217 | disk loads appropriate values into the 218 | registers RKDA, RKBA, RKWC and RKCS in 219 | succession. Only the last value needs 220 | to be computed at this stage. 221 | 222 | The calculation, though messy in 223 | appearance, is straight forward. Note 224 | that ``hbcom'' is zero and ``rbp-$>$b\_xmem'' 225 | contains the two high order bits of the 226 | physical core address. The loading of 227 | RKCS initialises the disk controller 228 | i.e. the operation is now entirely 229 | under the control of the hardware. 230 | 231 | ``devstart'' returns to ``rkstart'' (5448), 232 | which returns to ``rkstrategy'' (5416), 233 | which resets the processor priority and 234 | returns to ``swap'' (5213), which ... 235 | 236 | \sbs{rkintr (5451)} 237 | 238 | This procedure is invoked to handle the 239 | interrupts which occur when RK disk 240 | operations are completed. 241 | 242 | \bd 243 | \item[5455:] Check for a false alarm! 244 | 245 | \item[5459:] Inspect the error bit; if set ... 246 | 247 | \item[5460:] Call ``deverror'' (2447) to display 248 | a message on the system console 249 | terminal; 250 | 251 | \item[5461:] Clear the internal registers of 252 | the disk controller and ... 253 | 254 | \item[5462:] Wait till this is completed (usually a few microseconds); 255 | 256 | \item[5463:] If the operation has been retried 257 | less than ten times, call 258 | ``rkstart'' to try again. Otherwise 259 | give up and report an error; 260 | 261 | \item[5469:] Set the ``retry'' (!) count back to 262 | zero, remove the current operation from the ``actf'' list, and 263 | complete the operation by calling 264 | ``iodone''; 265 | 266 | \item[5472:] ``rkstart'' is called unconditionally here. If the call is not 267 | necessary (because the ``actf'' 268 | list is empty) ``rkstart'' will 269 | return immediately (5444). 270 | \ed 271 | 272 | 273 | \sbs{iodone (5018)} 274 | 275 | This routine is primarily concerned 276 | with the return of resources when a 277 | block i/o operation has completed. It: 278 | 279 | \bi 280 | \item frees up the Unibus map (for 11/70's, 281 | if appropriate); 282 | 283 | \item sets the ``B\_DONE'' flag; 284 | 285 | \item releases the buffer if the i/o was 286 | asynchronous, or else resets the 287 | ``B\_WANTED'' flag and wakes up any 288 | process waiting for the i/o 289 | operation to complete. 290 | \ei 291 | 292 | -------------------------------------------------------------------------------- /Original Files/ch26.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch26.tex, version 1.4, 15 May 1994 3 | % 4 | \se{Suggested Exercises} 5 | 6 | Any operating system design involves 7 | many subjective and ad hoc judgements 8 | on the part of system's designers. At 9 | many places in the UNIX source code 10 | you will find yourself wondering ``Why 11 | did they do it that way?'', ``What would 12 | happen if I changed this?'' 13 | 14 | The following exercises express some of 15 | these questions. Some can be answered 16 | from an examination of the source code 17 | alone after a study in more depth; others require some experimental probing 18 | and measurement, for which read-only 19 | access to the file ``/dev/kmem'' via terminal will prove invaluable; and still 20 | others really require the construction 21 | and testing of experimental versions of 22 | the operating system. 23 | 24 | \sbs{Section One} 25 | 26 | \bd 27 | \item[1.1] Devise changes to ``malloc'' (2528) 28 | to implement the Best Fit algorithm. 29 | 30 | \item[1.2] Rewrite the procedure ``mfree'' 31 | (2556) to render its function more 32 | easily discernible by the reader. 33 | 34 | \item[1.3] Investigate the adequacy of the 35 | sizes of the arrays ``coremap'' and 36 | ``swapmap'' (0203, 0204). How should 37 | ``CMAPSIZ'' and ``SWAPSIZ'' change when 38 | ``NPROC'' is increased? 39 | 40 | \item[1.4] Prove that ``malloc'' and ``mfree'' 41 | jointly solve the memory aliocation 42 | problem correctly. 43 | 44 | \item[1.5] By monitoring the contents of 45 | ``coremap'', estimate the efficiency with 46 | which main memory is utilised. Estimate also the cost of compacting ``in 47 | use areas'' of main memory from time to 48 | time to reduce memory fragmentation. 49 | 50 | Hence decide whether it would be 51 | worthwhile to extend the present memory 52 | allocation scheme to include memory 53 | compaction. 54 | 55 | \item[1.6] In setting the first six kernel 56 | page description registers, UNIX does 57 | not make use of all the hardware protection features that are available 58 | e.g. some pages which contain only pure 59 | text could be made read-only. Devise 60 | changes to the code to maximise the use 61 | of the available hardware protection. 62 | 63 | \item[1.7] Compile the program 64 | 65 | \begin{verbatim} 66 | char *init ``/etc/init''; 67 | main ( ) { 68 | execl (init, init, 0); 69 | while (1); 70 | } 71 | \end{verbatim} 72 | 73 | and compare the result with the contents of the array ``icode'' (1516). 74 | 75 | \item[1.8] Investigate the size required for 76 | kernel mode stack areas. Hence show 77 | that the 367 word area which is provided is adequate. 78 | 79 | \item[1.9] If main memory consists of several 80 | independent memory modules and one of 81 | these, not the last, is down, ``main'' 82 | will not include memory modules beyond 83 | the one which is down, in the list of 84 | available space in ``coremap''. Devise 85 | some simple changes to ``main'' to handle 86 | this situation. what other parts of the 87 | system would also need revision? 88 | 89 | \item[1.10] Rewrite the routines ``estabur'' 90 | (1650) and ``sureg'' (1739) so that they 91 | will work as efficiently as possible on 92 | the PDP11/40. How often are these routines used in practice? Would it really 93 | be worthwhile trying to implement your 94 | improved versions? 95 | 96 | \item[1.11] Investigate the overheads involved 97 | in initiating a new process. Perform a 98 | series of measurements for a set of 99 | different sized programs under different conditions. 100 | 101 | \item[1.12] Evaluate the following scheme 102 | which is intended by Ken Thompson as 103 | the basis for a revised scheduling 104 | algorithm: 105 | 106 | A number ``p'' is kept for each process, stored as ``p\_cpu''. 107 | ``p'' is incremented by one every clock tick that the 108 | process is found to be executing. ``p'' 109 | therefore accumulates the CPU usage. 110 | Every second, each value of ``p'' is 111 | replaced by four fifths of its value 112 | rounded to the nearest integer. This 113 | means that ``o'' has values which are 114 | bounded by zero and the solution of the 115 | equation $k = 0.8*(k + HZ)$ i.e. 116 | 4*HZ. Hence if HZ is 50 or 60, and ``p'' 117 | is integerised, ``p'' can be stored in 118 | one byte. 119 | 120 | \item[1.13] The ``proc'' table is always 121 | searched via a direct linear search. As 122 | the table size is increased, the search 123 | overheads also increase. Survey the 124 | alternatives for improving the search 125 | mechanism, when ``NPROC'' is say 300. 126 | \ed 127 | 128 | \sbs{Section Two} 129 | 130 | \bd 131 | \item[2.1] Explain in detail how the system 132 | reacts to a floating point trap which 133 | occurs when the processor is in kernel 134 | mode. 135 | 136 | \item[2.2] When a process dies, a ``zombie'' 137 | record is written to disk, and is 138 | subsequently read back by the parent. Devise a scheme for passing back the 139 | necessary information to the parent 140 | which will avoid the overhead of the 141 | two i/o operations. 142 | 143 | \item[2.3] Document ``backup'' (1012). 144 | 145 | \item[2.4] It is relatively easy using the 146 | ``shell'' to set up a set of asynchronous 147 | processes which will flood your terminal with useless output. Trying to stop 148 | these processes individually can be a 149 | problem, since their identifying 150 | numbers may not be known. Use of the 151 | command ``kill 0'' is usually an act of 152 | sheer desperation. Devise an alternative scheme, e.g. based on the use of 153 | messages such as ``kill --99'', which will 154 | be effective, but more selective. 155 | 156 | \item[2.5] Design a form of coroutine jump 157 | whlch will cause control to pass more 158 | efficiently between a program which is 159 | being traced, and its parent. 160 | \ed 161 | 162 | \sbs{Section Three} 163 | 164 | \bd 165 | \item[3.1] Rewrite the procedure ``sched'' to 166 | avoid the use of ``goto'' statements. 167 | 168 | \item[3.2] Modify ``sched'' so that the text 169 | segment and data segment for a program 170 | will possibly be allocated in separate 171 | main memory areas if a single large 172 | area is not immediately available. 173 | 174 | \item[3.3] If the system crashes and must be 175 | ``rebooted'' the contents of the buffers 176 | which were not written out at the time 177 | of the crash are lost. 178 | 179 | However if a core dump is taken, 180 | the contents of the buffers can be 181 | obtained and hence the contents of the 182 | disk can be brought completely up to 183 | date. Outline a detalled plan for carrying out this scheme. 184 | How effective do you think it would be? 185 | 186 | \item[3.4] Explain why the buffer areas 187 | declared on line 4720 are 514, and not 188 | 512, characters long. 189 | 190 | \item[3.5] Explain how deadlock situations may 191 | arise if there are too few ``large'' 192 | buffers available. What measures can 193 | you suggest to alleviate the problem, 194 | assuming that increasing the number of 195 | buffers is not possible. 196 | \ed 197 | 198 | \sbs{Section Four} 199 | 200 | \bd 201 | \item[4.1] Devise a scheme for labelling file 202 | system volumes and checking these 203 | labels when the volumes are mounted. 204 | 205 | \item[4.2] Discuss the problems of supporting 206 | ANSI standard labelled tapes under 207 | UNIX, and propose a solution. 208 | 209 | \item[4.3] Design a scheme for providing index 210 | sequential access to files. 211 | 212 | \item[4.4] The emergence of the ``sticky bit'' 213 | (see ``CHMOD(I)'' in the PM) confirms 214 | that there are some residual advantages 215 | in allocating all the space for a file 216 | contiguously. Discuss the merits of 217 | making ``contiguous files'' more generally available. 218 | 219 | \item[4.5] Devise a technique to measure the 220 | efficiency of pipes. Apply the technique and report your results. 221 | 222 | \item[4.6] Devise modifications to ``pipe.c'' 223 | which will make pipes more efficient 224 | according to the following scheme: 225 | whenever the ``read'' pointer is greater 226 | than 512, rotate the non-null block 227 | numbers in the ``inode'' ana decrease 228 | both the ``read'' and ``write'' pointers by 229 | 512. 230 | 231 | \item[5.1] By monitoring the number of free 232 | buffers or otherwise, determine whether 233 | the number of character buffers provided at your installation is adequate. 234 | 235 | \item[5.2] Perform measurements and/or experiments 236 | to determine whether the character buffer 237 | blocks would be more efficiently utilised if they consisted of 238 | four or eight characters, rather than 239 | six, per block. 240 | 241 | \item[5.3] Redesign the line printer driver to 242 | handle overprinting and backspacing 243 | more efficiently in the sense of 244 | minimising the number of print cycles. 245 | 246 | \item[5.4] Document ``mmread'' (0916) and 247 | ``mmwrite'' (9042). 248 | \ed 249 | \sbs{General} 250 | 251 | \bd 252 | \item[6.1] The easiest way to vary the main 253 | memory space used by the operating system is to 254 | vary ``NBUF''. If this is forbidden, propose the best way to: 255 | 256 | \bd 257 | \item[(a)] reduce the space required by 500 258 | words; 259 | 260 | \item[(b)] utilise an additional 500 words. 261 | \ed 262 | 263 | \item[6.2] Discuss the merits of ``C'' as a systems programming language. What 264 | features are missing? or superfluous? 265 | \ed 266 | -------------------------------------------------------------------------------- /Original Files/preface.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file preface.tex, version 1.5, 18 May 1994 3 | % 4 | \section*{Preface} 5 | 6 | This book is an attempt to explain in 7 | detail the nucleus of one of the most 8 | interesting computer operating systems 9 | to appear in recent years. 10 | 11 | It is the UNIX Time-sharing System, 12 | which runs on the larger models of 13 | Digital Equipment Corporation's PDP11 14 | computer system, and was developed by 15 | Ken Thompson and Dennis Ritchie at Bell 16 | Laboratories. It was first announced to 17 | the world in the July, 1974 issue of 18 | the ``Communications of the ACM''. 19 | 20 | Very soon in our experience with UNIX, 21 | it suggested itself as an interesting 22 | candidate for formal study by students, 23 | for the following reasons: 24 | 25 | \bi 26 | \item it runs on a system which is already available to us; 27 | 28 | \item it is compact and accessible; 29 | 30 | \item it provides an extensive set of very 31 | usable facilities; 32 | 33 | it is intrinsically interesting, and 34 | in fact breaks new ground in a 35 | number of areas. 36 | \ei 37 | 38 | Not least amongst the charms and virtues of the UNIX Time-sharing System is 39 | the compactness of its source code. 40 | The source code for the permanently 41 | resident ``nucleus'' of the system when 42 | only a small number of peripheral devices is represented, is comfortably 43 | less than 9,000 lines of code. 44 | 45 | It has often been suggested that 1,000 46 | lines of code represents the practical 47 | limit in size for a program which is to 48 | be understood and maintained by a single individual. 49 | Most operating systems either exceed 50 | this limit by one or even two orders of 51 | magnitude, or else offer the user a 52 | very limited set of facilities, i.e. 53 | either the details of the system are 54 | inaccessible to all but the most determined, dedicated and long-suffering 55 | student, or else the system is rather 56 | specialised and of little intrinsic 57 | interest. 58 | 59 | There seem to be three main approaches 60 | to teaching Operating Systems. 61 | First there is the ``{\it general principles}'' 62 | approach, wherein fundamental principles are expounded, and illustrated by 63 | references to various existing systems, 64 | (most of which happen to be outside the 65 | students' immediate experience). This 66 | is the approach advocated by the COSINE 67 | Committee, but in our view, many students are not mature or experienced 68 | enough to profit from it. 69 | 70 | The second approach is the ``{\it building 71 | block}'' approach, wherein the students 72 | are enabled to synthesize a small scale 73 | or ``toy'' operating system for themselves. While undoubtedly this can be a 74 | valuable exercise, if properly organised, it cannot but fail to encompass 75 | the complexity and sophistication of 76 | real operating systems, and is usually 77 | biased towards one aspect of operating 78 | system design, such as process synchronisation. 79 | 80 | The third approach is the ``{\it case study}'' 81 | approach. This is the one originally 82 | recommended for the Systems Programming 83 | course in ``Curriculum '68'', the report 84 | of the ACM Curriculum Committee on Computer Science, published in the March, 85 | 1968 issue of the ``Communications of 86 | the ACM''. 87 | 88 | Ten years ago, this approach, which 89 | advocates devoting ``most of the course 90 | to the study of a single system'' was 91 | unrealistic because the cost of providing adequate student access to a suitable system was simply too high. 92 | 93 | Ten years later, the economic picture 94 | has changed significantly, and the 95 | costs are no longer a decisive disadvantage if a minicomputer system can be 96 | the subject of study. The considerable 97 | advantages of the approach which undertakes a detailed analysis of an existing system are now attainable. 98 | 99 | In our opinion, it is highly beneficial 100 | for students to have the opportunity to 101 | study a working operating system in all 102 | its aspects. 103 | 104 | Moreover it is undoubtedly good for 105 | students majoring in Computer Science, 106 | to be confronted at least once in their 107 | careers, with the task of reading and 108 | understanding a program of major dimensions. 109 | 110 | In 1976 we adopted UNIX as the subject 111 | for case study in our courses in 112 | Operating Systems at the University of 113 | New South Wales. These notes were 114 | prepared originally for the assistance 115 | of students in those courses (6.602B 116 | and 6.657G). 117 | 118 | The courses run for one semester each. 119 | Before entering either Course, students 120 | are presumed to have studied the PDP11 121 | architecture and assembly language, and 122 | to have had an opportunity to use the 123 | UNIX operating system during exercises 124 | for earlier courses. 125 | 126 | In general, students seem to find the 127 | new courses more onerous, but much more 128 | satisfying than the previous courses 129 | based on the ``general principles'' 130 | approach of the COSINE Committee. 131 | 132 | Some mention needs to be made regarding 133 | the documentation provided by the 134 | authors of the UNIX system. As reproduced for use on our campus, this 135 | comprises two volumes of A4 size paper, 136 | with a total thickness of 3 cm, and a 137 | weight of 1250 grams. 138 | 139 | A first observation is that the whole 140 | documentation is not unreasonably transportable in a student's brief case. 141 | However it must not be assumed that 142 | this amount of documentation, which is 143 | written in a fresh, terse, whimsical 144 | style, is necessarily inadequate. 145 | 146 | In fact the second observation (which 147 | is only made after considerable experience) is that for reference purposes, 148 | the documentation is remarkably 149 | comprehensive. However there is plenty 150 | of scope for additional tutorial 151 | material, one part of which, it is 152 | hoped, is satisfied by these notes. 153 | 154 | The actual UNIX operating system source 155 | code is recorded in a separate companion volume entitled ``UNIX Operating 156 | System Source Code'', which was first 157 | printed in July, 1976. This is a specially edited selection of code from 158 | the Level Six version of UNIX, as 159 | received by us in December, 1975. 160 | 161 | During 1976, an initial version of the 162 | present notes was distributed in 163 | roneoed form, and only in the latter 164 | part of the year were the facilities of 165 | the ``nroff'' text formatting program 166 | exploited. The opportunity has 167 | recently been taken to revise and 168 | ``nroff'' the earlier material, to make 169 | some revisions and corrections, and to 170 | integrate them into their present form. 171 | 172 | A decision had to be made quite early 173 | regarding the order of presentation of 174 | the source code. The intention was to 175 | provide a reasonably logical sequence 176 | for the student who wanted to learn the 177 | whole system. With the benefit of 178 | hindsight, a great many improvements in 179 | detail are still possible, and it is 180 | intended that these changes will be 181 | made in some future edition. 182 | 183 | It is our hope that this book will be 184 | of interest and value to many students 185 | of the UNIX Time-sharing System. 186 | Although not prepared primarily for use 187 | as a reference work, some will wish to 188 | use it as such. The indices provided at 189 | the end should go some of the way 190 | towards satisfying the requirement for 191 | reference material at this level. 192 | 193 | Since these notes refer to proprietary 194 | material administered by the Western 195 | Electric Company, they can only be made 196 | available to licensees of the UNIX 197 | Time-sharing System and hence are 198 | unable to be published through more 199 | usual channels. 200 | 201 | Corrections, criticism and suggestions 202 | for improvement of these notes will be 203 | very welcome. 204 | 205 | \bigskip 206 | 207 | {\noindent \large \bf Acknowledgments} 208 | 209 | \smallskip 210 | 211 | The preparation of these notes has been 212 | encouraged and supported by many of my 213 | colleagues and students including David 214 | Carrington, Doug Crompton, Ian Hayes, 215 | David Horsfall, Peter Ivanov, Ian Johnstone, Chris Maltby, Dave Milway, John 216 | O'Brien and Greg Rose. 217 | 218 | Pat Mackie and Mary Powter did much of 219 | the initial typing, and Adele Green has 220 | assisted greatly in the transfer of the 221 | notes to ``nroff'' format. 222 | 223 | David Millis and the Publications Section of the University of New South 224 | Wales have assisted greatly with the 225 | mechanics of publication, and Ian Johnstone and the Australian Graduate 226 | School of Management provided facilities for the preparation of the final 227 | draft. 228 | 229 | Throughout this project, my wife 230 | Marianne has given me unfailing moral 231 | support and much practical support with 232 | proof-reading. 233 | 234 | Finally Ken Thompson and Dennis Ritchie 235 | started it all. 236 | 237 | To all the above, I wish to express my 238 | sincere thanks. 239 | 240 | The co-operation of the ``nroff'' program 241 | must also be mentioned. Without it, 242 | these notes could never have been produced in this form. However it has 243 | yielded some of its more enigmatic 244 | secrets so reluctantly, that the 245 | author's gratitude is indeed mixed. 246 | Certainly ``nroff'' itself must provide a 247 | fertile field for future practitioners 248 | of the program documenter's art. 249 | 250 | \bt 251 | \hspace{5cm} \= John Lions \\ 252 | \> Kensington, NSW \\ 253 | \> May, 1977 \\ 254 | \et 255 | -------------------------------------------------------------------------------- /Original Files/ch11.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch11.tex, version 1.4, 17 May 1994 3 | % 4 | \se{Clock Interrupts} 5 | 6 | The procedure ``clock'' (3725) handles 7 | interrupts from either the line frequency time clock 8 | (type \mbox{KW11-L}, interrupt vector address 100) or the 9 | programmable real-time clock (type KW11-P, 10 | interrupt vector address 104). 11 | 12 | UNIX requires that at least one of 13 | these should be available. (If both are 14 | present, only the line time clock is 15 | used.) 16 | 17 | Whichever clock is used, interrupts are 18 | generated at line frequency (i.e. with 19 | a 50 Hz power supply, every 20 milliseconds). 20 | The clock interrupt priority level is six, higher than for any 21 | other peripheral device on our typical 22 | system, so that there will usually be 23 | very little delay in the initiation of 24 | ``clock'' once the interrupt has been 25 | requested by the clock controller. 26 | 27 | 28 | \sbs{clock (3725)} 29 | 30 | The function of ``clock'' is one of general housekeeping: 31 | 32 | \bi 33 | \item the display register is updated 34 | (PDP11/45 and 11/70 only); 35 | 36 | \item various accounting values such as 37 | the time of day, accumulated processing times 38 | and execution profiles are maintained; 39 | 40 | \item processes sleeping for a fixed 41 | time interval are awakened as per 42 | schedule; 43 | 44 | \item core swapping activity is initiated once per second. 45 | \ei 46 | 47 | ``clock'' breaks most of the rules for 48 | peripheral device handlers: it does 49 | reference the current ``u'' structure, 50 | and it also runs at a low priority for 51 | some of the time. It abbreviates its 52 | activity if a previous execution has 53 | not yet completed. 54 | 55 | \bd 56 | \item[3740:] ``display'' is a no-op on the 57 | PDP11/40; 58 | 59 | \item[3743:] The array ``callout'' (0265) is an 60 | array of ``NCALL'' (0143) structures 61 | of type ``callo'' (0260). 62 | The ``callo'' structure contains 63 | three elements: an incremental 64 | time, an argument and the address 65 | of a function. When the function 66 | element is not null, the function 67 | is to be executed with the supplied 68 | argument after a specified time. 69 | 70 | 71 | (For the systems under study, the 72 | only function ever executed in 73 | this way is ``ttrstrt'' (8486), 74 | handler. (See Chapter 25.)); 75 | 76 | \item[3748:] If the first element of the list 77 | is null, the whole list is null; 78 | 79 | \item[3750:] The ``callout'' list is arranged in 80 | the desired order of execution. 81 | The time recorded is the number 82 | of clock ticks between events. 83 | Unless the first time (the time 84 | before the next event) is already 85 | zero, (meaning that the execution 86 | is already due) this time should 87 | be decremented by one. 88 | 89 | 90 | If this time has already been 91 | counted to zero, decrement the 92 | next time unless it is already 93 | zero also, etc. i.e. decrement 94 | the first non-zero time in the 95 | list. All the leading entries 96 | with zero times represent operations which are already due. (The 97 | operations are actually carried 98 | out a little later.); 99 | 100 | \item[3759:] Examine the previous processor 101 | status word, and if the priority 102 | was non-zero, bypass the next 103 | section, which executes those 104 | operations which are due; 105 | 106 | \item[3766:] Reduce the processor priority to 107 | five (other level six interrupts 108 | may now occur); 109 | 110 | \item[3767:] Search the ``callout'' array looking 111 | for operations which are due and execute them; 112 | 113 | \item[3773:] Move the entries for operations 114 | which are still not yet due, to 115 | the beginning of the array; 116 | 117 | \item[3787:] The code from here until line 118 | 3797 is executed, whatever the 119 | previous processor priority, at 120 | either priority level five or 121 | six; 122 | 123 | \item[3788:] If the previous mode was ``user 124 | mode'', then increment the user 125 | time counter, and if an execution 126 | profile is being accumulated, 127 | call ``incupc'' (a895) to make an 128 | entry in a histogram for the user 129 | mode program counter (PC). 130 | 131 | ``incupc'' is written in assembler, 132 | presumably for efficiency and 133 | convenience. A description of 134 | what it does may be found in the 135 | section ``PROFIL(II)'' of the UPM. 136 | See also the procedure ``profil'' 137 | (3667); 138 | 139 | \item[3792:] If the previous mode was not user 140 | mode, increment the system (kernel) time counter for the process. 141 | \ed 142 | 143 | The code just described performs the 144 | basic time accounting for the system. 145 | Every clock tick results in the incrementing of either ``u.u\_utime'' or 146 | ``u.u\_stime'' for some process. Both 147 | ``u.u\_utime'' and ``u.u\_stime'' are 148 | initialised to zero in ``fork'' (3322). Their 149 | values are interrogated in ``wait'' 150 | (3270). The values will go negative 151 | after 32K ticks (about 10 hours)! 152 | 153 | \bd 154 | \item[3795:] ``p\_cpu'' is used in determining 155 | process priorities. It is a character value which is always 156 | interpreted as a positive integer 157 | (0 to 255). When it is moved to a 158 | special register, sign extension 159 | occurs so that 255, for instance, 160 | becomes like --1. Adding one then 161 | leaves a zero result. In this 162 | case the value is reduced to --1 163 | again, and stored as 255 164 | unsigned. Note that in the other 165 | places where ``p\_cpu'' is referenced (2161, 3814), the top eight 166 | bits are masked off after the 167 | value has been transferred to a 168 | special register; 169 | 170 | \item[3797:] Increment ``lbolt'' and if it 171 | exceeds ``HZ'', i.e. a second or 172 | more has elapsed ... 173 | 174 | \item[3798:] Then provided the processor was 175 | not previously running at a nonzero priority, do a whole lot of 176 | housekeeping; 177 | 178 | \item[3800:] Decrement ``lbolt'' by ``HZ''; 179 | 180 | \item[3801:] Increment the time of day accumulator; 181 | 182 | \item[3803:] The events which follow may take 183 | some time, but they may reasonably be interrupted to service 184 | other peripherals. So the processor priority is dropped below all 185 | the device priority levels i.e. 186 | below {\bf four}. 187 | 188 | However there is now a possibility of another clock interrupt 189 | before this activation of the 190 | ``clock'' procedure is completed. 191 | By setting the processor priority 192 | to {\bf one} rather than to {\bf zero}, a 193 | second activation of ``clock'' will 194 | not attempt to execute the code 195 | from line 3804 on also. Note however that 196 | to the hardware, priority one is functionally the same 197 | as priority zero; 198 | 199 | \item[3804:] If the current time (measured in 200 | seconds) is equal to the value 201 | stored in ``tout'', wake all 202 | processes which have elected to 203 | suspend themselves for a period 204 | of time via the ``sleep'' system 205 | call i.e. via the procedure 206 | ``sslep'' (5979). 207 | \ed 208 | 209 | ``tout'' stores the time at which the 210 | next process is to be awakened. If 211 | there is more than one such process, 212 | then the remainder, which will have 213 | been disturbed, must reset ``tout'' 214 | between them. This mechanism, while 215 | quite effective, will not be efficient 216 | if the number of such processes ever 217 | becomes large. 218 | 219 | 220 | In this situation, a mechanism similar 221 | to the ``callout'' array (see 3767) would 222 | need to be provided. (In fact, how difficult would it be to merge the two 223 | mechanisms? What would be the disadvantages ??); 224 | 225 | \bd 226 | \item[3806:] When the last two bits of 227 | ``time[1]'' are zero i.e. every 228 | four seconds, reset the scheduling flag ``runrun'' and wake up 229 | everything waiting for a ``lightning bolt''. (``lbolt'' represents a 230 | general event which is caused 231 | every four seconds, to initiate 232 | miscellaneous housekeeping. It is 233 | used by ``pcopen'' (8648).); 234 | 235 | \item[3810:] For all currently defined 236 | processes: 237 | 238 | increment ``p\_time'' up to a maximum 239 | of 127 (it is only a character 240 | variable); 241 | 242 | decrement ``p\_cpu'' by ``SCHMAG'' 243 | (3707) but do not allow it to go 244 | negative. Note that as discussed 245 | earlier (line 3795) ``p\_cpu'' is 246 | treated as a positive integer in 247 | the range 0 to 255; 248 | 249 | if the processor priority is currently set 250 | at a depressed value, recalculate it. 251 | \ed 252 | 253 | 254 | Note that ``p\_cpu'' enters into the calculation of process priorities, 255 | ``p\_pri'', by ``setpri'' (2156). ``p\_pri'' 256 | is used by ``swtch'' (2209) in choosing 257 | which process, from among those which 258 | are in core (``SLOAD'') and ready to run 259 | (``SRUN''), should next receive the CPU's 260 | attention. 261 | 262 | ``p\_time'' is used to measure how long 263 | (in seconds) a process has been either 264 | in core or swapped out to disk. 265 | ``p\_time'' is set to zero by ``newproc'' 266 | (1869), by ``sched'' (2047) and by 267 | ``xswap'' (4386). It is used by ``sched'' 268 | (1962, 2009) to determine which 269 | processes to swap in or out. 270 | 271 | \bd 272 | \item[3820:] If the scheduler is waiting to 273 | rearrange things, wake it up. 274 | Thus the normal rate for scheduling decisions is once per second; 275 | 276 | \item[3824:] If the previous mode before the 277 | interrupt was ``user mode'', store 278 | the address of ``r0'' in a standard 279 | place, and if a ``signal'' has been 280 | received for the process, call 281 | ``psig'' (4043) for the appropriate 282 | action. 283 | \ed 284 | 285 | 286 | \sbs{timeout (3845)} 287 | 288 | This procedure makes new entries in the 289 | ``callout'' array. In this system it is 290 | only called from the routine ``ttstart'' 291 | (8505), passing the procedure ``ttrstrt'' 292 | (3486). Note that ``ttrstrt'' calls 293 | ``ttstart'', which may call ``timeout'', 294 | for a thoroughly incestuous relationship! 295 | 296 | Note also that most of ``timeout'' runs 297 | at priority level seven, to avoid clock 298 | interrupts. 299 | 300 | -------------------------------------------------------------------------------- /Original Files/lionc.log: -------------------------------------------------------------------------------- 1 | This is TeX, C Version 3.14 (format=lplain 92.7.25) 12 JUN 1994 15:46 2 | **&lplain lionc.tex 3 | (lionc.tex 4 | LaTeX Version 2.09 <25 March 1992> 5 | (/opt/lib/tex/inputs/article.sty 6 | Document Style `article' <16 Mar 88>. 7 | (/opt/lib/tex/inputs/art10.sty) 8 | \c@part=\count86 9 | \c@section=\count87 10 | \c@subsection=\count88 11 | \c@subsubsection=\count89 12 | \c@paragraph=\count90 13 | \c@subparagraph=\count91 14 | \c@figure=\count92 15 | \c@table=\count93 16 | ) (/opt/lib/tex/inputs/fancyheadings.sty 17 | \headrulewidth=\dimen100 18 | \footrulewidth=\dimen101 19 | \plainheadrulewidth=\dimen102 20 | \plainfootrulewidth=\dimen103 21 | \headwidth=\dimen104 22 | ) 23 | (lionc.aux (title.aux) (preface.aux) (ch1.aux) (ch2.aux) (ch3.aux) (ch4.aux) 24 | (ch5.aux) (ch6.aux) (ch7.aux) (ch8.aux) (ch9.aux) (ch10.aux) (ch11.aux) 25 | (ch12.aux) (ch13.aux) (ch14.aux) (ch15.aux) (ch16.aux) (ch17.aux) (ch18.aux) 26 | (ch19.aux) (ch20.aux) (ch21.aux) (ch22.aux) (ch23.aux) (ch24.aux) (ch25.aux) 27 | (ch26.aux)) (title.tex) [1 28 | 29 | 30 | ] [2 31 | 32 | 33 | ] (lionc.toc [1 34 | 35 | ] [2] [3]) 36 | \tf@toc=\write3 37 | [4 38 | 39 | ] (preface.tex 40 | [5 41 | 42 | 43 | ]) [6] (ch1.tex [1 44 | 45 | 46 | 47 | ] [2]) [3] (ch2.tex [4 48 | 49 | 50 | ] [5] [6] [7] 51 | Overfull \hbox (15.16429pt too wide) in paragraph at lines 738--738 52 | []\twlbf Memory Man-age-ment Sta-tus Reg- 53 | 54 | \hbox(8.23334+2.33331)x221.93158, glue set - 1.0 55 | .\hbox(7.73332+0.0)x37.5 56 | ..\glue 0.0 57 | ..\twlbf 2 58 | ..\twlbf . 59 | ..\twlbf 1 60 | ..\twlbf 1 61 | ..etc. 62 | .\twlbf M 63 | .\twlbf e 64 | .\twlbf m 65 | .\twlbf o 66 | .etc. 67 | 68 | [8]) [9 69 | 70 | ] (ch3.tex 71 | Underfull \hbox (badness 10000) in paragraph at lines 39--46 72 | 73 | 74 | \hbox(0.0+0.0)x221.93158 75 | .\glue(\rightskip) 0.0 76 | 77 | [10 78 | 79 | 80 | ] [11] [12] [13] [14] 81 | Overfull \hbox (24.81627pt too wide) in paragraph at lines 984--984 82 | [] \tentt n[0] =+ fp->f_inode->i size0 & 0377;[] 83 | 84 | \hbox(6.94444+2.22223)x221.93158 85 | .\hbox(0.0+0.0)x0.0 86 | .\penalty 10000 87 | .\glue 5.24995 88 | .\penalty 10000 89 | .\glue 5.24995 90 | .etc. 91 | 92 | [15] [16]) [17 93 | 94 | ] (ch4.tex [18 95 | 96 | 97 | ] [19] [20]) [21] (ch5.tex [22 98 | 99 | 100 | ] [23] [24] [25] 101 | [26] 102 | Overfull \hbox (20.68561pt too wide) in paragraph at lines 808--813 103 | \tenrm cluded to pro-vide dec-la-ra-tions for ``d[]major'', ``d[]minor'', 104 | 105 | \hbox(6.94444+1.94444)x221.93158, glue set - 1.0 106 | .\tenrm c 107 | .\tenrm l 108 | .\tenrm u 109 | .\tenrm d 110 | .\tenrm e 111 | .etc. 112 | 113 | ) [27 114 | 115 | ] (ch6.tex [28 116 | 117 | 118 | ] 119 | Overfull \hbox (24.3189pt too wide) in paragraph at lines 317--318 120 | [] []\tenrm the phys-i-cally avail-able mem-ory (``maxmem''); 121 | 122 | \hbox(7.5+2.5)x174.93158, glue set - 1.0 123 | .\hbox(0.0+0.0)x0.0 124 | .\glue 0.0 125 | .\hbox(4.44444+0.0)x0.0 126 | ..\glue 0.0 127 | ..\glue -17.0 128 | ..\glue -5.0 129 | ..\hbox(4.44444+0.0)x17.0, glue set 17.0fil 130 | ...\glue 0.0 plus 1.0fil minus 1.0fil 131 | ...\hbox(4.44444+0.0)x0.0, glue set - 5.00002fil [] 132 | ..\glue 5.0 133 | .\penalty 0 134 | .\tenrm t 135 | .etc. 136 | 137 | 138 | Overfull \hbox (43.93001pt too wide) in paragraph at lines 319--320 139 | [] []\tenrm an in-stal-la-tion de-fin-able pa-ram-e-ter (``MAXMEM'') 140 | 141 | \hbox(7.5+2.5)x174.93158, glue set - 1.0 142 | .\hbox(0.0+0.0)x0.0 143 | .\glue 0.0 144 | .\hbox(4.44444+0.0)x0.0 145 | ..\glue 0.0 146 | ..\glue -17.0 147 | ..\glue -5.0 148 | ..\hbox(4.44444+0.0)x17.0, glue set 17.0fil 149 | ...\glue 0.0 plus 1.0fil minus 1.0fil 150 | ...\hbox(4.44444+0.0)x0.0, glue set - 5.00002fil [] 151 | ..\glue 5.0 152 | .\penalty 0 153 | .\tenrm a 154 | .etc. 155 | 156 | [29] [30] [31]) [32] (ch7.tex [33 157 | 158 | 159 | ] [34] 160 | Underfull \vbox (badness 6016) has occurred while \output is active 161 | \vbox(685.71158+0.0)x221.93158, glue set 3.9218 162 | .\glue(\topskip) 2.5 163 | .\hbox(7.5+2.5)x221.93158, glue set - 0.01944 164 | ..\tenrm i 165 | ..\tenrm s 166 | ..\glue 3.33333 plus 1.66666 minus 1.11111 167 | ..\tenrm a 168 | ..\tenrm d 169 | ..etc. 170 | .\penalty 100 171 | .\glue(\baselineskip) 2.55556 172 | .\hbox(6.94444+1.94444)x221.93158, glue set - 0.00461 173 | ..\tenrm d 174 | ..\tenrm r 175 | ..\tenrm e 176 | ..\tenrm s 177 | ..\tenrm s 178 | ..etc. 179 | .etc. 180 | 181 | [35] 182 | [36]) [37] (ch8.tex [38 183 | 184 | 185 | ] [39] [40]) [41] (ch9.tex 186 | Overfull \hbox (26.19081pt too wide) in paragraph at lines 26--26 187 | []\frtnbf Hardware In-ter-rupts and Traps 188 | 189 | \hbox(9.99998+2.79999)x221.93158, glue set - 1.0 190 | .\hbox(9.27998+0.0)x24.83983 191 | ..\glue 0.0 192 | ..\frtnbf 9 193 | ..\glue 16.55989 194 | .\frtnbf H 195 | .\frtnbf a 196 | .\frtnbf r 197 | .\frtnbf d 198 | .etc. 199 | 200 | 201 | Overfull \hbox (29.818pt too wide) in paragraph at lines 118--132 202 | [] 203 | 204 | \hbox(68.7+63.7)x221.93158 205 | .\glue(\leftskip) 0.0 plus 1.0fil 206 | .\hbox(68.7+63.7)x251.74957 207 | ..\mathon 208 | ..\vbox(68.7+63.7)x251.74957 209 | ...\hbox(8.39996+3.60004)x251.74957 [] 210 | ...\glue(\lineskip) 0.0 211 | ...\hbox(8.39996+3.60004)x251.74957 [] 212 | ...\rule(0.4+0.0)x251.74957 213 | ...\hbox(8.39996+3.60004)x251.74957 [] 214 | ...etc. 215 | ..\mathoff 216 | .\glue(\rightskip) 0.0 plus 1.0fil 217 | 218 | [42 219 | 220 | 221 | ] [43]) [44] (ch10.tex [45 222 | 223 | 224 | ] [46] 225 | Overfull \hbox (18.15216pt too wide) in paragraph at lines 373--389 226 | [] 227 | 228 | \hbox(80.9+75.9)x221.93158 229 | .\glue(\leftskip) 0.0 plus 1.0fil 230 | .\hbox(80.9+75.9)x240.08374 231 | ..\mathon 232 | ..\vbox(80.9+75.9)x240.08374 233 | ...\hbox(8.39996+3.60004)x240.08374 [] 234 | ...\rule(0.4+0.0)x240.08374 235 | ...\hbox(8.39996+3.60004)x240.08374 [] 236 | ...\glue(\lineskip) 0.0 237 | ...\hbox(8.39996+3.60004)x240.08374 [] 238 | ...etc. 239 | ..\mathoff 240 | .\glue(\rightskip) 0.0 plus 1.0fil 241 | 242 | ) [47] (ch11.tex [48 243 | 244 | 245 | ]) [49] (ch12.tex 246 | Missing character: There is no ^^a3 in font cmr10! 247 | [50 248 | 249 | 250 | ] [51] [52]) [53] (ch13.tex 251 | Overfull \hbox (19.52888pt too wide) in paragraph at lines 55--61 252 | \tenrm dis-tin-guished be-cause UNIX en-sures that ``u.u[]signal[9]'' 253 | 254 | \hbox(7.5+2.5)x221.93158, glue set - 1.0 255 | .\tenrm d 256 | .\tenrm i 257 | .\tenrm s 258 | .\discretionary 259 | ..\tenrm - 260 | .\tenrm t 261 | .etc. 262 | 263 | [54 264 | 265 | 266 | ] [55] [56] [57] [58] 267 | Overfull \hbox (22.44656pt too wide) in paragraph at lines 836--841 268 | []\tenrm In the third case ``ptrace'' will al-ways set ``ipc.ip[]lock'' 269 | 270 | \hbox(6.94444+1.94444)x221.93158, glue set - 1.0 271 | .\hbox(0.0+0.0)x15.0 272 | .\tenrm I 273 | .\tenrm n 274 | .\glue 3.33333 plus 1.66666 minus 1.11111 275 | .\tenrm t 276 | .etc. 277 | 278 | ) [59] (ch14.tex [60 279 | 280 | 281 | ] [61]) [62] (ch15.tex [63 282 | 283 | 284 | ] [64]) [65 285 | 286 | ] (ch16.tex [66 287 | 288 | 289 | ]) 290 | [67] (ch17.tex 291 | Overfull \hbox (22.19656pt too wide) in paragraph at lines 152--157 292 | \tenrm and if the ``av''-list is empty, set the ``B[]WANTED'' 293 | 294 | \hbox(6.94444+1.94444)x196.93158, glue set - 1.0 295 | .\tenrm a 296 | .\tenrm n 297 | .\tenrm d 298 | .\glue 3.33333 plus 1.66666 minus 1.11111 299 | .\tenrm i 300 | .etc. 301 | 302 | [68 303 | 304 | 305 | ] [69]) [70] (ch18.tex [71 306 | 307 | 308 | ] [72] [73] [74] [75]) [76 309 | 310 | ] (ch19.tex [77 311 | 312 | 313 | ] 314 | [78] [79]) [80] (ch20.tex [81 315 | 316 | 317 | ] [82] [83] [84] [85]) [86 318 | 319 | ] (ch21.tex) [87 320 | 321 | 322 | ] 323 | (ch22.tex [88 324 | 325 | 326 | ] [89] [90] 327 | Overfull \hbox (18.17259pt too wide) in paragraph at lines 499--499 328 | []\twlbf PC-11 Pa-per Tape Reader/Punch 329 | 330 | \hbox(9.0+3.0)x221.93158, glue set - 1.0 331 | .\hbox(7.73332+0.0)x44.25 332 | ..\glue 0.0 333 | ..\twlbf 2 334 | ..\twlbf 2 335 | ..\twlbf . 336 | ..\twlbf 1 337 | ..etc. 338 | .\twlbf P 339 | .\twlbf C 340 | .\twlbf - 341 | .\discretionary 342 | .etc. 343 | 344 | ) [91] (ch23.tex (fig23_1.tex) (fig23_2.tex) (fig23_3.tex) (fig23_4.tex 345 | Overfull \hbox (33.21124pt too wide) in paragraph at lines 37--39 346 | [][] 347 | 348 | \hbox(122.0398+0.0)x221.93158 349 | .\hbox(0.0+0.0)x15.0 350 | .\hbox(122.0398+0.0)x240.14282 351 | ..\hbox(122.0398+0.0)x240.14282, glue set 287.38403fil 352 | ...\glue -47.24121 353 | ...\hbox(537.52686+0.0)x0.0, shifted 413.3606 [] 354 | ...\glue 0.0 plus 1.0fil minus 1.0fil 355 | .\glue(\rightskip) 0.0 356 | 357 | ) [92 358 | 359 | 360 | ] [93] 361 | Overfull \hbox (15.88098pt too wide) in paragraph at lines 275--289 362 | [] 363 | 364 | \hbox(80.7+75.7)x221.93158 365 | .\hbox(80.7+75.7)x237.81256 366 | ..\mathon 367 | ..\vbox(80.7+75.7)x237.81256 368 | ...\hbox(8.39996+3.60004)x237.81256 [] 369 | ...\glue(\lineskip) 0.0 370 | ...\hbox(8.39996+3.60004)x237.81256 [] 371 | ...\glue(\lineskip) 0.0 372 | ...\hbox(8.39996+3.60004)x237.81256 [] 373 | ...etc. 374 | ..\mathoff 375 | .\penalty 10000 376 | .\glue(\parfillskip) 0.0 plus 1.0fil 377 | .\glue(\rightskip) 0.0 378 | 379 | [94]) [95] (ch24.tex [96 380 | 381 | 382 | ] 383 | Overfull \hbox (26.34647pt too wide) in paragraph at lines 233--262 384 | [] 385 | 386 | \hbox(170.5+165.5)x196.93158 387 | .\hbox(170.5+165.5)x223.27805 388 | ..\mathon 389 | ..\vbox(170.5+165.5)x223.27805 390 | ...\hbox(8.39996+3.60004)x223.27805 [] 391 | ...\glue(\lineskip) 0.0 392 | ...\hbox(8.39996+3.60004)x223.27805 [] 393 | ...\glue(\lineskip) 0.0 394 | ...\hbox(8.39996+3.60004)x223.27805 [] 395 | ...etc. 396 | ..\mathoff 397 | .\penalty 10000 398 | .\glue(\parfillskip) 0.0 plus 1.0fil 399 | .\glue(\rightskip) 0.0 400 | 401 | [97] [98] [99]) [100 402 | 403 | ] (ch25.tex [101 404 | 405 | 406 | ] [102] [103] [104]) [105] (ch26.tex 407 | [106 408 | 409 | 410 | ] 411 | Overfull \hbox (22.48535pt too wide) in paragraph at lines 212--218 412 | [] []\tenrm The emer-gence of the ``sticky bit'' (see ``CHMOD(I)'' 413 | 414 | \hbox(7.5+2.5)x196.93158, glue set - 1.0 415 | .\hbox(0.0+0.0)x0.0 416 | .\glue 0.0 417 | .\hbox(6.44444+0.0)x-5.30563 418 | ..\glue -25.0 419 | ..\glue 0.0 420 | ..\glue -5.0 421 | ..\hbox(6.44444+0.0)x19.69437 422 | ...\glue 5.0 423 | ...\tenbf 4 424 | ...\tenbf . 425 | ...\tenbf 4 426 | ..\glue 5.0 427 | .\penalty 0 428 | .\tenrm T 429 | .etc. 430 | 431 | ) [107] (lionc.aux (title.aux) (preface.aux) (ch1.aux) (ch2.aux) (ch3.aux) 432 | (ch4.aux) (ch5.aux) (ch6.aux) (ch7.aux) (ch8.aux) (ch9.aux) (ch10.aux) 433 | (ch11.aux) (ch12.aux) (ch13.aux) (ch14.aux) (ch15.aux) (ch16.aux) (ch17.aux) 434 | (ch18.aux) (ch19.aux) (ch20.aux) (ch21.aux) (ch22.aux) (ch23.aux) (ch24.aux) 435 | (ch25.aux) (ch26.aux)) ) 436 | Here is how much of TeX's memory you used: 437 | 741 strings out of 62421 438 | 4452 string characters out of 93652 439 | 54535 words of memory out of 262141 440 | 2268 multiletter control sequences out of 3000 441 | 19604 words of font info for 74 fonts, out of 100000 for 255 442 | 0 hyphenation exceptions out of 307 443 | 20i,11n,18p,197b,302s stack positions out of 300i,40n,60p,32760b,6000s 444 | 445 | Output written on lionc.dvi (115 pages, 618904 bytes). 446 | -------------------------------------------------------------------------------- /Original Files/ch15.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch15.tex, version 1.5, 17 May 1994 3 | % 4 | \se{Introduction to Basic I/O} 5 | 6 | There are three files whose contents 7 | need to be thoroughly absorbed before 8 | the subject of UNIX input/output is 9 | broached in detail. 10 | 11 | \sbs{The File `buf.h'} 12 | 13 | This file declares two structures 14 | called ``buf'' (4520) and ``devtab'' 15 | (4551). Instances of the structure 16 | ``buf'' are declared as 'bfreelist 17 | (4567) and as the array ``buf'' (!) 18 | (4535) with ``NBUF'' elements. 19 | 20 | The structure ``buf'' is possibly 21 | misnamed because it is in fact a {\bf buffer 22 | header} (or buffer control block). The 23 | buffer areas proper are allocated 24 | separately and declared (4720) as 25 | 26 | \begin{verbatim} 27 | ``char buffers [NBUF] [514];'' 28 | \end{verbatim} 29 | 30 | Pointers from the ``buf'' array to the 31 | ``buffers'' array are set up by the procedure ``binit''. 32 | 33 | 34 | Other instances of the structure ``buf'' 35 | are declared as ``swbuf'' (4721) and 36 | ``rrkbuf'' (5387). No 514 character 37 | buffer areas are associated with 38 | ``bfreelist'' or ``swbuf'' or ``rrkbuf''. 39 | 40 | The ``buf'' structure may be divided into 41 | three parts: 42 | 43 | \bd 44 | \item[(a) flags] These convey status information and are contained within 45 | a single word. Masks for setting these flags are defined as 46 | ``B\_WRITE'', ``B\_READ'' etc. in lines 4572 to 4586. 47 | 48 | \item[(b) list pointer] Forward and backward pointers for two doubly 49 | linked lists, which we shall 50 | refer to as the ``b''-list and the 51 | ``av''-list. 52 | 53 | \item[(c) i/o parameters] A set of values 54 | associated with the actual data 55 | transfer. 56 | \ed 57 | 58 | \sbs{devtab (4551)} 59 | 60 | The ``devtab'' structure has five words, 61 | the last four of which are forward and 62 | backward pointers. 63 | 64 | One instance of ``devtab'' is declared 65 | within the device handler for each 66 | block type of peripheral device. For 67 | our model system the only block device 68 | is the RK05 disk, and ``rktab'' is 69 | declared as a ``devtab'' structure at 70 | line 5386. 71 | 72 | The ``devtab'' structure contains some 73 | status information for the the device 74 | and serves as a list head for: 75 | 76 | \bd 77 | \item[(a)] the list of buffers associated 78 | with the device, and simultaneously on the ``av''-list; 79 | 80 | \item[(b)] the list of outstanding i/o 81 | requests for the device. 82 | \ed 83 | 84 | \sbs{The File `conf.h'} 85 | 86 | The file ``conf.h'' declares: 87 | 88 | \bi 89 | \item yet another way to dissect an 90 | integer into two parts (``d\_minor'' 91 | and ``d\_major''). Note that 92 | ``d\_major'' corresponds to ``hibyte'' (0180); 93 | 94 | \item two arrays of structures; 95 | 96 | \item two integer variables, ``nlkdev'' 97 | and ``nchrdev''. 98 | \ei 99 | 100 | The two arrays of structures, ``bdevsw'' 101 | and ``cdevsw'', are declared but not 102 | dimensioned or initialised in ``conf.h''. 103 | The initialisation of these arrays is 104 | performed in the file ``conf.c''. 105 | 106 | \sbs{The File `conf.c'} 107 | 108 | This file, along with ``low.s'', is generated individually at each installation (to reflect the set of peripherals 109 | actually installed) by the program 110 | ``mkconf''. (In our case, ``conf.c'' 111 | reflects the representative devices for 112 | our model system.) 113 | 114 | This file initialises the following: 115 | 116 | \begin{verbatim} 117 | bdevsw (4656) swapdev (4696) 118 | cdevsw (4663) swplo (4637) 119 | rootdev (4635) nswap (4698) 120 | \end{verbatim} 121 | 122 | \sbs{System Generation} 123 | 124 | System generation at a UNIX installation consists mainly of: 125 | 126 | \bi 127 | \item running ``mkconf'' with appropriate 128 | input; 129 | 130 | \item recompiling the output files (created 131 | as ``c.c'' and ``l.s''); 132 | 133 | \item reloading the system with the revised 134 | object files. 135 | \ei 136 | 137 | This process only takes a few minutes 138 | (not the several hours of some other 139 | operating systems). Note that ``bdevsw'' 140 | and ``cdevsw'' are defined differently in 141 | ``conf.c'' from elsewhere, namely as a 142 | one dimensional array of pointers to 143 | functions which return integer values. 144 | This quietly ignores the fact that, for 145 | example, ``rktab'' is not a function, and 146 | relies on the linking program not to 147 | enquire too closely into the nature of 148 | the work which it is performing. 149 | 150 | \sbs{swap (5196)} 151 | 152 | Before plunging into all the detail of 153 | the file ``bio.c'', it will be instructive as well as convenient to examine 154 | one routine which was introduced earlier, namely ``swap''. 155 | 156 | The buffer head ``swbuf'' was declared to 157 | control swapping input/output, which 158 | must share access to the disk with 159 | other activity. No element of ``buffers'' 160 | is associated with ``swbuf''. Instead the 161 | core area occupied (or to be occupied) 162 | by the program serves as the data 163 | buffer. 164 | 165 | \bd 166 | \item[5200:] The address of the flags in 167 | ``swbuf'' is transferred to the 168 | register variable ``fp'' for convenience and economy; 169 | 170 | \item[5202:] The ``B\_BUSY'' flag is tested, and 171 | if it is on, a swap operation is 172 | already under way, so that the 173 | ``B\_WANTED'' flag is set and the 174 | process must wait via a call on ``sleep''. 175 | \ed 176 | 177 | Note that the code loop on lines 178 | 5202 to 5205 runs at priority 179 | level six, i.e. one higher than 180 | the disk interrupt priority. 181 | 182 | Can you see why this is necessary? Under what conditions will 183 | the ``B\_BUSY'' flag be set? 184 | 185 | \bd 186 | \item[5206:] The flags are set to reflect: 187 | 188 | \bi 189 | \item ``swbuf'' is in use (``B\_BUSY''); 190 | 191 | \item physical i/o implying a large 192 | transfer direct to/from the user 193 | data segment\\ 194 | (``B\_PHYS''); 195 | 196 | \item whether the operation is read or 197 | write. (``rdflg'' is a parameter to 198 | ``swap''); 199 | \ei 200 | 201 | \item[5207:] The ``b\_dev'' field is initialised. 202 | (Presumably this could have been 203 | performed once during initialisation rather than every time 204 | ``swbuf'' is used, i.e. in ``binit''.); 205 | 206 | \item[5208:] ``b\_wcount'' is initialised. Note 207 | the negative value and the effective multiplication by 32; 208 | 209 | \item[5210:] The hardware device controller 210 | requires a full physical address 211 | (18 bits on the PDP 11/40). The 212 | block number of a 32 word block 213 | must be converted into two parts: 214 | the low order ten bits are 215 | shifted left six places and 216 | stored as ``b\_addr'', and the 217 | remaining six high order bits as 218 | ``b\_xmem''. (On the PDP 11/40 and 219 | 11/45 only two of these bits are 220 | significant.); 221 | 222 | \item[5212:] A mouthful at first glance! Shift 223 | ``swapdev'' eight places to the 224 | right to obtain the major device 225 | number. Use the result to index 226 | ``bdevsw''. From the structure 227 | thus selected, extract the strategy routine and execute it with 228 | the address of ``swbuf'' passed as 229 | a parameter; 230 | 231 | \item[5213:] Explain why this call on ``spl6'' 232 | is necessary; 233 | 234 | \item[5214:] Wait until the i/o operation is 235 | complete. Note that the first 236 | parameter to ``sleep'' is in effect 237 | the address of ``swbuf''; 238 | 239 | \item[5216:] Wakeup those processes (if any) 240 | which are waiting for ``swbuf''; 241 | 242 | \item[5218:] Reset the process or priority to 243 | zero, thus allowing any pending 244 | interrupts to ``happen''; 245 | 246 | \item[5219:] Reset both the ``B\_BUSY'' and 247 | ``B\_WANTED'' flags. 248 | \ed 249 | 250 | \sbs{Race Conditions} 251 | 252 | The code for ``swap'' has a number of 253 | interesting features. In particular it 254 | displays in microcosm the problems of 255 | race conditions when several processes 256 | are running together. 257 | 258 | \bigskip 259 | 260 | \noindent Consider the following scenario: 261 | 262 | No swapping is taking place when process A initiates a swapping operation. 263 | Denoting ``swbuf.b\_flags'' by simply 264 | ``flags'', we have initially 265 | 266 | \begin{verbatim} 267 | flags == null 268 | \end{verbatim} 269 | 270 | \noindent Process A is not delayed at line 5204, 271 | initiates its i/o operation and goes to 272 | sleep at line 5215. We now have 273 | 274 | \begin{verbatim} 275 | flags == B_BUSY | B_PHYS | rdflg 276 | \end{verbatim} 277 | 278 | \noindent which was set at line 5206. 279 | 280 | 281 | Suppose now while the i/o operation is 282 | proceeding, process B also initiates a 283 | swapping operation. It too begins to 284 | execute ``swap'', but finds the ``B\_BUSY'' 285 | flag set, so it sets the ``B\_WANTED'' 286 | flag (5203) and goes to sleep also 287 | (5204). We now have 288 | 289 | \begin{verbatim} 290 | flags == B_BUSY | B_PHYS | rdflg | B_WANTED 291 | \end{verbatim} 292 | 293 | At last the i/o operation completes. 294 | Process C takes the interrupt and executes ``rkintr'', which calls (5471) 295 | ``iodone'' which calls (5301) ``wakeup'' to 296 | awaken process A and process B. 297 | ``iodone'' also sets the ``B\_DONE'' flag 298 | and resets the ``B\_WANTED'' flag so that 299 | 300 | \begin{verbatim} 301 | flags == B_BUSY | B_PHYS | rdflg | B_DONE 302 | \end{verbatim} 303 | 304 | What happens next depends on the order 305 | in which process A and process B are 306 | reactivated. (Since they both have the 307 | same priority, ``PSWP'', it is a toss-up 308 | which goes first.) 309 | 310 | \bd 311 | \item[Case (a):] Process A goes first. 312 | ``B\_DONE'' is set so no more sleeping is 313 | needed. ``B\_WANTED'' is reset so there is 314 | no one to ``wakeup''. Process A tidies up 315 | (5219), and leaves ``swap'' with 316 | 317 | \begin{verbatim} 318 | flags == B_PHYS | rdflg | B_DONE 319 | \end{verbatim} 320 | 321 | Process B now runs and is able to initiate its i/o operation without further 322 | delay. 323 | 324 | \item[Case (b):] Process B goes first. It 325 | finds ``B\_BUSY'' on, so it turns the 326 | ``B\_WANTED'' flag back on, and goes to 327 | sleep again, leaving 328 | 329 | \begin{verbatim} 330 | flags == B_BUSY | B_PHYS | rdflg | 331 | B_DONE | B_WANTED 332 | \end{verbatim} 333 | 334 | Process A starts again as in Case (a), 335 | but this time finds ``B\_WANTED'' on so it 336 | must call ``wakeup'' (5217) in addition 337 | to its other chores. Process B finally 338 | wakes again and the whole chain completes. 339 | \ed 340 | 341 | Case (b) is obviously much less efficient than case (a). It would seem that 342 | a simple change to line 5215 to read 343 | 344 | \begin{verbatim} 345 | sleep (fp, PSWP-1); 346 | \end{verbatim} 347 | 348 | \noindent would cost virtually nothing and ensure 349 | that Case (b) never occurred! 350 | 351 | The necessity for the raising of processor priority at various points 352 | should be studied: for example if line 353 | 5201 was omitted and if process B had 354 | just completed line 5203 when the ``i/o 355 | complete'' interrupt occurred for Process A's operation, then ``iodone'' would 356 | turn off ``B\_WANTED'' and perform 357 | ``wakeup'' before process B went to sleep ... forever! A bad scene. 358 | 359 | \sbs{Reentrancy} 360 | 361 | Note also the assumption made above, 362 | that both process A and process B could 363 | execute ``swap'' simultaneously. All UNIX 364 | procedures are in general ``re-entrant'' 365 | (which means multiple simultaneous executions are possible). How would UNIX 366 | have to change if re-entrancy were not 367 | allowed? 368 | 369 | \sbs{For the Uninitiated} 370 | 371 | We can now return to complete an investigation started 372 | in Chapter Eight concerning ``aretu'' and ``u.u\_ssav'': 373 | 374 | After setting ``u.u\_ssav'' (2284), 375 | ``expand'' calls (2285) ``xswap'', 376 | which calls (4380) ``swap'', 377 | which calls (5215) ``sleep'', 378 | which calls (2084) ``swtch'', 379 | which {\bf resets} ``u.u\_rsav'' (2189). 380 | 381 | Thus in fact ``u.u\_rsav'' finally gets 382 | reset to a value appropriate to four 383 | procedure calls deeper than that for 384 | ``u.u\_ssav''. 385 | 386 | \sbs{Additional Reading} 387 | 388 | The article ``The UNIX I/O System'' by 389 | Dennis Ritchie is highly pertinent. 390 | -------------------------------------------------------------------------------- /Original Files/ch1.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch1.tex, version 1.3, 18 May 1994 3 | % 4 | \setcounter{page}{1} 5 | \section{Introduction} 6 | 7 | ``UNIX'' is the name of a time-sharing 8 | system for PDP11 computers, written by 9 | Ken Thompson and Dennis Ritchie at Bell 10 | Laboratories. It was described by them 11 | in the July, 1974 issue of the ``Communications of the ACM''. 12 | 13 | UNIX has proved to be effective, efficient 14 | and reliable in operation and was 15 | in use at more than 150 installations 16 | by the end of 1976. 17 | 18 | The amount of effort to write UNIX, 19 | while not inconsiderable in itself 20 | (\verb+~+10 man years up to the release of the 21 | Level Six system) is insignificant when 22 | compared to other systems. (For 23 | instance, by 1968, OS/360 was reputed 24 | to have consumed more then five man 25 | millennia and TSS/360, another IBM 26 | operating system, more than one man 27 | millennium.) 28 | 29 | Of course there are systems which are 30 | easier to understand than UNIX but, it 31 | may be asserted, these are invariably 32 | much simpler and more modest in what 33 | they attempt to achieve. As far as the 34 | list of features offered to users is 35 | concerned, UNIX is in the ``big league''. 36 | In fact it offers many features which 37 | are notable by their absence from some 38 | of the well-known major systems. 39 | 40 | \subsection{The UNIX Operating System} 41 | 42 | The purpose of this document, and its 43 | companion, the ``UNIX Operating System 44 | Source Code'', is to present in detail 45 | that part of the UNIX time-sharing system 46 | which we choose to call the ``UNIX 47 | Operating System'', namely the code 48 | which is permanently resident in the 49 | main memory during the operation of 50 | UNIX. This code has the following 51 | major functions: 52 | 53 | \bi 54 | \item initialisation; 55 | \item process management; 56 | \item system calls; 57 | \item interrupt handling; 58 | \item input/output operations; 59 | \item file management. 60 | \ei 61 | 62 | \subsection{Utilities} 63 | 64 | The remaining part of UNIX (which is 65 | much larger!) is composed of a set of 66 | suitably tailored programs which run as 67 | ``user programs'', and which, for want of 68 | a better term, may be termed ``utilities''. 69 | 70 | Under this heading come a number of 71 | programs with a very strong symbiotic 72 | relationship with the operating system 73 | such as 74 | 75 | \bi 76 | \item the ``shell'' (the command language interpreter) 77 | 78 | \item ``/etc/init'' (the terminal configuration controller) 79 | \ei 80 | 81 | \noindent and a number of file system management 82 | programs such as: 83 | 84 | \bt 85 | \hspace{1cm} \= check \hspace{1cm} \= du \hspace{1.5cm} \= rmdir \\ 86 | \> chmod \> mkdir \> sync \\ 87 | \> clri \> mkfs \> umount \\ 88 | \> df \> mount \> update \\ 89 | \et 90 | 91 | It should be pointed out that many of 92 | the functions carried out by the 93 | above-named programs are regarded as 94 | operating system functions in other 95 | computer systems, and that this certainly 96 | does contribute significantly to 97 | the bulk of these other systems as 98 | compared with the UNIX Operating System 99 | (in the way we have defined it). 100 | 101 | 102 | Descriptions of the function and use of 103 | the above programs may be found in the 104 | ``UNIX Programmer's Manual'' (UPM), 105 | either in Section I (for the commonly 106 | used programs) or in Section VIII (for 107 | the programs used only by the System 108 | Manager). 109 | 110 | 111 | \subsection{Other Documentation} 112 | 113 | These notes make frequent reference to 114 | the ``UNIX Programmer's Manual'' (UPM), 115 | occasional reference to the ``UNIX 116 | Documents'' booklet, and constant 117 | reference to the ``UNIX Operating System 118 | Source Code''. 119 | 120 | All these are relevant to a complete 121 | understanding of the system. In addition, 122 | a full study of the assembly 123 | language routines requires reference to 124 | the ``PDP11 Processor Handbook'', published 125 | by Digital Equipment Corporation. 126 | 127 | 128 | \subsection{UNIX Programmer's Manual} 129 | 130 | The UPM is divided into eight major 131 | sections, preceded by a table of contents 132 | and a KWIC (Key Word In Context) 133 | index. The latter is mostly very useful but 134 | is occasionally annoying, as 135 | some indexed material does not exist, 136 | and some existing material is not 137 | indexed. 138 | 139 | Within each section of the manual, the 140 | material is arranged alphabetically by 141 | subject name. The section number is 142 | conventionally appended to the subject 143 | name, since some subjects appear in 144 | more than one section, e.g. ``CHDIR(I)'' 145 | and ``CHDIR(II)''. 146 | 147 | \bd 148 | \item[Section I] contains commands which 149 | either are recognised by the 150 | ``shell'' command interpreter, or 151 | are the names of standard user 152 | utility programs; 153 | 154 | \item[Section II] contains ``system calls'' 155 | which are operating system routines which 156 | may be invoked from a 157 | user program to obtain operating 158 | system service. A study of the 159 | operating system will render most 160 | of these quite familiar; 161 | 162 | \item[Section III] contains ``subroutines'' 163 | which are library routines which 164 | may be called from a user program. 165 | To the ordinary programmer, the 166 | distinctions between Sections II 167 | and III often appear somewhat 168 | arbitrary. Most of Section III is 169 | irrelevant to the operating system; 170 | 171 | \item[Section IV] describes ``special 172 | files'', which is another name for 173 | peripheral devices. Some of these 174 | are relevant, and some merely 175 | interesting. It depends where you 176 | are; 177 | 178 | \item[Section V] describes ``File Formats 179 | and Conventions''. A lot of highly 180 | relevant information is tucked 181 | away in this section; 182 | 183 | \item[Sections VI and VII] describe ``User 184 | Maintained'' programs and subroutines. 185 | No UNIXophile will ignore 186 | these sections, but they are not 187 | particularly relevant to the 188 | operating system; 189 | 190 | \item[Section VIII] describes ``system 191 | maintenance'' (software, not 192 | hardware!). There is lots of useful 193 | information here, especially 194 | if you are interested in how a 195 | UNIX installation is managed. 196 | \ed 197 | 198 | \subsection{UNIX Documents} 199 | 200 | This is a somewhat miscellaneous collection 201 | of essays of varying degrees of 202 | relevance: 203 | 204 | \bi 205 | \item {\it Setting up UNIX} really belongs in 206 | Section VIII of the UPM (it's 207 | relevant); 208 | 209 | \item {\it The UNIX Time-sharing System} is an 210 | updated version of the original 211 | ``Communications of the ACM'' paper. 212 | It should be re-read at least once 213 | per month; 214 | 215 | \item {\it UNIX for Beginners} is useful if 216 | your UNIX experience is limited; 217 | 218 | \item The tutorials on ``C'' and the editor, 219 | and the reference manuals for 220 | ``C'' and the assembler are highly 221 | useful unless you are completely 222 | expert; 223 | 224 | \item {\it The UNIX I/O System} provides a 225 | good overview of many features of 226 | the operating system; 227 | 228 | \item {\it UNIX Summary} provides a check list 229 | which will be useful in answering 230 | the question what does an operating system do? 231 | \ei 232 | 233 | \subsection{UNIX Operating System Source Code} 234 | 235 | This is an edited version of the 236 | operating system as supplied by Bell 237 | Laboratories. 238 | 239 | The code selection presumes a ``model'' 240 | system consisting of: 241 | 242 | \bi 243 | \item PDP11/40 processor; 244 | \item RK05 disk drives; 245 | \item LP11 line printer; 246 | \item PC11 paper tape reader/punch; 247 | \item KL11 terminal interface. 248 | \ei 249 | 250 | The principal editorial changes to the 251 | source code are as follows: 252 | 253 | \bi 254 | \item the order of presentation of files 255 | has been changed; 256 | 257 | \item the order of material within 258 | several files has been changed; 259 | 260 | \item to a very limited extent, code has 261 | been transferred between files 262 | (with hindsight a lot more of this 263 | would have been desirable); 264 | 265 | \item about 5\% of the lines have been 266 | shortened in various ways to less 267 | than 66 characters (by elimination 268 | of blanks, rearrangement of comments, 269 | splitting into two lines, etc.); 270 | 271 | \item a number of comments consisting of 272 | a line of underscore characters 273 | have been introduced, particularly 274 | at the end of procedures; 275 | 276 | \item the size of each file has been 277 | adjusted to an exact multiple of 278 | 50 lines by padding with blank 279 | lines; 280 | \ei 281 | 282 | 283 | The source code has been printed in 284 | double column format with fifty lines 285 | per column, giving one hundred lines 286 | per sheet (or page). Thus there is a 287 | convenient relationship between line 288 | numbers and sheet numbers. 289 | 290 | A number of summaries have been 291 | included at the beginning of the Source 292 | Code volume: 293 | 294 | \bi 295 | \item A {\it Table of Contents} showing files 296 | in order of appearance, together 297 | with the Procedures they contain; 298 | 299 | \item An {\it alphabetical list} of procedures 300 | with line numbers; 301 | 302 | \item A {\it list of Defined Symbols} with 303 | their values; 304 | 305 | \item A {\it Cross Reference Listing} giving 306 | the line numbers where each symbol 307 | is used. (Reserved words in ``C'' 308 | and a number of commonly used symbols 309 | such as ``p'' and ``u'' have been 310 | omitted.) 311 | \ei 312 | 313 | \subsection{Source Code Selections} 314 | 315 | The source code has been divided into 316 | five sections, each devoted primarily 317 | to a single major aspect of the system. 318 | 319 | The intention, which has been largely 320 | achieved, has been to make each section 321 | sufficiently self-contained so that it 322 | may be studied as a unit and before its 323 | successors have been mastered: 324 | 325 | \bd 326 | \item[Section One] deals with system initialisation, 327 | and process management. It also contains all the 328 | assembly language routines; 329 | 330 | \item[Section Two] deals with interrupts, 331 | traps, system calls and signals 332 | (software interrupts); 333 | 334 | \item[Section Three] deals primarily with 335 | disk operations for program swapping and 336 | basic, block oriented 337 | input/output. It also deals with 338 | the manipulation of the pool of 339 | large buffers; 340 | 341 | \item[Section Four] deals with files and 342 | file systems: their creation, 343 | maintenance, manipulation and destruction; 344 | 345 | \item[Section Five] deals with ``character 346 | special files'', which is the UNIX 347 | term for slow speed peripheral 348 | devices which operate out of a 349 | common, character oriented, buffer 350 | pool. 351 | \ed 352 | 353 | The contents of each section is outlined 354 | in more detail in Chapter Four. 355 | 356 | \subsection{Source Code Files} 357 | 358 | Each of the five sections just 359 | described consists of several source 360 | code files. The name of each file 361 | includes a suffix which identifies its 362 | type: 363 | 364 | \bd 365 | \item[``.s''] denotes a file of assembly 366 | language statements; 367 | 368 | \item[``.c''] denotes a file of executable ``C'' 369 | language statements; 370 | 371 | \item[``.h''] denotes a file of ``C'' language 372 | statements which is not for 373 | separate compilation, but for 374 | inclusion in other ``.c'' files 375 | when they are compiled i.e. the 376 | ``.h'' files contain global 377 | declarations. 378 | \ed 379 | 380 | \subsection{Use of these notes} 381 | 382 | These notes, which are intended to supplement 383 | the comments already present in 384 | the source code, are not essential for 385 | understanding the UNIX operating system. 386 | It is perfectly possible to 387 | proceed without them, and you should 388 | attempt to do so as long as you can. 389 | 390 | The notes are a crutch, to aid you when 391 | the going becomes difficult. If you 392 | attempt to read each file or procedure 393 | on your own first, your initial progress 394 | is likely to be slower, but your 395 | ultimate progress much faster. Reading 396 | other people's programs is an art which 397 | should be learnt and practised 398 | because it is useful! 399 | 400 | \subsection{A Note on Programming Standards} 401 | 402 | You will find that most of the code in 403 | UNIX is of a very high standard. Many 404 | sections which initially seem complex 405 | and obscure, appear in the light of 406 | further investigation and reflection, 407 | to be perfectly obvious and ``the only 408 | way to fly''. 409 | 410 | For this reason, the occasional comments 411 | in the notes on programming 412 | style, almost invariably refer to 413 | apparent lapses from the usual standard 414 | of near perfection. 415 | 416 | What caused these? Sometimes it appears 417 | that the original code has been patched 418 | expediently. More than once apparent 419 | lapses have proved not to be such: the 420 | ``bad'' code has been found in fact to 421 | incorporate some subtle feature which 422 | was not at all apparent initially. And 423 | some allowance is certainly needed for 424 | occasional human weakness. 425 | 426 | But on the whole you will find that the 427 | authors of UNIX, Ken Thompson and 428 | Dennis Ritchie, have created a program 429 | of great strength, integrity and effectiveness, 430 | which you should admire and seek to emulate. 431 | -------------------------------------------------------------------------------- /Original Files/ch10.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch10.tex, version 1.5, 17 May 1994 3 | % 4 | \se{The Assembler ``Trap'' Routine} 5 | 6 | The principal purpose of this chapter 7 | is to examine the assembly language 8 | code in ``m40.s'' which is involved in 9 | the handling of interrupts and traps. 10 | 11 | This code is found between lines 0750 12 | and 0805, and has two entry points, 13 | ``trap'' (0755) and ``call'' (0766). There 14 | are several different and relevant 15 | paths through this code and we shall 16 | trace some examples of these. 17 | 18 | \sbs{Sources of Traps and Interrupts} 19 | 20 | The discussion in Section One introduced three places where the occurrence 21 | of a trap or interrupt was expected: 22 | 23 | \bd 24 | \item[(a)] ``main'' (1564) calls ``fuibyte'' 25 | repeatedly until a negative 26 | value is returned. This will 27 | occur after a ``bus timeout 28 | error'' has been encountered with 29 | a subsequent trap to vector 30 | location 4 (line 0512); 31 | 32 | \item[(b)] The clock has been set running 33 | and will generate an interrupt 34 | every clock tick i.e. 16.7 or 20 35 | milliseconds; 36 | 37 | \item[(c)] Process \#1 is about to execute a 38 | ``trap'' instruction as part of 39 | the system call on ``exec''. 40 | \ed 41 | 42 | 43 | \sbs{fuibyte (0814), fuiword (0844)} 44 | 45 | ``main'' uses both ``fuibyte'' and ``fuiword''. 46 | Since the former is more complicated in a non-essential way, we leave 47 | it to the reader, and concentrate on the latter. 48 | 49 | ``fuiword'' is called (1602) when the 50 | system is running in kernel mode with 51 | one argument which is an address in 52 | user address space. The function of the 53 | routine is to fetch the value of the 54 | corresponding word and to return it as 55 | a result (left in r0). However if an 56 | error occurs, the value --1 is to be 57 | returned. 58 | 59 | Note that with ``fuiword'', there is an 60 | ambiguity which does not occur with 61 | ``fuibyte'', namely a returned value of 62 | --1 may not necessarily be an error 63 | indication but the actual value in the 64 | user space. Convince yourself that for 65 | the way it is used in ``main'', this does 66 | not matter. 67 | 68 | Also the code does not distinguish 69 | between a ``bus timeout error'' and a 70 | ``segmentation error''. 71 | 72 | The routine proceeds as follows: 73 | 74 | \bd 75 | \item[0846:] The argument is moved to r1; 76 | 77 | \item[0848:] ``gword'' is called; 78 | 79 | \item[0852:] The current PS is stored on the 80 | stack; 81 | 82 | \item[0853:] The priority level is raised to 7 83 | (to disable interrupts); 84 | 85 | \item[0854:] The contents of the location 86 | nofault (1466) are saved in the 87 | stack; 88 | 89 | \item[0855:] ``nofault'' is loaded with 90 | address of the routine ``err''; 91 | 92 | \item[0856:] An ``mfpi'' instruction is used to 93 | fetch the word from user space. 94 | \ed 95 | 96 | {\bf If nothing goes wrong} this value will 97 | left on the kernel stack. 98 | 99 | \bd 100 | \item[0857:] The value is transferred from the 101 | stack to r0; 102 | 103 | \item[0876:] The previous values of ``nofault'' 104 | and PS are restored; 105 | \ed 106 | 107 | 108 | {\bf Now suppose something does go wrong} 109 | with the ``mfpi'' instruction, and a bus 110 | time-out does occur. 111 | 112 | \bd 113 | \item[0856:] The ``mfpi'' instruction will be 114 | aborted. PC will point to the 115 | next instruction (0857) and a 116 | trap via vector location 4 will 117 | occur; 118 | 119 | \item[0512:] The new PC will have the value of 120 | ``trap''. The new PS will indicate: 121 | 122 | present mode = kernel mode 123 | 124 | previous mode = kernel mode 125 | 126 | priority = 7; 127 | 128 | \item[0756:] The next instruction executed is 129 | the first instruction of ``trap''. 130 | This saves the processor status 131 | word two words beyond the current 132 | ``top of stack''. (This is not 133 | relevant here.); 134 | 135 | \item[0757:] ``nofault'' contains the address of 136 | ``err'' and is non-zero; 137 | 138 | \item[0765:] Moving 1 to SR0 reinitialises the 139 | memory management unit; 140 | 141 | \item[0766:] The contents of ``nofault'' are 142 | moved on top of the stack, 143 | {\bf overwriting} the previous contents, which was the return 144 | address in ``gword''; 145 | 146 | \item[0767:] The ``rtt'' returns, not to ``gword'' 147 | but to the first word of ``err''; 148 | 149 | \item[0880:] ``err'' restores ``nofault'' and PS, 150 | skips the return to ``fuiword'', 151 | places --1 in r0, and returns 152 | directly to the calling routine. 153 | \ed 154 | 155 | \sbs{Interrupts} 156 | 157 | Suppose the clock has interrupted the 158 | processor. 159 | 160 | 161 | Both clock vector locations, 100 and 162 | 104, have the same information. PC is 163 | set to the address of the location 164 | labelled ``kwlp'' (0568) and PS is set to 165 | show: 166 | 167 | present mode = kernel mode 168 | 169 | previous mode = kernel or user mode 170 | 171 | priority = 6 172 | 173 | 174 | \noindent Note. 175 | The PS will contain the true previous mode, regardless of the value 176 | picked up from the vector location. 177 | 178 | \bd 179 | \item[0570:] The vector location contains a 180 | new PC value which is the address 181 | of the statement labelled ``kwlp''. 182 | This instruction is a subroutine 183 | call on ``call'' via r0. 184 | 185 | After the execution of this 186 | instruction, r0 is left with the 187 | address of the code word after 188 | the instruction which contains 189 | ``\_clock'', i.e. r0 contains {\bf the 190 | address of the address} of the 191 | ``clock'' routine in the file 192 | ``clock.c'' (3725). 193 | \ed 194 | 195 | \sbs{call (0776)} 196 | 197 | \bd 198 | \item[0777:] Copy PS onto the stack; 199 | 200 | \item[0779:] Copy r1 onto the stack; 201 | 202 | \item[0780:] Copy the stack pointer for the 203 | previous address space onto the 204 | stack. (This is only significant 205 | if the previous mode was user 206 | mode). 207 | 208 | This represents a {\bf special case} of 209 | the ``mfpi'' instruction. See the 210 | ``PDP11 Processor Handbook'', page 211 | 6-20; 212 | 213 | \item[781:] Copy the copy of PS onto the 214 | stack and mask out all but the 215 | lower five bits. The resulting 216 | value designates the cause of the 217 | interrupt (or trap). The original value of the PS had to be 218 | captured quickly; 219 | 220 | \item[0783:] Test if the previous mode is kernel or user. 221 | 222 | {\bf If the previous mode is kernel 223 | mode} the branch is taken (0784). 224 | PS is changed to show the previous 225 | mode as user mode (0798); 226 | 227 | \item[0799:] The specialised interrupt handling routine pointed to by r0 is 228 | entered. (In this case it is the 229 | routine ``clock'', which is discussed in detail in the next 230 | chapter.) 231 | 232 | \item[0800:] When the ``clock'' routine (or some 233 | other interrupt handler) returns, 234 | the top two words of the stack 235 | are deleted. These are the 236 | masked copy of the PS and the 237 | copy of the stack pointer; 238 | 239 | \item[0802:] r1 is restored from the stack; 240 | 241 | \item[0803:] Delete the copy of PS from the 242 | stack; 243 | 244 | \item[0804:] Restore the value of r0 from the 245 | stack; 246 | 247 | \item[0805:] Finally the ``rtt'' instruction 248 | returns to the ``kernel'' mode 249 | routine that was interrupted; 250 | 251 | {\bf If the previous mode was user mode} 252 | it is not certain that the interrupted routine will be resumed 253 | immediately; 254 | 255 | \item[0788:] After the specialised interrupt 256 | routine (in this case ``clock'') 257 | returns, a check (``runrun $>$ 0'') 258 | is made to see if any process of 259 | higher priority than the current 260 | process is ready to run. If the 261 | decision is to allow the current 262 | process to continue, then it is 263 | important that it be not interrupted as 264 | it restores its registers prior to the ``return from 265 | interrupt'' instruction. Hence 266 | before the test, the processor 267 | priority is raised to seven (line 268 | 0787), thus ensuring that no more 269 | interrupts occur until user mode 270 | is resumed. (Another interrupt 271 | may occur immediately thereafter, 272 | however.) 273 | \ed 274 | 275 | 276 | If ``runrun $>$ 0'', then another, higher 277 | priority, process is waiting. The processor priority is reset to 0, allowing 278 | any pending interrupt to be taken. A 279 | call is then made to ``swtch'' (2178), to 280 | allow the higher priority process to 281 | proceed. When the process returns from 282 | ``swtch'', the program loops back to 283 | repeat the test. 284 | 285 | 286 | The above discussion obviously extends 287 | to all interrupts. The only part which 288 | relates specifically to the clock 289 | interrupt is the call on the specialised routine ``clock''. 290 | 291 | 292 | \sbs{User Program Traps} 293 | 294 | The ``system call'' mechanism which 295 | enables user mode programs to call on 296 | the operating system for assistance, 297 | involves the execution by the user mode 298 | program of one of 256 versions of the 299 | ``trap'' instruction. (The ``version'' is 300 | the value of the low order byte of the 301 | instruction word.) 302 | 303 | \bd 304 | \item[0518:] Execution of the trap instruction in a user mode program 305 | causes a trap to occur to vector 306 | location 34 which causes the PC 307 | to be loaded with the value of 308 | the label ``trap'' (lines 0512, 309 | 0755). A new PS is set which 310 | indicates 311 | 312 | present mode = kernel mode 313 | 314 | previous mode = user mode 315 | 316 | priority = 7 317 | 318 | \item[0756:] The next instruction executed is 319 | the first instruction of ``trap''. 320 | This saves the processor status 321 | word in the stack two words 322 | beyond the current ``top of 323 | stack''. 324 | 325 | It is important to save the PS as 326 | soon as possible, before it can 327 | be changed, since it contains 328 | information defining the type of 329 | trap that occurred. The somewhat 330 | unconventional destination of the 331 | ``move'' is to provide compatibility with the 332 | handling of interrupts, so that the same code can 333 | be used further on; 334 | 335 | \item[0757:] ``nofault'' will be zero so the 336 | branch is not taken; 337 | 338 | \item[0759:] The memory management status 339 | registers are stored just in case 340 | they will be needed, and the 341 | memory management unit is reinitialised; 342 | 343 | \item[0762:] A subroutine entry is made to 344 | ``call'' using r0. (This neatly 345 | stores the old value of r0 in the 346 | stack, but not a return address. 347 | The new value is the address of 348 | the address of the routine to be 349 | entered next (in this case the 350 | ``trap'' routine in the file 351 | ``trap.c'' (2693)); 352 | 353 | \item[0772:] The stack pointer is adjusted to 354 | point to the location which 355 | already contains the copy of PS; 356 | 357 | \item[0773:] The CPU priority is set to zero; 358 | 359 | {\bf From here the same path as for an 360 | interrupt is followed.} 361 | \ed 362 | 363 | 364 | \sbs{The Kernel Stack} 365 | 366 | The state of the kernel stack at the 367 | time that the ``trap'' procedure (``C'' 368 | version) or one of the specialised 369 | interrupt handling routines is entered, 370 | is shown in Figure 10.1. 371 | 372 | \begin{center} 373 | \begin{tabular}{lrl|c|l} 374 | & & & .... & {\bf Previous top of stack} \\ \hline 375 | (rps & 2) & 7 & ps & old PS \\ 376 | (r7 & 1) & 6 & pc & old PC (r7) \\ 377 | (r0 & 0) & 5 --$>$ & r0 & old r0 \\ 378 | & & 4 & nps & new PS after trap \\ 379 | (r1 & --2) & 3 & r1 & old r1 \\ 380 | (r6 & --3) & 2 & sp & old SP for previous mode \\ 381 | & & 1 & dev & masked new PS \\ 382 | & & 0 --$>$ & tpc & return address in ``call'' \\ \hline 383 | (r5 & --6 & --1 & (r5) & old r5 \\ 384 | (r4 & --7 & --2 & (r4) & old r4 \\ 385 | (r3 & --8 & --3 & (r3) & old r3 \\ 386 | (r2 & --9 & --4 & (r2) & old r2 \\ 387 | \end{tabular} 388 | \bigskip 389 | 390 | Figure 10.1 391 | \end{center} 392 | 393 | Columns (2) and (3) give the positions 394 | of stack words relative to the positions in the stack of the words 395 | labelled ``r0'' and ``tpc'' respectively. 396 | 397 | Columns (1) and (2) define (or explain) 398 | the contents of the file ``reg.h'' (Sheet 26). 399 | 400 | ``dev'', ``sp'', ``r1'', ``nps'' ``r0'', ``pc'' and 401 | ``ps'' in that order are the names of the 402 | parameters used in the declaration of 403 | the procedures ``trap'' (2693) and 404 | ``clock'' (3725). 405 | 406 | Note that just before entry to ``trap'' 407 | (``C'' version) or the other interrupt 408 | handling routines, the values for the 409 | registers r2, r3, r4 and r5 have not 410 | yet been saved in the stack. This is 411 | performed by a call on ``csv'' (lg20) 412 | which is automatically included by the 413 | ``C'' compiler at the beginning of every 414 | compiled procedure. The form of the 415 | call on ``csv'' is equivalent to the 416 | assembler instruction 417 | 418 | \begin{verbatim} 419 | jsr r5,csv 420 | \end{verbatim} 421 | 422 | This saves the current value of r5 on 423 | the stack and replaces it by the 424 | address of the next instruction in the 425 | ``C'' procedure. 426 | 427 | \bd 428 | \item[1421:] This value of r5 is copied into r0; 429 | 430 | \item[1422:] the current value of the stack 431 | pointer is copied into r5. 432 | \ed 433 | 434 | 435 | Note that at this point, r5 points to a 436 | stack location containing the previous 437 | value of r5 i.e. it points to the 438 | beginning of a chain of pointers, one 439 | per procedure, which ``thread'' the 440 | stack. When a ``C'' procedure exits, it 441 | actually returns to ``cret'' (1430) where 442 | the value of r5 is used to restore the 443 | stack and r2, r3 and r4 to their earlier condition (i.e. as they were 444 | immediately prior to entering the procedure). For this reason r5 is often 445 | called the {\bf environment pointer}. 446 | -------------------------------------------------------------------------------- /Original Files/ch14.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch14.tex, version 1.5, 17 May 1994 3 | % 4 | {\noindent \Large \bf Section Three} 5 | 6 | {\noindent \sf Section Three 7 | is concerned with basic 8 | input/output operations between the 9 | main memory and disk storage. 10 | 11 | These operations are fundamental to the 12 | activities of program swapping and the 13 | creation and referencing of disk files. 14 | 15 | This section also introduces procedures 16 | for the use and manipulation of the 17 | large (512 byte) buffers. 18 | } 19 | 20 | \se{Program Swapping} 21 | 22 | UNIX, like all time-sharing systems, 23 | and some multiprogramming systems uses 24 | ``program swapping'' (also called ``rollin/roll-out'') 25 | to share the limited 26 | resource of the main physical memory 27 | among several processes. 28 | 29 | Processes which are suspended may be 30 | selectively ``swapped out'' by writing 31 | their data segments (including the ``per 32 | process data'') into a ``swap area'' on 33 | disk 34 | 35 | The main memory area which was occupied 36 | can then be reassigned to other 37 | processes, which quite probably will be 38 | ``swapped in'' from the ``swap area''. 39 | 40 | Most of the decisions regarding ``swapping out'', and all the decisions 41 | regarding ``swapping in'', are made by 42 | the procedure ``sched''. ``Swapping in'' is 43 | handled by a direct call (2034) on the 44 | procedure ``swap'' (5196), whereas ``swapping out'' is handled by a call (2024) 45 | on ``xswap'' (4368). 46 | 47 | For those archaeologists who like to 48 | ponder the ``bones'' of earlier versions 49 | of operating systems, it seems that 50 | originally ``sched'' called ``swap'' 51 | directly to ``swap out'' processes, 52 | rather than via ``xswap''. The extra procedure (one of several to be found in 53 | the file ``text.c'') has been necessitated by the implementation of the 54 | sharable ``text segments''. 55 | 56 | It is instructive to estimate how much 57 | extra code has been necessitated by the 58 | text segment feature: in ``text.c'' are 59 | four procedures ``xswap'', ``xalloc'', 60 | ``xfree'' and ``xccdec'', which manipulate 61 | an array of structures called ``text'', 62 | which is declared in the file ``text.h''. 63 | Additional code has also been added to 64 | ``sysl.c'' and ``slp.c''. 65 | 66 | 67 | \sbs{Text Segments} 68 | 69 | Text segments are segments which contain only ``pure'' code and data i.e. 70 | code and data which remain unaltered 71 | throughout the program execution, so 72 | that they may be shared amongst several 73 | processes executing the same program. 74 | 75 | The resulting economies in space can be 76 | quite substantial when many users of 77 | the system are executing the same program simultaneously e.g. the editor or 78 | the ``shell''. 79 | 80 | Information about text segments must be 81 | stored in a central location, and hence 82 | the existence of the ``text'' array. Each 83 | program which shares a text segment 84 | keeps a pointer to the corresponding 85 | text array element in ``u.u\_textp''. 86 | 87 | The text segment is stored at the 88 | beginning of the code file. The first 89 | program to begin execution causes a 90 | copy of the text segment to be made in 91 | the ``swap'' area. 92 | 93 | When subsequently no programs are left 94 | which reference the text segment, the 95 | resources absorbed by the text segment 96 | are released. The main memory resource 97 | is released whenever there are no programs which reference the text segment 98 | currently in main memory; the ``swap'' 99 | area is released in general whenever 100 | there are no programs left running 101 | which reference the text segment. 102 | 103 | 104 | The numbers in each of these states are 105 | denoted by ``x\_ccount'' and ``x\_count'' 106 | respectively. Decrementing these 107 | numbers is handled by the routines 108 | ``xccdec'' and ``xfree'' which also take 109 | care of releasing resources when the 110 | counts reach zero. (``xccdec'' is called 111 | whenever a program is swapped out or 112 | terminates. ``xfree'' is called by ``exit'' 113 | whenever a program terminates.) 114 | 115 | \sbs{sched (1940)} 116 | 117 | Process \#0 executes ``sched''. When it is 118 | not waiting for the completion of an 119 | input/output operation that it has initiated, it spends most of its time 120 | waiting in one of the following situations: 121 | 122 | \bd 123 | \item[A. (runout)] 124 | None of the processes which are 125 | swap\-ped out is ready to run, so 126 | that there is nothing to do. The 127 | situation may be changed by a call 128 | to ``wakeup'', or to ``xswap'' called 129 | by either ``newproc'' or ``expand''. 130 | 131 | \item[B. (runin)] 132 | There is at least one process 133 | swapped out and ready to run, but 134 | it hasn't been out more than 3 135 | seconds and/or none of the 136 | processes presently in main memory 137 | is inactive or has been there more 138 | than 2 seconds. The situation may 139 | be changed by the effluxion of 140 | time as measured by ``clock'' or by 141 | a call to ``sleep''. 142 | \ed 143 | 144 | \noindent When either of these situations terminate: 145 | 146 | \bd 147 | \item[1958:] With the processor running at 148 | priority six, so that the clock 149 | can't interrupt and change values 150 | of ``p\_time'', a search is made for 151 | the process which is ready to run 152 | and has been swapped out for the 153 | longest time; 154 | 155 | \item[1966:] If there is no such process then 156 | situation A holds; 157 | 158 | \item[1976:] Search for a main memory area of 159 | adequate size to hold the data 160 | segment. If an associated text 161 | segment must be present also but 162 | is not currently in main memory, 163 | the area is increased by the size 164 | of the text segment; 165 | 166 | \item[1982:] If an area of adequate size is 167 | available the program branches to 168 | ``found2'' (2031). (Note that the 169 | program does not handle the case 170 | where there is sufficient space 171 | for both text and data segments 172 | but in distinct areas of main 173 | memory. Would it be worth while 174 | to extend the code to cover this 175 | possibility?); 176 | 177 | \item[1990:] Search for a process which is in 178 | main memory, but which is not the 179 | scheduler or locked (i.e. already 180 | being swapped out), and whose 181 | state is ``SWAIT'' or ``SSTOP'' (but 182 | {\bf not}\\ 183 | ``SSLEEP'') (i.e. the process 184 | is waiting for an event of low 185 | precedence, or has stopped during 186 | tracing (see Chapter Thirteen)). 187 | If such a process is found, go to 188 | line 2021, to swap the image out. 189 | 190 | Note that there seems to be a 191 | bias here against processes whose 192 | ``proc'' entries are early in the 193 | ``proc'' array; 194 | 195 | \item[2003:] If the image to be swapped in has 196 | been out less than 3 seconds, 197 | then situation B holds; 198 | 199 | \item[2005:] Search for the process which is 200 | loaded, but is not the scheduler 201 | or locked, whose state is ``SRUN'' 202 | or ``SSLEEP'' (i.e. ready to run, 203 | or waiting for an event of high 204 | precedence) and which has been in 205 | main memory for the longest time; 206 | 207 | \item[2013:] If the process image to be 208 | swapped out has been in main 209 | memory for less than 2 seconds, 210 | then situation B holds. 211 | 212 | The constant ``2'' here (also the 213 | ``3'' on line 2003) is somewhat 214 | arbitrary. For some reason the 215 | programmer has departed from his 216 | usual practice of naming such 217 | constants to emphasise their origins; 218 | 219 | \item[2022:] The process image is flagged as 220 | not loaded and is swapped out 221 | using ``xswap'' (4368). 222 | 223 | Note that the ``SSWAP'' flag is not 224 | set here because the process 225 | swapped out is not the current 226 | process. (Cf. lines 1907, 2286); 227 | 228 | \item[2032:] Read the text segment into main 229 | memory if necessary. Note that 230 | the arguments for the ``swap'' procedure are: 231 | \bi 232 | \item an address within the swap area of the disk; 233 | 234 | \item a main memory address (ordinal 235 | number of a 32 word block); 236 | 237 | \item a size (number of 32 word blocks 238 | to be transferred); 239 | 240 | \item a direction indicator 241 | (``B\_READ==1'' denotes ``disk to 242 | main memory''); 243 | \ei 244 | 245 | \item[2042:] Swap in the data segment and ... 246 | 247 | \item[2044:] Release the disk swap area to the 248 | available list, record the main 249 | memory address, set the ``SLOAD'' 250 | flag and reset the accumulated 251 | time indicator. 252 | \ed 253 | 254 | \sbs{xswap (4368)} 255 | 256 | \bd 257 | \item[4373:] If ``oldsize'' data was not supplied, use the current size of 258 | the data segment stored in ``u''; 259 | 260 | \item[4375:] Find a space in the disk swap 261 | area for the process's data segment. (Note that the disk swap 262 | area is allocated in terms of 512 263 | character blocks); 264 | 265 | \item[4378:] ``xccdec'' (4490) is called (unconditionally!) to decrease the 266 | count, associated with the text 267 | segment, of the number of ``in 268 | main memory'' processes which 269 | reference that text segment. If 270 | the count becomes zero, the main 271 | memory area occupied by the text 272 | segment is simply returned to the 273 | available space. (There is no 274 | need to copy it out, since, as we 275 | shall see, there will be a copy 276 | already in the disk swap area); 277 | 278 | \item[4379:] The ``SLOCK'' flag is set while the 279 | process is being swapped out. 280 | This is to prevent ``sched'' from 281 | attempting to ``swap out'' a process which is already in the process of being ``swapped out''. 282 | (This can only happen if ``swapping out'' was started initially 283 | by some routine other than 284 | ``sched'' e.g. by ``expand''); 285 | 286 | \item[4382:] The main memory image is released 287 | except when ``xswap'' is called by 288 | ``newproc''; 289 | 290 | \item[4388:] If ``runout'' is set, ``sched'' is 291 | waiting for something to ``swap 292 | in'', so wake it up. 293 | \ed 294 | 295 | \sbs{xalloc (4433)} 296 | 297 | ``xalloc'' is called by ``exec'' (3130), 298 | when a new program is being initiated, 299 | to handle the allocation of, or linking 300 | to, the text segment. The argument, 301 | ``ip'', is a pointer to the ``mode'' of the 302 | code file. At the time of this call, 303 | ``u.u\_arg[1]'' contains the text segment 304 | size in bytes. 305 | 306 | \bd 307 | \item[4439:] If there is no text segment, 308 | return immediately; 309 | 310 | \item[4441:] Look through the ``text'' array for 311 | both an unused entry and an entry 312 | for the text segment. If the 313 | latter can be found, do the bookkeeping and go to ``out'' (4474); 314 | 315 | \item[4452:] Arrange to copy the text segment 316 | into the disk swap area. Initialise the unused text entry, and 317 | get space in the disk swap area; 318 | 319 | \item[4459:] Change the space occupied by the 320 | process to one large enough to 321 | contain the ``per process data'' 322 | area and the text segment; 323 | 324 | \item[4460:] The call on ``estabur'' is necessary to set the user mode 325 | segmentation registers before reading the code file; 326 | 327 | \item[4461:] A UNIX process can only initiate 328 | one input/output operation at a 329 | time. Hence it is possible to 330 | store i/o parameters at standard 331 | locations in the ``u'' structure, 332 | viz. ``u.u\_count'', ``u.u\_offset[ ]'' and 333 | ``u.u\_base''; 334 | 335 | 336 | 337 | \item[4462:] The octal value 020 (decimal 16) 338 | is an offset into the code file; 339 | 340 | \item[4463:] Information is to be read into 341 | the area beginning at location 342 | zero in the user address space; 343 | 344 | \item[4464:] Read the text segment part of the 345 | code file into the current data 346 | segment; 347 | 348 | \item[4467:] ``Swap out'' the data segment 349 | (minus the ``per process data'') 350 | into the disk swap area reserved 351 | for the text segment; 352 | 353 | \item[4473:] ``Shrink'' the data segment -- it is 354 | about to be swapped out; 355 | 356 | \item[4475:] ``sched'' always ``swaps in'' the 357 | text segment before the data segment i.e. there is no mechanism 358 | for bringing the text segment 359 | into main memory once the data 360 | segment is present. If the text 361 | segment is not in main memory, 362 | get back into step by ``swapping 363 | out'' the data segment to disk. 364 | \ed 365 | 366 | It will be noted that the code to handle text segments is very conservative 367 | whenever the situation starts to get 368 | complicated. For example, the ``panic'' 369 | (4451) when no more text entries are 370 | available would seem to be a rather 371 | extreme reaction. However the strategy 372 | of being generous with ``text'' array 373 | space is quite likely to be less expensive than the code needed to do 374 | ``better''. What do you think? 375 | 376 | 377 | \sbs{xfree (4398)} 378 | 379 | ``xfree'' is called by ``exit'' (3233); 380 | when a process is being terminated, and 381 | by ``exec'' (3128), when a process is 382 | being transmogrified. 383 | 384 | \bd 385 | \item[4402:] Set the text pointer in the 386 | ``proc'' entry to ``NULL''; 387 | 388 | \item[4403:] Decrement the main memory count 389 | and if it is now zero ... 390 | 391 | \item[4406:] and if the text segment has not 392 | been flagged to be saved, ... 393 | 394 | \item[4408:] Abandon the image of the text 395 | segment in the disk swap area; 396 | 397 | \item[4411:] Call ``iput'' (7344) to decrement 398 | the ``inode'' reference count and 399 | if necessary delete it. 400 | \ed 401 | 402 | 403 | ``ISVTX'' (5695) is a mask which defines 404 | the ``sticky bit'' mentioned in section 405 | ``CHMOD(I)'' of the UPM. If this bit is 406 | set, the disk copy of the text segment 407 | is allowed to remain in the disk swap 408 | area even when no programs are running 409 | which reference it, in the expectation 410 | that it will be required again shortly. 411 | This is an efficient device for commonly used programs such as the ``shell'' 412 | or the editor. 413 | -------------------------------------------------------------------------------- /Original Files/ch9.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch9.tex, version 1.5, 18 May 1994 3 | % 4 | \section*{Section Two} 5 | 6 | {\sf Section Two is concerned with traps, 7 | hardware interrupts and software interrupts. 8 | 9 | Traps and hardware interrupts introduce 10 | sudden switches into the CPU's normal 11 | instruction execution sequence. This 12 | provides a mechanism for handling special conditions which occur outside the 13 | CPU's immediate control. 14 | 15 | Use is made of this facility as part of 16 | another mechanism called the ``system 17 | call'', whereby a user program may execute a ``trap'' instruction to cause a 18 | trap deliberately and so obtain the 19 | operating system's attention and assistance. 20 | 21 | The software interrupt (or ``signal'') is 22 | a mechanism for communication between 23 | processes, particularly when there is 24 | ``bad news''.} 25 | 26 | \se{Hardware Interrupts and Traps} 27 | 28 | In the PDP11 computer, as in many other 29 | computers, there is an ``interrupt'' 30 | mechanism, which allows the controllers 31 | of peripheral devices (which are devices external to the CPU) to interrupt 32 | the CPU at appropriate times, with 33 | requests for operating system service. 34 | 35 | 36 | The same mechanism has been usefully 37 | and conveniently applied to ``traps'' 38 | which are events internal to the CPU, 39 | which relate to hardware and software 40 | errors, and to requests for service 41 | from user programs. 42 | 43 | \sbs{Hardware Interrupts} 44 | 45 | The effect of an interrupt is to divert 46 | the CPU from whatever it was doing and 47 | to redirect it to execute another program. 48 | 49 | During a hardware interrupt: 50 | 51 | \bi 52 | \item The CPU saves the current processor 53 | status word (PS) and the current 54 | program count (PC) in its internal registers; 55 | 56 | \item the PC and PS are then reloaded from 57 | two consecutive words located in 58 | the low area of main memory. The 59 | address of the first of these 60 | two words is known as the 61 | ``{\bf vector location}'' of the interrupt; 62 | 63 | \item finally the original PC and PS values 64 | are stored into the newly 65 | current stack. (Whether this is 66 | the kernel or user stack depends 67 | on the new value of the PS.) 68 | \ei 69 | 70 | Different peripheral devices may have 71 | different vector locations. The actual 72 | vector location for a particular device 73 | is determined by hard wiring, and can 74 | only be changed with difficulty. Moreover there are well entrenched conventions for choosing vector locations for 75 | the various devices. 76 | 77 | Thus after the interrupt has occurred, 78 | because the PC has been reloaded, the 79 | source of instructions executed by the 80 | CPU has been changed. The new source 81 | should be a procedure associated with 82 | the peripheral device controller which 83 | caused the interrupt. 84 | 85 | 86 | Also since the PS has also been 87 | changed, the processor mode may have 88 | changed. In UNIX, the initial mode may 89 | be either ``user'' or ``kernel'', but after 90 | the interrupt, the mode is always ``kernel''. Recall also that a change in mode 91 | implies: 92 | 93 | \bd 94 | \item[(a)] a change in memory mappings. 95 | (Note that to avoid any confusion, vector locations are 96 | always interpreted as kernel 97 | mode addresses.); 98 | 99 | \item[(b)] a change in stack pointers. 100 | (Recall that the stack pointer, 101 | SP or r6, is the only special 102 | register which is replicated for 103 | each mode. This implies that 104 | after a mode change, the stack 105 | pointer value will have changed 106 | even though it has not been 107 | reloaded!) 108 | \ed 109 | 110 | \sbs{The Interrupt Vector} 111 | 112 | For our sample system, the representative peripheral devices chosen are 113 | listed in Table 9.1, along with their 114 | conventional hardware defined vector 115 | locations and priorities. 116 | 117 | \begin{center} 118 | \begin{tabular}{llcc} 119 | {\bf vector} & {\bf peripheral} & {\bf interrupt} & {\bf process} \\ 120 | {\bf location} & {\bf device} & {\bf priority} & {\bf priority} \\ \hline 121 | 060 & teletype input & 4 & 4 \\ 122 | 064 & teletype output & 4 & 4 \\ 123 | 070 & paper tape input & 4 & 4 \\ 124 | 074 & paper tape output & 4 & 4 \\ 125 | 100 & line clock & 6 & 6 \\ 126 | 104 & programmable & 6 & 6 \\ 127 | & clock & &\\ 128 | 200 & line printer & 4 & 4 \\ 129 | 220 & RK disk drive & 5 & 5 \\ 130 | \end{tabular} 131 | \bigskip 132 | 133 | {\bf Table 9.1 Interrupt Vector Locations and Priorities} 134 | \end{center} 135 | 136 | \sbs{Interrupt Handlers} 137 | 138 | Within this selection of UNIX source 139 | code, there are seven procedures known 140 | as ``interrupt handlers'', i.e. which are 141 | executed as the result of, and only as 142 | the result of, interrupts: 143 | 144 | \begin{verbatim} 145 | clock (3725) pcrint (8719) 146 | rkintr (5451) pcpint (8739) 147 | klxint (8070) lpint (8976) 148 | klrint (8078) 149 | \end{verbatim} 150 | 151 | \noindent ``clock'' will be examined in detail in 152 | Chapter 11. The others are discussed 153 | with the code for their associated devices. 154 | 155 | \sbs{Priorities} 156 | 157 | An interrupt does not necessarily occur 158 | immediately the peripheral device controller requests it, but only when the 159 | CPU is ready to accept it. It is usually desirable that a request for a low 160 | priority service should not be allowed 161 | to interrupt an activity with a higher 162 | priority. 163 | 164 | Bits 7 to 5 of the PS determine the 165 | processor priority at one of eight levels (labelled zero to seven). Each 166 | interrupt also has an associated priority level determined by hardware 167 | wiring. An interrupt will be inhibited as 168 | long as the processor priority is 169 | greater than or equal to the interrupt 170 | priority. 171 | 172 | 173 | After the interrupt the processor 174 | priority will be determined from the PS 175 | stored in the vector location and this 176 | does not have to be the same as the 177 | interrupt priority. Whereas the interrupt priority is determined by 178 | hardware, it is possible for the 179 | operating system to change the contents 180 | of the vector location at any time. 181 | 182 | 183 | As a matter of curiosity, it may be 184 | noted that the PDP11 hardware restricts 185 | the possible interrupt priorities to 4, 186 | 5, 6 and 7 i.e. levels 1, 2 and 3 are 187 | not supported by the Unibus. 188 | 189 | \sbs{Interrupt Priorities} 190 | 191 | In UNIX, interrupt handling routines 192 | are initiated at the same priority as 193 | the interrupt priority. 194 | 195 | This means that during the handling of 196 | the interrupt, a second interrupt from 197 | a device of the same priority class 198 | will be delayed until the processor 199 | priority is reduced, either by the execution of one of the ``spl'' procedures, 200 | which are intended for just this purpose (see lines 1293 to 1315), or by 201 | reloading the processor status word 202 | e.g. upon returning from the interrupt. 203 | 204 | During interrupt handling, the processor priority may be raised temporarily 205 | to protect the integrity of certain 206 | operations. For instance, character 207 | oriented devices such as the paper tape 208 | reader/punch or the line printer interrupt at level four. Their interrupt 209 | handlers call ``getc'' (0930) or ``putc'' 210 | (0967), which raise the processor 211 | priority temporarily to level five, 212 | while the character buffer queues are 213 | manipulated. 214 | 215 | The interrupt handler for the console 216 | teletype makes use of a ``timeout'' 217 | facility. This involves a queue which 218 | is also manipulated by the clock interrupt handler, which runs at level six. 219 | To prevent possible interference, the 220 | ``timeout'' procedure (3835) runs at 221 | level seven (the highest possible 222 | level). 223 | 224 | 225 | Usually it does not make sense to run 226 | an interrupt handler at a processor 227 | priority lower than the interrupt 228 | priority, for this would then risk a 229 | second interrupt of the same type, even 230 | from the same device, before completion 231 | of the processing of the first interrupt. This likely to be at 232 | best inconvenient and at worst disastrous. However the clock 233 | interrupt handler, which 234 | once per second has a lot of extra work 235 | to do, does exactly this. 236 | 237 | \sbs{Rules for Interrupt Handlers} 238 | 239 | As discussed above, interrupt handlers 240 | need to be careful about the manipulation of the processor priority to avoid 241 | allowing other interrupts to happen 242 | ``too soon''. Likewise care needs to be 243 | taken that the other interrupts are not 244 | delayed excessively, lest the performance of the whole system be degraded. 245 | It is important to note that when an 246 | interrupt occurs, the process which is 247 | currently active will very likely not 248 | be the process which is interested in 249 | the occurrence. Consider the following 250 | scenario: 251 | 252 | 253 | User process \#m is active and initiates 254 | an i/o operation. It executes a trap 255 | instruction and transfers to kernel 256 | mode. Kernel process \#m initiates the 257 | required operation and then calls 258 | ``sleep'' to suspend itself to await completion of the operation ... 259 | 260 | Some time later, when some other process, user process \#n say, is active, 261 | the operation is completed and an 262 | interrupt occurs. Process \#n reverts to 263 | kernel mode, and kernel process \#n 264 | deals with the interrupt, even though 265 | it may have no interest in or prior 266 | knowledge of the operation. 267 | 268 | 269 | Usually kernel process \#n will include 270 | waking process \#m as part of its 271 | activity. This will not always be the 272 | case though, e.g. where an error has 273 | occurred and the operation is retried. 274 | 275 | Clearly, the interrupt handler for a 276 | peripheral device should not made 277 | references to the current ``u'' structure 278 | for this is not likely to be the 279 | appropriate ``u'' structure. (The 280 | appropriate ``u'' structure could quite 281 | possibly be inaccessible, if it has 282 | been temporarily swapped out to the 283 | disk.) 284 | 285 | Likewise the interrupt handler should 286 | not call ``sleep'' because the process 287 | thus suspended will most likely be some 288 | innocent process. 289 | 290 | \sbs{Traps} 291 | 292 | ``Traps'' are like ``interrupts'' in that 293 | they are events which are handled by 294 | the same hardware mechanism, and hence 295 | by similar software mechanisms. 296 | 297 | ``Traps'' are unlike ``interrupts'' in that 298 | they occur as the result of events 299 | internal to the CPU, rather than externally. (In other systems the 300 | terminology ``internal interrupt'' and ``external 301 | interrupt'' is used to draw this distinction more forcefully.) Traps may 302 | occur unexpectedly as the result of 303 | hardware or power failures, or predictably and reproducibly, e.g. as the 304 | result of executing an illegal instruction or a ``trap'' instruction. 305 | 306 | 307 | ``Traps'' are always recognised by the 308 | CPU immediately. They cannot be delayed 309 | in the way low priority interrupts may 310 | be. If you like, ``traps'' have an 311 | ``interrupt priority'' of eight. 312 | 313 | ``Trap'' instructions may be deliberately 314 | inserted in user mode programs to catch 315 | the attention of the operating system 316 | with a request to perform a specified 317 | service. This mechanism is used as part 318 | of the facility known as ``system 319 | calls''. 320 | 321 | Like interrupts, traps result in the 322 | reloading of the PC and PS from a vector location, and the saving of the old 323 | values of the PC and PS in the current 324 | stack. Table 9.2 lists the vector locations for the various ``trap'' types. 325 | 326 | \begin{center} 327 | \begin{tabular}{llc} 328 | {\bf vector} & {\bf trap type} & {\bf process} \\ 329 | {\bf location} & & {\bf priority} \\ \hline 330 | 004 & bus timeout & 7 \\ 331 | 010 & illegal instruction & 7 \\ 332 | 014 & bpt-trace & 7 \\ 333 | 020 & iot & 7 \\ 334 | 024 & power failure & 7 \\ 335 | 030 & emulator trap instruction & 7 \\ 336 | 034 & trap instruction & 7 \\ 337 | 114 & 11/10 parity & 7 \\ 338 | 240 & programmed interrupt & 7 \\ 339 | 244 & floating point error & 7 \\ 340 | 250 & segmentation violation & 7 \\ 341 | \end{tabular} 342 | \bigskip 343 | 344 | {\bf Table 9.2 Trap Vector Locations and Priorities} 345 | \end{center} 346 | 347 | 348 | The contents of Tables 9.1 and 9.2 349 | should be compared with the file 350 | ``low.s'' on Sheet 05. As noted earlier, 351 | this file is generated at each installation (along with the file ``conf.c'' 352 | (sheet 46)), as the product of the 353 | utility program ``mkconf'', so as to 354 | reflect the actual set of peripherals 355 | installed. 356 | 357 | 358 | \sbs{Assembly Language `trap'} 359 | 360 | From ``low.s'' it appears that traps and 361 | interrupts are handled separately by 362 | the software. However closer examination reveals that ``call'' and ``trap'' are 363 | different entry points to a single code 364 | sequence in the file ``m40.s'' (see lines 365 | 0755, 0776). This sequence is examined 366 | in detail in the next chapter. 367 | 368 | 369 | During the execution of this sequence, 370 | a call is made on a ``C'' language procedure to carry out further specific 371 | processing. In the case of an interrupt, the ``C'' procedure 372 | is the interrupt handler specific to the particular 373 | device controller. 374 | 375 | In the case of a trap, the ``C'' procedure is another procedure called 376 | ``trap'' (yes, the word ``trap'' is definitely overworked!), which in the case 377 | process of a system error will most likely call 378 | priority ``panic'' and in the case of a ``system 379 | call'', will invoke (indirectly via 380 | ``trapl''(2841)) the appropriate system 381 | call procedure. 382 | 383 | \sbs{Return} 384 | 385 | Upon completion of the handling of an 386 | interrupt or trap the code follows a 387 | common path ending in an ``rtt'' instruction (0805). This reloads both the PC 388 | and PS from the current stack, i.e. the 389 | kernel stack, in order to restore the 390 | processor environment that existed 391 | before the interrupt or trap. 392 | -------------------------------------------------------------------------------- /Original Files/ch17.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch17.tex, version 1.5, 16 May 1994 3 | % 4 | \se{Buffer Manipulation} 5 | 6 | In this chapter we look at the file 7 | ``bio.c'' in detail. It contains most of 8 | the basic routines used to manipulate 9 | buffer headers and buffers (4535, 10 | 4720). 11 | 12 | 13 | Individual buffer headers are tagged by 14 | a device number ``b\_dev'', (4527) and a 15 | block number ``b\_blkno'', (4531). (Note 16 | the way in which the latter is declared 17 | as an unsigned integer.) 18 | 19 | Buffer headers may be linked simultaneously into two lists: 20 | 21 | \bd 22 | \item[the ``b''-lists] are lists, one per 23 | device controller, which link 24 | together buffers associated with 25 | that device type; 26 | 27 | \item[the ``av''-list] is a list of buffers 28 | which may be detached from their 29 | current use and converted to an 30 | alternate use. 31 | \ed 32 | 33 | Both the ``av''-list and the various 34 | ``b''-lists are doubly linked to facilitate insertion and deletion at any 35 | point. 36 | 37 | \sbs{Flags} 38 | 39 | If a buffer is withdrawn temporarily 40 | from the ``av''-list, then its ``B\_BUSY'' 41 | flag is raised. 42 | 43 | If the contents of a buffer correctly 44 | reflect the information that is or 45 | should be stored on disk, then the 46 | ``B\_DONE'' flag is raised. 47 | 48 | If the ``B\_DELWRI'' flag is raised, the 49 | contents of the buffer are more up to 50 | date than the contents of the 51 | corresponding disk block, and hence the 52 | buffer must be written out before it 53 | can be reassigned. 54 | 55 | 56 | \sbs{A Cache-like Memory} 57 | 58 | It will be seen that the large buffers 59 | in UNIX are manipulated in a way which 60 | is analogous to the operation of 61 | hardware cache attached to the main 62 | memory of a computer e.g. the PDP11/70. 63 | 64 | Buffers are not assigned to any particular program or file, except for very 65 | short intervals at a time. In this way 66 | a relatively small number of buffers 67 | can be shared effectively amongst a 68 | large number of programs and files. 69 | 70 | Information is left in the buffers 71 | until the buffer is needed i.e. immediate ``write through'' is avoided if only 72 | part of the buffer has recently been 73 | changed. Programs which read or write 74 | records which are small compared with 75 | the buffer size are then not penalised 76 | unduly. 77 | 78 | Finally when programs are terminated 79 | and files are closed, the problems of 80 | ensuring that the program's buffers are 81 | flushed properly (problems which have 82 | plagued other operating systems) have 83 | largely disappeared. 84 | 85 | There is one area of practical concern: 86 | if the decision ``when to write'' is left 87 | to the operating system alone, then 88 | some buffers may not be written out for 89 | a very long time. Accordingly there is 90 | a utility program which runs twice per 91 | minute and forces all such buffers to 92 | be written out unconditionally. This 93 | limits the likely amount of damage that 94 | a sudden system crash may cause. 95 | 96 | 97 | \sbs{clrbuf (5038)} 98 | 99 | This routine zeros out the first 256 100 | words (512 bytes) of the buffer. Note 101 | that the parameter passed to ``clrbuf'' 102 | is the address of the buffer header. 103 | ``clrbuf'' is called by ``alloc'' (6982). 104 | 105 | \sbs{incore (4899)} 106 | 107 | This routine searches for a buffer that 108 | is already assigned to a particular 109 | (device, block number) pair. It 110 | searches the circular ``b''-list whose 111 | head is the ``devtab'' structure for the 112 | device type. If a buffer is found, the 113 | address of the buffer header is 114 | returned. ``incore'' is called by 115 | ``breada'' (4780, 4788). 116 | 117 | \sbs{getblk (4921)} 118 | 119 | This routine performs the same search 120 | as ``incore'' but goes further in that if 121 | the initial search is unsuccessful, a 122 | buffer is allocated from the ``av''-list 123 | (available list). 124 | 125 | By a call on ``notavail'' (4999), the 126 | buffer is removed from the ``av''-list 127 | and flagged as ``B\_BUSY''. 128 | 129 | 130 | 131 | ``getblk'' is more suspicious of its 132 | parameters than ``incore''. It is called 133 | by 134 | 135 | \begin{verbatim} 136 | exec (3040) writei (6304) 137 | exit (3237) iinit (6928) 138 | bread (4758) alloc (6981) 139 | breada (4781,4789) free (7016) 140 | smount (6123) update (7216) 141 | \end{verbatim} 142 | 143 | 144 | \bd 145 | \item[4940:] At this point the required buffer 146 | has been located by searching the 147 | ``b''-list. Either it is ``B\_BUSY'' 148 | in which case a ``sleep'' must be 149 | taken (4943), or else it is 150 | appropriated (4948); 151 | 152 | \item[4953:] If the required buffer has not 153 | been located, and if the 154 | ``av''-list is empty, set the 155 | ``B\_WANTED'' flag for the ``av''-list 156 | and go to ``sleep'' (4955); 157 | 158 | \item[4960:] If the ``av''-list is not empty, 159 | select the first member, and if 160 | it represents a ``delayed write'' 161 | arrange to have it written out 162 | asynchronously (4962); 163 | 164 | \item[4966:] ``B\_RELOC'' is a relic! (See 4583); 165 | 166 | \item[4967:] The code from here until 4973 167 | unconditionally removes the 168 | buffer from the ``b''-list for its 169 | current device type and reinserts 170 | it into the bn-list for the new 171 | device type. Since this will frequently be a ``no-op'' i.e. the new 172 | and old device type will be the 173 | same, it would seem desirable to 174 | insert a test 175 | 176 | \begin{verbatim} 177 | if (bp->b_dev == dev) 178 | \end{verbatim} 179 | 180 | \noindent before executing lines 4967 to 181 | 4974. 182 | 183 | Note the special handling for calls where\\ 184 | ``dev == NODEV'' (--1). 185 | (Such calls incidentally are made 186 | without a second parameter - tut! 187 | tut! See e.g. 3040.) 188 | \ed 189 | 190 | ``bfreelist'' serves as the ``devtab'' 191 | structure for the ``b''-list for ``NODEV''. 192 | 193 | \sbs{brelse (4869)} 194 | 195 | This procedure takes the buffer passed 196 | as a parameter and links it back into 197 | the ``av''-list. 198 | 199 | Any process which is either waiting for 200 | the particular buffer or any available 201 | buffer is woken up. 202 | 203 | Note however that since both ``sleeps'' 204 | (4943, 4955) are at the same priority, 205 | if two processes are waiting -- one for 206 | the particular buffer and one for any 207 | buffer -- it will be a toss-up which 208 | will get it. 209 | 210 | By giving the first priority over the 211 | second (e.g. by biasing by one) the 212 | race should be resolved more satisfactorily. The disadvantage of such a 213 | change might be that it could lead to a 214 | deadlock situation in certain rather 215 | peculiar circumstances. 216 | 217 | If an error has occurred e.g. upon 218 | reading information into the buffer 219 | the information in the buffer may be 220 | incorrect. The assignment on line 4883 221 | ensures that the information in the 222 | buffer will not be mistakenly retrieved 223 | subsequently. The ``B\_ERROR'' flag is 224 | set e.g. by ``rkstrategy'' (5403) and 225 | ``rkintr'' (5467). 226 | 227 | To see how this could occur, consider 228 | what happens to a buffer when a disk 229 | i/o operation is completed: 230 | 231 | \bd 232 | \item[5471] ``rkintr'' calls ``iodone''; 233 | \item[5026] ``iodone'' sets the ``B\_DONE'' flag; 234 | \item[5028] ``iodone'' calls ``brelse''; 235 | \item[4387] ``brelse'' resets the ``B\_WANTED'', 236 | ``B\_BUSY'' and ``B\_ASYNC'' flags 237 | but not the ``B\_DONE'' flag; 238 | 239 | . . . . . . . . . . . . 240 | 241 | \item[4948] ``getblk'' finds the buffer and 242 | calls ``notavail''; 243 | \item[5010] ``notavail'' sets the ``B\_BUSY'' flag; 244 | \item[4759] ``bread'' (which called ``getblk'') 245 | finds the ``B\_DONE'' flag set and exits. 246 | \ed 247 | 248 | Note that buffer headers are removed 249 | from the ``av''-list by ``notavail'' and 250 | are returned by ``brelse''. Buffer 251 | headers are moved from one ``b''-list to 252 | another by ``getblk''. 253 | 254 | 255 | \sbs{binit (5055)} 256 | 257 | This procedure is called by ``main'' 258 | (1614) to initialise the buffer pool. 259 | Empty, doubly linked circular lists are 260 | set up: 261 | 262 | \bi 263 | \item for the ``av''-list (``bfreelist'' is 264 | head); 265 | 266 | \item the ``b''-list for null devices (``dev 267 | == NODEV'') (``bfreelist'' is again 268 | head); 269 | 270 | \item a ``b''-list for each major device 271 | type. 272 | \ei 273 | 274 | \noindent For each buffer: 275 | 276 | \bi 277 | \item the buffer header is linked into the 278 | ``b''-list for the device ``NODEV'' (--1); 279 | 280 | \item the address of the buffer is set in 281 | the header (5067); 282 | 283 | \item the buffer flags are set as ``B\_BUSY'' 284 | (this doesn't seem to be really 285 | necessary) (5072); 286 | 287 | \item the buffer header is linked into the 288 | ``av''-list by a call on ``brelse'' (5073); 289 | \ei 290 | 291 | 292 | The number of block devices is recorded 293 | as ``nblkdev''. This is used for checking 294 | values for ``dev'' in ``getblk'' (4927), 295 | ``getmdev'' (6192) and ``openi'' (6720). 296 | Inspection of ``bdevsw'' (4656) shows 297 | that ``nblkdev'' will be set to eight 298 | whereas the value one is what is really 299 | required. 300 | 301 | This result could be obtained by ``editing'' as follows: 302 | 303 | \begin{verbatim} 304 | /5084/m/5081/ "nblkdev=i; 305 | /5083/m/5077/ "i++ 306 | \end{verbatim} 307 | 308 | \sbs{bread (4754)} 309 | 310 | This is the standard procedure for 311 | reading from block devices. It is 312 | called by: 313 | 314 | \begin{verbatim} 315 | wait (3282) iinit (6927) 316 | breada (4799) alloc (6973) 317 | statl (6051) ialloc (7097) 318 | smount (6116) iget (7319) 319 | readi (6258) iupdat (7386) 320 | writei (6305) itrunc (7426, 7431) 321 | bmap (6472,6488) namei (7625) 322 | \end{verbatim} 323 | 324 | ``getblk'' finds a buffer. If the 325 | ``B\_DONE'' flag is set no i/o is needed. 326 | 327 | \sbs{breada (4773)} 328 | 329 | This procedure has an additional parameter, as compared with ``bread''. It is 330 | called only by ``readi'' (6256). 331 | 332 | \bd 333 | \item[4780:] Check if the desired block has 334 | already been assigned to a 335 | buffer. (It may not yet be 336 | available, but at least is it 337 | there?); 338 | 339 | \item[4781:] If not initiate the necessary 340 | read operation but don't wait for 341 | it to finish; 342 | 343 | \item[4788:] Look around for the ``read ahead'' 344 | block. If it is not there, allocate a buffer (4789) but release 345 | it (4791) if the buffer is 346 | already ready; 347 | 348 | \item[4793:] The ``read ahead'' block is not 349 | ready, so initiate an asynchronous read operation; 350 | 351 | \item[4798:] If a buffer was assigned to the 352 | current block call ``bread'' to 353 | wrap it up, else... 354 | 355 | \item[4800:] Wait for the completion of the 356 | operation which was started at 357 | line 4785. 358 | \ed 359 | 360 | 361 | \sbs{bwrite (4809)} 362 | 363 | This is the standard procedure for 364 | writing to block devices. It is called 365 | by ``exit'' (3239), ``bawrite'' (4863), 366 | ``getblk'' (4963), ``bflush'' (5241), 367 | ``free'' (7021), ``update'' (7221) and 368 | ``iupdat'' (7400). N.B. ``writei'' calls 369 | ``bawrite'' (6310)! 370 | 371 | \bd 372 | \item[4820:] If the ``B\_ASYNC'' flag is not set, 373 | the procedure does not return 374 | until the i/o operation is completed; 375 | 376 | \item[4823:] If the ``B\_ASYNC'' is set, but 377 | ``B DELWRI'' {\bf was} not set (note 378 | ``flag'' is set at line 4816) call 379 | ``geterror'' (5336) to check on the 380 | error flag. (If ``B\_DELWRI'' was 381 | set, and there is an error, sending the error indication to the 382 | right process is ``too hard.''). 383 | The call (4824) on ``geterror'' 384 | will only report errors related 385 | to the initiation of the write 386 | operation. 387 | \ed 388 | 389 | \sbs{bawrite (4856)} 390 | 391 | This procedure is called by ``writei'' 392 | (6310) and ``bdwrite'' (4845). ``writei'' 393 | calls either ``bawrite'' or ``bdwrite'' 394 | depending on whether the block to be 395 | written has been wholly or partially 396 | filled. 397 | 398 | 399 | \sbs{bdwrite (4836)} 400 | 401 | This procedure is called by ``writei'' 402 | (6311) and ``bmap'' (6443, 6449, 6485, 403 | 6500 and 6501 !). 404 | 405 | \bd 406 | \item[4844:] Don't delay the write if the device is a magnetic tape drive ... 407 | keep everything in order; 408 | 409 | \item[4847:] Set the ``B\_DONE'', ``B\_DELWRI'' 410 | flags and call ``brelse'' to link 411 | the buffer into the ``av''-list. 412 | \ed 413 | 414 | \sbs{bflush (5229)} 415 | 416 | This procedure is called by ``update'' 417 | (7201), which is called by ``panic'' 418 | (2420), ``sync'' (3489) and ``sumount'' 419 | (6150). 420 | 421 | ``bflush'' searches the ``av''-list for 422 | ``delayed write'' blocks and forces them 423 | to be written out asynchronously. 424 | 425 | Note that as ``notavail'' adjusts the 426 | links of the ``av''-list, the search 427 | (which runs at processor priority six) 428 | is reinitiated after each ``delayed 429 | write'' block is encountered. 430 | 431 | Note also that since it happens that 432 | ``bflush'' is only called by ``update'' 433 | with ``dev'' equal to ``NODEV'', line 5238, 434 | in particular, could be simplified. 435 | 436 | 437 | \sbs{physio (5259)} 438 | 439 | This routine is called to handle ``raw'' 440 | input/output i.e. operations which 441 | ignore the normal 512 character block 442 | size. 443 | 444 | ``physio'' is called by ``rkread'' (5476) 445 | and ``rkwrite'' (5483) which appear as 446 | entries in the array ``cdevsw'' (4684) 447 | 448 | ``Raw i/o'' is not an essential feature 449 | of UNIX. For disk devices it is used 450 | mainly for copying whole disks and 451 | checking the integrity of the file system as a whole (see e.g. ICHECK (VIII) 452 | in the UPM), where it is convenient to 453 | read whole tracks, rather than single 454 | blocks, at a time. 455 | 456 | Note the declaration of ``strat'' (5261). 457 | Since the actual parameter used e.g. 458 | ``rkstrategy'' (5389) does not return any 459 | value, is this form of declaration 460 | really necessary? 461 | -------------------------------------------------------------------------------- /Original Files/ch23.tex: -------------------------------------------------------------------------------- 1 | % 2 | % The Lion's Commentary, file ch23.tex, version 1.4, 16 May 1994 3 | % 4 | \se{Character Handling} 5 | 6 | Buffering for character special devices 7 | is provided via a set of four word 8 | blocks, each of which provides storage 9 | for six characters. The prototype 10 | storage block is ``cblock'' (8140) which 11 | incorporates a word pointer (to a similar 12 | structure) along with the six characters. 13 | 14 | Structures of type ``clist'' (7908) which 15 | contain a character counter plus a head 16 | and tail pointer are used as ``headers'' 17 | for lists of blocks of type ``cblock''. 18 | 19 | ``cblock''s which are not in current use 20 | are linked via their head pointers into 21 | a list whose head is the pointer 22 | ``cfreelist'' (3149). The head pointer 23 | for the last element of the list has 24 | the value ``NULL''. 25 | 26 | A list of ``cblock''s provides storage 27 | for a list of characters. The procedure 28 | ``putc'' may be used to add a character 29 | to the tail of such a list, and ``getc'', 30 | to remove a character from the head of 31 | such a list. 32 | 33 | Figures 23.1 through 23.4 illustrate 34 | the development of a list as characters 35 | are deleted and added. 36 | 37 | \input{fig23_1.tex} 38 | 39 | \input{fig23_2.tex} 40 | 41 | Initially the list is assumed to contain the fourteen characters 42 | ``efghijklmnopqr''. Note that the head 43 | and tail pointers point to {\bf characters}. 44 | If the first character, ``e'', is removed 45 | by ``getc'', the situation portrayed in 46 | Figure 23.1 changes to that of Figure 47 | 23.2. The character count has been 48 | decremented and the head pointer has 49 | been advanced by one character position. 50 | 51 | If a further character, ``f'', is removed 52 | from the head of the list, the 53 | situation becomes as in Figure 23.3. 54 | The character count has been decremented; 55 | the first ``cblock'' no longer 56 | contains any useful information and has 57 | been returned to ``cfreelist''; and the 58 | head pointer now points to the first 59 | character in the second ``cblock''. 60 | 61 | \input{fig23_3.tex} 62 | 63 | The question now poses itself: ``how is 64 | the difference between the first and 65 | second situations detected so that the 66 | action taken is always appropriate?'': 67 | 68 | The answer (if you have not already 69 | guessed) involves looklng at the value 70 | of the pointer address modulo 8. Since 71 | division by eight is easily performed 72 | on a binary computer, the reason for 73 | the choice of six characters per 74 | ``cblock'' should now also be apparent. 75 | 76 | The addition of a character to the list 77 | is illustrated in the change between 78 | Figure 23.3 and Figure 23.4. 79 | 80 | \input{fig23_4.tex} 81 | 82 | Since the last ``cblock'' ln Figure 23.3 83 | was full, a new one has been obtained 84 | from ``cfreelist'' and linked into the 85 | list of ``cblock''s. The character count 86 | and tail pointer have been adjusted appropriately. 87 | 88 | \sbs{cinit (8234)} 89 | 90 | This procedure, which is called once by 91 | ``main'' (1613), links the set of character buffers into the free list, 92 | ``cfreelist'', and counts the number of 93 | character device types. 94 | 95 | \bd 96 | \item[8239:] ``ccp'' is the address of the first 97 | word in the array ``cfree'' (8146); 98 | 99 | \item[8240:] Round ``ccp'' up to the next 100 | highest multiple of eight, and 101 | mark out ``cblock'' sized pieces, 102 | taking care not to exceed the 103 | boundary of ``cfree''. 104 | 105 | Note. In general there will be 106 | ``NCLIST -- 1'' (rather than 107 | ``NCLIST'') blocks so defined; 108 | 109 | \item[8241:] Set the first word of the 110 | ``cblock'' to point to the current 111 | head of the free list. 112 | 113 | Note that ``c\_next'' is defined on 114 | line 8141, and that the initial 115 | value of ``cfreelist'' is ``NULL''. 116 | 117 | \item[8242:] Update ``cfreelist'' to point to 118 | the new head of the list; 119 | 120 | \item[8244:] Count the number of character 121 | device types. Upon reference to 122 | ``cdevsw'' on Sheet 46, it will be 123 | seen that ``nchrdev'' will be set 124 | to 16, whereas a more appropriate 125 | value would be 10. 126 | \ed 127 | 128 | \sbs{getc (0930)} 129 | 130 | This procedure is called by 131 | 132 | \begin{verbatim} 133 | flushtty (8258, 8259, 8264) 134 | canon (8292) pcread (8688) 135 | ttstart (8520) pcstart (8714) 136 | ttread (8544) lpstart (8971) 137 | pcclose (8673) 138 | \end{verbatim} 139 | 140 | \noindent with a single argument which is the 141 | address of a ``clist'' structure. 142 | 143 | \bd 144 | \item[0931:] Copy the parameter to r1 and save 145 | the initial processor status word 146 | and value of r2 on the stack; 147 | 148 | \item[0934:] Set the processor priority to 149 | five (higher than the interrupt 150 | priority of a character device); 151 | 152 | \item[0936:] r1 points to the first word of a 153 | ``clist'' structure (i.e. a character count). Move the second word 154 | of this structure (i.e. a pointer 155 | to the head character) to r2; 156 | 157 | \item[0937:] If the list is empty (head 158 | pointer is ``NULL'') go to line 0961; 159 | 160 | \item[0938:] Move the head character to r0 and 161 | increment r2 as a side effect; 162 | 163 | \item[0939:] Mask r0 to get rid of any 164 | extended negative sign; 165 | 166 | \item[0940:] Store the updated head pointer 167 | back in the ``clist'' structure. 168 | (This may have to be altered 169 | later.); 170 | 171 | \item[0941:] Decrement the character count and 172 | if this is still positive, go to 173 | line 0947; 174 | 175 | \item[0942:] The list is now empty, so reset the head and tail 176 | character pointers to ``NULL''. Go to line 0952; 177 | 178 | \item[0947:] Look at the three least significant bits of r2. If these are 179 | non-zero, branch to line 0957 180 | (and return to the calling routine forthwith); 181 | 182 | \item[0949:] At this point, r2 is pointing at 183 | the next character position 184 | beyond the ``cblock''. Move the 185 | value stored in the first word of 186 | the ``cblock'' (i.e. at r2 -- 8), 187 | which is the address of the next 188 | ``cblock'' in the list to the head 189 | pointer in the ``clist''. (Note 190 | that r1 was incremented as a side 191 | effect at line 0941): 192 | 193 | \item[0950:] The last value stored needs to 194 | incremented by two (Consult 195 | Figures 23.2 and 23.3); 196 | 197 | \item[0952:] At this point, a 198 | ``cblock'' determined by r2 is to be returned to 199 | ``cfreelist''. Either r2 points 200 | into the ``cblock'' or just beyond 201 | it. Decrement r2 so that r2 will 202 | point into the ``cblock''; 203 | 204 | \item[0953:] Reset the three least significant 205 | bits of r2, leaving a pointer to 206 | the ``cblock''; 207 | 208 | \item[0954:] Link the ``cblock'' into ``cfreelist''; 209 | 210 | \item[0957:] Restore the values of r2 and PS 211 | from the stack and return; 212 | 213 | \item[0961:] At this point the list is known 214 | to be empty because a ``NULL'' head 215 | pointer was encountered. Make 216 | sure that the tail pointer is 217 | ``NULL'' also; 218 | 219 | \item[0962:] Move --1 to r0 as the result to be 220 | returned when the list is empty. 221 | \ed 222 | 223 | \sbs{putc (0967)} 224 | 225 | This procedure is called by 226 | 227 | \begin{verbatim} 228 | canon (8323) 229 | ttyinput (8355, 8358) 230 | ttyoutput (8414, 8478) 231 | pcrint (8730) 232 | pcoutput (8756) 233 | lpoutput (8990) 234 | \end{verbatim} 235 | 236 | \noindent with two arguments: a character and the 237 | address of a ``clist'' structure. 238 | 239 | ``getc'' and ``putc'' have related functions and 240 | the codes for the two procedures are similar in many respects. 241 | For this reason the code for ``putc'' 242 | will not be examined in detail, but is 243 | left for the reader. 244 | 245 | It should be noted that ``putc'' can fail 246 | if a new ``cblock'' is needed and 247 | ``cfreelist'' is empty. In this case a 248 | non-zero value (line 1002) is returned 249 | rather than a zero value (line 0996). 250 | 251 | {\bf Note.} The procedures ``getc'' and ``putc'' 252 | discussed here are {\bf NOT} directly related 253 | to the procedures d1scussed in the Sections 254 | ``GETC(III)'' and ``PUTC(III)'' of the UPM. 255 | 256 | \sbs{Character Sets} 257 | 258 | UNIX makes use of the full ASCII character set, 259 | which is displayed in Section ``ASCII(V)'' of the UPM. Since 260 | knowledge of this character set is 261 | often assumed without comment, not 262 | always justifiably, some comment here 263 | would seem to be in order. 264 | 265 | ``ASCII'' is an acronym for ``American 266 | Standard Code for Information Interchange''. 267 | 268 | \sbs{Control Characters} 269 | 270 | The first 32 of the 128 ASCII characters are non-graphic and are intended 271 | for the control of some aspect of 272 | transmission or display. The control 273 | characters explicitly used or recognised by UNIX are 274 | 275 | \noindent\begin{tabular}{llll}\\ 276 | {\bf Numeric} & & \multicolumn{1}{c}{\bf Description} & {\bf UNIX} \\ 277 | {\bf Value} & & & {\bf Name} \\ \hline 278 | 004 & eot & end of transmission & 004 \\ 279 | & & or (control-D) & \\ 280 | 010 & bs & back space & 010 \\ 281 | 011 & ht & (horizontal) tab & '\verb+\+t' \\ 282 | 012 & nl & new line or line feed & FORM \\ 283 | 014 & np & new page or form feed & '\verb+\+r' \\ 284 | 015 & cr & carriage return & '\verb+\+n' \\ 285 | 034 & fs & file separator or quit & CQUIT \\ 286 | 040 & sp & forward space or blank & '~' \\ 287 | 0177 & del & delete & CINTR 288 | \end{tabular} 289 | 290 | 291 | It will be noted that the last two of 292 | these belong to the last 96 characters 293 | or the graphic portion, of the code. 294 | 295 | \sbs{Graphic Characters} 296 | 297 | There are 96 graphic characters. Two of 298 | these, the space and the delete, are 299 | not ``visible'', and may be ciassified 300 | with the control characters. 301 | 302 | The graphic characters may be divided 303 | into three groups of 32 characters, 304 | which may be roughly characterised as 305 | 306 | \bi 307 | \item numeric and special characters 308 | \item upper case alphabetic characters 309 | \item lower case alphabetic characters. 310 | \ei 311 | 312 | Of course, since there are only 26 313 | alphabetic characters, the latter two 314 | groups include some special characters 315 | as well. In particular, the last group 316 | includes the following six nonalphabetic characters: 317 | 318 | \begin{tabular}{lll}\\ 319 | 140 & ` & reverse apostrophe \\ 320 | 173 & \{ & left brace \\ 321 | 174 & \verb+|+ & vertical bar \\ 322 | 175 & \} & right brace \\ 323 | 176 & \verb+~+ & tilde \\ 324 | 177 & & delete \\ 325 | \end{tabular} 326 | 327 | \sbs{Graphic Character Sets} 328 | 329 | Devices such as line printers or terminals which support {\bf all} the ASCII 330 | graphic symbols are often said to support the 96 ASCII character set (though 331 | there are only 94 graphics actually 332 | involved). 333 | 334 | Devices which support all the ASCII 335 | graphic symbols except those in the 336 | last group of 32, are said to support 337 | the 64 ASCII character set. Such devices lack the lower case alphabetics 338 | and the symbols listed above, namely ``\verb+~+'', ``\{'', ``\verb+|+'' and 339 | ``\verb+\}+''. Note that 340 | ``delete'', since it is not a visible 341 | character, can still be supported. 342 | 343 | Devices in this latter group may be 344 | referred to as ``upper case only''. 345 | 346 | Sometimes some of the graphic symbols 347 | may be non-standard, e.g. $\leftarrow$ instead 348 | of \_ and this can be inconvenient, 349 | though not usually fatal. 350 | 351 | UNIX prefers, as the reader is no doubt 352 | well aware, to view the world through 353 | ``lower case'' spectacles. Alphabetic 354 | characters received from an ``upper case 355 | only'' terminal are translated 356 | immediately upon receipt from upper 357 | case to lower case. A lower case alphabetic may subsequently be translated 358 | back to upper case if it is preceded by 359 | a single backslash. For output to such 360 | a terminal, both upper and lower case 361 | alphabetic characters are mapped to uppercase. 362 | 363 | %Equivalences for the five ``upper case'' 364 | %special characters are as follows: 365 | 366 | The conventions for line printers and 367 | terminals are different because: 368 | 369 | \bd 370 | \item[(a)] for line printers, horizontal 371 | alignment is usually important, 372 | and it is possible (without too 373 | much difficulty) to print composite, overstruck characters 374 | (using the minus sign in this 375 | case); and 376 | 377 | \item[(b)] for terminals, horizontal alignment is not considered to be so 378 | important; backspacing to provide overstruck characters does 379 | not work on most VDUs; and, 380 | since the same graphic conventions are used for both input 381 | and output, the symbols should 382 | be as convenient to type as possible. 383 | \ed 384 | 385 | \sbs{maptab (8117)} 386 | 387 | This array is used in the translation 388 | of character input from a terminal preceded by a single backslash, ``\verb+\+''. 389 | 390 | There are three characters, 004 (eot), 391 | `\#' and `@', which always have special 392 | meanings and need to be asserted by a 393 | backslash whenever they are to be 394 | interpreted literally. These three 395 | characters occur in ``maptab'' in their 396 | ``natural'' locations (i.e. their locations in the ASCII table). Thus for 397 | example `\#' has code 043 and 398 | 399 | \begin{verbatim} 400 | maptab[043] == 043. 401 | \end{verbatim} 402 | 403 | The other non-null characters in ``maptab'' are involved in the translation of 404 | input characters from ``upper case only'' 405 | devices and do not occur in their 406 | ``natural'' locations but in the location 407 | of their equivalent character, e.g. ``\verb+\+\{'' 408 | occurs in the natural location for ``\{'', 409 | since ``\verb+\+\{'' will be interpreted as ``\{'', 410 | etc. 411 | 412 | Note the situation regarding alphabetic 413 | characters. This is only explicable 414 | when it is remembered that the alphabetic characters are all translated to 415 | lower case before any backslash is 416 | recognised. 417 | 418 | \sbs{partab (7947)} 419 | 420 | This array consists of 256 characters, 421 | like ``maptab''. Unfortunately the initialisation of ``partab'' 422 | was omitted from the UNIX Operating System Source Code 423 | booklet. It is certainly needed, and so 424 | is given now: 425 | 426 | \begin{verbatim} 427 | char partab [] { 428 | 429 | 0001,0201,0201,0001,0201,0001,0001,0201, 430 | 0202,0004,0003,0205,0005,0206,0201,0001, 431 | 0201,0001,0001,0201,0001,0201,0201,0001, 432 | 0001,0201,0201,0001,0201,0001,0001,0201, 433 | 0200 0000,0000,0200,0000,0200,0200,0000, 434 | 0000 0200,0200 0000,0200,0000,0000,0200, 435 | 0000,0200,0200 0000,0200,0000,0000,0200, 436 | 0200,0000,0000,0200,0000,0200,0200,0000, 437 | 0200,0000,0000,0200,0000,0200,0200,0000, 438 | 0000,0200,0200,0000,0200,0000,0000,0200, 439 | 0000,0200,0200,0000,0200,0000,0000,0200, 440 | 0200 0000,0000 0200,0000,0200,0200,0000, 441 | 0000 0200,0200 0000,0200,0000,0000,0200, 442 | 0200,0000,0000,0200,0000,0200,0200,0000, 443 | 0200,0000,0000,0200,0000,0200,0200,0000, 444 | 0000,0200,0200,0000,0200,0000,0000,0201 445 | }; 446 | \end{verbatim} 447 | 448 | Each element of ``partab'' is an eight 449 | bit character, which, with the use of 450 | appropriate bitmasks (0200 and 0177), 451 | can be interpreted as a two part structure: 452 | 453 | \begin{tabular}{ll}\\ 454 | bit 7 & parity bit;\\ 455 | bits 3-5 & not used. Always zero;\\ 456 | bits 0-2 & code number.\\ 457 | \end{tabular} 458 | 459 | \bigskip 460 | 461 | The parity bit is appended to the seven 462 | bit ASCII code when a character is 463 | transmitted by the computer, to form an 464 | eight bit code with even parity. 465 | 466 | The code number is used by ``ttyoutput'' 467 | (8426) to classify the character into 468 | one of seven categories for determining 469 | the delay which should ensue before the 470 | transmission of the next character. 471 | (This is particularly important for 472 | mechanical printers which require time 473 | for the carriage to return from the end 474 | of a line, etc.) 475 | --------------------------------------------------------------------------------