kernel - More tty and devfs race fixes
[dragonfly.git] / sys / boot / forth / beastie.4th
1 \ Copyright (c) 2003 Scott Long <scottl@freebsd.org>
2 \ Copyright (c) 2003 Aleksander Fafula <alex@fafula.com>
3 \ All rights reserved.
4 \
5 \ Redistribution and use in source and binary forms, with or without
6 \ modification, are permitted provided that the following conditions
7 \ are met:
8 \ 1. Redistributions of source code must retain the above copyright
9 \    notice, this list of conditions and the following disclaimer.
10 \ 2. Redistributions in binary form must reproduce the above copyright
11 \    notice, this list of conditions and the following disclaimer in the
12 \    documentation and/or other materials provided with the distribution.
13 \
14 \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 \ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 \ SUCH DAMAGE.
25 \
26 \ $FreeBSD: src/sys/boot/forth/beastie.4th,v 1.7 2003/10/28 17:18:42 scottl Exp $
27
28 marker task-beastie.4th
29
30 include screen.4th
31 include frames.4th
32
33 hide
34
35 variable menuidx
36 variable menubllt
37 variable menuX
38 variable menuY
39 variable promptwidth
40
41 variable bootkey
42 variable bootacpikey
43 variable bootsafekey
44 variable bootverbosekey
45 variable bootahcikey
46 variable bootsinglekey
47 variable escapekey
48 variable rebootkey
49
50 46 constant dot
51
52 \ Fred, the official DragonFly BSD mascot.
53 \ He is 19 rows high and 34 columns wide
54 : technicolor-fred ( x y -- )
55         2dup at-xy ." " 1+
56         2dup at-xy ." " 1+
57         2dup at-xy ." ,--,           \e[31m|           \e[37m,--," 1+
58         2dup at-xy ." |   `-,       \e[31m,^,       \e[37m,-'   |" 1+
59         2dup at-xy ."  `,    `-,   \e[32m(\e[31m/ \\e[32m)   \e[37m,-'    ,'" 1+
60         2dup at-xy ."    `-,    `-,\e[31m/   \\e[37m,-'    ,-'" 1+
61         2dup at-xy ."       `------\e[31m(   )\e[37m------'" 1+
62         2dup at-xy ."   ,----------\e[31m(   )\e[37m----------," 1+
63         2dup at-xy ."  |        _,-\e[31m(   )\e[37m-,_        |" 1+
64         2dup at-xy ."   `-,__,-'   \e[31m\   /   \e[37m`-,__,-'" 1+
65         2dup at-xy ."               \e[31m| |" 1+
66         2dup at-xy ."               | |" 1+
67         2dup at-xy ."               | |" 1+
68         2dup at-xy ."               | |" 1+
69         2dup at-xy ."               | |" 1+
70         2dup at-xy ."               | |" 1+
71         2dup at-xy ."               `|'\e[0m" 1+
72         2dup at-xy ." " 1+
73              at-xy ."
74 ;
75
76 : boring-fred ( x y -- )
77         2dup at-xy ." " 1+
78         2dup at-xy ." " 1+
79         2dup at-xy ." ,--,           |           ,--," 1+
80         2dup at-xy ." |   `-,       ,^,       ,-'   |" 1+
81         2dup at-xy ."  `,    `-,   (/ \)   ,-'    ,'" 1+
82         2dup at-xy ."    `-,    `-,/   \,-'    ,-'" 1+
83         2dup at-xy ."       `------(   )------'" 1+
84         2dup at-xy ."   ,----------(   )----------," 1+
85         2dup at-xy ."  |        _,-(   )-,_        |" 1+
86         2dup at-xy ."   `-,__,-'   \   /   `-,__,-'" 1+
87         2dup at-xy ."               | |" 1+
88         2dup at-xy ."               | |" 1+
89         2dup at-xy ."               | |" 1+
90         2dup at-xy ."               | |" 1+
91         2dup at-xy ."               | |" 1+
92         2dup at-xy ."               | |" 1+
93         2dup at-xy ."               `|'" 1+
94         2dup at-xy ." " 1+
95              at-xy ."
96 ;
97
98 : print-fred ( x y -- )
99         s" loader_color" getenv
100         dup -1 = if
101                 drop
102                 boring-fred
103                 exit
104         then
105         s" YES" compare-insensitive 0<> if
106                 boring-fred
107                 exit
108         then
109         technicolor-fred
110 ;
111
112 : acpienabled? ( -- flag )
113         s" acpi_load" getenv
114         dup -1 = if
115                 drop false exit
116         then
117         s" YES" compare-insensitive 0<> if
118                 false exit
119         then
120         s" hint.acpi.0.disabled" getenv
121         dup -1 <> if
122                 s" 0" compare 0<> if
123                         false exit
124                 then
125         then
126         true
127 ;
128
129 : printmenuitem ( -- n )
130         menuidx @
131         1+ dup
132         menuidx !
133         menuY @ + dup menuX @ swap at-xy
134         menuidx @ .
135         menuX @ 1+ swap at-xy
136         menubllt @ emit
137         menuidx @ 48 +
138 ;
139
140 : fred-menu ( -- )
141         0 menuidx !
142         dot menubllt !
143         8 menuY !
144         5 menuX !
145         clear
146         46 4 print-fred
147         42 20 2 2 box
148         13 6 at-xy ." Welcome to DragonFly!"
149         printmenuitem ."  Boot DragonFly [default]" bootkey !
150         s" arch-i386" environment? if
151                 printmenuitem ."  Boot DragonFly with ACPI " bootacpikey !
152                 acpienabled? if
153                         ." disabled"
154                 else
155                         ." enabled"
156                 then
157         else
158                 -2 bootacpikey !
159         then
160         printmenuitem ."  Boot DragonFly in Safe Mode" bootsafekey !
161         printmenuitem ."  Boot DragonFly in single user mode" bootsinglekey !
162         printmenuitem ."  Boot DragonFly with verbose logging" bootverbosekey !
163         printmenuitem ."  Boot DragonFly without AHCI driver " bootahcikey !
164         printmenuitem ."  Escape to loader prompt" escapekey !
165         printmenuitem ."  Reboot" rebootkey !
166         menuX @ 20 at-xy
167         ." Select option, [Enter] for default"
168         menuX @ 21 at-xy
169         s" or [Space] to pause timer    " dup 2 - promptwidth !
170         type
171 ;
172
173 : tkey
174         dup
175         seconds +
176         begin 1 while
177                 over 0<> if
178                         dup seconds u< if
179                                 drop
180                                 -1
181                                 exit
182                         then
183                         menuX @ promptwidth @ + 21 at-xy dup seconds - .
184                 then
185                 key? if
186                         drop
187                         key
188                         exit
189                 then
190         50 ms
191         repeat
192 ;
193
194 set-current
195
196 : beastie-start
197         s" fred_disable" getenv
198         dup -1 <> if
199                 s" YES" compare-insensitive 0= if
200                         exit
201                 then
202         then
203         fred-menu
204         s" autoboot_delay" getenv
205         dup -1 = if
206                 drop
207                 10
208         else
209                 0 0 2swap >number drop drop drop
210         then
211         begin true while
212                 dup tkey
213                 0 25 at-xy
214                 dup 32 = if nip 0 swap then
215                 dup -1 = if 0 boot then
216                 dup 13 = if 0 boot then
217                 dup bootkey @ = if 0 boot then
218                 dup bootacpikey @ = if
219                         acpienabled? if
220                                 s" acpi_load" unsetenv
221                                 s" 1" s" hint.acpi.0.disabled" setenv
222                                 s" 1" s" loader.acpi_disabled_by_user" setenv
223                         else
224                                 s" YES" s" acpi_load" setenv
225                                 s" 0" s" hint.acpi.0.disabled" setenv
226                         then
227                         0 boot
228                 then
229                 dup bootsafekey @ = if
230                         s" arch-i386" environment? if
231                                 s" acpi_load" unsetenv
232                                 s" 1" s" hint.acpi.0.disabled" setenv
233                                 s" 1" s" loader.acpi_disabled_by_user" setenv
234                         then
235                         s" ehci_load" unsetenv
236                         s" 1" s" hint.ehci.0.disabled" setenv
237                         s" 1" s" loader.ehci_disabled_by_user" setenv
238                         s" 0" s" hw.ata.ata_dma" setenv
239                         s" 0" s" hw.ata.atapi_dma" setenv
240                         s" 0" s" hw.ata.wc" setenv
241                         s" 0" s" hw.eisa_slots" setenv
242                         0 boot
243                 then
244                 dup bootverbosekey @ = if
245                         s" YES" s" boot_verbose" setenv
246                         0 boot
247                 then
248                 dup bootahcikey @ = if
249                         s" YES" s" hint.ahci.disabled" setenv
250                         0 boot
251                 then
252                 dup bootsinglekey @ = if
253                         s" YES" s" boot_single" setenv
254                         0 boot
255                 then
256                 dup escapekey @ = if
257                         2drop
258                         s" NO" s" autoboot_delay" setenv
259                         exit
260                 then
261                 rebootkey @ = if 0 reboot then
262         repeat
263 ;
264
265 previous