*BSD News Article 16172


Return to BSD News archive

Xref: sserve comp.os.386bsd.announce:55 comp.os.386bsd.questions:2491
Path: sserve!newshost.anu.edu.au!munnari.oz.au!spool.mu.edu!uwm.edu!cs.utexas.edu!sun-barr!ames!agate!agate!usenet
From: burgess@hrd769.brooks.af.mil (Dave Burgess)
Newsgroups: comp.os.386bsd.announce,comp.os.386bsd.questions
Subject: 386bsd/NetBSD FAQ Section 3
Followup-To: comp.os.386bsd.questions
Date: 15 May 1993 22:12:29 -0700
Organization: University of California, Berkeley
Lines: 563
Sender: cgd@agate.berkeley.edu
Approved: 386bsd-announce-request@agate.berkeley.edu
Message-ID: <9305131744.AA13418@hrd769.brooks.af.mil>
NNTP-Posting-Host: agate.berkeley.edu



Section 3.	(Kernel Building and Maintenance)
3.1	Kernel

  One of the interesting aspects of 386bsd is the fact that it comes with
  the complete source.  This allows you to make changes to the system,
  recompile, and test out your new ideas.  This section of the FAQ
  describes many of the different aspects of this endeavor and common
  problems and pitfalls that are encountered.  Kevin Lahey provided the
  substantial portion of this section.  You can contact him via E-Mail 
  at (kml@rokkaku.atl.ga.us) or contact Dave Burgess 
  (burgess@hrd769.brooks.af.mil).


3.1.1	How do I build a kernel?

  The kernel can be compiled in a variety of ways to support
  different devices and configurations.  Compilation is controlled by a
  config file that specifies the characteristics of the kernel.
  A set of different config files is located in /sys/i386/conf.
  The configuration file names are in upper case.

  To build a particular kernel (in this example, we use the GENERICISA
  configuration file):

	% cd /sys/i386/conf
	% config GENERICISA
	% cd /sys/compile/GENERICISA
	% make depend
	% make

  You'll need patch 1 from the patchkit to get the compilation to work,
  'cause the version file isn't correctly included in the makefile.


3.1.2	I want to do one of the following things:
	* add a device not in the distributed kernel (third com
	  port, additional disk or tape, line printer driver, etc).
	* use a patch from the net or the patchkit to fix a kernel bug.
	* add another swap device.
	* recompile the kernel to remove extraneous devices so that
	  it takes up less space.
	* configure more pseudo-terminals to allow for more xterms
	  or network logins.
	
  You're going to have to recompile the kernel after you modify the config 
  file.  See section 3.2 below for more information about the config file
  in general.
  

3.1.3	I don't have the source distribution -- how can I rebuild the
	kernel?

  You can get the source for just the kernel from agate.berkeley.edu in the 
  directory /pub/386BSD/386bsd-0.1/filesystem/usr/src/sys.386bsd.  In 
  addition, you will need to get a few include files, and make sure that 
  all of the files that are actually symbolic links point to the right
  places.  It is around five megs of source and maybe another meg compiled.  
  There are also reference sites available, as well as the 'good net-neighbor'
  policy, whereby you could make arrangements with a net neighbor to use
  a large local machine as a Network File System, or allow you to compile
  a mew kernel on their machine and transfer it to yours.  If you *still* 
  can't fit it in, you'll have to ftp a compiled kernel from agate in the
  unofficial/patchkit-old directory or one of the archive sites.  You can
  also ask for help from comp.os.386bsd.questions if you get stuck and 
  cannot make any headway.


