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>


   4 
   5  Copyright (c) 2006-2015 Devin Teske <dteske@FreeBSD.org>  All rights
   6 reserved.   Redistribution and use in source and binary forms, with or without
   7  modification, are permitted provided that the following conditions  are met:
   8 1. Redistributions of source code must retain the above copyright     notice,
   9 this list of conditions and the following disclaimer.   2. Redistributions in
  10 binary form must reproduce the above copyright     notice, this list of
  11 conditions and the following disclaimer in the     documentation and/or other
  12 materials provided with the distribution.   THIS SOFTWARE IS PROVIDED BY THE
  13 AUTHOR AND CONTRIBUTORS ``AS IS'' AND  ANY EXPRESS OR IMPLIED WARRANTIES,
  14 INCLUDING, BUT NOT LIMITED TO, THE  IMPLIED WARRANTIES OF MERCHANTABILITY AND
  15 FITNESS FOR A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL THE
  16 AUTHOR OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18 PROCUREMENT OF SUBSTITUTE GOODS  OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19 OR BUSINESS INTERRUPTION)  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20 WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21 OTHERWISE) ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22 ADVISED OF THE POSSIBILITY OF  SUCH DAMAGE.   Copyright 2015 Toomas Soome
  23 <tsoome@me.com>    Copyright 2019 OmniOS Community Edition (OmniOSce)
  24 Association.
  25 
  26 marker task-menu-commands.4th
  27 
  28 include /boot/forth/menusets.4th
  29 
  30 only forth definitions
  31 
  32 variable osconsole_state variable acpi_state variable kernel_state variable
  33 root_state variable kmdb_state variable debug_state 0 kmdb_state !  0
  34 debug_state !  0 osconsole_state !  0 acpi_state !  0 kernel_state !  0
  35 root_state !
  36 
  37 also menu-namespace also menu-command-helpers
  38 
  39  Boot
  40 
  41 : init_boot ( N -- N )   dup  s" smartos" getenv? if        s" set
  42 menu_keycode[N]=98"  base command to execute      else           s"
  43 boot_single" getenv -1 <> if              drop ( n n c-addr -- n n )  unused
  44                toggle_menuitem ( n n -- n n )               s" set
  45 menu_keycode[N]=115"  base command to execute          else                s"
  46 set menu_keycode[N]=98"  base command to execute       then      then      17
  47 +c!  replace 'N' with ASCII numeral     evaluate ;
  48 
  49  Alternate Boot
  50 
  51 : init_altboot ( N -- N )     dup  s" smartos" getenv? if        s" set
  52 menu_keycode[N]=114"  base command to execute     else           s"
  53 boot_single" getenv -1 <> if              drop ( n c-addr -- n )  unused
  54                toggle_menuitem ( n -- n )              s" set
  55 menu_keycode[N]=109"  base command to execute          else                s"


  97 
  98 : init_verbose ( N -- N )     verbose_enabled? if           toggle_menuitem (
  99 n -- n )  then ;
 100 
 101 : toggle_verbose ( N -- N TRUE )   toggle_menuitem     menu-redraw
 102 
 103       Now we're going to make the change effective
 104 
 105      dup toggle_stateN @ 0= if          verbose_disable     else
 106           verbose_enable      then
 107 
 108      TRUE  loop menu again ;
 109 
 110  kmdb
 111 
 112 : kmdb_enabled? ( -- flag )   s" boot_kmdb" getenv -1 <> dup if         swap
 113 drop ( c-addr flag -- flag )  then ;
 114 
 115 : kmdb_enable ( -- )     s" set boot_kmdb=YES" evaluate ;
 116 
 117 : kmdb_disable ( -- )    s" boot_kmdb" unsetenv   s" boot_debug" unsetenv ;

 118 
 119 : init_kmdb ( N -- N )   dup kmdb_state !          store entry number for
 120 kmdb+debug     kmdb_enabled? if         toggle_menuitem ( n -- n )    then ;

 121 
 122 : toggle_kmdb ( N -- N TRUE )      toggle_menuitem     dup toggle_stateN @ 0=
 123 if ( kmdb is not set )        debug_state @ if ( debug is set? )
 124                debug_state @ toggle_stateN @ if ( debug is enabled? )
 125                     debug_state @ toggle_menuitem drop                then
 126           then      then      menu-redraw
 127 
 128       Now we're going to make the change effective
 129 
 130      dup toggle_stateN @ 0= if          kmdb_disable   else
 131           kmdb_enable    then
 132 
 133      TRUE  loop menu again ;
 134 
 135  kmdb + debug
 136 
 137 : debug_disable ( -- )   s" boot_debug" unsetenv ;
 138 
 139 : debug_enabled? ( -- flag )  \[u00A0]-d is only allowed with -k      s"
 140 boot_debug" getenv -1 <> kmdb_enabled? and dup if     swap drop ( c-addr
 141 flag -- flag )      else           debug_disable        make sure env is not
 142 set  then ;
 143 
 144 : debug_enable ( -- )    kmdb_enable    s" set boot_debug=YES" evaluate ;

 145 
 146 : init_debug ( N -- N )  dup debug_state !         store entry number for kmdb
 147      kmdb_enabled? debug_enabled? and if          toggle_menuitem ( n -- n )
 148      then ;
 149 
 150 : toggle_debug ( N -- N TRUE )     toggle_menuitem     kmdb_enabled? 0= if
 151           kmdb_state @ toggle_menuitem drop  then      menu-redraw
 152 
 153       Now we're going to make the change effective
 154 
 155      dup toggle_stateN @ 0= if          debug_disable  else
 156           debug_enable   then
 157 
 158      TRUE  loop menu again ;
 159 
 160  Reconfiguration boot
 161 
 162 : reconfigure_enabled? ( -- flag )      s" boot_reconfigure" getenv -1 <> dup
 163 if        swap drop ( c-addr flag -- flag )  then ;
 164 
 165 : reconfigure_enable ( -- )   s" set boot_reconfigure=YES" evaluate ;
 166 
 167 : reconfigure_disable ( -- )  s" boot_reconfigure" unsetenv ;
 168 
 169 : init_reconfigure ( N -- N )      reconfigure_enabled? if
 170           toggle_menuitem ( n -- n )    then ;
 171 
 172 : toggle_reconfigure ( N -- N TRUE )    toggle_menuitem     menu-redraw
 173 
 174       Now we're going to make the change effective
 175 
 176      dup toggle_stateN @ 0= if          reconfigure_disable      else


 269 root_state !   ( n n2 -- n n2 )   copy for re-initialization     48 +
 270                ( n n2 -- n n2' )  root_state to ASCII num
 271 
 272      s" set root=${root_prefix}${root[N]}${root_suffix}"    30 +c!         ( n
 273 n2 c-addr/u -- n c-addr/u )  'N' to ASCII num     evaluate  ( n c-addr/u -- n
 274 )  sets $root to full kernel-path ;
 275 
 276 : cycle_root ( N -- N TRUE )  cycle_menuitem  cycle cycle_stateN to next value
 277      activate_root   apply current cycle_stateN   menu-redraw     redraw menu
 278      TRUE       loop menu again ;
 279 
 280  Menusets
 281 
 282 : goto_menu ( N M -- N TRUE )      menu-unset     menuset-loadsetnum ( n m --
 283 n )  menu-redraw    TRUE  Loop menu again ;
 284 
 285  Defaults
 286 
 287 : unset_boot_options     0 acpi_state !      s" acpi-user-options" unsetenv
 288      s" boot-args" unsetenv   s" boot_ask" unsetenv    singleuser_disable
 289      verbose_disable     kmdb_disable        \[u00A0]disables debug as well
 290      reconfigure_disable ;
 291 
 292 : set_default_boot_options ( N -- N TRUE )   unset_boot_options  2 goto_menu ;
 293 
 294  Set boot environment defaults
 295 
 296 
 297 : init_bootenv ( -- )    s" set
 298 menu_caption[1]=${bemenu_current}${zfs_be_active}" evaluate      s" set
 299 ansi_caption[1]=${beansi_current}${zfs_be_active}" evaluate      s" set
 300 menu_caption[2]=${bemenu_bootfs}${currdev}" evaluate   s" set
 301 ansi_caption[2]=${beansi_bootfs}${currdev}" evaluate   s" set
 302 menu_caption[3]=${bemenu_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}"
 303 evaluate  s" set
 304 ansi_caption[3]=${beansi_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}"
 305 evaluate ;
 306 
 307  Redraw the entire screen. A long BE name can corrupt the menu
 308 
 309 : be_draw_screen    clear           Clear the screen (in screen.4th)
 310      print_version   print version string (bottom-right; see version.4th)




   4 
   5  Copyright (c) 2006-2015 Devin Teske <dteske@FreeBSD.org>  All rights
   6 reserved.   Redistribution and use in source and binary forms, with or without
   7  modification, are permitted provided that the following conditions  are met:
   8 1. Redistributions of source code must retain the above copyright     notice,
   9 this list of conditions and the following disclaimer.   2. Redistributions in
  10 binary form must reproduce the above copyright     notice, this list of
  11 conditions and the following disclaimer in the     documentation and/or other
  12 materials provided with the distribution.   THIS SOFTWARE IS PROVIDED BY THE
  13 AUTHOR AND CONTRIBUTORS ``AS IS'' AND  ANY EXPRESS OR IMPLIED WARRANTIES,
  14 INCLUDING, BUT NOT LIMITED TO, THE  IMPLIED WARRANTIES OF MERCHANTABILITY AND
  15 FITNESS FOR A PARTICULAR PURPOSE  ARE DISCLAIMED.  IN NO EVENT SHALL THE
  16 AUTHOR OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18 PROCUREMENT OF SUBSTITUTE GOODS  OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19 OR BUSINESS INTERRUPTION)  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20 WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21 OTHERWISE) ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22 ADVISED OF THE POSSIBILITY OF  SUCH DAMAGE.   Copyright 2015 Toomas Soome
  23 <tsoome@me.com>    Copyright 2019 OmniOS Community Edition (OmniOSce)
  24 Association.   Copyright 2019 Joyent, Inc.
  25 
  26 marker task-menu-commands.4th
  27 
  28 include /boot/forth/menusets.4th
  29 
  30 only forth definitions
  31 
  32 variable osconsole_state variable acpi_state variable kernel_state variable
  33 root_state variable kmdb_state variable drop_into_kmdb_state 0 kmdb_state !  0
  34 drop_into_kmdb_state !  0 osconsole_state !  0 acpi_state !  0 kernel_state !
  35 0 root_state !
  36 
  37 also menu-namespace also menu-command-helpers
  38 
  39  Boot
  40 
  41 : init_boot ( N -- N )   dup  s" smartos" getenv? if        s" set
  42 menu_keycode[N]=98"  base command to execute      else           s"
  43 boot_single" getenv -1 <> if              drop ( n n c-addr -- n n )  unused
  44                toggle_menuitem ( n n -- n n )               s" set
  45 menu_keycode[N]=115"  base command to execute          else                s"
  46 set menu_keycode[N]=98"  base command to execute       then      then      17
  47 +c!  replace 'N' with ASCII numeral     evaluate ;
  48 
  49  Alternate Boot
  50 
  51 : init_altboot ( N -- N )     dup  s" smartos" getenv? if        s" set
  52 menu_keycode[N]=114"  base command to execute     else           s"
  53 boot_single" getenv -1 <> if              drop ( n c-addr -- n )  unused
  54                toggle_menuitem ( n -- n )              s" set
  55 menu_keycode[N]=109"  base command to execute          else                s"


  97 
  98 : init_verbose ( N -- N )     verbose_enabled? if           toggle_menuitem (
  99 n -- n )  then ;
 100 
 101 : toggle_verbose ( N -- N TRUE )   toggle_menuitem     menu-redraw
 102 
 103       Now we're going to make the change effective
 104 
 105      dup toggle_stateN @ 0= if          verbose_disable     else
 106           verbose_enable      then
 107 
 108      TRUE  loop menu again ;
 109 
 110  kmdb
 111 
 112 : kmdb_enabled? ( -- flag )   s" boot_kmdb" getenv -1 <> dup if         swap
 113 drop ( c-addr flag -- flag )  then ;
 114 
 115 : kmdb_enable ( -- )     s" set boot_kmdb=YES" evaluate ;
 116 
 117 : kmdb_disable ( -- )    s" boot_kmdb" unsetenv   s" boot_drop_into_kmdb"
 118 unsetenv ;
 119 
 120 : init_kmdb ( N -- N )   dup kmdb_state !          store entry number for
 121 kmdb+drop_into_kmdb      kmdb_enabled? if         toggle_menuitem ( n -- n )
 122      then ;
 123 
 124 : toggle_kmdb ( N -- N TRUE )      toggle_menuitem     dup toggle_stateN @ 0=
 125 if ( kmdb is not set )        drop_into_kmdb_state @ if ( drop_into_kmdb is
 126 set? )              drop_into_kmdb_state @ toggle_stateN @ if ( drop_into_kmdb
 127 is enabled? )                 drop_into_kmdb_state @ toggle_menuitem drop
 128                then           then      then      menu-redraw
 129 
 130       Now we're going to make the change effective
 131 
 132      dup toggle_stateN @ 0= if          kmdb_disable   else
 133           kmdb_enable    then
 134 
 135      TRUE  loop menu again ;
 136 
 137  drop into kmdb
 138 
 139 : drop_into_kmdb_disable ( -- )    s" boot_drop_into_kmdb" unsetenv ;
 140 
 141 : drop_into_kmdb_enabled? ( -- flag )    -d is only allowed with -k   s"
 142 boot_drop_into_kmdb" getenv -1 <> kmdb_enabled?   and dup if       swap drop (
 143 c-addr flag -- flag )    else           drop_into_kmdb_disable         make
 144 sure env is not set      then ;
 145 
 146 : drop_into_kmdb_enable ( -- )     kmdb_enable    s" set
 147 boot_drop_into_kmdb=YES" evaluate ;
 148 
 149 : init_drop_into_kmdb ( N -- N )   dup drop_into_kmdb_state !          store
 150 entry number for kmdb    kmdb_enabled? drop_into_kmdb_enabled? and if
 151           toggle_menuitem ( n -- n )    then ;
 152 
 153 : toggle_drop_into_kmdb ( N -- N TRUE )      toggle_menuitem     kmdb_enabled?
 154 0= if          kmdb_state @ toggle_menuitem drop  then      menu-redraw
 155 
 156       Now we're going to make the change effective
 157 
 158      dup toggle_stateN @ 0= if          drop_into_kmdb_disable   else
 159           drop_into_kmdb_enable    then
 160 
 161      TRUE  loop menu again ;
 162 
 163  Reconfiguration boot
 164 
 165 : reconfigure_enabled? ( -- flag )      s" boot_reconfigure" getenv -1 <> dup
 166 if        swap drop ( c-addr flag -- flag )  then ;
 167 
 168 : reconfigure_enable ( -- )   s" set boot_reconfigure=YES" evaluate ;
 169 
 170 : reconfigure_disable ( -- )  s" boot_reconfigure" unsetenv ;
 171 
 172 : init_reconfigure ( N -- N )      reconfigure_enabled? if
 173           toggle_menuitem ( n -- n )    then ;
 174 
 175 : toggle_reconfigure ( N -- N TRUE )    toggle_menuitem     menu-redraw
 176 
 177       Now we're going to make the change effective
 178 
 179      dup toggle_stateN @ 0= if          reconfigure_disable      else


 272 root_state !   ( n n2 -- n n2 )   copy for re-initialization     48 +
 273                ( n n2 -- n n2' )  root_state to ASCII num
 274 
 275      s" set root=${root_prefix}${root[N]}${root_suffix}"    30 +c!         ( n
 276 n2 c-addr/u -- n c-addr/u )  'N' to ASCII num     evaluate  ( n c-addr/u -- n
 277 )  sets $root to full kernel-path ;
 278 
 279 : cycle_root ( N -- N TRUE )  cycle_menuitem  cycle cycle_stateN to next value
 280      activate_root   apply current cycle_stateN   menu-redraw     redraw menu
 281      TRUE       loop menu again ;
 282 
 283  Menusets
 284 
 285 : goto_menu ( N M -- N TRUE )      menu-unset     menuset-loadsetnum ( n m --
 286 n )  menu-redraw    TRUE  Loop menu again ;
 287 
 288  Defaults
 289 
 290 : unset_boot_options     0 acpi_state !      s" acpi-user-options" unsetenv
 291      s" boot-args" unsetenv   s" boot_ask" unsetenv    singleuser_disable
 292      verbose_disable     kmdb_disable        \[u00A0]disables drop_into_kmdb
 293 as well   reconfigure_disable ;
 294 
 295 : set_default_boot_options ( N -- N TRUE )   unset_boot_options  2 goto_menu ;
 296 
 297  Set boot environment defaults
 298 
 299 
 300 : init_bootenv ( -- )    s" set
 301 menu_caption[1]=${bemenu_current}${zfs_be_active}" evaluate      s" set
 302 ansi_caption[1]=${beansi_current}${zfs_be_active}" evaluate      s" set
 303 menu_caption[2]=${bemenu_bootfs}${currdev}" evaluate   s" set
 304 ansi_caption[2]=${beansi_bootfs}${currdev}" evaluate   s" set
 305 menu_caption[3]=${bemenu_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}"
 306 evaluate  s" set
 307 ansi_caption[3]=${beansi_page}${zfs_be_currpage}${bemenu_pageof}${zfs_be_pages}"
 308 evaluate ;
 309 
 310  Redraw the entire screen. A long BE name can corrupt the menu
 311 
 312 : be_draw_screen    clear           Clear the screen (in screen.4th)
 313      print_version   print version string (bottom-right; see version.4th)