summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2020-04-02 06:06:22 +0000
committerotto <otto@openbsd.org>2020-04-02 06:06:22 +0000
commit973ae9bb5cccd0229f2be6f51e78276171db2025 (patch)
treeeef0b94f8f5d3cdc917f83be6dd6bb9bf41bc63f
parentAdd a W position to display-menu -y to use the line above (or below) the (diff)
downloadwireguard-openbsd-973ae9bb5cccd0229f2be6f51e78276171db2025.tar.xz
wireguard-openbsd-973ae9bb5cccd0229f2be6f51e78276171db2025.zip
Change bootblocks to be able to read from ffs1, ffs2 and softraid.
ffs2 part from eeh at netbsd. ok deraadt@
-rw-r--r--sys/arch/sparc64/stand/bootblk/Makefile22
-rw-r--r--sys/arch/sparc64/stand/bootblk/bootblk.fth892
-rw-r--r--sys/arch/sparc64/stand/bootblk/genassym.sh142
-rw-r--r--sys/arch/sparc64/stand/bootblk/genfth.cf47
4 files changed, 657 insertions, 446 deletions
diff --git a/sys/arch/sparc64/stand/bootblk/Makefile b/sys/arch/sparc64/stand/bootblk/Makefile
index 2e9f18b4319..2c4d2589ce6 100644
--- a/sys/arch/sparc64/stand/bootblk/Makefile
+++ b/sys/arch/sparc64/stand/bootblk/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.14 2017/10/17 19:31:56 naddy Exp $
+# $OpenBSD: Makefile,v 1.15 2020/04/02 06:06:22 otto Exp $
# $NetBSD: Makefile,v 1.1 2000/08/20 14:58:45 mrg Exp $
CURDIR= ${.CURDIR}
@@ -8,8 +8,8 @@ S= ${CURDIR}/../../../..
# Override normal settings
#
-CLEANFILES= assym.fth.h assym.fth.h.tmp machine \
- bootblk bootblk.text bootblk.text.tmp
+CLEANFILES= machine ffs.fth.h \
+ bootblk bootblk.text bootblk.text.tmp -.d
NOMAN=
STRIPFLAG=
@@ -26,17 +26,17 @@ CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM}
all: bootblk.text bootblk
-assym.fth.h: ${.CURDIR}/genassym.sh genfth.cf
- sh ${.CURDIR}/genassym.sh ${CC} ${CFLAGS} \
- ${CPPFLAGS} ${PROF} <${.CURDIR}/genfth.cf >assym.fth.h.tmp && \
- mv -f assym.fth.h.tmp assym.fth.h
+ffs.fth.h: ${.CURDIR}/genassym.sh genfth.cf
+ sh ${.CURDIR}/genassym.sh -f ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} \
+ < ${.CURDIR}/genfth.cf >ffs.fth.h.tmp && \
+ mv -f ffs.fth.h.tmp ffs.fth.h
-bootblk.text: bootblk.fth assym.fth.h
- awk '/fload/ { file=$$2; while ((ret = getline <file) == 1) print; close(file); if (ret == -1) print "unable to read " file >"/dev/stderr"; next }; !/fload/' \
- ${.CURDIR}/bootblk.fth >bootblk.text.tmp && \
+bootblk.text: bootblk.fth ffs.fth.h
+ 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
fgen -o bootblk ${.CURDIR}/bootblk.fth
beforeinstall:
diff --git a/sys/arch/sparc64/stand/bootblk/bootblk.fth b/sys/arch/sparc64/stand/bootblk/bootblk.fth
index d64f0ecdb04..5672643dfe8 100644
--- a/sys/arch/sparc64/stand/bootblk/bootblk.fth
+++ b/sys/arch/sparc64/stand/bootblk/bootblk.fth
@@ -1,12 +1,12 @@
-\ $OpenBSD: bootblk.fth,v 1.8 2014/11/26 19:57:41 stsp Exp $
-\ $NetBSD: bootblk.fth,v 1.3 2001/08/15 20:10:24 eeh Exp $
+\ $OpenBSD: bootblk.fth,v 1.9 2020/04/02 06:06:22 otto Exp $
+\ $NetBSD: bootblk.fth,v 1.15 2015/08/20 05:40:08 dholland 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
@@ -17,11 +17,6 @@
\ 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.
-\ 3. All advertising materials mentioning features or use of this software
-\ must display the following acknowledgement:
-\ This product includes software developed by Eduardo Horvath.
-\ 4. The name of the author may not be used to endorse or promote products
-\ derived from this software without specific prior written permission
\
\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -41,6 +36,8 @@ headers
false value boot-debug?
+: KB d# 1024 * ;
+
\
\ First some housekeeping: Open /chosen and set up vectors into
\ client-services
@@ -61,15 +58,15 @@ defer cif-seek ( low high ihandle -- -1|0|1 )
\ 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.
@@ -77,8 +74,53 @@ defer cif-seek ( low high ihandle -- -1|0|1 )
\ 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
+ ?dup if \ Shifting by 0 doesn't appear to work properly.
+ 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 +
+ then
+;
+: d>> ( d1 n -- d1>>n ) \ Hope this works
+ ?dup if \ Shifting by 0 doesn't appear to work properly.
+ rot over >> -rot ( d.lo' d.hi n )
+ 2dup >> -rot ( d.lo' d.hi' d.hi n )
+ d# 32 swap - << rot + swap
+ then
+;
+: 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=
;
@@ -118,166 +160,206 @@ defer cif-seek ( low high ihandle -- -1|0|1 )
;
\
-\ BSD FFS parameters
+\ BSD UFS parameters
\
-fload assym.fth.h
+fload ffs.fth.h
sbsize buffer: sb-buf
-1 value boot-ihandle
dev_bsize value bsize
-: strategy ( addr size start -- nread )
- bsize * 0 " seek" boot-ihandle $call-method
- -1 = if
- ." strategy: Seek failed" cr
- abort
- then
- " read" boot-ihandle $call-method
+: strategy ( addr size db.lo db.hi -- nread )
+ 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
;
+
\
-\ Cylinder group macros
+\ Multi-FS support
+\
+\ XXX Maybe the different filesystems should be segregated into separate files
+\ XXX that are individually loaded.
\
-: cgbase ( cg fs -- cgbase ) fs_fpg l@ * ;
-: cgstart ( cg fs -- cgstart )
- 2dup fs_cgmask l@ not and ( cg fs stuff -- )
- over fs_cgoffset l@ * -rot ( stuffcg fs -- )
- cgbase +
-;
-: 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 + ;
+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
\
-\ Block and frag position macros
+\ FFS Cylinder group macros
\
-: 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 )
-;
+: 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 ) \ Need to remove the stupid stack diags someday
+: 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 )
- -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@ << ;
+ 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<<
+;
+\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\
-\ File stuff
+\ The rest of the multi-filesystem stuff
\
+\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-niaddr /w* constant narraysize
+\
+\ 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_cgmask l@ invert and ( cg fs stuff )
+ over fs_cgoffset l@ um* ( cg fs off.lo off.hi )
+ 2swap cgbase d+ ( off.lo off.hi )
+;
+
+\
+\ FFS v2
+\
-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
+: 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@ ;
-file_SIZEOF buffer: the-file
-sb-buf the-file >f_fs x!
+\
+\ LFS v1
+\
+
+
+\
+\ File stuff
+\
+
+niaddr /w* constant narraysize
-ufs1_dinode_SIZEOF buffer: cur-inode
-h# 2000 buffer: indir-block
--1 value indir-addr
+\ Assume UFS2 dinodes are always biger than UFS1
+ufs2_dinode_SIZEOF buffer: cur-inode
+0 value indir-block
+create indir-addr -1 , -1 ,
\
\ Translate a fileblock to a disk block
\
-\ We only allow single indirection
-\
-
-: 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
+\ We don't do triple indirect blocks.
+\
+
+\ 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 )
;
\
@@ -285,71 +367,141 @@ h# 2000 buffer: indir-block
\
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 )
+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
-\ dup cur-offset + to cur-offset \ Set up next xfer -- not done
- nip nip swap - ( len )
- cur-block
+ \ 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 )
+
+ r> ino-to-fsbo /dino * ( off )
+ cur-block + cur-inode /dino move ( )
+;
- cur-block ( inode fs -- inode fs buffer )
+\ Identify inode type
- over ( inode fs buffer -- inode fs buffer fs )
- fs_bsize l@ ( inode fs buffer -- inode fs buffer size )
+: is-dir? ( ufs1_dinode -- is-dir? ) di-mode w@ ifmt and ifdir = ;
+: is-symlink? ( ufs1_dinode -- is-symlink? ) di-mode w@ ifmt and iflnk = ;
- 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 )
+\
+\ Multi-FS initialiation.
+\
+\ It's way down here so all the fs-specific routines have already been defined.
+\
- 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 )
+: 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
+;
- 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
+
+: ffs-oldcompat ( -- )
+ \ Make sure old ffs values in sb-buf are sane
+ sb-buf fs_npsect dup l@ sb-buf fs_nsect l@ max swap l!
+ sb-buf fs_interleave dup l@ 1 max swap l!
+ sb-buf fs_postblformat l@ fs_42postblfmt = if
+ 8 sb-buf fs_nrpos l!
+ then
+ sb-buf fs_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
;
-\ Identify inode type
-: is-dir? ( dinode -- true:false ) di_mode w@ ifmt and ifdir = ;
-: is-symlink? ( dinode -- true:false ) di_mode w@ ifmt and iflnk = ;
+: init-ffs-v1 ( -- )
+ boot-debug? if ." FFS v1" cr then
+ 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 ( -- )
+ boot-debug? if ." FFS v2" cr then
+ 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@
+;
+
+: fs-magic? ( sb -- is-ufs? )
+ \ The FFS magic is at the end of the superblock
+ \ XXX we should check to make sure this is not an alternate SB.
+ 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
+;
@@ -364,61 +516,52 @@ h# 2000 buffer: indir-block
\ 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 )
+: 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
;
-
-: ffs_oldcompat ( -- )
-\ Make sure old ffs values in sb-buf are sane
- sb-buf fs_npsect dup l@ sb-buf fs_nsect l@ max swap l!
- sb-buf fs_interleave dup l@ 1 max swap l!
- sb-buf fs_postblformat l@ fs_42postblfmt = if
- 8 sb-buf fs_nrpos l!
- then
- sb-buf fs_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-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
@@ -431,47 +574,65 @@ h# 2000 buffer: indir-block
then
;
-: ufs-open ( bootpath,len -- )
- sboff read-super
- sb-buf fs_magic l@ fs_magic_value <> if
- ." Invalid superblock magic" cr
- abort
- then
- sb-buf fs_bsize l@ dup maxbsize > if
+: check-supers ( -- found? )
+ \ Superblocks used to be 8KB into the partition, but ffsv2 changed that.
+ \ See comments in src/sys/ufs/ffs/fs.h
+ \ Put a list of offets to check on the stack, ending with -1
+ -1
+ 0
+ d# 128 KB
+ d# 64 KB
+ 8 KB
+
+ begin dup -1 <> while ( -1 .. off )
+ read-super ( -1 .. )
+ sb-buf fs-magic? if ( -1 .. )
+ begin -1 = until \ Clean out extra stuff from stack
+ true exit
+ then
+ repeat
+ drop false
+;
+
+: ufs-open ( -- )
+ boot-debug? if ." Try superblock read" cr then
+ check-supers 0= abort" Invalid superblock magic"
+ 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
+ cur-blocksize alloc-mem to indir-block
+ boot-debug? if ." ufs-open complete" cr then
;
-: ufs-close ( -- )
- cur-block 0<> if
- cur-block cur-blocksize free-mem
- then
+: ufs-close ( -- )
+ cur-block 0<> if
+ cur-block cur-blocksize free-mem
+ indir-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
@@ -479,114 +640,107 @@ h# 2000 buffer: indir-block
: 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 abort 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_shortlink 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
+ 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 ( 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
+: .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
-
-\
-\ 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
-
+: load-file ( load-file len -- load-base )
+
ufs-open ( load-file len )
- find-file ( )
-
- \
- \ 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 )
-
- \ Luckily the prom should be able to handle ELF executables by itself
-
- nip ( addr )
+ find-file ( load-file len )
+
+ \
+ \ 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 )
;
0 value dev-block \ Buffer for reading device blocks
@@ -596,8 +750,8 @@ h# 6000 constant loader-base
0 value part-type \ Type of 'a' partition.
: read-disklabel ( )
- dev-block dev-blocksize 0 \ LABELSECTOR == 0
- strategy ( buf len start -- nread )
+ dev-block dev-blocksize 0 0 \ LABELSECTOR == 0
+ strategy ( buf len start.lo start.hi -- nread )
dev-blocksize <> if
." Failed to read disklabel" cr
abort
@@ -613,8 +767,9 @@ h# 6000 constant loader-base
: is-bootable-softraid? ( -- softraid? )
part-type fs_raid <> if false exit then
- dev-block dev-blocksize sr_meta_offset
- strategy ( buf len block -- nread )
+ \ XXX
+ dev-block dev-blocksize sr_meta_offset 0
+ strategy ( buf len block.lo block.hi -- nread )
dev-blocksize <> if
." Failed to read softraid metadata" cr
abort
@@ -647,7 +802,8 @@ h# 6000 constant loader-base
\ Load boot loader from softraid boot area
begin over 0> while
- dev-block dev-blocksize dev-blockno
+ \ XXX
+ dev-block dev-blocksize dev-blockno 0
strategy ( size addr buf len start -- nread )
dup dev-blocksize <> if
." softraid-boot: block read failed" cr
@@ -665,7 +821,7 @@ h# 6000 constant loader-base
;
: do-boot ( bootfile -- )
- ." OpenBSD IEEE 1275 Bootblock 1.4" cr
+ ." OpenBSD IEEE 1275 Bootblock 2.0" cr
\ Open boot device
boot-path ( boot-path len )
diff --git a/sys/arch/sparc64/stand/bootblk/genassym.sh b/sys/arch/sparc64/stand/bootblk/genassym.sh
index 2e87f6c57ff..6ca7a09ffa0 100644
--- a/sys/arch/sparc64/stand/bootblk/genassym.sh
+++ b/sys/arch/sparc64/stand/bootblk/genassym.sh
@@ -1,8 +1,7 @@
-# $OpenBSD: genassym.sh,v 1.3 2003/07/02 00:37:31 avsm Exp $
-# $NetBSD: genassym.sh,v 1.1 2000/08/20 14:58:45 mrg Exp $
-
+#!/bin/sh -
+# $OpenBSD: genassym.sh,v 1.4 2020/04/02 06:06:22 otto Exp $
+# $NetBSD: genassym.sh,v 1.8 2014/01/06 22:43:15 christos Exp $
#
-# Copyright (c) 1998 Eduardo E. Horvath.
# Copyright (c) 1997 Matthias Pfaller.
# All rights reserved.
#
@@ -14,11 +13,6 @@
# 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.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by Matthias Pfaller.
-# 4. The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -32,35 +26,78 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-# If first argument is -c, create a temporary C file,
-# compile it and execute the result.
+progname="$(basename "${0}")"
+: ${AWK:=awk}
-awk=${AWK:-awk}
-TMP1=`mktemp /tmp/genassym1.XXXXXXXXXX` || exit 1
-TMP2=`mktemp /tmp/genassym2.XXXXXXXXXX` || {
- rm -f $TMP1
- exit 1
+ccode=0 # generate temporary C file, compile it, execute result
+fcode=0 # generate Forth code
+
+usage()
+{
+
+ echo "usage: ${progname} [-c | -f] -- compiler command" >&2
}
-trap 'rm -f $TMP1 $TMP2' 0 1 2 3 13 15
+set -e
+
+while getopts cf i
+do
+ case "$i" in
+ c)
+ ccode=1
+ ;;
+ f)
+ fcode=1
+ ;;
+ esac
+done
+shift "$(($OPTIND - 1))"
+if [ $# -eq 0 ]; then
+ usage
+ exit 1
+fi
-if [ $1 = '-c' ] ; then
- shift
- ccode=1
-else
- ccode=0
+# Deal with any leading environment settings..
+
+while [ -n "$1" ]
+do
+ case "$1" in
+ *=*)
+ eval export "$1"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+genassym_temp="$(mktemp -d "${TMPDIR-/tmp}/genassym.XXXXXX")"
+
+
+if [ ! -d $genassym_temp ]; then
+ echo "${progname}: unable to create temporary directory" >&2
+ exit 1
fi
+trap "rm -rf $genassym_temp" 0 1 2 3 15
-$awk '
+$AWK '
BEGIN {
- printf("#ifndef _KERNEL\n#define _KERNEL\n#endif\n");
+ printf("#if __GNUC__ >= 4\n");
+ printf("#define offsetof(type, member) __builtin_offsetof(type, member)\n");
+ printf("#else\n");
printf("#define offsetof(type, member) ((size_t)(&((type *)0)->member))\n");
+ printf("#endif\n");
defining = 0;
type = "long";
asmtype = "n";
asmprint = "";
}
+{
+ doing_member = 0;
+}
+
$0 ~ /^[ \t]*#.*/ || $0 ~ /^[ \t]*$/ {
# Just ignore comments and empty lines
next;
@@ -98,6 +135,15 @@ $0 ~ /^endif/ {
# fall through
}
+/^member[ \t]/ {
+ if (NF > 2)
+ $0 = "define " $2 " offsetof(struct " structname ", " $3 ")";
+ else
+ $0 = "define " $2 " offsetof(struct " structname ", " $2 ")";
+ doing_member = 1;
+ # fall through
+}
+
/^export[ \t]/ {
$0 = "define " $2 " " $2;
# fall through
@@ -107,26 +153,7 @@ $0 ~ /^endif/ {
if (defining == 0) {
defining = 1;
printf("void f" FNR "(void);\n");
- printf("void f" FNR "() {\n");
- if (ccode)
- call[FNR] = "f" FNR;
- defining = 1;
- }
- value = $0
- gsub("^define[ \t]+[A-Za-z_][A-Za-z_0-9]*[ \t]+", "", value)
- if (ccode)
- printf("printf(\"#define " $2 " %%ld\\n\", (%s)" value ");\n", type);
- else
- printf("__asm(\"XYZZY d# %%%s0 constant %s\" : : \"%s\" (%s));\n", asmprint, $2, asmtype, value);
- next;
-}
-
-/^member[ \t]/ {
- $0 = "define " $2 " offsetof(struct " structname ", " $2 ")";
- if (defining == 0) {
- defining = 1;
- printf("void f" FNR "(void);\n");
- printf("void f" FNR "() {\n");
+ printf("void f" FNR "(void) {\n");
if (ccode)
call[FNR] = "f" FNR;
defining = 1;
@@ -135,8 +162,13 @@ $0 ~ /^endif/ {
gsub("^define[ \t]+[A-Za-z_][A-Za-z_0-9]*[ \t]+", "", value)
if (ccode)
printf("printf(\"#define " $2 " %%ld\\n\", (%s)" value ");\n", type);
- else
- printf("__asm(\"XYZZY : %s d\# %%%s0 + ;\" : : \"%s\" (%s));\n", $2, asmprint, asmtype, value);
+ else if (fcode) {
+ if (doing_member)
+ printf("__asm(\"XYZZY : %s d# %%%s0 + ;\" : : \"%s\" (%s));\n", $2, asmprint, asmtype, value);
+ else
+ printf("__asm(\"XYZZY d# %%%s0 constant %s\" : : \"%s\" (%s));\n", asmprint, $2, asmtype, value);
+ } else
+ printf("__asm(\"XYZZY %s %%%s0\" : : \"%s\" (%s));\n", $2, asmprint, asmtype, value);
next;
}
@@ -163,13 +195,21 @@ END {
printf("return(0); }\n");
}
}
-' ccode=$ccode > $TMP1 || exit 1
+' ccode="$ccode" fcode="$fcode" > "${genassym_temp}/assym.c" || exit 1
-if [ $ccode = 1 ] ; then
- "$@" -x c $TMP1 -o $TMP2 && $TMP2
+if [ "$ccode" = 1 ]; then
+ "$@" "${genassym_temp}/assym.c" -o "${genassym_temp}/genassym" && \
+ "${genassym_temp}/genassym"
+elif [ "$fcode" = 1 ]; then
+ # Kill all of the "#" and "$" modifiers; locore.s already
+ # prepends the correct "constant" modifier.
+ "$@" -S "${genassym_temp}/assym.c" -o - | sed -e 's/\$//g' | \
+ sed -n 's/.*XYZZY//gp'
else
# Kill all of the "#" and "$" modifiers; locore.s already
# prepends the correct "constant" modifier.
- "$@" -x c -S ${TMP1} -o ${TMP2} || exit 1
- sed 's/\$//g' ${TMP2} | sed -n 's/.*XYZZY//gp'
+ "$@" -S "${genassym_temp}/assym.c" -o - > \
+ "${genassym_temp}/genassym.out" && \
+ sed -e 's/#//g' -e 's/\$//g' < "${genassym_temp}/genassym.out" | \
+ sed -n 's/.*XYZZY/#define/gp'
fi
diff --git a/sys/arch/sparc64/stand/bootblk/genfth.cf b/sys/arch/sparc64/stand/bootblk/genfth.cf
index 31c3b8638fc..13a72279bf2 100644
--- a/sys/arch/sparc64/stand/bootblk/genfth.cf
+++ b/sys/arch/sparc64/stand/bootblk/genfth.cf
@@ -1,5 +1,5 @@
-# $OpenBSD: genfth.cf,v 1.5 2014/11/26 19:57:41 stsp Exp $
-# $NetBSD: genfth.cf,v 1.1 2000/08/20 14:58:46 mrg Exp $
+# $OpenBSD: genfth.cf,v 1.6 2020/04/02 06:06:22 otto Exp $
+# $NetBSD: genfth.cf,v 1.9 2013/06/10 10:26:22 hannken Exp $
#
# Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -49,7 +49,11 @@
# 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.
-# 3. Neither the name of the University nor the names of its contributors
+# 3. All advertising materials mentioning features or use of this software
+# must display the following acknowledgement:
+# This product includes software developed by the University of
+# California, Berkeley and its contributors.
+# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
@@ -83,6 +87,7 @@ include <sys/stdarg.h> /* XXX */
include <sys/device.h>
include <sys/sensors.h>
include <dev/softraidvar.h>
+include <dev/biovar.h>
#endif
#
@@ -101,12 +106,13 @@ define fs_raid FS_RAID
#
define dev_bsize DEV_BSIZE
define maxbsize MAXBSIZE
-define bbsize BBSIZE
-define sbsize SBSIZE
-define bboff BBOFF
-define sboff SBOFF
-define bblock BBLOCK
-define sblock SBLOCK
+define bbsize BBSIZE
+define sbsize SBLOCKSIZE
+define bboff BBOFF
+define sboff SBLOCK_UFS1
+define bblock BBLOCK
+# XXX: Will not work for UFS2!
+define sblock SBLOCK_UFS1
#
# ufs superblock
@@ -143,14 +149,22 @@ member fs_frag
member fs_maxsymlinklen
#
-# ufs dinode
+# ufs1 dinode
#
struct ufs1_dinode
-member di_size
-member di_mode
-member di_db
-member di_ib
-member di_shortlink
+member di1_size di_size
+member di1_mode di_mode
+member di1_db di_db
+member di1_ib di_ib
+
+#
+# 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
@@ -162,7 +176,8 @@ member d_reclen
member d_namlen
member d_name
-define fs_magic_value FS_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