Author: wmb
Date: Tue Sep 2 23:07:35 2014
New Revision: 3738
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3738
Log:
Added a bunch of PReP stuff
Added:
cpu/ppc/prep/
cpu/ppc/prep/basevars.fth
cpu/ppc/prep/build/
cpu/ppc/prep/build/Makefile.cross
cpu/ppc/prep/build/prepfw.bth
cpu/ppc/prep/builton.bth
cpu/ppc/prep/crc.fth
cpu/ppc/prep/elf.fth
cpu/ppc/prep/encresid.fth
cpu/ppc/prep/fortyone.fth
cpu/ppc/prep/initpgm.fth
cpu/ppc/prep/isaio.fth
cpu/ppc/prep/leflag.fth
cpu/ppc/prep/mappci.fth
cpu/ppc/prep/mkresid.fth
cpu/ppc/prep/nv7x.fth
cpu/ppc/prep/nvramhdr.fth
cpu/ppc/prep/nvtypes.fth
cpu/ppc/prep/qemu/
cpu/ppc/prep/qemu/build/
cpu/ppc/prep/qemu/build/Makefile.cross
cpu/ppc/prep/qemu/cpunode.fth
cpu/ppc/prep/qemu/devalias.fth
cpu/ppc/prep/qemu/devices.fth
cpu/ppc/prep/qemu/fixednv.fth
cpu/ppc/prep/qemu/fw.bth
cpu/ppc/prep/qemu/initrav.fth
cpu/ppc/prep/qemu/macaddr.fth
cpu/ppc/prep/qemu/pcinode.fth
cpu/ppc/prep/qemu/probemem.fth
cpu/ppc/prep/qemu/resetvec.bth
cpu/ppc/prep/qemu/rom.bth
cpu/ppc/prep/qemu/rootnode.fth
cpu/ppc/prep/qemu/slam.fth
cpu/ppc/prep/qemu/start.bth
cpu/ppc/prep/raven.fth
cpu/ppc/prep/reset.fth
cpu/ppc/prep/residdef.fth
dev/ds1385n.fth
dev/ide/twolevel-ide.fth
dev/isa/pc87307.fth
dev/m48t559.fth
dev/via/vt82c586.fth
dev/video/bga.bth
dev/video/controlr/bga.fth
dev/video/controlr/bgapci.fth
ofw/fs/hfs/
ofw/fs/hfs/hfs.fth
ofw/fs/hfs/partition.fth
Modified:
cpu/ppc/resetvec.fth
cpu/x86/pc/emu/fw.bth
dev/i8259.fth
dev/ide/atapi.fth
dev/ide/idenode.fth
dev/pci/intmap.fth
ofw/fs/fatfs/partition.fth
Added: cpu/ppc/prep/basevars.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/basevars.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,102 @@
+purpose: Configuration variables needed by early startup code
+\ See license at end of file
+
+d# 20 value /fixed-nv
+h# 7ec value fixed-nv-base \ Override as needed for the platform
+
+true value fixed-nv-ok?
+
+: fixed-nv@ ( offset -- byte )
+ fixed-nv-base + nv-c@
+;
+: fixed-nv! ( byte offset -- )
+ fixed-nv-base + nv-c!
+;
+
+: fixed-nv-checksum ( -- checksum )
+ 0 /fixed-nv 0 ?do i fixed-nv@ xor loop ( checksum )
+;
+
+: set-fixed-nv-checksum ( -- )
+ fixed-nv-checksum 0 fixed-nv@ xor h# 5a xor 0 fixed-nv!
+;
+
+6 actions
+action: fixed-nv-ok? if l@ fixed-nv@ 0<> else la1+ @ then ;
+action: l@ fixed-nv! set-fixed-nv-checksum ;
+action: l@ ;
+action: drop flag>$ ;
+action: drop $>flag ;
+action: la1+ @ 0<> ;
+
+: fixed-nv-flag ( "name" default-value offset -- )
+ create-option use-actions l, ,
+;
+
+6 actions
+action:
+ fixed-nv-ok? if
+ l@ 4 bounds do i fixed-nv@ loop swap 2swap swap bljoin
+ else
+ la1+ @
+ then
+;
+action:
+ l@ >r lbsplit r> 4 bounds do i fixed-nv! loop
+ set-fixed-nv-checksum
+;
+action: l@ ;
+action: drop push-hex <# u#s [char] x hold [char] 0 hold u#> pop-base ;
+action: drop $>number ;
+action: la1+ @ ;
+
+: fixed-nv-int ( "name" default-value offset -- )
+ create-option use-actions l, ,
+;
+
+false 1 fixed-nv-flag diag-switch?
+false 2 fixed-nv-flag real-mode?
+-1 3 fixed-nv-int real-base
+-1 7 fixed-nv-int real-size
+-1 d# 11 fixed-nv-int virt-base
+-1 d# 15 fixed-nv-int virt-size
+false d# 19 fixed-nv-flag hrp-memmap?
+
+' diag-switch? is (diagnostic-mode?)
+
+: init-fixed-nv ( -- )
+ fixed-nv-checksum h# 5a = ?dup if to fixed-nv-ok? exit then
+ ['] diag-switch? do-set-default
+ ['] real-mode? do-set-default
+ ['] real-base do-set-default
+ ['] real-size do-set-default
+ ['] virt-base do-set-default
+ ['] virt-size do-set-default
+ ['] hrp-memmap? do-set-default
+ fixed-nv-checksum h# 5a = to fixed-nv-ok?
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/build/Makefile.cross
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/build/Makefile.cross Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,32 @@
+# This setting of HOSTDIR is for cross-building on an x86 Linux system
+# For it to work, you first need to build the simulator version of ppcforth
+# in cpu/x86/Linux with "make -f Makefile.ppcforth"
+OS := $(shell uname)
+
+HOSTCPU:=x86
+HOSTDIR:=../../../${HOSTCPU}/${OS}
+
+all: prepfw.dic
+
+.PHONY: FORCE all clean
+
+.PRECIOUS: prepfw.dic
+
+${HOSTDIR}/forth:
+ @make -C ${HOSTDIR} forth
+
+${HOSTDIR}/ppcforth:
+ @make -C ${HOSTDIR} -f Makefile.ppcforth ppcforth
+
+build: ${HOSTDIR}/forth
+ @ln -sf $< $@
+
+%.dic: FORCE build ${HOSTDIR}/ppcforth
+ ./build $@
+
+builder.dic: FORCE build
+ -[ ! -f builder.sav ] && cp builder.dic builder.sav
+ ./build builder.dic
+
+clean:
+ rm -f prepfw.dic *.log *~ build
Added: cpu/ppc/prep/build/prepfw.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/build/prepfw.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,206 @@
+purpose: Load file for PReP firmware - no board specifics
+\ See license at end of file
+
+dictionary: ${BP}/cpu/ppc/build/basefw.dic
+command: &ppcforth &dictionary &this
+build-now
+
+
+\ ' $report-name to include-hook
+
+fload ${BP}/cpu/ppc/prep/basevars.fth
+0 value little-endian?
+
+headerless
+h# 1000 to pagesize
+d# 12 to pageshift
+
+false value chrp? \ Change as needed
+headers
+
+dev /
+1 encode-int " #address-cells" property
+" prep" " compatible" string-property
+device-end
+
+\ Memory management services
+fload ${BP}/ofw/core/clntmem1.fth \ client services for memory
+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
+
+headerless
+: (memory?) ( phys -- flag )
+ chrp? if h# 4000.0000 else h# 8000.0000 then u<
+;
+' (memory?) to memory?
+
+\ Handy tools to mark device nodes with the "built-in" property
+: mark-builtin ( -- false )
+ 0 package( 0 0 encode-bytes " built-in" property )package
+ false
+;
+: mark-builtin-all ( -- )
+ ['] mark-builtin ['] search-preorder catch 2drop
+;
+headers
+
+\ Load file format handlers
+fload ${BP}/cpu/ppc/prep/initpgm.fth \ Basic boot handler
+fload ${BP}/cpu/ppc/prep/elf.fth \ handler for ELF booting
+
+\ Reboot and re-entry code
+fload ${BP}/cpu/ppc/reboot.fth \ Restart the client program
+fload ${BP}/cpu/ppc/reenter.fth \ Various entries into Forth
+
+\ Miscellaneous hardware interface words
+fload ${BP}/cpu/ppc/cache603.fth \ Cache synchronization
+fload ${BP}/cpu/ppc/segreg.fth \ Segment register access
+fload ${BP}/cpu/ppc/bat.fth \ BAT mapping register access
+fload ${BP}/cpu/ppc/scrub.fth \ Fast memory scrubbing using "dcbz"
+
+fload ${BP}/ofw/termemu/cp881-16.fth \ ISO-Latin1 Font
+hex
+warning on
+
+h# 40.0000 ' load-base set-config-int-default
+
+headerless
+: (initial-heap) ( -- adr len ) sp0 @ ps-size - limit tuck - ;
+' (initial-heap) is initial-heap
+headers
+
+" /openprom" find-device
+ " FirmWorks,3.0" encode-string " model" property
+device-end
+
+fload ${BP}/cpu/ppc/prep/isaio.fth \ ISA I/O space access
+\ XXX this may need to change for L2 cache support
+warning @ warning off
+\ We can't turn on the dcache until we have set up BAT mapping
+stand-init: Instruction cache on
+ icache-on? 0= if icache-on then
+;
+warning !
+
+fload ${BP}/cpu/ppc/dectrap.fth \ Null decrementer handler
+stand-init: Enable machine check exceptions
+ msr@ h# 1000 or msr!
+;
+
+headerless
+defer set-memory-map ' noop to set-memory-map
+
+headers
+stand-init: Set Memory Map
+ set-memory-map
+;
+
+headerless
+h# 6000.0000 value fw-virt-base \ 32 megs of mapping space
+h# 0200.0000 value fw-virt-size
+
+0 value memsize
+headers
+
+fload ${BP}/cpu/ppc/loadvmem.fth \ /mmu node
+stand-init: MMU
+ " /mmu" open-dev mmu-node !
+;
+
+fload ${BP}/cpu/ppc/rootnode.fth \ Methods for root node
+stand-init: Root node
+ " /" " init" execute-device-method drop
+;
+stand-init: Data cache on
+ msr@ h# 10 and dcache-on? 0= and if dcache-on then
+;
+stand-init: Fast CPU mode
+ fastest-mode
+;
+
+0 0 " " " /" begin-package
+fload ${BP}/cpu/ppc/prep/mappci.fth \ PCI-to-root-node address translation
+fload ${BP}/dev/pcibus.fth \ Generic PCI bus package
+end-package
+stand-init: PCI host bridge
+ " /pci" " init" execute-device-method drop
+;
+
+fload ${BP}/dev/pciprobe.fth
+defer probe-all ' probe-pci to probe-all
+
+fload ${BP}/dev/scsi/probscsi.fth
+
+fload ${BP}/cpu/ppc/cpunode.fth
+
+fload ${BP}/ofw/core/bailout.fth
+
+fload ${BP}/cpu/ppc/prep/reset.fth \ Reset via "92" register
+
+fload ${BP}/ofw/core/countdwn.fth \ Startup countdown
+
+: restore-stdout ( -- )
+ " restore" stdout @ ['] $call-method catch if 3drop then
+;
+
+fload ${BP}/forth/lib/pattern.fth \ Text string pattern matching
+fload ${BP}/ofw/core/filecmds.fth \ File commands: dir, del, ren, etc.
+
+: startup ( -- )
+ standalone? 0= if exit then
+
+ copy-reboot-info
+
+ \ Ensure a clean startup state regardless of the development
+ \ environment's use of these variables
+ 0 stdin ! 0 stdout ! 0 to my-self
+
+[ifdef] debug-startup ." nvramrc" cr [then]
+ use-nvramrc? if nvramrc safe-evaluate then
+
+[ifdef] debug-startup ." probe" cr [then]
+ auto-banner? if probe-all install-console banner then
+
+ hex
+ warning on
+ only forth also definitions
+
+ install-alarm
+
+ #line off
+
+ auto-boot
+ restore-stdout
+
+ user-interface
+;
+
+.( --- Saving prepfw.dic ---) " prepfw.dic" $save-forth cr
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/builton.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/builton.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,38 @@
+purpose: Create "builton.fth" file containing the current date
+copyright: Copyright 1997 FirmWorks All Rights Reserved
+
+command: &native &this
+build-now
+
+\needs today fload ${BP}/fm/cwrapper/date.fth
+
+: put$ ( adr len -- ) ofd @ fputs ;
+
+\ Creates a "builton.fth" file indicating the current date and time.
+\ It contains, for example:
+\ : build-date " December 17, 1996 18:26:50" ;
+\ d# 19961217 constant built-date-int
+\ dev /openprom
+\ built-date-int encode-int " built-on" property
+\ device-end
+
+writing builton.fth
+" \ Defines build-date"n" put$
+" : build-date "" " put$ today date$ put$ bl ofd @ fputc
+now time$ put$ " "" ;"n" put$
+
+" d# " put$
+base @ decimal
+today (.) put$ <# u# u# u#> put$ <# u# u# u#> put$
+base !
+" constant built-date-int"n" put$
+
+" dev /openprom"n" put$
+" built-date-int encode-int "" built-on"" property"n" put$
+" device-end"n" put$
+
+ofd @ fclose
+
+\ We don't want to log the creation of this file, because doing so
+\ tends to cause double-recompiles in some cases.
+" builton.log" delete-file drop
Added: cpu/ppc/prep/crc.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/crc.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,42 @@
+purpose: CRC calculation for PR*P NVRAM
+\ See license at end of file
+
+\ Uses CCITT polynomial x**16 + x**12 + x**5 + 1
+
+: rol ( x y mask -- n ) -rot 2dup << -rot d# 16 swap - >> or and ;
+: ror ( x y mask -- n ) -rot 2dup >> -rot d# 16 swap - << or and ;
+
+: crcgen ( oldcrc data -- newcrc )
+ swap wbsplit rot xor ( old.lo pd>> )
+ dup rot bwjoin ( pd>> crc )
+ swap 8 << swap ( pd crc )
+ over 4 h# f00f rol xor ( pd crc' )
+ over 3 h# 1fe0 ror xor ( pd crc'' )
+ over h# f000 and xor ( pd crc''' )
+ swap 7 h# 01e0 ror xor ( newcrc )
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/elf.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/elf.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,211 @@
+purpose: Load image handler for ELF (Extended Linker Format)
+\ See license at end of file
+
+hex
+
+headerless
+: elf? ( -- flag ) 0 +base 4 " "(7f)ELF" $= ;
+: elf-le? ( -- flag ) 5 +base c@ 1 = ;
+: elfl@ ( adr -- n ) elf-le? if le-l@ else be-l@ then ;
+: elfw@ ( adr -- w ) elf-le? if le-w@ else be-w@ then ;
+
+: eh-l@ ( offset -- l ) +base elfl@ ;
+: eh-w@ ( offset -- w ) +base elfw@ ;
+
+: +elfl@ ( adr offset -- n ) + elfl@ ;
+
+: 1275-note? ( note-adr -- flag )
+ \ note-type
+ dup 8 +elfl@ h# 1275 = if ( note-adr )
+
+ \ note-name-adr note-name-len
+ dup h# 0c + swap 0 +elfl@ 1- ( note-name$ )
+
+ " PowerPC" $= exit ( flag )
+ then ( note-adr )
+ drop false
+;
+: find-note-section ( -- true | adr false )
+ \ Look for a note entry among the program headers
+
+ \ e_phentsize e_phoff
+ h# 2a eh-w@ 1c eh-l@ +base
+ \ e_phnum
+ over h# 2c eh-w@ * bounds ?do ( phentsize )
+ \ p_type PT_NOTE
+ i 0 +elfl@ 4 = if ( phentsize )
+ \ p_offset
+ i 4 +elfl@ +base ( phentsize note-adr )
+ dup 1275-note? if ( phentsize note-adr )
+ nip unloop false exit ( note-adr false )
+ then ( phentsize note-adr )
+ drop ( phentsize )
+ then ( phentsize )
+ dup +loop ( phentsize )
+ drop ( )
+
+ \ Look for a note entry among the section headers
+
+ \ e_shentsize e_shoff
+ h# 2e eh-w@ h# 20 eh-l@ +base ( shentsize shbase )
+ \ e_shnum
+ over h# 30 eh-w@ * bounds ?do ( shentsize )
+ \ sh_type SHT_NOTE
+ i 4 +elfl@ 7 = if ( shentsize )
+ \ sh_offset
+ i h# 10 +elfl@ +base ( shentsize note-adr )
+ dup 1275-note? if ( shentsize note-adr )
+ nip unloop exit ( note-adr false )
+ then ( shentsize note-adr )
+ drop ( shentsize )
+ then ( shentsize )
+ dup +loop ( shentsize )
+ drop
+
+ true
+;
+
+: get-note-section
+ ( -- true | chrp? load-base virt-base virt-size real-mode? false )
+ find-note-section if true exit then ( note-adr )
+
+ \ advance to descriptor portion of note section
+ \ namesz name-offset padding
+ dup dup 0 +elfl@ + h# 0c + 4 round-up ( note-adr note-data-adr )
+
+ >r ( note-adr )
+
+ \ CHRP note sections are 6 longwords; PR*P has only 5. The additional
+ \ entry is for load-base. If we see a 6-entry note section, we also
+ \ assume that the CHRP memory map is desired.
+ 4 +elfl@ d# 20 > if ( )
+ true ( chrp? )
+ r@ h# 14 +elfl@ ( chrp? load-base )
+ else ( chrp? load-base )
+ false -1 ( chrp? load-base )
+ then ( chrp? load-base )
+
+ r@ 4 +elfl@ ( chrp? load-base real-base )
+ r@ 8 +elfl@ ( chrp? load-base real-base real-size )
+ r@ h# 0c +elfl@ ( chrp? load-base real-base real-size virt-base )
+ r@ h# 10 +elfl@ ( chrp? load-base real-base real-size virt-base virt-size )
+ r> 0 +elfl@ ( chrp? load-base virt-base virt-size real-mode? )
+ false
+;
+
+\ XXX the following code assumes that the value of load-base is such that
+\ the copying of program sections to their correct locations does not
+\ overwrite portions of other sections that have not yet been copied.
+
+\ One sufficient condition is that the program sections are stored in the
+\ ELF file in ascending order of their execution addresses (vaddr fields)
+\ and that load-base is large enough that the sections must be moved to
+\ lower addresses.
+
+0 value high-water
+0 value low-water
+: record-extent ( adr len -- )
+ bounds low-water umin to low-water high-water umax to high-water
+;
+
+: prepare-elf-program ( -- entry-point )
+ 0 to high-water
+ -1 to low-water
+
+ \ Copy all pheaders to allocated memory to protect them from being
+ \ overwritten when we copy the programs to their final destinations.
+
+ \ e_entry e_phentsize e_phnum
+ h# 18 eh-l@ h# 2a eh-w@ dup h# 2c eh-w@ * ( entry phentsize phsize)
+ dup alloc-mem swap ( entry phentsize pbbuf phsize )
+
+ \ e_phoff
+ 2dup 1c eh-l@ +base -rot move ( entry phentsize phbuf phsize )
+
+ \ Scan the program sections and determine how much memory is needed
+ 2dup bounds ?do ( entry phentsize phbuf phsize ) \ throughout loop
+ \ p_type PT_LOAD
+ i 0 +elfl@ 1 = if
+ \ p_vaddr p_memsz
+ i 8 +elfl@ i h# 14 +elfl@ record-extent
+ then
+ 2 pick +loop ( entry phentsize phbuf phsize )
+
+ \ XXX Ultimatelty we need to allocate physical memory and map
+ \ it appropriately, but for now we just claim the virtual address
+ \ space, assuming that it is already mapped.
+
+ low-water 0 high-water low-water - 0 mem-claim drop ( adr )
+ low-water <> abort" Couldn't claim the program's memory"
+
+ 2dup bounds ?do ( entry phentsize phbuf phsize ) \ throughout loop
+ \ p_type PT_LOAD
+ i 0 +elfl@ 1 = if
+
+ \ XXX we need to acquire and map the memory first!
+
+ \ Move it into the correct vaddr.
+ \ p_offset p_vaddr p_filesz
+ i 4 +elfl@ +base i 8 +elfl@ i h# 10 +elfl@ ( src dst len )
+ 2dup 2>r move 2r> sync-cache
+
+ \ Zero any bytes that are not stored in the file
+ \ p_vaddr p_memsz p_filesz
+ i 8 +elfl@ i h# 14 +elfl@ i h# 10 +elfl@ /string erase
+ then
+ 2 pick +loop ( entry phentsize phbuf phsize )
+ free-mem drop ( entry )
+;
+
+defer verify-machine-type
+: (verify-machine-type) ( -- )
+ h# 10 eh-w@ 2 <> abort" The loaded file is not executable"
+ h# 12 eh-w@ dup d# 17 <> swap d# 20 <> and
+ abort" The loaded file is not a PowerPC program"
+;
+' (verify-machine-type) to verify-machine-type
+
+: init-elf-program ( -- )
+ verify-machine-type
+ get-note-section if
+ elf-le? ?endian-restart
+ else ( chrp? load-base r-base r-size v-base v-size real-mode? )
+ elf-le? test-modes ?mode-restart
+ then
+
+ prepare-elf-program ( pc )
+
+ h# 8000 alloc-mem h# 8000 + ( pc sp )
+
+ (init-program)
+;
+
+headers
+warning @ warning off
+: init-program ( -- ) elf? if init-elf-program else init-program then ;
+warning !
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/encresid.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/encresid.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,94 @@
+purpose: Tools to create device-tree properties to drive residual-data creation
+\ See license at end of file
+
+: aix-id ( type id -- )
+ encode-int rot encode-int encode+ " aix-id&type" property
+;
+: aix-flags ( flags -- ) encode-int " aix-flags" property ;
+: chip-id ( id -- ) encode-int " aix-chip-id" property ;
+: in-82378 ( -- ) h# 24.4d.00.81 chip-id ;
+: pnp-data ( adr len -- ) encode-bytes " pnp-data" property ;
+
+\ Encode primitive data types in PnP format
+: start-encode ( -- adr len ) 0 0 encode-bytes ;
+: +byte ( adr len b -- adr' len' ) here >r c, r> 1 encode+ ;
+: +le16 ( adr len w -- adr' len' ) wbsplit >r +byte r> +byte ;
+: +le32 ( adr len l -- adr' len' ) lbflip encode-int encode+ ;
+: +le64 ( adr len l -- adr' len' ) +le32 0 encode-int encode+ ;
+: +bytes ( adr len adr1 len1 -- adr' len' ) encode-bytes encode+ ;
+
+\ Encode address ranges using the IBM vendor-unique PnP format
+: +regn ( base size #bits -- )
+ -rot >r >r >r
+ " "(84 15 00 09 01)" +bytes ( r: size base #bits )
+ r> +le16 0 +byte r> +le64 r> +le64
+;
+: +reg32 ( adr len base size -- adr' len' ) d# 32 +regn ;
+: +reg16 ( adr len base size -- adr' len' ) d# 16 +regn ;
+: +reg11 ( adr len base size -- adr' len' ) d# 11 +regn ;
+
+: +isa-mem32 ( adr len base size -- adr' len' )
+ >r >r
+ " "(84 15 00 09 02 20 00 00)" +bytes
+ r> ( base ) +le64 r> ( size ) +le64
+;
+: +isa-reg ( adr len base size -- adr' len' )
+ >r >r
+ " "(47 01)" +bytes r@ ( base ) +le16 r> +le16 1 +byte r> ( size ) +byte
+;
+
+: +fixed-isa-reg ( adr len base size -- adr' len' )
+ >r >r
+ h# 4b +byte r> ( base ) +le16 r> ( size ) +byte
+;
+
+\ Encode an IRQ number in PnP format
+: +irq ( adr len irq# -- adr' len' ) >r h# 22 +byte 1 r> lshift +le16 ;
+
+\ Encode IBM bus-bridge-attributes PnP item
+: +bus-attributes ( adr len speed #slots -- adr' len' )
+ >r >r " "(84 06 00 06)" +bytes r> +le32 r> +byte
+;
+
+\ Encode IBM bus-bridge-address-translation PnP item
+: +bus-range ( adr len decode type parent child size -- adr' len' )
+ >r >r >r >r >r
+ " "(84 1D 00 05)" +bytes r> +byte 1 +byte r> +byte 0 +byte
+ r> +le64 r> +le64 r> +le64
+;
+
+\ Encode IBM PCI-bridge-descriptor PnP item
+: start-pci-descriptor ( adr len #devices -- adr' len' )
+ >r h# 84 +byte r> d# 12 * d# 21 + +le16 3 +byte
+;
+
+\ Encode Device/slot entry in PCI-bridge-descriptor
+: +slot ( adr len slot# dev&func# int-type inta intb intc intd -- adr' len' )
+ >r >r >r >r >r >r >r
+ r> +byte r> +byte r> +le16 r> +le16 r> +le16 r> +le16 r> +le16
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/fortyone.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/fortyone.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,78 @@
+purpose: Load image handler for PR*P/IBM "0x41" boot partition format
+\ See license at end of file
+
+defer set-aix-modes ' noop to set-aix-modes
+
+[ifndef] residual-data
+0 value residual-data
+
+defer make-aix-l2-cache ' noop to make-aix-l2-cache
+defer make-residual-data ' noop to make-residual-data
+[then]
+
+warning @ warning off
+: init-program ( -- )
+ loaded h# 400 round-up swap h# 204 + le-l@ h# 400 round-up = if
+ \ Mostly we don't care about the addresses, but we must be in real
+ \ mode, big-endian, pr*p memory map.
+ \ chrp? <addresses> real? le?
+ false -1 -1 -1 -1 -1 true false test-modes
+ ?mode-restart
+
+ make-aix-l2-cache make-residual-data
+
+ loaded sync-cache
+ load-base h# 200 + le-l@ load-base + load-base (init-program)
+
+ residual-data to %r3
+ load-base to %r4
+
+ msr@ h# 8030 invert and to %msr \ disable translations
+
+ set-aix-modes
+
+ exit
+ then
+ \ Otherwise, try other formats
+ init-program
+;
+
+\ Handle IBTA format, i.e., AIX bootable tape images.
+\ Block 0 (at load-base) contains a partition map. Assume the first
+\ entry in the map describes this image.
+: init-program ( -- )
+ load-base be-l@ h# c9c2d4c1 ( "IBTA" in EBCDIC! ) = if
+ loaded over h# 1c6 + le-l@ /sector * ( load-adr,len offset )
+ /string ( image-adr,len )
+ dup !load-size ( image-adr,len )
+ load-base swap move ( )
+ then
+ \ Fall through to regular 41-format handler
+ init-program
+;
+warning !
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/initpgm.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/initpgm.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,110 @@
+purpose: Generic tools for load image handlers
+\ See license at end of file
+
+: (init-program) ( pc sp -- )
+ clear-save-area state-valid on
+ \ PowerPC calling conventions store the link register at SP+8,
+ \ so we start with r1 a little below the top of the allocated region
+ h# 20 - to %r1 to %pc
+ cif-handler to %r5
+
+ msr@ interrupt-enable-bit invert and to %msr
+
+ restartable? on
+ true to already-go?
+;
+
+headerless
+: ?endian-restart ( little-endian? -- )
+ dup little-endian? <> if
+ to little-endian?
+ collect(
+ ." Rebooting in " little-endian? if ." little" else ." big" then
+ ." -endian mode ..." )collect progress progress-done
+ reboot-same
+ else
+ drop
+ then
+;
+
+: +base ( n -- adr ) load-base + ;
+
+false value bad-mode?
+: bad-mode true to bad-mode? ;
+
+headers
+: test-modes ( hrp-memmap? load-base real-base real-size virt-base ...
+ ( ... virt-size real-mode? little-endian? -- )
+ false to bad-mode?
+ dup little-endian? <> if dup to little-endian? bad-mode then drop
+ dup real-mode? <> if dup to real-mode? bad-mode then drop
+
+ dup -1 <> if
+ dup virt-size <> if dup to virt-size bad-mode then
+ then
+ drop
+
+ dup -1 <> if
+ dup virt-base <> if dup to virt-base bad-mode then
+ then
+ drop
+
+ dup -1 <> if
+ dup real-size <> if dup to real-size bad-mode then
+ then
+ drop
+
+ dup -1 <> if
+ dup real-base <> if dup to real-base bad-mode then
+ then
+ drop
+
+ dup -1 <> if
+ dup load-base <> if dup to load-base bad-mode then
+ then
+ drop
+
+ dup hrp-memmap? <> if dup to hrp-memmap? bad-mode then drop
+;
+
+: ?mode-restart ( -- )
+ bad-mode? if
+ " Rebooting in the correct mode for this client program ..." progress
+ progress-done
+ reboot-same
+ then
+;
+
+dev /client-services
+: chain ( len args entry size virt -- )
+ release ( len args entry )
+ h# 8000 alloc-mem h# 8000 + (init-program) ( len args )
+ to %r6 to %r7
+ go
+;
+device-end
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/isaio.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/isaio.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,37 @@
+purpose: Real-mode access to ISA IO space
+\ See license at end of file
+
+headers
+h# 8000.0000 value io-base
+
+: pc@ ( offset -- n ) io-base + rb@ ;
+: pc! ( n offset -- ) io-base + rb! ;
+: pw@ ( offset -- n ) io-base + rw@ ;
+: pw! ( n offset -- ) io-base + rw! ;
+: pl@ ( offset -- n ) io-base + rl@ ;
+: pl! ( n offset -- ) io-base + rl! ;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/leflag.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/leflag.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,52 @@
+purpose: Read the endian flag byte from the NVRAM
+\ See license at end of file
+
+\needs get-nv-byte fload ${BP}/cpu/ppc/prep/nv7x.fth
+
+\ Destroys: r1,r4
+\ Out: r3: le-flag
+
+label read-le-flag ( -- r3: le-flag )
+ mfspr r4,lr
+
+ \ Read the big/little endian flag from location 9 of the NVRAM.
+ set r3,9 get-nv-byte bl *
+
+ cmpi 0,0,r3,h#4c \ Compare to 'L'
+ 0<> if \ Set r3 only if the byte is exactly 'L'
+ set r3,0
+ else
+ set r3,-1
+ then
+
+\ set r3,0 \ Big-endian
+\ set r3,1 \ Little-endian
+
+ mtspr lr,r4
+ bclr 20,0
+end-code
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/mappci.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/mappci.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,50 @@
+purpose: PCI physical address mapping to root node
+\ See license at end of file
+
+headerless
+: map-pci-phys ( paddr io? phys.hi size -- vaddr )
+ >r drop ( paddr io? R: size )
+ chrp? if ( paddr io? R: size )
+ if h# fe00.0000 else ( paddr R: size )
+ \ PCI addresses below 2G are really for ISA memory space, and
+ \ must be translated up to the "peripheral memory alias" space
+ \ so as not to look like system memory addresses.
+ dup h# 8000.0000 u< if h# fd00.0000 else h# 0000.0000 then
+ then
+ else
+ if h# 8000.0000 else h# c000.0000 then
+ then
+ or r> " map-in" $call-parent
+;
+: >pci-devaddr ( root-devaddr -- pci-devaddr )
+ chrp? 0= if h# 8000.0000 + then
+;
+: pci-devaddr> ( pci-devaddr -- root-devaddr )
+ chrp? 0= if h# 8000.0000 - then
+;
+headers
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/mkresid.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/mkresid.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,436 @@
+purpose: Create residual data structure
+\ See license at end of file
+
+hex
+
+0 value fw-revision \ Set me
+h# dc6 value fw-supports \ Change if needed
+h# 2 value fw-supplier \ Change if needed
+
+defer #cpus ' 1 to #cpus \ Actual # of CPUs installed
+
+: $pcall-parent ( ?? adr len -- ?? )
+ parent-device dup push-package $call-static-method pop-package
+;
+: get-parent-property ( adr len -- val$ false | true )
+ parent-device get-package-property
+;
+: get-bus-id ( -- true | bus-id false )
+ " aix-bus-id" get-parent-property if true exit then
+ get-encoded-int false
+;
+: isa-child? ( -- flag ) get-bus-id if false else 1 = then ;
+
+\ PnP stuff
+
+0 value next-pnp-adr
+: pnp-b, ( byte -- )
+ next-pnp-adr dup 1+ to next-pnp-adr c!
+;
+: pnp-w, ( word -- ) wbsplit swap pnp-b, pnp-b, ;
+: pnp-l, ( long -- ) lwsplit swap pnp-w, pnp-w, ;
+: pnp-x, ( d -- ) swap pnp-l, pnp-l, ;
+
+: pnp, ( adr len -- ) bounds ?do i c@ pnp-b, loop ;
+
+: make-interrupt-items ( -- )
+ isa-child? 0= if exit then
+ " interrupts" get-property 0= if ( adr len )
+ begin dup while
+ " pnp-decode-interrupt" $pcall-parent ( adr' len' irq-mask flags )
+ ?dup if
+ h# 23 pnp-b, swap pnp-w, pnp-b,
+ else
+ h# 22 pnp-b, pnp-w,
+ then
+ repeat
+ 2drop
+ then
+;
+: make-reg-item ( false | .. stuff .. true -- )
+ 0= if exit then
+ if ( adr' len' size isa-adr 16bit )
+ \ Variable I/O port item
+ h# 47 pnp-b, pnp-b, dup pnp-w, pnp-w, 1 pnp-b, pnp-b,
+ else ( adr' len' d.size d.base info type )
+ \ IBM "generic address" item
+ h# 84 pnp-b, d# 21 pnp-w, 9 pnp-b, pnp-b, pnp-b, 0 pnp-w,
+ pnp-x, pnp-x,
+ then
+;
+: make-reg-items ( -- )
+ \ Possible override
+ " aix-reg" get-property 0= if pnp, exit then
+ " reg" get-property 0= if ( adr len )
+ begin dup while
+ " pnp-decode-reg" $pcall-parent make-reg-item
+ repeat
+ 2drop
+ then
+ " other-bus-reg" get-property 0= if ( adr len )
+ begin dup while
+ decode-int " pnp-decode-reg" rot $call-static-method make-reg-item
+ repeat
+ 2drop
+ then
+;
+: make-ranges-items ( -- )
+ \ It isn't worthwhile to automate this, because the AIX ranges stuff
+ \ is too irregular.
+ " pnp-ranges" get-property 0= if pnp, then
+;
+: make-dma-items ( -- )
+ \ Only do this for children of the ISA node
+ isa-child? 0= if exit then
+
+ " dma" get-property 0= if ( adr len )
+ begin dup 0> while ( adr len )
+ h# 2a pnp-b, ( adr len )
+ decode-int 1 swap lshift pnp-b, ( adr' len' )
+ decode-int pnp-b, ( adr'' len'' )
+ repeat ( adr' len' )
+ 2drop
+ then
+;
+: make-id-item ( -- )
+ " aix-chip-id" get-property 0= if
+ h# 75 pnp-b, 1 pnp-b, get-encoded-int lbflip pnp-l,
+ then
+;
+: invent-pnp-data ( -- )
+ make-interrupt-items
+ make-reg-items
+ make-dma-items
+ make-id-item
+ make-ranges-items
+ " other-pnp-data" get-property 0= if pnp, then
+;
+: make-pnp-packet ( -- )
+ " pnp-data" get-property 0= if pnp, exit then
+ " make-pnp-data" current-device find-method if
+ execute pnp, exit
+ then ( )
+ invent-pnp-data
+;
+
+\ End of pure PNP stuff
+
+
+\ Constructors for residual-data fields
+
+0 value next-res-adr
+: res-b, ( byte -- ) next-res-adr dup 1+ to next-res-adr c! ;
+: res-w, ( word -- ) wbsplit res-b, res-b, ;
+: res-l, ( long -- ) lwsplit res-w, res-w, ;
+
+\ Add PnP info to the AIX device record
+
+0 value pnp-base
+: res-pnp, ( -- ) next-pnp-adr pnp-base - res-l, ;
+: end-pnp ( -- ) h# 78 pnp-b, ;
+: set-pnp-fields ( -- )
+ res-pnp, make-pnp-packet end-pnp
+ res-pnp, " pnp-possible" get-property 0= if pnp, then end-pnp
+ res-pnp, " pnp-compatible" get-property 0= if pnp, then end-pnp
+;
+
+
+[ifdef] compute-mem-segs
+: get-instance-property ( property-name$ ihandle -- adr len )
+ ihandle>phandle get-package-property drop
+;
+0 value mem-reg 0 value /mem-reg
+: mem-seg-open ( -- reg-adr,len avail-adr,len )
+ " reg" memory-node @ get-instance-property to /mem-reg
+ /mem-reg alloc-mem to mem-reg
+ mem-reg /mem-reg move
+ mem-reg /mem-reg
+ " available" memory-node @ get-instance-property
+;
+: mem-seg-close ( -- ) mem-reg /mem-reg free-mem ;
+: next-range ( reg-adr,len avail-adr,len -- reg-adr,len avail-adr,len adr ty )
+
+;
+[then]
+
+: mem-seg, ( start end usage -- end )
+ >r 2dup = if r> 2drop exit then \ Don't create pieces for null regions
+ r> res-l, ( start end )
+ over pageshift rshift res-l, ( start end )
+ dup rot - pageshift rshift res-l,
+;
+
+: mem-segs, ( -- )
+ next-res-adr >r 0 res-l, \ To be patched later
+
+ 0
+ \ end-address type
+ 4000 4 mem-seg, \ trap table
+\ htab 10 mem-seg, \ a little free piece
+\ htab /htab + 2 mem-seg, \ HTAB
+ load-base 10 mem-seg, \ free memory below load-base
+ loaded + pagesize round-up
+ 8 mem-seg, \ loaded program
+ origin 10 mem-seg, \ More free mem (XXX what about allocated mem)
+ limit 4 mem-seg, \ Firmware code (dictionary)
+ sp0 @ ps-size - 2 mem-seg, \ Firmware heap
+ memtop @ 1 mem-seg, \ Firmware stack
+ memsize 10 mem-seg, \ free piece above firmware
+ 8000.0000 20 mem-seg, \ Unpopulated memory area
+ 8080.0000 440 mem-seg, \ ISA I/O space
+ 8100.0000 480 mem-seg, \ PCI config space
+ bf80.0000 500 mem-seg, \ PCI I/O space
+ c000.0000 600 mem-seg, \ System I/O registers
+ ff00.0000 800 mem-seg, \ PCI memory space
+ fff0.0000 1000 mem-seg, \ Unpopulated system ROM area
+ 0000.0000 2000 mem-seg, \ ROM
+ drop
+
+ next-res-adr r@ - /mem-seg / dup r> be-l! ( actual-#mem-segs )
+ max#mem-segs swap - /mem-seg * next-res-adr + to next-res-adr
+;
+
+: get-dev&bus# ( -- dev/func# bus# )
+ " reg" get-property drop ( adr len )
+ get-encoded-int lbsplit ( reg# dev,func# bus# xxx )
+ drop rot drop drop ( dev/func# )
+ " bus-range" get-parent-property if 0 else get-encoded-int then
+;
+
+: make-aix-device ( -- false )
+ " aix-id&type" get-property if
+ \ No AIX property; try for PCI vendor-id, device-id, class-code props.
+
+ " vendor-id" get-property if false exit then ( adr len )
+
+ get-encoded-int
+ " device-id" get-property abort" No device-id property"
+ get-encoded-int wljoin >r
+
+ " class-code" get-property abort" No class-code property"
+ get-encoded-int >r ( r: devid type )
+
+ else ( adr len )
+ \ Use aix-id&type property value
+ decode-int >r get-encoded-int >r ( r: devid type )
+ then ( adr len )
+
+ get-bus-id if 2r> 2drop false exit then ( r: devid type ) ( bus-id )
+
+ dup res-l, r> r> res-l, ( bus-id type )
+
+ " slave" get-property if -1 else get-encoded-int then res-l,
+ " aix-flags" get-property if ( bus-id type )
+ over 4 = if 4180 else 2800 then ( bus-id type flags )
+ else ( bus-id type adr len )
+ get-encoded-int ( bus-id type flags )
+ then res-l, ( bus-id type )
+
+ 8 lshift res-l, ( bus-id )
+
+ 4 = if get-dev&bus# else 0 0 then res-b, res-b,
+ 0 res-w, ( )
+
+ set-pnp-fields
+
+ false
+;
+: cpu, ( state cpu# type -- ) res-l, res-b, res-b, 0 res-b, 0 res-b, ;
+\ XXX pvr@ should be done on each individual CPU
+: (cpus,) ( -- )
+ max#cpus res-w,
+ #cpus res-w,
+
+\ XXX 1 0 pvr@ cpu, \ Assumes that CPU 0 is running the firmware
+ 0 0 pvr@ cpu, \ Assumes that CPU 0 is running the firmware
+
+ #cpus 1 ?do 0 i pvr@ cpu, loop \ Assumes that all CPUs are good
+ res#cpus #cpus ?do 0 0 0 cpu, loop \ Zero the unused entries
+;
+defer cpus, ' (cpus,) to cpus,
+
+: mem-simm-size ( simm# -- #bytes )
+ " simm-size" memory-node @ $call-method
+;
+: simms, ( -- )
+ \ Count the number of SIMMs present
+ 0 max#mems 0 do i mem-simm-size if 1+ then loop res-l,
+
+ \ ??? should this be densely packed or sparse?
+ max#mems 0 do i mem-simm-size d# 20 rshift res-l, loop
+;
+: mem, ( -- )
+ " size" memory-node @ $call-method drop ( #bytes )
+ dup res-l, \ Total memory
+ res-l, \ Good memory
+ mem-segs,
+ simms,
+;
+
+: get-root-int ( name$ -- n ) root-phandle get-int ;
+: get-cpu-int ( name$ -- n ) cpu-package get-int ;
+
+: res-erase ( #bytes -- ) 0 ?do 0 res-b, loop ;
+: res-$, ( adr len maxlen -- )
+ dup >r min tuck ( adr len' )
+ bounds ?do i c@ res-b, loop ( len' ) ( r: maxlen )
+ r> swap ?do bl res-b, loop
+;
+: cpu-int, ( name$ -- ) get-cpu-int res-l, ;
+
+: >kb ( #bytes -- #kb ) d# 10 rshift ;
+: cache, ( -- )
+ \ XXX this needs work for 601 and other potential unified-cache processors
+ " i-cache-block-size" get-cpu-int ( line-size )
+ dup res-l, \ coherence block size
+ dup res-l, \ reservation granule size
+ " i-cache-size" get-cpu-int ( line-size i$-size )
+ " d-cache-size" get-cpu-int ( line-size i$-size d$-size )
+ 2dup + >kb res-l, \ Total cache size in KB
+
+ " cache-unified" cpu-package get-package-property if ( /i$l /i$ /d$ )
+ 1 res-l, \ split cache
+ 0 res-l, \ associativity
+ 0 res-l, \ unified cache line size
+ over >kb res-l, ( i$-line /i$ /d$ ) \ i-cache-size in KB
+ swap 2 pick / ( i$-line /d$ i$#lines )
+ " i-cache-sets" get-cpu-int / res-l, \ i-cache-associativity
+ swap res-l, ( /d$ ) \ i-cache-line-size
+ dup >kb res-l, ( /d$ ) \ d-cache-size in KB
+ " d-cache-block-size" get-cpu-int ( /d$ /d$ln )
+ tuck / ( /d$ln d$#lines )
+ " d-cache-sets" get-cpu-int / res-l, ( /d$ln) \ d-cache-associativity
+ res-l, \ d-cache-line-size
+
+ " tlb-size" get-cpu-int ( #tlb-entries )
+ dup res-l, \ tlb-size
+ 620-class? if ( #tlb-entries )
+ drop ( )
+ 2 res-l, \ unified TLB
+ 2 res-l, \ TLB associativity for unified TLB
+ d# 128 res-l, \ i-tlb-size
+ d# 2 res-l, \ i-tlb-associativity
+ d# 128 res-l, \ d-tlb-size
+ d# 2 res-l, \ d-tlb-associativity
+ else
+ 1 res-l, \ split TLB
+ 0 res-l, \ TLB associativity for unified TLB
+ 2/ dup " tlb-sets" get-cpu-int ( #itlb-ents #itlb-ents #tlb-sets )
+ 2/ / ( #itlb-entries #itlb-sets )
+ over res-l, \ i-tlb-size
+ dup res-l, \ i-tlb-associativity
+ swap res-l, \ d-tlb-size
+ res-l, \ d-tlb-associativity
+ then
+ else ( ... adr len )
+ 2drop
+[ifdef] notdef
+ 2 res-l, \ unified cache
+ ?? res-l, \ associativity
+ 0 res-l, \ unified cache line size
+[then]
+ then
+ 0 res-l,
+;
+
+: devs, ( -- )
+ next-res-adr >r 0 res-l, \ To be patched later
+
+ root-phandle push-package
+ ['] make-aix-device ['] (search-preorder) catch 2drop
+ pop-package
+
+ next-res-adr r@ - /device / r> be-l!
+;
+
+: make-residual-data ( -- )
+ /residual-data alloc-mem to residual-data
+ residual-data to next-res-adr
+
+ residual-data pnp-heap-offset + to pnp-base
+ pnp-base to next-pnp-adr
+
+ residual-data /residual-data erase
+
+ /residual-data res-l, \ length
+ 0 res-b, 1 res-b, \ version, revision
+ fw-revision res-w, \ firmware revision
+
+ " model" root-phandle get-package-property if
+ " "
+ else
+ get-encoded-string
+ then
+ d# 31 res-$, 0 res-b, \ Printable Model
+
+ " aix-serial#" root-phandle get-package-property if
+ " "
+ else
+ get-encoded-string
+ then
+ d# 16 res-$,
+
+ d# 48 res-erase
+
+ fw-supplier res-l, \ Firmware Supplier
+ fw-supports res-l, \ FirmwareSupports bit mask
+
+ " size" nvram-node $call-method drop d# 1024 round-up res-l,
+
+ " #simm-slots" memory-node @ ihandle>phandle get-package-property
+ abort" Missing #simm-slots property in memory node"
+ get-encoded-int res-l,
+
+ \ XXX depends on bridge
+ 1 res-w, \ Endian switch: Port A8 bit 5 - for Eagle
+ 0 res-w, \ Spread I/O: Port 850
+
+ \ XXX for SMP
+ 0 res-l, \ SMP enter-idle-loop address
+
+ 0 res-l, \ RAM error log offset into PnP heap
+ 8 res-erase
+
+ " clock-frequency" cpu-int,
+ " clock-frequency" get-root-int dup res-l, ( CPU-bus-clock-freq )
+ 4 res-erase
+
+ " timebase-frequency" get-cpu-int / d# 1000 * res-l,
+
+ 620-class? if d# 64 else d# 32 then res-l,
+
+ d# 4096 res-l, \ page size
+
+ cache,
+ cpus,
+ mem,
+
+ devs,
+
+ make-boot-name
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/nv7x.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/nv7x.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,37 @@
+purpose: Read bytes from NVRAM using indirect (port 7x) access
+\ See license at end of file
+
+\ Destroys: r1,r3
+label get-nv-byte ( r3:offset -- r3:byte )
+ io-base set r1,*
+ rlwinm r3,r3,24,0,31 nv-adr-high 1 stb r3,* \ High address byte
+ rlwinm r3,r3,08,0,31 nv-adr-low 1 stb r3,* \ Low address byte
+ eieio
+ nv-data 1 lbz r3,*
+ bclr 20,0
+end-code
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/nvramhdr.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/nvramhdr.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,105 @@
+purpose: PR*P-specific NVRAM functions
+\ See license at end of file
+
+headerless
+[ifndef] nvram-l@
+: nvram-l@ ( offset -- l ) dup wa1+ nvram-w@ swap nvram-w@ wljoin ;
+: nvram-l! ( l offset -- ) >r lwsplit r@ nvram-w! r> wa1+ nvram-w! ;
+[then]
+
+: crc-loop ( crc end start -- crc' ) ?do i nvram-c@ crcgen loop ;
+: os-area ( -- offset len ) h# e8 nvram-l@ h# ec nvram-l@ ;
+: config-area ( -- offset len ) h# d4 nvram-l@ h# d8 nvram-l@ ;
+: env-range ( -- offset len ) h# c4 nvram-l@ h# c8 nvram-l@ ;
+
+: prep-env-area ( -- adr len ) env-range swap config-mem + swap ;
+
+\ There is a bug in IBM's early firmware which causes it to omit byte 8.
+: crc-base ( -- offset ) 3 nvram-c@ 4 >= if 8 else 9 then ;
+: crc1 ( -- n )
+ h# ffff 4 0 crc-loop ( crc )
+ os-area drop crc-base crc-loop ( crc )
+;
+: fix-crc1 ( -- ) crc1 4 nvram-w! 4 2 write-range ;
+: fix-crc2 ( -- )
+ h# ffff
+
+ \ There is a bug in IBM's early firmware which causes it to omit
+ \ the last byte, hence the "1-" below.
+ h# d4 nvram-l@ h# d8 nvram-l@ 1- 0 max bounds crc-loop ( crc )
+ 6 nvram-w!
+
+ 6 2 write-range
+;
+
+\ True if the intersection between the two ranges in not empty
+: overlap? ( adr1 len1 adr2 len2 -- flag )
+ >r >r over r@ max -rot ( max-adr adr1 len1 )
+ + r> r> + min ( max-adr min-end-adr )
+ swap - 0>
+;
+: prep-config-checksum? ( -- okay? )
+ os-area drop crc-base config-size within if
+ crc1 4 nvram-w@ =
+ else
+ false
+ then
+;
+
+: set-prep-env-checksum ( -- )
+ modified-range 0 os-area drop overlap? if fix-crc1 then
+ modified-range config-area overlap? if fix-crc2 then
+;
+
+hex
+: >bcd ( binary -- bcd ) d# 10 /mod 4 << + ;
+: set-timestamp ( offset -- )
+ >r
+ time&date d# 100 /mod r@ 7 bounds do >bcd i nvram-c! loop
+ r> 7 + 0 swap nvram-c!
+;
+: init-timestamps ( -- ) 5c 34 do i set-timestamp 8 +loop ;
+: clear-passwords ( -- ) " none" " security-mode" $setenv ;
+: prep-layout-config ( -- )
+ config-size d# 1024 / 0 nvram-w! \ Size in KBytes
+ 1 2 nvram-c! 2 3 nvram-c! \ version and revision
+ 0 3 nvram-c! \ Last OS (Firmware)
+ init-timestamps
+
+ a00 e8 nvram-l! 200 ec nvram-l! \ OS Area
+ 1000 d4 nvram-l! 0 d8 nvram-l! \ ConfigArea (PnP packets)
+ f8 c4 nvram-l! 908 c8 nvram-l! \ Global Environment area
+
+ clear-passwords \ Depends on the area descriptors above!
+;
+: prep-nvram? ( -- flag )
+ 2 nvram-c@ 1 = 3 nvram-c@ 2 = and
+ 0 nvram-w@ config-size d# 1024 / = and
+ prep-config-checksum? and
+;
+headers
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/nvtypes.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/nvtypes.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,258 @@
+purpose: Configuration option data types that are PR*P but not CHRP specific
+\ See license at end of file
+
+: [']actions ( -- ) compile (') action-adr token, ; immediate
+
+6 actions
+action: drop 9 nvram-c@ ascii L = ;
+action: drop if ascii L else ascii B then config-rw 9 nvram-c! config-ro ;
+action: drop config-mem 9 + ;
+action: drop flag>$ ;
+action: drop $>flag ;
+action: la1+ @ 0<> ;
+
+\ Modify the code field of the little-endian? flag to make it use
+\ the PR*P storage location and encodings.
+: set-prep-le ( -- ) [']actions ['] little-endian? uses ;
+
+[ifdef] notdef
+: pack-prep-env ( adr len apf -- adr' len' ) \ Binary to ASCII text
+ >r
+ push-hex
+ >r r@ 2* alloc-mem ( adr adr' )
+ r@ 0 do ( adr adr' )
+ over i ca+ c@ <# u# u# u#> ( adr adr' n-adr 2 )
+ drop over i wa+ 2 move ( adr adr' )
+ loop
+ nip r> 2*
+ pop-base
+ 2dup r> false put-env$ ( adr' len' )
+ free-mem ( )
+;
+
+\ The maximum size required for this buffer is limited to the size of
+\ the global environment area divided by two. The size of the global
+\ environment area is established by set-mfg-defaults
+h# 908 2/ constant /decode-buf
+/decode-buf buffer: decode-buf
+
+0 value pntr
+: unpack-prep-env ( cstr -- adr' len' ) \ ASCII text to binary
+ push-hex
+ 0 to pntr
+ decode-buf ( adr adr' )
+ begin ( adr adr' )
+ over pntr wa+ 2 $number if
+ 0 true ( adr adr' 0 true )
+ else
+ pntr /decode-buf = ( adr adr' n flag )
+ then
+ >r ( adr adr' 0|n ) ( r: flag )
+ over pntr ca+ c! ( adr adr' ) ( r: flag )
+ pntr 1+ to pntr ( adr adr' ) ( r: flag )
+ r> ( adr adr' flag )
+ until
+ nip pntr 1- ( adr' len' )
+ pop-base
+;
+[then]
+
+headerless
+
+h# 20 constant boot-pw
+h# 30 constant config-pw
+max-password buffer: password-buf
+: password@ ( offset -- byte ) " rtc@" clock-node @ $call-method ;
+: password! ( byte offset -- ) " rtc!" clock-node @ $call-method ;
+: pw-crc! ( crc offset -- ) >r wbsplit r@ password! r> 1+ password! ;
+: pw-crc@ ( offset -- crc ) dup 1+ password@ swap password@ bwjoin ;
+: retrieve-password ( offset -- )
+ max-password 0 ?do dup i + password@ password-buf i + c! loop
+ drop
+;
+: password-string ( -- adr len )
+ max-password dup 0 ?do
+ password-buf i ca+ c@ 0= if drop i leave then
+ loop ( #chars )
+ password-buf swap
+;
+: compute-pw-crc ( offset -- crc offset' )
+ dup max-password + >r
+ retrieve-password
+ h# ffff password-buf max-password bounds ?do i c@ crcgen loop ( crc )
+ r>
+;
+: make-invalid ( offset -- ) compute-pw-crc swap invert swap pw-crc! ;
+: make-valid ( offset -- ) compute-pw-crc pw-crc! ;
+: pw-off ( -- ) 1 h# 19 password! 1 h# 1f password! ;
+: pw-on ( -- ) 0 h# 19 password! 0 h# 1f password! ;
+: pw-on? ( -- flag )
+ h# 19 password@ 0= h# 1f password@ 0= or
+;
+: pw-valid? ( offset -- flag ) compute-pw-crc pw-crc@ = ;
+: set-password ( adr len offset -- )
+ d# 14 0 do 0 over i + password! loop \ Erase old value
+ swap 0 ?do ( adr offset ) over i + c@ over i + password! loop
+ 2drop
+;
+
+: prep-secmode@ ( apf -- n )
+ drop
+ pw-on? 0= if 0 exit then
+ boot-pw pw-valid? if
+ 2
+ else
+ config-pw pw-valid? if 1 else 0 then
+ then
+;
+: prep-secmode! ( n apf -- )
+ drop
+ case
+ 1 of config-pw make-valid boot-pw make-invalid pw-on endof
+ 2 of config-pw make-valid boot-pw make-valid pw-on endof
+ config-pw make-invalid boot-pw make-invalid pw-off
+ endcase
+;
+: prep-password@ ( apf -- adr len )
+ drop config-pw retrieve-password password-string
+;
+: prep-password! ( adr len apf -- )
+ drop ( adr len )
+ max-password min 2dup config-pw set-password boot-pw set-password
+;
+
+5 actions
+action: drop h# 2c nvram-l@ h# 30 nvram-l@ + ;
+action: drop config-rw 0 h# 2c nvram-l! h# 30 nvram-l! config-ro ;
+action: ;
+action: drop (.d) ;
+action: drop $>number ;
+
+\ Modify the code field of the little-endian? flag to make it use
+\ the PR*P storage location and encodings.
+: set-prep-#badlogins ( -- )
+ [']actions ['] security-#badlogins uses
+;
+
+headers
+warning @ warning off
+: set-defaults ( -- )
+ security-on? if
+ ." Note: set-defaults does not change the security fields." cr
+ then
+ set-defaults
+;
+warning !
+
+d# 20 value /fixed-nv
+h# 7ec value fixed-nv-base \ Override as needed for the platform
+
+true value fixed-nv-ok?
+
+: fixed-nv@ ( offset -- byte ) fixed-nv-base + nv-c@ ;
+: fixed-nv! ( byte offset -- ) fixed-nv-base + nv-c! ;
+
+: fixed-nv-checksum ( -- checksum )
+ 0 /fixed-nv 0 ?do i fixed-nv@ xor loop ( checksum )
+;
+
+: set-fixed-nv-checksum ( -- )
+ fixed-nv-checksum 0 fixed-nv@ xor h# 5a xor 0 fixed-nv!
+;
+
+6 actions
+action: fixed-nv-ok? if l@ fixed-nv@ 0<> else la1+ @ then ;
+action: l@ fixed-nv! set-fixed-nv-checksum ;
+action: l@ ;
+action: drop flag>$ ;
+action: drop $>flag ;
+action: la1+ @ 0<> ;
+
+: is-fixed-nv-flag ( offset xt -- )
+ [']actions over uses ( offset xt )
+ >body l! ( )
+;
+
+6 actions
+action:
+ fixed-nv-ok? if
+ l@ 4 bounds do i fixed-nv@ loop swap 2swap swap bljoin
+ else
+ la1+ @
+ then
+;
+action:
+ l@ >r lbsplit r> 4 bounds do i fixed-nv! loop
+ set-fixed-nv-checksum
+;
+action: l@ ;
+action: drop
+ push-hex <# 0 hold u#s [char] x hold [char] 0 hold u#> pop-base
+;
+action: drop $>number ;
+action: la1+ @ ;
+
+: is-fixed-nv-int ( offset xt -- )
+ [']actions over uses ( offset xt )
+ >body l! ( )
+;
+
+' diag-switch? is (diagnostic-mode?)
+
+: init-fixed-nv ( -- )
+ fixed-nv-checksum h# 5a = ?dup if to fixed-nv-ok? exit then
+ ['] diag-switch? do-set-default
+ ['] real-mode? do-set-default
+ ['] real-base do-set-default
+ ['] real-size do-set-default
+ ['] virt-base do-set-default
+ ['] virt-size do-set-default
+ ['] hrp-memmap? do-set-default
+ fixed-nv-checksum h# 5a = to fixed-nv-ok?
+;
+
+headerless
+: install-prep-nv ( -- )
+ set-prep-le
+ set-prep-#badlogins
+
+ 1 ['] diag-switch? is-fixed-nv-flag
+ 2 ['] real-mode? is-fixed-nv-flag
+ 3 ['] real-base is-fixed-nv-int
+ 7 ['] real-size is-fixed-nv-int
+ d# 11 ['] virt-base is-fixed-nv-int
+ d# 15 ['] virt-size is-fixed-nv-int
+ d# 19 ['] hrp-memmap? is-fixed-nv-flag
+
+ ['] drop to grow-cv-area
+ ['] prep-env-area to cv-area
+ ['] prep-config-checksum? to config-checksum?
+ ['] prep-layout-config to layout-config
+ ['] set-prep-env-checksum to set-env-checksum
+;
+headers
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/build/Makefile.cross
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/build/Makefile.cross Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,38 @@
+# This setting of HOSTDIR is for cross-building on an x86 Linux system
+# For it to work, you first need to build the simulator version of ppcforth
+# in cpu/x86/Linux with "make -f Makefile.ppcforth"
+OS := $(shell uname)
+
+HOSTCPU:=x86
+HOSTDIR:=../../../../${HOSTCPU}/${OS}
+
+all: qprepofw.rom
+
+.PHONY: FORCE all clean
+
+.PRECIOUS: qprepofw.rom
+
+${HOSTDIR}/forth:
+ @make -C ${HOSTDIR} forth
+
+${HOSTDIR}/ppcforth:
+ @make -C ${HOSTDIR} -f Makefile.ppcforth ppcforth
+
+build: ${HOSTDIR}/forth
+ @ln -sf $< $@
+
+%.di: FORCE build ${HOSTDIR}/ppcforth
+ ./build $@
+
+%.dic: FORCE build resetvec.di start.di
+ ./build $@
+
+qprepofw.rom: FORCE build fw.dic
+ ./build rom
+
+builder.dic: FORCE build
+ -[ ! -f builder.sav ] && cp builder.dic builder.sav
+ ./build builder.dic
+
+clean:
+ rm -f fw.dic *.di *.log *~ build
Added: cpu/ppc/prep/qemu/cpunode.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/cpunode.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,36 @@
+purpose: CPU node
+\ See license at end of file
+
+hex
+headers
+
+defer l2cache-on ' noop to l2cache-on
+defer l2cache-off ' noop to l2cache-off
+defer l2cache-flush ' noop to l2cache-flush
+: allcache-off l2cache-off icache-off dcache-off ;
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/devalias.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/devalias.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,46 @@
+purpose: Platform-specific device aliases
+\ See license at end of file
+
+devalias net /pci/ethernet
+
+devalias scsi /pci/scsi
+devalias disk0 /pci/ide/disk@0,0:1
+devalias disk1 /pci/ide/disk@1,0:1
+devalias disk3 /pci/ide/disk@3,0:1
+devalias cdrom /pci/ide/disk@2,0
+
+devalias a /fdc/disk@0:\
+devalias c /pci/ide/disk@0,0:\
+
+devalias disk /pci/ide/disk@0,0:1
+
+\ devalias mouse /pci/isa/8042/mouse
+
+devalias com1 /pci/isa/serial@i3f8
+devalias com2 /pci/isa/serial@i2f8
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/qemu/devices.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/devices.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,69 @@
+purpose: Load file for devices of QEMU -M prep
+copyright: Copyright 1999 FirmWorks Inc. All Rights Reserved.
+
+fload ${BP}/cpu/ppc/prep/qemu/pcinode.fth
+
+: unswizzle-move ( arc dest len -- ) move ;
+
+0 0 " fff00000" " /" begin-package
+ " flash" device-name
+ h# 10.0000 dup constant /device constant /device-phys
+ my-address my-space /device reg
+ fload ${BP}/dev/flashpkg.fth
+
+end-package
+
+\ Create the /ISA node in the device tree, and load the ISA bridge code.
+\ Usually this includes the dma controller, interrupt controller, and timer.
+0 0 " b" " /pci" begin-package
+fload ${BP}/dev/via/vt82c586.fth \ ISA node
+end-package
+
+fload ${BP}/dev/isa/irq.fth
+
+support-package: 16550
+fload ${BP}/dev/16550pkg/16550.fth \ Serial port support package
+end-support-package
+
+\ Super I/O support.
+\ Usually includes serial, parallel, floppy, and keyboard.
+\ The 87308 also has gpio and power control functions.
+fload ${BP}/dev/isa/pc87307.fth \ SuperI/O
+
+\ QEMU doesn't have rtc/nvram on port 70
+" /rtc" find-package if delete-package then
+
+0 0 " i74" " /isa" begin-package \ RTC node
+ fload ${BP}/dev/m48t559.fth
+end-package
+
+fload ${BP}/cpu/ppc/prep/qemu/fixednv.fth \ Offsets of fixed regions of NVRAM
+
+
+fload ${BP}/cpu/ppc/prep/qemu/macaddr.fth
+
+0 0 " i74" " /pci/isa" begin-package \ NVRAM node
+fload ${BP}/dev/ds1385n.fth
+
+" mk48t18-nvram" encode-string
+" ds1385-nvram" encode-string encode+
+" pnpPNP,8" encode-string encode+
+" compatible" property
+
+env-end-offset to /nvram
+end-package
+stand-init: NVRAM
+ " /nvram" open-dev to nvram-node
+ init-config-vars
+;
+
+0 0 " b,1" " /pci" begin-package
+ fload ${BP}/dev/ide/pcilintf.fth
+ fload ${BP}/dev/ide/generic.fth
+ fload ${BP}/dev/ide/onelevel.fth
+end-package
+\ One-level IDE
+
+\ Mark all ISA devices as built-in.
+" /isa" find-device mark-builtin-all device-end
+
Added: cpu/ppc/prep/qemu/fixednv.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/fixednv.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,42 @@
+purpose: Offsets of fixed areas of NVRAM
+\ See license at end of file
+
+\ d# 19
+h# 400
+
+[ifdef] /fixed-nv to /fixed-nv [else] constant /fixed-nv [then]
+
+\ Allocate fixed regions of NVRAM from the top down
+h# 2000
+h# 8 - dup constant rtc-reg-offset ( h# 1ff8 ) \ RTC registers
+h# 10 - dup constant cmos-offset ( h# 1eb8 ) \ Simulated CMOS RAM
+
+/fixed-nv - dup ( h# 1ea5 h# 1ea5 ) \ real-base, etc.
+[ifdef] fixed-nv-base to fixed-nv-base [else] constant fixed-nv-base [then]
+
+constant env-end-offset ( )
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/fw.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/fw.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,130 @@
+purpose: OFW build file for QEMU/prep
+\ See license at end of file
+
+dictionary: ${BP}/cpu/ppc/prep/build/prepfw.dic
+command: &ppcforth &dictionary &this
+build-now
+
+true to stand-init-debug?
+
+hex
+warning on
+
+h# 4.0000 constant initial-heap-size
+
+fload ${BP}/dev/diaguart.fth \ Diagnostic driver for serial port
+h# 3f8 is uart-base
+fload ${BP}/forth/lib/sysuart.fth \ Plug UART routines into key and emit
+' ukey is diag-key \ Feed UART input to "dl"
+
+: ?report drop ;
+: fw-title ( -- )
+ ." Open Firmware"
+ " build-date" $find if ." , Built " execute type else 2drop then cr
+ ?spaces ." Copyright (c) 1995-2000, FirmWorks." cr
+ ?spaces ." Copyright (c) 2014, Artyom Tarasenko." cr
+;
+' fw-title to .firmware
+
+: .r3 ;
+
+fload ${BP}/cpu/ppc/ppcboot.fth \ Forth startup code
+
+fload ${BP}/dev/pci/configm1.fth
+fload ${BP}/cpu/ppc/prep/raven.fth
+
+\ Add name properties and an init method to the root node of the device tree.
+fload ${BP}/cpu/ppc/prep/qemu/rootnode.fth
+
+\ Add drivers for supported plug-in cards
+fload ${BP}/cpu/ppc/prep/qemu/devices.fth
+fload ${BP}/cpu/ppc/prep/qemu/devalias.fth
+
+: (probe-all)
+ true to fcode-debug?
+ true to diag-switch?
+ " probe-" do-drop-in
+ probe-pci
+;
+['] (probe-all) to probe-all
+
+stand-init: Keyboard overrides
+ ?bailout
+;
+
+\ Add CPU properties
+fload ${BP}/cpu/ppc/prep/qemu/cpunode.fth \ CPU node additions
+
+\ Scrub memory and add it to the available list.
+fload ${BP}/cpu/ppc/prep/qemu/probemem.fth \ Memory probing
+
+0 value residual-data
+: make-aix-l2-cache ;
+
+fload ${BP}/cpu/ppc/prep/residdef.fth \ Residual data structure
+
+: get-int ( name$ phandle -- int )
+ get-package-property abort" Missing property" get-encoded-int
+;
+
+: make-boot-name ;
+
+fload ${BP}/cpu/ppc/prep/mkresid.fth \ Residual data creation
+fload ${BP}/cpu/ppc/prep/encresid.fth \ Residual data encoding
+
+fload ${BP}/cpu/ppc/prep/fortyone.fth \ handler for AIX booting
+
+support-package: ufs-file-system
+ fload ${BP}/ofw/fs/ufs/ufs.fth \ Unix file system
+end-support-package
+
+fload ${BP}/forth/lib/crc32.fth
+\needs unix-seconds> fload ${BP}/ofw/fs/unixtime.fth \ Unix time calculation
+\needs ($crc16) fload ${BP}/forth/lib/crc16.fth
+support-package: ext2-file-system
+ fload ${BP}/ofw/fs/ext2fs/ext2fs.fth \ Linux file system
+end-support-package
+
+
+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
+
+\ XXX should check QEMU -nographic option
+\ for now, comment out the two following lines for graphic boot
+\ " com1" ' output-device set-config-string-default
+\ " com1" ' input-device set-config-string-default
+
+
+install-rom-cold
+
+.( --- Saving fw.dic ---) " fw.dic" $save-forth cr
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/qemu/initrav.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/initrav.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,114 @@
+purpose: Low-level startup code for Raven
+\ See license at end of file
+
+label setup-raven ( -- )
+ mfspr r30,lr
+
+[ifdef] slam-it
+
+ \ PPCbus registers
+ raven-base set r1,*
+
+ set r2,h#fd00.fdff
+ stw r2,h#40(r1)
+
+ set r2,h#0300.00c2
+ stw r2,h#44(r1)
+
+ set r2,h#fe00.fe7f
+ stw r2,h#48(r1)
+
+ set r2,h#0200.00c0
+ stw r2,h#4c(r1)
+
+ set r2,h#c000.fcff
+ stw r2,h#50(r1)
+
+ set r2,h#4000.00c2
+ stw r2,h#54(r1)
+
+ set r2,h#8000.bf7f
+ stw r2,h#58(r1)
+
+ set r2,h#8000.00c0
+ stw r2,h#5c(r1)
+
+ set r2,h#55
+ stb r2,h#60(r1)
+ set r2,h#aa0f
+ sth r2,h#60(r1)
+
+ set r2,h#55
+ stb r2,h#68(r1)
+ set r2,h#aa0f
+ sth r2,h#68(r1)
+
+ set r2,h#dead.beef
+ stw r2,h#74(r1)
+
+ \ PCIbus registers
+
+ set r1,h#80000cf8 \ PCI Configuration Address Register
+
+ set r2,h#80000004 \ Config address of word containing offset 4
+ stwbrx r2,r0,r1
+ set r3,h#06 \ Memory and mastership enable
+ stb r3,4(r1) \ Write to config register 0x04
+
+ set r2,h#80000014 \ Config address of word containing offset 14
+ stwbrx r2,r0,r1
+ set r3,h#0000003c \ (swapped) MPIC base address in PCI mem space
+ stw r3,4(r1) \ Write to config register 0x14
+
+ set r2,h#80000080 \ Config address of word containing offset 80
+ stwbrx r2,r0,r1
+ set r3,h#fe.81.00.80 \ (swapped) PCI aperture [8000.0000-81ff.0000)
+ stw r3,4(r1) \ Write to config register 0x80
+
+ set r2,h#80000084 \ Config address of word containing offset 84
+ stwbrx r2,r0,r1
+ set r3,h#f3.00.00.80 \ (swapped) maps to PPC bus 0
+ stw r3,4(r1) \ Write to config register 0x84
+
+ set r2,h#80000088 \ Config address of word containing offset 88
+ stwbrx r2,r0,r1
+ set r3,h#ff.81.ff.81 \ (swapped) PCI aperture [81ff.0000-8200.0000)
+ stw r3,4(r1) \ Write to config register 0x88
+
+ set r2,h#8000008c \ Config address of word containing offset 8c
+ stwbrx r2,r0,r1
+ set r3,h#e3.00.00.80 \ (swapped) maps to PPC bus 01ff.0000
+ stw r3,4(r1) \ Write to config register 0x8c
+
+
+[then]
+
+ mtspr lr,r30
+ bclr 20,0 \ ET go home...
+end-code
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/macaddr.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/macaddr.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,98 @@
+purpose: System MAC Address access
+\ See license at end of file
+
+8 buffer: id
+: (system-mac-address) ( -- addr len ) id 1+ 6 ;
+
+: mac-sum ( -- cksum ) h# a4 id 1+ 6 bounds do i c@ xor loop ;
+: mac-bad? ( -- flag )
+ \ If the version byte is 0 or ff, the EEPROM hasn't been programmed
+ id c@ dup 0= swap h# ff = or if true exit then
+
+ id 1+ c@ 1 and 0<> \ Don't allow multicast MAC addresses
+
+ \ Test the MAC address checksum
+ mac-sum id 0 + c@ xor 0<> or ( bad? )
+;
+: get-mac-address ( -- )
+ id 8 h# ff fill \ Default value (broadcast address)
+ 7 0 do i 1+ " cmos@" clock-node @ $call-method id 1+ c! loop
+ mac-bad? if
+ ." The MAC address in the EEPROM is invalid" cr
+\ ['] false to idprom-valid?
+ then
+;
+['] (system-mac-address) is system-mac-address
+
+stand-init: MAC address
+ get-mac-address
+;
+
+1 buffer: mkp-buf
+: gh ( value index -- ) id + c! ;
+: mkp ( value index -- )
+ 2dup gh
+ 1+ " cmos!" clock-node @ $call-method
+;
+: g0 ( n1 n2 -- )
+ <> if
+\ " Copyright (c) 1998 FirmWorks"
+ " Bnoxqhfgs 'b( 0887 EhqlVnqjr"
+ bounds ?do i c@ dup bl > if 1+ then emit loop
+ quit
+ then
+;
+: g1 ( -- ) key control D g0 ;
+: g2 ( -- ) key control R g0 ;
+: g3 ( -- ) mac-bad? 0= if 0 1 g0 then ;
+
+: mkpx ( mac0 mac1 mac2 mac3 mac4 mac5 -- )
+ g1
+ g2 g3
+ 6 0 do 6 i - gh loop \ Ethernet address
+ mac-sum 0 gh
+ 7 0 do id i + c@ i 1+ " cmos!" clock-node @ $call-method loop
+
+ ['] true to idprom-valid?
+;
+
+
+\ 2 buffer: xid-buf
+\
+\ : update-xid ( -- )
+\ nvram-node 0= if exit then
+\ [ also " /obp-tftp" find-device ]
+\ 8 ee-seek xid-buf 2 ee-read
+\ xid-buf le-w@ 1+ dup xid-buf le-w! ( xid-high )
+\ 8 ee-seek xid-buf 2 ee-write ( xid-high )
+\ d# 20 lshift to rpc-xid ( )
+\ [ previous definitions ]
+\ ;
+\ stand-init:
+\ update-xid
+\ ;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/pcinode.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/pcinode.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,61 @@
+purpose: System-specific portions of PCI bus package
+\ See license at end of file
+
+dev /pci
+
+d# 33,333,333 " clock-frequency" integer-property
+
+external
+
+h# 1.c000 " bus-master-capable" integer-property
+
+h# 1c000 encode-int \ Mask of implemented slots
+" Slot1" encode-string encode+
+" Slot2" encode-string encode+
+" Slot3" encode-string encode+ " slot-names" property
+
+: config-setup ( 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
+;
+
+: config-b@ ( config-adr -- b ) config-setup pc@ ;
+: config-w@ ( config-adr -- w ) config-setup pw@ ;
+: config-l@ ( config-adr -- l ) config-setup pl@ ;
+: config-b! ( b config-adr -- ) config-setup pc! ;
+: config-w! ( w config-adr -- ) config-setup pw! ;
+: config-l! ( l config-adr -- ) config-setup pl! ;
+
+
+fload ${BP}/dev/pci/intmap.fth \ Generic interrupt mapping code
+
+device-end
+
+" 2,3,4,5" dup config-string pci-probe-list
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/probemem.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/probemem.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,66 @@
+purpose: Create memory node properties and lists
+\ See license at end of file
+
+" /memory" find-device
+
+headerless
+
+: scrub&release ( bottom top -- )
+ 2dup = if 2drop exit then
+ over - 2dup berase
+ release
+;
+
+headers
+
+: probe ( -- )
+ 0 memsize reg \ Put all memory in the "reg" property value
+ 1 encode-int " #simm-slots" property \ 1 SIMM should be enough for everyone
+
+ \ NT and MacOS have different ideas about the reporting of low pages
+ in-little-endian? if h# 4000 else h# 3000 then
+ origin pagesize round-down virt-phys - scrub&release
+
+ memtop @ memsize scrub&release
+;
+
+\ mkresid.fth needs #simm-slots and simm-size. Let's give it one SIMM
+: simm-size ( simm# -- size )
+ 0<> if 0 exit then
+ memsize
+;
+
+device-end
+
+also forth definitions
+stand-init: Memory node
+ " probe" memory-node @ $call-method
+;
+previous definitions
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/qemu/resetvec.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/resetvec.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,34 @@
+purpose: Build script for the reset vector startup code
+\ See license at end of file
+
+dictionary: ${BP}/cpu/ppc/build/basefw.dic
+command: &ppcforth &dictionary &this
+
+build-now
+
+fload ${BP}/cpu/ppc/resetvec.fth
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/rom.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/rom.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,56 @@
+purpose: Build file rom image for QEMU -M prep
+\ See license at end of file
+
+command: &builder &this
+in: builton.fth
+in: ${BP}/cpu/ppc/prep/qemu/build/start.di
+in: ${BP}/cpu/ppc/prep/qemu/build/resetvec.di
+in: ${BP}/cpu/ppc/prep/qemu/build/fw.dic
+in: ${BP}/dev/video/build/bga.fc
+in: ${BP}/dev/video/build/cirrus.fc
+build-now
+
+\needs $add-dropin fload ${BP}/forth/lib/mkdropin.fth
+
+\ Always re-create the builton.fth file when we make a new rom.img
+fload ${BP}/forth/lib/date.fth
+fload ${BP}/cpu/ppc/prep/builton.bth
+
+writing qprepofw.rom
+ " resetvec.di" $add-file
+ " start.di" $add-file
+
+ " fw.dic" " firmware" $add-dropin
+
+ " builton.fth" " probe-" $add-dropin
+ " ${BP}/dev/video/build/cirrus.fc" " pci1013,b8" $add-dropin
+ " ${BP}/dev/video/build/bga.fc" " class030000" $add-dropin
+ " ${BP}/ofw/termemu/cp881-16.obf" " font" $add-dropin
+\ h# 8.0000 pad-file
+ofd @ fclose
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/qemu/rootnode.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/rootnode.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,40 @@
+purpose: Methods for root node
+\ See license at end of file
+
+dev /
+" device-tree" device-name
+" QEMU PReP" model
+
+: init ( -- )
+
+ d# 66,666,666 " clock-frequency" integer-property \ For root bus
+
+;
+
+device-end
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/qemu/slam.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/slam.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,172 @@
+purpose: Slam the Falcon and Raven back into default, poweron like mode
+\ See license at end of file
+
+label cfg-l! ( r3:value r4:offset -- )
+ mfspr r28,lr
+
+\ Needs some work here....
+label cfg-l! ( r3:value r4:index -- ) \ Hammers r1,r2
+
+ set r1,h#80000cf8 \ Config address register
+ set r2,h#80000cfc \ Config data register
+
+ sync
+ stwbrx r4,0,r1
+ sync
+ stwbrx r3,0,r2
+ sync
+
+ bclr 20,0
+end-code
+
+label slam-falcon ( -- )
+ mfspr r29,lr
+
+ falcon-base set r1,*
+
+ set r2,h#0000.0002 \ Setup General Control Register
+ stw r2,h#08(r1) \ Upper Falcon
+
+\ Danger Will Robinson! The next two stores will kill the machines
+\ DRAM. If you run this code from DRAM, your dead. If you enbale
+\ the stores, you must load the code to the pflash and then run the
+\ code with the "go ff000100" command.
+
+ set r2,h#0000.0000 \ Setup DRAM Size Register
+ stw r2,h#10(r1) \ Upper Falcon
+
+ set r2,h#0000.0000 \ Setup DRAM Base Register
+ stw r2,h#18(r1) \ Upper Falcon
+
+\ End of danger section
+
+ set r2,h#4200.0000 \ Setup Clock Frequency Register
+ stw r2,h#20(r1) \ Upper Falcon
+
+ set r2,h#0000.0000 \ Setup ECC Registers
+ stw r2,h#30(r1) \ Upper Falcon
+
+ set r2,h#0000.0000 \ Setup Scruber Registers
+ stw r2,h#40(r1) \ Upper Falcon
+
+ set r2,h#ff40.0000 \ Setup ROMB Registers
+ stw r2,h#58(r1) \ Upper Falcon
+
+ set r2,h#0000.0000 \ Setup Clock Enable Register
+ stw r2,h#28(r1) \ Upper Falcon
+
+ mtspr lr,r29
+ bclr 20,0
+end-code
+
+label slam-raven ( -- )
+ mfspr r29,lr
+
+ raven-base set r1,*
+
+ set r2,0
+ stw r2,h#70(r1)
+ stw r2,h#74(r1)
+ stw r2,h#78(r1)
+ stw r2,h#7c(r1)
+ stw r2,h#44(r1)
+ stw r2,h#4c(r1)
+ stw r2,h#54(r1)
+ stw r2,h#40(r1)
+ stw r2,h#48(r1)
+ stw r2,h#50(r1)
+ stw r2,h#30(r1)
+ stw r2,h#20(r1)
+
+ set r2,h#8000.00c0
+ stw r2,h#5c(r1)
+
+ set r2,h#8000.8080
+ stw r2,h#58(r1)
+
+ set r2,h#0000.00be
+ stw r2,h#10(r1)
+
+ lwz r2,h#8(r1)
+ sync
+ andi. r2,r2,h#ffff
+ sync
+ stw r2,h#8(r1)
+
+ mtspr lr,r29
+ bclr 20,0 \ ET go home...
+end-code
+
+label slam-pci
+ mfspr r29,lr
+
+ set r3,h#0280.0004
+ set r4,4
+ cfg-l! bl *
+
+ set r3,0
+ set r4,h#10
+ cfg-l! bl *
+
+ set r4,h#14
+ cfg-l! bl *
+
+ set r4,h#80
+ cfg-l! bl *
+ set r4,h#88
+ cfg-l! bl *
+ set r4,h#90
+ cfg-l! bl *
+ set r4,h#98
+ cfg-l! bl *
+
+ set r4,h#84
+ cfg-l! bl *
+ set r4,h#8c
+ cfg-l! bl *
+ set r4,h#94
+ cfg-l! bl *
+ set r4,h#9c
+ cfg-l! bl *
+
+
+ mtspr lr,r29
+ bclr 20,0
+end-code
+
+
+label grand-slam ( -- )
+ mfspr r30,lr
+
+ slam-pci bl *
+ slam-raven bl *
+ slam-falcon bl *
+
+ mtspr lr,r30
+ bclr 20,0
+end-code
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/qemu/start.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/qemu/start.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,133 @@
+purpose: Low-level startup code for QEMU -M prep
+\ See license at end of file
+
+dictionary: ${BP}/cpu/ppc/build/basefw.dic
+command: &ppcforth &dictionary &this
+
+build-now
+
+\ create debug-start
+create slam-it \ Slam the chipset into a working mode
+
+h# 0018.0000 constant RAMsize \ Firmware size
+h# fef8.0000 constant falcon-base
+h# fef8.0010 constant falcon-mem-config
+h# feff.0000 constant raven-base
+
+
+\needs start-assembling fload ${BP}/cpu/ppc/asmtools.fth
+\needs write-dropin fload ${BP}/forth/lib/mkdropin.fth
+
+assembler
+' be-l@ is asm@
+' be-l! is asm!
+forth
+
+start-assembling
+
+label my-entry
+ 0 , \ To be patched later
+end-code
+
+fload ${BP}/cpu/ppc/prep/qemu/slam.fth \ Code to emulate POR state
+
+
+\needs io-base h# 8000.0000 constant io-base
+fload ${BP}/cpu/ppc/prep/qemu/initrav.fth \ Code to init Raven
+[ifdef] debug-start
+fload ${BP}/arch/prep/initcom1.fth \ Code to init COM1
+[then]
+
+label init-pbc \ Setup VIA SouthBridge Chip
+ mfspr r30,lr
+
+ set r1,h#80000cf8 \ PCI Configuration Address Register
+
+ set r2,h#80005840 \ Config address of word containing offset 41
+ stwbrx r2,r0,r1
+ set r3,h#20 \ Enable Port 92 Fast Reset
+ stb r3,5(r1) \ Write to config register 0x41
+
+ set r2,h#80005844 \ Config address of word containing offset 46
+ stwbrx r2,r0,r1
+ set r3,h#0120 \ (swapped) Enable Delay Transaction, posting
+ sth r3,6(r1) \ Write to config register 0x46
+
+ set r2,h#80005848 \ Config address of word containing offset 48
+ stwbrx r2,r0,r1
+ set r3,h#0901 \ (swapped) Enable Extra RTC port 74/75
+ sth r3,4(r1) \ Write to config register 0x48
+
+ set r2,h#8000584c \ Config address of word containing offset 4e
+ stwbrx r2,r0,r1
+\ set r3,h#00f1 \ (byte-swapped) set mem/DMA routing
+ set r3,h#ffff \ (byte-swapped) set mem/DMA routing
+ sth r3,6(r1) \ Write to config register 0x4e
+
+ set r2,h#80005854 \ Config address of word containing offset 56
+ stwbrx r2,r0,r1
+ set r3,h#a500 \ (swapped) IRQ10 for PIRQA, IRQ5 for PIRQB
+ sth r3,6(r1) \ Write to config register 0x56
+
+ mtspr lr,r30 \ Restore return address
+ bclr 20,0 \ Return
+end-code
+
+label start-system
+ mfspr r31,lr
+
+ grand-slam bl * \ Attempt to emulate POR state...
+
+ setup-raven bl *
+ init-pbc bl *
+\ [ifdef] debug-start
+\ init-com1 bl *
+\ [then]
+
+\ XXX Read value from NVRAM when QEMU's NVRAM layout is settled
+\ or read in from the Falcon registers when it's emulated.
+
+ set r5,h#8000000 \ 128 MiB
+ stw r5,0(r0) \ Store here for ppcboot.fth
+
+ RAMsize set r4,* \ Space Firmware gets
+ subf r3,r4,r5 \ Memory base address
+
+
+ mtspr lr,r31 \ Restore return address
+ bclr 20,0 \ ET go home...
+end-code
+
+start-system my-entry put-branch
+
+end-assembling
+
+writing start.di
+asm-base here over - 0 " start" write-dropin
+ofd @ fclose
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 FirmWorks
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/ppc/prep/raven.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/raven.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,92 @@
+purpose: "Raven" PCI Bridge Controller Access Methods
+\ See license at end of file
+
+h# feff.0000 constant raven-addr
+
+: pcic-l@ ( offset -- l ) raven-addr + be-l@ ;
+: pcic-w@ ( offset -- l ) raven-addr + be-w@ ;
+: pcic-c@ ( offset -- l ) raven-addr + c@ ;
+
+: pcic-l! ( l offset -- ) raven-addr + be-l! ;
+: pcic-w! ( l offset -- ) raven-addr + be-w! ;
+: pcic-c! ( l offset -- ) raven-addr + c! ;
+
+: raven? ( -- flag ) \ True if we have a Raven controller
+ 0 pcic-l@ h# 10574801 =
+;
+
+: r-rev@ ( -- b ) 6 pcic-c@ ; \ Chip revision
+
+: r-csr@ ( -- w ) h# 0a pcic-w@ ; \ Control and status register
+: r-csr! ( w -- ) h# 0a pcic-w! ;
+
+: csr-or ( w -- ) r-csr@ or r-csr! ;
+
+\ Is PCI in little endian?
+: pci-le? ( -- le? ) r-csr@ h# 8000 and ;
+
+\ Set PCI bus to little endian
+: pci-le ( -- ) h# 8000 csr-or ;
+
+\ PCI Read will complete before writes
+: pci-flush-before-read ( -- ) h# 1000 csr-or ;
+
+\ PPC master ties up bus during xfer
+: buss-hog ( -- ) h# 800 csr-or ;
+
+\ PPC Read will complete before writes
+: ppc-flush-before-read ( -- ) h# 400 csr-or ;
+
+\ Set PPC bus timeouts
+\ 0 = 256 uS
+\ 1 = 64 uS
+\ 2 = 8 uS
+\ 3 = disable
+: ppc-bus-timeout ( 0|1|2|3 -- )
+ r-csr@ h# 300 invert and 8 lshift or r-csr!
+;
+
+\ Set 64-bit mode
+: p64 ( -- ) h# 80 csr-or ;
+
+\ Turn on open-pic controller
+: open-pic-enable ( -- ) h# 20 csr-or ;
+
+\ Read module-id bits, tells us who owns he bus in MP systems
+\ 0 = device on ABG0
+\ 1 = device on ABG1
+\ 2 = device on ABG2
+\ 3 = Raven
+: mid@ ( -- master-id ) r-csr@ h# 3 and ;
+
+: r-feature@ ( -- w ) h# 8 pcic-w@ ;
+: r-feature! ( w -- ) h# 8 pcic-w! ;
+
+: r-prescaler@ ( -- b ) h# 10 pcic-c@ ;
+: r-prescaler! ( b -- ) h# 10 pcic-c! ;
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/reset.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/reset.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,117 @@
+purpose: Reset system - this version works on many PR*P systems
+\ See license at end of file
+
+headerless
+: (reset-all) ( -- )
+ icache-off dcache-off
+
+ \ We are about to disable translations by modifying the MSR,
+ \ but we must preserve our ability to do ISA I/O cycles to the
+ \ "92" register, so we have to set io-base back to the physical
+ \ address of ISA space.
+ h# 8000.0000 to io-base
+
+ \ Warm reset doesn't affect all the MSR bits, so we have to
+ \ explicitly set some of them to their power-up values.
+ \ We want ILE (10000) off so that the reset interrupt will occur
+ \ in big-endian mode, external interrupts (8000) off, machine
+ \ checks (1000) off, address translation (30) off, and the
+ \ interrupt prefix (40) on (to direct the reset interrupt to ROM).
+
+ msr@ h# 19030 invert and h# 40 or msr!
+
+ \ Read the old value because we must not change the
+ \ endianness of the host bridge until the very last step.
+
+ \ h# 92 pc@ ( old-value )
+
+ \ Drive the reset bit low because it's the low-to-high transition
+ \ that does the work.
+
+ \ dup 1 invert and h# 92 pc! ( old-value )
+
+ \ Clear the bridge endian bit (2) and set the reset bit (1)
+ \ 2 invert and 1 or h# 92 pc!
+
+ \ See below for the history behind the following replacement code.
+ \ We first check the reset bit for 1 and reset it only if needed.
+
+ h# 92 pc@ dup 1 and if
+
+ \ If we must reset it, the following will get the endian bit
+ \ from the msr reg for the Ultra. The Viper will reset here.
+
+ dup msr@ 1 and 2* or 1 invert and h# 92 pc!
+
+ then 2 invert and 1 or h# 92 pc!
+
+ \ On some systems, it takes a while for the reset to take effect,
+ \ so we wait here rather than returning to the prompt immediately,
+ \ to avoid confusing the user.
+ d# 3000 ms
+;
+' (reset-all) to reset-all
+headers
+
+\ Here's the story:
+\
+\ On an Ultra, the PCI bridge endian bit is driven by bit 1 (0x02) in
+\ I/O port 92. In the same port, bit 0 (0x01) making the transition
+\ from 0 to 1 causes the machine to reset. This is the standard I/O
+\ port 92 reset.
+\
+\ On a Viper, any write to port 92 will reset the machine (apparently
+\ the implementation is a PAL) and the PCI bridge endian switch is
+\ controlled via the PCI configuration registers. As it turns out,
+\ the code for the Viper will work on a Ultra to control the bridge
+\ (that's good, eaglele.fth is in arch/prep/) so there isn't any
+\ problem until you go to mess with port 92 on the Ultra.
+\
+\ Here's the relevant code from arch/prep/reset.fth:
+\
+\ 92 pc@ dup 1 invert and 92 pc! 2 invert and 1 or 92 pc!
+\
+\ If you try to reset the Ultra while running in little endian, it now
+\ reads port 92 its endian bit as zero (meaning big endian) while the
+\ Eagle bridge chip is really running in little endian (controlled
+\ through the config registers). This bit is carefully saved and
+\ stored back into the port when the reset bit is forced to zero.
+\ This neatly hangs the system. From observation, bit 0 is never set
+\ on entry to this code, even though it is left set. It is probably
+\ reset after it's tested in the early startup code. We could try the
+\ following for the reset code:
+\
+\ 92 pc@ dup 1 and if
+\ dup msr@ 1 and 2* or 1 invert and 92 pc!
+\ then 2 invert and 1 or h# 92 pc!
+\
+\ We'll have a problem with this code if we get some machine which
+\ uses bit 1 (0x02) for something other than the Eagle chip endian
+\ switch and it hangs the machine to set it and the machine is in
+\ little endian and bit 0 of port 92 is 1 when we invoke the
+\ (reset-all) word.
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/prep/residdef.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ cpu/ppc/prep/residdef.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,214 @@
+purpose: Definitions of residual data structures and field values
+\ See license at end of file
+
+[ifdef] create-resid-field-names
+alias res-field field
+: rfield ( offset size "name" -- offset' )
+ create over , + does> @ residual-data +
+;
+[else]
+: res-field ( offset size "name" -- offset' ) safe-parse-word 2drop + ;
+alias rfield res-field ( offset size "name" -- offset' )
+[then]
+
+d# 32 constant res#cpus \ Number of CPU slots in residual data
+d# 64 constant max#mems
+d# 256 constant max#devices
+d# 32 constant /pnp-avg
+d# 64 constant max#mem-segs
+
+: bfield ( offset "name" -- offset' ) /c res-field ;
+: wfield ( offset "name" -- offset' ) /w res-field ;
+: lfield ( offset "name" -- offset' ) /l res-field ;
+
+struct ( cpu )
+ lfield >cpu-type \ PVR@
+ bfield >cpu# \ The interrupt cookie for MP interrupts - 0 for UP
+ bfield >cpu-state \ 0:good 1:running FW 2:inactive 3: failed
+ 2 + \ reserved
+constant /cpu
+
+struct ( mem-seg )
+ lfield >usage
+ \ 1: FW stack 2: FW heap 4: FW code 8: Boot image 10: free mem
+ \ 20: Unpopulated mem 40: ISA 80: PCI config 100: PCI
+ \ 200: system regs 400: system I/O 800: I/O memory
+ \ 1000: unpopulated ROM 2000: ROM 4000: resume block 8000: other
+ lfield >base-page
+ lfield >page-count
+constant /mem-seg
+
+struct ( mem )
+ lfield >simm-size \ size in Mbytes. 0 means absent or bad
+constant /mem
+
+struct ( device )
+ lfield >bus-id \ 1: ISA 2: EISA 4: PCI 8: PCMCIA 10: PNPISA
+ \ 20: MCA 40: MX 80: Processor bus 100: VME
+ lfield >dev-id \ bus-specific encoding
+ lfield >serial# \ logical unit number
+ lfield >flags \ 1: output 2: input 4: console out 8: console in
+ \ 10: removable 20: R/O 40: power managed
+ \ 80: disableable 100: configurable 200: bootable
+ \ 400: on docking station 800: not configurable
+ \ 1000: failed 2000: on motherboard 4000: enabled
+ bfield >base-type
+ bfield >sub-type
+ bfield >interface
+ \ 1:0 SCSI 1:1 IDE 1:1:1 ATA IDE
+ \ 1:2 floppy 1:2:1 765 1:2:2 Super I/O floppy at 398
+ \ 1:2:3 .. at 026e 1:2:4 .. at 15c 1:2:5 .. at 02e
+ \ 1:3 IPI 1:80 other mass storage
+ \ 2:0 Ethernet 2:1 Token Ring 2:2 FDDI 2:80 other net
+ \ 3:0 VGA 3:1 SVGA 3:2 XGA 3:80 other display
+ \ 4:0 video 4:1 audio 4:1:1 CS4232 audio
+ \ 4:80 other multimedia
+ \ 5:0 RAM 5:0:0 PCI mem ctlr 5:0:1 RS6K mem ctlr
+ \ 5:1 FLASH 5:80 other memory
+ \ 6:0 host bridge 6:1 ISA bridge 6:2 EISA bridge
+ \ 6:3 MCA bridge 6:4:0 PCI w/ memory mapped config.
+ \ 6:4:1 PCI with CF8/CFC config 6:4:2 RS6K PCI
+ \ 6:5 PCMCIA bridge 6:6 VME bridge 6:80 other bridge
+ \ 7:0 RS232 7:0:1 COMx 7:0:2 16450 7:0:3 16550
+ \ 7:0:4 Super I/O serial @ 398 7:0:5 .. @ 26e
+ \ 7:0:6 .. @ 15c 7:0:5 .. @ 02e
+ \ 7:1 parallel 7:1:1 LPTx
+ \ 7:1:2 Super I/O parallel @ 398 7:1:3 .. at 26e
+ \ 7:1:4 .. at 15c 7:1:5 .. at 02e
+ \ 7:80 other communications device
+ \ 8:0 interrupt controller 8:0:1 ISA 8259
+ \ 8:0:2 EISA PIC 8:0:3 MPIC 8:0:4 RS6K PIC
+ \ 8:1 DMA 8:1:1 ISA DMA 8:1:2 EISA DMA
+ \ 8:2 timer 8:2:1 ISA timer 8:2:2 EISA timer
+ \ 8:3 RTC 8:3:1 ISA RTC
+ \ 8:4 L2 cache 8:4:1 write-through-only L2 cache
+ \ 8:4:2 copyback-enabled L2 cache 8:4:3 RS6K L2 cache
+ \ 8:5:0 NVRAM at ports 74-76 8:5:1 direct mapped NVRAM
+ \ 8:5:2 24-bit indirect NVRAM at ports 73-76
+ \ 8:6 power management 8:6:1 emerg. power-off warning
+ \ 8:6:2 software power on/off
+ \ 8:7 CMOS RAM
+ \ 8:8 operator panel 8:8:1 hard disk light
+ \ 8:8:2 CDROM light 8:8:3 power light 8:8:4 key lock
+ \ 8:8:5 alphanumeric display 8:8:6 system status LED
+ \ 8:9 service processor class 1
+ \ 8:a service processor class 2
+ \ 8:b service processor class 3
+ \ 8:c graphics assist 8:c:0 none 8:c:1 transfer data
+ \ 8:c:2 IGM32 8:c:3 IGM64
+ \ 8:80 other system peripheral
+ bfield >spare
+ lfield >bus-access \ Processor bus: bus#:byte BUID:byte reserved:short
+ \ ISA bus: slot#:byte log dev#:byte reserved:short
+ \ PCI bus: bus#:byte DevFunc#:byte reserved:short
+ \ etc. PCI DevFunc# is bits 15:8 of conf. addr. reg
+ lfield >allocated-offset \ Offset into PnP heap
+ lfield >possible-offset \ Offset into PnP heap
+ \ usually points to a PnP terminator byte
+ lfield >compatible-offset \ Offset into PnP heap
+ \ usually points to a PnP terminator byte
+constant /device
+
+struct ( residual-data )
+ 4 rfield r-length \ constant
+ 1 rfield r-version \ constant
+ 1 rfield r-revision \ constant
+ 2 rfield r-ec \ constant
+
+ \ VPD section
+
+ d# 32 rfield r-printable-model \ from "banner-name" property in "/'
+ d# 16 rfield r-serial# \ from NVRAM or IDPROM
+ d# 48 + \ reserved
+ 4 rfield r-fw-supplier \ fixed
+ 4 rfield r-fw-supports \ fixed
+ 4 rfield r-nvram-size \ from "size" method in "/nvram"
+ 4 rfield r-#simm-slots \ Code in probemem.fth
+ 2 rfield r-endian-switch-method \ depends on bridge chip
+ 2 rfield r-spread-io-method \ depends on bridge chip
+ 4 rfield r-smpiar \ ??
+ 4 rfield r-ram-err-log-offset \ computed after setting up PnP heap
+ d# 8 + \ reserved
+ 4 rfield r-processor-hz \ "clock-frequency" prop. in CPU node
+ 4 rfield r-processor-bus-hz \ "clock-frequency" prop. in "/"
+ d# 4 + \ reserved
+ 4 rfield r-timebase-divisor \ CPU-dependent 1000 * bus-clocks/tick
+ 4 rfield r-wordwidth \ 32 for 60x, 64 for 620
+ 4 rfield r-pagesize \ constant
+ 4 rfield r-coherence-block-size \ from "cache-line-size" in CPU node
+ 4 rfield r-granule-size \ "
+ 4 rfield r-cache-size \ sum of i$ + d$ in Kbytes - 16 for 603, 32 for 604
+ 4 rfield r-cache-attrib \ 1 for split - from "cache-unified" property
+ 4 rfield r-cache-assoc \ 0 for 603, 603e, 604
+ 4 rfield r-cache-line-size \ 0
+ 4 rfield r-icache-size \ from cpu-node prop
+ 4 rfield r-icache-assoc \ 2 for 603, 4 for 603e, 604
+ 4 rfield r-icache-line-size \ 32
+ 4 rfield r-dcache-size \ 8 for 603, 16 for 604
+ 4 rfield r-dcache-assoc \ 2 for 603, 4 for 603e, 604
+ 4 rfield r-dcache-line-size \ 32
+ 4 rfield r-tlb-size \ 128
+ 4 rfield r-tlb-attrib \ 1 for split
+ 4 rfield r-tlb-assoc \ 0
+ 4 rfield r-itlb-size \ 64
+ 4 rfield r-itlb-assoc \ 2
+ 4 rfield r-dtlb-size \ 64
+ 4 rfield r-dtlb-assoc \ 2
+ 4 rfield r-extended-vpd \ NULL pointer
+
+ \ CPU section
+
+ 2 rfield r-max#cpus \ system-dependent
+ 2 rfield r-actual#cpus \ # of cpu nodes
+ /cpu res#cpus * rfield r-cpus
+
+ \ Memory section
+
+ 4 rfield r-total-memory \ "reg" in "memory"
+ 4 rfield r-good-memory \ "reg" in "memory"
+ 4 rfield r-actual#mem-segs \ "reg" & "avail"
+ /mem-seg max#mem-segs * rfield r-mem-segs
+ 4 rfield r-actual#memories
+ /mem max#mems * rfield r-mems
+
+ \ Device section
+
+ 4 rfield r-actual#devices
+ /device max#devices * rfield r-devices
+
+dup constant pnp-heap-offset
+
+ /pnp-avg max#devices * 2* rfield r-pnp-heap
+
+constant /residual-data
+
+\ : >mem ( mem# -- adr ) /mem * r-mems + ;
+\ : >mem-seg ( seg# -- adr ) /mem-seg * r-mem-segs + ;
+\ : >cpu ( cpu# -- adr ) /cpu * r-cpus + ;
+\ : >devices ( dev# -- adr ) /device * r-devices + ;
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/ppc/resetvec.fth
==============================================================================
--- cpu/ppc/resetvec.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ cpu/ppc/resetvec.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -8,7 +8,7 @@
[then]
\needs start-assembling fload ${BP}/cpu/ppc/asmtools.fth
-\needs write-dropin fload ${BP}/tools/mkdropin.fth
+\needs write-dropin fload ${BP}/forth/lib/mkdropin.fth
h# e.0000 d# 16 rshift constant inflate-offset \ Shifted for addis
h# f.0000 d# 16 rshift constant workspace-offset \ Shifted for addis
Modified: cpu/x86/pc/emu/fw.bth
==============================================================================
--- cpu/x86/pc/emu/fw.bth Sat Aug 30 03:45:28 2014 (r3737)
+++ cpu/x86/pc/emu/fw.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -4,6 +4,7 @@
dictionary: ${BP}/cpu/x86/build/basefw.dic
command: &x86forth &dictionary &this
in: builton.fth
+in: ${BP}/dev/ide/node.hex
build-now
" fw.tag" r/w create-file drop tag-file !
@@ -192,6 +193,8 @@
[then]
devalias nfs net//obp-tftp:last//nfs
+fload ${BP}/dev/ide/twolevel-ide.fth
+
fload ${BP}/ofw/inet/loadtcp.fth
support-package: http
Added: dev/ds1385n.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/ds1385n.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,94 @@
+purpose: Driver for NVRAM portion of DS1385
+\ See license at end of file
+
+" nvram" device-name
+" nvram" device-type
+" pnpPNP,8" " compatible" string-property
+
+d# 4096 value /nvram
+
+nv-adr-low 1+ nv-adr-high = [if]
+ nv-adr-low my-space encode-phys 2 encode-int encode+
+ nv-data my-space encode-phys encode+ 1 encode-int encode+
+[else]
+ nv-adr-low my-space encode-phys 1 encode-int encode+
+ nv-adr-high my-space encode-phys encode+ 1 encode-int encode+
+ nv-data my-space encode-phys encode+ 1 encode-int encode+
+[then]
+
+" reg" property
+
+nv-data global value data-adr
+nv-adr-low global value as0-adr
+nv-adr-high global value as1-adr
+
+0 instance value nvram-ptr
+
+\ Writing to the as1 address latches the high 4 bits of the address,
+\ writing to the as0 address latches the low 8 bits of the address,
+\ and reading or writing the data address reads or writes the data.
+: nvram-set-adr ( offset -- data-adr )
+ wbsplit as1-adr pc! as0-adr pc! data-adr
+;
+: nvram@ ( offset -- n ) nvram-set-adr pc@ ;
+: nvram! ( n offset -- ) nvram-set-adr pc! ;
+' nvram@ to nv-c@
+' nvram! to nv-c!
+
+\ headers
+: clip-size ( adr len -- len' adr len' )
+ nvram-ptr + /nvram min nvram-ptr - ( adr len' )
+ tuck
+;
+: update-ptr ( len' adr -- len' )
+ drop dup nvram-ptr + to nvram-ptr
+;
+
+\ external
+: seek ( d.offset -- status )
+ 0<> over /nvram u> or if drop true exit then \ Seek offset too large
+ to nvram-ptr
+ false
+;
+: read ( adr len -- actual )
+ clip-size 0 ?do ( len' adr )
+ i nvram-ptr + nvram@ ( len' adr value )
+ over i + c! ( len' adr )
+ loop ( len' adr )
+ update-ptr
+;
+: write ( adr len -- actual )
+ clip-size 0 ?do ( len' adr )
+ dup i + c@ ( len' adr value )
+ i nvram-ptr + nvram! ( len' adr )
+ loop ( len' adr )
+ update-ptr ( len' )
+;
+: size ( -- d ) /nvram 0 ;
+
+\ external
+: open ( -- flag ) true ;
+: close ( -- ) ;
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/i8259.fth
==============================================================================
--- dev/i8259.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ dev/i8259.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -137,12 +137,12 @@
drop false ( false )
then ( false | level true )
;
-: interrupt-done ( -- ) eoi ;
: eoi ( -- )
h# b h# 20 ocw3@ 4 and ( slave? )
h# 20 h# 20 pc! ( slave? ) \ EOI to master
if h# 20 h# a0 pc! then ( ) \ EOI to slave
;
+: interrupt-done ( -- ) eoi ;
[then]
\ XXX we really should map the registers
Modified: dev/ide/atapi.fth
==============================================================================
--- dev/ide/atapi.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ dev/ide/atapi.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -84,7 +84,8 @@
defer pio-rwblock ' noop to pio-rwblock
: sendpkt ( addr len pkt-addr -- count )
over h# a0 swap sendcmd ( addr len pkt-addr )
- wait-until-drq pkt-len chip-base io-blk-w! ( addr len )
+ wait-until-drq if h# 100 ms 3drop 0 then ( addr len pkt-addr )
+ pkt-len chip-base io-blk-w! ( addr len )
waitonbusy ( addr len )
waitfordrq if \ Timeout ( addr len )
h# 100 ms 2drop 0 ( 0 )
Modified: dev/ide/idenode.fth
==============================================================================
--- dev/ide/idenode.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ dev/ide/idenode.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -55,6 +55,18 @@
r> base !
;
+: probe-child ( unit -- )
+ dup set-address ( unit )
+ any-blocks? 0= if drop exit then ( unit )
+ new-device ( unit )
+ encode-int " reg" property ( )
+ " node-fcode" $call-parent 1 byte-load ( )
+ cdrom? if " cdrom" device-name then ( )
+ finish-device ( )
+;
+
+: probe ( -- ) 2 0 do i probe-child loop ;
+
headers
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
Added: dev/ide/twolevel-ide.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/ide/twolevel-ide.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,68 @@
+\ See license at end of file
+purpose: IDE two-level - master,slave / primary,secondary on different levels
+
+0 0 " i1f0" " /isa" begin-package
+" ide-controller" device-name
+
+create node-fcode
+fload $(BP)/dev/ide/node.hex
+
+fload $(BP)/dev/ide/isaintf.fth
+fload $(BP)/dev/ide/generic.fth
+
+\ The ide-controller address space is of the form "unit#", an integer.
+\ Each child is an IDE "string"
+
+: decode-unit ( unit-str len -- phys )
+ base @ >r hex
+ $number if 0 then
+ r> base !
+;
+
+: encode-unit ( phys -- unit-str len ) base @ >r hex (u.) r> base ! ;
+
+1 encode-int " #address-cells" property
+
+: any-blocks? ( -- flag ) /block@ ;
+: cdrom? ( -- flag ) atapi-drive?@ ;
+
+new-device \ Create ide@0
+ 0 encode-int " reg" property
+ fload ${BP}/dev/ide/idenode.fth \ "ide" name declared here
+finish-device
+
+new-device \ Create ide@1
+ 1 encode-int " reg" property
+ fload ${BP}/dev/ide/idenode.fth \ "ide" name declared here
+finish-device
+
+end-package
+
+stand-init: Probe IDE
+ " /ide-controller/ide@0" select-dev " probe" $call-self unselect-dev
+ " /ide-controller/ide@1" select-dev " probe" $call-self unselect-dev
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2014 William M. Bradley
+\
+\ 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/pc87307.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/isa/pc87307.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,322 @@
+purpose: Driver for National PC87307 "Super IO" chip with Plug 'n Play
+\ See license at end of file
+
+hex
+: sio-b@ ( index -- b ) h# 15c pc! h# 15d pc@ ;
+: sio-b! ( b index -- ) h# 15c pc! h# 15d pc! ;
+: select-sio-dev ( device# -- ) 7 sio-b! ;
+
+nuser superio-node
+
+0 0 " i15c" " /isa" begin-package \ SuperI/O configuration registers
+" configuration" device-name
+" NSM,PC87307" model
+my-address my-space 2 reg
+" configuration" device-type
+
+0 0 encode-bytes
+ " NSM,PC87307-configuration" encode-string encode+
+ " pnp-configuration" encode-string encode+
+" compatible" property
+
+headerless
+: enable-sio-dev ( device# -- ) select-sio-dev 1 h# 30 sio-b! ;
+
+: ps2-floppy ( -- ) h# 21 sio-b@ 4 invert and h# 21 sio-b! ;
+\ : at-floppy ( -- ) h# 21 sio-b@ 4 or h# 21 sio-b! ;
+
+\ Doubly-indirect access to programmable chip select control registers
+: pcs@ ( index -- data ) h# 23 sio-b! h# 24 sio-b@ ;
+: pcs! ( data index -- ) h# 23 sio-b! h# 24 sio-b! ;
+
+headers
+
+\ This table converts the "interrupt type" field in Open Firmware ISA
+\ "interrupts" property to the corresponding code for Plug N Play
+\ interrupt configuration registers.
+ \ OFW#/type 0/low level 1/high level 2/falling edge 3/rising edge
+create int-map 1 c, 3 c, 0 c, 2 c,
+
+: set-interrupt ( level mode int# device# -- )
+ select-sio-dev ( level mode int# )
+ h# 70 swap wa+ ( level mode pnp-reg# )
+ swap int-map + c@ swap ( level pnp-mode pnp-reg# )
+ tuck 1+ sio-b! sio-b! ( )
+;
+
+: set-dma ( channel dma# device# -- )
+ select-sio-dev ( channel dma# )
+ h# 74 swap ca+ ( channel pnp-reg# )
+ sio-b! ( )
+;
+
+: set-reg ( address space size port# device# -- )
+ select-sio-dev ( address space size port# )
+ h# 60 swap wa+ >r ( address space size r: pnp-reg# )
+ swap 1 and if \ I/O space ( address size r: pnp-reg# )
+ drop ( address r: pnp-reg# )
+ wbsplit r@ sio-b! r> 1+ sio-b! ( )
+ else \ Memory space ( address size r: pnp-reg# )
+ \ XXX implement me
+ \ The Memory configuration registers are at 40-44, 48-4d, 50-54, 58-5d
+ \ See /fw/doc/standards/pnp/isapnp.{doc,ps}
+ true abort" ISA memory space configuration not yet supported"
+ then
+;
+
+[ifdef] notdef
+: set-memory ( address size device# -- )
+\ XXX implement me
+;
+[then]
+
+0 value device#
+: set-configuration ( -- )
+ " device#" get-property if exit then ( adr len )
+ get-encoded-int to device# ( )
+
+ " reg" get-property 0= if ( adr len )
+ \ XXX we must maintain a separate count of I/O and memory descriptors
+ \ There can be up to 8 I/O ports and up to 4 memory ranges
+ d# 12 0 do ( adr len )
+ dup 3 /l* < if leave then ( adr len )
+ decode-phys 2>r decode-int 2r> rot ( adr len phys.lo,hi size )
+ i device# " set-reg" superio-node @ $call-method
+ loop ( adr len )
+ 2drop ( )
+ then ( )
+
+ " interrupts" get-property 0= if ( adr len )
+ 2 0 do ( adr len )
+ dup 2 /l* < if leave then ( adr len )
+ 2 decode-ints swap ( adr' len' level mode )
+ i device# " set-interrupt" superio-node @ $call-method
+ loop ( adr len )
+ 2drop ( )
+ then ( )
+
+ " dma" get-property 0= if ( adr len )
+ 2 0 do ( adr len )
+ dup 5 /l* < if leave then ( adr len )
+ decode-int i device# " set-dma" superio-node @ $call-method
+ 4 0 do decode-int drop loop ( adr' len' )
+ loop ( adr len )
+ 2drop ( )
+ then ( )
+
+ device# " enable-sio-dev" superio-node @ $call-method
+;
+
+: open ( -- okay? ) true ;
+: close ( -- ) ;
+
+also forth definitions
+: configure-superio ( -- )
+ " /isa/configuration" open-dev superio-node !
+ " /isa" ['] set-configuration scan-subtree
+;
+warning @ warning off
+: stand-init-io
+ stand-init-io
+ configure-superio
+;
+warning !
+previous definitions
+
+end-package
+
+fload ${BP}/dev/pci/isaall.fth \ The usual ISA devices
+
+\ Declare the Super-I/O chip type in the child nodes
+dev /isa/parallel
+" NSM,PC87307" model
+4 " device#" integer-property
+\ XXX We should configure this device in ECP mode so we can set
+\ it to level sensitive
+7 encode-int 3 encode-int encode+ " interrupts" property
+device-end
+
+[ifndef] no-com1-node
+dev /isa/serial@3f8
+" NSM,PC87307" model
+6 " device#" integer-property
+4 encode-int 1 encode-int encode+ " interrupts" property
+device-end
+[then]
+
+[ifndef] no-com2-node
+dev /isa/serial@2f8
+" NSM,PC87307" model
+5 " device#" integer-property
+3 encode-int 1 encode-int encode+ " interrupts" property
+device-end
+[then]
+
+[ifndef] no-floppy-node
+dev /isa/fdc
+" NSM,PC87307" model
+3 " device#" integer-property
+6 encode-int 1 encode-int encode+ " interrupts" property
+device-end
+[then]
+
+dev /isa/8042
+0 " device#" integer-property
+" NSM,PC87307" model
+" interrupts" delete-property
+device-end
+
+dev /isa/8042/keyboard
+0 " device#" integer-property
+1 encode-int 1 encode-int encode+ " interrupts" property
+device-end
+
+dev /isa/8042/mouse
+1 " device#" integer-property
+d# 12 encode-int 1 encode-int encode+ " interrupts" property
+device-end
+
+\ Driver for the power management device on the pc87308 sio chip.
+
+0 0 " i380" " /isa" begin-package \ power management node
+
+headerless
+" power" device-name
+" power" device-type
+
+my-address my-space 2 encode-reg " reg" property
+
+8 " device#" integer-property
+0 0 encode-bytes
+ " NSM,PC87307-power" encode-string encode+
+ " pnpNSC,c0f" encode-string encode+
+ " pnpPNP,c02" encode-string encode+
+" compatible" property
+
+0 value power-base
+
+\ Indirect access to power management control registers
+: pm@ ( index -- data ) power-base rb! power-base 1+ rb@ ;
+: pm! ( data index -- ) power-base rb! power-base 1+ rb! ;
+
+: open ( -- flag )
+ power-base 0= if
+ my-address my-space 2 " map-in" $call-parent is power-base
+ then
+ true
+;
+: close ( -- ) ;
+
+also forth definitions
+
+0 value power-node
+
+stand-init: Power
+ " /power" open-dev to power-node
+;
+
+previous definitions
+
+end-package
+
+0 0 " i3e0" " /isa" begin-package \ gpio node
+
+headerless
+" gpio" device-name
+" gpio" device-type
+
+my-address my-space 2 encode-reg " reg" property
+
+7 " device#" integer-property
+
+0 0 encode-bytes
+ " dnard,gpio" encode-string encode+
+ " NSM,PC87307-gpio" encode-string encode+
+ " pnpNSC,c02" encode-string encode+
+ " pnpPNP,c02" encode-string encode+
+" compatible" property
+
+0 value gpio-base
+
+: map-gpio ( -- )
+ my-address my-space 8 " map-in" $call-parent is gpio-base
+;
+
+: gpio@ ( index -- n ) gpio-base + rb@ ;
+: gpio! ( n index -- ) gpio-base + rb! ;
+
+0 constant gpio-data
+1 constant gpio-direction
+2 constant output-type
+3 constant pull-up-control
+
+: open ( -- flag )
+ gpio-base 0= if
+ map-gpio
+
+ \ This lets "reset-all" work even in the early phases of stand-init
+ power-node 0= if " /power" open-dev to power-node then
+
+ \ init the power management to turn on gpio
+ h# 01 " pm@" power-node $call-method h# 80 or
+ h# 01 " pm!" power-node $call-method
+ then
+ true
+;
+: close ( -- ) ;
+: init ( -- ) ; \ Redefine as needed
+
+0 encode-int " #size-cells" property
+0 encode-int " #address-cells" property
+: decode-unit ( adr len -- ) ;
+: encode-unit ( -- adr len ) " " ;
+
+also forth definitions
+
+0 value gpio-node
+
+stand-init: GPIO
+ " /gpio" open-dev to gpio-node
+ " init" gpio-node $call-method
+;
+
+previous definitions
+
+end-package
+
+
+0 0 " i70" " /isa" begin-package \ Real-time clock node
+fload ${BP}/dev/ds1385r.fth
+2 " device#" integer-property
+8 encode-int 0 encode-int encode+ " interrupts" property
+
+also forth definitions
+stand-init: RTC
+ " /rtc" open-dev clock-node !
+;
+previous definitions
+
+end-package
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/m48t559.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/m48t559.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,143 @@
+purpose: Driver for RTC portion og M48T559
+\ See license at end of file
+
+hex
+headerless
+" rtc" device-name
+" rtc" device-type
+
+" m48t559-rtc" encode-string
+" compatible" property
+
+my-address my-space encode-phys 4 encode-int encode+
+" reg" property
+
+h# 1ff8 constant rtc-base
+
+: rtc-set-adr ( offset -- data-adr )
+ rtc-base + wbsplit nv-adr-high pc! nv-adr-low pc! nv-data
+;
+: rtc@ ( offset -- n ) lock[ rtc-set-adr pc@ ]unlock ;
+: rtc! ( n offset -- ) lock[ rtc-set-adr pc! ]unlock ;
+: inhibit-updates ( -- ) lock[ 0 rtc@ h# 40 or 0 rtc! ]unlock ;
+: enable-writes ( -- ) lock[ 0 rtc@ h# 80 or 0 rtc! ]unlock ;
+: start-updates ( -- ) lock[ 0 rtc@ h# c0 invert and 0 rtc! ]unlock ;
+
+\ Going to carve out a few more bytes, just under the start of the rtc regs
+\ to use as a place to put things like the century and maybe battery status
+
+\ So our map looks like:
+\
+\ Offset Value Where
+\
+\ 0x1fff year RTC
+\ 0x1ffe month RTC
+\ 0x1ffd date RTC
+\ 0x1ffc day RTC
+\ 0x1ffb hours RTC
+\ 0x1ffa minutes RTC
+\ 0x1ff9 seconds RTC
+\ 0x1ff8 control RTC <- rtc-base address
+\ 0x1ff7 watchdog RTC
+\ 0x1ff6 interrupts RTC
+\ 0x1ff5 alarm date RTC
+\ 0x1ff4 alarm hours RTC
+\ 0x1ff3 alarm minutes RTC
+\ 0x1ff2 alarm seconds RTC
+\ 0x1ff1 unused RTC
+\ 0x1ff0 flags RTC
+\ 0x1fef mac NVRAM
+\ 0x1fee mac NVRAM
+\ 0x1fed mac NVRAM
+\ 0x1fec mac NVRAM
+\ 0x1feb mac NVRAM
+\ 0x1fea mac NVRAM
+\ 0x1fe9 mac checksum NVRAM
+\ 0x1fe8 century NVRAM
+
+: cmos-base-adr ( -- adr ) rtc-base h# 10 - ;
+: cmos-set-addr ( offset -- data-adr )
+ cmos-base-adr + wbsplit nv-adr-high pc! nv-adr-low pc! nv-data
+;
+: cmos@ ( offset -- b ) cmos-set-addr pc@ ;
+: cmos! ( b offset -- ) cmos-set-addr pc! ;
+
+: century! ( b -- ) 0 cmos! ;
+: century@ ( -- b ) 0 cmos@ ;
+
+: check-battery ( -- error? )
+ " status" get-my-property 0= if
+ decode-string 2nip " bad battery" $= nip exit
+ then
+
+ -8 rtc@ h# 10 and ( error? ) \ Get battery status
+ dup if ( error? )
+ " bad battery" ( error $ )
+ else ( 0 )
+ " okay" ( 0 $ )
+ then ( error? $ )
+ encode-string " status" property ( error? )
+;
+
+true value first-open?
+: open ( -- ok? )
+ first-open? if
+ check-battery drop
+ false to first-open?
+ then
+ true
+;
+: close ;
+
+: bcd> ( bcd -- binary ) dup h# f and swap 4 >> d# 10 * + ;
+: >bcd ( binary -- bcd ) d# 10 /mod 4 << + ;
+
+: bcd-time&date ( -- s m h d m y century )
+ inhibit-updates
+ 1 rtc@ 2 rtc@ 3 rtc@ 5 rtc@ 6 rtc@ 7 rtc@ century@ ( s m h d m y c )
+ start-updates
+;
+: bcd! ( n offset -- ) swap >bcd swap rtc! ;
+
+: get-time ( -- s m h d m y )
+ bcd-time&date >r >r >r >r >r >r
+ bcd> r> bcd> r> bcd> r> bcd> r> bcd> r> bcd> r> bcd> ( s m h d m y c )
+
+ \ We allow the century byte to force the year to 20xx, but not to force
+ \ it to 19xx, because that would cause a problem when the century
+ \ rolls over.
+ dup d# 20 <> if
+ drop dup d# 94 < if d# 20 else d# 19 then
+ then
+
+ d# 100 * + \ Merge century with year
+;
+: set-time ( s m h d m y -- )
+ enable-writes
+ d# 100 /mod century! 7 bcd! 6 bcd! 5 bcd! 3 bcd! 2 bcd! 1 bcd!
+ r> d# 11 rtc! ( )
+ start-updates
+;
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/pci/intmap.fth
==============================================================================
--- dev/pci/intmap.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ dev/pci/intmap.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -60,7 +60,7 @@
1- swap d# 11 rshift h# 1f and ( int-pin0 dev# )
\ Bail out for non-existent device IDs
- pin,dev>pic-irq if false exit then ( opic-int# )
+ pin,dev>isa-irq if false exit then ( opic-int# )
true
;
Added: dev/via/vt82c586.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/via/vt82c586.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,57 @@
+purpose: Device nodes for VIA Technologies PCI-to-ISA bridge chip
+\ See license at end of file
+
+" VIA,82C586" encode-string " model" property
+" pci1106,586" encode-string
+" pnpPNP,a00" encode-string encode+
+" compatible" property
+
+fload ${BP}/dev/pci/isa.fth
+
+fload ${BP}/dev/pci/isamisc.fth
+
+\ Amend various device nodes
+my-self 0 to my-self \ Force the properties to be created in the child nodes
+
+" dma-controller" find-device
+ " pci1106,586-dma-controller" +compatible
+ " chrp,dma" +compatible
+ " VIA,82C586" model
+pop-device
+
+" interrupt-controller" find-device
+ " pci8086,484-interrupt-controller" +compatible
+ " pci10ad,105-interrupt-controller" +compatible
+ " chrp,iic" +compatible
+ " WINB,83C553" model
+pop-device
+
+" timer" find-device
+ " pci10ad,105-timer" +compatible
+ " WINB,83C553" model
+pop-device
+
+to my-self
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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/bga.bth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/video/bga.bth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,51 @@
+\ See license at end of file
+purpose: Build file for Bochs Graphics Adapter driver
+
+command: &tokenize &this
+build-now
+
+silent on
+
+begin-tokenizing bga.fc
+
+FCode-version2
+
+" vga" device-name
+fload ${BP}/dev/video/common/defer.fth \ Defered words
+1024x768x16
+fload ${BP}/dev/video/controlr/pcimap.fth \ Generic PCI implementations
+fload ${BP}/dev/video/controlr/vga.fth \ Load generic VGA routines
+fload ${BP}/dev/video/controlr/bga.fth \ Load BGA routines
+fload ${BP}/dev/video/controlr/bgapci.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
+
+probe
+end0
+
+end-tokenizing
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/controlr/bga.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/video/controlr/bga.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,96 @@
+\ See license at end of file
+purpose: Initialize Bochs Graphics Adapter Controllers
+
+\ This file contains the Cirrus Controller specific code.
+
+hex
+\ headerless
+: .driver-info ( -- )
+ .driver-info
+ ." BGA Code Version" cr
+;
+\ Constants from http://wiki.osdev.org/Bochs_VBE_Extensions
+\ VBE_DISPI_INDEX_ID (0)
+\ VBE_DISPI_INDEX_XRES (1)
+\ VBE_DISPI_INDEX_YRES (2)
+\ VBE_DISPI_INDEX_BPP (3)
+\ VBE_DISPI_INDEX_ENABLE (4)
+\ VBE_DISPI_INDEX_BANK (5)
+\ VBE_DISPI_INDEX_VIRT_WIDTH (6)
+\ VBE_DISPI_INDEX_VIRT_HEIGHT (7)
+\ VBE_DISPI_INDEX_X_OFFSET (8)
+\ VBE_DISPI_INDEX_Y_OFFSET (9)
+
+: vbe-w!
+ h# 1ce pw!
+ h# 1d0 pw!
+;
+
+\ At least under QEMU this is a write only register.
+\ Reading from 1d0 just returns the last word written regardless of index.
+\ For the case it works different one day
+\ : vbe-w@
+\ h# 1ce pw!
+\ h# 1d0 pw@
+\ ;
+
+: init-bga-controller ( -- ) \ This gets plugged into "init-controller"
+ 0 4 vbe-w! \ Disable VBE extensions
+ 0 8 vbe-w! 0 9 vbe-w! \ Set offsets to 0
+ width 1 vbe-w! height 2 vbe-w! depth 3 vbe-w! \ Set resolution
+ h# 41 4 vbe-w! \ Enable VBE and Linear FB
+;
+
+: set-resolution ( width height depth -- )
+ unmap-frame-buffer
+ (set-resolution)
+ map-io-regs
+ init-bga-controller
+ width height over char-width / over char-height /
+ /scanline depth " fb-install" eval
+ unmap-io-regs
+ map-frame-buffer
+ frame-buffer-adr /fb h# ff fill
+;
+
+: use-bga-words ( -- ) \ Turns on the BGA-specific words
+ ['] init-bga-controller to init-controller
+ use-vga
+;
+
+: init-bga-dac ( -- )
+ true to 6-bit-primaries? \ The default BGA pallete DAC is 3x6
+;
+
+: use-bga-dac ( -- )
+ ['] init-bga-dac to init-dac
+;
+
+: probe-dac ( -- ) \ Chained probing word...sets the dac type
+ safe? if use-bga-dac exit then
+ probe-dac \ Try someone else's probe
+;
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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/controlr/bgapci.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ dev/video/controlr/bgapci.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,179 @@
+\ See license at end of file
+purpose: Bochs Graphics Adapter 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
+;
+
+: determine-controller ( -- ) \ Determines which PCI controller we have
+ 0 to safe?
+ 0 c-w@ ( vendor )
+ h# 1234 =
+ 2 c-w@ ( vendor? device )
+ h# 1111 = and if
+ use-bga-words \ bga.fth
+ true to safe?
+ then
+;
+
+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 ( -- )
+
+ safe? 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
+\ Copyright (c) 2014 Artyom Tarasenko
+\
+\ 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: ofw/fs/fatfs/partition.fth
==============================================================================
--- ofw/fs/fatfs/partition.fth Sat Aug 30 03:45:28 2014 (r3737)
+++ ofw/fs/fatfs/partition.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -97,7 +97,8 @@
else \ Ordinary partition ( ... n,s,b,t )
suitable? if ( ... n,s,b,t )
to partition-type drop ( ... n,s )
- r@ + to sector-offset ( ... n )
+ \ FAT partitions encode offsets in 512 byte sectors
+ r@ + /sector d# 512 / / to sector-offset ( ... n )
/sector um* to size-high to size-low ( ... )
true to found? ( ... )
else ( ... n,s,b,t )
Added: ofw/fs/hfs/hfs.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ ofw/fs/hfs/hfs.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,700 @@
+purpose: Macintosh File System support package
+\ See license at end of file
+
+dev /packages
+new-device
+" hfs-file-system" device-name
+0 0 " support" property
+
+headerless
+0 instance value /al-blk
+0 instance value al-blk0
+
+\ The "extents" structure describes a contiguous piece of a file.
+\ They are stored in groups of 3. The first group of three is
+\ stored in:
+\ a) The catalog file node, for ordinary file data and resource forks
+\ b) The volume info record, for the catalog file and the extents
+\ overflow file.
+\ Subsequent groups of three are stored in node records within the
+\ extents overflow file, tagged by file ID and which fork. The
+\ extents overflow file itself is described solely by its first
+\ three extent descriptors, and does not use overflow extents to
+\ describe itself.
+
+struct ( extent )
+ /w field >first-al-blk
+ /w field >#al-blks
+constant /extent
+/extent 3 * constant /extents
+
+\ Given a target logical block number, the address of an array of 3 extents
+\ entries, and the number of the logical block represented by the first
+\ entry in that array, find the physical block number corresponding to the
+\ target logical block number and the number of blocks after it in the
+\ enclosing extent.
+: (next-piece) ( log-blk# extents-adr extent-log-blk -- phys-blk# #blks )
+ 3 0 do ( log-blk# extent extent-blk# )
+ over >#al-blks be-w@ + ( log-blk# extent extent-max-blk# )
+ 2 pick over u< if leave then ( log-blk# extent extent-max-blk# )
+ swap /extent + swap ( log-blk# extent' extent-max-blk# )
+ loop ( log-blk# extent' extent-max-blk# )
+ swap >r swap - ( #blks )
+ r@ >first-al-blk be-w@ r> >#al-blks be-w@ + over - swap
+;
+
+\ Determine the total number of blocks described by the array of 3 extents
+\ entries beginning at extents-adr
+: extent-#blks ( extents-adr -- #blks )
+ 0 swap >#al-blks /extents bounds do i be-w@ + /extent +loop
+;
+
+\ A node record is is a fixed length container that contains one or more
+\ variable-length nodes.
+
+struct ( node-record )
+ /l field >flink
+ /l field >blink
+ /c field >type
+ /c field >level
+ /w field >#recs
+ h# 1f4 +
+constant /node-record
+/node-record instance buffer: node-record
+
+
+\ Each B*Tree file begins with a header node.
+
+struct ( header-node )
+ /w field >tree-depth
+ /l field >root-index
+ /l field >#leaf-records
+ /l field >first-leaf
+ /l field >last-leaf
+ /w field >reclen
+ /w field >whatever1
+ /l field >total#nodes
+ /l field >#free-nodes
+constant /master-index
+
+\ Nodes in the catalog file come in three flavors - thread, directory, and file
+
+struct ( thread-catalog-entry ) \ Type = 3 or 4
+ 1 +
+ d# 8 +
+ /l field >thread-parent
+ d# 32 field >thread-name
+drop
+
+struct ( times )
+ /l field >create-time
+ /l field >modify-time
+ /l field >backup-time
+constant /times
+
+struct ( dir-catalog-entry )
+ 1 +
+ /w field >dir-flags
+ /w field >valence
+ /l field >dir-id
+ /times field >dir-times
+ d# 16 field >dir-user-finder-info
+ d# 16 field >dir-finder-info
+ d# 16 field >dir-reserved
+drop
+
+struct ( file-catalog-entry )
+ 1 +
+ /c field >file-flags \ h#80:record used 2:thread rec exists 1:locked
+ /c field >file-type \ Supposed to always contain 0
+ d# 16 field >user-finder
+ /l field >file#
+ /w field >dblk0
+ /l field >dleof
+ /l field >dpeof
+ /w field >rblk0
+ /l field >rleof
+ /l field >rpeof
+ /times field >file-times
+ d# 16 field >finder-info
+ /w field >/clump
+ /extents field >data-extents
+ /extents field >resource-extents
+ /l + ( reserved )
+constant /catalog-entry
+
+: skip-key ( adr -- adr' ) count 1 or + ;
+
+\ Each HFS volume is described by a volume-info structure that is stored
+\ at offset 1K bytes from the beginning of the volume.
+
+struct ( volume-info )
+ /w field >magic
+ /l field >init-date
+ /l field >mode-date
+ /w field >volume-attributes
+ /w field >volume-#files
+ /w field >bitmap-blk#
+ /w field >al-ptr
+ /w field >vol-#al-blks
+ /l field >/al-blk
+ /l field >vol-/clump
+ /w field >al-blk0
+ /l field >next-file#
+ /w field >#free-blocks
+ h# 1c field >vol-name
+ /l field >bkup-date
+ /w field >vseq#
+ /l field >write-count
+ /l field >/extent-clump
+ /l field >/catalog-clump
+ /w field >#rt-dirs
+ /l field >#files
+ /l field >#directories
+ d# 32 field >vol-finder-info
+ /w field >vc-size
+ /w field >vcbm-size
+ /w field >ctlc-size
+ /l field >/extent-tree
+ /extents field >extent-extents
+ /l field >/catalog-tree
+ /extents field >catalog-extents
+ h# 15e + \ There's something at offset 0x5f4 too
+constant /volume-info
+
+/volume-info instance buffer: volume-info
+
+3 constant extent-file-id
+4 constant catalog-file-id
+
+\ This forward reference is necessary because B*Trees are stored in
+\ files that are described by extents, some of which can be stored in
+\ the extents overflow B*Tree file. Infinite recursion is prevented by
+\ ensuring that the extents overflow file is contained entirely within
+\ the three fixed extents, so that file does not need overflow extents.
+defer search-btree
+
+: >extent-file-blk# ( log-blk# -- phys-blk# )
+ volume-info >extent-extents 0 (next-piece) drop
+;
+
+: extent-compare ( key-adr1 key-adr2 -- -|0|+ )
+ over ca1+ c@ over ca1+ c@ - ?dup if ( key-adr1 key-adr2 +- )
+ over wa1+ be-l@ over wa1+ be-l@ - ?dup if ( key-adr1 key-adr2 +- )
+ swap 6 + be-w@ swap 6 + be-w@ - ( +|0|- )
+ else ( key-adr1 key-adr2 )
+ nip nip ( +|- )
+ then ( +|0|- )
+ else ( key-adr1 key-adr2 )
+ nip nip ( +|- )
+ then ( +|0|- )
+;
+
+: find-extent ( al-blk# file-id fork -- node-adr )
+ d# 10 alloc-mem >r ( al-blk# file-id fork r: key-buffer )
+ r@ ca1+ c! ( al-blk# file-id )
+ r@ wa1+ be-l! ( al-blk# )
+ r@ 6 + be-w! ( )
+ r@ ['] extent-compare extent-file-id search-btree
+ r> d# 10 free-mem
+ 0= abort" Can't find extent"
+;
+
+: >catalog-file-blk# ( log-blk# -- phys-blk# )
+ 0 volume-info >catalog-extents >r ( log-blk# 0 r: entents-adr )
+
+ begin 2dup r@ extent-#blks + u> while ( log-blk# blk# r: extents-adr )
+ r> extent-#blks + ( log-blk# blk#' )
+ dup catalog-file-id 0 find-extent ( log-blk# blk# node-adr )
+ skip-key >r ( log-blk# blk# r: extents-adr' )
+ repeat ( log-blk# blk# r: extents-adr )
+
+ \ Now log-blk# is within the group of extents at "extents-adr" and
+ \ blk# is the beginning logical block of that extents group.
+
+ r> swap (next-piece) drop ( phys-blk# )
+;
+
+: al-blk>offset ( al-blk# -- d.disk-offset ) /al-blk um* al-blk0 0 d+ ;
+
+0 instance value btree-file#
+
+\ Return the physical disk offset of the indicated node record from the file
+\ "btree-file#",
+: >node-rec-offset ( rec# -- d.disk-offset )
+ /node-record um* /al-blk um/mod 0 swap ( d.blk-offset log-blk# )
+ btree-file# case
+ extent-file-id of >extent-file-blk# endof
+ catalog-file-id of >catalog-file-blk# endof
+ endcase ( d.blk-offset phys-blk# )
+ al-blk>offset d+ ( d.disk-offset )
+;
+
+\ "Cache tags" to remember which node is currently in the buffer
+-1 instance value node-rec#
+-1 instance value node-file#
+
+: >node-rec ( rec# -- record-adr )
+ dup node-rec# = btree-file# node-file# = and if
+ drop node-record exit
+ then ( rec# )
+
+ dup >node-rec-offset " seek" $call-parent drop ( rec# )
+ node-record /node-record " read" $call-parent drop ( rec# )
+
+ \ Update "cache tags"
+ to node-rec# btree-file# to node-file# ( )
+
+ node-record
+;
+
+: >nextnode ( node# rec# -- node#' rec#' )
+ dup >node-rec dup >#recs be-w@ ( node# rec# rec& #recs )
+ 3 pick 1+ ( node# rec# rec& #recs node#' )
+ <= if ( node# rec# rec& )
+ nip nip >flink be-l@ 0 swap ( 0 rec#' )
+ else ( node# rec# rec& )
+ drop swap 1+ swap ( node#' rec# )
+ then
+;
+: >node ( node# rec# -- node-adr )
+ >node-rec dup /node-record + rot 1+ /w* - be-w@ +
+;
+
+defer key-compare
+: search-ply ( key-adr node# rec# -- key-adr node#' rec#' )
+ 2>r 2r@
+ begin
+ 3dup >node key-compare ( key-adr node#' rec#' )
+ ?dup 0= if ( key-adr node#' rec#' )
+ 2r> 2drop exit
+ then ( key-adr node#' rec#' flag )
+ 0< if ( key-adr node#' rec#' )
+ 2drop 2r> exit
+ then ( key-adr node#' rec#' )
+ 2r> 2drop 2>r ( key-adr node#' rec#' )
+ 2r@ >nextnode 2dup or while ( key-adr node#' rec#' )
+ repeat ( key-adr node#' rec#' )
+ 2drop 2r>
+;
+
+0 instance value last-node#
+0 instance value last-rec#
+: (search-btree) ( key-adr compare-xt btree-file# -- false | node-adr true )
+ btree-file# >r to btree-file#
+ ['] key-compare behavior >r to key-compare ( key-adr r: old-file# old-xt )
+ 0 0 >node >root-index be-l@ 0 swap ( key-adr node# rec# )
+ begin ( key-adr node# rec# )
+ search-ply ( key-adr node#' rec#' )
+ dup >node-rec >level c@ 1 > ( key-adr node#' rec#' leval )
+ while ( key-adr node# rec# )
+ \ Go down a level
+ >node skip-key be-l@ 0 swap ( key-adr node#' rec#' )
+ repeat ( key-adr node# rec# )
+
+ \ If we are searching the catalog tree, save the node and record
+ \ numbers for the benefit of next-file
+ btree-file# catalog-file-id = if
+ 2dup to last-rec# to last-node#
+ then
+
+ >node tuck key-compare if ( node-adr )
+ drop false
+ else
+ true
+ then
+
+ r> to key-compare r> to btree-file#
+;
+' (search-btree) to search-btree
+
+: read-blocks ( adr blk# #blks -- )
+ swap al-blk>offset " seek" $call-parent drop ( adr #blks )
+ /al-blk * " read" $call-parent drop
+;
+: get-catalog ( -- )
+ h# 400 0 " seek" $call-parent drop
+ volume-info /volume-info " read" $call-parent drop
+
+ volume-info >r
+ r@ >magic be-w@ h# 4244 <> abort" Bad volume magic number"
+ r@ >/al-blk be-l@ to /al-blk
+ r@ >al-blk0 be-w@ h# 200 * to al-blk0
+ r> drop
+;
+: name-compare ( name-adr1 name-adr2 -- -|0|+ )
+ >r count tuck ( len1 adr1 len1 r: name-adr2 )
+ r> count dup >r ( len1 adr1 len1 adr2 len2 r: len2 )
+ rot min caps-comp ?dup if ( len1 +|- r: len2 )
+ nip r> drop ( +|- )
+ else ( len1 r: len2 )
+ r> - ( +|- )
+ then
+;
+: path-compare ( key-adr1 key-adr2 -- -|0|+ )
+ dup c@ 0= if 2drop 1 exit then ( key-adr1 key-adr2 )
+ swap wa1+ swap wa1+ ( dirid-adr1 dirid-adr2 )
+ over be-l@ over be-l@ - ?dup if ( dirid-adr1 dirid-adr2 -|+ )
+ nip nip ( -|+ )
+ else ( dirid-adr1 dirid-adr2 )
+ swap la1+ swap la1+ name-compare ( -|0|+ )
+ then
+;
+: type-compare ( key-adr1 key-adr2 -- -|0|+ )
+ dup c@ 0= if 2drop 1 exit then ( key-adr1 key-adr2 )
+ swap wa1+ swap wa1+ ( dirid-adr1 dirid-adr2 )
+ over be-l@ over be-l@ - ?dup if ( dirid-adr1 dirid-adr2 -|+ )
+ nip nip exit ( -|+ )
+ then
+ node-record >level c@ 1 = if ( dirid-adr1 dirid-adr2 )
+ swap la1+ swap la1+ ( adr1 adr2 )
+ skip-key dup c@ 2 = if ( adr1 filerec )
+ 1+ >user-finder be-l@ swap ( type adr1 )
+ ca1+ be-l@ = if
+ 0 ( 0 ) \ found it
+ else
+ 1 ( 1 ) \ not the type we want
+ then
+ else ( adr1 filerec )
+ 2drop 1 ( 1 ) \ not a file
+ then
+ else ( dirid-adr1 dirid-adr2 )
+ 2drop -1 ( -1 ) \ not level 1
+ then
+;
+
+\ search string for %xx and replace with hex char
+: translate-name ( adr len -- adr len' )
+ push-hex
+ 2dup ( adr len adr len )
+ begin dup while ( adr len adr len )
+ over c@ [char] % = if ( adr len adr len )
+ rot 2 - -rot ( adr len' adr len )
+ over 1+ 2 $number 0= if ( adr len adr len n )
+ 2 pick c! 2 - swap 1+ swap ( adr len adr' len' )
+ over dup 2+ swap 4 pick move ( adr len adr' len' )
+ then
+ else
+ swap 1+ swap 1- ( adr len adr' len' )
+ then
+ repeat
+ 2drop
+ pop-base
+;
+
+d# 38 instance buffer: file-key
+: find-file ( adr len dir-id -- false | node-adr true )
+ file-key wa1+ be-l! ( adr len )
+ translate-name ( adr len )
+ over c@ [char] : = if \ search by type
+ 1 /string ( adr len )
+ file-key 6 + place ( )
+ file-key ['] type-compare catalog-file-id search-btree
+ else \ search by name
+ file-key 6 + place ( )
+ file-key ['] path-compare catalog-file-id search-btree
+ then
+;
+
+0 instance value next-log-blk
+/extents buffer: extents
+0 instance value extent-log-blk
+0 instance value blk-offset
+
+0 instance value the-fork
+0 instance value current-node \ The catalog node that the last lookup found
+0 instance value cwd-id \ The current directory; a parent if file-id !0
+0 instance value file-id \ The current fileid, or 0 if the last lookup
+ \ found a directory
+
+: follow-thread ( adr -- node-adr false | true true )
+ dup >thread-name count
+ rot >thread-parent be-l@ find-file if
+ false
+ else
+ true true
+ then
+;
+\ This can fail if you try to select an alias whose referent has been deleted
+: select-component ( node-adr -- error? )
+ begin
+ dup to current-node
+ skip-key count ( adr type )
+ case
+ 1 of >dir-id be-l@ to cwd-id false true endof
+ 2 of >file# be-l@ to file-id false true endof
+ 3 of follow-thread endof
+ 4 of follow-thread endof
+ ( default ) ." Bogus Record Type: " dup . nip cr
+ endcase
+ until
+;
+: select-file ( adr len -- error? )
+ dup 0= if 2drop exit then
+ 0 to file-id
+ over c@ [char] \ = if
+ 1 /string 2 to cwd-id
+ over c@ [char] \ = if \ blessed folder indicator?
+ 1 /string volume-info >vol-finder-info be-l@ to cwd-id
+ then
+\ " " cwd-id find-file if select-component else 2drop true exit then
+ then ( adr len )
+ begin dup while ( rem$ )
+
+ \ Error if we have already found a file but there's more in the path
+ file-id if
+ " %RESOURCES" $= if
+ h# ff to the-fork false
+ else
+ true
+ then
+ exit
+ then ( rem$ )
+
+ [char] \ left-parse-string ( rem$' name$ )
+
+ \ Error if we can't find the path component
+ cwd-id find-file 0= if 2drop true exit then ( rem$ node-adr )
+
+ select-component if 2drop true exit then ( rem$ )
+ repeat ( null$ )
+ 2drop false
+;
+
+: do-seek ( d -- ) /al-blk um/mod to next-log-blk to blk-offset ;
+: prime-extents ( -- ) -1 to extent-log-blk 0 0 do-seek ;
+: extent-max-blk ( -- last-blk#+1 )
+ extent-log-blk -1 = if 0 exit then
+ extents extent-#blks extent-log-blk +
+;
+: get-extents ( log-blk# -- )
+ dup extent-log-blk u< if
+ 0 to extent-log-blk
+ current-node skip-key 1+
+ the-fork if >resource-extents else >data-extents then
+ extents /extents move ( log-blk# )
+ then
+ \ Now ext-log-blk <= log-blk#
+ begin dup extent-max-blk u>= while
+ extent-max-blk to extent-log-blk
+ extent-log-blk file-id the-fork find-extent
+ skip-key extents /extents move
+ repeat
+ drop
+ \ Now ext-log-blk <= log-blk# < extent-max-blk
+;
+
+\ Returns the address and length of the next contiguous part of the file
+\ following the given logical block number
+: next-piece ( log-blk# -- phys-blk# #blks )
+ dup get-extents ( log-blk# )
+ extents extent-log-blk (next-piece) ( phys-blk# #blks )
+;
+: hfsdfalign ( d.byte# 'fh -- d.aligned )
+ drop /al-blk um/mod nip /al-blk um*
+;
+
+: this-size ( -- n )
+ current-node skip-key 1+ the-fork if >rleof else >dleof then be-l@
+;
+: hfsdflen ( 'fhandle -- d.size ) drop this-size 0 ;
+
+: hfsdfseek ( d.byte# 'fh -- ) drop do-seek ;
+
+: #remaining ( -- n ) this-size next-log-blk /al-blk * - 0 max ;
+
+: hfsfread ( addr count 'fh -- #read )
+ drop ( adr len )
+ #remaining min dup >r ( adr #to-read )
+ /al-blk 1- + /al-blk / ( adr #blks-to-read )
+ begin dup while ( adr #blks-rem )
+ >r ( adr )
+ dup next-log-blk next-piece ( adr adr phys-blk# #blks )
+ r@ min dup >r ( adr adr phys-blk# #to-read )
+ read-blocks r> r> ( adr #to-read #blks-rem )
+ over - -rot ( #blks-rem' adr #to-read )
+ /al-blk * + swap ( adr' #blks-rem' )
+ repeat ( adr 0 )
+ 2drop
+ r>
+;
+
+: hfsfclose ( 'fh -- ) drop bfbase @ /al-blk free-mem ;
+
+/fd instance buffer: my-fd
+
+: hfssetupfd ( -- )
+ 0 0 do-seek
+ file @ >r my-fd file !
+ /al-blk alloc-mem /al-blk initbuf
+ my-fd r/o
+ ['] hfsdflen ['] hfsdfalign ['] hfsfclose ['] hfsdfseek
+ ['] nullwrite ['] hfsfread
+ setupfd
+ r> file !
+;
+
+headers
+
+: open ( -- )
+ get-catalog
+ 1 to cwd-id
+ -1 to extent-log-blk
+ my-args select-file if false exit then
+ file-id if hfssetupfd then
+ true
+;
+
+: close ( -- )
+ file-id if
+ my-fd ['] fclose catch ?dup if .error drop then
+ then
+;
+: read ( adr len -- actual )
+ my-fd ['] fgets catch if 3drop 0 then
+;
+\ : write ( adr len -- actual )
+\ tuck my-fd ['] fputs catch if 2drop 2drop -1 then
+\ ;
+: seek ( offset.low offset.high -- error? )
+ my-fd ['] dfseek catch if 2drop true else false then
+;
+: size ( -- d ) my-fd ['] dfsize catch if 2drop 0 0 then ;
+: load ( adr -- size ) size drop read ;
+
+1 value showtype?
+
+: file-name ( -- adr len )
+ current-node 6 + count ( adr len )
+ showtype? if
+ current-node skip-key c@ 2 = if
+ current-node skip-key 1+ >user-finder be-l@ ( adr len type )
+ file-key be-l! file-key 4 + dup h# 20 swap c! 1+ ( adr len buf )
+ swap dup >r move file-key r> 5 + ( adr len )
+ then
+ then
+;
+
+headerless
+
+\ XXX Is this correct for directory records?
+: locked? ( flags -- flag ) h# 100 and 0<> ;
+
+\ Convert HFS file attributes to the firmware encoding
+\ see showdir.fth for a description of the firmware encoding
+create type-map h# 4000 , h# 8000 , 0 , h# a000 ,
+: >canonical-attrs ( hfs-flags -- canon-attrs )
+ >r
+ \ Access permissions
+ r@ locked? if o# 666 else o# 777 then \ rwxrwxrwx
+
+ \ XXX maybe the way to set the "archive" indication is to compare
+ \ the backup time with the modification time.
+
+ \ Mutually-exclusive file types
+ current-node skip-key c@ 1- type-map swap na+ @ or
+
+ r> drop
+;
+
+create alias-times 0 be-l, 0 be-l, 0 be-l,
+
+decimal
+
+\ The months are stored in this order so the leap day happens at the
+\ end of a cycle.
+
+create days/month
+\ Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Feb
+ 31 c, 30 c, 31 c, 30 c, 31 c, 31 c, 30 c, 31 c, 30 c, 31 c, 31 c, 29 c,
+
+: >d/m ( day-in-year -- day month )
+ d# 12 0 do
+ days/month i ca+ c@ 2dup < if ( rem days-in-month )
+ drop 1+ i leave
+ then
+ -
+ loop
+;
+
+\ The Mac filesystem stores timestamps in seconds since midnight on 1/1/1904
+: mac-time> ( seconds -- s m h d m y )
+ \ XXX we should account for accumulated leap seconds too
+ 60 u/mod 60 u/mod 24 u/mod ( s m h days )
+ 60 - \ shift to first cycle boundary (1Mar04)
+ [ 365 4 * 1+ ] literal /mod >r ( s m h day-in-cycle r: cycles )
+ 365 u/mod ( s m h day-in-year year-in-cycle )
+ dup 4 = if 2drop 365 3 then ( s m h day-in-year year-in-cycle )
+ swap >d/m ( s m h year-in-cycle day month )
+ 9 - dup 0> if rot 1+ else 12 + rot then ( s m h d m year-in-cycle )
+ r> 4 * + 1904 +
+;
+hex
+
+: get-mtime ( adr -- s m h d m y ) >modify-time be-l@ mac-time> ;
+headers
+: file-info ( -- s m h d m y len attributes name$ )
+ current-node skip-key count swap >r case ( r: adr )
+ 1 of
+ r@ >dir-times get-mtime r@ >valence be-w@
+ endof
+ 2 of
+ r@ >file-times get-mtime r@ >dleof be-l@ r@ >rleof be-l@ +
+ endof
+ ( default )
+ >r alias-times get-mtime 0 r>
+ endcase ( s m h d m y len r: adr )
+ r> >dir-flags be-w@ >canonical-attrs ( s m h d m y len attrs )
+ file-name ( s m h d m y len attrs name$ )
+;
+
+headerless
+: next-file ( -- found? )
+ catalog-file-id to btree-file#
+ last-node# last-rec# >nextnode 2dup to last-rec# to last-node#
+ 2dup or 0= if 2drop false exit then ( node# rec# )
+ >node dup to current-node ( node-adr )
+ wa1+ be-l@ cwd-id =
+;
+
+headers
+
+: next-file-info ( id -- false | id' s m h d m y len attributes name$ true )
+ dup 0= if
+ null$ cwd-id find-file if drop else drop false exit then
+ then ( id )
+ next-file if ( id )
+ 1+ file-info true
+ else
+ drop false
+ then
+;
+: free-bytes ( -- d.#bytes ) volume-info >#free-blocks be-w@ /al-blk m* ;
+
+finish-device
+device-end
+
+
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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: ofw/fs/hfs/partition.fth
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ ofw/fs/hfs/partition.fth Tue Sep 2 23:07:35 2014 (r3738)
@@ -0,0 +1,130 @@
+purpose: Macintosh partition map decoder
+\ See license at end of file
+
+\ MacOS HFS
+struct ( mac-partition )
+ /w field >part-magic
+ 2 + \ Reserved
+ /l field >mp-#pm-blks \ # of blocks in the partition map
+ /l field >mp-blk0 \ first logical block number for partition
+ /l field >mp-#blks \ # of blocks in the partition
+ d# 32 field >mp-part-name
+ d# 32 field >mp-part-type
+ /l field >mp-dblk0 \ Offset in blocks to first data block
+ /l field >mp-#dblks \ Number of data blocks
+ /l field >mp-status \ Flags
+ /l field >mp-bblk0 \ Offset in blocks to first boot block
+ /l field >mp-/boot \ Size in bytes of boot area
+ /l field >mp-boot-load \ Load address of boot code
+ /l + \ Reserved
+ /l field >mp-boot-entry \ Entry address of boot code
+ /l + \ Reserved
+ /l field >mp-boot-sum \ Checksum of boot code
+ \ d# 16 field >mp-proctype \ Processor type
+drop
+
+0 value /mac-block
+0 value mac-partition-sector
+: get-mac-partition-info ( -- )
+ \ XXX we need to think about the boot area
+ sector-buf >mp-blk0 be-l@ sector-buf >mp-dblk0 be-l@ + to sector-offset
+ sector-buf >mp-#dblks be-l@ ( #sectors )
+ /mac-block um* to size-high to size-low
+;
+
+: default-mac? ( -- flag )
+ \ If a file name (or directory name) is supplied, and it
+ \ is not "%BOOT", we don't want to select the first bootable
+ \ partition, because bootable partitions often contain nothing
+ \ but SCSI device drivers. Instead, we look for a partition
+ \ with a file system on it.
+ filename nip 0= filename " %BOOT" $= or if
+ \ Find the first bootable partition
+ \ Readable(10), bootable(8), allocated(2), valid(1)
+ sector-buf >mp-status be-l@ h# 1b and h# 1b = if true exit then
+ else
+ \ Find the first readable, allocated, valid partition
+ \ of type "Apple_HFS"
+ sector-buf >mp-status be-l@ h# 13 and h# 13 = if
+ sector-buf >mp-part-type " Apple_HFS" comp 0= if true exit then
+ then
+ then
+ false
+;
+
+: find-mac-partition ( criterion-xt -- error? )
+ to suitable?
+
+ \ XXX search for a Mac partition whose "valid" flag is set.
+ \ The 0x01 status bit is "valid?" The 0x08 status bit is "bootable?"
+ \ If one is found, set partition-type, size-high, size-low, and
+ \ sector-offset and return false.
+
+ \ Get the partition entry that describes the partition map as a whole
+ 1 read-sector
+ sector-buf >part-magic be-w@ h# 504d <> if true exit then
+
+ 1 sector-buf >mp-#pm-blks be-l@ ( first-block #partition-map-blocks )
+ bounds ?do ( )
+ i to mac-partition-sector
+ i 1 <> if i read-sector then \ Already read sector 1
+ sector-buf >mp-status be-l@ 1 and if \ Valid?
+ suitable? if get-mac-partition-info false unloop exit then
+ then
+ loop ( )
+ true
+;
+
+: mac-map ( -- )
+ #part -1 = if \ Find the default bootable partition
+ ['] default-mac? find-mac-partition 0= if exit then
+ \ Failing to find a suitable default partition, use the first valid one
+ 1 to #part
+ then
+ ['] nth? find-mac-partition abort" No such MAC partition"
+;
+
+2 buffer: hfs-magic
+: hfs-partition? ( -- flag )
+ h# 400 0 offset " seek" $call-parent drop ( )
+ hfs-magic 2 " read" $call-parent ( #read )
+ \ Re-establish initial position
+ 0 0 offset " seek" $call-parent drop ( #read )
+
+ 2 <> if false exit then
+ hfs-magic be-w@ h# 4244 =
+;
+
+\ In addition to returning the flag, if it is a mac disk, this
+\ routine has the side effect of setting /mac-block and size-low,high
+: mac-disk? ( -- flag )
+ sector-buf be-w@ h# 4552 = dup if
+ sector-buf wa1+ be-w@ to /mac-block
+ /sector /mac-block <>
+ abort" The partition map code cannot handle non-512-byte sector sizes"
+ sector-buf la1+ be-l@ /mac-block um* to size-high to size-low
+ then
+;
+\ LICENSE_BEGIN
+\ Copyright (c) 1997 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