BSD 3 development
[unix-history] / usr / doc / regen
CommitLineData
4a1fa43d
BJ
1.TL
2REGENERATING SYSTEM SOFTWARE
3.AU
4For UNIX/32V
5
6Thomas B. London
7.AU
8John F. Reiser
9.HO
10.SH
11Introduction
12.PP
13This document discusses how to
14assemble or compile various parts of the
15.UX \s-2/32V\s0
16system software.
17This may be necessary because
18a command or library is accidentally
19deleted or otherwise
20destroyed;
21also, it may be desirable to install a modified
22version of some command or library routine.
23A few commands depend
24to some degree on the current configuration
25of the system;
26thus in any new system modifications to some commands
27are advisable.
28Most of the likely modifications
29relate to the standard disk devices contained
30in the system.
31For example, the df(1) (`disk free')
32command has built into it the names of
33the standardly present disk storage drives
34(e.g. `/dev/rf0', `/dev/rp0').
35Df(1) takes an argument to indicate which
36disk to examine, but it is convenient
37if its default argument is adjusted to
38reflect the ordinarily present devices.
39The companion document `Setting up UNIX'
40discusses which commands are likely to require
41changes.
42.SH
43Where Commands and Subroutines Live
44.PP
45The
46source files for commands and subroutines reside
47in several subdirectories
48of the directory /usr/src.
49These subdirectories, and a general
50description of their contents, are
51.IP cmd 12
52Source files for commands.
53.IP libc/stdio 12
54Source files making up the `standard i/o package'.
55.IP libc/sys 12
56Source files for the C system call interfaces.
57.IP libc/gen 12
58Source files for most of the remaining routines described
59in section 3 of the manual.
60.IP libc/crt 12
61Source files making up the C runtime support package, as
62in call save-return and long arithmetic.
63.IP libc/csu 12
64Source for the C startup routines.
65.IP games 12
66Source for (some of) the games.
67No great care has been taken to try to make it obvious how
68to compile these; treat it as a game.
69.IP libF77 12
70Source for the Fortran 77 runtime library, exclusive of IO.
71.IP libI77 12
72Source for the Fortran 77 IO runtime routines.
73.IP libdbm 12
74Source for the `data-base manager' package
75.I dbm
76(3).
77.IP libm 12
78Source for the mathematical library.
79.IP libnm 12
80Source for the assembler language mathematical library.
81.IP libplot 12
82Source for plotting routines.
83.SH
84Commands
85.PP
86The regeneration of most commands
87is straightforward.
88The `cmd' directory will contain either a source file
89for the command or a subdirectory containing the set
90of files that make up the command.
91If it is a single file the command
92.DS
93cd /usr/src/cmd/Admin
94Mk cmd_name.c
95.DE
96suffices. (Cmd_name is the name of the command you
97are playing with.)
98The result of the Mk command will be an executable version,
99copied to /bin
100(or perhaps /etc or other places if appropriate).
101If you want the result placed somewhere else, the command
102.DS
103cd /usr/src/cmd/Admin
104DESTDIR=mydir Mk cmd_name.c
105.DE
106where mydir is a full pathname of some destination directory
107(e.g. /usr/tbl/newcmds),
108will compile the command and place the result in mydir/bin
109(or perhaps mydir/etc or mydir/usr/bin, etc.).
110.PP
111If the source files are in a subdirectory there will be a `makefile'
112(see make(1)) to control the regeneration.
113After changing to the proper directory (cd(1)) you type one of the following:
114.IP "make" 15
115The program is compiled and loaded; the executable is
116left in the current directory.
117.IP "make install" 15
118The program is compiled and loaded, and the executable is
119installed.
120.IP "make clean" 15
121Everything is cleanup; for example .o files are deleted.
122.PP
123Some of the makefiles have other options. Print (cat(1)) the ones you
124are interested in to find out.
125.PP
126Alternately, to compiler and install a subdirectory command, one may
127perform the following
128.DS
129cd /usr/src/cmd/Admin
130Mk cmd_name
131.DE
132which combines all three of the above make options.
133.SH
134The Assembler
135.PP
136The assembler consists of one executable file:
137/bin/as.
138The source files for /bin/as
139are named `/usr/src/cmd/as/as?.c'.
140Considerable care should be exercised
141in replacing the
142assembler.
143Remember that if the assembler is lost,
144the only recourse is to replace it from some backup storage;
145a broken assembler cannot assemble itself.
146.SH
147The C Compiler
148.PP
149The C compiler consists of
150six routines:
151`/bin/cc',
152which calls the phases of the compiler proper,
153the compiler control line expander `/lib/cpp',
154the assembler (`as'), and the loader (`ld').
155The C compiler proper is `/lib/ccom';
156`/lib/c2' is the optional
157assembler-language optimizer.
158The loss of the C compiler is as serious
159as that of the assembler.
160.PP
161The source for /bin/cc
162resides in `/usr/src/cmd/cc.c'.
163Its loss alone (or that of c2) is not fatal.
164If needed,
165prog.c can be compiled by
166.DS
167/lib/cpp prog.c >temp0
168/lib/ccom temp0 temp1
169as temp3
170ld /lib/crt0.o a.out \-lc
171.DE
172.PP
173The source for the compiler proper is in the
174directories /usr/src/cmd/mip and /usr/src/cmd/pcc.
175The /usr/src/cmd/mip directory contains files which are
176(relatively) machine independent;
177the machine dependent files reside in the
178directory /usr/src/cmd/pcc.
179The compiler is `made' by the makefile (see make(1))
180in the directory /usr/src/cmd/pcc.
181To make a new /lib/ccom use
182.DS
183cd /usr/src/cmd/pcc
184make
185.DE
186which produces the compiler
187(named /usr/src/cmd/pcc/comp).
188Before installing the new compiler,
189it is prudent to save the old one someplace.
190.PP
191In a similar manner,
192the optimizer phase of the C compiler
193(/lib/c2)
194is made up from the files
195c20.c, c21.c, and c22.c together with c2.h.
196Its loss is not critical since it is completely optional.
197.SH
198UNIX
199.PP
200The source and object programs for UNIX are kept in
201two subdirectories of
202.I /usr/src/sys.
203In the subdirectory
204.I h
205there are several files ending in `.h';
206these are header files which are
207picked up (via `#include ...')
208as required by each system module.
209The subdirectory
210.I sys
211is the rest of the system.
212.PP
213The file
214.I conf.c
215contains the tables which control
216device configuration of the system.
217.I Locore.s
218specifies the
219contents of the interrupt vectors,
220and all the
221machine-language code in the system.
222.PP
223To recreate the system, use
224.DS
225cd /usr/src/sys/sys
226make unix
227.DE
228See `Setting Up UNIX' for other information about configuration
229and such.
230.PP
231When the make is
232done, the new system is present in the
233current directory as `unix'.
234It should be tested before destroying the currently
235running `/unix', this is best done by doing something like
236.DS
237mv /unix /ounix
238mv unix /unix
239.DE
240If the new system doesn't work, you can still boot `ounix'
241and come up (see boot(8)).
242When you have satisfied yourself that the new system works,
243remove /ounix.
244.PP
245To install a new device driver,
246copy its source to /usr/src/sys/sys,
247and edit the `makefile' and the file `loadall' if
248necessary (see make(1)).
249.PP
250Next, the I/O interrupt fielding mechanism must be modified
251to properly handle the new device.
252If the device is connected via the UNIBUS, then one only
253need add the device's interrupt handling routine address(s)
254in the proper position in the table `UNIvec' in the
255file /usr/src/sys/sys/univec.c.
256`UNIvec'
257should be modified
258by placing a pointer to a callout routine
259in the proper vector.
260Use some other device (like the DZ11) as a guide.
261Notice that the entries in `UNIvec' must be in order.
262Bits 27-31 of the vector address
263will be available as the first argument of the interrupt routine.
264This stratagem is used when
265several similar devices share the same interrupt routine
266(as in dz11's).
267.PP
268If the device is connected via the MASSBUS,
269then /usr/src/sys/sys/univec.c is not to be modifed.
270Instead, code must be added to /usr/src/sys/sys/locore.s
271to actually transfer to the interrupt routine.
272Use the RP06 interrupt routine `Xmba0int' in locore.s as a guide.
273As an aside, note that
274external names in C programs have an
275underscore (`_') prepended to them.
276.PP
277The second step which must be performed to add a new
278device is
279to add it to the configuration table
280/usr/src/sys/sys/conf.c.
281This file contains two subtables, `bdevsw' and `cdevsw',
282one for block-type devices, and one for character-type devices.
283Block devices include disks, and magtape.
284All other devices are character devices.
285A line in each of these tables gives all the information
286the system needs to know about the device handler;
287the ordinal position of the line in the table implies
288its major device number, starting at 0.
289.PP
290There are four subentries per line in the block device table,
291which give its open routine, close routine, strategy routine, and
292device table.
293The open and close routines may be nonexistent,
294in which case the name `nulldev' is given;
295this routine merely returns.
296The strategy routine is called to do any I/O,
297and the device table contains status information for the device.
298.PP
299For character devices, each line in the table
300specifies a routine for open,
301close, read, and write, and one which sets and returns
302device-specific status (used, for example, for stty and gtty
303on typewriters).
304If there is no open or close routine, `nulldev' may
305be given; if there is no read, write, or status
306routine, `nodev' may be given.
307Nodev sets an error flag and returns.
308.PP
309The final step which must
310be taken to install a device is to make a special file for it.
311This is done by mknod(1), to which you must specify the
312device class (block or character),
313major device number (relative line in the configuration table)
314and minor device number
315(which is made available to the driver at appropriate times).
316.PP
317The documents
318`Setting up Unix' and
319`The Unix IO system'
320may aid in comprehending these steps.
321.SH
322The Library libc.a
323.PP
324The library /lib/libc.a is where most of the subroutines
325described in sections 2 and 3 of the manual are kept.
326This library
327can be remade using the following commands:
328.DS
329cd /usr/src/libc
330make libc.a
331make install
332make clean
333.DE
334If single routines need to be recompiled and replaced, use
335.DS
336cc \-c \-O x.c
337ar vr /lib/libc.a x.o
338rm x.o
339.DE
340The above can also be used to put new items into the library.
341See ar(1), lorder(1), and tsort(1).
342.PP
343The routines in /usr/src/cmd/libc/csu (C start up) are not in
344libc.a. These are separately assembled and put into
345/lib. The commands to do this are
346.DS
347cd /usr/src/libc
348for i in csu/*.s
349do
350 j=`basename $i .s`
351 as -o $j.o $i
352 mv $j.o /lib
353done
354.DE
355or, if you need only redo one routine,
356.DS
357cd /usr/src/libc/csu
358as -o x.o x.s
359mv x.o /lib
360.DE
361where x is the routine you want.
362.SH
363Other Libraries
364.PP
365Likewise,
366the directories containing the source for the other libraries
367have makefiles.
368.SH
369System Tuning
370.PP
371There are several tunable parameters in the system. These set
372the size of various tables and limits. They are found in the
373file /usr/sys/h/param.h as manifests (`#define's).
374Their values are rather generous in the system as distributed.
375Our typical maximum number of users is about 20, but there are
376many daemon processes.
377.PP
378When any parameter is changed, it is prudent to recompile
379the entire system, as discussed above.
380A brief discussion of each follows:
381.IP NBUF 12
382This sets the size of the disk buffer cache. Each buffer is 512 bytes.
383This number should be around 25 plus NMOUNT,
384or as big as can be if the above number of
385buffers cause the system to not fit in memory.
386.IP NFILE 12
387This sets the maximum number of open files. An entry is made in
388this table every time a file is `opened' (see open(2), creat(2)).
389Processes share these table entries across forks (fork(2)). This number
390should be about the same size as NINODE below. (It can be a bit smaller.)
391.IP NMOUNT 12
392This indicates the maximum number of mounted file systems. Make it
393big enough that you don't run out at inconvenient times.
394.IP MAXMEM 12
395This specifies the number of page-frames of real memory at this
396installation.
397It is currently set at 1024 (512K bytes), and should be increased
398if you have more (otherwise the additional memory will not be utilized).
399.IP MAXUMEM 12
400This sets an administrative limit on the amount of memory
401a process may have.
402It is currently set at MAXMEM-128 (i.e. 896).
403It will be increased automatically by increasing MAXMEM.
404Note, however, that the current upper bound on MAXUMEM is 128*12
405(i.e. 1536) which limits user process space to 768K bytes.
406.IP PHYSPAGES 12
407This indicates the number of pages which can be represented
408on the memory freelist.
409Its current value is 2048, and is sufficient for systems of
410up to one megabyte.
411If this value is too small (i.e. more memory than freelist)
412then system will only use PHYSPAGES page frames.
413.IP MAXUPRC 12
414This sets the maximum number of processes that any one user can
415be running at any one time. This should be set just large enough
416that people can get work done but not so large that a user can
417hog all the processes available (usually by accident!).
418.IP NPROC 12
419This sets the maximum number of processes that can be
420active.
421It depends on the demand pattern of the typical user;
422we seem to need about 8 times the number
423of terminals.
424.DE
425.IP NINODE 12
426This sets the size of the inode table. There is one entry in the inode
427table for every open device, current working directory,
428sticky text segment,
429open file, and mounted device.
430Note that if two users have a file open there is still only one entry
431in the inode table. A reasonable rule of thumb for the size of
432this table is
433.DS
434NPROC + NMOUNT + (number of terminals)
435.DE
436.IP SSIZE 12
437The initial size of a process stack. This may be made bigger
438if commonly run processes have large data areas on the stack.
439.IP SINCR 12
440The size of the stack growth increment.
441.IP NOFILE 12
442This sets the maximum number of files that any one process can have
443open.
44420 is plenty.
445.IP CANBSIZ 12
446This is the size of the typewriter canonicalization buffer. It is
447in this buffer that erase and kill processing is done. Thus this
448is the maximum size of an input typewriter line. 256 is usually
449plenty.
450.IP SMAPSIZ 12
451The number of fragments that secondary (swap) memory can be
452broken into.
453This should be big enough that it never runs out.
454The theoretical maximum is twice the number of processes,
455but this is a vast overestimate in practice.
45670 seems enough.
457.IP NCALL 12
458This is the size of the callout table. Callouts are entered in this
459table when some sort of internal system timing must be done, as in
460carriage return delays for terminals. The number must be big enough
461to handle all such requests.
462.IP NTEXT 12
463The maximum number of simultaneously executing pure programs. This
464should be big enough so as to not run out of space under heavy load.
465A reasonable rule of thumb is about
466.DS
467(number of terminals) + (number of sticky programs)
468.DE
469.IP NCLIST 12
470The number of clist segments. A clist segment is 12 characters.
471NCLIST should be big enough so that the list doesn't become exhausted
472when the machine is busy. The characters that have arrived from a terminal
473and are waiting to be given to a process live here. Thus enough space
474should be left so that every terminal can have at least one average
475line pending (about 30 or 40 characters).
476.IP TIMEZONE 12
477The number of minutes westward from Greenwich. See `Setting Up UNIX'.
478.IP DSTFLAG 12
479See `Setting Up UNIX' section on time conversion.
480.IP MSGBUFS 12
481The maximum number of characters of system error messages saved. This
482is used as a circular buffer.
483.IP NCARGS 12
484The maximum number of characters in an exec(2) arglist. This
485number controls how many arguments can be passed
486into a process.
4875120 is practically infinite.
488.IP HZ 12
489Set to the desired frequency of the system clock (e.g., 50 for
490a 50 Hz. clock).
491The current value is 60 (i.e. 60 Hz. clock).