3.1.4	Now that I have a kernel, how do I install it?

  Your kernel is called /386bsd.  Copy the new kernel from 
  /sys/compile/GENERICISA/386bsd to /, assuming that it is in that directory.
  This is relatively straightforward; there are a couple of things to 
  remember, though.  First, if you really screw up the new kernel, you want 
  to have something to fall back on, so be sure to save /386bsd to 
  /386bsd.old before copying in a new kernel.  Second, if you just copy the 
  new kernel over the currently running kernel, funny things can happen.  Be 
  sure to move aside the currently running kernel before copying over the new 
  one.  

  There are folks that have reported that overwriting their current kernel
  has never caused them any real problems.  On the other hand, if the old
  kernel was working and the new one doesn't, and you have made changes that
  require that old kernel, it should be available to the system, and saving
  it to /386bsd.alt or /386bsd.old are reasonable things to do.

  If you are really paranoid, you can mount a new fixit floppy and replace 
  its kernel with the one you just built, and then boot from the fixit floppy 
  to make sure everything will work.  This is a pretty good idea if you are 
  making radical changes or if you are unsure about your changes.


3.1.5	After installing the patchkit and recompiling the kernel with the
	option "WD8013", i am no longer able to reboot the machine. A cold
	boot (power on) runs fine, but after a reboot no boot drive is found
	by the BIOS. Besides having a 16-bit WD/SMC Ethernet card installed
	the machines try to boot using either a Adaptec 1742 or 1542 SCSI
	board to boot from.

  This answer was provided by Hellmuth Michaelis (hm@hcshh.hcs.de) and 
  written by Rodney Grimes (rgrimes@acacia).

  Remove "option WD8013" from the config files and recompile and
  reinstall the kernel. 

  The reason that option Wd8013 often causes this reboot problem is 
  this:
	
  There is a requirement that all memory within a 128k bank in the
  0xA0000 to 0xFFFFF region be either 16-bit or 8-bit.  Is what happens
  is on a cold boot the WD8013 boards are reset to 8-bit mode, the POST
  (Power On Self Test) passes without error.  386bsd comes up, the 
  if_we.c driver places the WD8013 in 16-bit mode.  Now on a soft boot
  when the BIOS runs some quick POST tests it finds a problem in the 
  0xA000 to 0xF000 region.  You probably get a "beep-beep" when this
  happens.  It means you have a memory size conflict.
  The machine has been misconfigured.
	
    This is a little known fact about 16-bit vs 8-bit option cards.  It
  has caused more than one person to go crazy tracking down what they
  swear is a bug in the program.  It is not, it is a flaw in the design
  of the ISA bus.  The signal MEMCS16- must be returned the same for
  every 128k block of memory:
  
  	B0000-CFFFF	Must all be either 8-bit or 16-bit.
  	D0000-FFFFF	Must all be either 8-bit or 16-bit.
  
    In your particular configuration (WD8013 @ cc000) I suspect that
  you have another board in the B0000-CFFFFF region that is 8-bit, ie
  your adaptec has an 8-bit BIOS on it!
  
    Try moving the board to the 0xD0000 region and see if it works there,
  you may still have a problem as many modern system bioses are now 8-bit.
  If your system bios is 8-bit, try shadowing the system bios region
  at 0xF0000 to 0xFFFFF, this effectively turns it into a 16-bit bios.
  
    Do not attempt to shadow the WD8013, it well cause you many headaches.
  
    As always, works for me, you milage may vary..
  


3.2	What exactly is this config file, anyway?  What are all of
	these cryptic notations?

  I've annotated the distributed GENERICISA file;  my comments are delineated 
  by the '--' symbols.

  #
  # GENERICISA -- Generic ISA machine -- distribution floppy
  #
--  BSD can be compiled for different hardware platforms, so it is important to
--  define the hardware types.  386bsd can only be built for 386 or
--  compatible machines, so this is sort of superfluous, but maintains
--  compatibility with standard BSD config files.
  machine		"i386"
  cpu		"i386"
--  The ident describes the machine for which this kernel is to be built.
--  It is usually the system name -- "ROKKAKU", "REF", or whatever.
--  This can be used for conditional compilation, so that kernel changes
--  can be compiled in only for one machine.
  ident		GENERICISA
--  This should indicate the timezone of the system relative the
--  Greenwich.   8 is PST;  4 is EST.  Somebody else might want to discuss
--  this more fully.
  timezone	8 dst
--  maxusers isn't strictly checked;  it is just used to size several
--  system data parameters.
  maxusers	10
--  The options control the conditional compilation of features into the
--  kernel.  The options can be listed all on a line separated by commas.
--  They are #define'ed when the kernel is compiled, so that #ifdef's
--  will work.  An option can be given a value by appending an equals sign
--  and a value (enclosed in double quotes) to the option name.
  
--  Hopefully the names are at least somewhat self-explanatory.  To
--  discover what everything does, you'd have to go through the kernel
--  looking for all of the appropriate #ifdef's.
  
--  [Perhaps somebody else could list the *exact* meanings of these
--  options and some of the other possible options?]
  options		INET,ISOFS,NFS
  options		"COMPAT_43"
  options		"TCP_COMPAT_42"
  
--  The config line controls the location of the root, swap, and dump
--  devices.  Anything not specified is defaulted.  This is where you add
--  support for multiple swap devices.  Just list 'em, separated by 'and'.
--  The config line below identifies the root drive as wd0 and the
--  swap drives as wd0 and as0.  See the section on swap devices in FAQ_02
--  for additional information.
  config		"386bsd"	root on wd0 swap on wd0 and as0
--  A 'controller' is a device or bus controller.  'isa' is obviously for
--  the ISA bus.  'wd0' is for regular disk controllers,  'fd0' is for the
--  floppies, and 'as0' is for SCSI disk controllers.
  controller	isa0
--  The fields work as follows:
  
--  a.  What do you call this device?  
--  b.  What controller is this on?  As you can see, the disk controller
--  talks to the ISA bus, and the disks talk to the disk controller.
--  c.  Where are the registers for the controller mapped into memory?
--  This is #defined in /sys/i386/isa/isa.h.
--  d.  What IRQ is this device set up for?
--  e.  What routine should be called on an interrupt from the device?
  
--               a          b           c             d           e
--              vvv        vvv       vvvvvvv          vv        vvvvvv
  controller	wd0	at isa? port "IO_WD1" bio irq 14 vector wdintr
--  You need a 'disk' entry for every disk on the controller.  In the
--  config file originally shipped with 386bsd, both hard disks were 
--  incorrectly identified as wd0.  Be sure to change the second occurrence 
--  to wd1, as I have done in below.
  disk		wd0	at wd0 drive 0
  disk		wd1	at wd0 drive 1
  
  controller	fd0	at isa? port "IO_FD1" bio irq 6 drq 2 vector fdintr
  disk		fd0	at fd0 drive 0
  disk		fd1	at fd0 drive 1

--  The 'drq' specifies the channel used for bus-mastering DMA.
  controller	as0	at isa? port 0x330 bio irq 11 drq 5 vector asintr
  disk		as0	at as0 drive 0
  disk		as1	at as0 drive 1

--  Define other physical devices.  pc0 is the keyboard, npx0 drives the
--  math coprocessor, and com* controls the com ports.
  device		pc0	at isa? port "IO_KBD" tty irq 1 vector pcrint
  device		npx0	at isa? port "IO_NPX" irq 13 vector npxintr
  device		com1	at isa? port "IO_COM1" tty irq 4 vector comintr
  device		com2	at isa? port "IO_COM2" tty irq 3 vector comintr
  
--  Ethernet drivers of various sorts and the particular configuration
--  information they require.
  device we0 at isa? port 0x280 net irq 2 iomem 0xd0000 iosiz 8192 vector weintr
  device ne0 at isa? port 0x300 net irq 2 vector neintr
  device ec0 at isa? port 0x250 net irq 2 iomem 0xd8000 iosiz 8192 vector ecintr
  device is0 at isa? port 0x280 net irq 10 drq 7 vector isintr

--  Tape driver
  device		wt0	at isa? port 0x300 bio irq 5 drq 1 vector wtintr
  
--  The TCP/IP loop-back device, ethernet interface, slip interface, log
--  device, and pseudo-terminals.
  pseudo-device	loop
  pseudo-device	ether
  pseudo-device	sl	2
  pseudo-device	log
  pseudo-device	pty	4
  
--  Devices required by VM. 
  pseudo-device	swappager
  pseudo-device	vnodepager
  pseudo-device	devpager
  

3.2.1	Okay, fine.  Why shouldn't I just add every device I can find to
	the kernel, so I'll never have to recompile this again?

  Because it takes up space.  The kernel is wired into memory, so every 
  byte it uses comes out of the pool of memory for everything else.  It 
  can't page out sections that aren't in use.  If your kernel is larger 
  than 640K, then it can't be loaded.  You'll need to use Julian Elischer's
  bootblocks to put it in high memory, which seem to be fairly complex.
  Installing them (once they are compiled) is as easy as using disklabel.


3.2.2	What should I remove from the kernel?

  What do you need?  If you only have an SCSI controller, you don't need 
  the wd0 device;  if you have another kind of disk controller, you don't 
  need as0.  Unless you actually HAVE more than one Ethernet controller, you 
  should comment out all but one of them.  If you don't have an ethernet 
  controller, you don't need any of the controllers or NFS compiled in.  
  Without a CD-ROM, ISOFS is kind of pointless.  Just look at what you have 
  and think about what you really need.


3.2.3	I can't get enough remote login sessions or xterm sessions.  What
	can I do?

  Increase the count of pseudo-terminals --

	pseudo-device	pty	12  # or whatever

  Every pseudo terminal should have a /dev/pty* entry.  If you have 12
  pseudo terminals, you should also have at least 12 pty devices in the
  /dev directory.  The MAKEDEV script in /dev will create as many pseudo-
  terminals as you tell it to.


3.2.4	How do I get ddb, the kernel debugger, compiled into the kernel
	and running?

  Add the following line to the configuration file:

	pseudo-device	ddb

  Build the kernel, then run dbsym on it:

  % dbsym ./386bsd

  Install it and go for it.  Ctl-Alt-Esc drops you into the debugger.

  Note: DDB as shipped originally is a memory hog, and it is very
  difficult to get a kernel small enough with enough fun things in it
  to debug in 640K


3.2.5	Can I have more than one config file?  Should I rename it to something
	else?  Any other hints?  

  You can create as many (or as few) config files as you desire.  The system,
  once the patchkit is applied, will have between 10 and 15, each of which
  implements certain functions or features.  In addition, the normal place
  for the patchkit to make changes to the config files is in the
  GENERICISA file.  Since this file should remain unchanged and available,
  it is always a good idea to copy this file to a meaningful name and
  modify that file.  In other words, change every reference in 3.1.1 from
  GENERICISA to HAL (or whatever you call your system).

  One final note.  Every /sys/compile directory takes up 800K or so;
  you might want to watch to see how big these all get.


3.2.6	What is the meaning of the trap codes I get in panic messages ?


Trap	0	Divide Error
		The DIV or IDIV instruction is executed with a zero denominator
		or the quotient is too large for the destination operand.
	
	
Trap	1	Debug Exceptions
		Used in conjunction with DR6 and DR7, The following flags
		need to be tested to determine what caused the trap:
		BS=1				Single-step trap
		B0=1 AND (GE0=1 or LE0=1)	Breakpoint, DR0, LEN0, R/W0
		B1=1 AND (GE1=1 or LE1=1)	Breakpoint, DR1, LEN1, R/W1
		B2=1 AND (GE2=1 or LE2=1)	Breakpoint, DR2, LEN2, R/W2
		B3=1 AND (GE3=1 or LE3=1)	Breakpoint, DR3, LEN3, R/W3
		BD=1				Debug registers not available,
						in use by ICE-386
		BT=1				Task Switch
			
	
Trap	2	NMI Interrupt
		On PC/AT systems, the NMI input to the CPU is usually
		connected to the main memory parity circuit.  By the time the
		error signal is generated, the data may have already been
		used in an instruction, so it isn't possible to reliably
		recover.
	
		And some not-so-common causes (from various sources):

		  PS50+ : I/O channel check, system watch-dog timer 
		  time-out interrupt, DMA timer time-out interrupt

		  parity errors on any 8-bit or 16-bit board pulling the 
		  IOCHCK* line low 

		  first generation of auto-switching EGA cards used NMI to trap port
		  access for CGA emulation (e.g., ATI's EGA Wonder)
	
		  Zeos Notebook low battery (perhaps other battery-based 
		  computers)


Trap	3	Breakpoint
		The result of executing an INT 3 instruction.  MS-DOS and
		Windows and some other non-386 systems use this for debugging.
		Code specific to the 386 and later processors should use
		the debugging features tied to Trap 1.
	
	
Trap	4	INT0 Detected Overflow
		Occurs if an INT0 instruction is executed and the overflow
		flag (OF) is currently set.
	
	
Trap	5	BOUND Range Exceeded
		Occurs if the BOUND instruction is executed and the array
		index points beyond the area of memory containing the array
		being tested.
	
	
Trap	6	Invalid Opcode
		The value read at CS:IP is not a valid opcode.
	
	
Trap	7	Coprocessor Not Available
		This occurs if the processor fetches an instruction that is
		for the coprocessor and no coprocessor is present.
	
	
Trap	8	Double Exception (Fault)
		An exception occurred while trying to execute the handler
		for a prior exception.  Example, an application causes a
		General Protection Fault (13) and the area of memory where
		the GPF handler should be is flagged not-present (paged-out?).
		The double-fault handler is invoked in these conditions.
		If a fault occurs while trying to run the double-fault handler,
		a triple-fault occurs and the CPU resets.
	
		The rules for deciding if a double-fault should occur or
		if the two faults can be handled serially are discussed in
		more detail in the Intel song book.
	
	
Trap	9	Coprocessor Segment Overrun
		A page or segment violation occurred while transferring
		the middle part of a coprocessor operand to the NPX.
	
	
Trap	10	Invalid Task State Segment
		During a task switch, the new TSS was invalid.  Here is
		a table of conditions that Invalidate the TSS:
		TSS id + EXT	The limit in the TSS descriptor is < 103
		LTD id + EXT	Invalid LDT selector or LDT not present
		SS id + EXT	Stack segment selector is outside table limit
		SS id + EXT	Stack segment is not a writable segment
		SS id + EXT	Stack segment DPL does not match new CPL
		SS id + EXT	Stack segment selector RPL <> CPL
		CS id + EXT 	Code segment is outside table limit
		CS id + EXT	Code segment selector does not refer to
					code segment
		CS id + EXT	DPL of non-conforming code segment <> new CPL
		CS id + EXT	CPL of conforming code segment > new CPL
		DS/ES/FS/GS id + EXT	DS, ES, FS or GS segment selector is
					outside table limits
		DS/ES/FS/FS id + EXT	DS, ES, FS, or GS is not readable
					segment


Trap	11	Segment Not Present
		Occurs when the "present" bit of a descriptor is zero.
		This can occur while loading any of these segment registers
		CS, DS, ES, FS, or GS.  Loading SS causes a Stack fault.
		Also occurs when attempting to use a gate descriptor that is
		marked "not present", and if attempting to load the LDT with
		an LLDT instruction.  Note that loading the LDT during a
		task switch causes an "invalid TSS" trap.


Trap	12	Stack Fault
		A limit violation relating to an address referenced off
		the SS register.  Includes POP, PUSH, ENTER and LEAVE
		opcodes, as well as references such as MOV AX,[BP+8]
		(which has an implied SS:).
		Also causes by loading SS with a descriptor that is marked
		"not present".


Trap	13	General Protection Fault (GPF)
		Americas Favorite, in the Windows 3.0 world, it is known as
		the UAE error.  The instruction tried to access data out of
		the bounds designated by the descriptors.  The access that
		failed can be a read, write or instruction fetch.  There are
		15 classifications of GPFs:
		1.  Exceeding segment limit when using CS, DE, ES, FS or GS.
		2.  Exceeding segment limit when referencing a descriptor
		    table.
		3.  Transferring control to a segment that is not executable.
		4.  Writing into a read-only data segment or into a code
		    segment.
		5.  Reading from an execute-only segment.
		6.  Loading the SS register with a read-only descriptor
		    (unless the selector comes from the TSS during a task
		    switch, in which case a TSS exception occurs.)
		7.  Loading SS, DS, ES, FS or GS with the descriptor of a
		    system segment.
		8.  Loading, DS, ES, FS or GS with the descriptor of an
		    executable segment that is not also readable.
		9.  Loading SS with the descriptor of an executable segment.
		10. Accessing memory via, DS, ES, FS or GS when the segment
		    register contains a null selector.
		11. Switching to a busy task.
		12. Violating priviledge rules.
		13. Loading CR0 with a PG=1 and PE=0.
		14. Interrupt or exception via trap or interrupt gate from
		    V86 mode to prviledge level other than zero.
		15. Exceeding the instruction limit of 15 bytes (this can
		    only occur if redundant prefixes are placed before an
		    instruction).
		To determine which condition caused the trap, you need
		the instruction, the contents of all associated registers,
		particularly the segment registers involved, then the various
		LDT, GDT and page control tables.  Lots of common coding
		errors cause the GPFs.  Even a stack imbalance will usually
		show up as a GPF.   Even MOV AX,7 MOV ES,AX or 
		MOV AX,5 PUSH AX POP DS will get a GPF error.  You can't
		use a segment register for "temporary storage" of any
		old value the way you could on the 8086.  The values loaded
		into the segment registers are checked in protected mode.


Trap	14	Page Fault
		The page directory or page table entry needed for the address
		translation has a zero in the present bit, or the current
		procedure does not have sufficient priviledge to access the
		indicated page.

Trap	15	(reserved)


Trap	16	Coprocessor Error
		The coprocessor asserted the ERROR# input pin on the 386
		(internal on the 486)


Trap	17	Alignment Check (486 and later)
		If enabled, this trap will occur if a data fetch does not
		occur on a word boundary.  I don't know of any software that
		activates this feature yet.  I have seen SCO UNIX get this
		error on early Cyrix processors, even though SCO had not
		enabled the feature.


Trap	18-32	(reserved)

[anwered by 	Frank Durda IV <uhclem@nemesis.lonestar.org>	and
		jim mullens jcm@ornl.gov  -or- mullens@jamsun.ic.ornl.gov]
	
-------------------------------------------------------------------------------

hope this helps!
hellmuth
-- 
 hellmuth michaelis    HCS Hanseatischer Computerservice GmbH    hamburg, europe
hm@hcshh.hcs.de             tel: +49/40/55903-170          fax: +49/40/5591486


3.2.7	Where can I learn more about all this?

  We've skipped over a lot of details here;  the straight dope comes from
  "Building Berkeley UNIX Kernels with Config", by Samuel J. Leffler and
  Michael J. Karels. 

3.3	X11/XFree86/XS3
3.3.1	What options should I define to get the X extensions included?

  Once you have applied the patch kit, the only thing left to do is to
  modify the config file to include the following line:

	options	XSERVER, UCONSOLE
 
  recompile the kernel and the kernel should support X.

3.3.2	Where can I get the FAQ for 'X'?

  Answers to frequently asked questions about XFree86 on 386BSD are
  available by anonymous ftp from agate.berkeley.edu (128.32.136.1) in
  /pub/386BSD/0.1-ports/XFree86-1.2/XFree86-1.2-386BSD-FAQ.  It
  supplements the more introductory material distributed with XFree86 1.2
  in README.386BSD.  It also supplements Steve Kotsopoulos' more general
  'X on Intel-based Unix' FAQ available by anonymous ftp from
  export.lcs.mit.edu in /contrib/Intel-Unix-X-faq.

3.4	Compiler and Library routines
--
Please send submissions for comp.os.386bsd.announce to:
					386bsd-announce@agate.berkeley.edu