menu-commands.4th revision 242667
1\ Copyright (c) 2006-2012 Devin Teske <dteske@FreeBSD.org>
2\ All rights reserved.
3\ 
4\ Redistribution and use in source and binary forms, with or without
5\ modification, are permitted provided that the following conditions
6\ are met:
7\ 1. Redistributions of source code must retain the above copyright
8\    notice, this list of conditions and the following disclaimer.
9\ 2. Redistributions in binary form must reproduce the above copyright
10\    notice, this list of conditions and the following disclaimer in the
11\    documentation and/or other materials provided with the distribution.
12\ 
13\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16\ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23\ SUCH DAMAGE.
24\ 
25\ $FreeBSD: head/sys/boot/forth/menu-commands.4th 242667 2012-11-06 19:26:36Z dteske $
26
27marker task-menu-commands.4th
28
29include /boot/menusets.4th
30
31variable kernel_state
32variable root_state
33
34: acpi_enable ( -- )
35	s" set acpi_load=YES" evaluate \ XXX deprecated but harmless
36	s" set hint.acpi.0.disabled=0" evaluate
37	s" loader.acpi_disabled_by_user" unsetenv
38;
39
40: acpi_disable ( -- )
41	s" acpi_load" unsetenv \ XXX deprecated but harmless
42	s" set hint.acpi.0.disabled=1" evaluate
43	s" set loader.acpi_disabled_by_user=1" evaluate
44;
45
46: toggle_acpi ( N -- N TRUE )
47
48	\ Make changes effective _before_ calling menu-redraw
49
50	acpienabled? if
51		acpi_disable
52	else
53		acpi_enable
54	then
55
56	menu-redraw
57
58	TRUE \ loop menu again
59;
60
61: init_safemode ( N -- N )
62	s" kern.smp.disabled" getenv -1 <> if
63		drop ( n c-addr -- n ) \ unused
64		toggle_menuitem ( n -- n )
65	then
66;
67
68: toggle_safemode ( N -- N TRUE )
69	toggle_menuitem
70
71	\ Now we're going to make the change effective
72
73	s" toggle_stateN @"      \ base name of toggle state var
74	-rot 2dup 12 + c! rot    \ replace 'N' with ASCII numeral
75
76	evaluate 0= if
77		s" kern.smp.disabled" unsetenv
78		s" hw.ata.ata_dma" unsetenv
79		s" hw.ata.atapi_dma" unsetenv
80		s" hw.ata.wc" unsetenv
81		s" hw.eisa_slots" unsetenv
82		s" kern.eventtimer.periodic" unsetenv
83		s" kern.geom.part.check_integrity" unsetenv
84	else
85		s" set kern.smp.disabled=1" evaluate
86		s" set hw.ata.ata_dma=0" evaluate
87		s" set hw.ata.atapi_dma=0" evaluate
88		s" set hw.ata.wc=0" evaluate
89		s" set hw.eisa_slots=0" evaluate
90		s" set kern.eventtimer.periodic=1" evaluate
91		s" set kern.geom.part.check_integrity=0" evaluate
92	then
93
94	menu-redraw
95
96	TRUE \ loop menu again
97;
98
99: init_singleuser ( N -- N )
100	s" boot_single" getenv -1 <> if
101		drop ( n c-addr -- n ) \ unused
102		toggle_menuitem ( n -- n )
103	then
104;
105
106: toggle_singleuser ( N -- N TRUE )
107	toggle_menuitem
108	menu-redraw
109
110	\ Now we're going to make the change effective
111
112	s" toggle_stateN @"      \ base name of toggle state var
113	-rot 2dup 12 + c! rot    \ replace 'N' with ASCII numeral
114
115	evaluate 0= if
116		s" boot_single" unsetenv
117	else
118		s" set boot_single=YES" evaluate
119	then
120
121	TRUE \ loop menu again
122;
123
124: init_verbose ( N -- N )
125	s" boot_verbose" getenv -1 <> if
126		drop ( n c-addr -- n ) \ unused
127		toggle_menuitem ( n -- n )
128	then
129;
130
131: toggle_verbose ( N -- N TRUE )
132	toggle_menuitem
133	menu-redraw
134
135	\ Now we're going to make the change effective
136
137	s" toggle_stateN @"      \ base name of toggle state var
138	-rot 2dup 12 + c! rot    \ replace 'N' with ASCII numeral
139
140	evaluate 0= if
141		s" boot_verbose" unsetenv
142	else
143		s" set boot_verbose=YES" evaluate
144	then
145
146	TRUE \ loop menu again
147;
148
149: goto_prompt ( N -- N FALSE )
150
151	s" set autoboot_delay=NO" evaluate
152
153	cr
154	." To get back to the menu, type `menu' and press ENTER" cr
155	." or type `boot' and press ENTER to start FreeBSD." cr
156	cr
157
158	FALSE \ exit the menu
159;
160
161: init_cyclestate ( N K -- N )
162	over                   ( n k -- n k n )
163	s" cycle_stateN"       ( n k n -- n k n c-addr u )
164	-rot tuck 11 + c! swap ( n k n c-addr u -- n k c-addr u )
165	evaluate               ( n k c-addr u -- n k addr )
166	begin
167		tuck @  ( n k addr -- n addr k c )
168		over <> ( n addr k c -- n addr k 0|-1 )
169	while
170		rot ( n addr k -- addr k n )
171		cycle_menuitem
172		swap rot ( addr k n -- n k addr )
173	repeat
174	2drop ( n k addr -- n )
175;
176
177: init_kernel ( N -- N )
178	kernel_state @  ( n -- n k )
179	init_cyclestate ( n k -- n )
180;
181
182: cycle_kernel ( N -- N TRUE )
183	cycle_menuitem
184	menu-redraw
185
186	\ Now we're going to make the change effective
187
188	s" cycle_stateN"         \ base name of array state var
189	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
190	evaluate                 \ translate name into address
191	@                        \ dereference address into value
192	dup kernel_state !       \ save a copy for re-initialization
193	48 +                     \ convert to ASCII numeral
194
195	s" set kernel=${kernel_prefix}${kernel[N]}${kernel_suffix}"
196	                          \ command to assemble full kernel-path
197	-rot tuck 36 + c! swap    \ replace 'N' with array index value
198	evaluate                  \ sets $kernel to full kernel-path
199
200	TRUE \ loop menu again
201;
202
203: init_root ( N -- N )
204	root_state @    ( n -- n k )
205	init_cyclestate ( n k -- n )
206;
207
208: cycle_root ( N -- N TRUE )
209	cycle_menuitem
210	menu-redraw
211
212	\ Now we're going to make the change effective
213
214	s" cycle_stateN"         \ base name of array state var
215	-rot 2dup 11 + c! rot    \ replace 'N' with ASCII numeral
216	evaluate                 \ translate name into address
217	@                        \ dereference address into value
218	dup root_state !         \ save a copy for re-initialization
219	48 +                     \ convert to ASCII numeral
220
221	s" set root=${root_prefix}${root[N]}${root_suffix}"
222	                          \ command to assemble root image-path
223	-rot tuck 30 + c! swap    \ replace 'N' with array index value
224	evaluate                  \ sets $kernel to full kernel-path
225
226	TRUE \ loop menu again
227;
228
229: goto_menu ( N M -- N TRUE )
230	menu-unset
231	menuset-loadsetnum ( n m -- n )
232	menu-redraw
233	TRUE \ Loop menu again
234;
235