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/loader.4th
+++ new/usr/src/boot/sys/boot/forth/loader.4th
1 1 \ Copyright (c) 1999 Daniel C. Sobral <dcs@FreeBSD.org>
2 2 \ Copyright (c) 2011-2015 Devin Teske <dteske@FreeBSD.org>
3 3 \ All rights reserved.
4 4 \
5 5 \ Redistribution and use in source and binary forms, with or without
6 6 \ modification, are permitted provided that the following conditions
7 7 \ are met:
8 8 \ 1. Redistributions of source code must retain the above copyright
9 9 \ notice, this list of conditions and the following disclaimer.
10 10 \ 2. Redistributions in binary form must reproduce the above copyright
11 11 \ notice, this list of conditions and the following disclaimer in the
12 12 \ documentation and/or other materials provided with the distribution.
13 13 \
14 14 \ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 15 \ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 16 \ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 17 \ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 18 \ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 19 \ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 20 \ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 21 \ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 22 \ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 23 \ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 24 \ SUCH DAMAGE.
25 25 \
26 26 \ $FreeBSD$
27 27
28 28 only forth definitions
29 29
30 30 s" arch-i386" environment? [if] [if]
31 31 s" loader_version" environment? [if]
32 32 11 < [if]
33 33 .( Loader version 1.1+ required) cr
34 34 abort
35 35 [then]
36 36 [else]
37 37 .( Could not get loader version!) cr
38 38 abort
39 39 [then]
40 40 [then] [then]
41 41
42 42 include /boot/forth/support.4th
43 43 include /boot/forth/color.4th
44 44 include /boot/forth/delay.4th
45 45 include /boot/forth/check-password.4th
46 46 s" efi-version" getenv? [if]
47 47 include /boot/forth/efi.4th
48 48 [then]
49 49
50 50 only forth definitions
51 51
52 52 : bootmsg ( -- )
53 53 loader_color? dup ( -- bool bool )
54 54 if 7 fg 4 bg then
55 55 ." Booting..."
56 56 if me then
57 57 cr
58 58 ;
59 59
60 60 : try-menu-unset
61 61 \ menu-unset may not be present
62 62 s" beastie_disable" getenv
63 63 dup -1 <> if
64 64 s" YES" compare-insensitive 0= if
65 65 exit
66 66 then
67 67 else
68 68 drop
69 69 then
70 70 s" menu-unset"
71 71 sfind if
72 72 execute
73 73 else
74 74 drop
75 75 then
76 76 s" menusets-unset"
77 77 sfind if
78 78 execute
79 79 else
80 80 drop
81 81 then
82 82 ;
83 83
84 84 only forth also support-functions also builtins definitions
85 85
86 86 \ the boot-args was parsed to individual options while loaded
87 87 \ now compose boot-args, so the boot can set kernel arguments
88 88 \ note the command line switched for boot command will cause
89 89 \ environment variable boot-args to be ignored
90 90 \ There are 2 larger strings, acpi-user-options and existing boot-args
91 91 \ other switches are 1 byte each, so allocate boot-args+acpi + extra bytes
92 92 \ for rest. Be sure to review this, if more options are to be added into
93 93 \ environment.
94 94
95 95 : set-boot-args { | addr len baddr blen aaddr alen -- }
96 96 s" boot-args" getenv dup -1 <> if
97 97 to blen to baddr
98 98 else
99 99 drop
100 100 then
101 101 s" acpi-user-options" getenv dup -1 <> if
102 102 to alen to aaddr
103 103 else
104 104 drop
105 105 then
106 106
107 107 \ allocate temporary space. max is:
108 108 \ 7 kernel switches
109 109 \ 26 for acpi, so use 40 for safety
110 110 blen alen 40 + + allocate abort" out of memory"
111 111 to addr
112 112 \ boot-addr may have file name before options, copy it to addr
113 113 baddr 0<> if
114 114 baddr c@ [char] - <> if
115 115 baddr blen [char] - strchr ( addr len )
116 116 dup 0= if \ no options, copy all
117 117 2drop
118 118 baddr addr blen move
119 119 blen to len
120 120 0 to blen
121 121 0 to baddr
122 122 else ( addr len )
123 123 dup blen
124 124 swap -
125 125 to len ( addr len )
126 126 to blen ( addr )
127 127 baddr addr len move ( addr )
128 128 to baddr \ baddr points now to first option
129 129 then
130 130 then
131 131 then
132 132 \ now add kernel switches
133 133 len 0<> if
134 134 bl addr len + c! len 1+ to len
135 135 then
136 136 [char] - addr len + c! len 1+ to len
137 137
138 138 s" boot_single" getenv dup -1 <> if
139 139 s" YES" compare-insensitive 0= if
140 140 [char] s addr len + c! len 1+ to len
141 141 then
142 142 else
143 143 drop
144 144 then
145 145 s" boot_verbose" getenv dup -1 <> if
146 146 s" YES" compare-insensitive 0= if
147 147 [char] v addr len + c! len 1+ to len
148 148 then
↓ open down ↓ |
148 lines elided |
↑ open up ↑ |
149 149 else
150 150 drop
151 151 then
152 152 s" boot_kmdb" getenv dup -1 <> if
153 153 s" YES" compare-insensitive 0= if
154 154 [char] k addr len + c! len 1+ to len
155 155 then
156 156 else
157 157 drop
158 158 then
159 - s" boot_debug" getenv dup -1 <> if
159 + s" boot_drop_into_kmdb" getenv dup -1 <> if
160 160 s" YES" compare-insensitive 0= if
161 161 [char] d addr len + c! len 1+ to len
162 162 then
163 163 else
164 164 drop
165 165 then
166 166 s" boot_reconfigure" getenv dup -1 <> if
167 167 s" YES" compare-insensitive 0= if
168 168 [char] r addr len + c! len 1+ to len
169 169 then
170 170 else
171 171 drop
172 172 then
173 173 s" boot_ask" getenv dup -1 <> if
174 174 s" YES" compare-insensitive 0= if
175 175 [char] a addr len + c! len 1+ to len
176 176 then
177 177 else
178 178 drop
179 179 then
180 180
181 181 \ now add remining boot args if blen != 0.
182 182 \ baddr[0] is '-', if baddr[1] != 'B' append to addr,
183 183 \ otherwise add space then copy
184 184 blen 0<> if
185 185 baddr 1+ c@ [char] B = if
186 186 addr len + 1- c@ [char] - = if \ if addr[len -1] == '-'
187 187 baddr 1+ to baddr
188 188 blen 1- to blen
189 189 else
190 190 bl addr len + c! len 1+ to len
191 191 then
192 192 else
193 193 baddr 1+ to baddr
194 194 blen 1- to blen
195 195 then
196 196 baddr addr len + blen move
197 197 len blen + to len
198 198 0 to baddr
199 199 0 to blen
200 200 then
201 201 \ last part - add acpi.
202 202 alen 0<> if
203 203 addr len + 1- c@ [char] - <> if
204 204 bl addr len + c! len 1+ to len
205 205 [char] - addr len + c! len 1+ to len
206 206 then
207 207 s" B acpi-user-options=" dup -rot ( len addr len )
208 208 addr len + swap move ( len )
209 209 len + to len
210 210 aaddr addr len + alen move
211 211 len alen + to len
212 212 then
213 213
214 214 \ check for left over '-'
215 215 addr len 1- + c@ [char] - = if
216 216 len 1- to len
217 217 \ but now we may also have left over ' '
218 218 len if ( len <> 0 )
219 219 addr len 1- + c@ bl = if
220 220 len 1- to len
221 221 then
222 222 then
223 223 then
224 224
225 225 \ if len != 0, set boot-args
226 226 len 0<> if
227 227 addr len s" boot-args" setenv
228 228 then
229 229 addr free drop
230 230 ;
231 231
232 232 : boot
233 233 0= if ( interpreted ) get_arguments then
234 234 set-boot-args
235 235
236 236 \ Unload only if a path was passed. Paths start with /
237 237 dup if
238 238 >r over r> swap
239 239 c@ [char] / = if
240 240 0 1 unload drop
241 241 else
242 242 s" kernelname" getenv? if ( a kernel has been loaded )
243 243 try-menu-unset
244 244 bootmsg 1 boot exit
245 245 then
246 246 load_kernel_and_modules
247 247 ?dup if exit then
248 248 try-menu-unset
249 249 bootmsg 0 1 boot exit
250 250 then
251 251 else
252 252 s" kernelname" getenv? if ( a kernel has been loaded )
253 253 try-menu-unset
254 254 bootmsg 1 boot exit
255 255 then
256 256 load_kernel_and_modules
257 257 ?dup if exit then
258 258 try-menu-unset
259 259 bootmsg 0 1 boot exit
260 260 then
261 261 load_kernel_and_modules
262 262 ?dup 0= if bootmsg 0 1 boot then
263 263 ;
264 264
265 265 \ ***** boot-conf
266 266 \
267 267 \ Prepares to boot as specified by loaded configuration files.
268 268
269 269 : boot-conf
270 270 0= if ( interpreted ) get_arguments then
271 271 0 1 unload drop
272 272 load_kernel_and_modules
273 273 ?dup 0= if 0 1 autoboot then
274 274 ;
275 275
276 276 also forth definitions previous
277 277
278 278 builtin: boot
↓ open down ↓ |
109 lines elided |
↑ open up ↑ |
279 279 builtin: boot-conf
280 280
281 281 only forth definitions also support-functions
282 282
283 283 \
284 284 \ in case the boot-args is set, parse it and extract following options:
285 285 \ -a to boot_ask=YES
286 286 \ -s to boot_single=YES
287 287 \ -v to boot_verbose=YES
288 288 \ -k to boot_kmdb=YES
289 -\ -d to boot_debug=YES
289 +\ -d to boot_drop_into_kmdb=YES
290 290 \ -r to boot_reconfigure=YES
291 291 \ -B acpi-user-options=X to acpi-user-options=X
292 292 \
293 293 \ This is needed so that the menu can manage these options. Unfortunately, this
294 294 \ also means that boot-args will override previously set options, but we have no
295 295 \ way to control the processing order here. boot-args will be rebuilt at boot.
296 296 \
297 297 \ NOTE: The best way to address the order is to *not* set any above options
298 298 \ in boot-args.
299 299
300 300 : parse-boot-args { | baddr blen -- }
301 301 s" boot-args" getenv dup -1 = if drop exit then
302 302 to blen
303 303 to baddr
304 304
305 305 baddr blen
306 306
307 307 \ loop over all instances of switch blocks, starting with '-'
308 308 begin
309 309 [char] - strchr
310 310 2dup to blen to baddr
311 311 dup 0<>
312 312 while ( addr len ) \ points to -
313 313 \ block for switch B. keep it on top of the stack for case
314 314 \ the property list will get empty.
315 315
316 316 over 1+ c@ [char] B = if
317 317 2dup \ save "-B ...." in case options is empty
318 318 2 - swap 2 + ( addr len len-2 addr+2 ) \ skip -B
319 319
320 320 begin \ skip spaces
321 321 dup c@ bl =
322 322 while
323 323 1+ swap 1- swap
324 324 repeat
325 325
326 326 ( addr len len' addr' )
327 327 \ its 3 cases now: end of string, -switch, or option list
328 328
329 329 over 0= if \ end of string, remove trailing -B
330 330 2drop ( addr len )
331 331 swap 0 swap c! \ store 0 at -B
332 332 blen swap ( blen len )
333 333 - ( rem )
334 334 baddr swap ( addr rem )
335 335 dup 0= if
336 336 s" boot-args" unsetenv
337 337 2drop
338 338 exit
339 339 then
340 340 \ trailing space(s)
341 341 begin
342 342 over ( addr rem addr )
343 343 over + 1- ( addr rem addr+rem-1 )
344 344 c@ bl =
345 345 while
346 346 1- swap ( rem-1 addr )
347 347 over ( rem-1 addr rem-1 )
348 348 over + ( rem-1 addr addr+rem-1 )
349 349 0 swap c!
350 350 swap
351 351 repeat
352 352 s" boot-args" setenv
353 353 recurse \ restart
354 354 exit
355 355 then
356 356 ( addr len len' addr' )
357 357 dup c@ [char] - = if \ it is switch. set to boot-args
358 358 swap s" boot-args" setenv
359 359 2drop
360 360 recurse \ restart
361 361 exit
362 362 then
363 363 ( addr len len' addr' )
364 364 \ its options string "option1,option2,... -..."
365 365 \ cut acpi-user-options=xxx and restart the parser
366 366 \ or skip to next option block
367 367 begin
368 368 dup c@ dup 0<> swap bl <> and \ stop if space or 0
369 369 while
370 370 dup 18 s" acpi-user-options=" compare 0= if \ matched
371 371 ( addr len len' addr' )
372 372 \ addr' points to acpi options, find its end [',' or ' ' or 0 ]
373 373 \ set it as acpi-user-options and move remaining to addr'
374 374 2dup ( addr len len' addr' len' addr' )
375 375 \ skip to next option in list
376 376 \ loop to first , or bl or 0
377 377 begin
378 378 dup c@ [char] , <> >r
379 379 dup c@ bl <> >r
380 380 dup c@ 0<> r> r> and and
381 381 while
382 382 1+ swap 1- swap
383 383 repeat
384 384 ( addr len len' addr' len" addr" )
385 385 >r >r ( addr len len' addr' R: addr" len" )
386 386 over r@ - ( addr len len' addr' proplen R: addr" len" )
387 387 dup 5 + ( addr len len' addr' proplen proplen+5 )
388 388 allocate abort" out of memory"
389 389
390 390 0 s" set " strcat ( addr len len' addr' proplen caddr clen )
391 391 >r >r 2dup r> r> 2swap strcat ( addr len len' addr' proplen caddr clen )
392 392 2dup + 0 swap c! \ terminate with 0
393 393 2dup evaluate drop free drop
394 394 ( addr len len' addr' proplen R: addr" len" )
395 395 \ acpi-user-options is set, now move remaining string to its place.
396 396 \ addr: -B, addr': acpi... addr": reminder
397 397 swap ( addr len len' proplen addr' )
398 398 r> r> ( addr len len' proplen addr' len" addr" )
399 399 dup c@ [char] , = if
400 400 \ skip , and move addr" to addr'
401 401 1+ swap 1- ( addr len len' proplen addr' addr" len" )
402 402 rot swap 1+ move ( addr len len' proplen )
403 403 else \ its bl or 0 ( addr len len' proplen addr' len" addr" )
404 404 \ for both bl and 0 we need to copy to addr'-1 to remove
405 405 \ comma, then reset boot-args, and recurse will clear -B
406 406 \ if there are no properties left.
407 407 dup c@ 0= if
408 408 2drop ( addr len len' proplen addr' )
409 409 1- 0 swap c! ( addr len len' proplen )
410 410 else
411 411 >r >r ( addr len len' proplen addr' R: addr" len" )
412 412 1- swap 1+ swap
413 413 r> r> ( addr len len' proplen addr' len" addr" )
414 414 rot rot move ( addr len len' proplen )
415 415 then
416 416 then
417 417
418 418 2swap 2drop ( len' proplen )
419 419 nip ( proplen )
420 420 baddr blen rot -
421 421 s" boot-args" setenv
422 422 recurse
423 423 exit
424 424 else
425 425 ( addr len len' addr' )
426 426 \ not acpi option, skip to next option in list
427 427 \ loop to first , or bl or 0
428 428 begin
429 429 dup c@ [char] , <> >r
430 430 dup c@ bl <> >r
431 431 dup c@ 0<> r> r> and and
432 432 while
433 433 1+ swap 1- swap
434 434 repeat
435 435 \ if its ',', skip over
436 436 dup c@ [char] , = if
437 437 1+ swap 1- swap
438 438 then
439 439 then
440 440 repeat
441 441 ( addr len len' addr' )
442 442 \ this block is done, remove addr and len from stack
443 443 2swap 2drop swap
444 444 then
445 445
446 446 over c@ [char] - = if ( addr len )
447 447 2dup 1- swap 1+ ( addr len len' addr' )
↓ open down ↓ |
148 lines elided |
↑ open up ↑ |
448 448 begin \ loop till ' ' or 0
449 449 dup c@ dup 0<> swap bl <> and
450 450 while
451 451 dup c@ [char] s = if
452 452 s" set boot_single=YES" evaluate TRUE
453 453 else dup c@ [char] v = if
454 454 s" set boot_verbose=YES" evaluate TRUE
455 455 else dup c@ [char] k = if
456 456 s" set boot_kmdb=YES" evaluate TRUE
457 457 else dup c@ [char] d = if
458 - s" set boot_debug=YES" evaluate TRUE
458 + s" set boot_drop_into_kmdb=YES" evaluate TRUE
459 459 else dup c@ [char] r = if
460 460 s" set boot_reconfigure=YES" evaluate TRUE
461 461 else dup c@ [char] a = if
462 462 s" set boot_ask=YES" evaluate TRUE
463 463 then then then then then then
464 464 dup TRUE = if
465 465 drop
466 466 dup >r ( addr len len' addr' R: addr' )
467 467 1+ swap 1- ( addr len addr'+1 len'-1 R: addr' )
468 468 r> swap move ( addr len )
469 469
470 470 2drop baddr blen 1-
471 471 \ check if we have space after '-', if so, drop '- '
472 472 swap dup 1+ c@ bl = if
473 473 2 + swap 2 -
474 474 else
475 475 swap
476 476 then
477 477 dup dup 0= swap 1 = or if \ empty or only '-' is left.
478 478 2drop
479 479 s" boot-args" unsetenv
480 480 exit
481 481 else
482 482 s" boot-args" setenv
483 483 then
484 484 recurse
485 485 exit
486 486 then
487 487 1+ swap 1- swap
488 488 repeat
489 489
490 490 2swap 2drop
491 491 dup c@ 0= if \ end of string
492 492 2drop
493 493 exit
494 494 else
495 495 swap
496 496 then
497 497 then
498 498 repeat
499 499
500 500 2drop
501 501 ;
502 502
503 503 \ ***** start
504 504 \
505 505 \ Initializes support.4th global variables, sets loader_conf_files,
506 506 \ processes conf files, and, if any one such file was successfully
507 507 \ read to the end, loads kernel and modules.
508 508
509 509 : start ( -- ) ( throws: abort & user-defined )
510 510 s" /boot/defaults/loader.conf" initialize
511 511 include_bootenv
512 512 include_conf_files
513 513 include_transient
514 514 \ If the user defined a post-initialize hook, call it now
515 515 s" post-initialize" sfind if execute else drop then
516 516 parse-boot-args
517 517 \ Will *NOT* try to load kernel and modules if no configuration file
518 518 \ was successfully loaded!
519 519 any_conf_read? if
520 520 s" loader_delay" getenv -1 = if
521 521 load_xen_throw
522 522 load_kernel
523 523 load_modules
524 524 else
525 525 drop
526 526 ." Loading Kernel and Modules (Ctrl-C to Abort)" cr
527 527 s" also support-functions" evaluate
528 528 s" set delay_command='load_xen_throw load_kernel load_modules'" evaluate
529 529 s" set delay_showdots" evaluate
530 530 delay_execute
531 531 then
532 532 then
533 533 ;
534 534
535 535 \ ***** initialize
536 536 \
537 537 \ Overrides support.4th initialization word with one that does
538 538 \ everything start one does, short of loading the kernel and
539 539 \ modules. Returns a flag.
540 540
541 541 : initialize ( -- flag )
542 542 s" /boot/defaults/loader.conf" initialize
543 543 include_bootenv
544 544 include_conf_files
545 545 include_transient
546 546 \ If the user defined a post-initialize hook, call it now
547 547 s" post-initialize" sfind if execute else drop then
548 548 parse-boot-args
549 549 any_conf_read?
550 550 ;
551 551
552 552 \ ***** read-conf
553 553 \
554 554 \ Read a configuration file, whose name was specified on the command
555 555 \ line, if interpreted, or given on the stack, if compiled in.
556 556
557 557 : (read-conf) ( addr len -- )
558 558 conf_files string=
559 559 include_conf_files \ Will recurse on new loader_conf_files definitions
560 560 ;
561 561
562 562 : read-conf ( <filename> | addr len -- ) ( throws: abort & user-defined )
563 563 state @ if
564 564 \ Compiling
565 565 postpone (read-conf)
566 566 else
567 567 \ Interpreting
568 568 bl parse (read-conf)
569 569 then
570 570 ; immediate
571 571
572 572 \ show, enable, disable, toggle module loading. They all take module from
573 573 \ the next word
574 574
575 575 : set-module-flag ( module_addr val -- ) \ set and print flag
576 576 over module.flag !
577 577 dup module.name strtype
578 578 module.flag @ if ." will be loaded" else ." will not be loaded" then cr
579 579 ;
580 580
581 581 : enable-module find-module ?dup if true set-module-flag then ;
582 582
583 583 : disable-module find-module ?dup if false set-module-flag then ;
584 584
585 585 : toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
586 586
587 587 \ ***** show-module
588 588 \
589 589 \ Show loading information about a module.
590 590
591 591 : show-module ( <module> -- ) find-module ?dup if show-one-module then ;
592 592
593 593 : set-module-path ( addr len <module> -- )
594 594 find-module ?dup if
595 595 module.loadname string=
596 596 then
597 597 ;
598 598
599 599 \ Words to be used inside configuration files
600 600
601 601 : retry false ; \ For use in load error commands
602 602 : ignore true ; \ For use in load error commands
603 603
604 604 \ Return to strict forth vocabulary
605 605
606 606 : #type
607 607 over - >r
608 608 type
609 609 r> spaces
610 610 ;
611 611
612 612 : .? 2 spaces 2swap 15 #type 2 spaces type cr ;
613 613
614 614 : ?
615 615 ['] ? execute
616 616 s" boot-conf" s" load kernel and modules, then autoboot" .?
617 617 s" read-conf" s" read a configuration file" .?
618 618 s" enable-module" s" enable loading of a module" .?
619 619 s" disable-module" s" disable loading of a module" .?
620 620 s" toggle-module" s" toggle loading of a module" .?
621 621 s" show-module" s" show module load data" .?
622 622 s" try-include" s" try to load/interpret files" .?
623 623 s" beadm" s" list or activate Boot Environments" .?
624 624 ;
625 625
626 626 : try-include ( -- ) \ see loader.4th(8)
627 627 ['] include ( -- xt ) \ get the execution token of `include'
628 628 catch ( xt -- exception# | 0 ) if \ failed
629 629 LF parse ( c -- s-addr/u ) 2drop \ advance >in to EOL (drop data)
630 630 \ ... prevents words unused by `include' from being interpreted
631 631 then
632 632 ; immediate \ interpret immediately for access to `source' (aka tib)
633 633
634 634 include /boot/forth/beadm.4th
635 635 only forth definitions
↓ open down ↓ |
167 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX