menu-commands.4th revision 281843
1275970Scy\ Copyright (c) 2006-2015 Devin Teske <dteske@FreeBSD.org>
2275970Scy\ All rights reserved.
3275970Scy\ 
4275970Scy\ Redistribution and use in source and binary forms, with or without
5275970Scy\ modification, are permitted provided that the following conditions
6275970Scy\ are met:
7275970Scy\ 1. Redistributions of source code must retain the above copyright
8275970Scy\    notice, this list of conditions and the following disclaimer.
9275970Scy\ 2. Redistributions in binary form must reproduce the above copyright
10275970Scy\    notice, this list of conditions and the following disclaimer in the
11290000Sglebius\    documentation and/or other materials provided with the distribution.
12275970Scy\ 
13275970Scy\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14275970Scy\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15275970Scy\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16275970Scy\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17275970Scy\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18275970Scy\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19275970Scy\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20275970Scy\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21275970Scy\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22275970Scy\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23275970Scy\ SUCH DAMAGE.
24275970Scy\ 
25275970Scy\ $FreeBSD: stable/10/sys/boot/forth/menu-commands.4th 281843 2015-04-22 01:08:40Z dteske $
26275970Scy
27275970Scymarker task-menu-commands.4th
28275970Scy
29275970Scyinclude /boot/menusets.4th
30275970Scy
31275970Scyonly forth definitions
32275970Scy
33275970Scyvariable kernel_state
34275970Scyvariable root_state
35275970Scy0 kernel_state !
36275970Scy0 root_state !
37275970Scy
38275970Scyalso menu-namespace also menu-command-helpers
39275970Scy
40275970Scy\ 
41275970Scy\ Boot
42275970Scy\ 
43275970Scy
44275970Scy: init_boot ( N -- N )
45275970Scy	dup
46275970Scy	s" boot_single" getenv -1 <> if
47275970Scy		drop ( n n c-addr -- n n ) \ unused
48275970Scy		toggle_menuitem ( n n -- n n )
49275970Scy		s" set menu_keycode[N]=115" \ base command to execute
50275970Scy	else
51275970Scy		s" set menu_keycode[N]=98" \ base command to execute
52275970Scy	then
53275970Scy	17 +c! \ replace 'N' with ASCII numeral
54275970Scy	evaluate
55275970Scy;
56275970Scy
57275970Scy\ 
58275970Scy\ Alternate Boot
59275970Scy\ 
60275970Scy
61275970Scy: init_altboot ( N -- N )
62275970Scy	dup
63275970Scy	s" boot_single" getenv -1 <> if
64275970Scy		drop ( n c-addr -- n ) \ unused
65275970Scy		toggle_menuitem ( n -- n )
66275970Scy		s" set menu_keycode[N]=109" \ base command to execute
67275970Scy	else
68275970Scy		s" set menu_keycode[N]=115" \ base command to execute
69275970Scy	then
70275970Scy	17 +c! \ replace 'N' with ASCII numeral
71275970Scy	evaluate
72275970Scy;
73275970Scy
74275970Scy: altboot ( N -- NOTREACHED )
75275970Scy	s" boot_single" 2dup getenv -1 <> if
76275970Scy		drop ( c-addr/u c-addr -- c-addr/u ) \ unused
77275970Scy		unsetenv ( c-addr/u -- )
78275970Scy	else
79275970Scy		2drop ( c-addr/u -- ) \ unused
80275970Scy		s" set boot_single=YES" evaluate
81275970Scy	then
82275970Scy	0 boot ( state -- )
83275970Scy;
84275970Scy
85275970Scy\ 
86275970Scy\ ACPI
87275970Scy\ 
88275970Scy
89275970Scy: acpi_enable ( -- )
90275970Scy	s" set acpi_load=YES" evaluate \ XXX deprecated but harmless
91275970Scy	s" set hint.acpi.0.disabled=0" evaluate
92275970Scy	s" loader.acpi_disabled_by_user" unsetenv
93275970Scy;
94275970Scy
95275970Scy: acpi_disable ( -- )
96275970Scy	s" acpi_load" unsetenv \ XXX deprecated but harmless
97275970Scy	s" set hint.acpi.0.disabled=1" evaluate
98275970Scy	s" set loader.acpi_disabled_by_user=1" evaluate
99275970Scy;
100275970Scy
101275970Scy: toggle_acpi ( N -- N TRUE )
102275970Scy
103275970Scy	\ Make changes effective _before_ calling menu-redraw
104275970Scy
105275970Scy	acpienabled? if
106275970Scy		acpi_disable
107275970Scy	else
108275970Scy		acpi_enable
109275970Scy	then
110275970Scy
111275970Scy	menu-redraw
112275970Scy
113275970Scy	TRUE \ loop menu again
114275970Scy;
115275970Scy
116290000Sglebius\ 
117310419Sdelphij\ Safe Mode
118310419Sdelphij\ 
119310419Sdelphij
120310419Sdelphij: safemode_enabled? ( -- flag )
121310419Sdelphij	s" kern.smp.disabled" getenv -1 <> dup if
122290000Sglebius		swap drop ( c-addr flag -- flag )
123290000Sglebius	then
124290000Sglebius;
125290000Sglebius
126290000Sglebius: safemode_enable ( -- )
127290000Sglebius	s" set kern.smp.disabled=1" evaluate
128310419Sdelphij	s" set hw.ata.ata_dma=0" evaluate
129290000Sglebius	s" set hw.ata.atapi_dma=0" evaluate
130290000Sglebius	s" set hw.ata.wc=0" evaluate
131290000Sglebius	s" set hw.eisa_slots=0" evaluate
132310419Sdelphij	s" set kern.eventtimer.periodic=1" evaluate
133310419Sdelphij	s" set kern.geom.part.check_integrity=0" evaluate
134310419Sdelphij;
135290000Sglebius
136290000Sglebius: safemode_disable ( -- )
137290000Sglebius	s" kern.smp.disabled" unsetenv
138290000Sglebius	s" hw.ata.ata_dma" unsetenv
139275970Scy	s" hw.ata.atapi_dma" unsetenv
140275970Scy	s" hw.ata.wc" unsetenv
141275970Scy	s" hw.eisa_slots" unsetenv
142275970Scy	s" kern.eventtimer.periodic" unsetenv
143275970Scy	s" kern.geom.part.check_integrity" unsetenv
144275970Scy;
145275970Scy
146275970Scy: init_safemode ( N -- N )
147275970Scy	safemode_enabled? if
148275970Scy		toggle_menuitem ( n -- n )
149275970Scy	then
150275970Scy;
151290000Sglebius
152290000Sglebius: toggle_safemode ( N -- N TRUE )
153275970Scy	toggle_menuitem
154275970Scy
155275970Scy	\ Now we're going to make the change effective
156275970Scy
157275970Scy	dup toggle_stateN @ 0= if
158275970Scy		safemode_disable
159275970Scy	else
160275970Scy		safemode_enable
161275970Scy	then
162275970Scy
163275970Scy	menu-redraw
164275970Scy
165290000Sglebius	TRUE \ loop menu again
166275970Scy;
167275970Scy
168275970Scy\ 
169275970Scy\ Single User Mode
170275970Scy\ 
171275970Scy
172275970Scy: singleuser_enabled? ( -- flag )
173275970Scy	s" boot_single" getenv -1 <> dup if
174275970Scy		swap drop ( c-addr flag -- flag )
175275970Scy	then
176275970Scy;
177275970Scy
178275970Scy: singleuser_enable ( -- )
179275970Scy	s" set boot_single=YES" evaluate
180275970Scy;
181275970Scy
182275970Scy: singleuser_disable ( -- )
183275970Scy	s" boot_single" unsetenv
184275970Scy;
185275970Scy
186275970Scy: init_singleuser ( N -- N )
187275970Scy	singleuser_enabled? if
188275970Scy		toggle_menuitem ( n -- n )
189275970Scy	then
190275970Scy;
191275970Scy
192275970Scy: toggle_singleuser ( N -- N TRUE )
193275970Scy	toggle_menuitem
194275970Scy	menu-redraw
195275970Scy
196275970Scy	\ Now we're going to make the change effective
197275970Scy
198275970Scy	dup toggle_stateN @ 0= if
199275970Scy		singleuser_disable
200275970Scy	else
201275970Scy		singleuser_enable
202275970Scy	then
203275970Scy
204275970Scy	TRUE \ loop menu again
205275970Scy;
206275970Scy
207275970Scy\ 
208275970Scy\ Verbose Boot
209275970Scy\ 
210275970Scy
211275970Scy: verbose_enabled? ( -- flag )
212275970Scy	s" boot_verbose" getenv -1 <> dup if
213275970Scy		swap drop ( c-addr flag -- flag )
214275970Scy	then
215275970Scy;
216275970Scy
217275970Scy: verbose_enable ( -- )
218275970Scy	s" set boot_verbose=YES" evaluate
219275970Scy;
220275970Scy
221275970Scy: verbose_disable ( -- )
222275970Scy	s" boot_verbose" unsetenv
223275970Scy;
224275970Scy
225275970Scy: init_verbose ( N -- N )
226275970Scy	verbose_enabled? if
227275970Scy		toggle_menuitem ( n -- n )
228275970Scy	then
229275970Scy;
230275970Scy
231275970Scy: toggle_verbose ( N -- N TRUE )
232275970Scy	toggle_menuitem
233275970Scy	menu-redraw
234290000Sglebius
235290000Sglebius	\ Now we're going to make the change effective
236275970Scy
237275970Scy	dup toggle_stateN @ 0= if
238275970Scy		verbose_disable
239275970Scy	else
240275970Scy		verbose_enable
241275970Scy	then
242275970Scy
243275970Scy	TRUE \ loop menu again
244275970Scy;
245275970Scy
246275970Scy\ 
247275970Scy\ Escape to Prompt
248275970Scy\ 
249275970Scy
250275970Scy: goto_prompt ( N -- N FALSE )
251275970Scy
252275970Scy	s" set autoboot_delay=NO" evaluate
253275970Scy
254275970Scy	cr
255275970Scy	." To get back to the menu, type `menu' and press ENTER" cr
256275970Scy	." or type `boot' and press ENTER to start FreeBSD." cr
257275970Scy	cr
258275970Scy
259275970Scy	FALSE \ exit the menu
260275970Scy;
261275970Scy
262275970Scy\ 
263275970Scy\ Cyclestate (used by kernel/root below)
264275970Scy\ 
265275970Scy
266275970Scy: init_cyclestate ( N K -- N )
267275970Scy	over cycle_stateN ( n k -- n k addr )
268275970Scy	begin
269275970Scy		tuck @  ( n k addr -- n addr k c )
270275970Scy		over <> ( n addr k c -- n addr k 0|-1 )
271275970Scy	while
272275970Scy		rot ( n addr k -- addr k n )
273275970Scy		cycle_menuitem
274275970Scy		swap rot ( addr k n -- n k addr )
275275970Scy	repeat
276275970Scy	2drop ( n k addr -- n )
277275970Scy;
278275970Scy
279275970Scy\
280275970Scy\ Kernel
281275970Scy\ 
282275970Scy
283275970Scy: init_kernel ( N -- N )
284275970Scy	kernel_state @  ( n -- n k )
285275970Scy	init_cyclestate ( n k -- n )
286275970Scy;
287275970Scy
288275970Scy: activate_kernel ( N -- N )
289275970Scy	dup cycle_stateN @	( n -- n n2 )
290275970Scy	dup kernel_state !	( n n2 -- n n2 )  \ copy for re-initialization
291275970Scy	48 +			( n n2 -- n n2' ) \ kernel_state to ASCII num
292275970Scy
293275970Scy	s" set kernel=${kernel_prefix}${kernel[N]}${kernel_suffix}"
294275970Scy	36 +c!		( n n2 c-addr/u -- n c-addr/u ) \ 'N' to ASCII num
295275970Scy	evaluate	( n c-addr/u -- n ) \ sets $kernel to full kernel-path
296275970Scy;
297275970Scy
298275970Scy: cycle_kernel ( N -- N TRUE )
299275970Scy	cycle_menuitem	\ cycle cycle_stateN to next value
300275970Scy	activate_kernel \ apply current cycle_stateN
301275970Scy	menu-redraw	\ redraw menu
302275970Scy	TRUE		\ loop menu again
303275970Scy;
304275970Scy
305275970Scy\ 
306275970Scy\ Root
307275970Scy\ 
308275970Scy
309275970Scy: init_root ( N -- N )
310275970Scy	root_state @    ( n -- n k )
311275970Scy	init_cyclestate ( n k -- n )
312275970Scy;
313275970Scy
314275970Scy: activate_root ( N -- N )
315275970Scy	dup cycle_stateN @	( n -- n n2 )
316275970Scy	dup root_state !	( n n2 -- n n2 )  \ copy for re-initialization
317275970Scy	48 +			( n n2 -- n n2' ) \ root_state to ASCII num
318275970Scy
319275970Scy	s" set root=${root_prefix}${root[N]}${root_suffix}"
320275970Scy	30 +c!		( n n2 c-addr/u -- n c-addr/u ) \ 'N' to ASCII num
321275970Scy	evaluate	( n c-addr/u -- n ) \ sets $root to full kernel-path
322275970Scy;
323275970Scy
324275970Scy: cycle_root ( N -- N TRUE )
325275970Scy	cycle_menuitem	\ cycle cycle_stateN to next value
326275970Scy	activate_root	\ apply current cycle_stateN
327275970Scy	menu-redraw	\ redraw menu
328275970Scy	TRUE		\ loop menu again
329275970Scy;
330275970Scy
331275970Scy\ 
332275970Scy\ Menusets
333275970Scy\ 
334275970Scy
335275970Scy: goto_menu ( N M -- N TRUE )
336275970Scy	menu-unset
337275970Scy	menuset-loadsetnum ( n m -- n )
338275970Scy	menu-redraw
339275970Scy	TRUE \ Loop menu again
340275970Scy;
341275970Scy
342275970Scy\ 
343275970Scy\ Defaults
344275970Scy\ 
345275970Scy
346275970Scy: set_default_boot_options ( N -- N TRUE )
347275970Scy	acpi_enable
348275970Scy	safemode_disable
349275970Scy	singleuser_disable
350275970Scy	verbose_disable
351275970Scy	2 goto_menu
352275970Scy;
353275970Scy
354275970Scyonly forth definitions
355275970Scy