[OpenBIOS] r824 - cpu/x86/pc cpu/x86/pc/lxdevel cpu/x86/pc/olpc dev/geode dev/geode/nandflash

svn at openbios.org svn at openbios.org
Wed May 21 23:12:54 CEST 2008


Author: wmb
Date: 2008-05-21 23:12:54 +0200 (Wed, 21 May 2008)
New Revision: 824

Added:
   cpu/x86/pc/linux.fth
   cpu/x86/pc/lxdevel/addrs.fth
   cpu/x86/pc/lxdevel/banner.fth
   cpu/x86/pc/lxdevel/loaddropins.fth
   cpu/x86/pc/lxdevel/rmstart.fth
   cpu/x86/pc/memtest.fth
   dev/geode/draminit.fth
   dev/geode/gpio.fth
   dev/geode/startmacros.fth
   dev/geode/usb.fth
Modified:
   cpu/x86/pc/lxdevel/config.fth
   cpu/x86/pc/lxdevel/devices.fth
   cpu/x86/pc/lxdevel/fw.bth
   cpu/x86/pc/lxdevel/lxdevel.bth
   cpu/x86/pc/lxdevel/msrinit.fth
   cpu/x86/pc/lxdevel/pcinode.fth
   cpu/x86/pc/lxdevel/rmstart.bth
   cpu/x86/pc/lxdevel/romreset.bth
   cpu/x86/pc/lxdevel/versions.fth
   cpu/x86/pc/olpc/fw.bth
   cpu/x86/pc/olpc/romreset.bth
   cpu/x86/pc/olpc/versions.fth
   dev/geode/nandflash/methods.fth
   dev/geode/nandflash/nand5536.fth
   dev/geode/nandflash/nandflash.bth
Log:

Fixed the lxdevel build by:

  Moved some files that aren't really OLPC-specific from cpu/x86/pc/olpc into
  cpu/x86/pc and dev/geode, doing a little refactoring (mostly just moving
  code into different files) in the process.

  Made lxdevel-specific versions of some files that contained OLPC dependencies

  Removed spurious OLPC dependencies from the lxdevel build.

This change is intended to be functionally neutral for the OLPC build.


