Module Name: src Committed By: eeh Date: Sat Feb 13 23:38:17 UTC 2010
Modified Files: src/sys/arch/sparc/stand/bootblk: Makefile bootblk.fth genfth.cf Added Files: src/sys/arch/sparc/stand/bootblk: genlfs.cf Log Message: Major overhaul: 1) Add support for multiple filesystems including ffsv1, ffsv2, lfsv1 and lfsv2. (ffsv1 and lfsv2 are known to work. ffv2 support needs more work. lfsv1 is probably untested.) 2) Only 32-bit Fcodes are used. All 64-bit math uses two cells. This means it should work on 32-bit machines. Additional work to consider: 1) Rename genfth.cf to genffs.cf, or keep it and move the ffs symbols to genffs.cf 2) Move the ffs code and the lfs code to different source files so you can selectively fload the just the filesystems you want. 3) Add code to load ELF files directly instead of relying on the host firmware ELF support. But, since the binary is now 7250 bytes there may not be room. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/sys/arch/sparc/stand/bootblk/Makefile cvs rdiff -u -r1.9 -r1.10 src/sys/arch/sparc/stand/bootblk/bootblk.fth cvs rdiff -u -r1.6 -r1.7 src/sys/arch/sparc/stand/bootblk/genfth.cf cvs rdiff -u -r0 -r1.1 src/sys/arch/sparc/stand/bootblk/genlfs.cf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sparc/stand/bootblk/Makefile diff -u src/sys/arch/sparc/stand/bootblk/Makefile:1.12 src/sys/arch/sparc/stand/bootblk/Makefile:1.13 --- src/sys/arch/sparc/stand/bootblk/Makefile:1.12 Mon Apr 6 12:43:26 2009 +++ src/sys/arch/sparc/stand/bootblk/Makefile Sat Feb 13 23:38:17 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.12 2009/04/06 12:43:26 tsutsui Exp $ +# $NetBSD: Makefile,v 1.13 2010/02/13 23:38:17 eeh Exp $ CURDIR= ${.CURDIR} S= ${CURDIR}/../../../.. @@ -10,7 +10,7 @@ PROG= bootblk SRCS= bootblk.fth OBJS= -CLEANFILES= assym.fth.h assym.fth.h.tmp machine sparc \ +CLEANFILES= ffs.fth.h lfs.fth.h assym.fth.h.tmp machine sparc \ bootblk bootblk.text bootblk.text.tmp NOMAN= # defined @@ -32,17 +32,22 @@ machine: ln -s ${.CURDIR}/../../../${MACHINE}/include machine -assym.fth.h: genfth.cf machine sparc +ffs.fth.h: genfth.cf machine sparc ${TOOL_GENASSYM} -f -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \ - <${.CURDIR}/genfth.cf >assym.fth.h.tmp && \ - mv -f assym.fth.h.tmp assym.fth.h + <${.CURDIR}/genfth.cf >ffs.fth.h.tmp && \ + mv -f ffs.fth.h.tmp ffs.fth.h -bootblk.text: bootblk.fth assym.fth.h +lfs.fth.h: genlfs.cf machine sparc + ${TOOL_GENASSYM} -f -- ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \ + <${.CURDIR}/genlfs.cf >lfs.fth.h.tmp && \ + mv -f lfs.fth.h.tmp lfs.fth.h + +bootblk.text: bootblk.fth ffs.fth.h lfs.fth.h ${TOOL_AWK} '/fload/ { print "#include \"" $$2 "\"" }; !/fload/' \ ${.CURDIR}/bootblk.fth | /usr/bin/cpp -P >bootblk.text.tmp && mv -f bootblk.text.tmp bootblk.text -bootblk: bootblk.fth assym.fth.h +bootblk: bootblk.fth ffs.fth.h lfs.fth.h ${TOOL_FGEN} -o bootblk ${.CURDIR}/bootblk.fth beforedepend: Index: src/sys/arch/sparc/stand/bootblk/bootblk.fth diff -u src/sys/arch/sparc/stand/bootblk/bootblk.fth:1.9 src/sys/arch/sparc/stand/bootblk/bootblk.fth:1.10 --- src/sys/arch/sparc/stand/bootblk/bootblk.fth:1.9 Mon Oct 19 18:12:37 2009 +++ src/sys/arch/sparc/stand/bootblk/bootblk.fth Sat Feb 13 23:38:17 2010 @@ -1,11 +1,11 @@ -\ $NetBSD: bootblk.fth,v 1.9 2009/10/19 18:12:37 snj Exp $ +\ $NetBSD: bootblk.fth,v 1.10 2010/02/13 23:38:17 eeh Exp $ \ \ IEEE 1275 Open Firmware Boot Block \ \ Parses disklabel and UFS and loads the file called `ofwboot' \ \ -\ Copyright (c) 1998 Eduardo Horvath. +\ Copyright (c) 1998-2010 Eduardo Horvath. \ All rights reserved. \ \ Redistribution and use in source and binary forms, with or without @@ -55,15 +55,15 @@ \ defer cif-peer ( phandle -- phandle ) \ defer cif-getprop ( len adr cstr phandle -- ) -: find-cif-method ( method,len -- xf ) +: find-cif-method ( method len -- xf ) cif-phandle find-method drop ; -" claim" find-cif-method to cif-claim -" open" find-cif-method to cif-open -" close" find-cif-method to cif-close -" read" find-cif-method to cif-read -" seek" find-cif-method to cif-seek +" claim" find-cif-method to cif-claim +" open" find-cif-method to cif-open +" close" find-cif-method to cif-close +" read" find-cif-method to cif-read +" seek" find-cif-method to cif-seek : twiddle ( -- ) ." ." ; \ Need to do this right. Just spit out periods for now. @@ -71,8 +71,49 @@ \ Support routines \ +\ 64-bit math support + +here h# ffff over l! <w@ constant little-endian? +: ul>d ( l -- d.lo d.hi ) 0 ; +: l>d ( l -- d.lo d.hi ) dup 0< if -1 else 0 then ; +: d>l ( d.lo d.hi -- l ) drop ; +: d@ ( addr -- d.lo d.hi ) dup l@ swap la1+ l@ little-endian? invert if swap then ; +: d! ( d.lo d.hi addr -- ) + little-endian? invert if -rot swap rot then tuck la1+ l! l! ; +: d-and ( d1 d2 -- d1-and-d2 ) rot and -rot and swap ; +: d*u ( d1 u -- d2 ) tuck um* drop -rot um* rot + ; +: d<< ( d1 n -- d1<<n ) \ Hope this works + tuck << ( d.lo n d.hi' ) + -rot 2dup << ( d.hi' d.lo n d.lo' ) + -rot d# 32 swap - >> ( d.hi' d.lo' lo.hi ) + rot + +; +: d>> ( d1 n -- d1>>n ) \ Hope this works + rot over >> -rot ( d.lo' d.hi n ) + 2dup >> -rot ( d.lo' d.hi' d.hi n ) + d# 32 swap - << rot + swap +; +: d> ( d1 d2 -- d1>d2? ) + rot swap 2dup = if + 2drop > exit + then + > nip nip +; +: d>= ( d1 d2 -- d1>=d2? ) + rot swap 2dup = if + 2drop >= exit + then + >= nip nip +; +: d< ( d1 d2 -- d1<d2? ) d>= invert ; +: d= ( d1 d2 -- d1=d2? ) rot = -rot = and ; +: d<> ( d1 d2 -- d1<>d2? ) d= invert ; + + +\ String support + : strcmp ( s1 l1 s2 l2 -- true:false ) - rot tuck <> if 3drop false exit then + rot tuck <> if 3drop false exit then comp 0= ; @@ -112,91 +153,181 @@ ; \ -\ BSD FFS parameters +\ BSD UFS parameters \ -fload assym.fth.h +fload ffs.fth.h +fload lfs.fth.h sbsize buffer: sb-buf -1 value boot-ihandle dev_bsize value bsize 0 value raid-offset \ Offset if it's a raid-frame partition -false value force-raid \ Force reads from raid offset -: strategy ( addr size start -- nread ) - raid-offset + bsize * 0 " seek" boot-ihandle $call-method - -1 = if - ." strategy: Seek failed" cr - abort +: strategy ( addr size db.lo db.hi -- nread ) + raid-offset l>d d+ ( addr size db.lo' db.hi' ) + bsize d*u ( addr size sector.lo sector.hi ) + " seek" boot-ihandle $call-method -1 = if + ." strategy: Seek failed" cr + abort + then ( addr size ) + " read" boot-ihandle $call-method +; + + +\ +\ Multi-FS support +\ +\ XXX Maybe the different filesystems should be segregated into separate files +\ XXX that are individually fload-ed. +\ + +defer fs-size +defer di-size +defer di-mode +defer /dino +defer cgstart +defer di-db@ +defer di-ib@ +defer ib-ib@ +defer fs-bsize +defer fsbtodb +defer blksize +defer lblkno +defer blkoff +defer read-inode +\ LFS ifile +defer /ifile +defer if_daddr + +\ +\ FFS Cylinder group macros +\ + +: cgdmin ( cg fs -- d-1st-data-block ) dup fs_dblkno l@ l>d 2swap cgstart d+ ; +: cgimin ( cg fs -- d-inode-block ) dup fs_iblkno l@ l>d 2swap cgstart d+ ; +: cgsblock ( cg fs -- d-super-block ) dup fs_sblkno l@ l>d 2swap cgstart d+ ; +: cgstod ( cg fs -- d-cg-block ) dup fs_cblkno l@ l>d 2swap cgstart d+ ; + +\ +\ FFS Block and frag position macros +\ + +: ffs-blkoff ( pos.lo pos.hi fs -- off.lo off.hi ) fs_qbmask d@ d-and ; +\ : ffs-fragoff ( pos.lo pos.hi fs -- off.lo off.hi ) fs_qfmask d@ d-and ; +\ : ffs-lblktosize ( blk fs -- off.lo off.hi ) 0 fs_bshift l@ d<< ; +: ffs-lblkno ( pos.lo pos.hi fs -- off.lo off.hi ) fs_bshift l@ d>> ; +: ffs-numfrags ( pos.lo pos.hi fs -- off.lo off.hi ) fs_fshift l@ d>> ; +: ffs-blkroundup ( pos.lo pos.hi fs -- off.lo off.hi ) + >r r@ fs_qbmask d@ d+ r> fs_bmask l@ l>d d-and +; +: ffs-fragroundup ( pos.lo pos.hi fs -- off.lo off.hi ) + >r r@ fs_qfmask d@ d+ r> fs_fmask l@ l>d d-and +; +: ffs-fragstoblks ( pos.lo pos.hi fs -- off.lo off.hi ) fs_fragshift l@ d>> ; +: ffs-blkstofrags ( blk fs -- frag ) fs_fragshift l@ << ; +\ : ffs-fragnum ( fsb fs -- off ) fs_frag l@ 1- and ; +\ : ffs-blknum ( fsb fs -- off ) fs_frag l@ 1- not and ; +: ffs-dblksize ( lbn.lo lbn.hi inodep fs -- size ) + >r -rot 2dup ndaddr l>d d> ( inop d-lbn >ndaddr? ) + -rot 1 0 d+ ( inop >ndaddr? d-lbn+1 ) + r@ fs_bshift l@ d<< ( inop >ndaddr? d-lbn+1<<bshift ) + 2swap >r di-size d@ ( d-lbn+1<<bshift d-size ) + 2swap 2over d< r> or if ( d-size ) + 2drop r> fs-bsize l@ exit + then + r@ ffs-blkoff ( size.lo size.hi ) + r> ffs-fragroundup d>l ( size ) +; + +: ino-to-cg ( ino fs -- cg ) fs_ipg l@ / ; +: ino-to-fsbo ( ino fs -- fsb0 ) fs_inopb l@ mod ; +: ino-to-fsba ( ino fs -- ba.lo ba.hi ) \ Need to remove the stupid stack diags someday + 2dup ( ino fs ino fs ) + ino-to-cg ( ino fs cg ) + over ( ino fs cg fs ) + cgimin ( ino fs inode-blk.lo inode-blk.hi ) + 2swap ( d-inode-blk ino fs ) + tuck ( d-inode-blk fs ino fs ) + fs_ipg l@ ( d-inode-blk fs ino ipg ) + mod ( d-inode-blk fs mod ) + swap ( d-inode-blk mod fs ) + dup ( d-inode-blk mod fs fs ) + fs_inopb l@ ( d-inode-blk mod fs inopb ) + rot ( d-inode-blk fs inopb mod ) + swap ( d-inode-blk fs mod inopb ) + / ( d-inode-blk fs div ) + swap ( d-inode-blk div fs ) + ffs-blkstofrags ( d-inode-blk frag ) + 0 d+ +; +: ffs-fsbtodb ( fsb.lo fsb.hi fs -- db.lo db.hi ) + fs_fsbtodb l@ d<< +; + + +\ +\ LFS suff +\ +: lfs-blkoff ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_bmask d@ d-and ; +\ : lfs-fragoff ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_ffmask d@ d-and ; +\ : lfs-lblktosize ( blk fs -- off.lo off.hi ) 0 lfs_bshift l@ d<< ; +: lfs-lblkno ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_bshift l@ d>> ; +: lfs-numfrags ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_ffshift l@ d>> ; +: lfs-roundup ( pos.lo pos.hi mask.lo mask.hi ) + 2swap 2over d+ 2swap ( d-pos* d-mask ) + invert swap invert swap d-and +; +: lfs-blkroundup ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_bmask d@ lfs-roundup ; +: lfs-fragroundup ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_ffmask d@ lfs-roundup ; +: lfs-fragstoblks ( pos.lo pos.hi fs -- off.lo off.hi ) lfs_fbshift l@ d>> ; +: lfs-dblksize ( lbn.lo lbn.hi inodep fs -- size ) + >r -rot 2dup ndaddr l>d d> ( inop d-lbn >ndaddr? ) + -rot 1 0 d+ ( inop >ndaddr? d-lbn+1 ) + r@ fs_bshift l@ d<< ( inop >ndaddr? d-lbn+1<<bshift ) + 2swap >r di-size d@ ( d-lbn+1<<bshift d-size ) + 2swap 2over d< r> or if ( d-size ) + 2drop r> fs-bsize l@ exit then - " read" boot-ihandle $call-method + r@ lfs-blkoff ( size.lo size.hi ) + r> lfs-fragroundup d>l ( size ) +; +: lfs-fsbtodb ( fsb.lo fsb.hi fs -- db.lo db.hi ) + lfs_fsbtodb l@ d<< ; +\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ -\ Cylinder group macros +\ The rest of the multi-filesystem stuff \ +\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ -: cgbase ( cg fs -- cgbase ) fs_fpg l@ * ; -: cgstart ( cg fs -- cgstart ) - 2dup fs_old_cgmask l@ not and ( cg fs stuff -- ) - over fs_old_cgoffset l@ * -rot ( stuffcg fs -- ) - cgbase + +\ +\ FFS v1 +\ +: di-db-v1@ ( indx dinode -- db.lo db.hi ) di1_db swap la+ l@ l>d ; +: di-ib-v1@ ( indx dinode -- db.lo db.hi ) di1_ib swap la+ l@ l>d ; +: ib-ib-v1@ ( indx iblk -- db.lo db.hi ) swap la+ l@ l>d ; + +: cgbase ( cg fs -- daddr.lo daddr.hi ) fs_fpg l@ um* ; +: cgstart-ufs1 ( cg fs -- cgstart ) + 2dup fs_old_cgmask l@ invert and ( cg fs stuff ) + over fs_old_cgoffset l@ um* ( cg fs off.lo off.hi ) + 2swap cgbase d+ ( off.lo off.hi ) ; -: cgdmin ( cg fs -- 1st-data-block ) dup fs_dblkno l@ -rot cgstart + ; -: cgimin ( cg fs -- inode-block ) dup fs_iblkno l@ -rot cgstart + ; -: cgsblock ( cg fs -- super-block ) dup fs_sblkno l@ -rot cgstart + ; -: cgstod ( cg fs -- cg-block ) dup fs_cblkno l@ -rot cgstart + ; \ -\ Block and frag position macros +\ FFS v2 \ -: blkoff ( pos fs -- off ) fs_qbmask x@ and ; -: fragoff ( pos fs -- off ) fs_qfmask x@ and ; -: lblktosize ( blk fs -- off ) fs_bshift l@ << ; -: lblkno ( pos fs -- off ) fs_bshift l@ >> ; -: numfrags ( pos fs -- off ) fs_fshift l@ >> ; -: blkroundup ( pos fs -- off ) dup fs_bmask l@ -rot fs_qbmask x@ + and ; -: fragroundup ( pos fs -- off ) dup fs_fmask l@ -rot fs_qfmask x@ + and ; -\ : fragroundup ( pos fs -- off ) tuck fs_qfmask x@ + swap fs_fmask l@ and ; -: fragstoblks ( pos fs -- off ) fs_fragshift l@ >> ; -: blkstofrags ( blk fs -- frag ) fs_fragshift l@ << ; -: fragnum ( fsb fs -- off ) fs_frag l@ 1- and ; -: blknum ( fsb fs -- off ) fs_frag l@ 1- not and ; -: dblksize ( lbn dino fs -- size ) - -rot ( fs lbn dino ) - di_size x@ ( fs lbn di_size ) - -rot dup 1+ ( di_size fs lbn lbn+1 ) - 2over fs_bshift l@ ( di_size fs lbn lbn+1 di_size b_shift ) - rot swap << >= ( di_size fs lbn res1 ) - swap ndaddr >= or if ( di_size fs ) - swap drop fs_bsize l@ exit ( size ) - then tuck blkoff swap fragroundup ( size ) -; +: di-db-v2@ ( indx dinode -- db.lo db.hi ) di2_db swap 2* la+ d@ ; +: di-ib-v2@ ( indx dinode -- db.lo db.hi ) di2_ib swap 2* la+ d@ ; +: ib-ib-v2@ ( indx iblk -- db.lo db.hi ) 2* la+ d@ ; +\ +\ LFS v1 +\ -: ino-to-cg ( ino fs -- cg ) fs_ipg l@ / ; -: ino-to-fsbo ( ino fs -- fsb0 ) fs_inopb l@ mod ; -: ino-to-fsba ( ino fs -- ba ) \ Need to remove the stupid stack diags someday - 2dup ( ino fs ino fs ) - ino-to-cg ( ino fs cg ) - over ( ino fs cg fs ) - cgimin ( ino fs inode-blk ) - -rot ( inode-blk ino fs ) - tuck ( inode-blk fs ino fs ) - fs_ipg l@ ( inode-blk fs ino ipg ) - mod ( inode-blk fs mod ) - swap ( inode-blk mod fs ) - dup ( inode-blk mod fs fs ) - fs_inopb l@ ( inode-blk mod fs inopb ) - rot ( inode-blk fs inopb mod ) - swap ( inode-blk fs mod inopb ) - / ( inode-blk fs div ) - swap ( inode-blk div fs ) - blkstofrags ( inode-blk frag ) - + -; -: fsbtodb ( fsb fs -- db ) fs_fsbtodb l@ << ; \ \ File stuff @@ -204,76 +335,58 @@ niaddr /w* constant narraysize -struct - 8 field >f_ihandle \ device handle - 8 field >f_seekp \ seek pointer - 8 field >f_fs \ pointer to super block - ufs1_dinode_SIZEOF field >f_di \ copy of on-disk inode - 8 field >f_buf \ buffer for data block - 4 field >f_buf_size \ size of data block - 4 field >f_buf_blkno \ block number of data block -constant file_SIZEOF - -file_SIZEOF buffer: the-file -sb-buf the-file >f_fs x! - -ufs1_dinode_SIZEOF buffer: cur-inode +\ Assume UFS2 dinodes are always biger than UFS1 +ufs2_dinode_SIZEOF buffer: cur-inode h# 2000 buffer: indir-block --1 value indir-addr +create indir-addr -1 , -1 , \ \ Translate a fileblock to a disk block \ -\ We only allow single indirection +\ We don't do triple indirect blocks. \ -: block-map ( fileblock -- diskblock ) - \ Direct block? - dup ndaddr < if ( fileblock ) - cur-inode di_db ( arr-indx arr-start ) - swap la+ l@ exit ( diskblock ) - then ( fileblock ) - ndaddr - ( fileblock' ) - \ Now we need to check the indirect block - dup sb-buf fs_nindir l@ < if ( fileblock' ) - cur-inode di_ib l@ dup ( fileblock' indir-block indir-block ) - indir-addr <> if ( fileblock' indir-block ) - to indir-addr ( fileblock' ) - indir-block ( fileblock' indir-block ) - sb-buf dup fs_bsize l@ ( fileblock' indir-block fs fs_bsize ) - swap indir-addr swap ( fileblock' indir-block fs_bsize indiraddr fs ) - fsbtodb ( fileblock' indir-block fs_bsize db ) - strategy ( fileblock' nread ) - then ( fileblock' nread|indir-block ) - drop \ Really should check return value - indir-block swap la+ l@ exit +\ Get the disk address from a single indirect block +: ib@ ( indx indir.lo indir.hi -- db.lo db.hi ) + 2dup indir-addr d@ d<> if ( indx indir.hi indir.lo ) + indir-addr d! ( indx ) + indir-block ( indx indir-block ) + sb-buf fs-bsize l@ ( indx indir-block fs fs-bsize ) + indir-addr d@ sb-buf ( indx indir-block fs-bsize indiraddr fs ) + fsbtodb ( indx indir-block fs-bsize db.lo db.hi ) + strategy 0 ( indx nread 0 ) \ Really should check return value + then + 2drop ( indx ) + indir-block ib-ib@ +; + + +: block-map ( fileblock -- diskblock.lo diskblock.hi ) + \ Direct block? + dup ndaddr < if ( fileblock ) + cur-inode di-db@ exit ( diskblock.lo diskblock.hi ) + then ( fileblock ) + ndaddr - ( fileblock' ) + \ Now we need to check the indirect block + dup sb-buf fs_nindir l@ < if ( fileblock' ) + 0 cur-inode di-ib@ ( fileblock' indir.lo indir.hi ) + ib@ exit ( db.lo db.hi ) then dup sb-buf fs_nindir - ( fileblock'' ) \ Now try 2nd level indirect block -- just read twice - dup sb-buf fs_nindir l@ dup * < if ( fileblock'' ) - cur-inode di_ib 1 la+ l@ ( fileblock'' indir2-block ) - to indir-addr ( fileblock'' ) - \ load 1st level indir block - indir-block ( fileblock'' indir-block ) - sb-buf dup fs_bsize l@ ( fileblock'' indir-block fs fs_bsize ) - swap indir-addr swap ( fileblock'' indir-block fs_bsize indiraddr fs ) - fsbtodb ( fileblock'' indir-block fs_bsize db ) - strategy ( fileblock'' nread ) - drop ( fileblock'' ) - dup sb-buf fs_nindir / ( fileblock'' indir-offset ) - indir-block swap la+ l@ ( fileblock'' indirblock ) - to indir-addr ( fileblock'' ) - \ load 2nd level indir block - indir-block ( fileblock'' indir-block ) - sb-buf dup fs_bsize l@ ( fileblock'' indir-block fs fs_bsize ) - swap indir-addr swap ( fileblock'' indir-block fs_bsize indiraddr fs ) - fsbtodb ( fileblock'' indir-block fs_bsize db ) - strategy ( fileblock'' nread ) - drop ( fileblock'' ) - sb-buf fs_nindir l@ mod indir-block swap la+ l@ exit + dup sb-buf fs_nindir l@ dup * >= if ( fileblock'' ) + ." block-map: exceeded max file size" cr + abort then - ." block-map: exceeded max file size" cr - abort + + 1 cur-inode di-ib@ ( fileblock'' ib.lo ib.hi ) + + \ Get 1st indirect block and find the 2nd indirect block + rot dup sb-buf fs_nindir u/mod ( ib2.lo ib2.hi indx2 indx1 ) + 2swap ib@ ( indx2 ib2.lo ib2.hi ) + + \ Get 2nd indirect block and find our diskblock + ib@ ( db.lo db.hi ) ; \ @@ -281,71 +394,228 @@ \ 0 value cur-block \ allocated dynamically in ufs-open -0 value cur-blocksize \ size of cur-block --1 value cur-blockno -0 value cur-offset - -: buf-read-file ( fs -- len buf ) - cur-offset swap ( seekp fs ) - 2dup blkoff ( seekp fs off ) - -rot 2dup lblkno ( off seekp fs block ) - swap 2dup cur-inode ( off seekp block fs block fs inop ) - swap dblksize ( off seekp block fs size ) - rot dup cur-blockno ( off seekp fs size block block cur ) - <> if ( off seekp fs size block ) - block-map ( off seekp fs size diskblock ) - dup 0= if ( off seekp fs size diskblock ) - over cur-block swap 0 fill ( off seekp fs size diskblock ) - boot-debug? if ." buf-read-file fell off end of file" cr then - else - 2dup sb-buf fsbtodb cur-block -rot strategy ( off seekp fs size diskblock nread ) - rot 2dup <> if " buf-read-file: short read." cr abort then - then ( off seekp fs diskblock nread size ) - nip nip ( off seekp fs size ) - else ( off seekp fs size block block cur ) - 2drop ( off seekp fs size ) - then -\ dup cur-offset + to cur-offset \ Set up next xfer -- not done - nip nip swap - ( len ) - cur-block +0 value cur-blocksize \ size allocated to cur-block +create cur-blockno -1 l, -1 l, \ Current disk block. +-1 value file-blockno \ Current file block no. +0 value file-offset \ Current file offset, max 4GB. + +: buf-read-file ( fs -- buf len ) + >r file-offset ( seek ) + dup l>d r@ lblkno drop ( seek blk ) + dup l>d cur-inode r@ blksize ( seek blk blksize ) + over file-blockno <> if ( seek blk blksize ) + over to file-blockno + swap block-map ( seek blksize fsblk.lo fsblk.hi ) + 2dup or 0= if ( seek blksize fsblk.lo fsblk.hi ) + \ Clear out curblock XXX Why? Idunno. + 2drop dup + cur-block swap erase ( seek blksize ) + boot-debug? if ." buf-read-file reading block 0" cr then + -1 l>d \ Invalid disk block + else + \ Call strategy to load the correct block. + r@ fsbtodb ( seek blksize dblk.lo dblk.hi ) + rot >r cur-block r@ 2over ( seek addr size db.lo db.hi ) + strategy r@ <> if ." buf-read-file: short read." cr abort then + r> -rot ( seek size db.lo db.hi ) + then + \ Save the new current disk block number + cur-blockno d! ( seek size ) + else + nip ( seek size ) + then + \ Now figure out how much we have in the buffer. + swap l>d r> blkoff ( size off.lo off.hi ) + d>l cur-block over + ( size off buf ) + -rot - ( buf siz ) ; \ \ Read inode into cur-inode -- uses cur-block \ -: read-inode ( inode fs -- ) - twiddle ( inode fs -- inode fs ) +: read-inode-ffs ( inode fs -- ) + twiddle + + >r dup r@ ino-to-fsba ( ino fsblk.lo fsblck.hi ) + r@ fsbtodb ( ino dblk.lo dblk.hi ) + 2dup cur-blockno d@ d<> if ( ino dblk.lo dblk.hi ) + \ We need to read the block + cur-block r@ fs-bsize l@ ( ino dblk.lo dblk.hi addr size ) + >r r@ 2over strategy r> <> if ( ino dblk.lo dblk.hi ) + ." read-inode - residual" cr abort + then + 2dup cur-blockno d! ( ino dblk.lo dblk.hi ) + then 2drop ( ino ) - cur-block ( inode fs -- inode fs buffer ) + r> ino-to-fsbo /dino * ( off ) + cur-block + cur-inode /dino move ( ) +; - over ( inode fs buffer -- inode fs buffer fs ) - fs_bsize l@ ( inode fs buffer -- inode fs buffer size ) +: find-inode-sector ( ino fs -- d-dblkno true | false ) + >r r@ lfs_ifile l@ r@ read-inode ( ino ) - 2over ( inode fs buffer size -- inode fs buffer size inode fs ) - 2over ( inode fs buffer size inode fs -- inode fs buffer size inode fs buffer size ) - 2swap tuck ( inode fs buffer size inode fs buffer size -- inode fs buffer size buffer size fs inode fs ) - - ino-to-fsba ( inode fs buffer size buffer size fs inode fs -- inode fs buffer size buffer size fs fsba ) - swap ( inode fs buffer size buffer size fs fsba -- inode fs buffer size buffer size fsba fs ) - fsbtodb ( inode fs buffer size buffer size fsba fs -- inode fs buffer size buffer size db ) - - dup to cur-blockno ( inode fs buffer size buffer size dstart -- inode fs buffer size buffer size dstart ) - strategy ( inode fs buffer size buffer size dstart -- inode fs buffer size nread ) - <> if ." read-inode - residual" cr abort then - dup 2over ( inode fs buffer -- inode fs buffer buffer inode fs ) - ino-to-fsbo ( inode fs buffer -- inode fs buffer buffer fsbo ) - ufs1_dinode_SIZEOF * + ( inode fs buffer buffer fsbo -- inode fs buffer dinop ) - cur-inode ufs1_dinode_SIZEOF move ( inode fs buffer dinop -- inode fs buffer ) - \ clear out the old buffers - drop ( inode fs buffer -- inode fs ) - 2drop + r@ lfs_ifpb l@ u/mod ( rem q ) + + r@ lfs_cleansz l@ + + r@ lfs_segtabsz l@ + ( rem blkno ) + + r@ fs-bsize l@ um* rot /ifile um* d+ ( dseekp ) + + drop to file-offset r@ buf-read-file ( buf len ) + + /ifile < if r> 2drop false exit then ( buf ) + + if_daddr l@ l>d r> fsbtodb ( daddr ) + 2dup lfs_unused_daddr l>d d= if 2drop false then + true +; + +: read-inode-lfs ( inode fs -- ) + twiddle + + >r dup r@ lfs_ifile l@ = if ( ino r: fs ) + r@ lfs_idaddr l@ l>d ( ino d-idaddr ) + r@ fsbtodb ( ino d-db ) + else + dup r@ find-inode-sector 0= abort" Could not find inode sector!" + then ( ino d-db ) + + 2dup cur-blockno d@ d<> if ( ino dblk.lo dblk.hi ) + \ We need to read the block + cur-block r@ fs-bsize l@ ( ino dblk.lo dblk.hi addr size ) + >r r@ 2over strategy r> <> if ( ino dblk.lo dblk.hi ) + ." read-inode - residual" cr abort + then + 2dup cur-blockno d! ( ino dblk.lo dblk.hi ) + then 2drop ( ino ) + + r@ lfs_inopb l@ ( ino cnt ) + swap cur-block begin ( cnt ino p ) + tuck di_inumber l@ over <> ( cnt p ino !found? ) + while ( cnt p ino ) + rot 1- ?dup 0= abort" Could not find inode!" + rot /dino + swap -rot ( cnt ino p ) + repeat swap ( cnt ino p ) + + cur-inode /dino move ( cnt ino ) + + r> 3drop ; \ Identify inode type -: is-dir? ( ufs1_dinode -- true:false ) di_mode w@ ifmt and ifdir = ; -: is-symlink? ( ufs1_dinode -- true:false ) di_mode w@ ifmt and iflnk = ; +: is-dir? ( ufs1_dinode -- is-dir? ) di-mode w@ ifmt and ifdir = ; +: is-symlink? ( ufs1_dinode -- is-symlink? ) di-mode w@ ifmt and iflnk = ; + +\ +\ Multi-FS initialiation. +\ +\ It's way down here so all the fs-specific routines have already been defined. +\ + +: init-ffs-common ( -- ) + ' fs_SIZEOF to fs-size + ' fs_bsize to fs-bsize + ' ffs-dblksize to blksize + ' read-inode-ffs to read-inode + ' ffs-fsbtodb to fsbtodb + ' ffs-lblkno to lblkno + ' ffs-blkoff to blkoff +; + + +: ffs-oldcompat ( -- ) + \ Make sure old ffs values in sb-buf are sane + sb-buf fs_old_npsect dup l@ sb-buf fs_old_nsect l@ max swap l! + sb-buf fs_old_interleave dup l@ 1 max swap l! + sb-buf fs_old_postblformat l@ fs_42postblfmt = if + 8 sb-buf fs_old_nrpos l! + then + sb-buf fs_old_inodefmt l@ fs_44inodefmt < if + sb-buf fs-bsize l@ + dup ndaddr um* 1 d- sb-buf fs_maxfilesize d! + niaddr 0 ?do + sb-buf fs_nindir l@ * dup ( sizebp sizebp ) + sb-buf fs_maxfilesize dup d@ ( sizebp sizebp *mxfs mxfs.lo mxfs.hi ) + 2over drop l>d d+ 2swap d! ( sizebp ) + loop drop ( ) + sb-buf dup fs_bmask l@ invert l>d rot fs_qbmask d! + sb-buf dup fs_fmask l@ invert l>d rot fs_qfmask d! + then +; + + +: init-ffs-v1 ( -- ) + init-ffs-common + ' di1_size to di-size + ' di1_mode to di-mode + ' ufs1_dinode_SIZEOF to /dino + ' cgstart-ufs1 to cgstart + ' di-db-v1@ to di-db@ + ' di-ib-v1@ to di-ib@ + ' ib-ib-v1@ to ib-ib@ + ffs-oldcompat +; + +: init-ffs-v2 ( -- ) + init-ffs-common + ' di2_size to di-size + ' di2_mode to di-mode + ' ufs2_dinode_SIZEOF to /dino + ' cgbase to cgstart + ' di-db-v2@ to di-db@ + ' di-ib-v2@ to di-ib@ + ' ib-ib-v2@ to ib-ib@ +; + +: init-lfs-common ( -- ) + ' dlfs_SIZEOF to fs-size + ' di1_size to di-size + ' di1_mode to di-mode + ' ufs1_dinode_SIZEOF to /dino + ' cgbase to cgstart + ' di-db-v1@ to di-db@ + ' di-ib-v1@ to di-ib@ + ' ib-ib-v1@ to ib-ib@ + ' lfs-dblksize to blksize + ' read-inode-lfs to read-inode + ' lfs-fsbtodb to fsbtodb + ' lfs-lblkno to lblkno + ' lfs-blkoff to blkoff +; + +: init-lfs-v1 ( -- ) + init-lfs-common + ' lfs_ibsize to fs-bsize + ' ifile_v1_SIZEOF to /ifile + ' if1_daddr to if_daddr +; + +: init-lfs-v2 ( -- ) + init-lfs-common + ' lfs_bsize to fs-bsize + ' ifile_SIZEOF to /ifile + ' if2_daddr to if_daddr +; + + +: fs-magic? ( sb -- is-ufs? ) + \ The LFS magic is the first word in the superblock + dup lfs_magic l@ lfs_magic_value = if + dup lfs_version l@ case ( sb sel ) + 1 of init-lfs-v1 drop true exit endof + 2 of init-lfs-v2 drop true exit endof + ." Invalid LFS version." \ Try FFS. + endcase + then ( sb ) + \ The FFS magic is at the end of the superblock + fs_magic l@ case + fs1_magic_value of init-ffs-v1 true endof + fs2_magic_value of init-ffs-v2 true endof + false swap \ Return false + endcase +; @@ -360,61 +630,52 @@ \ until no buffers \ -: search-directory ( str len -- ino|0 ) - 0 to cur-offset - begin cur-offset cur-inode di_size x@ < while ( str len ) - sb-buf buf-read-file ( str len len buf ) - over 0= if ." search-directory: buf-read-file zero len" cr abort then - swap dup cur-offset + to cur-offset ( str len buf len ) - 2dup + nip ( str len buf bufend ) - swap 2swap rot ( bufend str len buf ) - begin dup 4 pick < while ( bufend str len buf ) - dup d_ino l@ 0<> if ( bufend str len buf ) - boot-debug? if dup dup d_name swap d_namlen c@ type cr then - 2dup d_namlen c@ = if ( bufend str len buf ) - dup d_name 2over ( bufend str len buf dname str len ) - comp 0= if ( bufend str len buf ) - \ Found it -- return inode - d_ino l@ nip nip nip ( dino ) - boot-debug? if ." Found it" cr then - exit ( dino ) - then - then ( bufend str len buf ) - then ( bufend str len buf ) - dup d_reclen w@ + ( bufend str len nextbuf ) - repeat - drop rot drop ( str len ) - repeat - 2drop 2drop 0 ( 0 ) -; - -: ffs_oldcompat ( -- ) -\ Make sure old ffs values in sb-buf are sane - sb-buf fs_old_npsect dup l@ sb-buf fs_old_nsect l@ max swap l! - sb-buf fs_old_interleave dup l@ 1 max swap l! - sb-buf fs_old_postblformat l@ fs_42postblfmt = if - 8 sb-buf fs_old_nrpos l! - then - sb-buf fs_old_inodefmt l@ fs_44inodefmt < if - sb-buf fs_bsize l@ - dup ndaddr * 1- sb-buf fs_maxfilesize x! - niaddr 0 ?do - sb-buf fs_nindir l@ * dup ( sizebp sizebp -- ) - sb-buf fs_maxfilesize dup x@ ( sizebp sizebp *fs_maxfilesize fs_maxfilesize -- ) - rot ( sizebp *fs_maxfilesize fs_maxfilesize sizebp -- ) - + ( sizebp *fs_maxfilesize new_fs_maxfilesize -- ) - swap x! ( sizebp -- ) - loop drop ( -- ) - sb-buf dup fs_bmask l@ not swap fs_qbmask x! - sb-buf dup fs_fmask l@ not swap fs_qfmask x! - then +: search-dir-block ( str len buf len -- ino | 0 ) + 2dup + nip ( str len buf bufend ) + swap 2swap rot ( bufend str len direct ) + begin dup 4 pick < while ( bufend str len direct ) + dup d_ino l@ 0<> if ( bufend str len direct ) + boot-debug? if + \ Print the current file name + dup dup d_name swap d_namlen c@ type cr + then + 2dup d_namlen c@ = if ( bufend str len direct ) + dup d_name 2over ( bufend str len direct dname str len ) + comp 0= if ( bufend str len direct ) + \ Found it -- return inode + d_ino l@ nip nip nip ( dino ) + boot-debug? if ." Found it" cr then + exit ( dino ) + then + then ( bufend str len direct ) + then ( bufend str len direct ) + dup d_reclen w@ + ( bufend str len nextdirect ) + repeat + 2drop 2drop 0 +; + + +: search-directory ( str len -- ino | 0 ) + 0 to file-offset + begin + file-offset cur-inode di-size d@ drop < + while ( str len ) + \ Read a directory block + sb-buf buf-read-file ( str len buf len ) + dup 0= if ." search-directory: buf-read-file zero len" cr abort then + dup file-offset + to file-offset ( str len buf len ) + + 2over 2swap search-dir-block ?dup if + \ Found it + nip nip exit + then ( str len ) + repeat + 2drop 2drop 0 ( 0 ) ; : read-super ( sector -- ) -0 " seek" boot-ihandle $call-method - -1 = if - ." Seek failed" cr - abort + 0 " seek" boot-ihandle $call-method -1 = if + ." Seek failed" cr abort then sb-buf sbsize " read" boot-ihandle $call-method dup sbsize <> if @@ -427,74 +688,63 @@ then ; -: ufs-open ( bootpath,len -- ) +: ufs-open ( bootpath len -- ) boot-ihandle -1 = if - over cif-open dup 0= if ( boot-path len ihandle? ) - ." Could not open device" space type cr - abort + 2dup + 0 swap c! \ Nul terminate. + over cif-open dup 0= if ( boot-path len ihandle? ) + ." Could not open device" space type cr + abort then ( boot-path len ihandle ) - to boot-ihandle \ Save ihandle to boot device - then 2drop - force-raid if - boot-debug? if ." Force RAID superblock read" cr then - rf_protected dup to raid-offset - dev_bsize * sboff + read-super - sb-buf fs_magic l@ fs_magic_value <> if - ." Invalid superblock magic" cr - abort - then - else - boot-debug? if ." Normal superblock read" cr then + to boot-ihandle \ Save ihandle to boot device + then + 2drop + + boot-debug? if ." Try a RAID superblock read" cr then + rf_protected dup to raid-offset + dev_bsize * sboff + read-super + sb-buf fs-magic? invert if + boot-debug? if ." Try a normal superblock read" cr then + 0 to raid-offset sboff read-super - sb-buf fs_magic l@ fs_magic_value <> if - boot-debug? if ." RAID superblock read" cr then - true to force-raid - rf_protected dup to raid-offset - dev_bsize * sboff + read-super - sb-buf fs_magic l@ fs_magic_value <> if - ." Invalid superblock magic" cr - abort - then - then + sb-buf fs-magic? invert abort" Invalid superblock magic" then - sb-buf fs_bsize l@ dup maxbsize > if + sb-buf fs-bsize l@ dup maxbsize > if ." Superblock bsize" space . ." too large" cr abort then - dup fs_SIZEOF < if + dup fs-size < if ." Superblock bsize < size of superblock" cr abort then - ffs_oldcompat ( fs_bsize -- fs_bsize ) - dup to cur-blocksize alloc-mem to cur-block \ Allocate cur-block - boot-debug? if ." ufs-open complete" cr then + dup to cur-blocksize alloc-mem to cur-block \ Allocate cur-block + boot-debug? if ." ufs-open complete" cr then ; : ufs-close ( -- ) - boot-ihandle dup -1 <> if - cif-close -1 to boot-ihandle - then - cur-block 0<> if - cur-block cur-blocksize free-mem - then + boot-ihandle dup -1 <> if + cif-close -1 to boot-ihandle + then + cur-block 0<> if + cur-block cur-blocksize free-mem + then ; : boot-path ( -- boot-path ) - " bootpath" chosen-phandle get-package-property if - ." Could not find bootpath in /chosen" cr - abort - else - decode-string 2swap 2drop - then + " bootpath" chosen-phandle get-package-property if + ." Could not find bootpath in /chosen" cr + abort + else + decode-string 2swap 2drop + then ; : boot-args ( -- boot-args ) - " bootargs" chosen-phandle get-package-property if - ." Could not find bootargs in /chosen" cr - abort - else - decode-string 2swap 2drop - then + " bootargs" chosen-phandle get-package-property if + ." Could not find bootargs in /chosen" cr + abort + else + decode-string 2swap 2drop + then ; 2000 buffer: boot-path-str @@ -502,152 +752,123 @@ : split-path ( path len -- right len left len ) \ Split a string at the `/' - begin - dup -rot ( oldlen right len left ) - ascii / left-parse-string ( oldlen right len left len ) - dup 0<> if 4 roll drop exit then - 2drop ( oldlen right len ) - rot over = ( right len diff ) - until + begin + dup -rot ( oldlen right len left ) + ascii / left-parse-string ( oldlen right len left len ) + dup 0<> if 4 roll drop exit then + 2drop ( oldlen right len ) + rot over = ( right len diff ) + until ; : find-file ( load-file len -- ) - rootino dup sb-buf read-inode ( load-file len -- load-file len ino ) - -rot ( load-file len ino -- pino load-file len ) - \ - \ For each path component - \ - begin split-path dup 0<> while ( pino right len left len -- ) - cur-inode is-dir? not if ." Inode not directory" cr false exit then - boot-debug? if ." Looking for" space 2dup type space ." in directory..." cr then - search-directory ( pino right len left len -- pino right len ino|false ) - dup 0= if ." Bad path" cr abort then ( pino right len cino ) - sb-buf read-inode ( pino right len ) - cur-inode is-symlink? if \ Symlink -- follow the damn thing - \ Save path in boot-path-tmp - boot-path-tmp strmov ( pino new-right len ) - - \ Now deal with symlink - cur-inode di_size x@ ( pino right len linklen ) - dup sb-buf fs_maxsymlinklen l@ ( pino right len linklen linklen maxlinklen ) - < if \ Now join the link to the path - cur-inode di_db l@ ( pino right len linklen linkp ) - swap boot-path-str strmov ( pino right len new-linkp linklen ) - else \ Read file for symlink -- Ugh - \ Read link into boot-path-str - boot-path-str dup sb-buf fs_bsize l@ - 0 block-map ( pino right len linklen boot-path-str bsize blockno ) - strategy drop swap ( pino right len boot-path-str linklen ) - then ( pino right len linkp linklen ) - \ Concatenate the two paths - strcat ( pino new-right newlen ) - swap dup c@ ascii / = if \ go to root inode? - rot drop rootino -rot ( rino len right ) - then - rot dup sb-buf read-inode ( len right pino ) - -rot swap ( pino right len ) - then ( pino right len ) - repeat - 2drop drop - true -; - -: read-file ( size addr -- ) - \ Read x bytes from a file to buffer - begin over 0> while - cur-offset cur-inode di_size x@ > if ." read-file EOF exceeded" cr abort then - sb-buf buf-read-file ( size addr len buf ) - over 2over drop swap ( size addr len buf addr len ) - move ( size addr len ) - dup cur-offset + to cur-offset ( size len newaddr ) - tuck + ( size len newaddr ) - -rot - swap ( newaddr newsize ) - repeat - 2drop + rootino dup sb-buf read-inode ( load-file len pino ) + -rot ( pino load-file len ) + \ + \ For each path component + \ + begin split-path dup 0<> while ( pino right len left len ) + cur-inode is-dir? not if ." Inode not directory" cr abort then + boot-debug? if ." Looking for" space 2dup type space ." in directory..." cr then + search-directory ( pino right len ino|false ) + dup 0= abort" Bad path" ( pino right len cino ) + sb-buf read-inode ( pino right len ) + cur-inode is-symlink? if \ Symlink -- follow the damn thing + \ Save path in boot-path-tmp + boot-path-tmp strmov ( pino new-right len ) + + \ Now deal with symlink XXX drop high word of linklen + cur-inode di-size d@ drop ( pino right len linklen.lo ) + dup sb-buf fs_maxsymlinklen l@ ( pino right len linklen linklen maxlinklen ) + < if \ Now join the link to the path + 0 cur-inode di-db@ drop ( pino right len linklen linkp ) + swap boot-path-str strmov ( pino right len new-linkp linklen ) + else \ Read file for symlink -- Ugh + \ Read link into boot-path-str + boot-path-str dup sb-buf fs-bsize l@ + 0 block-map ( pino right len linklen boot-path-str bsize blockno.lo blockno.hi ) + strategy drop swap ( pino right len boot-path-str linklen ) + then ( pino right len linkp linklen ) + \ Concatenate the two paths + strcat ( pino new-right newlen ) + swap dup c@ ascii / = if \ go to root inode? + rot drop rootino -rot ( rino len right ) + then + rot dup sb-buf read-inode ( len right pino ) + -rot swap ( pino right len ) + then ( pino right len ) + repeat + 2drop drop +; + +: .read-file-msg ( addr xxx siz -- addr xxx siz ) + boot-debug? if + ." Copying " dup . ." bytes to " 3 pick . cr + then +; + +: read-file ( addr size -- ) + noop \ In case we need to debug this + \ Read x bytes from a file to buffer + begin dup 0> while + file-offset cur-inode di-size d@ drop > if + ." read-file EOF exceeded" cr abort + then + sb-buf buf-read-file ( addr size buf len ) + + .read-file-msg + + \ Copy len bytes to addr XXX min ( len, size ) ? + 2over drop 3dup swap move drop ( addr size buf len ) + + dup file-offset + to file-offset ( addr size buf len ) + + nip tuck - -rot + swap ( addr' size' ) + repeat + 2drop ; -\ -\ According to the 1275 addendum for SPARC processors: -\ Default load-base is 0x4000. At least 0x8.0000 or -\ 512KB must be available at that address. -\ -\ The Fcode bootblock can take up up to 8KB (O.K., 7.5KB) -\ so load programs at 0x4000 + 0x2000=> 0x6000 -\ - -h# 6000 constant loader-base - -\ -\ Elf support -- find the load addr -\ - -: is-elf? ( hdr -- res? ) h# 7f454c46 = ; - -\ -\ Finally we finish it all off -\ +" load-base " evaluate constant loader-base : load-file-signon ( load-file len boot-path len -- load-file len boot-path len ) ." Loading file" space 2over type cr ." from device" space 2dup type cr ; -: load-file-print-size ( size -- size ) - ." Loading" space dup . space ." bytes of file..." cr -; - : load-file ( load-file len boot-path len -- load-base ) - boot-debug? if load-file-signon then - the-file file_SIZEOF 0 fill \ Clear out file structure - \ copy "load-file len boot-path len" in case we need to set "force-raid" - 2over 2over ( load-file len boot-path len load-file len boot-path len ) - ufs-open ( load-file len boot-path len load-file len ) - find-file not if ( load-file len boot-path len ) - force-raid not if - true to force-raid ( ) - ufs-close - 2drop 2drop drop ( load-file len boot-path len ) - ufs-open ( load-file len ) - find-file ( true:false ) - drop - else - abort - then - else - \ We didn't set "force-raid", discard the copies - 2drop 2drop ( ) - then - - \ - \ Now we've found the file we should read it in in one big hunk - \ - - cur-inode di_size x@ ( file-len ) - dup " to file-size" evaluate ( file-len ) - boot-debug? if load-file-print-size then - 0 to cur-offset - loader-base ( buf-len addr ) - 2dup read-file ( buf-len addr ) - ufs-close ( buf-len addr ) - dup is-elf? if ." load-file: not an elf executable" cr abort then - - \ Luckily the prom should be able to handle ELF executables by itself + boot-debug? if load-file-signon then + + ufs-open ( load-file len ) + find-file ( ) - nip ( addr ) + \ + \ Now we've found the file we should read it in in one big hunk + \ + + cur-inode di-size d@ if ." File len >2GB!" cr abort then +\ dup " to file-size " evaluate ( file-len ) \ Wassthis? + boot-debug? if + ." Loading " dup . ." bytes of file..." cr + then + 0 to file-offset + -1 to file-blockno + loader-base ( buf-len addr ) + tuck swap read-file ( addr ) + ufs-close ( addr ) ; : do-boot ( bootfile -- ) - ." NetBSD IEEE 1275 Bootblock" cr - boot-path load-file ( -- load-base ) - dup 0<> if " to load-base init-program" evaluate then -; + ." NetBSD IEEE 1275 Multi-FS Bootblock" cr + boot-path load-file ( -- load-base ) + dup 0<> if " init-program " evaluate then +; -boot-args ascii V strchr 0<> swap drop if - true to boot-debug? +boot-args ascii V strchr 0<> swap drop if + true to boot-debug? then -boot-args ascii D strchr 0= swap drop if - " /ofwboot" do-boot -then exit +boot-args ascii D strchr 0= swap drop if + " /ofwboot" do-boot +then exit Index: src/sys/arch/sparc/stand/bootblk/genfth.cf diff -u src/sys/arch/sparc/stand/bootblk/genfth.cf:1.6 src/sys/arch/sparc/stand/bootblk/genfth.cf:1.7 --- src/sys/arch/sparc/stand/bootblk/genfth.cf:1.6 Fri May 2 18:11:05 2008 +++ src/sys/arch/sparc/stand/bootblk/genfth.cf Sat Feb 13 23:38:17 2010 @@ -1,4 +1,4 @@ -# $NetBSD: genfth.cf,v 1.6 2008/05/02 18:11:05 martin Exp $ +# $NetBSD: genfth.cf,v 1.7 2010/02/13 23:38:17 eeh Exp $ # # Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -132,10 +132,20 @@ # ufs1 dinode # struct ufs1_dinode -member di_size -member di_mode -member di_db -member di_ib +member di1_size di_size +member di1_mode di_mode +member di1_db di_db +member di1_ib di_ib +member di_inumber di_inumber + +# +# ufs2 dinode +# +struct ufs2_dinode +member di2_size di_size +member di2_mode di_mode +member di2_db di_db +member di2_ib di_ib # # ufs direct @@ -147,7 +157,8 @@ member d_namlen member d_name -define fs_magic_value FS_UFS1_MAGIC +define fs1_magic_value FS_UFS1_MAGIC +define fs2_magic_value FS_UFS2_MAGIC define fs_42postblfmt FS_42POSTBLFMT define fs_44inodefmt FS_44INODEFMT define ndaddr NDADDR Added files: Index: src/sys/arch/sparc/stand/bootblk/genlfs.cf diff -u /dev/null src/sys/arch/sparc/stand/bootblk/genlfs.cf:1.1 --- /dev/null Sat Feb 13 23:38:17 2010 +++ src/sys/arch/sparc/stand/bootblk/genlfs.cf Sat Feb 13 23:38:17 2010 @@ -0,0 +1,77 @@ +# $NetBSD: genlfs.cf,v 1.1 2010/02/13 23:38:17 eeh Exp $ + +# Copyright (c) 2010 Eduardo Horvath. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +include <sys/param.h> +include <sys/time.h> +include <ufs/ufs/dinode.h> +include <ufs/ufs/dir.h> +include <sys/queue.h> +include <sys/condvar.h> +include <sys/mount.h> +include <ufs/ufs/inode.h> +include <ufs/lfs/lfs.h> + +# +# lfs superblock +# +struct dlfs +member lfs_magic dlfs_magic +member lfs_version dlfs_version +member lfs_bsize dlfs_bsize +member lfs_ibsize dlfs_ibsize +member lfs_bmask dlfs_bmask +member lfs_ffmask dlfs_ffmask +member lfs_bshift dlfs_bshift +member lfs_ffshift dlfs_ffshift +member lfs_fbshift dlfs_fbshift +member lfs_fsbtodb dlfs_fsbtodb +member lfs_ifile dlfs_ifile +member lfs_ifpb dlfs_ifpb +member lfs_cleansz dlfs_cleansz +member lfs_segtabsz dlfs_segtabsz +member lfs_idaddr dlfs_idaddr +member lfs_inopb dlfs_inopb + +# +# LFS v1 ifile +# +struct ifile_v1 +member if1_version if_version +member if1_daddr if_daddr + +# +# LFS v2 ifile +# +struct ifile +member if2_version if_version +member if2_daddr if_daddr + +# +# the dinode is the same as ffs v1 +# + +define lfs_magic_value LFS_MAGIC +define lfs_unused_daddr LFS_UNUSED_DADDR