blob: ded2b0ed1563b363d5088e4de2bd47142ac31ffd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
\ *****************************************************************************
\ * Copyright (c) 2004, 2007 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
\ \\\\\\\\\\\\\\ Global Data
CREATE (bootdevice) 2 cells allot (bootdevice) 2 cells erase
CREATE bootargs 2 cells allot bootargs 2 cells erase
CREATE load-list 2 cells allot load-list 2 cells erase
' (bootdevice) to bootdevice
0 VALUE load-size
0 VALUE go-entry
VARIABLE state-valid false state-valid !
CREATE go-args 2 cells allot go-args 2 cells erase
\ \\\\\\\\\\\\\\ Structure/Implementation Dependent Methods
: $bootargs
bootargs 2@ ?dup IF
ELSE s" diagnostic-mode?" evaluate and IF s" diag-file" evaluate
ELSE s" boot-file" evaluate THEN THEN
;
: $bootdev
bootdevice 2@ ?dup IF
ELSE s" diagnostic-mode?" evaluate and IF
s" diag-device" evaluate
ELSE
s" boot-device" evaluate
THEN
THEN
?dup 0= IF
disable-watchdog
drop ABORT" No boot device!"
THEN
;
\ \\\\\\\\\\\\\\ Implementation Independent Methods (Depend on Previous)
\ *
\ *
: set-boot-args ( str len -- ) dup IF strdup ELSE nip dup THEN bootargs 2! ;
: (set-boot-device) ( str len -- )
?dup IF 1+ strdup 1- ELSE drop 0 0 THEN bootdevice 2! ;
' (set-boot-device) to set-boot-device
: (add-boot-device) ( str len -- ) \ Concatenate " str" to "bootdevice"
bootdevice 2@ ?dup IF $cat-space ELSE drop THEN set-boot-device ;
' (add-boot-device) to add-boot-device
0 value claim-list
: no-go ( -- ) -64 boot-exception-handler ABORT ;
defer go ( -- )
: go-32 ( -- )
state-valid @ IF
0 ciregs >r3 ! 0 ciregs >r4 !
go-args 2@ go-entry start-elf client-data
claim-list elf-release 0 to claim-list
THEN
-6d boot-exception-handler ABORT" "
;
: go-64 ( -- )
state-valid @ IF
0 ciregs >r3 ! 0 ciregs >r4 !
go-args 2@ go-entry start-elf64 client-data
claim-list elf-release 0 to claim-list
THEN
-6d boot-exception-handler ABORT" "
;
: load-elf-init ( arg len file-addr -- success )
false state-valid ! \ Not valid anymore ...
claim-list IF \ Release claimed mem
claim-list elf-release 0 to claim-list \ from last load
THEN
dup ['] elf-check-file CATCH IF
( -64 THROW ) \ Not now, let the 'go' (i.e. no-go) whine about it
drop 0
THEN
CASE
1 OF true swap ['] load-elf32-claim CATCH IF
2drop drop -66 THROW
THEN
['] go-32 ENDOF ( arg len true claim-list entry go )
2 OF true swap ['] load-elf64-claim CATCH IF
2drop drop -66 THROW
THEN
['] go-64 ENDOF ( arg len true claim-list entry go )
dup OF drop ['] no-go to go
2drop false EXIT ENDOF ( false )
ENDCASE
to go to go-entry to claim-list
dup state-valid ! -rot
2 pick IF
go-args 2!
ELSE
2drop
THEN
;
: init-program ( -- )
$bootargs LOAD-BASE ['] load-elf-init CATCH ?dup IF
boot-exception-handler
2drop 2drop false \ Could not claim
ELSE IF
0 ciregs 2dup >r3 ! >r4 ! \ Valid (ELF ) Image
THEN
THEN
;
\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ Generic device load method:
\ *
: do-load ( devstr len -- img-size ) \ Device method wrapper
258 set-watchdog \ Set watchdog timer to 10 minutes
my-self >r current-node @ >r \ Save my-self
." Trying to load: " $bootargs type ." from: " 2dup type ." ... "
2dup open-dev dup IF
dup to my-self
dup ihandle>phandle set-node
-rot ( ihandle devstr len )
my-args nip 0= IF
2dup 1- + c@ [char] : <> IF \ Add : to device path if missing
1+ strdup 2dup 1- + [char] : swap c!
THEN
THEN
encode-string s" bootpath" set-chosen
$bootargs encode-string s" bootargs" set-chosen
LOAD-BASE s" load" 3 pick ['] $call-method CATCH IF
-67 boot-exception-handler 3drop drop false
ELSE
dup 0> IF
init-program
ELSE
false state-valid !
drop 0 \ Could not load
THEN
THEN
swap close-dev device-end dup to load-size
ELSE -68 boot-exception-handler 3drop false THEN
r> set-node r> to my-self \ Restore my-self
;
: parse-load ( "{devlist}" -- success ) \ Parse-execute boot-device list
cr BEGIN parse-word dup WHILE
( de-alias ) do-load dup 0< IF drop 0 THEN IF
state-valid @ IF ." Successfully loaded" cr THEN
true 0d parse strdup load-list 2! EXIT
THEN
REPEAT 2drop 0 0 load-list 2! false
;
: load ( "{params}<eol>"} -- success ) \ Client interface to load
parse-word 0d parse -leading 2swap ?dup IF
de-alias
over c@ [char] / = IF
set-boot-device
ELSE
s" " 2swap $cat $cat
THEN
ELSE
drop
THEN
set-boot-args s" parse-load " $bootdev $cat strdup evaluate
;
: load-next ( -- success ) \ Continue after go failed
load-list 2@ ?dup IF s" parse-load " 2swap $cat strdup evaluate
ELSE drop false THEN
;
\ \\\\\\\\\\\\\\\\\\\\\\\\\\
\ load/go utilities
\ -> Should be in loaders.fs
\ *
: noload false ;
' no-go to go
: (go-and-catch) ( -- )
['] go behavior CATCH IF -69 boot-exception-handler THEN
;
\ if the board does not get the bootlist from the nvram
\ then this word is supposed to be overloaded with the
\ word to get the bootlist from VPD (or from wheresoever)
read-bootlist
\ \\\\\\\\\\\\\\ Exported Interface:
\ *
\ IEEE 1275 : load (user interface)
\ *
: boot
load IF
disable-watchdog (go-and-catch)
BEGIN load-next WHILE
(go-and-catch)
REPEAT
\ When we return from boot print the banner again.
.banner
ELSE
-65 boot-exception-handler
THEN
;
: load load 0= IF -65 boot-exception-handler THEN ;
\ \\\\ Temporary hacks for backwards compatibility
: yaboot ." use 'boot disk' instead " ;
: netboot ( -- rc ) ." Use 'boot net' instead " ;
: netboot-arg ( arg-string -- rc ) s" boot net " 2swap $cat (parse-line) $cat
evaluate ;
: netload ( -- rc ) (parse-line)
load-base >r FLASH-LOAD-BASE to load-base
s" load net:" strdup 2swap $cat strdup evaluate
r> to load-base
load-size
;
: neteval ( -- ) FLASH-LOAD-BASE netload evaluate ;
|