.if n .pH portguide.STARTUP @(#)STARTUP	40.1
.\" Copyright 1989 AT&T 
..
.BK "Programmer's Guide: Porting the Kernel"
.CH "Startup" 2
.H 1 "Building UNIX"
.IX \f4cunix\f1(1M)
The tool \f3cunix\f1 is used to build the UNIX operating system
on a 3B2.
\f3cunix\fP examines each module in the \f3boot\f1 directory and
generates the appropriate kernel data structure.
That is, if a module is flagged as a block device then a \f4bdevsw\f1 entry 
is generated,
if a module is an exec type then an \f4execsw\f1 entry is generated, etc.
The file \f4conf.o\f1 is generated by \f3cunix\f1 and then linked with all the
boot modules to create a bootable absolute.
See also the \f4cunix\f1(1M) manual page.
.H 2 "Startup Procedure"
.IX startup procedure
The startup procedure described here is specific to a 3B2.
When the \f3boot\f1 program loads in a bootable absolute, control is passed to
the section COFF, or segment ELF, with the lowest loadable address.
These addresses are controlled by the loader directive files,
\f4vuifile\f1 and \f4ifile4.0\f1 for COFF
and \f4mapfile4.0\f1 for ELF.
See the COFF and ELF documentation about using control directives for the loader 
(the section
.ST "Object Files"
in the
.BT "Programmer's Guide: ANSI C and Programming Support Tools"
and ELF library routines that are in the section 3C manual pages).
The startup code for the 3B2 is in \f3ml/uprt.s\f1. 
.P
After an initial stack is set up, control is passed to \f4pstart\f1 in \f3pstart.c\f1.
The primary job of \f4pstart\f1 is to set up the kernel memory map in preparation 
for a switch to virtual mode.
In \f4pstart\f1 the \f2sgate, stext, sdata\f1, and \f2sbss\f1 variables are
initialized to zero.
This forces these variables to be put in the initialized data segment.
By being in the initialized data segment \f3cunix\f1 can find these variables
and overwrite them with the real virtual start of each section/segment.
This particular method is used because ELF mapfiles do not support the
initialization of variables to a location counter value as can be done in 
\f4ifile\f1 under COFF.
The adjusted symbols are then used to set up the virtual layout of the 
system, the size of each segment/section is initialized in the \f4mapfile\f1
or \f4ifile\f1.
Note also that the addresses of board specific registers are controlled 
in the loader directive files.
.P
\f4pstart\f1 also informs the firmware debugger as to where to find the 
operating system symbols for debugging.
This is strictly a 3B2 feature [see \f4sys3b\f1(2)] for information on the
internal symbol table.
.P
When the MMU tables have been properly initialized virtual mode can be
enabled and control is passed to \f4vstart_s\f1.
See the 
.CT "Directory - ML"
notes on \f4vtsart_s\f1 for the remaining process.
