Update license section.
[pintos-anon] / doc / intro.texi
1 @node Introduction, Pintos Tour, Top, Top
2 @chapter Introduction
3
4 Welcome to Pintos.  Pintos is a simple operating system framework for
5 the 80@var{x}86 architecture.  It supports kernel threads, loading and
6 running user programs, and a file system, but it implements all of
7 these in a very simple way.  In the Pintos projects, you and your
8 project team will strengthen its support in all three of these areas.
9 You will also add a virtual memory implementation.
10
11 Pintos could, theoretically, run on a regular IBM-compatible PC.  As
12 much fun as it might be, it is impractical to supply every student in
13 CS 140 with his or her own PC.  Therefore, we will run Pintos projects
14 in a PC simulator, that is, a program that simulates an 80@var{x}86
15 CPU and its peripheral devices well enough that unmodified operating
16 systems and software can run under it.  In class we will use the
17 @uref{http://bochs.sourceforge.net, , Bochs} simulator.  Pintos has
18 also been tested within @uref{http://fabrice.bellard.free.fr/qemu/, ,
19 qemu} and
20 @uref{http://www.vmware.com/products/server/gsx_features.html, ,
21 VMware GSX Server}.
22
23 These projects are hard.  CS 140 has a reputation of taking a lot of
24 time, and deservedly so.  We will do what we can to ease the pain,
25 such as providing a lot of support material, but to some extent there
26 is simply some amount of hard work that needs to be done.  Because
27 Pintos is a new system, it is also possible that some parts of the
28 projects are not only difficult, but more difficult than they should
29 be.  We welcome your feedback.  If you have suggestions on how we can
30 reduce the unnecessary overhead of assignments, cutting them down to
31 the important underlying issues, please let us know.
32
33 This chapter explains how to get started working with Pintos.  You
34 should read the entire chapter before you proceed to any of the
35 projects.
36
37 @menu
38 * Getting Started::             
39 * Pintos License::              
40 * Pintos Trivia::               
41 @end menu
42
43 @node Getting Started
44 @section Getting Started
45
46 To get started, you'll have to log into a machine that Pintos can be
47 built on.  For the purposes of CS 140, our ``officially supported''
48 Pintos development machines are the Sun Solaris machines managed by
49 Stanford ITSS, as described on the
50 @uref{http://www.stanford.edu/dept/itss/services/cluster/environs/sweet/,
51 , ITSS webpage}.  We will test your code on these machines, and the
52 instructions given here assume this environment.  However, Pintos and
53 its supporting tools are portable enough that it should build ``out of
54 the box'' in other environments, including the Linux machines managed
55 by ITSS.
56
57 Once you've logged into one of these machines, either locally or
58 remotely, start out by adding our binaries directory to your
59 @env{PATH} environment.  Under @command{csh}, the Stanford default
60 shell, you can do so with this command:
61 @example
62 set path = ( $path /usr/class/cs140/i386/bin )
63 @end example
64 @noindent
65 It might be a good idea to add this line into the @file{.cshrc} file
66 in your home directory.  Otherwise, you'll have to type it every time
67 you log in.
68
69 @menu
70 * Source Tree Overview::        
71 * Building Pintos::             
72 * Running Pintos::              
73 @end menu
74
75 @node Source Tree Overview
76 @subsection Source Tree Overview
77
78 Now you can extract the source for Pintos into a directory named
79 @file{pintos/src} by executing
80 @example
81 tar xzf /usr/class/cs140/pintos/pintos.tar.gz
82 @end example
83 Alternatively, retrieve
84 @uref{http://www.stanford.edu/class/cs140/pintos/pintos.tar.gz} and
85 extract it in a similar way.
86
87 Let's take a look at what's inside.  Here's the directory structure
88 that you should see in @file{pintos/src}:
89
90 @table @file
91 @item threads/
92 Source code for the base kernel, which you will modify starting with
93 project 1.
94
95 @item userprog/
96 Source code for the user program loader, which you will modify
97 starting with project 2.
98
99 @item vm/
100 An almost empty directory, where you will implement virtual memory in
101 project 3.
102
103 @item filesys/
104 Source code for a basic file system, which you will use starting with
105 project 2 but which you should not modify until project 4.
106
107 @item devices/
108 Source code for I/O device interfacing: keyboard, timer, disk, etc.
109 You will improve the timer implementation in project 1, but otherwise
110 you should have no need to change this code.
111
112 @item lib/
113 An implementation of a subset of the standard C library.  The code in
114 this directory is compiled into both the Pintos kernel and, starting
115 from project 2, user programs that run under it.  Headers in this
116 directory can be included using the @code{#include <@dots{}>}
117 notation.  You should have little need to modify this code.
118
119 @item lib/kernel/
120 Parts of the C library that are included only in the Pintos kernel.
121 This also includes implementations of some data types that you are
122 free to use in your kernel code: bitmaps, doubly linked lists, and
123 hash tables.
124
125 @item lib/user/
126 Parts of the C library that are included only in Pintos user programs.
127
128 @item tests/
129 Code for testing each project.
130
131 @item misc/
132 @itemx utils/
133 These files may come in handy if you decide to try working with Pintos
134 away from ITSS's Sun Solaris machines.  Otherwise, you can ignore
135 them.
136 @end table
137
138 @node Building Pintos
139 @subsection Building Pintos
140
141 The next thing to do is to try building the source code supplied for
142 the first project.  First, @command{cd} into the @file{threads}
143 directory.  Then, issue the @samp{make} command.  This will create a
144 @file{build} directory under @file{threads}, populate it with a
145 @file{Makefile} and a few subdirectories, and then build the kernel
146 inside.  The entire build should take less than 30 seconds.
147
148 Watch the commands executed during the build.  You should notice that
149 the build tools' names begin with @samp{i386-elf-}, e.g.@:
150 @code{i386-elf-gcc}, @code{i386-elf-ld}.  These are ``cross-compiler''
151 tools.  That is, the build is running on a Sparc machine (called the
152 @dfn{host}), but the result will run on an 80@var{x}86 machine (called
153 the @dfn{target}).  The @samp{i386-elf-@var{program}} tools, which
154 reside in @file{/usr/class/cs140/i386/bin}, are specially built for
155 this configuration.
156
157 Following the build, the following are the interesting files in the
158 @file{build} directory:
159
160 @table @file
161 @item Makefile
162 A copy of @file{pintos/src/Makefile.build}.  It describes how to build
163 the kernel.  @xref{Adding c or h Files}, for more information.
164
165 @item kernel.o
166 Object file for the entire kernel.  This is the result of linking
167 object files compiled from each individual kernel source file into a
168 single object file.  It contains debug information, so you can run
169 @command{gdb} or @command{backtrace} (@pxref{Backtraces}) on it.
170
171 @item kernel.bin
172 Memory image of the kernel.  These are the exact bytes loaded into
173 memory to run the Pintos kernel.  To simplify loading, it is always
174 padded out with zero bytes so that it is an exact multiple of 4 kB in
175 size.
176
177 @item loader.bin
178 Memory image for the kernel loader, a small chunk of code written in
179 assembly language that reads the kernel from disk into memory and
180 starts it up.  It is exactly 512 bytes long.  Its size is fixed by the
181 PC BIOS.
182
183 @item os.dsk
184 Disk image for the kernel, simply @file{loader.bin} followed by
185 @file{kernel.bin}.  This file is used as a ``virtual disk'' by the
186 simulator.
187 @end table
188
189 Subdirectories of @file{build} contain object files (@file{.o}) and
190 dependency files (@file{.d}), both produced by the compiler.  The
191 dependency files tell @command{make} which source files need to be
192 recompiled when other source or header files are changed.
193
194 @node Running Pintos
195 @subsection Running Pintos
196
197 To start the kernel that you just built in the Bochs simulator, first
198 @command{cd} into the newly created @file{build} directory.  Then
199 issue the command @code{pintos run}.  This command will create a
200 @file{bochsrc.txt} file, which is needed for running Bochs, and then
201 invoke Bochs.
202
203 Bochs opens a new window that represents the simulated machine's
204 display, and a BIOS message briefly flashes.  Then Pintos boots and
205 runs a simple test program that outputs a few screenfuls of text.
206 When it's done, you can close Bochs by clicking on the ``Power''
207 button in the window's top right corner, or rerun the whole process by
208 clicking on the ``Reset'' button just to its left.  The other buttons
209 are not very useful for our purposes.
210
211 (If no window appeared at all, and you just got a terminal full of
212 corrupt-looking text, then you're probably logged in remotely and X
213 forwarding is not set up correctly.  In this case, you can fix your X
214 setup, or you can use the @option{-v} option.)
215
216 The text printed by Pintos inside Bochs probably went by too quickly
217 to read.  However, you've probably noticed by now that the same text
218 was displayed in the terminal you used to run @command{pintos}.  This
219 is because Pintos sends all output both to the VGA display and to the
220 first serial port, and by default the serial port is connected to
221 Bochs's @code{stdout}.  You can log this output to a file by
222 redirecting at the command line, e.g.@: @code{pintos run > logfile}.
223
224 The @command{pintos} program offers multiple options for running
225 Pintos.  Specify these options on the command line @emph{before} the
226 @option{run} command.  Use @code{pintos help} to see a list of the
227 options.  You can select a simulator other than Bochs, although the
228 Leland systems only have Bochs installed.  You can start the simulator
229 running a debugger (@pxref{i386-elf-gdb}).  You can set the amount of
230 memory to give the VM.  Finally, you can set up how you want VM output
231 to be displayed: use @option{-v} to turn off the VGA display,
232 @option{-t} to use your terminal window as the VGA display instead of
233 opening a new window, or @option{-s} to suppress the serial output to
234 @code{stdout}.
235
236 The @command{pintos} program offers commands other than @samp{run} and
237 @samp{help}, but we won't have any need for them until project 2.
238
239 The Pintos kernel has its own command line that you can use to pass
240 options.  These options must be specified @emph{after} the
241 @option{run} command.  These options are not very interesting for now,
242 but you can see a list of them using the @option{-u} option, e.g.@:
243 @code{pintos run -u}.
244
245 @node Pintos License
246 @section Pintos License
247
248 Pintos is distributed under a liberal license that allows it to be
249 freely used, modified, and distributed.  Students and others own their
250 own code and may use it for any purpose.  In the context of Stanford's
251 CS 140 course, please respect the spirit and the letter of the honor
252 code by refraining from reading any homework solutions available
253 online or elsewhere.  (Source code for other operating system kernels,
254 such as Linux or FreeBSD, is of course fair game.)
255
256 There is NO WARRANTY for Pintos, not even for MERCHANTABILITY or
257 FITNESS FOR A PARTICULAR PURPOSE.
258
259 Please refer to the @file{LICENSE} file at the top level of the Pintos
260 source distribution for details of license and lack of warranty.
261
262 @node Pintos Trivia
263 @section Pintos Trivia
264
265 The design of Pintos is inspired by Nachos, an instructional operating
266 system originally from UC Berkeley, and even uses a few pieces of
267 Nachos code.  Pintos is different from Nachos in two important ways.
268 First, Nachos requires a host operating system such as Solaris,
269 whereas Pintos runs on real or simulated 80@var{x}86 hardware.
270 Second, Nachos is written in C++, whereas, like most real-world
271 operating systems, Pintos is written in C.
272
273 The name ``Pintos'' was chosen for multiple reasons.  First, it was
274 named for a Mexican food to reflect that it was inspired by Nachos.
275 Second, Pintos is small and a ``pint'' is a small quantity.  Third,
276 like drivers of the eponymous car, students are likely to have trouble
277 with blow-ups.