Added: cpu/x86/pc/linux.fth
===================================================================
--- cpu/x86/pc/linux.fth	                        (rev 0)
+++ cpu/x86/pc/linux.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,331 @@
+\ See license at end of file
+purpose: Linux bzImage program loading
+
+\ Example boot configuration variable settings:
+
+\ Example default values for a system that boots primarily from hard disk:
+
+\ \needs ramdisk  " disk:\boot\initrd.img" d# 128 config-string ramdisk
+\ " ro root=LABEL=OLPCRoot rootfstype=ext3 console=ttyS0,115200 console=tty0"
+\   ' boot-file set-config-string-default
+\ " disk:\boot\vmlinuz"   ' boot-device      set-config-string-default
+
+\ Example default values for a system that boots primarily from JFFS2 on NAND:
+
+\ " nand:\boot\vmlinuz"   ' boot-device      set-config-string-default
+\ " ro root=mtd0 rootfstype=jffs2 console=ttyS0,115200 console=tty0"
+\   ' boot-file set-config-string-default
+
+0 value ramdisk-adr
+0 value /ramdisk
+
+create screen-info   \ See struct screen_info in include/linux/tty.h
+   0 c,     \  0 x position
+   0 c,     \  1 y position
+   0 w,     \  2 plug in memory size here
+   0 w,     \  4 video page
+   0 c,     \  6 video mode - 7 means monochrome, anything else is color
+   d# 80 c, \  7 columns
+   0 w,     \  8 unused
+   0 w,     \  a ega_bx - anything but 0x10
+   0 w,     \  c unused
+   d# 25 c, \  e lines
+   0 c,     \  f isVGA?
+   d# 16 w, \ 10 font height
+here screen-info - constant /screen-info
+
+
+h# 9.0000 constant linux-params
+h# 10.0000 value linux-base
+: code16-size  ( -- #bytes )   load-base h# 1f1 + c@ 1+  d# 512 *   ;
+0 value cmdline-offset
+
+\ Find the end of the largest piece of memory
+: memory-limit  ( -- limit )
+   " /memory" find-package 0= abort" No /memory node"  ( phandle )
+   " available" rot get-package-property abort" No memory node available property"  ( $ )
+   \ Find the memory piece that starts at 1 Meg
+   begin  dup  8 >=  while           ( $ )
+      decode-int  h# 10.0000 =  if   ( $ )   \ Found the one we want
+         decode-int h# 10.0000 +     ( $ limit )
+         nip nip  exit
+      then                           ( $ )
+      decode-int drop                ( $ )
+   repeat                            ( $ )
+   2drop true abort" No suitable memory piece"
+;
+
+d# 20 constant /root-dev-buf
+/root-dev-buf buffer: root-dev-buf
+
+: make-root-dev$    ( idx -- root-dev$ )
+   root-dev-buf /root-dev-buf 0 fill
+   "  root=/dev/hda" rot
+   1+ base @ >r d# 10 base ! (.) r> base !
+   $cat2
+   2dup 2>r root-dev-buf swap move
+   2r> free-mem
+   root-dev-buf /root-dev-buf
+;
+: +lp  ( offset -- adr )  linux-params +  ;
+
+0 [if]
+: add-root-dev ( cmdline$ -- cmdline$' )
+   2>r " root=" 2r@ sindex -1 =  if
+      2r>
+      " disk:root,\" $partition-idx dup -1 <>  if
+         make-root-dev$ $cat2
+      else
+         drop
+      then
+   else
+      2r>
+   then
+;
+[else]
+: add-root-dev  ( cmdline$ -- cmdline$' )
+;
+[then]
+
+: set-parameters  ( cmdline$ -- )
+   screen-info  linux-params  /screen-info  move  \ Ostensibly screen info
+
+   memory-limit ( #bytes )
+   d# 1023 invert and  d# 1024 /  ( #kbytes )
+   d# 1024 -  h# 002 +lp  w!	\ Kbytes of extended (not the 1st meg) memory
+
+   memory-limit ( #bytes )
+   d# 1023 invert and  d# 1024 /  ( #kbytes )
+   d# 1024 -  h# 1e0 +lp  l!    \ Alternate amount of extended memory
+
+           0  h# 1f2 +lp  w!	\ root flags - non0 to mount root read-only
+           0  h# 1f8 +lp  w!	\ Ramdisk flags
+
+\ 301 for /dev/hda,  100 for /dev/ram0,  0 for nothing (set it from cmdline)
+\      h# 301  h# 1fc +lp  w!	\ root_dev - see init/main.c:parse_root_dev
+\      h# 100  h# 1fc +lp  w!	\ root_dev - see init/main.c:parse_root_dev
+       h#   0  h# 1fc +lp  w!	\ root_dev - see init/main.c:parse_root_dev
+
+           0  h# 1ff +lp  c!	\ Aux device - set to AA if PS2 mouse present
+ /ramdisk 0<> h# 210 +lp  w!	\ loader type - set non0 to enable ramdisk info
+\  h# 100000  h# 214 +lp  l!	\ kernel start - unused
+ ramdisk-adr  h# 218 +lp  l!	\ initrd start
+    /ramdisk  h# 21c +lp  l!	\ initrd size
+
+   \ Put Open Firmware signature and IDT pointer in the params area
+   " OFW " drop @  h# b0 +lp l!   \ Validator for this area
+   1               h# b4 +lp l!   \ Number of additional items (version#)
+   cif-handler     h# b8 +lp l!   \ Client interface handler
+   idt drop        h# bc +lp l!   \ So Linux can preserve our debug vectors
+
+   \ Command line goes after the 16-bit wad
+   ( cmdline$ ) add-root-dev
+   ( cmdline$ ) cmdline-offset +lp  swap 1+  move
+   h# a33f h# 20 +lp w!		\ Command line validator (magic number)
+   cmdline-offset      h#  22 +lp  w!  \ Command line offset
+   cmdline-offset +lp  h# 228 +lp  l!  \ New command line address
+;
+
+: linux-fixup  ( -- )
+[ifdef] linux-logo  linux-logo  [then]
+   args-buf cscount set-parameters          ( )
+   h# ff h# 21 pc!	\ Squelch the timer interrupt and others
+
+   linux-base  linux-params  (init-program)
+   linux-params to %esi
+;
+
+d# 256 buffer: ramdisk-buf
+' ramdisk-buf  " ramdisk" chosen-string
+
+defer load-ramdisk
+: $load-ramdisk  ( name$ -- )
+   0 to /ramdisk                                  ( name$ )
+
+   ['] load-path behavior >r                      ( name$ r: xt )
+   ['] ramdisk-buf to load-path                   ( name$ r: xt )
+
+   ." Loading ramdisk image from " 2dup type  ."  ..."  ( name$ r: xt )
+   ['] boot-read catch                            ( throw-code r: xt )
+   cr                                             ( throw-code r: xt )
+   r> to load-path                                ( throw-code )
+   throw
+   loaded to /ramdisk  to ramdisk-adr
+;
+: cv-load-ramdisk  ( -- )
+   " ramdisk" eval  dup 0=  if  2drop exit  then  ( name$ )
+   $load-ramdisk
+;
+' cv-load-ramdisk to load-ramdisk
+
+: claim-params  ( -- )
+[ifdef] virtual-mode
+   0 0 1meg -1 mmu-map     ( )		\ Make the parameter area accessible
+[then]
+   0 +lp  h# 1000 0 mem-claim drop      \ Play nice with memory reporting
+   0 +lp  h# 1000  erase
+;
+
+0 value linux-loaded?
+: ?linux-elf-map-in  ( va size -- )
+   \ The Linux startup code really wants the physical address to be
+   \ virtual_address AND 0x0fff.ffff.  We recognize Linux by the virtual
+   \ address range that it uses (0xc0xx.xxxx)
+   over h# f000.0000 and  h# c000.0000 =  if
+      h# 40.0000 to linux-base
+      h# 800 to cmdline-offset
+      true to linux-loaded?
+      over  h# 0fff.ffff and   ( va size pa )
+      -rot -1                  ( pa va size mode )
+      mmu-map
+      exit
+   then
+   (elf-map-in)
+;
+' ?linux-elf-map-in is elf-map-in
+
+: init-bzimage?   ( -- flag )
+   loaded                               ( adr len )
+   h# 202 /string                       ( adr' len' )
+   4 <  if  drop false exit  then       ( adr )
+   " HdrS"  comp  if  false exit  then  ( )
+   h# 10.0000 to linux-base
+   code16-size to cmdline-offset         \ Save in case we clobber load-base
+   load-base  0 +lp  code16-size  move   \ Copy the 16-bit stuff
+   loaded code16-size /string  linux-base  swap  move  \ Copy the 32-bit stuff
+   true to linux-loaded?
+   true
+;
+
+warning @ warning off
+: init-program  ( -- )
+   init-bzimage?  if  exit  then
+   init-program
+;
+
+: sym  ( "name" -- adr )
+   parse-word  $sym>  0=  if  err-sym-not-found throw  then
+;
+warning !
+
+warning @ warning off
+: init-program  ( -- )
+   false to linux-loaded?
+   init-program
+   linux-loaded?  if
+      claim-params
+      ['] load-ramdisk guarded
+      linux-fixup
+   then
+;
+warning !
+
+: mcr  ( -- )  cr exit? throw  ;
+: help-debug  ( -- )
+   red-letters
+   ." Debugging the Linux kernel requires a few patches to keep Linux from"  mcr
+   ." overwriting the firmware debug vector."  mcr mcr
+   black-letters
+
+   ." COMMAND   STACK EFFECT   DESCRIPTION" mcr
+   ." .registers  ( -- )       Display registers" mcr
+   ." go          ( -- )       Resume execution" mcr
+   ." step        ( -- )       Single-step" mcr
+   ." ^T          ( -- )       (Control-T) Keystroke shortcut for 'step'" mcr
+   ." steps       ( n -- )     Single-step n times" mcr
+   ." hop         ( -- )       Step over subroutine calls" mcr
+   ." hops        ( n -- )     Hop n times" mcr
+   ." dis         ( addr -- )  Disassemble starting at given address" mcr
+   ." +dis        ( -- )       Continue disassembling" mcr
+   ." bp          ( addr -- )  Set breakpoint at given address" mcr
+   ." till        ( addr -- )  Set breakpoint at given address and go" mcr 
+   ." -bp         ( addr -- )  Delete breakpoint at given address" mcr 
+   ." --bp        ( -- )       Delete last breakpoint" mcr
+   ." .bp         ( -- )       Show breakpoints" mcr
+   ." return      ( -- )       Finish execution of current subroutine"  mcr
+   ." finish-loop ( -- )       Finish execution of current loop"  mcr
+   ." %eax        ( -- n )     Push EAX (etc.) register value on stack" mcr
+   ." %eip        ( -- n )     Push EIP register value on stack" mcr
+   ." %pc         ( -- n )     Same as %eip" mcr
+   ." to %eax     ( n -- )     Set EAX (etc.) register value from stack" mcr
+   ." to %eip     ( n -- )     Set EIP register value from stack" mcr
+   ." sym <name>  ( -- n )     Push value of named kernel symbol on stack" mcr
+   ." .adr        ( n -- )     Display symbol name closest to n" mcr
+   ." Examples: " mcr
+   ."    %pc dis            Disassemble starting at program counter" mcr
+   ."    %ebx u.            Display saved value of EBX register" mcr
+   ."    step               Single step once" mcr
+   ."    10 hops            Step 10 times, don't go down into subroutines" mcr
+   ."    1234 to %ebp       Set EBP register to (hex) 1234" mcr
+   ."    sym kbd_init dis   Disassemble starting at kbd_init" mcr
+   ."    sym kbd_init till  Set breakpoint at kbd_init and go" mcr
+   ."    %pc 5 +  to %pc    Add 5 to the program counter register" mcr
+
+   mcr
+   ." More information: http://firmworks.com/QuickRef.html" cr
+;
+
+d# 34 to default-#lines
+
+warning @ warning off
+: help  ( -- )
+   blue-letters  ." UPDATES:" black-letters  mcr
+   ."   flash u:\q2c18.rom              Rewrite the firmware from USB key" mcr
+   ."   flash nand:\q2c18.rom           Rewrite the firmware from NAND file" mcr
+   ."   copy-nand u:\boot\nand290.img   Rewrite the OS on NAND from USB key" mcr
+   mcr
+   blue-letters  ." DIRECTORY LISTING:" black-letters  mcr
+   ."   dir u:\               List USB key root directory" mcr
+   ."   dir u:\boot\          List USB key /boot directory" mcr
+   ."   dir nand:\boot\       List NAND FLASH /boot directory" mcr
+   ."   dir nand:\boot\*.rom  List .rom files in NAND FLASH /boot directory" mcr
+   mcr
+   blue-letters  ." BOOTING:" black-letters  mcr
+   ."   boot                  Load the OS from list of default locations" mcr
+   ."                         'printenv boot-device' shows the list" mcr
+   ."   boot <cmdline>        Load the OS, passing <cmdline> to kernel" mcr
+   ."   boot u:\boot\vmlinuz  Load the OS from a specific location" mcr
+   mcr
+   blue-letters  ." CONFIGURATION VARIABLES FOR BOOTING:" black-letters  mcr
+   ."   boot-device  Kernel or boot script path.  Example: nand:\boot\olpc.fth" mcr
+   ."   boot-file    Default cmdline.    Example: console=ttyS0,115200" mcr
+   ."   ramdisk      initrd pathname.    Example: disk:\boot\initrd.imz" mcr
+   mcr
+   blue-letters  ." MANAGING CONFIGURATION VARIABLES:" black-letters  mcr
+   ."   printenv [ <name> ]     Show configuration variables" mcr
+   ."   setenv <name> <value>   Set configuration variable" mcr
+   ."   editenv <name>          Edit configuration variable" mcr
+   mcr
+   blue-letters  ." DIAGNOSTICS:" black-letters  mcr
+   ."   test <device-name>      Test device.  Example: test mouse" mcr
+   ."   test-all                Test all devices that have test routines" mcr
+   mcr
+   ." More information: "
+   green-letters  ." http://wiki.laptop.org/go/OFW_FAQ" black-letters  cr
+;
+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/lxdevel/addrs.fth
===================================================================
--- cpu/x86/pc/lxdevel/addrs.fth	                        (rev 0)
+++ cpu/x86/pc/lxdevel/addrs.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,109 @@
+\ See license at end of file
+purpose: Establish address and I/O configuration definitions
+
+[ifdef] use-meg0
+h#  f0.0000 constant dropin-base
+h#  08.0000 constant dropin-size
+h#   0.4000 constant fw-pa
+h#   f.c000 constant /fw-ram
+[then]
+
+[ifdef] rom-loaded
+[ifdef] lx-devel
+h# fff8.0000   constant rom-pa		\ Physical address of boot ROM
+h#    8.0000   constant /rom		\ Size of boot ROM
+rom-pa         constant dropin-base
+[else]
+h# fff0.0000   constant rom-pa		\ Physical address of boot ROM
+h#   10.0000   constant /rom		\ Size of boot ROM
+rom-pa  h# 1.0000 +  constant dropin-base
+[then]
+
+h#    8.0000   constant dropin-size
+
+dropin-base h# 20 +  constant ResetBase	\ Location of "reset" dropin in ROM
+
+h#  1c0.0000 constant fw-pa
+h#   20.0000 constant /fw-ram
+[then]
+
+[ifdef] linuxbios-loaded
+\ h#  d8.0000 constant dropin-base
+h# fff2.0000 constant dropin-base  \ Location of payload in FLASH
+\ h# fff8.0000 constant dropin-base  \ Location of payload in FLASH
+dropin-base h# 80 + h# 20 +  constant ResetBase	\ Location of "reset" dropin in ROM
+h#   08.0000 constant dropin-size
+h#  1e0.0000 constant fw-pa
+h#   20.0000 constant /fw-ram
+h# fff0.0000 constant rom-pa
+h#   10.0000 constant /rom
+[then]
+
+[ifdef] old-bzimage-loaded
+\ h#  d8.0000 constant dropin-base
+h#   10.0020 constant dropin-base  \ RAM address where Linux normally loads 
+h#   08.0000 constant dropin-size
+h#   20.0000 constant fw-pa
+h#   20.0000 constant /fw-ram
+[then]
+
+[ifdef] bzimage-loaded
+h#  1d8.0020 constant dropin-base  \ RAM address where we want to end up
+h#   08.0000 constant dropin-size
+h#  1e0.0000 constant fw-pa
+h#   20.0000 constant /fw-ram
+[then]
+
+[ifdef] syslinux-loaded
+h#  10.1020 constant dropin-base
+h#  07.e0e0 constant dropin-size
+h#  20.0000 constant fw-pa
+h#  20.0000 constant /fw-ram
+[then]
+
+[ifdef] grub-loaded
+h# 1b8.0000 constant dropin-base
+h#  08.0000 constant dropin-size
+h# 1c0.0000 constant fw-pa
+h#  20.0000 constant /fw-ram
+[then]
+
+h#  80.0000 constant def-load-base      \ Convenient for initrd
+
+\ The heap starts at RAMtop, which on this system is "fw-pa /fw-ram +"
+h#  20.0000 constant heap-size
+
+h# 300.0000 constant jffs2-dirent-base
+h# 500.0000 constant jffs2-inode-base
+h# 700.0000 constant dma-base
+h# 900.0000 constant dma-size
+
+h# f.0000 constant suspend-base      \ In the DOS hole
+h# f.0008 constant resume-entry
+h# f.0800 constant resume-data
+
+fload ${BP}/cpu/x86/pc/virtaddr.fth
+
+\ 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/lxdevel/banner.fth
===================================================================
--- cpu/x86/pc/lxdevel/banner.fth	                        (rev 0)
+++ cpu/x86/pc/lxdevel/banner.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,56 @@
+\ See license at end of file
+purpose: Banner customization for this system
+
+headerless
+
+: .rom  ( -- )
+   ." OpenFirmware  "
+   push-decimal
+   major-release (.) type ." ." minor-release (.) type    sub-release type
+   pop-base
+[ifdef] bzimage-loaded
+   ." booted from disk - " .built
+[then]
+;
+
+: (xbanner-basics)  ( -- )
+   ?spaces  cpu-model type  ." , "   .memory
+   ?spaces  .rom
+;
+' (xbanner-basics) to banner-basics
+
+' (banner-warnings) to banner-warnings
+
+: stop-auto?  ( -- flag )  idprom-valid? 0=  auto-boot?  and ;
+
+defer gui-banner  ' true to gui-banner
+: ?gui-banner  ( -- )
+   stop-auto?  if  suppress-auto-boot  then
+
+   gui-banner drop
+;
+
+headers
+\ 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: cpu/x86/pc/lxdevel/config.fth
===================================================================
--- cpu/x86/pc/lxdevel/config.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/config.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -1,8 +1,6 @@
 \ See license at end of file
 purpose: Establish configuration definitions
 
-create olpc-gui         \ Use OLPC graphics
-
 create use-lx
 create lx-devel
 
@@ -43,7 +41,7 @@
 
 create use-null-nvram
 
-fload ${BP}/cpu/x86/pc/olpc/addrs.fth
+fload ${BP}/cpu/x86/pc/lxdevel/addrs.fth
 
 \ LICENSE_BEGIN
 \ Copyright (c) 2006 FirmWorks

Modified: cpu/x86/pc/lxdevel/devices.fth
===================================================================
--- cpu/x86/pc/lxdevel/devices.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/devices.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -1,9 +1,8 @@
 \ See license at end of file
 purpose: Load device drivers according to configuration definitions
 
-: board-revision  ( -- n )
-   h# 4c00.0014 rdmsr drop 4 rshift 7 and
-;
+: gx?  ( -- flag )  h# 4c000017 msr@ drop  4 rshift  2 =  ;
+: lx?  ( -- flag )  h# 4c000017 msr@ drop  4 rshift  3 =  ;
 
 fload ${BP}/cpu/x86/pc/isaio.fth
 
@@ -221,12 +220,12 @@
    dend
 ;
 
-fload ${BP}/cpu/x86/pc/olpc/mfgdata.fth      \ Manufacturing data
-
 \ fload ${BP}/dev/geode/lpcflash.fth           \ Reflasher for PLCC FLASH on A-test
 
 : +i encode-int encode+  ;  : 0+i  0 +i  ;
 
+false config-int tft-mode?
+
 fload ${BP}/cpu/x86/fb16-ops.fth
 fload ${BP}/ofw/termemu/fb16.fth
 0 0  " 1,1"  " /pci" begin-package

Modified: cpu/x86/pc/lxdevel/fw.bth
===================================================================
--- cpu/x86/pc/lxdevel/fw.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/fw.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -83,7 +83,7 @@
 alias lmove lmove			\ Needed by CS5536 NAND FLASH driver
 dend
 
-fload ${BP}/cpu/x86/pc/olpc/gpio.fth	\ Rudimentary GPIO driver
+fload ${BP}/dev/geode/gpio.fth		\ Rudimentary GPIO driver
 fload ${BP}/cpu/x86/pc/lxdevel/probemem.fth	\ Memory probing
 
 [ifdef] virtual-mode
@@ -117,12 +117,14 @@
 [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]
 
 [ifdef] jffs2-support
+\needs unix-seconds>  fload ${BP}/ofw/fs/unixtime.fth	\ Unix time calculation
 support-package: jffs2-file-system
    fload ${BP}/ofw/fs/jffs2/jffs2.fth	\ Journaling flash file system 2
 end-support-package
@@ -224,7 +226,7 @@
 fload ${BP}/cpu/x86/pc/boot.fth
 
 h# 3ea constant usb-port-power-map  \ USB4:PWR2  USB3:PWR1  USB2:PWR1  USB1:PWR1
-fload ${BP}/cpu/x86/pc/olpc/usb.fth
+fload ${BP}/dev/geode/usb.fth
 
 false to stand-init-debug?
 \ true to stand-init-debug?
@@ -277,33 +279,27 @@
 ;
 
 [ifdef] linux-support
-fload ${BP}/cpu/x86/pc/olpc/linux.fth
+fload ${BP}/cpu/x86/pc/linux.fth
+\ Use values like these if you want to boot directly instead of through an intermediate script
+\ " disk:\vmlinuz"   ' boot-device  set-config-string-default
+\ " disk:\initrd" d# 128 config-string ramdisk
+
+\needs ramdisk  " " d# 128 config-string ramdisk
+" "   ' boot-file      set-config-string-default   \ Let the boot script set the cmdline
 [then]
 
+" disk:\boot\boot.fth nand:\boot\boot.fth /prober /usb/ethernet"   ' boot-device  set-config-string-default
+
+
 fload ${BP}/ofw/gui/bmptools.fth
 fload ${BP}/dev/null.fth
 fload ${BP}/ofw/core/bailout.fth
 
-[ifdef] olpc-gui
-\ GUI
-false value gui-safeboot?
+fload ${BP}/cpu/x86/pc/lxdevel/banner.fth
 
-\ FIXME need to implement user-ok to lockout ok prompt
-: 2tuck  ( d1 d2 -- d2 d1 d2 )  2swap 2over  ;
-false value fru-test?
-: user-ok  "ok"  ;  \ This is supposed to check for authorization
-true value user-mode?
-
-fload ${BP}/cpu/x86/pc/olpc/banner.fth
-[then]
-
 fload ${BP}/ofw/gui/loadmenu.fth
 \ fload ${BP}/ofw/gui/insticon.fth
 
-[ifdef] olpc-gui
-fload ${BP}/cpu/x86/pc/olpc/gui.fth
-[then]
-
 \ Eliminate 4 second delay in install console for the case where
 \ there is no keyboard.  The delay is unnecessary because the screen
 \ does not go blank when the device is closed.
@@ -349,14 +345,6 @@
 fload ${BP}/ofw/ppp/loadppp.fth
 [then]
 
-[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]
-
 " dhcp" ' ip-address  set-config-string-default
 
 \ fload ${BP}/cpu/x86/pc/report.fth
@@ -492,15 +480,11 @@
    quit
 ;
 
-fload ${BP}/cpu/x86/pc/olpc/copynand.fth
-
-[ifndef] olpc
 \ This sometimes helps with VGA/EGA boards, enabling I/O space access
 \ to the CRT registers that control the hardware cursor.
 : cursor  ( -- )
    " begin-select /display  3 my-space 4 + config-w! unselect" evaluate
 ;
-[then]
 
 \ This helps with TeraTerm, which sends ESC-O as the arrow key prefix
 also hidden also keys-forth definitions

Added: cpu/x86/pc/lxdevel/loaddropins.fth
===================================================================
--- cpu/x86/pc/lxdevel/loaddropins.fth	                        (rev 0)
+++ cpu/x86/pc/lxdevel/loaddropins.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,22 @@
+\ Loads the set of drivers that is common to different output formats
+
+   " paging.di"             $add-file
+   " ${BP}/cpu/x86/build/inflate.bin"        " inflate"         $add-dropin
+   " fw.img"   " firmware"  $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/net/build/usbnet.fc"       " usbnet"     $add-deflated-dropin
+   " ${BP}/dev/usb2/device/keyboard/build/usbkbd.fc"  " usb,class3,1" $add-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
+
+   " ${BP}/dev/geode/ac97/build/ac97.fc"       " pci1022,2093"   $add-deflated-dropin
+
+   " builton.fth"                       " probe-"          $add-dropin
+   " ${BP}/ofw/fcode/memtest.fth"  " memtest.fth"          $add-deflated-dropin
+
+   " ${BP}/ofw/inet/telnetd.fth"          " telnetd"             $add-deflated-dropin
+
+   " ${BP}/ofw/termemu/gallant.obf"             " font"          $add-deflated-dropin

Modified: cpu/x86/pc/lxdevel/lxdevel.bth
===================================================================
--- cpu/x86/pc/lxdevel/lxdevel.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/lxdevel.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -7,8 +7,6 @@
 in: ${BP}/cpu/x86/pc/lxdevel/build/paging.di
 in: ${BP}/cpu/x86/pc/lxdevel/build/fw.dic
 in: ${BP}/dev/geode/nandflash/build/nandflash.fc
-in: ${BP}/dev/mmc/sdhci/build/sdhci.fc
-in: ${BP}/dev/mmc/sdhci/build/sdmmc.fc
 in: ${BP}/dev/geode/ac97/build/ac97.fc
 in: ${BP}/dev/usb2/hcd/ohci/build/ohci.fc
 in: ${BP}/dev/usb2/hcd/ehci/build/ehci.fc
@@ -17,11 +15,7 @@
 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}/dev/usb2/device/wlan/build/usb8388.fc
-in: ${BP}/dev/olpc/cafenand/build/cafenand.fc
-in: ${BP}/dev/olpc/cafecamera/build/cafecamera.fc
 in: ${BP}/dev/pci/build/pcibridg.fc
-in: usb8388.bin
 
 build-now
 
@@ -48,7 +42,7 @@
    " romreset.di"           $add-file
 \  " resume.di"             $add-file
 
-   fload ${BP}/cpu/x86/pc/olpc/loaddropins.fth
+   fload ${BP}/cpu/x86/pc/lxdevel/loaddropins.fth
    " ${BP}/dev/pci/build/pcibridg.fc"           " class060400"     $add-deflated-dropin
 
    /rom h# 400 - pad-file	\ rmstart image must start 0x400 from end

Modified: cpu/x86/pc/lxdevel/msrinit.fth
===================================================================
--- cpu/x86/pc/lxdevel/msrinit.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/msrinit.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -193,7 +193,7 @@
   msr: 5100.0023 0189c001.01880001.  \ IRQ mapper
   msr: 5100.0024 0147c001.01400001.  \ PMS
   msr: 5100.0025 0187c001.01840001.  \ ACPI
-  msr: 5100.0026 014fc001.01480001.  \ What?? 128 bytes (0x80)
+  msr: 5100.0026 014fc001.01480001.  \ AC97
   msr: 5100.0027 fe01a000.fe01a001.  \ OHCI
   msr: 5100.0028 fe01b000.fe01b001.  \ EHCI
   msr: 5100.0029 efc00000.efc00001.  \ UOC

Modified: cpu/x86/pc/lxdevel/pcinode.fth
===================================================================
--- cpu/x86/pc/lxdevel/pcinode.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/pcinode.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -9,6 +9,7 @@
 patch nonvirtual-probe-state? probe-state? map-in
 
 \  patch noop assign-all-addresses prober
+warning @ warning off
 : assign-pci-addr  ( phys.lo phys.mid phys.hi len | -1 -- phys.hi paddr size )
    2dup -1 <>  swap virtual-pci-slot?  and  if  ( phys.lo phys.mid phys.hi len )
       2swap 2drop    >r                         ( phys.hi r: len )
@@ -17,6 +18,7 @@
    then
    assign-pci-addr
 ;
+warning !
 
 : ?clear-addresses  ( -- )
    my-space virtual-pci-slot?  if  exit  then  clear-addresses

Modified: cpu/x86/pc/lxdevel/rmstart.bth
===================================================================
--- cpu/x86/pc/lxdevel/rmstart.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/rmstart.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -8,4 +8,4 @@
 \ create debug-reset
 
 fload ${BP}/cpu/x86/pc/lxdevel/config.fth
-fload ${BP}/cpu/x86/pc/olpc/rmstart.fth
+fload ${BP}/cpu/x86/pc/lxdevel/rmstart.fth

Added: cpu/x86/pc/lxdevel/rmstart.fth
===================================================================
--- cpu/x86/pc/lxdevel/rmstart.fth	                        (rev 0)
+++ cpu/x86/pc/lxdevel/rmstart.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,277 @@
+\ See license at end of file
+purpose: x86 real mode startup code.
+
+command: &native &this
+build-now
+
+\ 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
+protected-mode
+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] debug-reset
+.( debug reports enabled ) cr
+\ 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
+;
+: 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
+;
+
+[else]
+: report    ( char -- )  drop  ;
+: reportc  ( -- )    ;
+[then]
+
+hex
+
+\ odds for testing, evens for release
+d# 8 constant loader-version#	\ monotonic
+2 constant loader-format#	\ >1 when crc present
+
+.( ROM loader: version# ) loader-version# .d
+.( , format# )  loader-format#  .d cr
+
+\ Real Mode Startup
+
+hex
+
+label rm-startup	\ Executes in real mode with 16-bit operand forms
+
+   \ ffff.fc00	GDT
+
+   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.
+
+   real-mode
+
+   h# 01 # al mov  al h# 80 # out
+
+   \ This code is highly optimized because it runs when the CPU is in
+   \ it slowest operation mode, so we want to get it done fast.
+   \ GLCP_SYS_RSTPLL - page 406
+   \ If the PLL is already set up, we don't redo the 5536 setup
+   op: h# 4c000014 # cx mov   rdmsr     \ MSR value in dx,ax
+   al bl mov
+   op: h# fc00.0000 # ax and  0=  if    \ Start the PLL if not already on
+      rdmsr                             \ Get base MSR value with divisors
+      op: h# 04de.0000 # ax or          \ Set the startup time (de) and breadcrumb (4)
+      op: h# 0000.04d9 # dx mov         \ PLL value for 333 MB clk, 433 CPU
+      wrmsr                             \ Put in the base value
+      op: h# 0000.1800 invert # ax and  \ Turn off the BYPASS bits
+
+      h# 6001 # ax or                   \ Set PD, RESETPLL
+      wrmsr                             \ Start the PLL and reset the CPU
+   then
+
+   \ Return to here after the reset
+   h# 02 # al mov  al h# 80 # out
+
+
+[ifdef] init-com1      init-com1      [then]
+
+[ifdef] debug-reset
+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
+   eb c, 0 c,		\ jmp to next location to flush prefetch queue
+                        \ note: CPL is now 0
+
+   h# 03 # al mov  al h# 80 # out
+
+   \ 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
+   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 # al mov  al h# 80 # out
+
+   op: h# 1430 # dx mov  op: dx ax in  op: h# 9999 # ax cmp  =  if
+      h# 34 #  al mov    al  h# 70 #  out   \ Write to CMOS 0x34
+      h# 0f #  al mov    al  h# 71 #  out   \ Write value 01
+   then
+
+   op: ad: ResetBase h# 10 #)  far jmp	\ Jump to Forth startup
+
+   real-mode
+
+   \ 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
+   ffff.fff0 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
+
+   cli cld		\ Turn off interrupts (does not affect NMI)
+   #) jmp		\ Relative jump back to ffff.fc28
+   0 w, 0 c,		\ align "pad" to end of ROM
+   loader-version# l,	\ version#
+   loader-format#  w,	\ "format" (>1 when crc present)
+   ffff w,		\ placeholder for crc
+
+end-code
+
+end-assembling
+
+writing rmstart.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) 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: cpu/x86/pc/lxdevel/romreset.bth
===================================================================
--- cpu/x86/pc/lxdevel/romreset.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/romreset.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -17,7 +17,7 @@
 \ startmacros.fth defines some assembler macros that make MSR and I/O port
 \  access very easy by hiding the details of register use.
 
-fload ${BP}/cpu/x86/pc/olpc/startmacros.fth
+fload ${BP}/dev/geode/startmacros.fth
 
 hex
 
@@ -62,6 +62,9 @@
    \ setup CPU interface serial to mode C on both sides
    44000020.00200013. 51000010 set-msr   \ 5536 p 229
 
+   \ Set up GPIO base register
+   0000f001.00001000.   5140000c set-msr  \ GPIO BAR
+
  \ Init UART
    \ uart_init,serial.c
    \ This is a garden-variety 8250 UART setup sequence
@@ -123,8 +126,17 @@
    \ char b 3f8 port-wb  begin  3fd port-rb 40 bitand  0<> until
    h# 12 # al mov  al h# 80 # out
 
-fload ${BP}/cpu/x86/pc/olpc/draminit.fth
+fload ${BP}/dev/geode/draminit.fth
 
+   \ Last-minute check for LX erratum 34 - reset if the DLL didn't start correctly
+   h# 4c000017 rmsr  h# 10 bitand  0<>  if   \ LX branch
+      h# 4c00000f rmsr  h# 7ff bitclr  h# 4 bitset  h# 4c00000f wmsr  \ Set DLL_OV
+      h# 4c00000f rmsr  h# 7ff # ax and  h# 104 # ax cmp  =  if       \ Check the result
+         \ The value 104 indicates that the DLL did not start, so we must reset
+         1. 5140.0017 set-msr
+      then
+   then
+
    \ Now we can use the stack and do conventional subroutine calls
 
    h# 1f # al mov  al h# 80 # out

Modified: cpu/x86/pc/lxdevel/versions.fth
===================================================================
--- cpu/x86/pc/lxdevel/versions.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/lxdevel/versions.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -3,11 +3,3 @@
 \ The overall firmware revision
 macro: FW_MAJOR C
 macro: FW_MINOR 02
-
-\ The EC microcode
-macro: EC_VERSION b87
-
-\ The wireless LAN module firmware
-macro: WLAN_RPM 5.220.10.p5-1.olpc1
-macro: WLAN_VERSION 5.220.10.p5
-macro: WLAN_DATE 2007-03-30

Added: cpu/x86/pc/memtest.fth
===================================================================
--- cpu/x86/pc/memtest.fth	                        (rev 0)
+++ cpu/x86/pc/memtest.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,41 @@
+purpose: Interface to memtest86
+
+: ?memtest-elf-map-in  ( vaddr size -- )
+   \ We recognize memtest by its virtual address of 0x10000
+   \ It expects that virtual = physical; we depend on the fact
+   \ that we have low memory mapped V=P
+   over  h# 10000 =  if  ( vaddr size )
+      \ Map the frame buffer (virtual=physical)
+      h# 910 config-l@ dup 100.0000 -1 mmu-map
+   then
+
+   \ If it's not memtest, chain to the linux recognizer
+   ?linux-elf-map-in
+;
+' ?memtest-elf-map-in is elf-map-in
+
+: memtest  ( -- )  " rom:memtest" $boot  ;
+
+\ 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/olpc/fw.bth
===================================================================
--- cpu/x86/pc/olpc/fw.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/olpc/fw.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -104,7 +104,7 @@
 ;
 [then]
 
-fload ${BP}/cpu/x86/pc/olpc/gpio.fth	\ Rudimentary GPIO driver
+fload ${BP}/dev/geode/gpio.fth		\ Rudimentary GPIO driver
 fload ${BP}/cpu/x86/pc/olpc/probemem.fth	\ Memory probing
 
 [ifdef] virtual-mode
@@ -244,7 +244,7 @@
       h# 3aa   \ USB4:PWR1  USB3:PWR1  USB2:PWR1  USB1:PWR1
    then
 ;
-fload ${BP}/cpu/x86/pc/olpc/usb.fth
+fload ${BP}/dev/geode/usb.fth
 
 \ false to stand-init-debug?
 true to stand-init-debug?
@@ -336,7 +336,8 @@
 fload ${BP}/cpu/x86/pc/olpc/crypto.fth       \ Cryptographic image validation
 fload ${BP}/cpu/x86/pc/olpc/lzip.fth         \ Access zip images from memory
 fload ${BP}/cpu/x86/pc/olpc/gamekeys.fth
-fload ${BP}/cpu/x86/pc/olpc/linux.fth
+fload ${BP}/cpu/x86/pc/linux.fth
+fload ${BP}/cpu/x86/pc/memtest.fth
 fload ${BP}/cpu/x86/pc/olpc/setwp.fth
 fload ${BP}/cpu/x86/pc/olpc/security.fth
 fload ${BP}/cpu/x86/pc/olpc/fsupdate.fth
@@ -350,6 +351,13 @@
 ' gx-power-off to power-off
 [then]
 
+" disk:\boot\olpc.fth sd:\boot\olpc.fth nand:\boot\olpc.fth /prober /usb/ethernet /usb/wlan"
+   ' boot-device  set-config-string-default
+
+\needs ramdisk  " " d# 128 config-string ramdisk
+" "   ' boot-file      set-config-string-default   \ Let the boot script set the cmdline
+
+
 : dimmer  ( -- )  screen-ih  if  " dimmer" screen-ih $call-method  then  ;
 : brighter  ( -- )  screen-ih  if  " brighter" screen-ih $call-method  then  ;
 

Modified: cpu/x86/pc/olpc/romreset.bth
===================================================================
--- cpu/x86/pc/olpc/romreset.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/olpc/romreset.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -17,7 +17,7 @@
 \ startmacros.fth defines some assembler macros that make MSR and I/O port
 \  access very easy by hiding the details of register use.
 
-fload ${BP}/cpu/x86/pc/olpc/startmacros.fth
+fload ${BP}/dev/geode/startmacros.fth
 
 hex
 
@@ -346,7 +346,7 @@
       h# 12 #  al mov    al  h# 71 #  out   \ Write value 01
    then
 
-fload ${BP}/cpu/x86/pc/olpc/draminit.fth
+fload ${BP}/dev/geode/draminit.fth
 
    \ Last-minute check for LX erratum 34 - reset if the DLL didn't start correctly
    h# 4c000017 rmsr  h# 10 bitand  0<>  if   \ LX branch

Modified: cpu/x86/pc/olpc/versions.fth
===================================================================
--- cpu/x86/pc/olpc/versions.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ cpu/x86/pc/olpc/versions.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -2,7 +2,7 @@
 
 \ The overall firmware revision
 macro: FW_MAJOR D
-macro: FW_MINOR 14
+macro: FW_MINOR 14b
 
 \ The EC microcode
 macro: EC_VERSION d13

Added: dev/geode/draminit.fth
===================================================================
--- dev/geode/draminit.fth	                        (rev 0)
+++ dev/geode/draminit.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,117 @@
+   h# 18 # al mov  al h# 80 # out
+   h# 1430 # dx mov  dx ax in  h# 9999 # ax cmp  =  if
+      h# 34 #  al mov    al  h# 70 #  out   \ Write to CMOS 0x34
+      h# 18 #  al mov    al  h# 71 #  out   \ Write value 01
+   then
+
+   \ Enable DLL, load Extended Mode Register by set and clear PROG_DRAM
+   20000018 rmsr
+   10000001 bitset  20000018 wmsr
+   10000001 bitclr  20000018 wmsr
+
+   \ Reset DLL (bit 27 is undocumented in GX datasheet, but is in the LX one)
+   08000001 bitset  20000018 wmsr
+   08000001 bitclr  20000018 wmsr
+
+   \ Here we are supposed to wait 200 SDCLK cycles to let the DLL settle.
+   \ That is approximately 2 uS.  The ROM instruction access is so slow that
+   \ anything we do will take quite a bit longer than that, so we just let the
+   \ "rmsr, bitset" sequence take care of the time delay for us.
+
+   \ In the following sequence of writes the 2000.0018 MSR, we
+   \ take advantage of the fact that the existing value stays
+   \ in EAX/EDX, so we don't have to re-read the value.
+
+   \ Generate 2 refresh requests.  The refresh queue is 8 deep, and we
+   \ need to make sure 2 refreshes hit the chips, so we have to issue
+   \ 10 requests to the queue.  According to the GX datasheet, we don't
+   \ have to clear the REF_TST bit (8) explicitly between writes 
+   20000018 rmsr  8 bitset
+   wrmsr wrmsr wrmsr wrmsr wrmsr wrmsr wrmsr wrmsr wrmsr wrmsr
+   8 bitclr
+
+\ LinuxBIOS LX raminit.c has a big delay here, using Port 61
+
+   \ Load Mode Register
+   1 bitset  20000018 wmsr
+   1 bitclr  20000018 wmsr
+
+   \ Set up a descriptor to give access to memory
+   \ GLIU0 P2D Base Mask Descriptors - page 85
+   20000000.000fff00.   10000020 set-msr  \ memory - 0..fffff
+
+   \ The RAM DLL needs a write to lock on
+   ax  h# ffff0 #)  mov
+
+   h# 19 # al mov  al h# 80 # out
+   h# 1430 # dx mov  dx ax in  h# 9999 # ax cmp  =  if
+      h# 34 #  al mov    al  h# 70 #  out   \ Write to CMOS 0x34
+      h# 19 #  al mov    al  h# 71 #  out   \ Write value 01
+   then
+
+   \ Turn on the cache
+   cr0	ax   mov
+   6000.0000 bitclr  \ Cache-disable off, coherent
+   ax   cr0  mov
+   invd
+
+   h# 1a # al mov  al h# 80 # out
+   h# 1430 # dx mov  dx ax in  h# 9999 # ax cmp  =  if
+      h# 34 #  al mov    al  h# 70 #  out   \ Write to CMOS 0x34
+      h# 1a #  al mov    al  h# 71 #  out   \ Write value 01
+   then
+
+   0000f001.00001400.   5140000f set-msr  \ PMS BAR
+
+   \ It is tempting to test bit 0 of PM register 5c, but a 5536 erratum
+   \ prevents that bit from working.  Bit 1 works, but LX errata 34
+   \ sometimes requires that we reset the system to fix the memory DLL,
+   \ which destroys all the bits of PM register 5c.  So we put a breadcrumb
+   \ in a PM register that we don't otherwise use.
+   1430 port-rl  h# 9999 # ax cmp  =  if  \ Wakeup event flag
+      0 1430 port-wl
+      h# 1b # al mov  al h# 80 # out
+      h# 34 #  al mov    al  h# 70 #  out   \ Write to CMOS 0x34
+      h# 1b #  al mov    al  h# 71 #  out   \ Write value 01
+
+      char r 3f8 port-wb  begin  3fd port-rb 40 bitand  0<> until
+
+      resume-data  # sp mov
+      resume-entry # ax mov  ax call   \ This might return if checksumming fails
+      char x 3f8 port-wb  begin  3fd port-rb 40 bitand  0<> until
+   then
+
+   h# 1c # al mov  al h# 80 # out
+   h# 1808 rmsr                \ Default region configuration properties MSR
+   h# 0fffff00 # ax and        \ Top of System Memory field
+   4 # ax shl                  \ Shift into place
+   ax mem-info-pa 4 + #)  mov  \ Put it where resetend.fth can find it
+
+   \ char D 3f8 port-wb  begin  3fd port-rb 40 bitand  0<> until
+
+   \ Memory is now on
+   h# 8.0000 #  sp  mov        \ Setup a stack pointer for later code
+
+   h# 1d # al mov  al h# 80 # out
+\ Some optional debugging stuff ...
+[ifdef] debug-startup
+init-com1
+
+carret report
+linefeed report
+ascii F report
+ascii o report
+ascii r report
+[then]
+
+\ fload ${BP}/cpu/x86/pc/ramtest.fth
+
+0 [if]
+ax ax xor
+h# 12345678 #  bx mov
+bx 0 [ax] mov
+h# 5555aaaa #  4 [ax] mov
+0 [ax] dx  mov
+dx bx cmp  <>  if  ascii B report  ascii A report  ascii D report  begin again  then
+[then]
+

Added: dev/geode/gpio.fth
===================================================================
--- dev/geode/gpio.fth	                        (rev 0)
+++ dev/geode/gpio.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,61 @@
+\ See license at end of file
+purpose: Access to GPIO registers
+
+\ GPIO registers
+h# 00 constant OUT_VAL 
+h# 04 constant OUT_EN  
+h# 08 constant OUT_OD_EN  
+h# 0c constant OUT_INVRT_EN  
+h# 10 constant OUT_AUX1
+h# 14 constant OUT_AUX2
+h# 18 constant PU_EN
+h# 1c constant PD_EN
+h# 20 constant IN_EN 
+h# 24 constant INV_EN 
+h# 28 constant IN_FLTR_EN 
+h# 2c constant EVNTCNT_EN 
+h# 30 constant READ_BACK 
+h# 38 constant EVNT_EN 
+
+h# 1000 value gpio-base  \ stand-init sets this from an MSR
+: gpio@  ( offset -- 0 )  gpio-base +  pl@  ;
+: gpio!  ( l offset -- )  gpio-base +  pl!  ;
+
+alias >set noop   ( mask -- mask' )  
+: >clr    ( mask -- mask' )  d# 16 lshift  ;
+
+: >hi     ( reg# -- reg#' )  h# 80 +  ;   \ High bank for GPIO bits 16..31
+
+: gpio-data@  ( -- l )  h# 30 gpio@  ;
+
+
+h# 5140000C constant MSR_LBAR_GPIO
+
+stand-init: gpio
+   MSR_LBAR_GPIO rdmsr  ( lo hi )
+   h# 0000f001 <>  abort" GPIO not enabled"
+   h# ff00 and  to gpio-base
+;
+\ 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/geode/nandflash/methods.fth
===================================================================
--- dev/geode/nandflash/methods.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ dev/geode/nandflash/methods.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -10,6 +10,27 @@
 
 external
 
+: dma-alloc  ( len -- adr )  " dma-alloc" $call-parent  ;
+
+: dma-free  ( adr len -- )  " dma-free" $call-parent  ;
+
+: close  ( -- )  ;
+
+: size  ( -- d )  partition-size /page um*  ;
+
+: $set-partition  ( $ -- error? )
+   dup 0=  if  2drop false exit  then      ( $ )
+   over c@  ascii 0 ascii 9 between  if    ( $ )  \ number
+      base @ >r decimal  $number  r> base !  if  true exit  then   ( )
+      set-partition-number                 ( error? )
+   else                                    ( $ )  \ name
+      set-partition-name                   ( error? )
+   then                                    ( error? )
+   dup  if                                 ( error? )
+      ." NAND: No such partition" cr       ( error? )
+   then         
+;
+
 : open  ( -- okay? )
    \ We assume that LinuxBIOS has already set up the address map
    \ and the timing MSRs.
@@ -17,40 +38,34 @@
 
    h# 51400010 msr@ drop h# 1000 " map-in" $call-parent  to nand-base
 
+   0 to partition#
+   0 to partition-start
    configure 0=  if  false exit  then
 
    get-bbt
+   usable-page-limit to partition-size
+   read-partmap
 
    my-args  dup  if   ( arg$ )
       ascii , left-parse-string    ( arg2$ arg1$ )
-      2dup " zip" $=  if           ( arg2$ arg1$ )
-         2drop                         ( arg2$ )
-         map-reserved                  ( arg2$ )
-         init-deblocker  0=  if  2drop ?free-resmap false exit  then  ( arg2$ )
 
-         \ If no file is specified, open the raw archive
-         dup 0=  if  2drop true exit  then                ( arg2$ )
-      
-         \ Otherwise interpose the filesystem handler
-         " zip-file-system" find-package  if              ( arg2$ xt )
-            interpose true                                ( true )
-         else                                             ( arg2$ )
-            ." Can't find zip-file-system package" cr     ( arg2$ )
-            2drop  deblocker close-package  ?free-resmap  ( )
-            false                                         ( false )
-         then
-         exit
-      then                                                ( arg2$ arg1$ )
-
-      \ Accept either "path" or "jffs2,path"
-      2dup " jffs2" $=  if                                ( arg2$ arg1$ )
-         2drop                                            ( arg2$ )
+      \ Handle partitions                                 ( arg2$ arg1$ )
+      2dup 1 min  " \"  $=  if                            ( arg2$ arg1$ )
+         2swap 2drop                                      ( arg1$ )
+         \ If there is no "mtd" specifier and there is a partition map,
+         \ select the boot partition.
+         #partitions 0>=  if                              ( arg1$ )
+            " boot" $set-partition  if  2drop false exit  then
+         then                                             ( arg2$ arg1$ )
       else                                                ( arg2$ arg1$ )
-         \ XXX probably should check that arg$2 is empty...
-         2swap 2drop                                      ( arg1$ )
-      then                                                ( arg$ )
+         \ The argument is not a file so it must be a partition spec
+         #partitions 0<  if  2drop 2drop  false exit  then  ( arg2$ arg1$ )
+         $set-partition  if  2drop false exit  then         ( arg2$ )
+      then                                                  ( arg$ )
 
-      " jffs2-file-system" find-package  if  ( arg$ xt )
+      dup 0=  if  2drop  true exit  then                    ( arg$ )
+
+      " jffs2-file-system" find-package  if                 ( arg$ xt )
          interpose  true   ( okay? )
       else                 ( arg$ )
          ." Can't find jffs2-file-system package" cr
@@ -60,14 +75,7 @@
       2drop  true          ( okay? )
    then                    ( okay? )
 ;
-: close  ( -- )  ?free-resmap  ;
 
-: size  ( -- d )  pages/chip /page um*  ;
-
-: dma-alloc  ( len -- adr )  " dma-alloc" $call-parent  ;
-
-: dma-free  ( adr len -- )  " dma-free" $call-parent  ;
-
 headers
 
 [then]

Modified: dev/geode/nandflash/nand5536.fth
===================================================================
--- dev/geode/nandflash/nand5536.fth	2008-05-21 21:05:04 UTC (rev 823)
+++ dev/geode/nandflash/nand5536.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -42,8 +42,12 @@
 : data  ( -- )  0 h# 800 nand!  ;
 : wait-ready  ( -- )  data  begin  h# 810 nand@ 8 and  until  ;
 
+0 instance value partition#
+0 instance value partition-start  \ Boundary between chip 0 and chip 1
+0 instance value partition-size   \ Boundary between chip 0 and chip 1
+0 instance value usable-page-limit \ #pages excluding bad block tables
 
-: page-adr  ( page# -- )  dup adr  8 rshift dup adr  8 rshift adr  ;
+: page-adr  ( page# -- )  partition-start +  dup adr  8 rshift dup adr  8 rshift adr  ;
 : start-io  ( page# offset cmd -- )
    cmd                      ( page# offset )
    wbsplit swap  adr  adr   ( page# )

Modified: dev/geode/nandflash/nandflash.bth
===================================================================
--- dev/geode/nandflash/nandflash.bth	2008-05-21 21:05:04 UTC (rev 823)
+++ dev/geode/nandflash/nandflash.bth	2008-05-21 21:12:54 UTC (rev 824)
@@ -12,6 +12,7 @@
 fload ${BP}/dev/geode/nandflash/nand5536.fth
 fload ${BP}/dev/olpc/cafenand/configure.fth
 fload ${BP}/dev/olpc/cafenand/badblock.fth
+fload ${BP}/dev/olpc/cafenand/redboot.fth
 fload ${BP}/dev/geode/nandflash/methods.fth
 
 end0

Added: dev/geode/startmacros.fth
===================================================================
--- dev/geode/startmacros.fth	                        (rev 0)
+++ dev/geode/startmacros.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,131 @@
+\ See license at end of file
+
+\ Some x86 assembler macros for writing Geode early startup code
+\ in a clean, compact way.  Most of the Geode initialization is
+\ done with 64-bit MSRs (Machine Specific Registers).  These
+\ macros make it easy to set MSRs to specific values and to
+\ set and clear individual bits.
+
+\ 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.
+\ In addition to the MSR operations, there are similar ones for
+\ I/O ports.  They leave the data in %eax, so you can use bitset
+\ and bitclr with them too.
+
+-1 value last-cx
+also 386-assembler definitions
+
+: 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  ;
+
+: 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 AX
+   config-setup     ( )
+   ax ax xor
+   op: dx ax 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/geode/usb.fth
===================================================================
--- dev/geode/usb.fth	                        (rev 0)
+++ dev/geode/usb.fth	2008-05-21 21:12:54 UTC (rev 824)
@@ -0,0 +1,156 @@
+purpose: USB elaborations for the OLPC platform
+\ See license at end of file
+
+0 config-int usb-delay  \ Milliseconds to wait before set-address
+
+devalias usb1 /usb at f,4
+devalias usb2 /usb at f,5
+devalias u    /usb/disk
+devalias net  /usb/wlan
+
+\ If there is a USB ethernet adapter, use it as the default net device.
+: report-net  ( -- )
+   " /usb/ethernet" 2dup  find-package  if  ( name$ phandle )
+      drop                                  ( name$ )
+     " net" 2swap $devalias                 ( )
+   else                                     ( name$ )
+      2drop                                 ( )
+   then
+;
+
+[ifdef] notdef   \ We have the graphical penguin
+: linux-logo  ( -- )
+   " penguin.txt" find-drop-in  if  page type  then
+;
+[then]
+
+\ Like $show-devs, but ignores pagination keystrokes
+: $nopage-show-devs  ( nodename$ -- )
+   ['] exit? behavior >r  ['] false to exit?
+   $show-devs
+   r> to exit?
+;
+
+: probe-usb  ( -- )
+   ." USB2 devices:" cr
+   " /usb at f,5" open-dev  ?dup  if  close-dev  then
+   " /usb at f,5" $nopage-show-devs
+
+   ." USB1 devices:" cr
+   " /usb at f,4" open-dev  ?dup  if  close-dev  then
+   " /usb at f,4" $nopage-show-devs
+
+   report-disk
+   report-net
+   report-keyboard
+;
+alias probe-usb2 probe-usb
+alias p2 probe-usb2
+
+: ?usb-keyboard  ( -- )
+   " keyboard" expand-alias  if   ( devspec$ )
+      drop " /usb"  comp  0=  if  ( )
+         red-letters  ." Using USB keyboard." cr  black-letters
+         " keyboard" input
+      then
+   then
+;
+
+\ Unlink every node whose phys.hi component matches port
+: port-match?  ( port -- flag )
+   get-unit  if  drop false exit  then
+   get-encoded-int =
+;
+: rm-usb-children  ( port -- )
+   device-context? 0=  if  drop exit  then
+   also                             ( port )
+   'child                           ( port prev )
+   first-child  begin while         ( port prev )
+      over port-match?  if          ( port prev )
+         'peer link@  over link!    ( port prev )      \ Disconnect
+      else                          ( port prev )
+         drop 'peer                 ( port prev' )
+      then                          ( port prev )
+   next-child  repeat               ( port prev )
+   2drop                            ( )
+   previous definitions
+;
+
+0 value usb-power-done-time
+
+\ This version assumes that power has been applied already, and
+\ all we have to do is wait enough time for the devices to be ready.
+: wait-usb-power  ( -- )
+   begin  usb-power-done-time get-msecs - 0<=  until    ( )
+;
+
+: usb-quiet  ( -- )
+   [ ' go-hook behavior compile, ]    \ Chain to old behavior
+   " usb1" " reset-usb" execute-device-method drop
+   " usb2" " reset-usb" execute-device-method drop
+;
+' usb-quiet to go-hook
+
+0 0 " " " /" begin-package
+   " prober" device-name
+   : open
+      " /usb at f,5" open-dev  ?dup  if  close-dev  then
+      " /usb at f,4" open-dev  ?dup  if  close-dev  then
+      report-disk
+      report-net
+      report-keyboard
+      false
+   ;
+   : close ;
+end-package
+
+stand-init: USB setup
+   \ Set up an address routing to the USB Option Controller
+   h# efc00000.efc00001. h# 5100.0029 wrmsr
+   h# 400000ef.c00fffff. h# 5101.0020 wrmsr
+   h# 00000002.efc00000. h# 5120.000b wrmsr
+[ifdef] virtual-mode
+   h# efc00000 h# 1000 0 mmu-claim drop  \ UOC
+   h# efc00000 dup h# 1000 -1 mmu-map    \ UOC
+   h# fe01a000 h# 1000 0 mmu-claim drop  \ OHCI
+   h# fe01a000 dup h# 1000 -1 mmu-map    \ OHCI
+[then]
+   \ Configure the assignment of 2 USB Power Enable pins to USB ports
+   \ to correspond to the way they are wired on the board.
+   \ USB port 1 is PWR_EN2, USB ports 2-4 are PWR_EN1
+   usb-port-power-map h# efc00000 l!
+   2 h# efc00004 l!
+   h#       1 h# fe01a008 l!   \ Reset OHCI host controller
+   h# 1e.0000 h# fe01a04c l!   \ Configure ports for individual power
+   h#     100 h# fe01a058 l!   \ Power-on ports 2 and 3
+   d# 10 ms                    \ Stagger for glitch-prevention
+   h#     100 h# fe01a054 l!   \ Power-on port 1
+   h#     100 h# fe01a05c l!   \ Power-on port 3
+   h#     100 h# fe01a060 l!   \ Power-on port 4
+   get-msecs d# 1000 +  to usb-power-done-time
+;
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2007 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




More information about the OpenBIOS mailing list