These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / SLOF / board-qemu / slof / OF.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2011 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 \ The master file.  Everything else is included into here.
14
15 hex
16
17 ' ll-cr to cr
18
19 #include "header.fs"
20
21 #include "hvterm.fs"
22
23 #include "base.fs"
24
25 \ Set default load-base to 0x4000
26 4000 to default-load-base
27
28 \ Little-endian accesses.  Also known as `wrong-endian'.
29 #include <little-endian.fs>
30
31 : #join  ( lo hi #bits -- x )  lshift or ;
32 : #split ( x #bits -- lo hi )  2dup rshift dup >r swap lshift xor r> ;
33
34 : blink ;
35 : reset-dual-emit ;
36 : console-clean-fifo ;
37 : bootmsg-nvupdate ;
38 : asm-cout 2drop drop ;
39
40 #include "logging.fs"
41
42 : log-string 2drop ;
43
44 #include "bootmsg.fs"
45
46 000 cp
47
48 #include "exception.fs"
49
50 : mm-log-warning 2drop ;
51
52 : write-mm-log ( data length type -- status )
53         3drop 0
54 ;
55
56 100 cp
57
58 \ Input line editing.
59 #include "accept.fs"
60
61 120 cp
62
63 #include "dump.fs"
64
65 cistack ciregs >r1 ! \ kernel wants a stack :-)
66
67 140 cp
68
69 #include "romfs.fs"
70
71 200 cp
72
73 #include <slof-logo.fs>
74
75 201 cp
76
77 #include <banner.fs>
78
79 : .banner .slof-logo .banner ;
80
81 220 cp
82
83 DEFER find-boot-sector ( -- )
84
85 240 cp
86 \ Timebase frequency, in Hz. Start with a good default
87 \ Use device-tree later to fix it up
88 d# 512000000 VALUE tb-frequency   \ default value - needed for "ms" to work
89 -1 VALUE cpu-frequency
90
91 #include "helper.fs"
92 260 cp
93
94 #include <timebase.fs>
95
96 270 cp
97
98 #include <fcode/evaluator.fs>
99
100 2e0 cp
101
102 #include <quiesce.fs>
103
104 300 cp
105
106 #include <usb/usb-static.fs>
107
108 320 cp
109
110 #include <scsi-loader.fs>
111
112 340 cp
113
114 #include "fdt.fs"
115
116 360 cp
117
118 #include <root.fs>
119
120 370 cp
121
122 : check-boot-menu
123    s" qemu,boot-menu" get-chosen IF
124       decode-int 1 = IF
125          ." Press F12 for boot menu." cr cr
126       THEN
127       2drop
128    THEN
129 ;
130 check-boot-menu
131
132 380 cp
133
134 \ Grab rtas from qemu
135 #include "rtas.fs"
136
137 3f0 cp
138
139 #include "tree.fs"
140
141 800 cp
142
143 #include "nvram.fs"
144
145 880 cp
146
147 #include "envvar.fs"
148 check-for-nvramrc
149
150 890 cp
151
152 #include "qemu-bootlist.fs"
153
154 8a0 cp
155
156 \ The client interface.
157 #include "client.fs"
158 \ ELF binary file format.
159 #include "elf.fs"
160 #include <loaders.fs>
161
162 8a8 cp
163 CREATE version-str 10 ALLOT
164 0 value temp-ptr
165
166 : dump-display-buffer
167     disp-ptr to temp-ptr
168     " SLOF **********************************************************************" terminal-write drop
169     cr
170     version-str get-print-version
171     version-str @                   \ start
172     version-str 8 + @               \ end
173     over - terminal-write drop
174     " Press 's' to enter Open Firmware." terminal-write drop
175     cr cr
176     temp-ptr disp-size > IF
177         temp-ptr disp-size MOD
178         dup
179         prevga-disp-buf + swap disp-size swap - terminal-write drop
180         temp-ptr disp-size MOD
181         prevga-disp-buf swap 1 - terminal-write drop
182     ELSE
183         prevga-disp-buf temp-ptr terminal-write drop
184     THEN
185 ;
186
187 : enable-framebuffer-output  ( -- )
188 \ enable output on framebuffer
189    s" screen" find-alias ?dup  IF
190       \ we need to open/close the screen device once
191       \ before "ticking" display-emit to emit
192       open-dev close-node
193       false to store-prevga?
194       s" display-emit" $find  IF 
195          to emit 
196          dump-display-buffer
197       ELSE
198          2drop
199       THEN
200    THEN
201 ;
202
203 enable-framebuffer-output
204
205 8b0 cp
206
207 \ Scan USB devices
208 usb-scan
209
210 8c0 cp
211
212 \ Claim remaining memory that is used by firmware:
213 romfs-base 400000 0 ' claim CATCH IF ." claim failed!" cr 2drop THEN drop
214
215 8d0 cp
216
217 : set-default-console
218     s" linux,stdout-path" get-chosen IF
219         decode-string
220         ." Using default console: " 2dup type cr
221         io
222         2drop
223     ELSE
224         ." No console specified "
225         " screen" find-alias dup IF nip THEN
226         " keyboard" find-alias dup IF nip THEN
227         AND IF
228           ." using screen & keyboard" cr
229           " screen" output
230           " keyboard" input
231         ELSE
232           " hvterm" find-alias IF
233             drop
234             ." using hvterm" cr
235             " hvterm" io
236           ELSE
237             " /openprom" find-node ?dup IF
238                 set-node
239                 ." and no default found, creating dev-null" cr
240                 " dev-null.fs" included
241                 " devnull-console" io
242                 0 set-node
243             THEN
244           THEN
245         THEN
246     THEN
247 ;
248 set-default-console
249
250 8e0 cp
251
252 \ Check if we are booting a kernel passed by qemu, in which case
253 \ we skip initializing some devices
254
255 0 VALUE direct-ram-boot-base
256 0 VALUE direct-ram-boot-size
257
258 : (boot-ram)
259     direct-ram-boot-size 0<> IF
260         ." Booting from memory..." cr
261         s" go-args 2@ " evaluate
262         direct-ram-boot-base 0
263         s" true state-valid ! " evaluate
264         s" disable-watchdog go-64" evaluate
265     THEN
266 ;
267
268 8e8 cp
269
270 : check-boot-from-ram
271     s" qemu,boot-kernel" get-chosen IF
272         decode-int -rot decode-int -rot ( n1 n2 p s )
273         decode-int -rot decode-int -rot ( n1 n2 n3 n4 p s )
274         2drop
275         swap 20 << or to direct-ram-boot-size
276         swap 20 << or to direct-ram-boot-base
277         ." Detected RAM kernel at " direct-ram-boot-base .
278         ." (" direct-ram-boot-size . ." bytes) "
279         \ Override the boot-command word without touching the
280         \ nvram environment
281         s" boot-command" $create " (boot-ram)" env-string
282     THEN
283 ;
284 check-boot-from-ram
285
286 8ff cp
287
288 #include <start-up.fs>
289
290 ."      "   \ Clear last checkpoint
291
292 #include <boot.fs>
293
294 cr .(   Welcome to Open Firmware)
295 cr
296 #include "copyright-oss.fs"
297 cr cr
298
299 \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
300 ' start-it CATCH drop
301
302 cr ." Ready!"