1986fd29aSsetje\
2986fd29aSsetje\ CDDL HEADER START
3986fd29aSsetje\
4986fd29aSsetje\ The contents of this file are subject to the terms of the
5986fd29aSsetje\ Common Development and Distribution License (the "License").
6986fd29aSsetje\ You may not use this file except in compliance with the License.
7986fd29aSsetje\
8986fd29aSsetje\ You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9986fd29aSsetje\ or http://www.opensolaris.org/os/licensing.
10986fd29aSsetje\ See the License for the specific language governing permissions
11986fd29aSsetje\ and limitations under the License.
12986fd29aSsetje\
13986fd29aSsetje\ When distributing Covered Code, include this CDDL HEADER in each
14986fd29aSsetje\ file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15986fd29aSsetje\ If applicable, add the following below this CDDL HEADER, with the
16986fd29aSsetje\ fields enclosed by brackets "[]" replaced with your own identifying
17986fd29aSsetje\ information: Portions Copyright [yyyy] [name of copyright owner]
18986fd29aSsetje\
19986fd29aSsetje\ CDDL HEADER END
20986fd29aSsetje\
21986fd29aSsetje\
22*c713350eSJohn Johnson\ Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23986fd29aSsetje\ Use is subject to license terms.
24986fd29aSsetje\
25986fd29aSsetje
26986fd29aSsetjepurpose: boot block for OBP systems
27*c713350eSJohn Johnsoncopyright: Copyright 2009 Sun Microsystems, Inc. All Rights Reserved
28986fd29aSsetje
29986fd29aSsetje
30986fd29aSsetjeheaderless
31986fd29aSsetjed# 1024 dup  *     constant  1meg
32986fd29aSsetjed# 4  1meg   *     constant  4meg
33986fd29aSsetjed# 32 1meg   *     constant  32meg
34986fd29aSsetje
35986fd29aSsetjeheaders
36986fd29aSsetje" /"  get-package  constant  root-ph
37986fd29aSsetje
38986fd29aSsetje0                  value     fs-ih
39986fd29aSsetjefalse              value     nested?
40986fd29aSsetje0                  value     file-sz
41986fd29aSsetje
42986fd29aSsetje/buf-len  buffer:  boot-dev
43986fd29aSsetje: boot-dev$  ( -- dev$ )  boot-dev cscount  ;
44986fd29aSsetje
45986fd29aSsetje: loader-base  ( -- base )
46986fd29aSsetje   nested?  if
47986fd29aSsetje      h# 5000.0000
48986fd29aSsetje   else
49986fd29aSsetje      h# 5100.0000
50986fd29aSsetje   then
51986fd29aSsetje;
52986fd29aSsetje
53986fd29aSsetje
54986fd29aSsetje\
55986fd29aSsetje\ methods we expect of fs reader packages
56986fd29aSsetje\
57986fd29aSsetjeheaderless
58986fd29aSsetje: fs-open  ( file$ -- fd true | false )
59986fd29aSsetje   " open-file" fs-ih $call-method
60986fd29aSsetje;
61986fd29aSsetje
62986fd29aSsetje: fs-close  ( fd -- )
63986fd29aSsetje   " close-file" fs-ih $call-method
64986fd29aSsetje;
65986fd29aSsetje
66986fd29aSsetje: fs-size  ( fd -- size )
67986fd29aSsetje   " size-file" fs-ih $call-method
68986fd29aSsetje;
69986fd29aSsetje
70986fd29aSsetje: fs-read  ( adr len fd -- #read )
71986fd29aSsetje   " read-file" fs-ih $call-method
72986fd29aSsetje;
73986fd29aSsetje
74986fd29aSsetje: fs-getrd  ( adr len -- )
75986fd29aSsetje   " get-rd" fs-ih $call-method
76986fd29aSsetje;
77986fd29aSsetje
78986fd29aSsetje: fs-bootprop  ( -- propval propname true  |  false )
79986fd29aSsetje   " bootprop" fs-ih $call-method
80986fd29aSsetje;
81986fd29aSsetjeheaders
82986fd29aSsetje
83986fd29aSsetje
84629270abSjgj: check-elf ( base -- is-elf? )
85629270abSjgj   l@  h# 7f454c46 ( \x7fELF )  =
86629270abSjgj;
87629270abSjgj
88629270abSjgj: check-fcode ( base -- is-fcode? )
89629270abSjgj   c@ dup  h# f0 h# f3 between  swap h# fd =  or
90629270abSjgj;
91629270abSjgj
92629270abSjgj
93986fd29aSsetje\ zfs bootblks with all headers exceeds 7.5k
94986fd29aSsetje\ 'bigbootblk' allows us to load the fs reader from elsewhere
95986fd29aSsetje[ifdef] bigbootblk
96986fd29aSsetje
97986fd29aSsetje: load-pkg  ( -- )
98629270abSjgj   boot-dev$                              ( dev$ )
99629270abSjgj   2dup dev-open  ?dup 0=  if
100986fd29aSsetje      open-abort
101986fd29aSsetje   then  >r 2drop                         ( r: ih )
102629270abSjgj
103986fd29aSsetje   /fs-fcode  mem-alloc                   ( adr  r: ih )
104986fd29aSsetje   dup  /fs-fcode fs-offset r@  read-disk
105629270abSjgj
106629270abSjgj   dup check-fcode  invert  if
107629270abSjgj      " No fs fcode found"  die
108629270abSjgj   then
109986fd29aSsetje   dup  1 byte-load
110629270abSjgj
111986fd29aSsetje   /fs-fcode  mem-free                    ( r: ih )
112986fd29aSsetje   r>  dev-close
113986fd29aSsetje;
114986fd29aSsetje
115986fd29aSsetje[else]
116986fd29aSsetje
117986fd29aSsetje: load-pkg  ( -- )  ;
118986fd29aSsetje
119986fd29aSsetje[then]
120986fd29aSsetje
121986fd29aSsetje
122986fd29aSsetje: get-bootdev  ( -- )
123986fd29aSsetje   \ first try boot archive (nested boot from ramdisk)
124986fd29aSsetje   \ then try boot device (direct boot from disk)
125986fd29aSsetje   " bootarchive" chosen-ph  get-package-property  if
126986fd29aSsetje      " bootpath" chosen-ph  get-string-prop            ( bootpath$ )
127986fd29aSsetje   else                                                 ( archiveprop$ )
128986fd29aSsetje      decode-string  2swap 2drop                        ( archivepath$ )
129986fd29aSsetje      true to nested?
130986fd29aSsetje   then                                                 ( bootpath$ )
131986fd29aSsetje   boot-dev swap  move                                  (  )
132986fd29aSsetje;
133986fd29aSsetje
134986fd29aSsetje: mount-root  ( -- )
135986fd29aSsetje   boot-dev$ fs-pkg$  $open-package to fs-ih
136986fd29aSsetje   fs-ih 0=  if
137e7cbe64fSgw      " Can't mount root" die
138986fd29aSsetje   then
139986fd29aSsetje;
140986fd29aSsetje
141986fd29aSsetje\
142986fd29aSsetje\ cheap entertainment for those watching
143986fd29aSsetje\ boot progress
144986fd29aSsetje\
145986fd29aSsetjeheaderless
146986fd29aSsetjecreate spin-data
147986fd29aSsetje   ascii | c,  ascii / c,  ascii - c,  ascii \ c,
148986fd29aSsetje
149*c713350eSJohn Johnsonvariable spindex
150986fd29aSsetje
151*c713350eSJohn Johnsonheaders
152986fd29aSsetje: spinner ( -- )
153986fd29aSsetje   spindex @  3 and  spin-data +   ( c-adr )
154986fd29aSsetje   c@ emit  (cr
155