Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / pkg / boot / sunlabel.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: sunlabel.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)sunlabel.fth 2.24 97/01/28
43purpose: Sun disk label (disk-label) package
44copyright: Copyright 1990 Sun Microsystems, Inc. All Rights Reserved
45
46\ Sun Label package. Runs on top of a disk device, dividing that disk
47\ into logical partitions as described in a "label" stored in the first
48\ 512-byte block. Implements the "load" operation by reading a 7.5 Kbyte
49\ "bootblk" starting 512 bytes from the beginning of a partition.
50\
51\ The complete contents of the label block is described in
52\ /usr/include/sun/dklabel.h
53
54" /packages" find-device
55new-device
56" disk-label" device-name
57headerless
58
59d# 512 constant ublock \ Logical block size. Also size of label.
60ublock d# 15 * constant /bootblk \ Size of "bootblk" code stored after label
61
620 instance value dklabel \ Label buffer; used temporarily during open
63instance variable partition#
64instance variable dkl_ncyl \ # of data cylinders
65instance variable dkl_acyl \ # of alternate cylinders
66instance variable dkl_nhead \ # of heads
67instance variable dkl_nsect \ # of sectors per track
68
69: label@ ( offset -- short ) dklabel + w@ ;
70
71: label-valid? ( -- flag )
72 d# 508 label@ h# dabe <> if
73 ." Bad magic number in disk label" cr false exit
74 then
75
76 0 dklabel ublock bounds ?do i w@ xor /w +loop ( checksum )
77
78 0<> if ." Bad checksum in disk label" cr false exit then
79
80 true
81;
82
83: set-start-block ( partition# -- error?? )
84 8 * d# 444 dklabel + + unaligned-l@ ( start-cyl )
85 d# 436 label@ ( .. #heads ) * ( start-trk )
86 d# 438 label@ ( .. sectors/trk ) * ( start-block )
87 ublock * ( byte-offset )
88 partition# !
89 d# 432 label@ dkl_ncyl !
90 d# 434 label@ dkl_acyl !
91 d# 436 label@ dkl_nhead !
92 d# 438 label@ dkl_nsect !
93;
94: get-dkl-info ( -- ncyl acyl nhead nsect )
95 dkl_ncyl @
96 dkl_acyl @
97 dkl_nhead @
98 dkl_nsect @
99;
100
101headers
102: read ( len buf -- actual-len ) " read" $call-parent ;
103: write ( len buf -- actual-len ) " write" $call-parent ;
104: seek ( offset-low offset-high -- okay? ) " seek" $call-parent ;
105
106: offset ( offset-low offset-high -- offset-low' offset-high' )
107 partition# @ 0 d+ ( low high ) \ Add start of partition
108;
109headerless
110: open-part ( file$ part$ -- file$ okay? )
111 \ The "nolabel" partition maps the entire disk, and does not look at the label
112 2dup " nolabel" $= if 2drop true exit then
113
114 \ Accept partition letters a, b, c, ... or A, B, C, ...
115 if ( file$ adr )
116 c@ upc ascii A - ( file$ part# )
117 else
118 \ No partition specified : default to "a"
119 \ Rewrite "my-args" and insert the partition label.
120 drop dup if ( file$ )
121 \ File argument--need to allocate space for that
122 dup 2+ ( <part><,><file$> ) dup alloc-mem ( file$ len adr )
123 ascii a over c! ascii , over 1+ c! ( file$ len adr )
124 2over 2 pick 2+ swap move swap ( file$ adr len )
125 else
126 ascii a 1 alloc-mem tuck c! 1 ( file$ adr len )
127 then
128 my-parent package( to my-args-len to my-args-adr )package
129 0
130 then ( file$ part# )
131
132 \ Initially set partition to 0 so that we can
133 \ read the label which is in the first partition
134 0 partition# ! ( file$ part# )
135
136 ublock alloc-mem is dklabel ( file$ part# )
137 dklabel 0= if ( file$ part# )
138 ." Can't allocate memory for disk label" ( file$ part# )
139 drop false exit ( file$ false )
140 then ( file$ part# )
141
142 0 0 seek drop ( file$ part# )
143 dklabel ublock read ublock <> if ( file$ part# )
144 ." Can't read disk label." cr drop false ( file$ false )
145 else ( file$ part# )
146 set-start-block label-valid? ( file$ okay? )
147 then ( file$ okay? )
148
149 dklabel ublock free-mem ( file$ okay? )
150;
151
152headers
153: open ( -- okay? )
154 \ Arg string is <part>[,<filespec>]
155 \ Split off partition, and handle via open-part
156 my-args ascii , left-parse-string ( file$ part$ )
157
158 open-part 0= if 2drop false exit then ( file$ )
159
160 ?dup if
161 " ufs-file-system" find-package if
162 interpose
163 else
164 2drop false exit
165 then
166 else
167 drop
168 then
169 true
170;
171
172
173: close ( -- ) ; \ Nothing to do, since we only use 1 cell of data
174
175: load ( adr -- size ) \ Pass in load-base
176 ublock 0 seek drop ( adr ) \ Should check for errors
177 ublock d# 15 * tuck ( len adr len )
178 read ( len actual-len )
179 tuck <> if ." Short disk read" cr then ( actual-len )
180;
181
182: size ( -- d.size ) /bootblk s>d ;
183headers
184finish-device
185device-end
186