Add qemu 2.4.0
[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 390 cp
138
139 #include "virtio.fs"
140
141 3f0 cp
142
143 #include "tree.fs"
144
145 800 cp
146
147 #include "nvram.fs"
148
149 880 cp
150
151 #include "envvar.fs"
152 check-for-nvramrc
153
154 890 cp
155
156 #include "qemu-bootlist.fs"
157
158 8a0 cp
159
160 \ The client interface.
161 #include "client.fs"
162 \ ELF binary file format.
163 #include "elf.fs"
164 #include <loaders.fs>
165
166 8a8 cp
167 CREATE version-str 10 ALLOT
168 0 value temp-ptr
169
170 : dump-display-buffer
171     disp-ptr to temp-ptr
172     " SLOF **********************************************************************" terminal-write drop
173     cr
174     version-str get-print-version
175     version-str @                   \ start
176     version-str 8 + @               \ end
177     over - terminal-write drop
178     " Press 's' to enter Open Firmware." terminal-write drop
179     cr cr
180     temp-ptr disp-size > IF
181         temp-ptr disp-size MOD
182         dup
183         prevga-disp-buf + swap disp-size swap - terminal-write drop
184         temp-ptr disp-size MOD
185         prevga-disp-buf swap 1 - terminal-write drop
186     ELSE
187         prevga-disp-buf temp-ptr terminal-write drop
188     THEN
189 ;
190
191 : enable-framebuffer-output  ( -- )
192 \ enable output on framebuffer
193    s" screen" find-alias ?dup  IF
194       \ we need to open/close the screen device once
195       \ before "ticking" display-emit to emit
196       open-dev close-node
197       false to store-prevga?
198       s" display-emit" $find  IF 
199          to emit 
200          dump-display-buffer
201       ELSE
202          2drop
203       THEN
204    THEN
205 ;
206
207 enable-framebuffer-output
208
209 8b0 cp
210
211 \ Scan USB devices
212 usb-scan
213
214 8c0 cp
215
216 \ Claim remaining memory that is used by firmware:
217 romfs-base 400000 0 ' claim CATCH IF ." claim failed!" cr 2drop THEN drop
218
219 8d0 cp
220
221 : set-default-console
222     s" linux,stdout-path" get-chosen IF
223         decode-string
224         ." Using default console: " 2dup type cr
225         io
226         2drop
227     ELSE
228         ." No console specified "
229         " screen" find-alias dup IF nip THEN
230         " keyboard" find-alias dup IF nip THEN
231         AND IF
232           ." using screen & keyboard" cr
233           " screen" output
234           " keyboard" input
235         ELSE
236           " hvterm" find-alias IF
237             drop
238             ." using hvterm" cr
239             " hvterm" io
240           ELSE
241             " /openprom" find-node ?dup IF
242                 set-node
243                 ." and no default found, creating dev-null" cr
244                 " dev-null.fs" included
245                 " devnull-console" io
246                 0 set-node
247             THEN
248           THEN
249         THEN
250     THEN
251 ;
252 set-default-console
253
254 8e0 cp
255
256 \ Check if we are booting a kernel passed by qemu, in which case
257 \ we skip initializing some devices
258
259 0 VALUE direct-ram-boot-base
260 0 VALUE direct-ram-boot-size
261
262 : (boot-ram)
263     direct-ram-boot-size 0<> IF
264         ." Booting from memory..." cr
265         s" go-args 2@ " evaluate
266         direct-ram-boot-base 0
267         s" true state-valid ! " evaluate
268         s" disable-watchdog go-64" evaluate
269     THEN
270 ;
271
272 8e8 cp
273
274 : check-boot-from-ram
275     s" qemu,boot-kernel" get-chosen IF
276         decode-int -rot decode-int -rot ( n1 n2 p s )
277         decode-int -rot decode-int -rot ( n1 n2 n3 n4 p s )
278         2drop
279         swap 20 << or to direct-ram-boot-size
280         swap 20 << or to direct-ram-boot-base
281         ." Detected RAM kernel at " direct-ram-boot-base .
282         ." (" direct-ram-boot-size . ." bytes) "
283         \ Override the boot-command word without touching the
284         \ nvram environment
285         s" boot-command" $create " (boot-ram)" env-string
286     THEN
287 ;
288 check-boot-from-ram
289
290 8ff cp
291
292 #include <start-up.fs>
293
294 ."      "   \ Clear last checkpoint
295
296 #include <boot.fs>
297
298 cr .(   Welcome to Open Firmware)
299 cr
300 #include "copyright-oss.fs"
301 cr cr
302
303 \ this CATCH is to ensure the code bellow always executes:  boot may ABORT!
304 ' start-it CATCH drop
305
306 cr ." Ready!"