Print this page
11581 'debug' loader option is a little obscure
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Rob Johnston <rob.johnston@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/boot/sys/boot/forth/menu-commands.4th
+++ new/usr/src/boot/sys/boot/forth/menu-commands.4th
1 1 \ Copyright (c) 2006-2015 Devin Teske <dteske@FreeBSD.org>
2 2 \ All rights reserved.
3 3 \
4 4 \ Redistribution and use in source and binary forms, with or without
5 5 \ modification, are permitted provided that the following conditions
6 6 \ are met:
7 7 \ 1. Redistributions of source code must retain the above copyright
8 8 \ notice, this list of conditions and the following disclaimer.
9 9 \ 2. Redistributions in binary form must reproduce the above copyright
10 10 \ notice, this list of conditions and the following disclaimer in the
11 11 \ documentation and/or other materials provided with the distribution.
12 12 \
13 13 \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 14 \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 15 \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 16 \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 18 \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 19 \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 20 \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 21 \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 22 \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 23 \ SUCH DAMAGE.
24 24 \
25 25 \ Copyright 2015 Toomas Soome <tsoome@me.com>
26 26 \ Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
27 +\ Copyright 2019 Joyent, Inc.
27 28
28 29 marker task-menu-commands.4th
29 30
30 31 include /boot/forth/menusets.4th
31 32
32 33 only forth definitions
33 34
34 35 variable osconsole_state
35 36 variable acpi_state
36 37 variable kernel_state
37 38 variable root_state
38 39 variable kmdb_state
39 -variable debug_state
40 +variable drop_into_kmdb_state
40 41 0 kmdb_state !
41 -0 debug_state !
42 +0 drop_into_kmdb_state !
42 43 0 osconsole_state !
43 44 0 acpi_state !
44 45 0 kernel_state !
45 46 0 root_state !
46 47
47 48 also menu-namespace also menu-command-helpers
48 49
49 50 \
50 51 \ Boot
51 52 \
52 53
53 54 : init_boot ( N -- N )
54 55 dup
55 56 s" smartos" getenv? if
56 57 s" set menu_keycode[N]=98" \ base command to execute
57 58 else
58 59 s" boot_single" getenv -1 <> if
59 60 drop ( n n c-addr -- n n ) \ unused
60 61 toggle_menuitem ( n n -- n n )
61 62 s" set menu_keycode[N]=115" \ base command to execute
62 63 else
63 64 s" set menu_keycode[N]=98" \ base command to execute
64 65 then
65 66 then
66 67 17 +c! \ replace 'N' with ASCII numeral
67 68 evaluate
68 69 ;
69 70
70 71 \
71 72 \ Alternate Boot
72 73 \
73 74
74 75 : init_altboot ( N -- N )
75 76 dup
76 77 s" smartos" getenv? if
77 78 s" set menu_keycode[N]=114" \ base command to execute
78 79 else
79 80 s" boot_single" getenv -1 <> if
80 81 drop ( n c-addr -- n ) \ unused
81 82 toggle_menuitem ( n -- n )
82 83 s" set menu_keycode[N]=109" \ base command to execute
83 84 else
84 85 s" set menu_keycode[N]=115" \ base command to execute
85 86 then
86 87 then
87 88 17 +c! \ replace 'N' with ASCII numeral
88 89 evaluate
89 90 ;
90 91
91 92 : altboot ( N -- NOTREACHED )
92 93 s" smartos" getenv? if
93 94 s" alt-boot-args" getenv dup -1 <> if
94 95 s" boot-args" setenv ( c-addr/u -- )
95 96 then
96 97 ." NoInstall/Recovery mode boot. login/pw: root/root" cr
97 98 else
98 99 s" boot_single" 2dup getenv -1 <> if
99 100 drop ( c-addr/u c-addr -- c-addr/u ) \ unused
100 101 unsetenv ( c-addr/u -- )
101 102 else
102 103 2drop ( c-addr/u -- ) \ unused
103 104 s" set boot_single=YES" evaluate
104 105 then
105 106 then
106 107 0 boot ( state -- )
107 108 ;
108 109
109 110 \
110 111 \ Single User Mode
111 112 \
112 113
113 114 : singleuser_enabled? ( -- flag )
114 115 s" boot_single" getenv -1 <> dup if
115 116 swap drop ( c-addr flag -- flag )
116 117 then
117 118 ;
118 119
119 120 : singleuser_enable ( -- )
120 121 s" set boot_single=YES" evaluate
121 122 ;
122 123
123 124 : singleuser_disable ( -- )
124 125 s" boot_single" unsetenv
125 126 ;
126 127
127 128 : init_singleuser ( N -- N )
128 129 singleuser_enabled? if
129 130 toggle_menuitem ( n -- n )
130 131 then
131 132 ;
132 133
133 134 : toggle_singleuser ( N -- N TRUE )
134 135 toggle_menuitem
135 136 menu-redraw
136 137
137 138 \ Now we're going to make the change effective
138 139
139 140 dup toggle_stateN @ 0= if
140 141 singleuser_disable
141 142 else
142 143 singleuser_enable
143 144 then
144 145
145 146 TRUE \ loop menu again
146 147 ;
147 148
148 149 \
149 150 \ Verbose Boot
150 151 \
151 152
152 153 : verbose_enabled? ( -- flag )
153 154 s" boot_verbose" getenv -1 <> dup if
154 155 swap drop ( c-addr flag -- flag )
155 156 then
156 157 ;
157 158
158 159 : verbose_enable ( -- )
159 160 s" set boot_verbose=YES" evaluate
160 161 ;
161 162
162 163 : verbose_disable ( -- )
163 164 s" boot_verbose" unsetenv
164 165 ;
165 166
166 167 : init_verbose ( N -- N )
167 168 verbose_enabled? if
168 169 toggle_menuitem ( n -- n )
169 170 then
170 171 ;
171 172
172 173 : toggle_verbose ( N -- N TRUE )
173 174 toggle_menuitem
174 175 menu-redraw
175 176
176 177 \ Now we're going to make the change effective
177 178
178 179 dup toggle_stateN @ 0= if
179 180 verbose_disable
180 181 else
181 182 verbose_enable
182 183 then
183 184
184 185 TRUE \ loop menu again
185 186 ;
186 187
187 188 \
188 189 \ kmdb
189 190 \
190 191
191 192 : kmdb_enabled? ( -- flag )
192 193 s" boot_kmdb" getenv -1 <> dup if
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
193 194 swap drop ( c-addr flag -- flag )
194 195 then
195 196 ;
196 197
197 198 : kmdb_enable ( -- )
198 199 s" set boot_kmdb=YES" evaluate
199 200 ;
200 201
201 202 : kmdb_disable ( -- )
202 203 s" boot_kmdb" unsetenv
203 - s" boot_debug" unsetenv
204 + s" boot_drop_into_kmdb" unsetenv
204 205 ;
205 206
206 207 : init_kmdb ( N -- N )
207 - dup kmdb_state ! \ store entry number for kmdb+debug
208 + dup kmdb_state ! \ store entry number for kmdb+drop_into_kmdb
208 209 kmdb_enabled? if
209 210 toggle_menuitem ( n -- n )
210 211 then
211 212 ;
212 213
213 214 : toggle_kmdb ( N -- N TRUE )
214 215 toggle_menuitem
215 216 dup toggle_stateN @ 0= if ( kmdb is not set )
216 - debug_state @ if ( debug is set? )
217 - debug_state @ toggle_stateN @ if ( debug is enabled? )
218 - debug_state @ toggle_menuitem drop
217 + drop_into_kmdb_state @ if ( drop_into_kmdb is set? )
218 + drop_into_kmdb_state @ toggle_stateN @ if ( drop_into_kmdb is enabled? )
219 + drop_into_kmdb_state @ toggle_menuitem drop
219 220 then
220 221 then
221 222 then
222 223 menu-redraw
223 224
224 225 \ Now we're going to make the change effective
225 226
226 227 dup toggle_stateN @ 0= if
227 228 kmdb_disable
228 229 else
229 230 kmdb_enable
230 231 then
231 232
232 233 TRUE \ loop menu again
233 234 ;
234 235
235 236 \
236 -\ kmdb + debug
237 +\ drop into kmdb
237 238 \
238 239
239 -: debug_disable ( -- )
240 - s" boot_debug" unsetenv
240 +: drop_into_kmdb_disable ( -- )
241 + s" boot_drop_into_kmdb" unsetenv
241 242 ;
242 243
243 -: debug_enabled? ( -- flag )
244 - \ -d is only allowed with -k
245 - s" boot_debug" getenv -1 <> kmdb_enabled? and dup if
244 +: drop_into_kmdb_enabled? ( -- flag )
245 + \ -d is only allowed with -k
246 + s" boot_drop_into_kmdb" getenv -1 <> kmdb_enabled? and dup if
246 247 swap drop ( c-addr flag -- flag )
247 248 else
248 - debug_disable \ make sure env is not set
249 + drop_into_kmdb_disable \ make sure env is not set
249 250 then
250 251 ;
251 252
252 -: debug_enable ( -- )
253 +: drop_into_kmdb_enable ( -- )
253 254 kmdb_enable
254 - s" set boot_debug=YES" evaluate
255 + s" set boot_drop_into_kmdb=YES" evaluate
255 256 ;
256 257
257 -: init_debug ( N -- N )
258 - dup debug_state ! \ store entry number for kmdb
259 - kmdb_enabled? debug_enabled? and if
258 +: init_drop_into_kmdb ( N -- N )
259 + dup drop_into_kmdb_state ! \ store entry number for kmdb
260 + kmdb_enabled? drop_into_kmdb_enabled? and if
260 261 toggle_menuitem ( n -- n )
261 262 then
262 263 ;
263 264
264 -: toggle_debug ( N -- N TRUE )
265 +: toggle_drop_into_kmdb ( N -- N TRUE )
265 266 toggle_menuitem
266 267 kmdb_enabled? 0= if
267 268 kmdb_state @ toggle_menuitem drop
268 269 then
269 270 menu-redraw
270 271
271 272 \ Now we're going to make the change effective
272 273
273 274 dup toggle_stateN @ 0= if
274 - debug_disable
275 + drop_into_kmdb_disable
275 276 else
276 - debug_enable
277 + drop_into_kmdb_enable
277 278 then
278 279
279 280 TRUE \ loop menu again
280 281 ;
281 282
282 283 \
283 284 \ Reconfiguration boot
284 285 \
285 286
286 287 : reconfigure_enabled? ( -- flag )
287 288 s" boot_reconfigure" getenv -1 <> dup if
288 289 swap drop ( c-addr flag -- flag )
289 290 then
290 291 ;
291 292
292 293 : reconfigure_enable ( -- )
293 294 s" set boot_reconfigure=YES" evaluate
294 295 ;
295 296
296 297 : reconfigure_disable ( -- )
297 298 s" boot_reconfigure" unsetenv
298 299 ;
299 300
300 301 : init_reconfigure ( N -- N )
301 302 reconfigure_enabled? if
302 303 toggle_menuitem ( n -- n )
303 304 then
304 305 ;
305 306
306 307 : toggle_reconfigure ( N -- N TRUE )
307 308 toggle_menuitem
308 309 menu-redraw
309 310
310 311 \ Now we're going to make the change effective
311 312
312 313 dup toggle_stateN @ 0= if
313 314 reconfigure_disable
314 315 else
315 316 reconfigure_enable
316 317 then
317 318
318 319 TRUE \ loop menu again
319 320 ;
320 321
321 322 \
322 323 \ Escape to Prompt
323 324 \
324 325
325 326 : goto_prompt ( N -- N FALSE )
326 327
327 328 s" set autoboot_delay=NO" evaluate
328 329
329 330 cr
330 331 ." To get back to the menu, type `menu' and press ENTER" cr
331 332 ." or type `boot' and press ENTER to start illumos." cr
332 333 cr
333 334
334 335 FALSE \ exit the menu
335 336 ;
336 337
337 338 \
338 339 \ Cyclestate (used by osconsole/acpi/kernel/root below)
339 340 \
340 341
341 342 : init_cyclestate ( N K -- N )
342 343 over cycle_stateN ( n k -- n k addr )
343 344 begin
344 345 tuck @ ( n k addr -- n addr k c )
345 346 over <> ( n addr k c -- n addr k 0|-1 )
346 347 while
347 348 rot ( n addr k -- addr k n )
348 349 cycle_menuitem
349 350 swap rot ( addr k n -- n k addr )
350 351 repeat
351 352 2drop ( n k addr -- n )
352 353 ;
353 354
354 355 \
355 356 \ OS Console
356 357 \ getenv os_console, if not set getenv console, if not set, default to "text"
357 358 \ allowed serial consoles: ttya .. ttyd
358 359 \ if new console will be added (graphics?), this section needs to be updated
359 360 \
360 361 : init_osconsole ( N -- N )
361 362 s" os_console" getenv dup -1 = if
362 363 drop
363 364 s" console" getenv dup -1 = if
364 365 drop 0 \ default to text
365 366 then
366 367 then ( n c-addr/u | n 0 )
367 368
368 369 dup 0<> if ( n c-addr/u )
369 370 2dup s" ttyd" compare 0= if
370 371 2drop 4
371 372 else 2dup s" ttyc" compare 0= if
372 373 2drop 3
373 374 else 2dup s" ttyb" compare 0= if
374 375 2drop 2
375 376 else 2dup s" ttya" compare 0= if
376 377 2drop 1
377 378 else
378 379 2drop 0 \ anything else defaults to text
379 380 then then then then
380 381 then
381 382 osconsole_state !
382 383 ;
383 384
384 385 : activate_osconsole ( N -- N )
385 386 dup cycle_stateN @ ( n -- n n2 )
386 387 dup osconsole_state ! ( n n2 -- n n2 ) \ copy for re-initialization
387 388
388 389 case
389 390 0 of s" text" endof
390 391 1 of s" ttya" endof
391 392 2 of s" ttyb" endof
392 393 3 of s" ttyc" endof
393 394 4 of s" ttyd" endof
394 395 dup s" unknown state: " type . cr
395 396 endcase
396 397 s" os_console" setenv
397 398 ;
398 399
399 400 : cycle_osconsole ( N -- N TRUE )
400 401 cycle_menuitem \ cycle cycle_stateN to next value
401 402 activate_osconsole \ apply current cycle_stateN
402 403 menu-redraw \ redraw menu
403 404 TRUE \ loop menu again
404 405 ;
405 406
406 407 \
407 408 \ ACPI
408 409 \
409 410 : init_acpi ( N -- N )
410 411 s" acpi-user-options" getenv dup -1 <> if
411 412 evaluate \ use ?number parse step
412 413
413 414 \ translate option to cycle state
414 415 case
415 416 1 of 1 acpi_state ! endof
416 417 2 of 2 acpi_state ! endof
417 418 4 of 3 acpi_state ! endof
418 419 8 of 4 acpi_state ! endof
419 420 0 acpi_state !
420 421 endcase
421 422 else
422 423 drop
423 424 then
424 425 ;
425 426
426 427 : activate_acpi ( N -- N )
427 428 dup cycle_stateN @ ( n -- n n2 )
428 429 dup acpi_state ! ( n n2 -- n n2 ) \ copy for re-initialization
429 430
430 431 \ if N == 0, it's default, just unset env.
431 432 dup 0= if
432 433 drop
433 434 s" acpi-user-options" unsetenv
434 435 else
435 436 case
436 437 1 of s" 1" endof
437 438 2 of s" 2" endof
438 439 3 of s" 4" endof
439 440 4 of s" 8" endof
440 441 endcase
441 442 s" acpi-user-options" setenv
442 443 then
443 444 ;
444 445
445 446 : cycle_acpi ( N -- N TRUE )
446 447 cycle_menuitem \ cycle cycle_stateN to next value
447 448 activate_acpi \ apply current cycle_stateN
448 449 menu-redraw \ redraw menu
449 450 TRUE \ loop menu again
450 451 ;
451 452
452 453 \
453 454 \ Kernel
454 455 \
455 456
456 457 : init_kernel ( N -- N )
457 458 kernel_state @ ( n -- n k )
458 459 init_cyclestate ( n k -- n )
459 460 ;
460 461
461 462 : activate_kernel ( N -- N )
462 463 dup cycle_stateN @ ( n -- n n2 )
463 464 dup kernel_state ! ( n n2 -- n n2 ) \ copy for re-initialization
464 465 48 + ( n n2 -- n n2' ) \ kernel_state to ASCII num
465 466
466 467 s" set kernel=${kernel_prefix}${kernel[N]}${kernel_suffix}"
467 468 36 +c! ( n n2 c-addr/u -- n c-addr/u ) \ 'N' to ASCII num
468 469 evaluate ( n c-addr/u -- n ) \ sets $kernel to full kernel-path
469 470 ;
470 471
471 472 : cycle_kernel ( N -- N TRUE )
472 473 cycle_menuitem \ cycle cycle_stateN to next value
473 474 activate_kernel \ apply current cycle_stateN
474 475 menu-redraw \ redraw menu
475 476 TRUE \ loop menu again
476 477 ;
477 478
478 479 \
479 480 \ Root
480 481 \
481 482
482 483 : init_root ( N -- N )
483 484 root_state @ ( n -- n k )
484 485 init_cyclestate ( n k -- n )
485 486 ;
486 487
487 488 : activate_root ( N -- N )
488 489 dup cycle_stateN @ ( n -- n n2 )
489 490 dup root_state ! ( n n2 -- n n2 ) \ copy for re-initialization
490 491 48 + ( n n2 -- n n2' ) \ root_state to ASCII num
491 492
492 493 s" set root=${root_prefix}${root[N]}${root_suffix}"
493 494 30 +c! ( n n2 c-addr/u -- n c-addr/u ) \ 'N' to ASCII num
494 495 evaluate ( n c-addr/u -- n ) \ sets $root to full kernel-path
495 496 ;
496 497
497 498 : cycle_root ( N -- N TRUE )
498 499 cycle_menuitem \ cycle cycle_stateN to next value
499 500 activate_root \ apply current cycle_stateN
500 501 menu-redraw \ redraw menu
501 502 TRUE \ loop menu again
502 503 ;
503 504
504 505 \
505 506 \ Menusets
506 507 \
507 508
508 509 : goto_menu ( N M -- N TRUE )
509 510 menu-unset
510 511 menuset-loadsetnum ( n m -- n )
511 512 menu-redraw
512 513 TRUE \ Loop menu again
513 514 ;
514 515
515 516 \
↓ open down ↓ |
229 lines elided |
↑ open up ↑ |
516 517 \ Defaults
517 518 \
518 519
519 520 : unset_boot_options
520 521 0 acpi_state !
521 522 s" acpi-user-options" unsetenv
522 523 s" boot-args" unsetenv
523 524 s" boot_ask" unsetenv
524 525 singleuser_disable
525 526 verbose_disable
526 - kmdb_disable \ disables debug as well
527 + kmdb_disable \ disables drop_into_kmdb as well
527 528 reconfigure_disable
528 529 ;
529 530
530 531 : set_default_boot_options ( N -- N TRUE )
531 532 unset_boot_options
532 533 2 goto_menu
533 534 ;
534 535
535 536 \
536 537 \ Set boot environment defaults
537 538 \
538 539
539 540
540 541 : init_bootenv ( -- )
541 542 s" set menu_caption[1]=${bemenu_current}${zfs_be_active}" evaluate
542 543 s" set ansi_caption[1]=${beansi_current}${zfs_be_active}" evaluate
543 544 s" set menu_caption[2]=${bemenu_bootfs}${currdev}" evaluate
544 545 s" set ansi_caption[2]=${beansi_bootfs}${currdev}" evaluate
545 546 s" set menu_caption[3]=${bemenu_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}" evaluate
546 547 s" set ansi_caption[3]=${beansi_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}" evaluate
547 548 ;
548 549
549 550 \
550 551 \ Redraw the entire screen. A long BE name can corrupt the menu
551 552 \
552 553
553 554 : be_draw_screen
554 555 clear \ Clear the screen (in screen.4th)
555 556 print_version \ print version string (bottom-right; see version.4th)
556 557 draw-beastie \ Draw FreeBSD logo at right (in beastie.4th)
557 558 draw-brand \ Draw brand.4th logo at top (in brand.4th)
558 559 menu-init \ Initialize menu and draw bounding box (in menu.4th)
559 560 ;
560 561
561 562 \
562 563 \ Select a boot environment
563 564 \
564 565
565 566 : set_bootenv ( N -- N TRUE )
566 567 dup s" bootenv_root[E]" 13 +c! getenv
567 568 s" currdev" getenv compare 0= if
568 569 s" zfs_be_active" getenv type ." is already active"
569 570 else
570 571 dup s" set currdev=${bootenv_root[E]}" 27 +c! evaluate
571 572 dup s" bootenvmenu_caption[E]" 20 +c! getenv
572 573 s" zfs_be_active" setenv
573 574 ." Activating " s" currdev" getenv type cr
574 575 s" unload" evaluate
575 576 free-module-options
576 577 unset_boot_options
577 578 s" /boot/defaults/loader.conf" read-conf
578 579 s" /boot/loader.conf" read-conf
579 580 s" /boot/loader.conf.local" read-conf
580 581 init_bootenv
581 582
582 583 s" 1" s" zfs_be_currpage" setenv
583 584 s" be-set-page" evaluate
584 585 then
585 586
586 587 500 ms \ sleep so user can see the message
587 588 be_draw_screen
588 589 menu-redraw
589 590 TRUE
590 591 ;
591 592
592 593 \
593 594 \ Chainload this entry. Normally we do not return, in case of error
594 595 \ from chain load, we continue with normal menu code.
595 596 \
596 597
597 598 : set_be_chain ( N -- no return | N TRUE )
598 599 dup s" chain ${bootenv_root[E]}" 21 +c! evaluate catch drop
599 600
600 601 menu-redraw
601 602 TRUE
602 603 ;
603 604
604 605 \
605 606 \ Switch to the next page of boot environments
606 607 \
607 608
608 609 : set_be_page ( N -- N TRUE )
609 610 s" zfs_be_currpage" getenv dup -1 = if
610 611 drop s" 1"
611 612 else
612 613 s2n
613 614 1+ \ increment the page number
614 615 dup
615 616 s" zfs_be_pages" getenv
616 617 s2n
617 618 > if drop 1 then
618 619 n2s
619 620 then
620 621
621 622 s" zfs_be_currpage" setenv
622 623 s" be-set-page" evaluate
623 624 3 goto_menu
624 625 ;
625 626
626 627 only forth definitions
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX