[openfirmware] r1050 - cpu/arm/Linux cpu/arm/build cpu/x86 cpu/x86/pc cpu/x86/pc/emu cpu/x86/pc/emu/build dev/isa dev/ne2000 dev/video dev/video/build dev/video/common dev/video/controlr

svn at openfirmware.info svn at openfirmware.info
Sun Dec 28 04:58:44 CET 2008


Author: wmb
Date: 2008-12-28 04:58:44 +0100 (Sun, 28 Dec 2008)
New Revision: 1050

Added:
   cpu/x86/pc/emu/
   cpu/x86/pc/emu/addrs.fth
   cpu/x86/pc/emu/build/
   cpu/x86/pc/emu/build/Makefile
   cpu/x86/pc/emu/config.fth
   cpu/x86/pc/emu/devices.fth
   cpu/x86/pc/emu/emuofw.bth
   cpu/x86/pc/emu/fw.bth
   cpu/x86/pc/emu/pcinode.fth
   cpu/x86/pc/emu/pmreset.bth
   cpu/x86/pc/emu/probemem.fth
   cpu/x86/pc/emu/rmreset.bth
   cpu/x86/startmacros.fth
   dev/isa/soundblaster.fth
   dev/ne2000/build/
   dev/ne2000/ne2kpci.bth
   dev/ne2000/ne2kpci.fth
   dev/video/build/video.bth
   dev/video/cirrus.bth
   dev/video/controlr/cirruspci.fth
   dev/video/loadcirrus.fth
Modified:
   cpu/arm/Linux/
   cpu/arm/build/
   cpu/x86/pc/linux.fth
   dev/video/common/pci.fth
   dev/video/controlr/cirrus.fth
   dev/video/controlr/vga.fth
Log:
Added a new platform directory "cpu/x86/pc/emu" for building a version
that can run as a direct ROM image under QEMU and perhaps eventually
VirtualBox and VMWare.  Also added some drivers in support of that version,
notably ne2000 Ethernet, Cirrus video, and SoundBlaster.



Property changes on: cpu/arm/Linux
___________________________________________________________________
Added: svn:ignore
   + armforth
forth



Property changes on: cpu/arm/build
___________________________________________________________________
Added: svn:ignore
   + armbuild
build


Added: cpu/x86/pc/emu/addrs.fth
===================================================================
--- cpu/x86/pc/emu/addrs.fth	                        (rev 0)
+++ cpu/x86/pc/emu/addrs.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,65 @@
+\ See license at end of file
+purpose: Establish address and I/O configuration definitions
+
+\ Dropin-base is where the set of dropin modules, the verbatim
+\ image of what is stored in ROM or on disk, ends up in memory.
+\ If OFW is in FLASH, dropin-base can just be the FLASH address.
+\ If OFW is pulled in from disk, dropin-base is where the very
+\ early startup code - the first few instructions in the image -
+\ copies it to get it out of the way of things like OS load areas.
+
+h# fff8.0000 constant dropin-base  \ Location of payload in FLASH
+dropin-base h# 20 +  constant ResetBase	\ Location of "reset" dropin in ROM
+h#   08.0000 constant dropin-size
+
+h#    1.0000 constant dma-base  \ DMA heap
+h#    8.0000 constant dma-size
+
+\ This is considerably more memory than Open Firmware needs
+\ on platforms where you have a well bounded set of I/O devices.
+
+h#  20.0000 constant /fw-ram
+h#  20.0000 constant heap-size
+
+[ifndef] virtual-mode
+h# 200.0000 constant ramsize	\ 32 MB
+\ h# 2000.0000 constant ramsize	\ 512 MB
+
+ramsize heap-size - constant heap-base	\ Dynamic allocation heap
+heap-base /fw-ram - constant fw-pa	\ OFW dictionary location
+[then]
+
+\ Where OFW initially loads an OS that it is going to boot
+\ OFW will then move it to the address where the OS wants to run from.
+
+h# 100.0000 constant def-load-base
+
+fload ${BP}/cpu/x86/pc/virtaddr.fth
+
+[ifdef] virtual-mode
+h#        3 constant pte-control	\ Page table entry attributes
+[then]
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2008 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END


Property changes on: cpu/x86/pc/emu/build
___________________________________________________________________
Added: svn:ignore
   + build
builton.fth
emuofw.rom


Added: cpu/x86/pc/emu/build/Makefile
===================================================================
--- cpu/x86/pc/emu/build/Makefile	                        (rev 0)
+++ cpu/x86/pc/emu/build/Makefile	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,24 @@
+OS := $(shell uname)
+
+all: emuofw.rom
+
+emuofw.rom: FORCE build ../../../build/inflate.bin
+	./build $@
+
+../../../${OS}/forth:
+	@make -C ../../../${OS} forth
+
+../../../build/inflate.bin:
+	@make -C ../../../build inflate.bin
+
+build: ../../../${OS}/forth
+	@ln -sf ../../../${OS}/forth build
+
+clean:
+	rm -f *.dic *.log headers *~ *.elf *.di *.img builton.fth build *.c32 *.rom
+
+clean-all: clean
+	@make -C ../../../build clean
+	@make -C ../../../${OS} clean
+
+.PHONY: FORCE clean all clean-all

Added: cpu/x86/pc/emu/config.fth
===================================================================
--- cpu/x86/pc/emu/config.fth	                        (rev 0)
+++ cpu/x86/pc/emu/config.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,154 @@
+\ See license at end of file
+purpose: Establish configuration definitions
+
+\ create pc		\ Demo version for generic PC
+\ create pc-linux	\ Demo version for generic PC and Linux
+\ create pc-serial	\ Demo version for generic PC
+
+\ --- The environment that "boots" OFW ---
+\ - Image Format - Example Media - previous stage bootloader
+
+create rom-loaded
+
+\ debug-startup enables early-startup reports on COM1
+
+create debug-startup
+
+\ serial-console makes COM1 the default OFW console device
+
+\ create serial-console
+
+\ resident-packages causes a lot of support packages to be
+\ precompiled into the Forth dictionary, instead of being
+\ demand-loaded from dropin modules
+
+create resident-packages
+
+\ addresses-assigned suppresses PCI address autoconfiguration.
+\ It is useful when OFW is loaded by lower-level firmware that
+\ has already assigned PCI addresses.
+
+\ create addresses-assigned
+
+\ use-root-isa puts the ISA bus device node directly under the
+\ device tree root (/isa), instead of under the PCI node (/pci/isa).
+\ For modern machines, it is usually best not to define use-root-isa .
+
+\ create use-root-isa
+
+\ use-pci-isa puts the ISA bus device node under the PCI node (/pci/isa),
+\ which is usually accurate for modern machines.
+
+create use-pci-isa
+
+\ use-timestamp-counter makes low-level timing operations use the
+\ timestamp counter (TSC) register.  This is a good thing for modern
+\ CPUs that have that register.
+
+create use-timestamp-counter
+
+\ use-isa-ide enables support for a legacy IDE controller accessed
+\ directly via I/O ports.  It is usually better to use the PCI IDE
+\ controller support via a dynamically-bound FCode driver.
+
+\ create use-isa-ide
+
+\ use-ega enables support for an OFW console that uses EGA text-mode 
+\ This typically only works when OFW is loaded on top of a conventional
+\ BIOS, because it assumes that the display device is already in the
+\ correct mode and OFW can just start writing to the text mode framebuffer.
+
+\ create use-ega
+
+\ use-vga enables support for an OFW console on a legacy VGA device,
+\ with OFW initializing the VGA registers to establish the mode.
+\ This does not work very well.  It is better to bind the "super driver"
+\ (dev/video/build/video.fc) to the PCI display class code.
+
+\ create use-vga
+
+\ use-elf enables support for loading and debugging ELF binaries
+
+create use-elf
+
+\ use-ne2000 enables support for a legacy ISA bus NE2000 network interface
+
+\ create use-ne2000
+
+\ use-watch-all enables the "watch-all" diagnostic command that
+\ exercises a variety of common I/O devices.
+
+\ create use-watch-all
+
+\ use-null-nvram installs stub implementations of non-volatile
+\ access routines, thus disabling persistent storage of OFW
+\ configuration variables.  Generic PCs generally have no good
+\ place to store those configuration variables, as the CMOS RAM
+\ is too small for typical string-valued variables.
+
+create use-null-nvram
+
+\ pseudo-nvram installs non-volatile access routines that use
+\ a fixed-name file on drive A to store the data.  It is a
+\ reasonable way to enable configuration variable storage
+\ when running OFW under an emulator where such a drive is
+\ "always" present, but it is not particularly useful for
+\ real hardware platforms.
+
+\ create pseudo-nvram
+
+
+\ no-floppy-node prevents the creation of a floppy disk device node
+\ among the set of legacy ISA devices.  Modern PCs rarely have
+\ floppy drives.
+
+\ create no-floppy-node
+
+\ In virtual mode, OFW runs with the MMU on.  The advantages are
+\ that OFW can automatically locate itself out of the way, at the
+\ top of physical memory, it can dynamically allocate exactly as
+\ much physical memory as it needs, and it can remain alive after
+\ the OS starts.  The disadvantage is that it is more confusing -
+\ you always have to be aware of the distinction between virtual
+\ and physical addresses.
+
+\ If you use virtual mode for Linux, you can debug past the point
+\ where Linux starts using the MMU.  It is not strictly
+\ necessary to use virtual mode if you just want to boot Linux
+\ and then have OFW disappear.
+
+create virtual-mode
+
+\ linux-support enables support for ext2 filesystems and bzimage format
+
+create linux-support
+
+
+\ cpu/x86/pc/<platform>/addrs.fth configures the basic system
+\ address assignment.
+
+fload ${BP}/cpu/x86/pc/emu/addrs.fth
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2008 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/devices.fth
===================================================================
--- cpu/x86/pc/emu/devices.fth	                        (rev 0)
+++ cpu/x86/pc/emu/devices.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,325 @@
+\ See license at end of file
+purpose: Load device drivers according to configuration definitions
+
+fload ${BP}/cpu/x86/pc/isaio.fth
+
+fload ${BP}/dev/pci/configm1.fth	\ Generic PCI configuration access
+
+0 0  " "  " /"  begin-package
+   fload ${BP}/cpu/x86/pc/mappci.fth	\ Map PCI to root
+   fload ${BP}/dev/pcibus.fth		\ Generic PCI bus package
+
+[ifdef] addresses-assigned
+   \ Suppress PCI address assignment; use the addresses the BIOS assigned
+   patch false true master-probe
+   patch noop assign-all-addresses prober
+   patch noop clear-addresses populate-device-node
+   patch noop clear-addresses populate-device-node
+   patch noop temp-assign-addresses find-fcode?
+   patch 2drop my-w! populate-device-node
+   : or-w!  ( bitmask reg# -- )  tuck my-w@  or  swap my-w!  ;
+   patch or-w! my-w! find-fcode?
+   patch 2drop my-w! find-fcode?
+[then]
+
+   fload ${BP}/cpu/x86/pc/biosload/pcinode.fth	\ System-specific words for PCI
+end-package
+stand-init: PCI host bridge
+   " /pci" " init" execute-device-method drop
+;
+
+fload ${BP}/dev/pciprobe.fth		\ Generic PCI probing
+
+[ifdef] use-timestamp-counter
+\ Use the CPU chip's Time Stamp Counter for timing; it does just what we want
+fload ${BP}/cpu/x86/tsc.fth
+[then]
+
+[ifdef] use-ega
+0 0 " " " /" begin-package
+   fload ${BP}/dev/egatext.fth
+end-package
+devalias screen /ega-text
+[then]
+
+[ifdef] use-root-isa
+0 0  " "  " /" begin-package
+   fload ${BP}/cpu/x86/pc/isabus.fth	\ ISA Bus Bridge under root node
+end-package
+[then]
+
+[ifndef] use-timestamp-counter
+fload ${BP}/cpu/x86/pc/getms.fth
+[then]
+
+[ifdef] use-pci-isa
+
+\ This must precede isamisc.fth in the load file, to execute it first
+fload ${BP}/cpu/x86/pc/moveisa.fth
+
+0 0  " 0"  " /pci" begin-package
+   fload ${BP}/dev/pci/isa.fth		\ ISA bus bridge under PCI node
+   fload ${BP}/dev/pci/isamisc.fth
+end-package
+[then]
+
+[ifdef] use-pc87560
+0 0  " 5,1"  " /pci" begin-package	\ ISA bus bridge
+   fload ${BP}/dev/pc87560.fth	\ SouthBridge ISA bus bridge
+end-package
+[then]
+
+dev /interrupt-controller
+h# 20 to vector-base0
+h# 28 to vector-base1
+device-end
+
+[ifdef] use-pc87317
+fload ${BP}/dev/pc87317.fth		\ National PC87317 superIO
+[then]
+
+0 0  dropin-base <# u#s u#>  " /" begin-package
+   " flash" device-name
+
+   dropin-size
+   dup value /device
+   constant /device-phys
+   my-address my-space /device-phys reg
+\   fload ${BP}/cpu/x86/pc/flashpkg.fth
+   fload ${BP}/dev/flashpkg.fth
+end-package
+
+[ifdef] notdef
+\ Create a node below the top-level FLASH node to accessing the portion
+\ containing the dropin modules
+0 0   0 0    " flash" begin-package
+   " dropins" device-name
+
+   dropin-size constant /device
+   fload ${BP}/dev/subrange.fth
+end-package
+[then]
+
+\ devalias dropins /dropins
+devalias dropins /flash
+
+\ Create a pseudo-device that presents the dropin modules as a filesystem.
+fload ${BP}/ofw/fs/dropinfs.fth
+
+\ This devalias lets us say, for example, "dir rom:"
+devalias rom     /dropin-fs
+
+fload ${BP}/cpu/x86/forthint.fth	\ Low-level interrupt handling code
+fload ${BP}/dev/isa/irq.fth		\ ISA interrupt dispatcher
+fload ${BP}/cpu/x86/pc/isatick.fth		\ Use ISA timer as the alarm tick timer
+
+[ifdef] resident-packages
+support-package: 16550
+fload ${BP}/dev/16550pkg/16550.fth  \ Serial port support package
+end-support-package
+[then]
+
+fload ${BP}/dev/pci/isaall.fth
+devalias seriala /isa/serial at i3f8
+devalias com1 /isa/serial at i3f8:115200
+devalias serialb /isa/serial at i2f8
+devalias com2 /isa/serial at i2f8
+devalias a /isa/fdc/disk at 0
+devalias b /isa/fdc/disk at 1
+devalias mouse /isa/8042/mouse
+
+[ifdef] use-timestamp-counter
+fload ${BP}/cpu/x86/pc/tsccal1.fth
+[then]
+
+[ifdef] use-ega
+dev /8042      patch false ctlr-selftest open   device-end
+[then]
+
+[ifdef] use-16552
+0 0  " i3a0"  " /isa" begin-package
+   3 encode-int  0 encode-int encode+    " interrupts" property
+   fload ${BP}/dev/16550pkg/ns16550p.fth
+   fload ${BP}/dev/16550pkg/isa-int.fth
+end-package
+
+0 0  " i3a8"  " /isa" begin-package
+   4 encode-int  0 encode-int encode+    " interrupts" property
+   fload ${BP}/dev/16550pkg/ns16550p.fth
+   fload ${BP}/dev/16550pkg/isa-int.fth
+end-package
+
+devalias seriald /isa/serial at i3a0	: seriald " seriald"  ;
+devalias serialc /isa/serial at i3a8	: serialc " serialc"  ;
+[then]
+
+0 0  " i70"  " /isa" begin-package   	\ Real-time clock node
+   fload ${BP}/dev/ds1385r.fth
+   8 encode-int  0 encode-int encode+    " interrupts" property
+   2 encode-int " device#" property
+end-package
+stand-init: RTC
+   " /rtc" open-dev  clock-node !
+;
+
+fload ${BP}/cpu/x86/pc/cpunode.fth
+
+[ifndef] serial-console
+fload ${BP}/ofw/core/bailout.fth
+stand-init:  Keyboard overrides
+   ?bailout
+;
+[then]
+
+fload ${BP}/ofw/core/countdwn.fth	\ Startup countdown
+fload ${BP}/forth/lib/pattern.fth		\ Text string pattern matching
+\ XXX remove the OS file commands from tools.dic
+fload ${BP}/ofw/core/filecmds.fth	\ File commands: dir, del, ren, etc.
+
+[ifdef] pseudo-nvram
+fload ${BP}/cpu/x86/pc/biosload/filenv.fth
+dev /file-nvram
+: hd-nv-file  ( -- )  " c:\nvram.dat"  ;
+' hd-nv-file to nv-file
+device-end
+stand-init: Pseudo-NVRAM
+   " /file-nvram" open-dev  to nvram-node
+   nvram-node 0=  if
+      ." The configuration EEPROM is not working" cr
+   then
+   ['] init-config-vars catch drop
+;
+[then]
+
+fload ${BP}/dev/isa/soundblaster.fth
+
+[ifdef] use-vga
+0 0  " i3c0" " /isa" begin-package
+  " vga" name
+  my-address my-space h# 20 reg
+  fload ${BP}/dev/video/common/defer.fth	\ Defered words
+  fload ${BP}/dev/video/common/graphics.fth	\ Graphics and color routines
+  fload ${BP}/dev/video/controlr/vga.fth	\ Controller code
+  use-vga
+  fload ${BP}/dev/video/common/init.fth		\ Init code
+  fload ${BP}/dev/video/common/display.fth	\ High level interface code
+  fload ${BP}/dev/video/common/textmode.fth	\ VGA text mode
+  : (map-io-regs)  h# ffff0000 to io-base  ;
+  ' (map-io-regs) to map-io-regs
+end-package
+[then]
+
+[ifdef] use-ct65550
+0 0  " i3b0" " /isa" begin-package
+   fload ${BP}/dev/ct6555x/loadpkg.fth	\ Video driver
+end-package
+devalias screen /isa/display		\ Explicit, because it's not probed
+[then]
+
+[ifdef] use-es1887
+fload ${BP}/dev/isa/es1887.fth		\ Sound chip driver
+devalias audio /isa/sound
+fload ${BP}/cpu/x86/decnc/sound.fth	\ Startup sound
+[then]
+
+[ifdef] use-isa-ide
+0 0  " i1f0" " /isa" begin-package
+   fload ${BP}/dev/ide/isaintf.fth
+   fload ${BP}/dev/ide/generic.fth
+   2 to max#drives
+   fload ${BP}/dev/ide/onelevel.fth
+end-package
+\ One-level IDE
+[then]
+
+\ Create the alias unless it already exists
+: $?devalias  ( alias$ value$ -- )
+   2over  not-alias?  if  $devalias exit  then  ( alias$ value$ alias$ )
+   2drop 4drop
+;
+
+: report-pci-fb  ( -- )
+   " /pci/display" locate-device 0=  if  ( phandle )
+      " open" rot find-method  if        ( xt )
+         drop
+         " screen" " /pci/display"  $devalias
+      then
+   then
+;
+
+: report-disk  ( -- )
+   " /scsi" locate-device  0=  if
+      drop
+      " scsi" " /scsi"        $devalias
+      " disk" " /scsi/disk at 0" $devalias
+      " c"    " /scsi/disk at 0" $devalias
+      " d"    " /scsi/disk at 1" $devalias
+      " e"    " /scsi/disk at 2" $devalias
+      " f"    " /scsi/disk at 3" $devalias
+      exit
+   then
+   " /pci-ide" locate-device  0=  if
+      drop
+      " disk" " /pci-ide/ide at 0/disk at 0" $devalias
+      " c"    " /pci-ide/ide at 0/disk at 0" $devalias
+      " d"    " /pci-ide/ide at 0/disk at 1" $devalias
+      " e"    " /pci-ide/ide at 1/disk at 0" $devalias
+      " f"    " /pci-ide/ide at 1/disk at 1" $devalias
+      exit
+   then
+   " /ide" locate-device  0=  if
+      drop
+      " disk" " /ide at 1f0/disk at 0" $devalias
+      " c"    " /ide at 1f0/disk at 0" $devalias
+      " d"    " /ide at 170/disk at 1" $devalias
+      " e"    " /ide at 1f0/disk at 0" $devalias
+      " f"    " /ide at 170/disk at 2" $devalias
+      exit
+   then
+;
+
+fload ${BP}/cpu/x86/inoutstr.fth	\ Multiple I/O port read/write
+[ifdef] use-isa-ide
+dev /ide
+' pseudo-dma-in  ' pseudo-dma-out  set-blk-w
+device-end
+[then]
+
+[ifdef] use-ne2000
+0 0  " i300" " /isa" begin-package
+   start-module
+      fload ${BP}/dev/ne2000/ne2000.fth	\ Ethernet Driver
+   end-module
+end-package
+[then]
+
+fload ${BP}/dev/isa/diaguart.fth	\ ISA COM port driver
+h# 3f8 is uart-base
+fload ${BP}/forth/lib/sysuart.fth	\ Use UART for key and emit
+\ fload ${BP}/cpu/x86/pc/egauart.fth		\ Output also to EGA
+
+fload ${BP}/cpu/x86/pc/reset.fth		\ reset-all
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2008 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/emuofw.bth
===================================================================
--- cpu/x86/pc/emu/emuofw.bth	                        (rev 0)
+++ cpu/x86/pc/emu/emuofw.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,110 @@
+purpose: Construct the final OFW image 
+
+command: &builder &this
+\ in: biostart.img
+in: rmreset.img
+in: pmreset.di
+in: paging.di
+in: fw.img
+in: ${BP}/dev/usb2/hcd/ohci/build/ohci.fc
+in: ${BP}/dev/usb2/hcd/uhci/build/uhci.fc
+in: ${BP}/dev/usb2/hcd/ehci/build/ehci.fc
+in: ${BP}/dev/usb2/device/hub/build/hub.fc
+in: ${BP}/dev/usb2/device/net/build/usbnet.fc
+in: ${BP}/dev/usb2/device/serial/build/usbserial.fc
+in: ${BP}/dev/usb2/device/storage/build/usbstorage.fc
+in: ${BP}/dev/usb2/device/keyboard/build/usbkbd.fc
+\ in: ${BP}/ofw/fs/nfs/build/nfs.di
+\ in: ${BP}/ofw/fs/cdfs/build/cdfs.di
+\ in: ${BP}/ofw/fs/fatfs/build/fatfs.di
+\ in: ${BP}/ofw/disklabel/build/disklabel.di
+\ in: ${BP}/ofw/inet/build/obptftp.di
+in: ${BP}/dev/pci/build/pcibridg.fc
+in: ${BP}/dev/ide/build/leghier.fc
+in: ${BP}/dev/video/build/cirrus.fc
+in: ${BP}/dev/ne2000/build/ne2kpci.fc
+in: ${BP}/dev/amd79970/build/vmlance.fc
+\ in: ${BP}/dev/video/build/video.fc
+in: ${BP}/cpu/x86/pc/biosload/linux.fth
+
+build-now
+
+fload ${BP}/cpu/x86/pc/emu/config.fth
+
+\ Always re-create the builton.fth file when we make a new rom.img
+fload ${BP}/cpu/x86/pc/builton.bth
+
+hex
+
+: pad-file  ( location -- )
+   ofd @ fsize
+   2dup u< abort" The ROM image is too large"
+   ?do  h# ff ofd @ fputc  loop
+;
+
+.( --- Saving as emuofw.rom - Binary ROM image format for emulator) cr
+writing emuofw.rom
+   " pmreset.di"            $add-file
+   " paging.di"             $add-file
+   " ${BP}/cpu/x86/build/inflate.bin"           " inflate"         $add-dropin
+   " fw.img"                                    " firmware"        $add-deflated-dropin
+   " ${BP}/dev/pci/build/pcibridg.fc"           " class060400"     $add-deflated-dropin
+   " ${BP}/dev/ide/build/leghier.fc"            " class010180"     $add-deflated-dropin
+
+\ The super-driver is overkill, we don't need support for lots of obsolete video cards
+\  " ${BP}/dev/video/build/video.fc"            " class030000"     $add-deflated-dropin
+
+\ Just use a driver targeted at the specific chipset that QEMU emulates
+   " ${BP}/dev/video/build/cirrus.fc"           " pci1013,b8"      $add-deflated-dropin
+
+   " ${BP}/dev/ne2000/build/ne2kpci.fc"         " pci10ec,8029"    $add-deflated-dropin
+   " ${BP}/dev/amd79970/build/vmlance.fc"       " pci1022,2000"    $add-deflated-dropin
+
+   " ${BP}/dev/usb2/hcd/uhci/build/uhci.fc"	" class0c0300"     $add-deflated-dropin
+   " ${BP}/dev/usb2/hcd/ohci/build/ohci.fc"	" class0c0310"     $add-deflated-dropin
+   " ${BP}/dev/usb2/hcd/ehci/build/ehci.fc"	" class0c0320"     $add-deflated-dropin
+
+   " ${BP}/dev/usb2/device/hub/build/hub.fc"            " usb,class9"    $add-dropin
+   " ${BP}/dev/usb2/device/keyboard/build/usbkbd.fc"    " usb,class3,1"  $add-dropin
+   " ${BP}/dev/usb2/device/net/build/usbnet.fc"         " usbnet"      $add-deflated-dropin
+   " ${BP}/dev/usb2/device/serial/build/usbserial.fc"   " usbserial"   $add-deflated-dropin
+   " ${BP}/dev/usb2/device/storage/build/usbstorage.fc" " usbstorage"  $add-deflated-dropin
+
+   " builton.fth"                       " probe-"          $add-dropin
+[ifndef] resident-packages
+   " ${BP}/ofw/fs/cdfs/build/cdfs.di"                      $add-file
+   " ${BP}/ofw/fs/fatfs/build/fatfs.di"                    $add-file
+   " ${BP}/ofw/fs/nfs/build/nfs.di"                        $add-file
+   " ${BP}/ofw/fs/dropinfs.fth"    " dropin-file-system"   $add-deflated-dropin
+   " ${BP}/ofw/disklabel/build/disklabel.di"               $add-file
+   " ${BP}/ofw/inet/build/obptftp.di"                      $add-file
+   " ${BP}/dev/16550pkg/16550.fth" " 16550"                $add-deflated-dropin
+   " ${BP}/cpu/x86/disassem.fth"   " disassem.fth"         $add-deflated-dropin
+   " ${BP}/ofw/ppp/build/ppp.di"                           $add-file
+\  " ${BP}/ofw/fs/ufs/ufs.fth"     " ufs-file-system"      $add-deflated-dropin
+   " ${BP}/ofw/fs/zipfs.fth"       " zip-file-system"      $add-deflated-dropin
+   " ${BP}/ofw/inet/tcp.fth"       " tcp"                  $add-deflated-dropin
+   " ${BP}/ofw/inet/http.fth"      " http"                 $add-deflated-dropin
+   " ${BP}/ofw/fs/ext2fs/ext2fs.fth"  " ext2-file-system"  $add-deflated-dropin
+   " ${BP}/ofw/inet/telnetd.fth"      " telnetd"           $add-deflated-dropin
+   " ${BP}/ofw/fs/fatfs/fdisk2.fth"   " fdisk2.fth"        $add-deflated-dropin
+[then]
+   " ${BP}/ofw/fcode/memtest.fth"          " memtest.fth"  $add-deflated-dropin
+
+   " ${BP}/ofw/inet/telnetd.fth"           " telnetd"      $add-deflated-dropin
+
+   " ${BP}/ofw/inet/httpdemo/index.htm"	   " index.htm"    $add-dropin
+   " ${BP}/ofw/inet/httpdemo/config.htm"   " config.htm"   $add-dropin
+\  " ${BP}/ofw/inet/httpdemo/post.htm"     " post.htm"     $add-dropin
+   " ${BP}/ofw/inet/httpdemo/free.htm"	   " free.htm"     $add-dropin
+   " ${BP}/ofw/inet/httpdemo/homelogo.gif" " homelogo.gif" $add-dropin
+
+   " ${BP}/cpu/x86/pc/biosload/linux.fth"  " linux.fth"    $add-dropin
+   " ${BP}/ofw/linux/penguin.txt"          " penguin.txt"  $add-dropin
+
+   " ${BP}/ofw/termemu/cp881-16.obf"       " font"         $add-deflated-dropin
+
+   h# 7.fc00 pad-file
+   " rmreset.img"  $add-file
+   ofd @ fsize  dropin-size <>  if  ." Size is wrong" cr  then
+ofd @ fclose

Added: cpu/x86/pc/emu/fw.bth
===================================================================
--- cpu/x86/pc/emu/fw.bth	                        (rev 0)
+++ cpu/x86/pc/emu/fw.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,361 @@
+\ See license at end of file
+purpose: Build Open Firmware core for PC
+
+dictionary: ${BP}/cpu/x86/build/basefw.dic
+command: &x86forth &dictionary &this
+in: builton.fth
+build-now
+
+hex
+\ ' $report-name is include-hook
+
+fload ${BP}/cpu/x86/pc/emu/config.fth
+
+: headerless ;  : headers  ;  : headerless0 ;
+
+' (quit) to quit
+
+create debug-startup
+: \Tags [compile] \  ; immediate
+: \NotTags [compile] \  ; immediate
+
+: RAMbase  ( -- adr )  fw-virt-base  ;
+: RAMtop  ( -- adr )  RAMbase /fw-ram +  ;
+
+h# 00.0000 value    dp-loc	\ Set in patchboot
+: stacktop    ( -- adr )  RAMtop  ;
+: dict-limit  ( -- adr )  RAMtop  h# 06.0000 -  ;
+
+\ XXX What we should do is pass in the top address in SP, and have
+\ boot.fth allocate the user area by subtracting user-size.  But
+\ we need some way of finding it again for exception re-entry.
+\ prom-main-task is used in arch/pc/boot.fth .  The constant
+\ value is wired into the assembly code
+stacktop  user-size - ( fw-virt-base - ) constant prom-main-task	\ user area for main task
+
+0 value load-limit	\ Top address of area at load-base
+' 2drop to sync-cache
+
+def-load-base ' load-base set-config-int-default
+
+true ' fcode-debug? set-config-int-default
+\ false  ' auto-boot?    set-config-int-default
+
+[ifdef] serial-console
+" com1" ' output-device set-config-string-default
+" com1" ' input-device set-config-string-default
+[then]
+
+\ XXX should be loaded by basefw.bth
+fload ${BP}/cpu/x86/initpgm.fth		\ Basic boot handler
+
+: (cpu-arch  ( -- adr len )
+   " architecture" ['] root-node  get-package-property  drop
+   get-encoded-string
+;
+' (cpu-arch to cpu-arch
+
+h# 1000 to pagesize
+d# 12   to pageshift
+
+dev /
+1 encode-int  " #address-cells"  property
+
+" Emulated PC" model
+" PC" encode-string  " architecture" property
+
+\ XXX figure out bus frequency.  How?
+\ d# 33,333,333 " clock-frequency" integer-property
+device-end
+
+\ Memory management services
+[ifdef] virtual-mode
+fload ${BP}/ofw/core/clntmem1.fth	\ client services for memory
+[else]
+fload ${BP}/ofw/core/clntphy1.fth	\ client services for memory
+[then]
+fload ${BP}/ofw/core/memlist.fth	\ Resource list common routines
+fload ${BP}/ofw/core/showlist.fth	\ Linked list display tool
+fload ${BP}/ofw/core/allocph1.fth	\ S Physical memory allocator
+fload ${BP}/ofw/core/availpm.fth	\ Available memory list
+
+fload ${BP}/cpu/x86/pc/rootnode.fth	\ Platform-specific root node changes
+
+fload ${BP}/cpu/x86/pc/emu/probemem.fth	\ Memory probing
+
+[ifdef] virtual-mode
+fload ${BP}/cpu/x86/loadvmem.fth	\ /mmu node
+stand-init: MMU
+   " /mmu" open-dev mmu-node !
+;
+fload ${BP}/cpu/x86/pc/initdict.fth	\ Dynamic dictionary allocation
+[then]
+
+\ XXX should be elsewhere
+dev /client-services
+: chain  ( len args entry size virt -- )
+   release                                       ( len args entry )
+   h# 8000 alloc-mem h# 8000 +  (init-program)   ( len args )
+   to %ebx  to %ecx
+   go
+;
+device-end
+
+fload ${BP}/cpu/x86/crc32.fth		\ Assembly language Zip CRC calculation
+fload ${BP}/forth/lib/crc32.fth	\ High-level portion of CRC calculation
+
+[ifdef] resident-packages
+
+[ifdef]  use-ufs
+support-package: ufs-file-system
+   fload ${BP}/ofw/fs/ufs/ufs.fth	\ Unix file system
+end-support-package
+[then]
+
+[ifdef] linux-support
+\needs unix-seconds>  fload ${BP}/ofw/fs/unixtime.fth	\ Unix time calculation
+support-package: ext2-file-system
+   fload ${BP}/ofw/fs/ext2fs/ext2fs.fth	\ Linux file system
+end-support-package
+[then]
+
+support-package: zip-file-system
+   fload ${BP}/ofw/fs/zipfs.fth		\ Zip file system
+end-support-package
+
+support-package: dropin-file-system
+   fload ${BP}/ofw/fs/dropinfs.fth	\ Dropin file system
+end-support-package
+[then]
+
+\ Load file format handlers
+
+: call32 ;
+
+fload ${BP}/ofw/core/allocsym.fth    \ Allocate memory for symbol table
+fload ${BP}/ofw/core/symcif.fth
+fload ${BP}/ofw/core/symdebug.fth
+: release-load-area  ( boundary-adr -- )  drop  ;
+
+fload ${BP}/cpu/x86/pc/fixkbd.fth	\ Switch keyboard scan codes
+
+[ifdef] use-elf
+fload ${BP}/ofw/elf/elf.fth
+fload ${BP}/ofw/elf/elfdebug.fth
+[ifdef] virtual-mode
+\ Depends on the assumption that physical memory is mapped 1:1 already
+: (elf-map-in) ( va size -- )  0 mem-claim  drop  ;
+' (elf-map-in) is elf-map-in
+[else]
+' 2drop is elf-map-in
+[then]
+[then]
+
+\ Reboot and re-entry code
+fload ${BP}/cpu/x86/pc/reboot.fth	\ Restart the client program
+fload ${BP}/cpu/x86/pc/reenter.fth	\ Various entries into Forth
+
+headerless
+[ifdef] virtual-mode
+: (initial-heap)  ( -- adr len )
+   mem-info-pa la1+ l@  heap-size  -  ( adr )
+   dup mem-info-pa la1+ l!            ( adr )
+   heap-size
+;
+[else]
+: (initial-heap)  ( -- adr len )  heap-base heap-size  ;
+[then]
+' (initial-heap) is initial-heap
+headers
+
+" /openprom" find-device
+   " FirmWorks,3.0" encode-string " model" property
+device-end
+
+[ifdef] virtual-mode
+fload ${BP}/cpu/x86/pc/mmusetup.fth	\ Initial values for MMU lists
+[then]
+
+fload ${BP}/cpu/x86/pc/emu/devices.fth
+
+fload ${BP}/dev/scsi/probscsi.fth	\ probe-scsi and probe-scsi-all
+
+true ' local-mac-address? set-config-int-default
+[ifdef] resident-packages
+support-package: nfs
+   fload ${BP}/ofw/fs/nfs/loadpkg.fth
+end-support-package
+[then]
+devalias nfs net//obp-tftp:last//nfs
+
+fload ${BP}/ofw/inet/loadtcp.fth
+
+support-package: http
+   fload ${BP}/ofw/inet/http.fth	\ HTTP client
+end-support-package
+
+[ifndef] use-timestamp-counter
+fload ${BP}/cpu/x86/pc/mscal.fth
+[then]
+fload ${BP}/cpu/x86/pc/boot.fth
+
+hex 
+\ If there is a PCI ethernet adapter, use it as the default net device,
+\ otherwise use any ethernet that can be found in the device tree.
+: report-net  ( -- )
+   " /pci/ethernet" 2dup  find-package  if  ( name$ phandle )
+      drop                                  ( name$ )
+   else                                     ( name$ )
+      2drop  " /ethernet"                   ( name$' )
+   then                                     ( name$ )
+   " net" 2swap $devalias                   ( )
+;
+
+fload ${BP}/cpu/x86/pc/biosload/usb.fth
+
+\ false to stand-init-debug?
+true to stand-init-debug?
+
+hex
+stand-init-debug?  [if]
+warning @  warning off 
+: init
+\ initial-heap add-memory
+   init
+
+   standalone?  if
+      cr ." Type 'i' to interrupt stand-init sequence" cr 
+      d# 2000 ms
+      key?  if
+         key upc ascii I  =  if  ." Interacting" cr  hex interact  then
+      then
+   then
+
+\  cr0@ h# 9fff.ffff and cr0!	\ enable L1 and L2 caches
+
+;
+warning !
+[then]
+
+[ifdef] virtualbox-loaded
+also hidden also keys-forth definitions
+\ The VirtualBox "serial port" can be accessed via a telnet client.
+\ Telnet normally sends CR-LF at the end of the line and it is hard
+\ to turn that off because of incompatibilies between various clients
+\ and servers.  So if there is a key already queued up right after a
+\ newline, we just eat it.
+: telnet-newline  ( -- )
+   new-line-or-done  key?  if  key drop  then
+;
+warning @ warning off
+: ^m telnet-newline  ;
+: ^j telnet-newline  ;
+warning !
+previous previous definitions
+[then]
+
+: (.firmware)  ( -- )
+   ." Open Firmware  "  .built  cr
+   ." Copyright 1999 FirmWorks  All Rights Reserved" cr
+;
+' (.firmware) to .firmware
+
+: linux-logo  ( -- )
+   " penguin.txt" find-drop-in  if  page type  then
+;
+
+: probe-all  ( -- )
+   " probe-" do-drop-in
+   ." probe-pci"  cr
+\   debug-me
+   probe-pci
+[ifdef] probe-isa-modem
+   probe-isa-modem
+[then]
+   probe-usb
+   report-disk
+   report-net
+   report-pci-fb
+;
+
+: startup  ( -- )
+   standalone?  0=  if  exit  then
+\   ." calibrate-ms"  cr
+\   calibrate-ms
+
+    ." nvramrc" cr
+    use-nvramrc?  if  nvramrc safe-evaluate  then
+
+   auto-banner?  if
+      " Probing" ?type  probe-all
+      " Install console" ?type  install-console
+      banner
+   then
+
+   hex
+   warning on
+   only forth also definitions
+
+\   install-alarm
+
+   #line off
+
+   ." Open Firmware demonstration version by FirmWorks (info at firmworks.com)" cr
+
+   quit
+;
+
+[ifdef] use-watch-all
+fload ${BP}/cpu/x86/pc/watchall.fth
+[then]
+
+alias crcgen drop  ( crc byte -- crc' )
+fload ${BP}/cpu/x86/pc/saveabs.fth
+
+fload ${BP}/forth/lib/selstr.fth
+
+[ifdef] pc-linux
+" a:\initrd.imz" d# 128 config-string ramdisk
+" root=/dev/ram0 mount_ramdisk=1"  ' boot-file        set-config-string-default
+" a:\vmlinuz"                      ' boot-device      set-config-string-default
+true                               ' client-symbols?  set-config-int-default
+\ Also try " console=/dev/ttyS0,9600 console=/dev/tty0" in boot-file
+[then]
+
+[ifdef] linux-support
+fload ${BP}/cpu/x86/pc/linux.fth
+[then]
+
+fload ${BP}/cpu/x86/pc/biosload/vmdoor.fth   \ VMware interfaces
+
+" dhcp" ' ip-address  set-config-string-default
+
+.( SAVING FW.dic ...)
+" fw.dic" $save-forth cr
+
+.( Saving fw.img ...)
+" fw.img"  RAMbase save-abs-rom cr
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/pcinode.fth
===================================================================
--- cpu/x86/pc/emu/pcinode.fth	                        (rev 0)
+++ cpu/x86/pc/emu/pcinode.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,115 @@
+\ See license at end of file
+purpose: PCI bus package
+
+also forth definitions
+
+\ probe all slots
+" 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12,13,14,15,16,17,18,19,1a,1b,1c,1d,1e,1f"
+\ " 1,2,3,4,5,6,7,8,9,a,b,c,d,e,f"
+   dup  config-string pci-probe-list
+
+previous definitions
+
+h# c000.0000 to first-mem		\ Avoid RAM at low addresses
+h# e000.0000 to mem-space-top
+h# 0000.8000 to first-io		\ Avoid mappings established by BIOS
+
+defer config-setup
+defer config-done
+
+\ Configuration mechanism #1 as defined in the PCI spec.
+: config-setup1  ( config-adr -- vaddr )
+   \ Bit 31 ("enable") must be 1, bits 30:24 ("reserved") must be 0,
+   \ bits 1:0 must be 0.
+   dup h# ff.fffc and  h# 8000.0000 or  h# cf8 pl!  ( config-adr )
+
+   3 and  h# cfc +  \ Merge in the byte selector bits
+;
+
+\ These versions of config-x@/! are for "configuration mechanism #2"
+\ as described in the PCI design guide.  That mechanism is not the
+\ recommended one, but several PC PCI chipsets use it.
+
+: config-setup2  ( bus#|dev#|function|reg# -- port-adr )
+   \ XXX For now, we ignore the bus number
+   \ Write function number and "access config space" key to the config
+   \ space enable register
+   dup 7 >> h# e and  h# 10 or  h# cf8 pc!  ( bus#|dev#|function#|reg#)
+   dup h# ff and  swap d# 11 >> h# f and 8 <<  or  h# c000 or
+;
+: config-done2  ( -- )  0 h# cf8 pc!  ; 
+
+: config-b@  ( config-adr -- b )  config-setup pc@ config-done  ;
+: config-w@  ( config-adr -- w )  config-setup pw@ config-done  ;
+: config-l@  ( config-adr -- l )  config-setup pl@ config-done  ;
+: config-b!  ( b config-adr -- )  config-setup pc! config-done  ;
+: config-w!  ( w config-adr -- )  config-setup pw! config-done  ;
+: config-l!  ( l config-adr -- )  config-setup pl! config-done  ;
+
+: mechanism1   ( -- )
+   ['] config-setup1 to config-setup
+   ['] noop          to config-done
+;
+mechanism1
+: mechanism2   ( -- )
+   ['] config-setup2 to config-setup
+   ['] config-done2  to config-done
+;
+
+\ !!! assumes a device in either slot 0 or slot 1 !!!
+\ and that failed reads return -1.
+: init  ( -- )
+   mechanism1
+   0 config-l@  -1 =  h# 800 config-l@  -1 =  and  if
+      mechanism2
+\      h# 0000.5000  to first-io    \ Avoid on-board SCSI chip's BIOS mapping 
+\      " 3,4,5" to pci-probe-list
+   then
+;
+
+\ Determine the parent interrupt information (the "interrupt line" in PCI
+\ parlance) from the child's "interrupt pin" and the child's address,
+\ returning "int-line true" if the child's interrupt line register should
+\ be set or "false" otherwise.
+: assign-int-line  ( phys.hi.func INTx -- irq true )
+   \ Reiterate the value that is already in the int line register,
+   \ which was presumably placed there by the BIOS
+   drop  h# 3c +  config-b@  true
+;
+
+\ XXX we should keep a table of already-mapped addresses so that
+\ successive map/unmaps of the same address will succeed.
+
+
+\ The io-base handling really ought to be in the root node, but
+\ that would require more changes than I'm willing to do at present.
+warning @ warning off
+: map-out  ( vaddr size -- )
+   over io-base u>=  if  2drop exit  then  ( vaddr size )
+   map-out                                 ( )
+;   
+warning !
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/pmreset.bth
===================================================================
--- cpu/x86/pc/emu/pmreset.bth	                        (rev 0)
+++ cpu/x86/pc/emu/pmreset.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,156 @@
+\ See license at end of file
+purpose: Build file for dropin dispatcher  - version for direct ROM startup
+
+command: &builder &this
+build-now
+
+fload ${BP}/cpu/x86/pc/emu/config.fth
+
+\ If debug-startup is not defined in config.fth, the "init-com1" and "report"
+\ macros will be noops; otherwise they will generate COM port access code.
+
+\needs start-assembling  fload ${BP}/cpu/x86/asmtools.fth
+\needs write-dropin      fload ${BP}/forth/lib/mkdropin.fth
+
+fload ${BP}/cpu/x86/mmuparam.fth
+
+\ startmacros.fth defines some assembler macros that make it easy to
+\ access MSRs, I/O ports, and PCI config registers.
+
+fload ${BP}/cpu/x86/startmacros.fth
+
+hex
+
+fload ${BP}/cpu/x86/pc/finddi.fth	\ find-dropin and other tools
+
+h#  3e.0000 constant inflate-base       \ Where to put the inflater in memory
+h#  30.0000 constant workspace          \ when inflating the Forth part of OFW
+
+start-assembling
+
+label my-entry
+   h# e9 c,  0 l,	\ Skip support subroutines, jmp offset patched later
+end-code
+
+[ifdef] debug-startup
+fload ${BP}/cpu/x86/pc/dot.fth		\ Numeric output
+[then]
+
+fload ${BP}/cpu/x86/pc/romfind.fth	\ Support subroutine: find-dropin
+
+label startup		\ Target of jmp instruction at my-entry
+   h# 10 port80
+
+\ Perform low-level initialization of bridges here, typically at least
+\ to the level where it's possible to talk to the COM port
+
+   h# 12 port80
+
+   init-com1
+   carret report  linefeed report
+   char F report
+
+\ Perform RAM controller initialization here.
+
+   h# 14 port80
+   char o report
+
+   h# 80000 # sp mov   \ Temporary stack pointer for debugging
+
+[ifdef] notdef
+   \ This is an example of how you could display numeric information
+   \ on the serial port during startup.  This only works after memory
+   \ is turned on, because it requires a stack.  Before memory is on,
+   \ you can display individual characters with "report", but not numbers.
+   ax push       \ Save EAX because "dot" destroys it
+   dot #) call   \ Display whatever is in EAX as a hex number
+   ax pop        \ Restore saved EAX
+[then]
+
+   \ Determine the memory size
+
+   \ Adjust assembler structured conditionals to permit long blocks
+   long-offsets on
+
+   \ Set locations just below power-of-two boundaries to the boundary value
+   h# 8000.0000 # si mov     \ Start address
+   h#  200.0000 # di mov     \ End address (assume at least 32 MiB)
+   si ax mov
+   begin
+      ax  -4 [ax]  mov       \ Set e.g. loc 3ffffffc to 40000000
+      1 # ax shr             \ Step down to the next power of two
+      di  ax cmp             \ Stop at lower limit
+   < until
+
+   \ Look for a location that contains the expected data
+   si ax mov
+   begin
+      -4 [ax]  bx  mov
+      bx  ax  cmp
+   <> while
+      1 # ax shr
+      di  ax cmp
+      <  if
+         \ Halt with a message if we go below the end address
+         h# 1e port80
+         bl report
+         char B report  char A report  char D report
+         char M report  char E report  char M report
+         begin hlt again
+      then
+   repeat
+
+   \ Put the memory size where resetend.fth can find it
+   ax mem-info-pa #)  mov      \ Total size
+   ax mem-info-pa 4 + #)  mov  \ Allocation pointer
+
+   \ Turn on the cache
+   cr0	ax   mov
+   6000.0000 bitclr  \ Cache-disable off, coherent
+   ax   cr0  mov
+   invd
+
+   \ Now we can use the stack and do conventional subroutine calls
+   h# 16 port80
+   char r report
+
+   \ resetend.fth finds the Forth part of OFW, moves/uncompresses it
+   \ into RAM, and runs it.  It's independent of board-specific
+   \ I/O hardware, so it can be shared between different board ports.
+
+   fload ${BP}/cpu/x86/pc/resetend.fth
+end-code
+
+also 386-assembler
+startup  my-entry  put-branch
+previous
+
+end-assembling
+
+writing pmreset.di
+asm-base  here over -  0  " pmreset" write-dropin
+ofd @ fclose
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2008 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/probemem.fth
===================================================================
--- cpu/x86/pc/emu/probemem.fth	                        (rev 0)
+++ cpu/x86/pc/emu/probemem.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,66 @@
+\ See license at end of file
+purpose: Create memory node properties and lists
+
+dev /memory
+
+: cmos@   ( offset -- byte )  h# 70 pc!  h# 71 pc@  ;
+: /ram  ( -- #bytes )  mem-info-pa l@  ;
+
+: release-range  ( start-adr end-adr -- )  over - release  ;
+
+: probe  ( -- )
+   0 /ram  reg   \ Report extant memory
+
+   \ Put h# 10.0000-1f.ffff and 28.0000-memsize in pool,
+   \ reserving 0..10.0000 for the firmware
+   \ and 20.0000-27.ffff for the "flash"
+
+\   h#  0.0000  h# 02.0000  release   \ A little bit of DMA space, we hope
+\   h# 10.0000  h# 0f.ffff  release
+\   h# 28.0000  h# 80.0000 h# 28.0000 -  release
+
+\ Release some of the first meg, between the page tables and the DOS hole,
+\ for use as DMA memory.
+   mem-info-pa 2 la+ l@   h# a.0000  release-range  \ Below DOS hole
+
+[ifdef] virtual-mode
+   h# 10.0000  mem-info-pa la1+ l@  over -  release
+[else]
+   fw-pa h# 10.0000 u>  if
+      h# 10.0000   fw-pa over -  release
+      fw-pa /fw-ram +  heap-base heap-size +  umax  /ram  release
+   then
+[then]
+;
+
+device-end
+
+also forth definitions
+stand-init: Probing memory
+   " probe" memory-node @ $call-method  
+;
+previous definitions
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: cpu/x86/pc/emu/rmreset.bth
===================================================================
--- cpu/x86/pc/emu/rmreset.bth	                        (rev 0)
+++ cpu/x86/pc/emu/rmreset.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,260 @@
+\ See license at end of file
+purpose: x86 real mode startup code.
+
+command: &builder &this
+build-now
+
+fload ${BP}/cpu/x86/pc/emu/config.fth
+
+\ 386/486 processors begin executing at address ffff.fff0 in real mode
+\ when they come out of reset.  Normally, that address would not be
+\ accessable in real mode, but the processor does some magic things to
+\ the Code Segment register so that the high order address lines are
+\ "boosted" up to the ffff.xxxx range just after reset.  The "boosting"
+\ persists until the CS register is modified (i.e. with a far jump).
+
+\ The other segment register are not "boosted", so they can only access
+\ the normal real mode range, essentially just the first megabyte.
+
+\ The startup code must establish a Global Descriptor Table containing
+\ suitable mappings, and then enter protected mode.  The space between
+\ ffff.fff0 and the end of the ROM is insufficient to do this, so the
+\ first few instructions must jump elsewhere, to a place where there
+\ is enough room.
+
+\ The code below is rather tricky, especially since the Forth assembler
+\ always assumes 32-bit operand size and 32-bit addressing modes.
+\ The code is executing in 16-bit mode, so the assembler must be used
+\ carefully to ensure generation of the correct opcodes, and override
+\ prefixes where necessary.
+
+
+\needs start-assembling  fload ${BP}/cpu/x86/asmtools.fth
+\needs write-dropin      fload ${BP}/forth/lib/mkdropin.fth
+
+hex
+
+start-assembling
+hex
+
+\ Addresses where the following items will be located in the processor's
+\ physical address space:
+
+\ ffff.fc00:  GDT  ( 3 entries ) + padding
+\ ffff.fc20:  GDT address + size ( 6 bytes ) plus padding
+\ ffff.fc28:  Startup code plus padding
+\ ffff.fff0:  Reset entry point - jump to startup code plus padding to end
+
+\ Assembler macros for startup diagnostics
+
+\ write a byte to an ISA port
+: risa-c!   ( n a - )  "  # dx mov  # al mov   al dx out " evaluate  ;
+
+: num>asc  ( al: b -- al: low ah: hi )
+   " al ah mov " evaluate
+   " h# f # al and " evaluate
+   " h# 9 # al cmp  >  if h# 57 # al add  else  h# 30 # al add  then " evaluate
+
+   " ah shr  ah shr  ah shr  ah shr " evaluate	\ shift down four bits
+   " h# f # ah and " evaluate
+   " h# 9 # ah cmp  >  if h# 57 # ah add  else  h# 30 # ah add then " evaluate
+
+   " al bl mov  ah al mov  bl ah mov " evaluate
+
+;
+
+[ifdef] no-port80
+: port80  ( byte -- )  drop  ;
+[else]
+: port80  ( byte -- )  " # al mov  al h# 80 # out" evaluate  ;
+[then]
+
+\ The simple COM port initialization in this file assumes that the hardware
+\ path to the COM port (southbridge+superIO or whatever) is active immediately
+\ after reset, requiring no special initialization.  That's usually not a good
+\ assumption for modern machines.  So it's often best to ignore the serial
+\ debugging feature in this file, perhaps using it in later files after the
+\ bridges have been set up.  Port80 debug generally suffices herein.
+
+[ifdef] debug-reset
+.( debug reports enabled ) cr
+: init-com1  ( -- )
+    1 3fc  risa-c!	\ DTR on
+   80 3fb  risa-c!	\ Switch to bank 1 to program baud rate
+   01 3f8  risa-c!	\ Baud rate divisor low - 115200 baud
+    0 3f9  risa-c!	\ Baud rate divisor high - 115200 baud
+    3 3fb  risa-c!	\ 8 bits, no parity, switch to bank 0
+;
+\ Assembler macro to assemble code to send the character "char" to COM1
+: report  ( char -- )
+   " begin   3fd # dx mov   dx al in   20 # al and  0<> until" evaluate
+   ( char )  " # al mov   3f8 # dx mov  al dx out  " evaluate
+   " begin   3fd # dx mov   dx al in   20 # al and  0<> until" evaluate
+;
+\ Put character in al
+: reportc
+   " al ah mov " eval
+   " begin   3fd # dx mov  dx al in   20 # al and  0<> until" evaluate
+   ( char )  " ah al mov   3f8 # dx mov  al dx out  " evaluate
+   " begin   3fd # dx mov  dx al in   20 # al and  0<> until" evaluate
+;
+[else]
+: report    ( char -- )  drop  ;
+: reportc  ( -- )    ;
+[then]
+
+\ Real Mode Startup
+
+label rm-startup	\ Executes in real mode with 16-bit operand forms
+
+   \ ffff.fc00	GDT
+hex
+
+   0    w,  0         l,	 0      w,  \ 0 Mandatory null descriptor
+   0    w,  0         l,	 0      w,  \ * Another null descriptor
+   ffff w,  9b.000000 l,  00.c.f w,  \ 10 Code, linear=physical, full 4Gbytes
+   ffff w,  93.000000 l,  00.c.f w,  \ 18 Data, linear=physical, full 4Gbytes
+
+   \ ffff.fc20	GDT limit + address
+
+   1f w,  ffff.fc00 l,	\ # slots (4 * 8 - 1) ,  starting address
+   0  w,		\ Padding
+
+   \ ------->>>>> Startup code, reached by branch from main entry point below
+   \
+   \ ffff.fc28
+
+   here		\ Mark the beginning of this code so its size may be determined
+		\ and so that a jump to it may be assembled later.
+
+   16-bit
+
+   h# 01 port80
+   cld
+
+\ Normally it's best to keep this file short, thus minimizing the time spend
+\ in 16-bit real mode (which is painful to program in).  But some CPUs start
+\ out with a really slow clock, only running fast after you turn on the PLL.
+\ On such machines, if you are trying to achieve the fastest possible startup,
+\ it makes sense to put the PLL turnon code here, thus minimizing the number
+\ of instructions executed in slow mode.
+
+   h# 02 port80
+
+[ifdef] debug-reset
+init-com1
+carret report	 \ send it to com1 if you can...
+linefeed report  \ send it to com1 if you can...
+ascii F report	 \ send it to com1 if you can...
+[then]
+
+   \ The following instruction uses the CS: segment override because
+   \ that segment is currently "boosted" up into the ROM space.
+   \ It uses the operation size override to load a 32-bit pointer.
+   \ The address override is not used; the GDT limit/address data structure
+   \ above is reachable with a 16-bit address and through the "boosted"
+   \ code segment.
+
+   op: cs:  0f c, 01 c, 16 c, fc20 w,	\ lgdte  cs:[fc20]   Setup GDT
+
+   op: cr0  bx  mov	\ Get existing CR0 value
+
+   1 #  bl  or		\ Set "protected mode" bit
+
+   bx  cr0  mov		\ Enter protected mode
+   ahead  then		\ jmp to next location to flush prefetch queue
+                        \ note: CPL is now 0
+
+   h# 03 port80
+
+   \ We are in protected mode, but we are still executing from old
+   \ 16-bit code segment, and will continue to do so until the far jump
+   \ below
+
+[ifdef] debug-reset
+ascii o report
+[then]
+
+   \ set segment registers
+   bx   bx  xor			\ Clear high byte
+   h# 18 # bl  mov		\ Data segment selector
+   bx   ds  mov			\ Set segment register
+   bx   es  mov			\ Set segment register
+   bx   fs  mov			\ Set segment register
+   bx   gs  mov			\ Set segment register
+
+[ifdef] debug-reset
+ascii r report
+[then]
+
+   bx   ss  mov			\ Set segment register
+
+[ifdef] debug-reset
+ascii t report
+ascii h report
+[then]
+
+   h# 0f port80
+
+   op: ad: ResetBase h# 10 #)  far jmp	\ Jump to Forth startup
+
+   \ Pad the startup code so that the main entry point ends up at the
+   \ correct address.
+
+   here over -   ( adr , size-of-preceding-code )
+
+   \ ffff.fc28 is the location of the code that follows the GDT
+   h# ffff.fff0 h# ffff.fc28 - swap - ( address #bytes-to-pad )
+
+   \ The code mustn't extend past ffff.ffc0, because that is where PC
+   \ manufacturers put the 0x10-byte BIOS version string.
+   dup h# 30 -  also forth 0< previous abort" Real mode startup code is too big"
+
+   also forth  here over h# ff fill  previous	\ fill with FFs
+   ( #bytes-to-pad ) allot	\ Pad out to ffff.fff0
+
+   \ ------->>>>> Main Entry Point
+   \ 
+   \ ffff.fff0 - This is the hardwired address where the processor jumps
+   \             when it comes out of reset
+
+   16-bit
+   cli			\ Turn off interrupts (does not affect NMI) 
+   #) jmp		\ Relative jump back to ffff.fc28
+   h# ffffffff l,
+   h# ffffffff l,
+   h# ffffffff l,	\ Good place to put a CRC
+end-code
+
+end-assembling
+
+writing rmreset.img
+rm-startup here over - ofd @ fputs
+ofd @ fclose
+
+here rm-startup - constant /rm-startup
+/rm-startup h# 400 <>  abort" Real mode startup code is not the right size"
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2008 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Modified: cpu/x86/pc/linux.fth
===================================================================
--- cpu/x86/pc/linux.fth	2008-12-24 21:16:22 UTC (rev 1049)
+++ cpu/x86/pc/linux.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -135,6 +135,7 @@
 
 \ If we are running in physical address mode, make a page directory
 \ that will map up when the kernel turns on paging.
+[ifdef] fw-map-limit
 : v=p-pde  ( adr -- )
    dup h# 83 or  cr3@  rot d# 22 rshift la+  l!
 ;
@@ -145,6 +146,7 @@
    fw-map-limit fw-map-base  do  i v=p-pde  h# 40.0000 +loop
    cr4@  h# 10 or  cr4!
 ;
+[then]
 
 : linux-fixup  ( -- )
 [ifdef] linux-logo  linux-logo  [then]
@@ -153,7 +155,7 @@
 
    linux-base  linux-params  (init-program)
    linux-params to %esi
-   make-ofw-pdir
+   [ifdef] make-ofw-pdir  make-ofw-pdir  [then]
    linux-hook
 ;
 

Added: cpu/x86/startmacros.fth
===================================================================
--- cpu/x86/startmacros.fth	                        (rev 0)
+++ cpu/x86/startmacros.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,148 @@
+\ See license at end of file
+
+\ Some x86 assembler macros to make it easier to write x86 early
+\ startup code.  There are macros to set MSRs to specific values,
+\ to set and clear individual MSR bits, to read and write PCI
+\ configuration registers with the common CF8/CFC mechanism,
+\ and to read and write I/O ports.
+
+\ The code keeps the MSR register number in %ecx, the low 32 bits
+\ of the value in %eax, and the high 32 bits in %edx, consistent
+\ with the way the rdmsr and wrmsr machine instructions work.
+
+\ The bitset and bitclr operations work on %eax, and the -hi versions
+\ work on %edx.
+
+\ The I/O port operations also leave the data in %eax, so you can
+\ use bitset and bitclr with them too.
+
+-1 value last-cx
+also 386-assembler definitions
+
+\ If you do any direct manipulation of ECX in your startup code,
+\ say "forget-msr" afterwards, so the MSR access macro will know
+\ that ECX needs to be reloaded.
+
+: forget-msr  -1 to last-cx  ;
+
+\ set-cx is an internal implementation factor used by wmsr and rmsr.
+\ It assembles code to put an MSR number in %ecx, optimizing out
+\ unnecessary code by remembering what was last put there.
+
+: set-cx  ( reg# -- )
+   [ also forth ]
+   dup last-cx =  if
+      drop
+   else
+      dup to last-cx
+      [ previous ] # cx mov  [ also forth ]
+   then
+   [ previous ]
+;
+
+\ Read/write an MSR to/from %edx,%eax
+: rmsr  ( reg# -- )  set-cx   h# 0f c,  h# 32 c,  ;
+: wmsr  ( reg# -- )  set-cx   h# 0f c,  h# 30 c,  ;
+
+\ These bit operations can be used between "rmsr" and "wmsr"
+
+\ Bit operations on the low 32-bit value in %eax
+: bitset  ( mask -- )  # ax or  ;
+: bitand  ( mask -- )  # ax and  ;
+: bitclr  ( mask -- )  invert  bitand  ;
+
+\ Bit operations on the high 32-bit value in %edx
+: bitset-hi  ( mask -- )  # dx or  ;
+: bitand-hi  ( mask -- )  # dx and  ;
+: bitclr-hi  ( mask -- )  invert  bitand-hi  ;
+
+\ Set an MSR to a verbatim 64-bit value
+: set-msr    ( d.val reg# -- )   -rot # dx mov  # ax mov  wmsr  ;
+
+\ Set or clear bits in an MSR (read-modify-write the register)
+: bitset-msr ( mask reg# -- )  tuck rmsr  bitset  wmsr  ;
+: bitclr-msr ( mask reg# -- )  tuck rmsr  bitclr  wmsr  ;
+
+\ Some I/O port operations
+\ These could be optimized to generate the immediate forms of in and out
+\ for 8-bit port numbers, but it's not worth the trouble because we
+\ access very few low-numbered ports.
+: port-wb  ( b port# -- )   swap # al mov   # dx mov  al dx out  ;
+: port-rb  ( port# -- )  # dx mov  dx al in  ;
+: port-ww  ( w port# -- )   swap # ax mov   # dx mov  op: ax dx out  ;
+: port-rw  ( port# -- )  ax ax xor  # dx mov  op: dx ax in  ;
+: port-wl  ( l port# -- )  swap # ax mov   # dx mov  ax dx out  ;
+: port-rl  ( port# -- )  # dx mov  dx ax in  ;
+
+[ifdef] no-port80
+: port80  ( byte -- )  drop  ;
+[else]
+: port80  ( byte -- )  " # al mov  al h# 80 # out" evaluate  ;
+[then]
+
+: config-setup  ( config-adr -- )
+   [ also forth ]
+   dup 3 invert and  h# 8000.0000 or   ( config-adr cf8-value )
+   [ previous ]
+   #  ax  mov                          ( config-adr )
+   h# cf8 #  dx  mov                   ( config-adr )
+   ax dx out                           ( config-adr )
+   [ also forth ]
+   3 and h# cfc or                     ( data-port )
+   [ previous ]
+   # dx mov
+;
+: config-wl  ( l config-adr -- )
+   config-setup  ( l )
+   #  ax  mov
+   ax dx out
+;
+: config-rl  ( config-adr -- )  \ Returns value in EAX
+   config-setup
+   dx ax in
+;
+: config-ww  ( w config-adr -- )
+   config-setup     ( w )
+   op: # ax  mov    ( )
+   op: ax dx out
+;
+: config-rw  ( config-adr -- )  \ Returns value in AX
+   config-setup     ( )
+   ax ax xor
+   op: dx ax in
+;
+: config-rb  ( config-adr -- )  \ Returns value in AL
+   config-setup     ( )
+   ax ax xor
+   dx al in
+;
+
+: set-base  ( adr -- )  # bx mov  ;
+: reg-save  ( offset -- )  [bx] ax mov  ax stos  ;
+: reg-restore  ( offset -- )  ax lods  ax  swap [bx]  mov  ;
+
+previous definitions
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: dev/isa/soundblaster.fth
===================================================================
--- dev/isa/soundblaster.fth	                        (rev 0)
+++ dev/isa/soundblaster.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,378 @@
+purpose: SoundBlaster driver
+copyright: Copyright 1997 FirmWorks  All Rights Reserved
+
+hex
+
+headers
+\needs +i            : +i  ( adr len n -- adr' len' )   encode-int encode+  ;
+\needs encode-null   : encode-null  ( -- adr len )  0 0 encode-bytes   ;
+\needs microseconds  : microseconds  ( n -- )  0 do  d# 4 0 do loop  loop  ;
+
+0 0  " i220"  " /isa" begin-package
+   " sound"  device-name
+   " sound"  device-type
+
+   h# 10 encode-int      " #channels"   property
+
+   encode-null " built-in" property
+
+   encode-null
+      d#  9 encode-int encode+  1 encode-int encode+	\ Input (capture)
+      d# 15 encode-int encode+  1 encode-int encode+	\ Output (playback)
+   " interrupts"  property
+
+   encode-null
+   \ Channel Type(2=F)  DataBits  CountBits  BusMastering?
+      0 +i      3 +i      8 +i     d# 16 +i      0 +i	\ First channel
+      5 +i      3 +i      8 +i     d# 16 +i      0 +i	\ Second channel
+   " dma" property
+
+
+true instance value use-dma?		\ set at open
+false instance value polled-mode?	\ set at read/write/tone
+
+: dma-alloc    ( n -- vaddr )  " dma-alloc" $call-parent  ;
+: dma-free     ( vaddr n -- )  " dma-free" $call-parent  ;
+
+1 value dma-channel#
+: >chan  ( offset -- port )  dma-channel# wa+  ;
+: low-page  ( -- port )  " "(87 83 81 82)" drop dma-channel# + c@  ;
+: high-page  ( -- port )  low-page h# 400 +  ;
+: dma-setup  ( vadr len write-memory? -- vadr devaddr len )
+   if  44  else  48  then  dma-channel# +  b pc!   \ single transfer, increment addr,
+				                   \ no autoinit, ch 0
+   \ Autoinit adds the 0x10 bit
+
+   2dup true  " dma-map-in" $call-parent  swap     ( vadr devadr len )
+
+   \ Load count
+   0 c pc!		        \ Reset address byte pointer
+   dup 1- wbsplit  swap  1 >chan pc!  1 >chan pc!  ( vadr devadr len )
+
+   \ Load address
+   0 c pc!		        \ Reset address byte pointer
+   over  lbsplit  2swap  swap
+   0 >chan pc!  0 >chan pc!	( vadr devadr len page-byte hi-byte )
+   swap low-page pc!		( vadr devadr len hi-byte )
+   high-page pc!		( vadr devadr len )
+
+   c0 d6 pc!  			\ Set cascade mode for channel 4
+   0 d4 pc!			\ Release channel 4 (master for chs. 0-3)
+
+   0 dma-channel# +  a pc!	\ Release channel
+
+\   10 8 pc!			\ re-enable the chip
+;
+: dma-wait  ( vaddr devaddr len -- timeout? )
+   1 dma-channel# <<  true swap
+   d# 400  0  do
+      dup 8 pc@  and  if  nip 0 swap  leave  then
+      d# 10 ms
+   loop
+   drop
+   >r
+   " dma-map-out" $call-parent
+   r>
+;
+
+: mixer!   ( byte regnum -- )  h# 224 pc!  h# 225 pc!  ;
+: mixer@   ( regnum -- byte)   h# 224 pc!  h# 225 pc@  ;
+
+\ 82 is the IRQ status register
+: irq-wait  ( vaddr devaddr len bit -- timeout? )
+   true swap            ( vaddr devaddr len timeout? bit )
+   d# 400  0  do        ( vaddr devaddr len timeout? bit )
+      dup 82 mixer@  and  if  nip 0 swap  leave  then
+      d# 10 ms          ( vaddr devaddr len timeout? bit )
+   loop                 ( vaddr devaddr len timeout? bit )
+   drop                 ( vaddr devaddr len timeout? )
+   >r
+   " dma-map-out" $call-parent
+   r>
+;
+
+\ The SCR0 value "1c" enables the audio device at port 220, the joystick
+\ at port 201, and establishes the port address of (but does not enable)
+\ the FM synthesizer at port 388.
+: enable  ( -- )
+\   0 h# fb pc!  0 h# e0 pc!  h# 1c h# e1 pc!   0 h# f9 pc!
+   3 h# 40 mixer!       \ Enable the synthesizer and game ports
+;
+
+: read1  ( -- byte )  begin  h# 22e pc@ h# 80 and  until  h# 22a pc@  ;
+
+: wait-reset  ( -- )
+   get-msecs
+   begin                                                 ( old-ms )
+     h# 22e pc@ h# 80 and  if                            ( old-ms )
+        h# 22a pc@  h# aa =  if  drop exit  then         ( old-ms )
+     then                                                ( old-ms )
+     get-msecs over -  2 >=                              ( old-ms flag )
+  until                                                  ( old-ms )
+  drop
+;
+
+: rddata@  ( -- b )  22c pc@  ;
+: cmd  ( cmd -- )  begin  rddata@  h# 80 and  0= until  h# 22c pc!  ;
+: cmd1!  ( data cmd -- data )  cmd cmd  ;
+: cmd1@  ( cmd -- data )  cmd read1  ;
+: cmd2!  ( data data cmd -- data )  cmd cmd cmd  ;
+: cmd2@  ( cmd -- data data )  cmd read1 read1  ;
+
+: put8  ( byte -- )  10 cmd1!  ;
+: get8  ( -- byte )  20 cmd1@  ;
+\ : put16  ( word -- )  11 cmd1!  ;
+\ : get16  ( -- word )  21 cmd1@  ;
+
+: start-out8-normal   ( length -- )  1-  wbsplit swap  14 cmd2!  ;
+\ : start-out16-normal  ( length -- )  1-  wbsplit swap  15 cmd2!  ;
+: start-out8-auto     ( length -- )  1-  wbsplit swap  1c cmd2!  ;
+\ : start-out16-auto    ( length -- )  1-  wbsplit swap  1d cmd2!  ;
+
+: start-out8-fast  ( -- )  90 cmd  ;
+: start-out16-fast  ( -- )  91 cmd  ;
+: halt-dma8  ( -- )  d0 cmd  ;
+\ d1 and d3 above
+: continue-dma8  ( -- )  d4 cmd  ;
+: halt-dma16  ( -- )  d5 cmd  ;
+: continue-dma16  ( -- )  d6 cmd  ;
+: exit-dma16  ( -- )  d9 cmd  ;
+: exit-dma8  ( -- )  da cmd  ;
+\ e0 returns the bitwise inverse of its argument byte, for probing
+\ e3 returns a copyright string
+\ e4 writes a test register, e8 reads it back
+\ f2 and f3 force an irq
+
+\ : start-in8-normal   ( length -- )  1-  wbsplit swap  24 cmd2!  ;
+\ : start-in16-normal  ( length -- )  1-  wbsplit swap  25 cmd2!  ;
+\ : start-in8-auto     ( length -- )  1-  wbsplit swap  2c cmd2!  ;
+\ : start-in16-auto    ( length -- )  1-  wbsplit swap  2d cmd2!  ;
+
+: set-block-size  ( n -- )  1-  wbsplit swap  48 cmd2!  ;
+
+: set-time-constant  ( b -- )  40 cmd1!  ;   \ rate = 1,000,000 / (256 - n)
+: set-freq           ( w -- )  1- wbsplit swap  41 cmd2!  ;  \ 
+
+0 instance value sample-counts
+0 instance value sample-rate
+
+: 1sample-time  ( -- )  sample-counts  0  do  loop  ;
+: sb-sample!  ( byte -- )  put8 1sample-time  ;
+: sb-sample@  ( -- byte )  get8 1sample-time  ;
+: passthrough  ( seconds -- )
+   sample-rate *  0  do  get8 put8 1sample-time  loop
+;
+
+: set-sample-rate  ( hz -- )
+   dup to sample-rate
+   ms-factor d# 1000 rot */  to sample-counts
+;
+
+: 8kmono  ( -- )  d# 131  set-time-constant  h# 8000 set-sample-rate  ;
+: 8kstereo  ( -- )  d# 16000  set-freq  h# 8000 set-sample-rate  ;
+: 16kmono  ( -- )  d# 16000  set-freq  h# 16000 set-sample-rate ;
+: 11kmono  ( -- )  d# 165  set-time-constant  h# 11025 set-sample-rate  ;
+: 11kstereo  ( -- )  d# 11025  set-freq  h# 11025 set-sample-rate  ;
+: 22kmono    ( -- )  d# 22050  set-freq  h# 22050 set-sample-rate  ;
+
+: dac>mixer  ( -- )  d# 100 ms  h# d1 cmd  ;
+: undac>mixer  ( -- )  d# 25 ms  h# d3 cmd  ;
+: reset  ( -- )
+   enable  
+   1 h# 226 pc!  
+   d# 300 ms  0 h# 226 pc!  wait-reset  dac>mixer
+;
+
+[ifndef] rounded-/
+\ Integer division which rounds to nearest instead of truncating
+: rounded-/  ( dividend divisor -- rounded-result )
+   swap 2*  swap /  ( result*2 )
+   dup 1 and +      \ add 1 to the result if it is odd
+   2/               ( rounded-result )
+;
+[then]
+
+defer sample!  ['] sb-sample! to sample!
+defer sample@  ['] sb-sample@ to sample@
+
+: dma-sample@  ( adr size -- actual )
+\   dup set-block-size
+   tuck                ( size  adr size )
+   true dma-setup      ( size  vadr devadr len )
+   \ use "2 irq-wait" for 16-bit DMA
+   1 irq-wait  if  drop 0  then   ( actual )
+;
+: dma-sample!  ( adr size -- actual )
+\   dup set-block-size
+   tuck                   ( size adr size )
+   false dma-setup        ( size vadr devadr len )
+   dac>mixer              ( size vadr devadr len )
+   dup start-out8-normal  ( size vadr devadr len )
+   1 irq-wait  if  drop 0  then   ( actual )
+   undac>mixer                  ( actual )
+;
+
+\ Mixer 80 is IRQ#
+\ Mixer 81 is DMA  hdma and dma
+\ Mixer 82 is IRQ status
+
+: stereo  ( -- )  2 h# 0e mixer!  ;
+: mono    ( -- )  0 h# 0e mixer!  ;
+
+: reset-mixer  ( -- )  0 0 mixer!  ;
+
+: dac-volume  ( l/r -- )  14 mixer!  ;
+: mic-mix-volume  ( l/r )  1a mixer!  ;
+: record-mic   ( -- )  0 1c mixer!  ;
+: record-cd    ( -- )  2 1c mixer!  ;
+: record-line  ( -- )  6 1c mixer!  ;
+: record-mixer ( -- )  7 1c mixer!  ;
+
+: master-volume  ( l/r -- )  22 mixer!  ;
+: fm-volume  ( l/r -- )  26 mixer!  ;
+: auxa-volume  ( l/r -- )  28 mixer!  ;
+: auxb-volume  ( l/r -- )  2a mixer!  ;
+: pc-speaker-volume  ( l/r -- )  2c mixer!  ;
+\ : line-volume  ( l/r -- )  2e mixer!  ;
+
+h# cc constant initial-gain
+
+external
+
+\ Determine chip type by looking for register bit differences
+: init  ( -- )
+   enable
+   " SoundBlaster"
+   2dup model                ( $ )
+   encode-string
+\     " pnpPNP,b007" encode-string encode+   \ Windows Sound System compatible
+   " pnpPNP,b002" encode-string encode+   \ SoundBlaster Pro compatible
+   " pnpPNP,b000" encode-string encode+   \ SoundBlaster compatible
+   " compatible" property
+
+   \ Probe for the FM synthesizer
+
+   h# 220 my-space d# 16  encode-reg  ( adr len )  \ Soundblaster
+
+   \ If the synthesizer address port is writeable, add the synthesizer
+   \ register to the property value
+
+   h# 5a 38a pc!  38a pc@  h# 5a =  if
+      h# 388 my-space d#  4  encode-reg encode+   \ Synthesizer
+   then
+   " reg" property
+
+   \ Put the synthesizer address port back to its default value, just in case
+   1 h# 38a pc!
+;
+
+: dma  ( -- )  true to use-dma?  ;
+: pio  ( -- )  false to use-dma?  ;
+: change-mode  ( -- )
+   my-args  begin  dup  while       \ Execute mode modifiers
+      ascii , left-parse-string            ( rem$ first$ )
+      my-self ['] $call-method  catch  if  ( rem$ x x x )
+         ." Unknown argument" cr
+         3drop 2drop false exit
+      then                                 ( rem$ )
+   repeat                                  ( rem$ )
+   2drop
+;
+: open  ( -- flag? )
+   change-mode
+   reset 
+   initial-gain master-volume
+   true  
+;
+: close  ( -- )  0 master-volume  ;
+
+: read  ( addr size -- actual )
+   use-dma?  if
+      false to polled-mode?
+
+      dup dma-alloc over 2dup 2>r
+      dma-sample@
+      nip 2r@ drop -rot dup >r move r>
+      2r> dma-free
+   else
+      true to polled-mode?
+
+      tuck  bounds ?do  sample@  i c!  loop
+   then
+;
+: write  ( adr size -- actual )
+   use-dma?  if
+      false to polled-mode?
+
+      dup dma-alloc swap 2dup 2>r move
+      2r@ dma-sample!
+      2r> dma-free
+   else
+      true to polled-mode?
+      tuck  bounds ?do  i c@ sample!  loop
+   then
+;
+decimal
+
+\ This table contains all 4 quadrants of the sine function, biased with the
+\ zero point at d# 128, and beginning at -pi/2 radians (-90 degrees).  This
+\ is convenient for sampling.
+create sine
+   0 c,    3 c,   10 c,   22 c,   38 c,   57 c,   79 c,  104 c,
+ 128 c,  152 c,  177 c,  199 c,  218 c,  234 c,  246 c,  253 c,
+ 255 c,  253 c,  246 c,  234 c,  218 c,  199 c,  177 c,  152 c,
+ 128 c,  104 c,   79 c,   57 c,   38 c,   22 c,   10 c,    3 c,
+hex
+
+0 value sample-buf
+0 value /sample-buf
+
+\ Play a tone of the given frequency and duration
+: tone  ( hz msecs -- )
+   8kmono
+
+   8 *                                  ( hz samples )
+   dup to /sample-buf  dup dma-alloc  to sample-buf
+
+   \ We divide the circle into 64K counts, increment the angle by "delta"
+   \ counts each sample, and pick the closest entry in the sine table.
+   \ Here we compute the delta angle from the frequency as:
+   \   delta (counts/sample) =
+   \      freq (cycles/sec) * 64K (counts/cycle) / 8000 (samples/sec)
+
+   swap  d# 16 lshift  d# 8000 /  swap  ( delta samples )
+
+   true to polled-mode?                 ( delta samples )
+
+   0 swap  0  do                        ( delta angle )
+      \ Round to nearest sample ("400 +).  For lower distortion,
+      \ we could increase the number of entries in the sine table
+      \ and/or interpolate between entries, but it hardly seems
+      \ worth the trouble for this application.
+      dup  h# 400 +  d# 11 rshift  h# 1f and  sine + c@
+
+      sample-buf i + c!
+
+      \ Update angle, taking advantage of 2-complement arithmetic
+      \ to do the modulus for us.  We don't worry about the carry
+      \ into the high bits here, because the "1f and" above will
+      \ throw them away for us.
+      over +                            ( delta angle' )
+   loop                                 ( delta angle' )
+   2drop                                ( )
+
+   sample-buf /sample-buf dma-sample! drop
+   sample-buf /sample-buf dma-free
+;
+
+: ring-bell  ( -- )
+   open drop
+   d# 2000  d# 100  tone  close
+;
+end-package
+
+also forth definitions
+stand-init: Sound
+   " /isa/sound" " init" execute-device-method drop
+;
+previous definitions

Added: dev/ne2000/ne2kpci.bth
===================================================================
--- dev/ne2000/ne2kpci.bth	                        (rev 0)
+++ dev/ne2000/ne2kpci.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,17 @@
+\ See license at end of file
+purpose: Main load file for driver
+
+command: &tokenize &this
+build-now
+
+silent on
+
+begin-tokenizing ne2kpci.fc
+
+FCode-version2
+
+fload ${BP}/dev/ne2000/ne2kpci.fth
+
+end0
+
+end-tokenizing

Added: dev/ne2000/ne2kpci.fth
===================================================================
--- dev/ne2000/ne2kpci.fth	                        (rev 0)
+++ dev/ne2000/ne2kpci.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,660 @@
+purpose: PCI variant of NE2000 network controller
+\ See license at end of file
+
+\ 0 0  " i300"  " /isa"  begin-package
+
+\ NE2000 controller board offsets
+
+" ethernet" device-name
+
+h# 10 constant dataport		\  NE2000 Port Window.
+
+[ifdef] ISA
+my-address my-space h# 20 reg
+my-address value chip-base
+: 1us  ( -- )  h# 61 pc@ drop  ;  \ Touch timer port to pause
+: reg!  ( b offset -- )  chip-base +  pc!  1us  ;
+: reg@  ( offset -- b )  chip-base +  pc@  1us  ;
+: data-out  ( adr -- )  le-w@ dataport chip-base +  pw!  ;
+: data-in   ( adr -- )  dataport chip-base +  pw@  swap le-w!  ;
+: map-regs ;  : unmap-regs ;
+[else]
+h# 100 constant /regs
+
+\ Configuration space registers
+my-address my-space              encode-phys
+                             0     encode-int encode+ 0 encode-int encode+
+
+\ I/O space registers
+0 0        my-space  0100.0010 + encode-phys encode+
+                             0 encode-int encode+  /regs encode-int encode+
+ " reg" property
+
+0 instance value chip-base
+
+: my-w@  ( offset -- w )  my-space +  " config-w@" $call-parent  ;
+: my-w!  ( w offset -- )  my-space +  " config-w!" $call-parent  ;
+: unmap-regs  ( -- )
+   4 my-w@  6 invert and  4 my-w!
+   chip-base /regs " map-out" $call-parent
+;
+: map-regs  ( -- )
+   0 0  my-space h# 0100.0010 +  /regs " map-in" $call-parent  to chip-base
+   4 my-w@  5 or  4 my-w!
+;
+: reg!  ( b offset -- )  chip-base +  rb!  ;
+: reg@  ( offset -- b )  chip-base +  rb@  ;
+: data-out  ( adr -- )  w@ dataport chip-base +  rw!  ;
+: data-in   ( adr -- )  dataport chip-base +  rw@  swap w!  ;
+
+[then]
+
+" network" device-type
+
+headerless
+
+[ifdef] 386-assembler
+[ifndef] pseudo-dma-in
+fload ${BP}/cpu/i386/inoutstr.fth
+[then]
+[then]
+
+\ The EN registers - the DS8390 chip registers
+\ There are two (really 3) pages of registers in the chip. You select
+\ which page you want, then address them at offsets 00-0F from base.
+\ The chip command register (CCMD; offset 0) appears in both pages.
+
+\ Page 1
+
+h# 001 constant PHYS	\ This board's physical enet addr RD WR
+h# 007 constant CURPAG	\ Current memory page RD WR
+h# 008 constant MULT	\ Multicast filter mask array (8 bytes) RD WR
+
+\ Chip commands in command register
+h# 001 constant STOP	\ Stop the chip
+h# 002 constant START	\ Start the chip
+h# 004 constant TRANS	\ Transmit a frame
+h# 008 constant RREAD	\ remote read
+h# 010 constant RWRITE	\ remote write
+h# 020 constant NODMA	\ No remote DMA used on this card
+h# 000 constant PAGE0	\ Select page 0 of chip registers
+h# 040 constant PAGE1	\ Select page 1 of chip registers
+
+\ Commands for RXCR - RX control reg
+h# 001 constant RCRC	\ Save error pkts
+h# 002 constant RUNT	\ Accept runt pkt
+h# 004 constant BCST	\ Accept broadcasts
+h# 008 constant MULTI	\ Multicast (if pass filter)
+h# 010 constant PROMP	\ Promiscuous physical addresses
+h# 020 constant MON	\ Monitor mode (no packets rcvd)
+
+\ Bits in TXCR - transmit control reg
+h# 001 constant TCRC	\ inhibit CRC, do not append crc
+h# 002 constant LOOPB	\ Set loopback mode
+h# 006 constant LB01	\ encoded loopback control
+h# 008 constant ATD	\ auto tx disable
+h# 010 constant OFST	\ collision offset enable
+
+\ Bits in DCFG - Data config register
+h# 001 constant WTS	\ word transfer mode selection
+\ h# 002 constant BOS	\ byte order selection
+\ h# 004 constant LAS	\ long addr selection
+\ h# 008 constant BMS	\ burst mode selection
+\ h# 010 constant ARM	\ autoinitialize remote
+\ h# 000 constant FT00	\ burst length selection
+\ h# 020 constant FT01	\ burst length selection
+\ h# 040 constant FT10	\ burst length selection
+\ h# 060 constant FT11	\ burst length selection
+
+\ Bits in ISR - Interrupt status register
+h# 001 constant RX	\ Receiver, no error
+h# 002 constant TX	\ Transmitter, no error
+h# 004 constant RX-ERR	\ Receiver, with error
+h# 008 constant TX-ERR	\ Transmitter, with error
+h# 010 constant OVR	\ Receiver overwrote the ring
+h# 020 constant COUNTERS	\ Counters need emptying
+h# 040 constant RDC	\ remote dma complete
+h# 080 constant RESET	\ Reset completed
+
+h# 03f constant ALL	\ Interrupts we will enable
+
+\ Bits in received packet status byte and RSR
+h# 001 constant RXOK	\ Received a good packet
+h# 002 constant CRCE	\ CRC error
+h# 004 constant FAE	\ frame alignment error
+h# 008 constant FO	\ FIFO overrun
+h# 010 constant MPA	\ missed pkt
+h# 020 constant PHY	\ physical/multicase address
+h# 040 constant DIS	\ receiver disable. set in monitor mode
+h# 080 constant DEF	\ deferring
+
+\ Bits in TSR -  TX status reg
+
+h# 001 constant PTX	\ Packet transmitted without error
+h# 002 constant DFR	\ non deferred tx
+h# 004 constant COLL	\ Collided at least once
+h# 008 constant COLL16	\ Collided 16 times and was dropped
+h# 010 constant CRS	\ carrier sense lost
+h# 020 constant FU	\ TX FIFO Underrun
+h# 040 constant CDH	\ collision detect heartbeat
+h# 080 constant OWC	\ out of window collision
+
+\ Description of header of each packet in receive area of memory
+
+h# 0 constant STAT	\ Received frame status
+h# 1 constant NXT-PG	\ Page after this frame
+h# 2 constant SIZE-LO	\ Length of this frame
+h# 3 constant SIZE-HI	\ Length of this frame
+h# 4 constant NHDR	\ Length of above header area
+
+
+\ Shared memory management parameters
+
+h# 040 constant TSTART-PG	\ First page of TX buffer
+h# 046 constant RSTART-PG	\ Starting page of RX ring
+h# 080 constant RSTOP-PG	\ Last page +1 of RX ring
+
+: longpause  ( -- )  2 ms  ;	\ Should be 1.6 ms
+
+0 instance value #crc-errors
+0 instance value #alignment-errors
+0 instance value #missed
+
+\ Page 0 registers
+: cmd!  ( b -- )  0 reg!  ;
+: stat@  ( -- b )  0 reg@  ;
+: startpg!   ( page# -- )  1 reg!  ;	\ Starting page of ring buffer
+: stoppg!    ( page# -- )  2 reg!  ;	\ Ending page + 1 of ring buffer
+: clda@      ( -- adr )  1 reg@  2 reg@  bwjoin  ;  \ Current local DMA address
+: boundary@  ( -- page# )  3 reg@  ;	\ Boundary page of ring bfr
+: boundary!  ( page# -- )  3 reg!  ;
+: tsr@   ( -- bits )   4 reg@  ;	\ Transmit status reg
+: tpsr!  ( page# -- )  4 reg!  ;	\ Transmit starting page
+: ncr@   ( -- count )  5 reg@  ;	\ Number of collision reg
+: fifo@  ( -- data )   6 reg@  ;	\ FIFO data
+: rcnt!  ( cnt -- )  wbsplit swap  h# 0a reg!  h# 0b reg!  ;
+: tcnt!  ( cnt -- )  wbsplit swap  5 reg!  6 reg!  ;
+: isr@   ( -- mask )  7 reg@  ;		\ Interrupt status reg
+: isr!   ( mask -- )  7 reg!  ;
+: rsr@   ( -- mask )  h# c reg@  ;	\ Receive status reg
+: imr!   ( mask -- )  h# f reg!  ;	\ Interrupt mask reg
+: rxcr!  ( bits -- )  h# c reg!  ;	\ Receive control reg
+: txcr!  ( bits -- )  h# d reg!  ;	\ Transmit control reg
+: dcfg!  ( bits -- )  h# e reg!  ;	\ Data configuration reg
+: counter0@  ( -- count )  h# d reg@  ;  \ Rcv alignment error counter
+: counter1@  ( -- count )  h# e reg@  ;  \ Rcv CRC error counter
+: counter2@  ( -- count )  h# f reg@  ;  \ Rcv missed frame error counter
+: rda!  ( page# -- )  wbsplit swap  8 reg!  9 reg!  ;
+: crda@  ( -- adr )  8 reg@  9 reg@  bwjoin  ;  \ Current remote DMA address
+
+: set-page  ( page# -- old-cmd-reg )  6 lshift  stat@ tuck or cmd!  ;
+: preg@  ( reg# page# -- b )  set-page >r  reg@  r> cmd!  ;
+: preg!  ( b reg# page# -- )  set-page >r  reg!  r> cmd!  ;
+
+: curpag@  ( -- page# )  7 1 preg@  ;
+: curpag!  ( page# -- )  7 1 preg!  ;
+
+: stop-chip  ( -- )  NODMA STOP or cmd!  ;
+: reset-8390  ( -- )
+   h# 1f reg@  longpause  h# 1f reg!   \ should set command 21, 80
+;
+
+0 value endcfg
+
+\ Block input routine
+
+: block-input  ( adr len offset -- )
+   NODMA START or  cmd!
+   rda!  dup rcnt!                      ( adr len )
+   RREAD START or  cmd!		\ read and start
+
+\ [ endcfg WTS and ]  [if]
+   ( buf len )
+[ifdef] pseudo-dma-in
+   dataport chip-base +  pseudo-dma-in
+[else]
+   2dup  1 invert and  bounds  ?do	( adr len )
+      i data-in				( adr len )
+   /w +loop				( adr len )
+   dup 1 and  if			( adr len )
+      + 1- dataport reg@ swap c!
+   else
+      2drop
+   then
+[then]
+\ [else]
+\    bounds  ?do  dataport reg@  i c!  loop
+\ [then]
+;
+
+: block-output  ( adr len offset -- error? )
+   NODMA START or  cmd!	\ stop & clear the chip
+   rda!  dup 1 and +  dup rcnt!     ( adr len )
+   RWRITE START or  cmd!  \ write and start
+   ( buf len )
+[ifdef] pseudo-dma-out
+   dataport chip-base +  pseudo-dma-out
+[else]
+   bounds  ?do  i data-out  /w +loop
+[then]
+
+   h# 10000 0  do
+      isr@  RDC and  if  unloop false exit  then
+   loop
+   true
+;
+
+RSTOP-PG value sm-rstop-ptr
+
+[ifdef] board-features
+0 value is-overrun-690
+[then]
+
+\ a temp buffer for the received header
+d# 4 constant RCV-HDR-SIZE
+RCV-HDR-SIZE buffer: rcv-hdr
+
+0 instance value #rx-errors
+0 instance value #rx-overruns
+0 instance value #tx-errors
+
+\ Next Packet Pointer
+\
+\   Initialize to the same value as the current page pointer (start page 1).
+\   Update after each reception to be the value of the next packet pointer
+\   read from the NIC Header.
+\   Copy value -1 to boundry register after each update.
+\   Compare value with contents of current page pointer to verify that a
+\   packet has been received (don't trust ISR RXE/PRX bits). If !=, one
+\   or more packets have been received.
+
+0 value next-page
+0 value last-curpag
+
+\ Added flags and temp storage for new receive overrun processing
+
+: tx-wait  ( -- )
+   d# 1024 7 *  0  do	\ max coll time in Ethernet slot units
+      d# 51 0  do		\ Wait 1 time slot, assuming 1 usec I/O
+         stat@  TRANS and  0=  if  \ transmitter still running?
+            unloop unloop exit
+         then
+      loop
+   loop
+   #tx-errors 1+ to #tx-errors	\ count hard errors.
+;
+
+[ifdef] interrupt-driven
+: tx-ack  ( -- )
+   tsr@ drop	\ get state from prior TX
+
+   \ Acknowledge the TX interrupt
+   TX TX-ERR or isr! \ clr either possible TX int bit
+;
+[then]
+
+headers
+: write  ( adr len -- actual )
+   stat@  TRANS  and  if
+      tx-wait
+[ifdef] interrupt-driven
+      tx-ack
+   else
+      \ Check for recent TX completions in the interrupt status register
+      isr@ TX TX-ERR  and  if
+         tx-ack
+      then
+[then]
+   then
+
+   d# 1514 min  tuck			     ( len adr len' )
+   d# 60 max				     ( len adr len' )
+
+   RDC isr!	\ clear remote interrupt int.
+
+   dup tcnt!                                 ( len adr len' )
+   TSTART-PG 8 lshift  block-output          ( len error? )
+   if  drop -1 exit  then		     ( len )
+
+   TSTART-PG tpsr!		\ Transmit Page Start Register
+   TRANS NODMA or START or  cmd!	\ Start the transmitter
+;
+headerless
+
+: set-address  ( adr len -- )
+   0  do  dup i + c@  PHYS i + 1 preg!  loop  drop
+;
+
+false value promiscuous?
+false value loopback?
+false value dma?
+BCST value rx-mode
+
+\ Set the multicast filter mask bits for promiscuous reception
+: set-multicast  ( -- )
+   NODMA PAGE1 or STOP or cmd!  \ Select page 1
+   8 0  do  h# ff  MULT i + reg!  loop
+   NODMA START or cmd!  \ Select page 0
+;
+
+: set-rx-mode  ( -- )	\ Set receiver to selected mode
+   BCST  promiscuous?  if  MULTI or  PROMP or  then  rxcr!
+;
+: set-tx-mode  ( -- )  loopback?  if  LOOPB  else  0  then  txcr!  ;
+
+: reset-board  ( -- )
+   reset-8390
+   stop-chip
+
+   \ Wait 1.6ms for the NIC to stop transmitting or receiving a packet.
+   \ National says monitoring the ISR RST bit is not reliable, so a wait
+   \ of the maximum packet time (1.2ms) plus some padding is required.
+
+   longpause
+;
+
+: reset-interface  ( -- )
+   reset-board
+   h# ff isr!		\ Clear all pending interrupts
+   0 imr!		\ Turn off all interrupt enables
+;
+: rx-error  ( -- )
+   #rx-errors 1+ to #rx-errors
+
+   \ Error recovery:
+   \ Copy the last known current page pointer into the next packet pointer
+   \ which will result in skipping all the packets from the errored one to
+   \ where the NIC was storing them when we entered this ISR, but prevents
+   \ us from trying to follow totally bogus next packet pointers through
+   \ the card RAM space.
+
+   last-curpag to next-page
+;
+
+: +boundary  ( -- )
+   next-page 1-  dup RSTART-PG  <  if  drop  sm-rstop-ptr 1-  then
+   boundary!
+;
+
+: next-buffer  ( -- page# )  rcv-hdr NXT-PG + c@  ;
+[ifndef] le-w@  : le-w@  ( adr -- w )  dup c@ swap 1+ c@ bwjoin  ;  [then]
+: packet-ok?  ( -- len true | false )
+   rcv-hdr  RCV-HDR-SIZE  next-page 8 lshift  block-input  ( )
+   rcv-hdr STAT + c@  RXOK and   if                        ( )
+      next-buffer  RSTART-PG sm-rstop-ptr within  if
+         rcv-hdr SIZE-LO + le-w@  NHDR -                   ( len )
+         true                                              ( len true )
+         exit
+      then
+   then
+   \ Bad packet or chip screwup
+   rx-error +boundary  false                               ( false )
+;
+
+\ Do the work of copying out a receive frame.
+: do-receive  ( adr len -- len )
+   tuck  next-page 8 <<  NHDR +  block-input    ( len )
+   next-buffer  to next-page			( len )
+   +boundary                 			( len )
+;
+
+fload ${BP}/dev/ne2000/queue.fth
+
+: pull-packets  ( -- )
+   begin  last-curpag next-page <>  while    ( )
+      packet-ok?  if                         ( length )
+         new-buffer                          ( handle adr len )
+         do-receive drop                     ( handle )
+         enque-buffer                        ( )
+      then                                   ( )
+   repeat                                    ( )
+;
+
+0 value rcv-ovr-resend		\ flag to indicate resend needed
+: overrun  ( mask -- )
+   drop
+[ifdef] board-features
+   board-features BF-NIC-690 and  if
+      1 to is-overrun-690
+      exit
+   then
+[then]
+
+   #rx-overruns 1+ to #rx-overruns
+
+   \ Get the command register TXP bit to test for incomplete transmission later
+
+   stat@  ( status )
+
+   stop-chip
+
+   \ Wait for the NIC to stop transmitting or receiving a packet.
+   longpause
+
+   \ Clear the remote byte count registers
+   0 rcnt!
+
+   \ check the saved state of the TXP bit in the command register
+   0 to rcv-ovr-resend		 \ clear the resend flag
+   ( status ) TRANS  and  if     \ Was transmitter still running?
+      \ Transmitter was running, see if it finished or died
+      isr@  TX TX-ERR  or  0=  if
+         \ Transmitter did not complete, remember to resend the packet later.
+	 true to rcv-ovr-resend
+      then
+   then
+
+   \ Put the NIC chip into loopback so it won't keep trying to
+   \ receive into a full ring
+
+   LOOPB txcr!			\ Put transmitter in loopback mode
+   START NODMA or  cmd!		\ Start the chip running again
+
+   \ Verify that there is really a packet to receive by fetching the current
+   \ page pointer and comparing it to the next packet pointer.
+
+   curpag@ curpag!		\ Rewrite current page to fix SMC bug.
+
+   pull-packets
+
+   +boundary
+
+   \ When we get here we have either removed one packet from the ring and
+   \ updated the boundary register, or determined that there really were
+   \ no new packets in the ring.
+
+   OVER isr!		\ Clear the overrun interrupt bit
+   set-tx-mode		\ Take the NIC out of loopback
+
+   \ Resend any incomplete transmission
+   rcv-ovr-resend  if
+      TRANS NODMA or START or cmd!  \ Start the transmitter
+   then
+;
+
+[ifdef] board-features
+: recv-690-overrun  ( -- )
+   false to is-overrun-690
+   boundary@ boundary!		\ rewrite bndry with itself
+   OVER isr!		\ Clear overrun interrupt bit
+;
+[then]
+
+: empty-counters  ( -- )
+   \ We have to read the counters to clear them and to clear the interrupt.
+   counter0@ #alignment-errors + to #alignment-errors
+   counter1@ #crc-errors       + to #crc-errors
+   counter2@ #missed           + to #missed
+;
+: .errors  ( -- )
+   isr@
+   dup  RX-ERR    and  if  ." RX-ERR "    then
+   dup  TX-ERR    and  if  ." TX-ERR "    then
+   dup  OVR       and  if  ." OVR "  dup overrun  then
+   dup  COUNTERS  and  if  ." COUNTERS "  empty-counters  then
+   isr!
+;
+
+headers
+: read  ( adr len -- -2 | actual )
+   curpag@ to last-curpag            ( adr len )
+
+   .errors                           ( adr len )
+
+   ?return-queued  0=  if            ( adr len )
+      last-curpag  next-page <>  if  ( adr len )
+         packet-ok?  if              ( adr len actual )
+            min do-receive           ( actual | -1 )     \ Good packet
+         else                        ( adr len )
+            2drop -1                 ( -1 )              \ Bad packet
+         then                        ( actual | -1 )
+      else                           ( adr len )
+         2drop -2                    ( -2 )		 \ No packet
+      then                           ( actual | -2 )
+   then                              ( actual | -2 )
+
+   pull-packets
+;
+
+headerless
+h# 10 buffer: board-data
+h# 6 buffer: rom-address
+: init-card  ( -- okay? )
+   \ Put the board data, which is 16 bytes starting at remote
+   \ dma address 0, into a buffer called board-data.
+
+\ [ base c@ base @ <> ]  [if]
+   endcfg WTS or to endcfg
+\ [then]
+   endcfg dcfg!
+
+   NODMA PAGE0 or  START or  cmd!
+
+   0 rda!  h# 20 rcnt!			\ address is 0, byte count is 0x10*2
+   RREAD START or  cmd!			\ read and start
+
+   board-data  h# 10  bounds  do  dataport reg@  i c!  loop
+
+   board-data rom-address 6 move
+   rom-address 6 encode-bytes  " local-mac-address" property
+   true
+;
+
+[ifndef] $=
+: $=  ( $1 $2 -- equal? )
+   rot tuck <>  if  3drop false exit  then  ( adr1 adr2 len1 )
+   comp 0=
+;
+[then]
+
+0 value tftp-args
+0 value tftp-len
+: parse-args  ( -- )
+   my-args  begin                                               ( rem$ )
+      2dup to tftp-len to tftp-args                             ( rem$ )
+   dup  while                                                   ( rem$ )
+      ascii , left-parse-string                                 ( rem$ head$ )
+      2dup  " promiscuous" $=  if  true  to promiscuous?  else  ( rem$ head$ )
+      2dup  " loopback"    $=  if  true  to loopback?     else  ( rem$ head$ )
+      2dup  " pio"         $=  if  false to dma?          else  ( rem$ head$ )
+      2dup  " dma"         $=  if  true  to dma?          else  ( rem$ head$ )
+                                   2drop 2drop exit             ( )
+      then then then then                                       ( rem$ head$ )
+      2drop                                                     ( rem$ )
+   repeat                                                       ( rem$ )
+   2drop                                                        ( )
+;
+
+headers
+\ Called once to initialize the card
+: open  ( -- )
+   map-regs
+   parse-args
+
+   \ Set burst mode, 8 deep FIFO, maybe big-endian
+   h# 48  base c@ base @ <>  if  2 or  then  to endcfg
+
+   reset-board				\ Reset and stop the 8390.
+   endcfg dcfg!				\ Init the Data Config Reg.
+   stop-chip				\ Stop chip and select page 0
+   0 rcnt!				\ Clear Remote Byte Count Regs.
+   MON rxcr!				\ Set receiver to monitor mode
+   LOOPB txcr!				\ Put NIC in Loopback Mode 1.
+
+   \ Do anything special that the card needs.
+   \ Read the Ethernet address into rom-address.
+   init-card  0=  if  false exit  then
+
+   endcfg dcfg!				\ Re-init endcfg in case they
+					\ put it into word mode.
+
+   \ Init STARTPG to same value as BOUNDARY
+   RSTART-PG dup startpg!  boundary!
+   sm-rstop-ptr stoppg!
+
+   h# ff isr!				\ Clear pending interrupts.
+
+\  ALL imr!				\ Init IMR
+   0 imr!				\ Init IMR
+
+   \ Init the Ethernet address and multicast filters.
+   mac-address set-address		\ Now set the address in the 8390 chip
+   set-multicast  			\ Set the multicast masks
+
+   \ Program the Current Page Register to Boundary Pointer + 1
+   RSTART-PG 1+ dup  curpag!
+   dup to last-curpag  to next-page
+
+   set-rx-mode
+   set-tx-mode
+
+   NODMA START or  cmd!			\ Start chip
+
+   init-queue
+
+   true
+;
+: close  ( -- )
+   NODMA STOP or  cmd!			\ Start chip
+   drain-queue
+   unmap-regs
+;
+
+: load  ( adr -- len )
+   " obp-tftp" find-package  if      ( adr phandle )
+      my-args rot  open-package      ( adr ihandle|0 )
+   else                              ( adr )
+      0                              ( adr 0 )
+   then                              ( adr ihandle|0 )
+
+   dup  0=  if  ." Can't open obp-tftp support package" abort  then
+                                     ( adr ihandle )
+
+   >r
+   " load" r@ $call-method           ( len )
+   r> close-package
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Added: dev/video/build/video.bth
===================================================================
--- dev/video/build/video.bth	                        (rev 0)
+++ dev/video/build/video.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,12 @@
+purpose: Load file for Video "super driver"
+
+command: &tokenize &this
+build-now
+
+silent on
+
+begin-tokenizing video.fc
+
+fload ${BP}/dev/video/build/loadfcod.fth
+
+end-tokenizing

Added: dev/video/cirrus.bth
===================================================================
--- dev/video/cirrus.bth	                        (rev 0)
+++ dev/video/cirrus.bth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,42 @@
+\ See license at end of file
+purpose: Main load file for driver
+
+command: &tokenize &this
+build-now
+
+silent on
+
+begin-tokenizing cirrus.fc
+
+FCode-version2
+
+fload ${BP}/dev/video/loadcirrus.fth
+probe
+
+end0
+
+end-tokenizing
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Modified: dev/video/common/pci.fth
===================================================================
--- dev/video/common/pci.fth	2008-12-24 21:16:22 UTC (rev 1049)
+++ dev/video/common/pci.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -69,6 +69,7 @@
 0 instance value fb-base-reg
 
 : munge-map-size  ( raw -- new )	\ Makes a proper map-size argument
+   dup 0=  if  exit  then
 
    1 to mask-val		\ Basically, just walk a one up mask-val value,
    begin			\ anding all the way looking for first non-zero
@@ -128,7 +129,7 @@
       use-cirrus-words		\ Cirrus stuff is inside S3 code      
       " CL54xx" add-arc-ident
       dup case			\ Look for known ID values.
-         b8 of gd5434 endof
+         b8 of gd5434 endof     \ Actually gd5446, but gd5434 is close enough
          a8 of gd5434 endof
          a0 of gd5430 endof
          ac of gd5436 endof
@@ -220,23 +221,26 @@
    0 encode-int encode+ r> encode-int encode+
 ;
 
-false instance value needs-rom
+: add-rom-regs  ( -- )
+   \ If this driver is used for an on board frame buffer, the builtin.fth
+   \ file for that platform should declare a "no-rom" property in the node 
+   \ where this driver is used. This will prevent the reg property from 
+   \ including an entry for a non-existent ROM
 
+   " no-rom" get-my-property 0=  if
+      2drop exit
+   then
+
+   h# 30 get-map-size  if
+      0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
+   then
+;
+
 : encode-reg-property  ( -- )
 
-   " no-rom" get-my-property 0=  if	\ If this driver is used for an on
-      false to needs-rom 2drop		\ board frame buffer, the builtin.fth
-   else					\ file for that platform should declare
-      true to needs-rom			\ a "no-rom" property in the node 
-   then					\ where this driver is used. This will
-					\ prevent the reg property from 
-					\ including an entry for a non-existent
-					\ ROM
    cirrus?  if
          0 0m h# 200.0010 0 h# 10 get-map-size h# 10 >reg-props	\ Frame buffer
-         needs-rom  if
-            0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
-         then
+         add-rom-regs
          legacy-regs
    then
 
@@ -244,9 +248,7 @@
 
       s3-928? s3-964? or s3-864? or s3-868? or if
          h# 000.0000 0m 200.0010 0 h# 100.0000 10 >reg-props	\ Frame buffer
-         needs-rom  if
-            0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
-         then
+         add-rom-regs
          legacy-regs
          h#  102 0m a100.0000 0 1 0  >reg-props		\ Non-relocatable regs
          s3-common-regs
@@ -258,9 +260,7 @@
          h# 100.0000 0m 200.0010 0 h# 1.80a0 10 >reg-props   \ LE MMIO regs
          h# 300.0000 0m 200.0010 0 h# 1.80a0 10 >reg-props   \ BE MMIO regs
 
-         needs-rom  if
-            0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
-         then
+         add-rom-regs
 
          legacy-regs
          h#  102 0m a100.0000 0 1 0  >reg-props		\ Non-relocatable regs
@@ -282,9 +282,7 @@
          h# 100.0000 0m 200.0010 0 h# 1.80a0 10 >reg-props   \ LE MMIO regs
          h# 300.0000 0m 200.0010 0 h# 1.80a0 10 >reg-props   \ BE MMIO regs
 
-         needs-rom  if
-            0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
-         then
+         add-rom-regs
 
          h# a8000 0m a200.0000 0 6900 0 >reg-props	\ MMIO regs
          legacy-regs
@@ -302,26 +300,20 @@
       0 0m h# 200.001c 0 h# 14 get-map-size h# 1c >reg-props
       \ Can't actually probe 20, set = 18
       0 0m h# 200.0020 0 h# 18 get-map-size h# 20 >reg-props
-      needs-rom  if
-         0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props	\ ROM
-      then
+      add-rom-regs
    then
    
 
    mga?  if
       0 0m h# 200.0014 0 h# 14 get-map-size h# 14 >reg-props	\ Frame Buffer
       0 0m h# 200.0010 0 h# 10 get-map-size h# 10 >reg-props	\ IO
-      needs-rom  if
-         0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props	\ ROM
-      then
+      add-rom-regs
       legacy-regs
    then
 
    weitek?  if
       0 0m h# 200.0010 0 h# 10 get-map-size h# 10 >reg-props	\ Memory
-      needs-rom  if
-         0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props	\ ROM
-      then
+      add-rom-regs
       legacy-regs
       h# 102 0m a100.0000 0 1 0 >reg-props	\ Unique non-relocateable IO
       s3-common-regs
@@ -334,16 +326,12 @@
       0 0m h# 200.001c 0 h# 1c get-map-size h# 1c >reg-props	\ Base 3
       0 0m h# 200.0020 0 h# 20 get-map-size h# 20 >reg-props	\ Base 4
       0 0m h# 100.0024 0 h# 24 get-map-size h# 24 >reg-props	\ Base 5
-      needs-rom  if
-         0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props	\ ROM
-      then
+      add-rom-regs
    then
 
    ct?  if
       0 0m h# 200.0010 0 h# 10 get-map-size h# 10 >reg-props	\ Frame buffer
-      needs-rom  if
-         0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
-      then
+      add-rom-regs
       legacy-regs
    then
 
@@ -373,7 +361,6 @@
    " reg" property
 
    reg-props /reg-props free-mem		\ Release the tempory buffer
-
 ;
 
 encode-reg-property			\ Build the reg property now

Modified: dev/video/controlr/cirrus.fth
===================================================================
--- dev/video/controlr/cirrus.fth	2008-12-24 21:16:22 UTC (rev 1049)
+++ dev/video/controlr/cirrus.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -58,13 +58,14 @@
 : use-cirrus-words  ( -- )	\ Turns on the Cirrus-specific words
    ['] init-cirrus-controller to init-controller
    ['] cirrus-textmode        to ext-textmode
-   use-vga-dac
+   use-vga
 ;
 
 : probe-dac  ( -- )		\ Chained probing word...sets the dac type
-   cirrus?  if  use-cirrus-dac exit  then
+   cirrus?  if    use-cirrus-dac exit  then
    probe-dac				\ Try someone else's probe
 ;
+
 \ LICENSE_BEGIN
 \ Copyright (c) 2006 FirmWorks
 \ 

Added: dev/video/controlr/cirruspci.fth
===================================================================
--- dev/video/controlr/cirruspci.fth	                        (rev 0)
+++ dev/video/controlr/cirruspci.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,198 @@
+\ See license at end of file
+purpose: PCI Methods
+
+\ PCI access code.
+\ This code is used to determine which controller is present and
+\ to begin the process of sorting out which specific words are to
+\ be plugged into the various defered words. Also, and just as important,
+\ the REG property gets formed here.
+
+hex
+headers
+
+struct
+   04 field >physlo	\ phys.lo address
+   04 field >physmid	\ phys.mid address
+   04 field >physhi	\ phys.hi address
+   04 field >hiflag	\ phis.hi modifiers (n/p/t... bits)
+   04 field >size1	\ First size
+   04 field >size2	\ Second size
+   04 field >reg#	\ PCI Base address register offset (10,14,18...)
+constant /array
+
+0 instance value reg-props			\ Pointer for temp storage
+0 instance value tpoint				\ A second pointer
+d# 50 /array * instance value /reg-props	\ Allocate 50 entries for now
+
+/reg-props alloc-mem to reg-props		\ Allocate some memory
+reg-props /reg-props erase			\ Clean it up
+
+: >reg-props  ( phys.[lo,mid,hi] hi.flag size size -- )
+
+   reg-props /array - to tpoint   
+   begin
+      tpoint /array + to tpoint
+      tpoint >physhi l@ 0=
+   until				\ tpoint now points to first empty slot
+
+			( phys.[lo,mid,hi] hi.flag size size reg# )
+   tpoint >reg# l!	( phys.[lo,mid,hi] hi.flag size size )
+   tpoint >size2 l!	( phys.[lo,mid,hi] hi.flag size )
+   tpoint >size1 l!	( phys.[lo,mid,hi] hi.flag )
+   tpoint >hiflag l!	( phys.[lo,mid,hi] )
+   tpoint >physhi l!	( phys.lo phys.mid )
+   tpoint >physmid l!	( phys.lo )
+   tpoint >physlo l!	( )
+;
+
+: 0m  ( -- 0 my-space )  0 my-space  ;
+
+: legacy-regs  ( -- )
+      h# 3b0 0m h# a100.0000 0 h# C  0 >reg-props
+      h# 3c0 0m h# a100.0000 0 h# 20 0 >reg-props
+      h# a.0000 0m h# a200.0000 0 h# 2.0000 0 >reg-props
+;
+   
+0 instance value mask-val
+
+: munge-map-size  ( raw -- new )	\ Makes a proper map-size argument
+   dup 0=  if  exit  then
+
+   1 to mask-val		\ Basically, just walk a one up mask-val value,
+   begin			\ anding all the way looking for first non-zero
+      mask-val 2 * to mask-val	\ bit. If chip is working correctly, first non
+      dup mask-val and 0 <>	\ zero bit location tells you how big a 
+   until			\ map-size you need.
+   drop
+   mask-val
+;
+
+: get-map-size  ( reg# -- map-size )	\ Returns the amount of memory required
+   >r r@ c-l@		( old-val )	\ Get old value
+   -1 r@ c-l!		( old-val )	\ Write all ones
+   r@ c-l@ 		( old-val raw )	\ Read back
+   ff invert and	( old-val raw ) \ Mask off low bits
+   swap r> c-l!		( raw )		\ Put old value back
+   munge-map-size	( map-size )	\ Mask off high bits
+;
+
+: add-arc-ident  ( adr len -- )
+   encode-string " arc-identifier" property
+;
+
+: determine-controller  ( -- )	\ Determines which PCI controller we have
+   0 c-w@	( id )		\ PCI ID now on stack
+
+   case		( id )		\ First we figure out which chip set...
+      h# 1013 of   cirrus to chip   endof
+   endcase	( )
+
+   2 c-w@ ff and	( version )
+
+   cirrus?  if			\ Cirrus based, sort out various controllers
+      use-cirrus-words		\ Cirrus stuff is inside S3 code      
+      " CL54xx" add-arc-ident
+      dup case			\ Look for known ID values.
+         b8 of gd5434 endof     \ Actually gd5446, but gd5434 is close enough
+         a8 of gd5434 endof
+         a0 of gd5430 endof
+         ac of gd5436 endof
+         ( default ) -1 swap	\ Well, maybe we can't program it...
+      endcase
+      to variant
+   then			( version )
+
+   drop			( )
+
+   variant -1 <> to safe?	\ If varient is <> -1, then we know what it is.
+;
+
+headers
+
+: reg-entry  ( map reg size -- )
+   >r >r >r
+   0 0 my-space
+   r> r> + +
+   encode-phys encode+
+   0 encode-int encode+ r> encode-int encode+
+;
+
+: add-rom-regs  ( -- )
+   \ If this driver is used for an on board frame buffer, the builtin.fth
+   \ file for that platform should declare a "no-rom" property in the node 
+   \ where this driver is used. This will prevent the reg property from 
+   \ including an entry for a non-existent ROM
+
+   " no-rom" get-my-property 0=  if
+      2drop exit
+   then
+
+   h# 30 get-map-size  if
+      0 0m h# 200.0030 0 h# 30 get-map-size h# 30 >reg-props \ ROM
+   then
+;
+
+: encode-reg-property  ( -- )
+
+   cirrus?  if
+         0 0m h# 200.0010 0 h# 10 get-map-size h# 10 >reg-props	\ Frame buffer
+         add-rom-regs
+         legacy-regs
+   then
+
+   \ Now we build reg entry up
+
+   my-address my-space encode-phys 0 encode-int encode+ 0 encode-int encode+
+
+   reg-props to tpoint
+   begin
+      tpoint >physhi l@ 0<>  if
+         tpoint >physlo l@		( phys.lo )
+         tpoint >physmid l@		( phys.lo phys.mid )
+         tpoint >physhi l@		( phys.lo phys.mid phys.hi )
+         tpoint >hiflag l@ or		( phys.lo phys.mid phys.hi )
+         encode-phys encode+
+         tpoint >size1 l@		( size )
+         encode-int encode+
+         tpoint >size2 l@		( size )
+         encode-int encode+
+         tpoint /array + to tpoint
+         false
+      else
+         true
+      then
+   until
+
+   " reg" property
+
+   reg-props /reg-props free-mem		\ Release the tempory buffer
+;
+
+: probe
+   determine-controller
+   encode-reg-property			\ Build the reg property now
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\ 
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\ 
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\ 
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END

Modified: dev/video/controlr/vga.fth
===================================================================
--- dev/video/controlr/vga.fth	2008-12-24 21:16:22 UTC (rev 1049)
+++ dev/video/controlr/vga.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -120,7 +120,7 @@
 : crtc@  ( index -- value )  crtcbuf + c@  ;
 
 : .vga-mode  ( -- )
-   push-decimal
+   base @ >r decimal
    ." HTotal:      "  0 crtc@  4 u.r  cr
    ." HDispEnd:    "  1 crtc@  4 u.r  cr
    ." HBlankStart: "  2 crtc@  4 u.r  cr
@@ -154,7 +154,7 @@
    ." SelectRowScn:"  h# 17 crtc@  1 rshift 1 and 4 u.r  cr
    ." SelectA13:   "  h# 17 crtc@  1 and 4 u.r  cr
    ." LineCompare: "  h# 18 crtc@  4 u.r  cr
-   pop-base
+   r> base !
 ;
 : showmode  ( adr len -- )   crtcbuf swap move  .vga-mode  ;
 
@@ -189,6 +189,22 @@
    ['] vga-video-on to video-on
 ;
 
+: basic-vga-init  ( -- )
+   vga-reset
+   seq-regs
+   attr-regs
+   grf-regs
+
+   crt-regs
+   4 feature-ctl!		\ Vertical sync ctl
+   hsync-on
+;
+: basic-vga  ( -- )
+   ['] (vga-crt-table) to crt-table
+   ['] basic-vga-init to init-controller
+   ['] noop is init-dac   
+;
+
 \ LICENSE_BEGIN
 \ Copyright (c) 2006 FirmWorks
 \ 

Added: dev/video/loadcirrus.fth
===================================================================
--- dev/video/loadcirrus.fth	                        (rev 0)
+++ dev/video/loadcirrus.fth	2008-12-28 03:58:44 UTC (rev 1050)
@@ -0,0 +1,13 @@
+purpose: Interior load file for Cirrus video driver
+
+" vga" device-name
+
+fload ${BP}/dev/video/common/defer.fth		\ Defered words
+fload ${BP}/dev/video/controlr/pcimap.fth	\ Generic PCI implementations
+fload ${BP}/dev/video/dacs/cirrus.fth
+fload ${BP}/dev/video/controlr/vga.fth		\ Load generic VGA routines
+fload ${BP}/dev/video/controlr/cirrus.fth	\ Load Cirrus routines
+fload ${BP}/dev/video/controlr/cirruspci.fth	\ PCI routines
+fload ${BP}/dev/video/common/graphics.fth	\ Graphics and color routines
+fload ${BP}/dev/video/common/init.fth		\ Init code
+fload ${BP}/dev/video/common/display.fth	\ High level interface code




More information about the openfirmware mailing list