Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / start-up.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 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 : (boot) ( -- )
14    s" Executing following boot-command: "
15    boot-command $cat nvramlog-write-string-cr
16    s" boot-command" evaluate      \ get boot command
17    ['] evaluate catch ?dup IF     \ and execute it
18       ." boot attempt returned: "
19       abort"-str @ count type cr
20       nip nip                     \ drop string from 1st evaluate
21       throw
22    THEN
23 ;
24
25 \ Note: The following ESC sequences has to be handled:
26 \     1B 4F 50
27 \     1B 5B 31 31 7E
28
29 \ Reads and converts the function key.
30 \ key = F1 -- n = 1
31 : (function-key) ( -- n )
32    key? IF
33       key CASE
34          50  OF 1 ENDOF
35          7e  OF 1 ENDOF
36          dup OF 0 ENDOF
37       ENDCASE
38    THEN
39 ;
40
41 \ Checks if an ESC sequence occurs.
42 : (esc-sequence) ( -- n )
43    key? IF
44       key CASE
45           4f  OF (function-key) ENDOF
46           5b  OF
47              key key (function-key) ENDOF
48           dup OF 0 ENDOF
49        ENDCASE
50    THEN
51 ;
52
53 : (s-pressed) ( -- )
54    s" An 's' has been pressed. Entering Open Firmware Prompt"
55    nvramlog-write-string-cr
56 ;
57
58 : (boot?) ( -- )
59    of-prompt? not auto-boot? and IF
60       (boot)
61    THEN
62 ;
63
64
65 #include "sms/sms-load.fs"
66
67
68 \ Watchdog will be rearmed during load if use-load-watchdog variable is TRUE
69 TRUE VALUE use-load-watchdog?
70
71 1 value my-boot-dev
72 1 value digit-val
73 0 value boot-dev-no
74
75 : boot-selected
76    1 to my-boot-dev
77    BEGIN parse-word dup WHILE
78       boot-dev-no my-boot-dev = IF
79          s" boot " 2swap $cat
80          ['] evaluate catch ?dup IF     \ and execute it
81             ." boot attempt returned: "
82             abort"-str @ count type cr
83             throw
84          THEN
85          0 0 load-list 2!
86          UNLOOP EXIT
87       ELSE
88          2drop
89       THEN
90       my-boot-dev 1 + to my-boot-dev
91    REPEAT 2drop 0 0 load-list 2!
92
93    (boot)
94 ;
95
96 : boot-start
97    \ Remove multiple F12 key presses if any
98    BEGIN key? WHILE
99       key drop
100    REPEAT
101
102    decimal
103    BEGIN parse-word dup WHILE
104       my-boot-dev (u.) s" . " $cat type 2dup type ." : " de-alias type cr
105       my-boot-dev 1 + to my-boot-dev
106    REPEAT 2drop 0 0 load-list 2!
107
108    cr BEGIN KEY dup emit
109       dup isdigit IF
110          dup 30 - to digit-val
111          boot-dev-no a * digit-val + to boot-dev-no
112       THEN
113    d = UNTIL
114
115    boot-dev-no my-boot-dev < IF
116       s" boot-selected " s" $bootdev" evaluate $cat strdup evaluate
117    ELSE
118       ." Invalid choice!" cr
119    THEN
120    hex
121 ;
122
123 : boot-menu-start
124    ." Select boot device:" cr cr
125    s" boot-start " s" $bootdev" evaluate $cat strdup evaluate
126 ;
127
128 : boot-menu-enabled? ( -- true|false )
129    s" qemu,boot-menu" get-chosen IF
130       decode-int 1 = IF
131          2drop TRUE EXIT
132       THEN
133       2drop
134    THEN
135    FALSE
136 ;
137
138 : f12-pressed?
139    34 = >r 32 = r> and IF
140       TRUE
141    ELSE
142       FALSE
143    THEN
144 ;
145
146 : start-it ( -- )
147    key? IF
148       key CASE
149          [char] s  OF (s-pressed) ENDOF
150          1b        OF
151              (esc-sequence) CASE
152                  1   OF
153                         console-clean-fifo
154                         f12-pressed? boot-menu-enabled? and IF
155                            boot-menu-start
156                         ELSE
157                            (boot?)
158                         THEN
159                      ENDOF
160                  dup OF (boot?) ENDOF
161              ENDCASE
162          ENDOF
163          dup OF (boot?) ENDOF
164       ENDCASE
165    ELSE
166       (boot?)
167    THEN
168
169    disable-watchdog  FALSE to use-load-watchdog?
170    .banner
171 ;