boot.fth revision c713350eb0c205161e2a4ab06cd996300721ac78
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ CDDL HEADER START
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ The contents of this file are subject to the terms of the
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ Common Development and Distribution License (the "License").
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ You may not use this file except in compliance with the License.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ See the License for the specific language governing permissions
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ and limitations under the License.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ When distributing Covered Code, include this CDDL HEADER in each
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ If applicable, add the following below this CDDL HEADER, with the
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ fields enclosed by brackets "[]" replaced with your own identifying
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ information: Portions Copyright [yyyy] [name of copyright owner]
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ CDDL HEADER END
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson\ Copyright 2009 Sun Microsystems, Inc. All rights reserved.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ Use is subject to license terms.
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjepurpose: boot block for OBP systems
c713350eb0c205161e2a4ab06cd996300721ac78John Johnsoncopyright: Copyright 2009 Sun Microsystems, Inc. All Rights Reserved
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjed# 1024 dup * constant 1meg
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjed# 4 1meg * constant 4meg
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjed# 32 1meg * constant 32meg
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje" /" get-package constant root-ph
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 value fs-ih
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value nested?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 value file-sz
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: boot-dev
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: boot-dev$ ( -- dev$ ) boot-dev cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: loader-base ( -- base )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje h# 5000.0000
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje h# 5100.0000
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ methods we expect of fs reader packages
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-open ( file$ -- fd true | false )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " open-file" fs-ih $call-method
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-close ( fd -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " close-file" fs-ih $call-method
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-size ( fd -- size )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " size-file" fs-ih $call-method
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-read ( adr len fd -- #read )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " read-file" fs-ih $call-method
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-getrd ( adr len -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " get-rd" fs-ih $call-method
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-bootprop ( -- propval propname true | false )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " bootprop" fs-ih $call-method
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj: check-elf ( base -- is-elf? )
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj l@ h# 7f454c46 ( \x7fELF ) =
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj: check-fcode ( base -- is-fcode? )
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj c@ dup h# f0 h# f3 between swap h# fd = or
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ zfs bootblks with all headers exceeds 7.5k
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ 'bigbootblk' allows us to load the fs reader from elsewhere
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje[ifdef] bigbootblk
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: load-pkg ( -- )
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj boot-dev$ ( dev$ )
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj 2dup dev-open ?dup 0= if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then >r 2drop ( r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /fs-fcode mem-alloc ( adr r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup /fs-fcode fs-offset r@ read-disk
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj dup check-fcode invert if
629270abbcc9bcad8f09aeb9500f67a1933334d1jgj " No fs fcode found" die
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup 1 byte-load
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /fs-fcode mem-free ( r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje r> dev-close
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: load-pkg ( -- ) ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-bootdev ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ first try boot archive (nested boot from ramdisk)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ then try boot device (direct boot from disk)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " bootarchive" chosen-ph get-package-property if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " bootpath" chosen-ph get-string-prop ( bootpath$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else ( archiveprop$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje decode-string 2swap 2drop ( archivepath$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to nested?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( bootpath$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje boot-dev swap move ( )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: mount-root ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje boot-dev$ fs-pkg$ $open-package to fs-ih
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-ih 0= if
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw " Can't mount root" die
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ cheap entertainment for those watching
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ boot progress
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjecreate spin-data
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje ascii | c, ascii / c, ascii - c, ascii \ c,
c713350eb0c205161e2a4ab06cd996300721ac78John Johnsonvariable spindex
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: spinner ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje spindex @ 3 and spin-data + ( c-adr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje c@ emit (cr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 1 spindex +!
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ allocate and return physical allocation size
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: vmem-alloc-prop ( size virt -- alloc-size virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup ['] vmem-alloc catch if ( size virt ??? ??? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2drop ( size virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup begin ( size virt len adr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over 32meg min >r ( size virt len adr r: alloc-sz )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje r@ over vmem-alloc ( size virt len adr adr r: alloc-sz )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje nip r@ + ( size virt len adr' r: alloc-sz )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje swap r> - ( size virt adr len' )
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj swap over 0= ( size virt len' adr done? )
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj until ( size virt len' adr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2drop nip 32meg ( virt 32meg )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else ( size virt virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje nip nip 0 ( virt 0 )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( virt alloc-sz )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson\ read file in chunks so we can toggle the spinner
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson: read-file ( virt size fd -- failed? )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson >r ( virt sz-left r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson begin dup while
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson dup 4meg min ( virt sz-left read-sz r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson 3dup nip r@ fs-read ( virt sz-left read-sz size-read r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson over <> if ( virt sz-left read-sz r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson r> 2drop 2drop ( )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson true exit ( failed )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson rot over + ( sz-left read-sz virt' r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson -rot - ( virt' sz-left' r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson r> 3drop ( )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson false ( succeeded )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ read in file and return buffer
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ if base==0, vmem-alloc will allocate virt
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj\ NB returned size is 8k rounded since the
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj\ memory allocator rounded it for us
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj: get-file ( base fd -- [ alloc-sz virt size ] failed? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup >r fs-size ( base size r: fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup rot vmem-alloc-prop ( size alloc-sz virt r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson rot 2dup ( alloc-sz virt size virt size r: fd )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson r> read-file if ( alloc-sz virt size )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 3drop true exit ( failed )
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj h# 2000 roundup ( alloc-sz virt size' )
b8b2ae86d7bf3651ade08dc386dbd2317d3e1febjgj false ( alloc-sz virt size' succeeded )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value is-elf?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value is-archive?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: >bootblk ( adr -- adr' ) d# 512 + ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ figure out what we just loaded
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-type ( adr -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup check-elf to is-elf?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ if not nested, check for boot archive (executable after label)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje nested? invert if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup check-fcode ( adr is-fcode? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over check-elf ( adr is-fcode? is-elf? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje or to is-archive?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ file name routines
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ boot file (-F name or boot archive)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value fflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: boot-file
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: boot-file$ ( -- file$ ) boot-file cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ kernel name (final name or unix)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value kern?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: kern-file
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: kern-file$ ( -- file$ ) kern-file cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ platform name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: plat-name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: plat-name$ ( -- plat$ ) plat-name cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: arch-name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: arch-name$ ( -- arch$ ) arch-name cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ final name after /platform massaging
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: targ-file
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: targ-file$ ( -- file$ ) targ-file cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: init-targ ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file /buf-len erase
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " /platform/" targ-file swap move
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ remove illegal file name chars (e.g., '/')
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: munge-name ( name$ -- name$' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup ( name$ name$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje begin dup while
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over c@ ascii / = if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over ascii _ swap c! ( name$ name$' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje repeat 2drop ( name$ )
296a41153b384aff24610e491670659621352e81jgj\ does /platform/<name> exist?
296a41153b384aff24610e491670659621352e81jgj: try-platname ( name$ -- name$ true | false )
296a41153b384aff24610e491670659621352e81jgj munge-name ( name$' )
296a41153b384aff24610e491670659621352e81jgj init-targ 2dup targ-file$ $append
296a41153b384aff24610e491670659621352e81jgj targ-file$ fs-open if ( name$ fd )
296a41153b384aff24610e491670659621352e81jgj fs-close true ( name$ true )
296a41153b384aff24610e491670659621352e81jgj else ( name$ )
296a41153b384aff24610e491670659621352e81jgj 2drop false ( false )
296a41153b384aff24610e491670659621352e81jgj then ( name$ true | false )
296a41153b384aff24610e491670659621352e81jgj\ setup arch-name
296a41153b384aff24610e491670659621352e81jgj\ sun4v -or- sun4u
296a41153b384aff24610e491670659621352e81jgj: get-def-arch ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " device_type" root-ph get-package-property if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ some older sunfires don't have device_type set
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje false ( sun4u )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else ( devtype-prop$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje decode-string 2swap 2drop ( devtype$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " sun4v" $= ( sun4v? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( sun4v? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje if " sun4v" else " sun4u" then ( arch$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje arch-name swap move
296a41153b384aff24610e491670659621352e81jgj\ setup plat-name
296a41153b384aff24610e491670659621352e81jgj\ platform name -or-
296a41153b384aff24610e491670659621352e81jgj\ compatible name -or-
296a41153b384aff24610e491670659621352e81jgj\ default name
296a41153b384aff24610e491670659621352e81jgj: get-arch ( -- )
296a41153b384aff24610e491670659621352e81jgj get-def-arch
296a41153b384aff24610e491670659621352e81jgj \ first try "name" in root
296a41153b384aff24610e491670659621352e81jgj " name" root-ph get-string-prop ( name$ )
296a41153b384aff24610e491670659621352e81jgj try-platname if
296a41153b384aff24610e491670659621352e81jgj plat-name swap move exit ( )
296a41153b384aff24610e491670659621352e81jgj \ next try "compatible"
296a41153b384aff24610e491670659621352e81jgj " compatible" root-ph ( prop$ ph )
296a41153b384aff24610e491670659621352e81jgj get-package-property invert if ( compat$ )
296a41153b384aff24610e491670659621352e81jgj begin decode-string dup while ( compat$ name$ )
296a41153b384aff24610e491670659621352e81jgj try-platname if
296a41153b384aff24610e491670659621352e81jgj plat-name swap move 2drop exit ( )
296a41153b384aff24610e491670659621352e81jgj then ( compat$ )
296a41153b384aff24610e491670659621352e81jgj repeat 2drop 2drop ( )
296a41153b384aff24610e491670659621352e81jgj \ else use default name
296a41153b384aff24610e491670659621352e81jgj arch-name$ plat-name swap move
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ make <pre> <file> into /platform/<pre>/<file>
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: $plat-prepend ( file$ pre$ -- file$' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file$ $append ( file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " /" targ-file$ $append
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file$ $append ( )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file$ ( new$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-boot ( -- file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " boot_archive"
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-kern ( -- file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ if we're nested, load the kernel, else load the bootarchive
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-targ ( -- file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: try-file ( file$ -- [ fd ] error? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje diagnostic-mode? if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup ." Loading: " type cr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-open invert ( fd false | true )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ try "/platform/<plat-name>/<file>" e.g., SUNW,Sun-Blade-1000
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ then "/platform/<arch-name>/<file>" e.g., sun4u
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: open-path ( file$ - fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over c@ ascii / <> if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup plat-name$ $plat-prepend ( file$ file$' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje try-file if ( file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup arch-name$ $plat-prepend ( file$ file$' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje try-file if ( file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( file$ fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( file$ fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else ( file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ copy to targ-file for 'whoami' prop
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file /buf-len erase
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup targ-file swap move
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup try-file if ( file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( file$ fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then ( file$ fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje -rot 2drop ( fd )
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gwfalse value lflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ ZFS support
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ -Z fsname opens specified filesystem in disk pool
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value zflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje/buf-len buffer: fs-name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fs-name$ ( -- fs$ ) fs-name cscount ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: open-zfs-fs ( fs$ -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup " open-fs" fs-ih $call-method 0= if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: open-zfs-fs ( fs$ -- )
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw \ ignore on -L
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw lflag? invert if
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw " -Z not supported on non-zfs root" die
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ arg parsing
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: printable? ( n -- flag ) \ true if n is a printable ascii character
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup bl th 7f within swap th 80 th ff between or
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: white-space? ( n -- flag ) \ true is n is non-printable? or a blank
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup printable? 0= swap bl = or
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: skip-blanks ( adr len -- adr' len' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje begin dup while ( adr' len' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over c@ white-space? 0= if exit then
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: skip-non-blanks ( adr len -- adr' len' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje begin dup while ( adr' len' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over c@ white-space? if exit then
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ left-parse-string w/ any white space as delimeter
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: next-str ( adr len -- adr' len' s-adr s-len )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup skip-non-blanks ( s-adr len adr' len' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup >r 2swap r> - ( adr' len' s-adr s-len )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson\ next char or 0 if eol
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: next-c ( adr len -- adr' len' c )
c713350eb0c205161e2a4ab06cd996300721ac78John Johnson dup if over c@ >r str++ r> else 0 then
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setjefalse value halt?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: parse-bootargs ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " bootargs" chosen-ph get-string-prop ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ check for explicit kernel name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje skip-blanks dup if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje over c@ ascii - <> if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje next-str ( arg$ kern$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ use default kernel if user specific a debugger
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup " kadb" $= >r ( arg$ kern$ r: kadb? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 2dup " kmdb" $= r> or ( arg$ kern$ debugger? )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje invert if ( arg$ kern$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje kern-file swap move ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to kern?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else 2drop then ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ process args
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje skip-blanks dup ( arg$ len )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje next-c ascii - = if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje next-c case
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ for "boot kadb -D kernel.foo/unix"
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje skip-blanks next-str ( arg$ file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje kern? invert if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje kern-file swap move ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to kern?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else drop then ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else 2drop then ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje skip-blanks next-str ( arg$ file$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje boot-file swap move ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to fflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else drop then ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to halt?
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw ascii L of
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw " /" fs-name swap move
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw true to zflag?
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw " bootlst" boot-file swap move
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw true to fflag?
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw true to lflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje skip-blanks next-str ( arg$ fs-name$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-name swap move ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje true to zflag?
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje else drop then ( arg$ )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 value rd-alloc-sz
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: "ramdisk" ( -- dev$ ) " /ramdisk-root" ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: setup-bootprops ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje chosen-ph push-package
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje nested? invert if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-type$ encode-string " fstype" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-ih encode-int " bootfs" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-bootprop if property then
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-type$ encode-string " archive-fstype" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-ih encode-int " archfs" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje is-archive? if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje "ramdisk" encode-string " bootarchive" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje loader-base encode-int " elfheader-address" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje file-sz encode-int " elfheader-length" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje plat-name$ encode-string " impl-arch-name" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje targ-file$ encode-string " whoami" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-pkg$ encode-string " fs-package" property
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje pop-package
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ load ramdisk fcode and tell the driver where
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ we put the ramdisk data
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: setup-ramdisk ( base size -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /rd-fcode mem-alloc ( base size adr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup /rd-fcode fs-getrd
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje root-ph push-package
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje "ramdisk" str++ device-name
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup 1 byte-load
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje finish-device
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje pop-package
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje /rd-fcode mem-free ( base size )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje "ramdisk" dev-open dup 0= if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje "ramdisk" open-abort
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje then >r ( base size r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje rd-alloc-sz ( base size alloc-sz r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " create" r@ $call-method ( r: ih )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje r> dev-close ( )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ ELF parsing
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 value elfhdr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 value phdr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: +elfhdr ( index -- value ) elfhdr swap ca+ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: e_machine ( -- n ) h# 12 +elfhdr w@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: e_entry ( -- n ) h# 18 +elfhdr x@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: e_phoff ( -- n ) h# 20 +elfhdr x@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: e_phentsize ( -- n ) h# 36 +elfhdr w@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: e_phnum ( -- n ) h# 38 +elfhdr w@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje1 constant pt_load
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: +phdr ( index -- value ) phdr swap ca+ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: p_type ( -- n ) h# 0 +phdr l@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: p_vaddr ( -- n ) h# 10 +phdr x@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: p_memsz ( -- n ) h# 28 +phdr x@ ;
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: get-phdr ( filebase index -- phdr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje e_phentsize * e_phoff + + ( phdr )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ alloc 4MB pages for kernel text/data
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: vmem-alloc-4mb ( size virt -- base )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje swap 4meg roundup swap
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje 4meg (mem-alloc)
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ OBP doesn't allocate memory for elf
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ programs, it assumes they'll fit
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ under the default 10MB limit
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: fix-elf-mem ( base -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup to elfhdr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje e_machine d# 43 <> if drop exit then \ 64b only
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje e_phnum 0 ?do
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup i get-phdr to phdr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje p_type pt_load = p_vaddr h# a0.0000 > and if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje \ allocate 4MB segs for text & data
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje p_vaddr 4meg 1- and if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje p_memsz p_vaddr vmem-alloc drop
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje p_memsz p_vaddr vmem-alloc-4mb drop
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje loop drop ( )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: load-file ( -- virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje get-targ open-path ( fd )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje loader-base over get-file if ( fd alloc-sz virt size )
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gw " Boot load failed" die
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje to file-sz ( fd alloc-sz virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje swap to rd-alloc-sz ( fd virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje swap fs-close ( virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: setup-props ( virt -- virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup get-type
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje setup-bootprops
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje is-archive? if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup file-sz setup-ramdisk
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: exec-file ( virt -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje dup fix-elf-mem
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje is-archive? if >bootblk then ( virt' )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje " to load-base init-program" evaluate
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje: do-boot ( -- )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje parse-bootargs
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje ." Halted with -H flag. " cr
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje get-bootdev
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje zflag? nested? invert and if
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje fs-name$ open-zfs-fs
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje load-file ( virt )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje setup-props
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje exec-file ( )
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje\ Tadpole proms don't initialize my-self
986fd29a0dc13f7608ef7f508f6e700bd7bc2720setje0 to my-self