2015-03-31 22:32:35 +00:00
|
|
|
\ Copyright (c) 1999 Daniel C. Sobral <dcs@FreeBSD.org>
|
1999-03-09 14:06:55 +00:00
|
|
|
\ All rights reserved.
|
|
|
|
\
|
|
|
|
\ Redistribution and use in source and binary forms, with or without
|
|
|
|
\ modification, are permitted provided that the following conditions
|
|
|
|
\ are met:
|
|
|
|
\ 1. Redistributions of source code must retain the above copyright
|
|
|
|
\ notice, this list of conditions and the following disclaimer.
|
|
|
|
\ 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
\ notice, this list of conditions and the following disclaimer in the
|
|
|
|
\ documentation and/or other materials provided with the distribution.
|
|
|
|
\
|
|
|
|
\ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
\ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
\ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
\ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
\ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
\ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
\ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
\ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
\ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
\ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
\ SUCH DAMAGE.
|
|
|
|
\
|
1999-08-28 01:08:13 +00:00
|
|
|
\ $FreeBSD$
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
\ Loader.rc support functions:
|
|
|
|
\
|
|
|
|
\ initialize ( addr len -- ) as above, plus load_conf_files
|
|
|
|
\ load_conf ( addr len -- ) load conf file given
|
|
|
|
\ include_conf_files ( -- ) load all conf files in load_conf_files
|
|
|
|
\ print_syntax_error ( -- ) print line and marker of where a syntax
|
|
|
|
\ error was detected
|
|
|
|
\ print_line ( -- ) print last line processed
|
|
|
|
\ load_kernel ( -- ) load kernel
|
|
|
|
\ load_modules ( -- ) load modules flagged
|
|
|
|
\
|
|
|
|
\ Exported structures:
|
|
|
|
\
|
|
|
|
\ string counted string structure
|
|
|
|
\ cell .addr string address
|
|
|
|
\ cell .len string length
|
|
|
|
\ module module loading information structure
|
|
|
|
\ cell module.flag should we load it?
|
|
|
|
\ string module.name module's name
|
|
|
|
\ string module.loadname name to be used in loading the module
|
|
|
|
\ string module.type module's type
|
|
|
|
\ string module.args flags to be passed during load
|
|
|
|
\ string module.beforeload command to be executed before load
|
|
|
|
\ string module.afterload command to be executed after load
|
|
|
|
\ string module.loaderror command to be executed if load fails
|
|
|
|
\ cell module.next list chain
|
|
|
|
\
|
|
|
|
\ Exported global variables;
|
|
|
|
\
|
|
|
|
\ string conf_files configuration files to be loaded
|
|
|
|
\ cell modules_options pointer to first module information
|
|
|
|
\ value verbose? indicates if user wants a verbose loading
|
2016-04-30 02:47:41 +00:00
|
|
|
\ value any_conf_read? indicates if a conf file was successfully read
|
1999-03-09 14:06:55 +00:00
|
|
|
\
|
|
|
|
\ Other exported words:
|
2009-01-05 20:09:54 +00:00
|
|
|
\ note, strlen is internal
|
1999-03-09 14:06:55 +00:00
|
|
|
\ strdup ( addr len -- addr' len) similar to strdup(3)
|
|
|
|
\ strcat ( addr len addr' len' -- addr len+len' ) similar to strcat(3)
|
|
|
|
\ s' ( | string' -- addr len | ) similar to s"
|
|
|
|
\ rudimentary structure support
|
|
|
|
|
|
|
|
\ Exception values
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
1 constant ESYNTAX
|
|
|
|
2 constant ENOMEM
|
|
|
|
3 constant EFREE
|
|
|
|
4 constant ESETERROR \ error setting environment variable
|
|
|
|
5 constant EREAD \ error reading
|
|
|
|
6 constant EOPEN
|
|
|
|
7 constant EEXEC \ XXX never catched
|
|
|
|
8 constant EBEFORELOAD
|
|
|
|
9 constant EAFTERLOAD
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2001-12-11 00:49:34 +00:00
|
|
|
\ I/O constants
|
|
|
|
|
|
|
|
0 constant SEEK_SET
|
|
|
|
1 constant SEEK_CUR
|
|
|
|
2 constant SEEK_END
|
|
|
|
|
|
|
|
0 constant O_RDONLY
|
|
|
|
1 constant O_WRONLY
|
|
|
|
2 constant O_RDWR
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Crude structure support
|
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
: structure:
|
|
|
|
create here 0 , ['] drop , 0
|
|
|
|
does> create here swap dup @ allot cell+ @ execute
|
|
|
|
;
|
1999-03-09 14:06:55 +00:00
|
|
|
: member: create dup , over , + does> cell+ @ + ;
|
|
|
|
: ;structure swap ! ;
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
: constructor! >body cell+ ! ;
|
|
|
|
: constructor: over :noname ;
|
|
|
|
: ;constructor postpone ; swap cell+ ! ; immediate
|
1999-03-09 14:06:55 +00:00
|
|
|
: sizeof ' >body @ state @ if postpone literal then ; immediate
|
|
|
|
: offsetof ' >body cell+ @ state @ if postpone literal then ; immediate
|
|
|
|
: ptr 1 cells member: ;
|
|
|
|
: int 1 cells member: ;
|
|
|
|
|
|
|
|
\ String structure
|
|
|
|
|
|
|
|
structure: string
|
|
|
|
ptr .addr
|
|
|
|
int .len
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
constructor:
|
|
|
|
0 over .addr !
|
|
|
|
0 swap .len !
|
|
|
|
;constructor
|
1999-03-09 14:06:55 +00:00
|
|
|
;structure
|
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Module options linked list
|
|
|
|
|
|
|
|
structure: module
|
|
|
|
int module.flag
|
|
|
|
sizeof string member: module.name
|
|
|
|
sizeof string member: module.loadname
|
|
|
|
sizeof string member: module.type
|
|
|
|
sizeof string member: module.args
|
|
|
|
sizeof string member: module.beforeload
|
|
|
|
sizeof string member: module.afterload
|
|
|
|
sizeof string member: module.loaderror
|
|
|
|
ptr module.next
|
|
|
|
;structure
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ Internal loader structures (preloaded_file, kernel_module, file_metadata)
|
2017-11-14 23:02:19 +00:00
|
|
|
\ must be in sync with the C struct in stand/common/bootstrap.h
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
structure: preloaded_file
|
|
|
|
ptr pf.name
|
|
|
|
ptr pf.type
|
|
|
|
ptr pf.args
|
|
|
|
ptr pf.metadata \ file_metadata
|
|
|
|
int pf.loader
|
|
|
|
int pf.addr
|
|
|
|
int pf.size
|
|
|
|
ptr pf.modules \ kernel_module
|
|
|
|
ptr pf.next \ preloaded_file
|
|
|
|
;structure
|
|
|
|
|
|
|
|
structure: kernel_module
|
|
|
|
ptr km.name
|
|
|
|
\ ptr km.args
|
|
|
|
ptr km.fp \ preloaded_file
|
|
|
|
ptr km.next \ kernel_module
|
|
|
|
;structure
|
|
|
|
|
|
|
|
structure: file_metadata
|
|
|
|
int md.size
|
|
|
|
2 member: md.type \ this is not ANS Forth compatible (XXX)
|
|
|
|
ptr md.next \ file_metadata
|
|
|
|
0 member: md.data \ variable size
|
|
|
|
;structure
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ end of structures
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Global variables
|
|
|
|
|
|
|
|
string conf_files
|
2002-05-24 02:28:58 +00:00
|
|
|
string nextboot_conf_file
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
create module_options sizeof module.next allot 0 module_options !
|
|
|
|
create last_module_option sizeof module.next allot 0 last_module_option !
|
1999-03-09 14:06:55 +00:00
|
|
|
0 value verbose?
|
2002-05-24 02:28:58 +00:00
|
|
|
0 value nextboot?
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
\ Support string functions
|
2009-01-05 20:09:54 +00:00
|
|
|
: strdup { addr len -- addr' len' }
|
|
|
|
len allocate if ENOMEM throw then
|
|
|
|
addr over len move len
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: strcat { addr len addr' len' -- addr len+len' }
|
|
|
|
addr' addr len + len' move
|
|
|
|
addr len len' +
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: strchr { addr len c -- addr' len' }
|
2000-06-07 22:03:37 +00:00
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
len
|
|
|
|
while
|
|
|
|
addr c@ c = if addr len exit then
|
|
|
|
addr 1 + to addr
|
|
|
|
len 1 - to len
|
|
|
|
repeat
|
|
|
|
0 0
|
2000-06-07 22:03:37 +00:00
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: s' \ same as s", allows " in the string
|
1999-03-09 14:06:55 +00:00
|
|
|
[char] ' parse
|
2009-01-05 20:09:54 +00:00
|
|
|
state @ if postpone sliteral then
|
1999-03-09 14:06:55 +00:00
|
|
|
; immediate
|
|
|
|
|
2000-06-07 22:03:37 +00:00
|
|
|
: 2>r postpone >r postpone >r ; immediate
|
|
|
|
: 2r> postpone r> postpone r> ; immediate
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
: 2r@ postpone 2r> postpone 2dup postpone 2>r ; immediate
|
1999-11-24 17:56:40 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: getenv? getenv -1 = if false else drop true then ;
|
2000-09-16 19:49:52 +00:00
|
|
|
|
2012-12-09 15:25:34 +00:00
|
|
|
\ determine if a word appears in a string, case-insensitive
|
|
|
|
: contains? ( addr1 len1 addr2 len2 -- 0 | -1 )
|
|
|
|
2 pick 0= if 2drop 2drop true exit then
|
|
|
|
dup 0= if 2drop 2drop false exit then
|
|
|
|
begin
|
|
|
|
begin
|
2012-12-10 15:29:56 +00:00
|
|
|
swap dup c@ dup 32 = over 9 = or over 10 = or
|
|
|
|
over 13 = or over 44 = or swap drop
|
2012-12-09 15:25:34 +00:00
|
|
|
while 1+ swap 1- repeat
|
|
|
|
swap 2 pick 1- over <
|
|
|
|
while
|
|
|
|
2over 2over drop over compare-insensitive 0= if
|
|
|
|
2 pick over = if 2drop 2drop true exit then
|
|
|
|
2 pick tuck - -rot + swap over c@ dup 32 =
|
2012-12-10 15:29:56 +00:00
|
|
|
over 9 = or over 10 = or over 13 = or over 44 = or
|
2012-12-09 15:25:34 +00:00
|
|
|
swap drop if 2drop 2drop true exit then
|
|
|
|
then begin
|
2012-12-10 15:29:56 +00:00
|
|
|
swap dup c@ dup 32 = over 9 = or over 10 = or
|
|
|
|
over 13 = or over 44 = or swap drop
|
|
|
|
if false else true then 2 pick 0> and
|
2012-12-09 15:25:34 +00:00
|
|
|
while 1+ swap 1- repeat
|
|
|
|
swap
|
|
|
|
repeat
|
|
|
|
2drop 2drop false
|
|
|
|
;
|
|
|
|
|
|
|
|
: boot_serial? ( -- 0 | -1 )
|
|
|
|
s" console" getenv dup -1 <> if
|
|
|
|
s" comconsole" 2swap contains?
|
|
|
|
else drop false then
|
|
|
|
s" boot_serial" getenv dup -1 <> if
|
|
|
|
swap drop 0>
|
|
|
|
else drop false then
|
|
|
|
or \ console contains comconsole ( or ) boot_serial
|
|
|
|
s" boot_multicons" getenv dup -1 <> if
|
|
|
|
swap drop 0>
|
|
|
|
else drop false then
|
|
|
|
or \ previous boolean ( or ) boot_multicons
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Private definitions
|
|
|
|
|
|
|
|
vocabulary support-functions
|
|
|
|
only forth also support-functions definitions
|
|
|
|
|
|
|
|
\ Some control characters constants
|
|
|
|
|
1999-11-24 17:56:40 +00:00
|
|
|
7 constant bell
|
|
|
|
8 constant backspace
|
1999-03-09 14:06:55 +00:00
|
|
|
9 constant tab
|
|
|
|
10 constant lf
|
1999-11-24 17:56:40 +00:00
|
|
|
13 constant <cr>
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
\ Read buffer size
|
|
|
|
|
|
|
|
80 constant read_buffer_size
|
|
|
|
|
|
|
|
\ Standard suffixes
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: load_module_suffix s" _load" ;
|
|
|
|
: module_loadname_suffix s" _name" ;
|
|
|
|
: module_type_suffix s" _type" ;
|
|
|
|
: module_args_suffix s" _flags" ;
|
|
|
|
: module_beforeload_suffix s" _before" ;
|
|
|
|
: module_afterload_suffix s" _after" ;
|
|
|
|
: module_loaderror_suffix s" _error" ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
\ Support operators
|
|
|
|
|
|
|
|
: >= < 0= ;
|
|
|
|
: <= > 0= ;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ Assorted support functions
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: free-memory free if EFREE throw then ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
PROBLEM: putting in a loader config file a line of the form
loader_conf_files="foo bar baz"
should cause loading the files listed, and then resume with the
remaining config files (from previous values of the variable).
Unfortunately, sometimes the line was ignored -- actually even
modifying the line in /boot/default/loader.conf sometimes doesn't work.
ANALYSIS: After much investigation, turned out to be a bug in the logic.
The existing code detected a new assignment by looking at the address
of the the variable containing the string. This only worked by pure
chance, i.e. if the new string is longer than the previous value
then the memory allocator may return a different address
to store the string hence triggering the detection.
SOLUTION: This commit contains a minimal change to fix the problem,
without altering too much the existing structure of the code.
However, as a step towards improving the quality and reliability of
this code, I have introduced a handful of one-line functions
(strget, strset, strfree, string= ) that could be used in dozens
of places in the existing code.
HOWEVER:
There is a much bigger problem here. Even though I am no Forth
expert (as most fellow src committers) I can tell that much of the
forth code (in support.4th at least) is in severe need of a
review/refactoring:
+ pieces of code are replicated multiple times instead of writing
functions (see e.g. set_module_*);
+ a lot of stale code (e.g. "structure" definitions for
preloaded_files, kernel_module, pnp stuff) which is not used
or at least belongs elsewhere.
The code bload is extremely bad as the loader runs with very small
memory constraints, and we already hit the limit once (see
http://svn.freebsd.org/viewvc/base?view=revision&revision=185132
Reducing the footprint of the forth files is critical.
+ two different styles of coding, one using pure stack functions
(maybe beautiful but surely highly unreadable), one using
high level mechanisms to give names to arguments and local
variables (which leads to readable code).
Note that this code is used by default by all FreeBSD installations,
so the fragility and the code bloat are extremely damaging.
I will try to work fixing the three items above, but if others have
time, please have a look at these issues.
MFC after: 4 weeks
2008-12-07 19:42:20 +00:00
|
|
|
: strget { var -- addr len } var .addr @ var .len @ ;
|
|
|
|
|
|
|
|
\ assign addr len to variable.
|
2009-01-05 20:09:54 +00:00
|
|
|
: strset { addr len var -- } addr var .addr ! len var .len ! ;
|
PROBLEM: putting in a loader config file a line of the form
loader_conf_files="foo bar baz"
should cause loading the files listed, and then resume with the
remaining config files (from previous values of the variable).
Unfortunately, sometimes the line was ignored -- actually even
modifying the line in /boot/default/loader.conf sometimes doesn't work.
ANALYSIS: After much investigation, turned out to be a bug in the logic.
The existing code detected a new assignment by looking at the address
of the the variable containing the string. This only worked by pure
chance, i.e. if the new string is longer than the previous value
then the memory allocator may return a different address
to store the string hence triggering the detection.
SOLUTION: This commit contains a minimal change to fix the problem,
without altering too much the existing structure of the code.
However, as a step towards improving the quality and reliability of
this code, I have introduced a handful of one-line functions
(strget, strset, strfree, string= ) that could be used in dozens
of places in the existing code.
HOWEVER:
There is a much bigger problem here. Even though I am no Forth
expert (as most fellow src committers) I can tell that much of the
forth code (in support.4th at least) is in severe need of a
review/refactoring:
+ pieces of code are replicated multiple times instead of writing
functions (see e.g. set_module_*);
+ a lot of stale code (e.g. "structure" definitions for
preloaded_files, kernel_module, pnp stuff) which is not used
or at least belongs elsewhere.
The code bload is extremely bad as the loader runs with very small
memory constraints, and we already hit the limit once (see
http://svn.freebsd.org/viewvc/base?view=revision&revision=185132
Reducing the footprint of the forth files is critical.
+ two different styles of coding, one using pure stack functions
(maybe beautiful but surely highly unreadable), one using
high level mechanisms to give names to arguments and local
variables (which leads to readable code).
Note that this code is used by default by all FreeBSD installations,
so the fragility and the code bloat are extremely damaging.
I will try to work fixing the three items above, but if others have
time, please have a look at these issues.
MFC after: 4 weeks
2008-12-07 19:42:20 +00:00
|
|
|
|
|
|
|
\ free memory and reset fields
|
|
|
|
: strfree { var -- } var .addr @ ?dup if free-memory 0 0 var strset then ;
|
|
|
|
|
|
|
|
\ free old content, make a copy of the string and assign to variable
|
|
|
|
: string= { addr len var -- } var strfree addr len strdup var strset ;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: strtype ( str -- ) strget type ;
|
|
|
|
|
|
|
|
\ assign a reference to what is on the stack
|
|
|
|
: strref { addr len var -- addr len }
|
|
|
|
addr var .addr ! len var .len ! addr len
|
|
|
|
;
|
|
|
|
|
|
|
|
\ unquote a string
|
|
|
|
: unquote ( addr len -- addr len )
|
|
|
|
over c@ [char] " = if 2 chars - swap char+ swap then
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Assignment data temporary storage
|
|
|
|
|
|
|
|
string name_buffer
|
|
|
|
string value_buffer
|
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
\ Line by line file reading functions
|
|
|
|
\
|
|
|
|
\ exported:
|
|
|
|
\ line_buffer
|
|
|
|
\ end_of_file?
|
|
|
|
\ fd
|
|
|
|
\ read_line
|
|
|
|
\ reset_line_reading
|
|
|
|
|
|
|
|
vocabulary line-reading
|
2015-04-01 01:54:28 +00:00
|
|
|
also line-reading definitions
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ File data temporary storage
|
|
|
|
|
|
|
|
string read_buffer
|
|
|
|
0 value read_buffer_ptr
|
|
|
|
|
|
|
|
\ File's line reading function
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
get-current ( -- wid ) previous definitions
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
|
|
|
string line_buffer
|
1999-03-09 14:06:55 +00:00
|
|
|
0 value end_of_file?
|
|
|
|
variable fd
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
>search ( wid -- ) definitions
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: skip_newlines
|
|
|
|
begin
|
|
|
|
read_buffer .len @ read_buffer_ptr >
|
|
|
|
while
|
|
|
|
read_buffer .addr @ read_buffer_ptr + c@ lf = if
|
|
|
|
read_buffer_ptr char+ to read_buffer_ptr
|
|
|
|
else
|
|
|
|
exit
|
|
|
|
then
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
|
|
|
: scan_buffer ( -- addr len )
|
|
|
|
read_buffer_ptr >r
|
|
|
|
begin
|
|
|
|
read_buffer .len @ r@ >
|
|
|
|
while
|
|
|
|
read_buffer .addr @ r@ + c@ lf = if
|
|
|
|
read_buffer .addr @ read_buffer_ptr + ( -- addr )
|
|
|
|
r@ read_buffer_ptr - ( -- len )
|
|
|
|
r> to read_buffer_ptr
|
|
|
|
exit
|
|
|
|
then
|
|
|
|
r> char+ >r
|
|
|
|
repeat
|
|
|
|
read_buffer .addr @ read_buffer_ptr + ( -- addr )
|
|
|
|
r@ read_buffer_ptr - ( -- len )
|
|
|
|
r> to read_buffer_ptr
|
|
|
|
;
|
|
|
|
|
|
|
|
: line_buffer_resize ( len -- len )
|
|
|
|
>r
|
|
|
|
line_buffer .len @ if
|
|
|
|
line_buffer .addr @
|
|
|
|
line_buffer .len @ r@ +
|
2009-01-05 20:09:54 +00:00
|
|
|
resize if ENOMEM throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
else
|
2009-01-05 20:09:54 +00:00
|
|
|
r@ allocate if ENOMEM throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
line_buffer .addr !
|
|
|
|
r>
|
|
|
|
;
|
|
|
|
|
|
|
|
: append_to_line_buffer ( addr len -- )
|
2009-01-05 20:09:54 +00:00
|
|
|
line_buffer strget
|
1999-03-09 14:06:55 +00:00
|
|
|
2swap strcat
|
|
|
|
line_buffer .len !
|
|
|
|
drop
|
|
|
|
;
|
|
|
|
|
|
|
|
: read_from_buffer
|
|
|
|
scan_buffer ( -- addr len )
|
|
|
|
line_buffer_resize ( len -- len )
|
|
|
|
append_to_line_buffer ( addr len -- )
|
|
|
|
;
|
|
|
|
|
|
|
|
: refill_required?
|
|
|
|
read_buffer .len @ read_buffer_ptr =
|
|
|
|
end_of_file? 0= and
|
|
|
|
;
|
|
|
|
|
|
|
|
: refill_buffer
|
|
|
|
0 to read_buffer_ptr
|
|
|
|
read_buffer .addr @ 0= if
|
2009-01-05 20:09:54 +00:00
|
|
|
read_buffer_size allocate if ENOMEM throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
read_buffer .addr !
|
|
|
|
then
|
|
|
|
fd @ read_buffer .addr @ read_buffer_size fread
|
2009-01-05 20:09:54 +00:00
|
|
|
dup -1 = if EREAD throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
dup 0= if true to end_of_file? then
|
|
|
|
read_buffer .len !
|
|
|
|
;
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
get-current ( -- wid ) previous definitions >search ( wid -- )
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
|
|
|
: reset_line_reading
|
|
|
|
0 to read_buffer_ptr
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: read_line
|
2009-01-05 20:09:54 +00:00
|
|
|
line_buffer strfree
|
1999-03-09 14:06:55 +00:00
|
|
|
skip_newlines
|
|
|
|
begin
|
|
|
|
read_from_buffer
|
|
|
|
refill_required?
|
|
|
|
while
|
|
|
|
refill_buffer
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
only forth also support-functions definitions
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Conf file line parser:
|
|
|
|
\ <line> ::= <spaces><name><spaces>'='<spaces><value><spaces>[<comment>] |
|
|
|
|
\ <spaces>[<comment>]
|
|
|
|
\ <name> ::= <letter>{<letter>|<digit>|'_'}
|
|
|
|
\ <value> ::= '"'{<character_set>|'\'<anything>}'"' | <name>
|
|
|
|
\ <character_set> ::= ASCII 32 to 126, except '\' and '"'
|
|
|
|
\ <comment> ::= '#'{<anything>}
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
\
|
|
|
|
\ exported:
|
|
|
|
\ line_pointer
|
|
|
|
\ process_conf
|
1999-03-09 14:06:55 +00:00
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
0 value line_pointer
|
|
|
|
|
|
|
|
vocabulary file-processing
|
|
|
|
also file-processing definitions
|
1999-03-09 14:06:55 +00:00
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
\ parser functions
|
|
|
|
\
|
|
|
|
\ exported:
|
|
|
|
\ get_assignment
|
|
|
|
|
|
|
|
vocabulary parser
|
2015-04-01 01:54:28 +00:00
|
|
|
also parser definitions
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
|
|
|
0 value parsing_function
|
1999-03-09 14:06:55 +00:00
|
|
|
0 value end_of_line
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: end_of_line? line_pointer end_of_line = ;
|
|
|
|
|
|
|
|
\ classifiers for various character classes in the input line
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
: letter?
|
|
|
|
line_pointer c@ >r
|
|
|
|
r@ [char] A >=
|
|
|
|
r@ [char] Z <= and
|
|
|
|
r@ [char] a >=
|
|
|
|
r> [char] z <= and
|
|
|
|
or
|
|
|
|
;
|
|
|
|
|
|
|
|
: digit?
|
|
|
|
line_pointer c@ >r
|
2007-12-19 17:06:32 +00:00
|
|
|
r@ [char] - =
|
1999-03-09 14:06:55 +00:00
|
|
|
r@ [char] 0 >=
|
|
|
|
r> [char] 9 <= and
|
2007-12-19 17:06:32 +00:00
|
|
|
or
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: quote? line_pointer c@ [char] " = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: assignment_sign? line_pointer c@ [char] = = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: comment? line_pointer c@ [char] # = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: space? line_pointer c@ bl = line_pointer c@ tab = or ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: backslash? line_pointer c@ [char] \ = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: underscore? line_pointer c@ [char] _ = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: dot? line_pointer c@ [char] . = ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ manipulation of input line
|
|
|
|
: skip_character line_pointer char+ to line_pointer ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: skip_to_end_of_line end_of_line to line_pointer ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
: eat_space
|
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? if 0 else space? then
|
1999-03-09 14:06:55 +00:00
|
|
|
while
|
|
|
|
skip_character
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
|
|
|
: parse_name ( -- addr len )
|
|
|
|
line_pointer
|
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? if 0 else letter? digit? underscore? dot? or or or then
|
1999-03-09 14:06:55 +00:00
|
|
|
while
|
|
|
|
skip_character
|
|
|
|
repeat
|
|
|
|
line_pointer over -
|
|
|
|
strdup
|
|
|
|
;
|
|
|
|
|
|
|
|
: remove_backslashes { addr len | addr' len' -- addr' len' }
|
2009-01-05 20:09:54 +00:00
|
|
|
len allocate if ENOMEM throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
to addr'
|
|
|
|
addr >r
|
|
|
|
begin
|
|
|
|
addr c@ [char] \ <> if
|
|
|
|
addr c@ addr' len' + c!
|
|
|
|
len' char+ to len'
|
|
|
|
then
|
|
|
|
addr char+ to addr
|
|
|
|
r@ len + addr =
|
|
|
|
until
|
|
|
|
r> drop
|
|
|
|
addr' len'
|
|
|
|
;
|
|
|
|
|
|
|
|
: parse_quote ( -- addr len )
|
|
|
|
line_pointer
|
|
|
|
skip_character
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
begin
|
|
|
|
quote? 0=
|
|
|
|
while
|
|
|
|
backslash? if
|
|
|
|
skip_character
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
skip_character
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
repeat
|
|
|
|
skip_character
|
|
|
|
line_pointer over -
|
|
|
|
remove_backslashes
|
|
|
|
;
|
|
|
|
|
|
|
|
: read_name
|
|
|
|
parse_name ( -- addr len )
|
2009-01-05 20:09:54 +00:00
|
|
|
name_buffer strset
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: read_value
|
|
|
|
quote? if
|
|
|
|
parse_quote ( -- addr len )
|
|
|
|
else
|
|
|
|
parse_name ( -- addr len )
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strset
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: comment
|
|
|
|
skip_to_end_of_line
|
|
|
|
;
|
|
|
|
|
|
|
|
: white_space_4
|
|
|
|
eat_space
|
|
|
|
comment? if ['] comment to parsing_function exit then
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? 0= if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: variable_value
|
|
|
|
read_value
|
|
|
|
['] white_space_4 to parsing_function
|
|
|
|
;
|
|
|
|
|
|
|
|
: white_space_3
|
|
|
|
eat_space
|
|
|
|
letter? digit? quote? or or if
|
|
|
|
['] variable_value to parsing_function exit
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
ESYNTAX throw
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: assignment_sign
|
|
|
|
skip_character
|
|
|
|
['] white_space_3 to parsing_function
|
|
|
|
;
|
|
|
|
|
|
|
|
: white_space_2
|
|
|
|
eat_space
|
|
|
|
assignment_sign? if ['] assignment_sign to parsing_function exit then
|
2009-01-05 20:09:54 +00:00
|
|
|
ESYNTAX throw
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: variable_name
|
|
|
|
read_name
|
|
|
|
['] white_space_2 to parsing_function
|
|
|
|
;
|
|
|
|
|
|
|
|
: white_space_1
|
|
|
|
eat_space
|
|
|
|
letter? if ['] variable_name to parsing_function exit then
|
|
|
|
comment? if ['] comment to parsing_function exit then
|
2009-01-05 20:09:54 +00:00
|
|
|
end_of_line? 0= if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
get-current ( -- wid ) previous definitions >search ( wid -- )
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: get_assignment
|
2009-01-05 20:09:54 +00:00
|
|
|
line_buffer strget + to end_of_line
|
1999-03-09 14:06:55 +00:00
|
|
|
line_buffer .addr @ to line_pointer
|
|
|
|
['] white_space_1 to parsing_function
|
|
|
|
begin
|
|
|
|
end_of_line? 0=
|
|
|
|
while
|
|
|
|
parsing_function execute
|
|
|
|
repeat
|
|
|
|
parsing_function ['] comment =
|
|
|
|
parsing_function ['] white_space_1 =
|
|
|
|
parsing_function ['] white_space_4 =
|
2009-01-05 20:09:54 +00:00
|
|
|
or or 0= if ESYNTAX throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
only forth also support-functions also file-processing definitions
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Process line
|
|
|
|
|
|
|
|
: assignment_type? ( addr len -- flag )
|
2009-01-05 20:09:54 +00:00
|
|
|
name_buffer strget
|
1999-03-09 14:06:55 +00:00
|
|
|
compare 0=
|
|
|
|
;
|
|
|
|
|
|
|
|
: suffix_type? ( addr len -- flag )
|
|
|
|
name_buffer .len @ over <= if 2drop false exit then
|
|
|
|
name_buffer .len @ over - name_buffer .addr @ +
|
|
|
|
over compare 0=
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: loader_conf_files? s" loader_conf_files" assignment_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: nextboot_flag? s" nextboot_enable" assignment_type? ;
|
2002-05-24 02:28:58 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: nextboot_conf? s" nextboot_conf" assignment_type? ;
|
2002-05-24 02:28:58 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: verbose_flag? s" verbose_loading" assignment_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: execute? s" exec" assignment_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_load? load_module_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_loadname? module_loadname_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_type? module_type_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_args? module_args_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_beforeload? module_beforeload_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_afterload? module_afterload_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: module_loaderror? module_loaderror_suffix suffix_type? ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ build a 'set' statement and execute it
|
|
|
|
: set_environment_variable
|
|
|
|
name_buffer .len @ value_buffer .len @ + 5 chars + \ size of result string
|
|
|
|
allocate if ENOMEM throw then
|
|
|
|
dup 0 \ start with an empty string and append the pieces
|
|
|
|
s" set " strcat
|
|
|
|
name_buffer strget strcat
|
|
|
|
s" =" strcat
|
|
|
|
value_buffer strget strcat
|
|
|
|
['] evaluate catch if
|
|
|
|
2drop free drop
|
|
|
|
ESETERROR throw
|
2002-05-24 02:28:58 +00:00
|
|
|
else
|
2009-01-05 20:09:54 +00:00
|
|
|
free-memory
|
2002-05-24 02:28:58 +00:00
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_conf_files
|
|
|
|
set_environment_variable
|
|
|
|
s" loader_conf_files" getenv conf_files string=
|
|
|
|
;
|
|
|
|
|
2015-12-31 19:37:14 +00:00
|
|
|
: set_nextboot_conf
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote nextboot_conf_file string=
|
2002-05-24 02:28:58 +00:00
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: append_to_module_options_list ( addr -- )
|
|
|
|
module_options @ 0= if
|
|
|
|
dup module_options !
|
|
|
|
last_module_option !
|
|
|
|
else
|
|
|
|
dup last_module_option @ module.next !
|
|
|
|
last_module_option !
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: set_module_name { addr -- } \ check leaks
|
|
|
|
name_buffer strget addr module.name string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: yes_value?
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget \ XXX could use unquote
|
1999-03-09 14:06:55 +00:00
|
|
|
2dup s' "YES"' compare >r
|
|
|
|
2dup s' "yes"' compare >r
|
|
|
|
2dup s" YES" compare >r
|
|
|
|
s" yes" compare r> r> r> and and and 0=
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: find_module_option ( -- addr | 0 ) \ return ptr to entry matching name_buffer
|
1999-03-09 14:06:55 +00:00
|
|
|
module_options @
|
|
|
|
begin
|
|
|
|
dup
|
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.name strget
|
|
|
|
name_buffer strget
|
1999-03-09 14:06:55 +00:00
|
|
|
compare 0= if exit then
|
|
|
|
module.next @
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
|
|
|
: new_module_option ( -- addr )
|
2009-01-05 20:09:54 +00:00
|
|
|
sizeof module allocate if ENOMEM throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
dup sizeof module erase
|
|
|
|
dup append_to_module_options_list
|
|
|
|
dup set_module_name
|
|
|
|
;
|
|
|
|
|
|
|
|
: get_module_option ( -- addr )
|
|
|
|
find_module_option
|
|
|
|
?dup 0= if new_module_option then
|
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_flag
|
|
|
|
name_buffer .len @ load_module_suffix nip - name_buffer .len !
|
|
|
|
yes_value? get_module_option module.flag !
|
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_args
|
|
|
|
name_buffer .len @ module_args_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.args string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_loadname
|
|
|
|
name_buffer .len @ module_loadname_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.loadname string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_type
|
|
|
|
name_buffer .len @ module_type_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.type string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_beforeload
|
|
|
|
name_buffer .len @ module_beforeload_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.beforeload string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_afterload
|
|
|
|
name_buffer .len @ module_afterload_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.afterload string=
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: set_module_loaderror
|
|
|
|
name_buffer .len @ module_loaderror_suffix nip - name_buffer .len !
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
get_module_option module.loaderror string=
|
PROBLEM: putting in a loader config file a line of the form
loader_conf_files="foo bar baz"
should cause loading the files listed, and then resume with the
remaining config files (from previous values of the variable).
Unfortunately, sometimes the line was ignored -- actually even
modifying the line in /boot/default/loader.conf sometimes doesn't work.
ANALYSIS: After much investigation, turned out to be a bug in the logic.
The existing code detected a new assignment by looking at the address
of the the variable containing the string. This only worked by pure
chance, i.e. if the new string is longer than the previous value
then the memory allocator may return a different address
to store the string hence triggering the detection.
SOLUTION: This commit contains a minimal change to fix the problem,
without altering too much the existing structure of the code.
However, as a step towards improving the quality and reliability of
this code, I have introduced a handful of one-line functions
(strget, strset, strfree, string= ) that could be used in dozens
of places in the existing code.
HOWEVER:
There is a much bigger problem here. Even though I am no Forth
expert (as most fellow src committers) I can tell that much of the
forth code (in support.4th at least) is in severe need of a
review/refactoring:
+ pieces of code are replicated multiple times instead of writing
functions (see e.g. set_module_*);
+ a lot of stale code (e.g. "structure" definitions for
preloaded_files, kernel_module, pnp stuff) which is not used
or at least belongs elsewhere.
The code bload is extremely bad as the loader runs with very small
memory constraints, and we already hit the limit once (see
http://svn.freebsd.org/viewvc/base?view=revision&revision=185132
Reducing the footprint of the forth files is critical.
+ two different styles of coding, one using pure stack functions
(maybe beautiful but surely highly unreadable), one using
high level mechanisms to give names to arguments and local
variables (which leads to readable code).
Note that this code is used by default by all FreeBSD installations,
so the fragility and the code bloat are extremely damaging.
I will try to work fixing the three items above, but if others have
time, please have a look at these issues.
MFC after: 4 weeks
2008-12-07 19:42:20 +00:00
|
|
|
;
|
|
|
|
|
2002-05-24 02:28:58 +00:00
|
|
|
: set_nextboot_flag
|
|
|
|
yes_value? to nextboot?
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: set_verbose
|
|
|
|
yes_value? to verbose?
|
|
|
|
;
|
|
|
|
|
|
|
|
: execute_command
|
2009-01-05 20:09:54 +00:00
|
|
|
value_buffer strget unquote
|
|
|
|
['] evaluate catch if EEXEC throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: process_assignment
|
|
|
|
name_buffer .len @ 0= if exit then
|
|
|
|
loader_conf_files? if set_conf_files exit then
|
2002-05-24 02:28:58 +00:00
|
|
|
nextboot_flag? if set_nextboot_flag exit then
|
|
|
|
nextboot_conf? if set_nextboot_conf exit then
|
1999-03-09 14:06:55 +00:00
|
|
|
verbose_flag? if set_verbose exit then
|
|
|
|
execute? if execute_command exit then
|
|
|
|
module_load? if set_module_flag exit then
|
|
|
|
module_loadname? if set_module_loadname exit then
|
|
|
|
module_type? if set_module_type exit then
|
|
|
|
module_args? if set_module_args exit then
|
|
|
|
module_beforeload? if set_module_beforeload exit then
|
|
|
|
module_afterload? if set_module_afterload exit then
|
|
|
|
module_loaderror? if set_module_loaderror exit then
|
|
|
|
set_environment_variable
|
|
|
|
;
|
|
|
|
|
1999-11-24 17:56:40 +00:00
|
|
|
\ free_buffer ( -- )
|
|
|
|
\
|
|
|
|
\ Free some pointers if needed. The code then tests for errors
|
|
|
|
\ in freeing, and throws an exception if needed. If a pointer is
|
|
|
|
\ not allocated, it's value (0) is used as flag.
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: free_buffers
|
2009-01-05 20:09:54 +00:00
|
|
|
name_buffer strfree
|
|
|
|
value_buffer strfree
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
\ Higher level file processing
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
get-current ( -- wid ) previous definitions >search ( wid -- )
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: process_conf
|
|
|
|
begin
|
|
|
|
end_of_file? 0=
|
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
free_buffers
|
1999-03-09 14:06:55 +00:00
|
|
|
read_line
|
|
|
|
get_assignment
|
|
|
|
['] process_assignment catch
|
|
|
|
['] free_buffers catch
|
|
|
|
swap throw throw
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
2015-12-30 02:15:12 +00:00
|
|
|
: peek_file ( addr len -- )
|
2002-05-24 02:28:58 +00:00
|
|
|
0 to end_of_file?
|
|
|
|
reset_line_reading
|
|
|
|
O_RDONLY fopen fd !
|
2009-01-05 20:09:54 +00:00
|
|
|
fd @ -1 = if EOPEN throw then
|
|
|
|
free_buffers
|
2002-05-24 02:28:58 +00:00
|
|
|
read_line
|
|
|
|
get_assignment
|
|
|
|
['] process_assignment catch
|
|
|
|
['] free_buffers catch
|
|
|
|
fd @ fclose
|
2015-12-30 02:15:12 +00:00
|
|
|
swap throw throw
|
2002-05-24 02:28:58 +00:00
|
|
|
;
|
|
|
|
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
only forth also support-functions definitions
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Interface to loading conf files
|
|
|
|
|
|
|
|
: load_conf ( addr len -- )
|
|
|
|
0 to end_of_file?
|
Add constructors to crude structure support. Rework some of the
code into a more modular interface, with hidden vocabularies and
such. Remove the need to a lot of ugly initialization.
Also, add a few structure definitions, from stuff used on the C
part of loader. Some of this will disappear, and the crude structure
support will most likely be replaced by full-blown OOP support
already present on FICL, but not installed by default. But it was
getting increasingly inconvenient to keep this separate on my tree,
and I already lost lots of work once because of the hurdles, so
commit this.
Anyway, it makes support.4th more structured, and I'm not proceeding
with the work on it any time soon, unfortunately.
2000-09-08 16:57:28 +00:00
|
|
|
reset_line_reading
|
2001-12-11 00:49:34 +00:00
|
|
|
O_RDONLY fopen fd !
|
2009-01-05 20:09:54 +00:00
|
|
|
fd @ -1 = if EOPEN throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
['] process_conf catch
|
|
|
|
fd @ fclose
|
|
|
|
throw
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: print_line line_buffer strtype cr ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
: print_syntax_error
|
2009-01-05 20:09:54 +00:00
|
|
|
line_buffer strtype cr
|
1999-03-09 14:06:55 +00:00
|
|
|
line_buffer .addr @
|
|
|
|
begin
|
|
|
|
line_pointer over <>
|
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
bl emit char+
|
1999-03-09 14:06:55 +00:00
|
|
|
repeat
|
|
|
|
drop
|
|
|
|
." ^" cr
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
|
2006-10-13 20:48:17 +00:00
|
|
|
\ Debugging support functions
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
only forth definitions also support-functions
|
|
|
|
|
|
|
|
: test-file
|
|
|
|
['] load_conf catch dup .
|
2009-01-05 20:09:54 +00:00
|
|
|
ESYNTAX = if cr print_syntax_error then
|
|
|
|
;
|
|
|
|
|
|
|
|
\ find a module name, leave addr on the stack (0 if not found)
|
|
|
|
: find-module ( <module> -- ptr | 0 )
|
|
|
|
bl parse ( addr len )
|
|
|
|
module_options @ >r ( store current pointer )
|
|
|
|
begin
|
|
|
|
r@
|
|
|
|
while
|
|
|
|
2dup ( addr len addr len )
|
|
|
|
r@ module.name strget
|
|
|
|
compare 0= if drop drop r> exit then ( found it )
|
|
|
|
r> module.next @ >r
|
|
|
|
repeat
|
|
|
|
type ." was not found" cr r>
|
|
|
|
;
|
|
|
|
|
|
|
|
: show-nonempty ( addr len mod -- )
|
|
|
|
strget dup verbose? or if
|
|
|
|
2swap type type cr
|
|
|
|
else
|
|
|
|
drop drop drop drop
|
|
|
|
then ;
|
|
|
|
|
|
|
|
: show-one-module { addr -- addr }
|
|
|
|
." Name: " addr module.name strtype cr
|
|
|
|
s" Path: " addr module.loadname show-nonempty
|
|
|
|
s" Type: " addr module.type show-nonempty
|
|
|
|
s" Flags: " addr module.args show-nonempty
|
|
|
|
s" Before load: " addr module.beforeload show-nonempty
|
|
|
|
s" After load: " addr module.afterload show-nonempty
|
|
|
|
s" Error: " addr module.loaderror show-nonempty
|
|
|
|
." Status: " addr module.flag @ if ." Load" else ." Don't load" then cr
|
|
|
|
cr
|
|
|
|
addr
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: show-module-options
|
|
|
|
module_options @
|
|
|
|
begin
|
|
|
|
?dup
|
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
show-one-module
|
1999-03-09 14:06:55 +00:00
|
|
|
module.next @
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
2015-12-31 20:00:53 +00:00
|
|
|
: free-one-module { addr -- addr }
|
|
|
|
addr module.name strfree
|
|
|
|
addr module.loadname strfree
|
|
|
|
addr module.type strfree
|
|
|
|
addr module.args strfree
|
|
|
|
addr module.beforeload strfree
|
|
|
|
addr module.afterload strfree
|
|
|
|
addr module.loaderror strfree
|
|
|
|
addr
|
|
|
|
;
|
|
|
|
|
|
|
|
: free-module-options
|
|
|
|
module_options @
|
|
|
|
begin
|
|
|
|
?dup
|
|
|
|
while
|
|
|
|
free-one-module
|
|
|
|
dup module.next @
|
|
|
|
swap free-memory
|
|
|
|
repeat
|
|
|
|
0 module_options !
|
|
|
|
0 last_module_option !
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
only forth also support-functions definitions
|
|
|
|
|
|
|
|
\ Variables used for processing multiple conf files
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
string current_file_name_ref \ used to print the file name
|
1999-03-09 14:06:55 +00:00
|
|
|
|
2016-04-30 02:47:41 +00:00
|
|
|
\ Indicates if any conf file was successfully read
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
0 value any_conf_read?
|
|
|
|
|
|
|
|
\ loader_conf_files processing support functions
|
|
|
|
|
PROBLEM: putting in a loader config file a line of the form
loader_conf_files="foo bar baz"
should cause loading the files listed, and then resume with the
remaining config files (from previous values of the variable).
Unfortunately, sometimes the line was ignored -- actually even
modifying the line in /boot/default/loader.conf sometimes doesn't work.
ANALYSIS: After much investigation, turned out to be a bug in the logic.
The existing code detected a new assignment by looking at the address
of the the variable containing the string. This only worked by pure
chance, i.e. if the new string is longer than the previous value
then the memory allocator may return a different address
to store the string hence triggering the detection.
SOLUTION: This commit contains a minimal change to fix the problem,
without altering too much the existing structure of the code.
However, as a step towards improving the quality and reliability of
this code, I have introduced a handful of one-line functions
(strget, strset, strfree, string= ) that could be used in dozens
of places in the existing code.
HOWEVER:
There is a much bigger problem here. Even though I am no Forth
expert (as most fellow src committers) I can tell that much of the
forth code (in support.4th at least) is in severe need of a
review/refactoring:
+ pieces of code are replicated multiple times instead of writing
functions (see e.g. set_module_*);
+ a lot of stale code (e.g. "structure" definitions for
preloaded_files, kernel_module, pnp stuff) which is not used
or at least belongs elsewhere.
The code bload is extremely bad as the loader runs with very small
memory constraints, and we already hit the limit once (see
http://svn.freebsd.org/viewvc/base?view=revision&revision=185132
Reducing the footprint of the forth files is critical.
+ two different styles of coding, one using pure stack functions
(maybe beautiful but surely highly unreadable), one using
high level mechanisms to give names to arguments and local
variables (which leads to readable code).
Note that this code is used by default by all FreeBSD installations,
so the fragility and the code bloat are extremely damaging.
I will try to work fixing the three items above, but if others have
time, please have a look at these issues.
MFC after: 4 weeks
2008-12-07 19:42:20 +00:00
|
|
|
: get_conf_files ( -- addr len ) \ put addr/len on stack, reset var
|
|
|
|
conf_files strget 0 0 conf_files strset
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
1999-11-24 17:56:40 +00:00
|
|
|
: skip_leading_spaces { addr len pos -- addr len pos' }
|
1999-03-09 14:06:55 +00:00
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
pos len = if 0 else addr pos + c@ bl = then
|
1999-03-09 14:06:55 +00:00
|
|
|
while
|
1999-11-24 17:56:40 +00:00
|
|
|
pos char+ to pos
|
1999-03-09 14:06:55 +00:00
|
|
|
repeat
|
1999-11-24 17:56:40 +00:00
|
|
|
addr len pos
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ return the file name at pos, or free the string if nothing left
|
1999-11-24 17:56:40 +00:00
|
|
|
: get_file_name { addr len pos -- addr len pos' addr' len' || 0 }
|
|
|
|
pos len = if
|
1999-03-09 14:06:55 +00:00
|
|
|
addr free abort" Fatal error freeing memory"
|
|
|
|
0 exit
|
|
|
|
then
|
1999-11-24 17:56:40 +00:00
|
|
|
pos >r
|
1999-03-09 14:06:55 +00:00
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
\ stay in the loop until have chars and they are not blank
|
|
|
|
pos len = if 0 else addr pos + c@ bl <> then
|
1999-03-09 14:06:55 +00:00
|
|
|
while
|
1999-11-24 17:56:40 +00:00
|
|
|
pos char+ to pos
|
1999-03-09 14:06:55 +00:00
|
|
|
repeat
|
1999-11-24 17:56:40 +00:00
|
|
|
addr len pos addr r@ + pos r> -
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: get_next_file ( addr len ptr -- addr len ptr' addr' len' | 0 )
|
|
|
|
skip_leading_spaces
|
|
|
|
get_file_name
|
|
|
|
;
|
|
|
|
|
|
|
|
: print_current_file
|
2009-01-05 20:09:54 +00:00
|
|
|
current_file_name_ref strtype
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: process_conf_errors
|
|
|
|
dup 0= if true to any_conf_read? drop exit then
|
|
|
|
>r 2drop r>
|
2009-01-05 20:09:54 +00:00
|
|
|
dup ESYNTAX = if
|
1999-03-09 14:06:55 +00:00
|
|
|
." Warning: syntax error on file " print_current_file cr
|
|
|
|
print_syntax_error drop exit
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
dup ESETERROR = if
|
1999-03-09 14:06:55 +00:00
|
|
|
." Warning: bad definition on file " print_current_file cr
|
|
|
|
print_line drop exit
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
dup EREAD = if
|
1999-03-09 14:06:55 +00:00
|
|
|
." Warning: error reading file " print_current_file cr drop exit
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
dup EOPEN = if
|
1999-03-09 14:06:55 +00:00
|
|
|
verbose? if ." Warning: unable to open file " print_current_file cr then
|
|
|
|
drop exit
|
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
dup EFREE = abort" Fatal error freeing memory"
|
|
|
|
dup ENOMEM = abort" Out of memory"
|
1999-03-09 14:06:55 +00:00
|
|
|
throw \ Unknown error -- pass ahead
|
|
|
|
;
|
|
|
|
|
|
|
|
\ Process loader_conf_files recursively
|
|
|
|
\ Interface to loader_conf_files processing
|
|
|
|
|
|
|
|
: include_conf_files
|
2009-01-05 20:09:54 +00:00
|
|
|
get_conf_files 0 ( addr len offset )
|
1999-03-09 14:06:55 +00:00
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
get_next_file ?dup ( addr len 1 | 0 )
|
1999-03-09 14:06:55 +00:00
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
current_file_name_ref strref
|
1999-03-09 14:06:55 +00:00
|
|
|
['] load_conf catch
|
|
|
|
process_conf_errors
|
PROBLEM: putting in a loader config file a line of the form
loader_conf_files="foo bar baz"
should cause loading the files listed, and then resume with the
remaining config files (from previous values of the variable).
Unfortunately, sometimes the line was ignored -- actually even
modifying the line in /boot/default/loader.conf sometimes doesn't work.
ANALYSIS: After much investigation, turned out to be a bug in the logic.
The existing code detected a new assignment by looking at the address
of the the variable containing the string. This only worked by pure
chance, i.e. if the new string is longer than the previous value
then the memory allocator may return a different address
to store the string hence triggering the detection.
SOLUTION: This commit contains a minimal change to fix the problem,
without altering too much the existing structure of the code.
However, as a step towards improving the quality and reliability of
this code, I have introduced a handful of one-line functions
(strget, strset, strfree, string= ) that could be used in dozens
of places in the existing code.
HOWEVER:
There is a much bigger problem here. Even though I am no Forth
expert (as most fellow src committers) I can tell that much of the
forth code (in support.4th at least) is in severe need of a
review/refactoring:
+ pieces of code are replicated multiple times instead of writing
functions (see e.g. set_module_*);
+ a lot of stale code (e.g. "structure" definitions for
preloaded_files, kernel_module, pnp stuff) which is not used
or at least belongs elsewhere.
The code bload is extremely bad as the loader runs with very small
memory constraints, and we already hit the limit once (see
http://svn.freebsd.org/viewvc/base?view=revision&revision=185132
Reducing the footprint of the forth files is critical.
+ two different styles of coding, one using pure stack functions
(maybe beautiful but surely highly unreadable), one using
high level mechanisms to give names to arguments and local
variables (which leads to readable code).
Note that this code is used by default by all FreeBSD installations,
so the fragility and the code bloat are extremely damaging.
I will try to work fixing the three items above, but if others have
time, please have a look at these issues.
MFC after: 4 weeks
2008-12-07 19:42:20 +00:00
|
|
|
conf_files .addr @ if recurse then
|
1999-03-09 14:06:55 +00:00
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
2002-05-24 02:28:58 +00:00
|
|
|
: get_nextboot_conf_file ( -- addr len )
|
2015-12-31 19:33:17 +00:00
|
|
|
nextboot_conf_file strget
|
2002-05-24 02:28:58 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
: rewrite_nextboot_file ( -- )
|
|
|
|
get_nextboot_conf_file
|
|
|
|
O_WRONLY fopen fd !
|
2009-01-05 20:09:54 +00:00
|
|
|
fd @ -1 = if EOPEN throw then
|
2015-12-30 02:15:12 +00:00
|
|
|
fd @ s' nextboot_enable="NO" ' fwrite ( fd buf len -- nwritten ) drop
|
2002-05-24 02:28:58 +00:00
|
|
|
fd @ fclose
|
|
|
|
;
|
|
|
|
|
2015-12-30 02:15:12 +00:00
|
|
|
: include_nextboot_file ( -- )
|
2002-05-24 02:28:58 +00:00
|
|
|
get_nextboot_conf_file
|
2015-12-30 02:15:12 +00:00
|
|
|
['] peek_file catch if 2drop then
|
2002-05-24 02:28:58 +00:00
|
|
|
nextboot? if
|
|
|
|
get_nextboot_conf_file
|
2015-12-30 02:15:12 +00:00
|
|
|
current_file_name_ref strref
|
2002-05-24 02:28:58 +00:00
|
|
|
['] load_conf catch
|
|
|
|
process_conf_errors
|
2015-12-30 02:15:12 +00:00
|
|
|
['] rewrite_nextboot_file catch if 2drop then
|
2002-05-24 02:28:58 +00:00
|
|
|
then
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
\ Module loading functions
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
: load_parameters { addr -- addr addrN lenN ... addr1 len1 N }
|
|
|
|
addr
|
|
|
|
addr module.args strget
|
|
|
|
addr module.loadname .len @ if
|
|
|
|
addr module.loadname strget
|
1999-03-09 14:06:55 +00:00
|
|
|
else
|
2009-01-05 20:09:54 +00:00
|
|
|
addr module.name strget
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
addr module.type .len @ if
|
|
|
|
addr module.type strget
|
1999-03-09 14:06:55 +00:00
|
|
|
s" -t "
|
|
|
|
4 ( -t type name flags )
|
|
|
|
else
|
|
|
|
2 ( name flags )
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: before_load ( addr -- addr )
|
|
|
|
dup module.beforeload .len @ if
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.beforeload strget
|
|
|
|
['] evaluate catch if EBEFORELOAD throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: after_load ( addr -- addr )
|
|
|
|
dup module.afterload .len @ if
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.afterload strget
|
|
|
|
['] evaluate catch if EAFTERLOAD throw then
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: load_error ( addr -- addr )
|
|
|
|
dup module.loaderror .len @ if
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.loaderror strget
|
1999-03-09 14:06:55 +00:00
|
|
|
evaluate \ This we do not intercept so it can throw errors
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: pre_load_message ( addr -- addr )
|
|
|
|
verbose? if
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.name strtype
|
1999-03-09 14:06:55 +00:00
|
|
|
." ..."
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: load_error_message verbose? if ." failed!" cr then ;
|
|
|
|
|
2016-11-09 21:28:46 +00:00
|
|
|
: load_successful_message verbose? if ." ok" cr then ;
|
1999-03-09 14:06:55 +00:00
|
|
|
|
|
|
|
: load_module
|
|
|
|
load_parameters load
|
|
|
|
;
|
|
|
|
|
|
|
|
: process_module ( addr -- addr )
|
|
|
|
pre_load_message
|
|
|
|
before_load
|
|
|
|
begin
|
|
|
|
['] load_module catch if
|
|
|
|
dup module.loaderror .len @ if
|
|
|
|
load_error \ Command should return a flag!
|
|
|
|
else
|
|
|
|
load_error_message true \ Do not retry
|
|
|
|
then
|
|
|
|
else
|
|
|
|
after_load
|
2016-11-09 21:28:46 +00:00
|
|
|
load_successful_message true \ Successful, do not retry
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
until
|
|
|
|
;
|
|
|
|
|
|
|
|
: process_module_errors ( addr ior -- )
|
2009-01-05 20:09:54 +00:00
|
|
|
dup EBEFORELOAD = if
|
1999-03-09 14:06:55 +00:00
|
|
|
drop
|
|
|
|
." Module "
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.name strtype
|
1999-03-09 14:06:55 +00:00
|
|
|
dup module.loadname .len @ if
|
2009-01-05 20:09:54 +00:00
|
|
|
." (" dup module.loadname strtype ." )"
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
cr
|
|
|
|
." Error executing "
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.beforeload strtype cr \ XXX there was a typo here
|
1999-03-09 14:06:55 +00:00
|
|
|
abort
|
|
|
|
then
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
dup EAFTERLOAD = if
|
1999-03-09 14:06:55 +00:00
|
|
|
drop
|
|
|
|
." Module "
|
|
|
|
dup module.name .addr @ over module.name .len @ type
|
|
|
|
dup module.loadname .len @ if
|
2009-01-05 20:09:54 +00:00
|
|
|
." (" dup module.loadname strtype ." )"
|
1999-03-09 14:06:55 +00:00
|
|
|
then
|
|
|
|
cr
|
|
|
|
." Error executing "
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.afterload strtype cr
|
1999-03-09 14:06:55 +00:00
|
|
|
abort
|
|
|
|
then
|
|
|
|
|
|
|
|
throw \ Don't know what it is all about -- pass ahead
|
|
|
|
;
|
|
|
|
|
|
|
|
\ Module loading interface
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ scan the list of modules, load enabled ones.
|
1999-03-09 14:06:55 +00:00
|
|
|
: load_modules ( -- ) ( throws: abort & user-defined )
|
2009-01-05 20:09:54 +00:00
|
|
|
module_options @ ( list_head )
|
1999-03-09 14:06:55 +00:00
|
|
|
begin
|
|
|
|
?dup
|
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
dup module.flag @ if
|
1999-03-09 14:06:55 +00:00
|
|
|
['] process_module catch
|
|
|
|
process_module_errors
|
|
|
|
then
|
|
|
|
module.next @
|
|
|
|
repeat
|
|
|
|
;
|
|
|
|
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\ h00h00 magic used to try loading either a kernel with a given name,
|
|
|
|
\ or a kernel with the default name in a directory of a given name
|
|
|
|
\ (the pain!)
|
|
|
|
|
|
|
|
: bootpath s" /boot/" ;
|
|
|
|
: modulepath s" module_path" ;
|
|
|
|
|
|
|
|
\ Functions used to save and restore module_path's value.
|
|
|
|
: saveenv ( addr len | -1 -- addr' len | 0 -1 )
|
|
|
|
dup -1 = if 0 swap exit then
|
|
|
|
strdup
|
|
|
|
;
|
|
|
|
: freeenv ( addr len | 0 -1 )
|
|
|
|
-1 = if drop else free abort" Freeing error" then
|
|
|
|
;
|
|
|
|
: restoreenv ( addr len | 0 -1 -- )
|
|
|
|
dup -1 = if ( it wasn't set )
|
|
|
|
2drop
|
|
|
|
modulepath unsetenv
|
|
|
|
else
|
|
|
|
over >r
|
|
|
|
modulepath setenv
|
|
|
|
r> free abort" Freeing error"
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: clip_args \ Drop second string if only one argument is passed
|
|
|
|
1 = if
|
|
|
|
2swap 2drop
|
|
|
|
1
|
|
|
|
else
|
|
|
|
2
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
also builtins
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ Parse filename from a semicolon-separated list
|
|
|
|
|
|
|
|
\ replacement, not working yet
|
|
|
|
: newparse-; { addr len | a1 -- a' len-x addr x }
|
|
|
|
addr len [char] ; strchr dup if ( a1 len1 )
|
|
|
|
swap to a1 ( store address )
|
|
|
|
1 - a1 @ 1 + swap ( remove match )
|
|
|
|
addr a1 addr -
|
|
|
|
else
|
|
|
|
0 0 addr len
|
|
|
|
then
|
|
|
|
;
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
|
|
|
|
: parse-; ( addr len -- addr' len-x addr x )
|
2009-01-05 20:09:54 +00:00
|
|
|
over 0 2swap ( addr 0 addr len )
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
dup 0 <> ( addr 0 addr len )
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
over c@ [char] ; <> ( addr 0 addr len flag )
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
while
|
|
|
|
1- swap 1+ swap
|
|
|
|
2swap 1+ 2swap
|
|
|
|
repeat then
|
|
|
|
dup 0 <> if
|
|
|
|
1- swap 1+ swap
|
|
|
|
then
|
|
|
|
2swap
|
|
|
|
;
|
|
|
|
|
|
|
|
\ Try loading one of multiple kernels specified
|
|
|
|
|
|
|
|
: try_multiple_kernels ( addr len addr' len' args -- flag )
|
|
|
|
>r
|
|
|
|
begin
|
|
|
|
parse-; 2>r
|
|
|
|
2over 2r>
|
2000-09-16 20:20:44 +00:00
|
|
|
r@ clip_args
|
|
|
|
s" DEBUG" getenv? if
|
|
|
|
s" echo Module_path: ${module_path}" evaluate
|
|
|
|
." Kernel : " >r 2dup type r> cr
|
|
|
|
dup 2 = if ." Flags : " >r 2over type r> cr then
|
|
|
|
then
|
|
|
|
1 load
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
while
|
|
|
|
dup 0=
|
|
|
|
until
|
|
|
|
1 >r \ Failure
|
|
|
|
else
|
|
|
|
0 >r \ Success
|
|
|
|
then
|
|
|
|
2drop 2drop
|
|
|
|
r>
|
|
|
|
r> drop
|
|
|
|
;
|
|
|
|
|
|
|
|
\ Try to load a kernel; the kernel name is taken from one of
|
|
|
|
\ the following lists, as ordered:
|
|
|
|
\
|
2000-09-09 18:20:00 +00:00
|
|
|
\ 1. The "bootfile" environment variable
|
|
|
|
\ 2. The "kernel" environment variable
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\
|
2000-09-16 19:49:52 +00:00
|
|
|
\ Flags are passed, if available. If not, dummy values must be given.
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\
|
|
|
|
\ The kernel gets loaded from the current module_path.
|
|
|
|
|
2000-09-16 19:49:52 +00:00
|
|
|
: load_a_kernel ( flags len 1 | x x 0 -- flag )
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
local args
|
|
|
|
2local flags
|
|
|
|
0 0 2local kernel
|
|
|
|
end-locals
|
|
|
|
|
|
|
|
\ Check if a default kernel name exists at all, exits if not
|
2000-09-09 18:20:00 +00:00
|
|
|
s" bootfile" getenv dup -1 <> if
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
to kernel
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
flags kernel args 1+ try_multiple_kernels
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
dup 0= if exit then
|
|
|
|
then
|
|
|
|
drop
|
|
|
|
|
2000-09-09 18:20:00 +00:00
|
|
|
s" kernel" getenv dup -1 <> if
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
to kernel
|
|
|
|
else
|
|
|
|
drop
|
|
|
|
1 exit \ Failure
|
|
|
|
then
|
|
|
|
|
|
|
|
\ Try all default kernel names
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
flags kernel args 1+ try_multiple_kernels
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
\ Try to load a kernel; the kernel name is taken from one of
|
|
|
|
\ the following lists, as ordered:
|
|
|
|
\
|
2000-09-09 18:20:00 +00:00
|
|
|
\ 1. The "bootfile" environment variable
|
|
|
|
\ 2. The "kernel" environment variable
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\
|
|
|
|
\ Flags are passed, if provided.
|
|
|
|
\
|
|
|
|
\ The kernel will be loaded from a directory computed from the
|
|
|
|
\ path given. Two directories will be tried in the following order:
|
|
|
|
\
|
|
|
|
\ 1. /boot/path
|
|
|
|
\ 2. path
|
|
|
|
\
|
2016-04-30 02:47:41 +00:00
|
|
|
\ The module_path variable is overridden if load is successful, by
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\ prepending the successful path.
|
|
|
|
|
|
|
|
: load_from_directory ( path len 1 | flags len' path len 2 -- flag )
|
|
|
|
local args
|
|
|
|
2local path
|
|
|
|
args 1 = if 0 0 then
|
|
|
|
2local flags
|
2009-01-05 20:09:54 +00:00
|
|
|
0 0 2local oldmodulepath \ like a string
|
|
|
|
0 0 2local newmodulepath \ like a string
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
end-locals
|
|
|
|
|
|
|
|
\ Set the environment variable module_path, and try loading
|
|
|
|
\ the kernel again.
|
|
|
|
modulepath getenv saveenv to oldmodulepath
|
|
|
|
|
|
|
|
\ Try prepending /boot/ first
|
2009-01-05 20:09:54 +00:00
|
|
|
bootpath nip path nip + \ total length
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
oldmodulepath nip dup -1 = if
|
|
|
|
drop
|
|
|
|
else
|
2009-01-05 20:09:54 +00:00
|
|
|
1+ + \ add oldpath -- XXX why the 1+ ?
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
then
|
2009-01-05 20:09:54 +00:00
|
|
|
allocate if ( out of memory ) 1 exit then \ XXX throw ?
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
|
|
|
|
0
|
|
|
|
bootpath strcat
|
|
|
|
path strcat
|
|
|
|
2dup to newmodulepath
|
|
|
|
modulepath setenv
|
|
|
|
|
|
|
|
\ Try all default kernel names
|
2000-09-16 19:49:52 +00:00
|
|
|
flags args 1- load_a_kernel
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
0= if ( success )
|
|
|
|
oldmodulepath nip -1 <> if
|
|
|
|
newmodulepath s" ;" strcat
|
|
|
|
oldmodulepath strcat
|
|
|
|
modulepath setenv
|
|
|
|
newmodulepath drop free-memory
|
|
|
|
oldmodulepath drop free-memory
|
|
|
|
then
|
|
|
|
0 exit
|
|
|
|
then
|
|
|
|
|
|
|
|
\ Well, try without the prepended /boot/
|
|
|
|
path newmodulepath drop swap move
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
newmodulepath drop path nip
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
2dup to newmodulepath
|
|
|
|
modulepath setenv
|
|
|
|
|
|
|
|
\ Try all default kernel names
|
2000-09-16 19:49:52 +00:00
|
|
|
flags args 1- load_a_kernel
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
if ( failed once more )
|
|
|
|
oldmodulepath restoreenv
|
|
|
|
newmodulepath drop free-memory
|
|
|
|
1
|
|
|
|
else
|
|
|
|
oldmodulepath nip -1 <> if
|
|
|
|
newmodulepath s" ;" strcat
|
|
|
|
oldmodulepath strcat
|
|
|
|
modulepath setenv
|
|
|
|
newmodulepath drop free-memory
|
|
|
|
oldmodulepath drop free-memory
|
|
|
|
then
|
|
|
|
0
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
\ Try to load a kernel; the kernel name is taken from one of
|
|
|
|
\ the following lists, as ordered:
|
|
|
|
\
|
2000-09-09 18:20:00 +00:00
|
|
|
\ 1. The "bootfile" environment variable
|
|
|
|
\ 2. The "kernel" environment variable
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\ 3. The "path" argument
|
|
|
|
\
|
|
|
|
\ Flags are passed, if provided.
|
|
|
|
\
|
|
|
|
\ The kernel will be loaded from a directory computed from the
|
|
|
|
\ path given. Two directories will be tried in the following order:
|
|
|
|
\
|
|
|
|
\ 1. /boot/path
|
|
|
|
\ 2. path
|
|
|
|
\
|
|
|
|
\ Unless "path" is meant to be kernel name itself. In that case, it
|
|
|
|
\ will first be tried as a full path, and, next, search on the
|
|
|
|
\ directories pointed by module_path.
|
|
|
|
\
|
2016-04-30 02:47:41 +00:00
|
|
|
\ The module_path variable is overridden if load is successful, by
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
\ prepending the successful path.
|
|
|
|
|
|
|
|
: load_directory_or_file ( path len 1 | flags len' path len 2 -- flag )
|
|
|
|
local args
|
|
|
|
2local path
|
|
|
|
args 1 = if 0 0 then
|
|
|
|
2local flags
|
|
|
|
end-locals
|
|
|
|
|
|
|
|
\ First, assume path is an absolute path to a directory
|
|
|
|
flags path args clip_args load_from_directory
|
|
|
|
dup 0= if exit else drop then
|
|
|
|
|
|
|
|
\ Next, assume path points to the kernel
|
|
|
|
flags path args try_multiple_kernels
|
|
|
|
;
|
|
|
|
|
1999-03-09 14:06:55 +00:00
|
|
|
: initialize ( addr len -- )
|
2009-01-05 20:09:54 +00:00
|
|
|
strdup conf_files strset
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
: kernel_options ( -- addr len 1 | 0 )
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
s" kernel_options" getenv
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
dup -1 = if drop 0 else 1 then
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
;
|
|
|
|
|
2000-09-16 19:49:52 +00:00
|
|
|
: standard_kernel_search ( flags 1 | 0 -- flag )
|
|
|
|
local args
|
|
|
|
args 0= if 0 0 then
|
|
|
|
2local flags
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
s" kernel" getenv
|
2000-09-16 19:49:52 +00:00
|
|
|
dup -1 = if 0 swap then
|
|
|
|
2local path
|
|
|
|
end-locals
|
|
|
|
|
2000-09-25 11:36:55 +00:00
|
|
|
path nip -1 = if ( there isn't a "kernel" environment variable )
|
2000-09-16 19:49:52 +00:00
|
|
|
flags args load_a_kernel
|
|
|
|
else
|
|
|
|
flags path args 1+ clip_args load_directory_or_file
|
|
|
|
then
|
1999-03-09 14:06:55 +00:00
|
|
|
;
|
|
|
|
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
: load_kernel ( -- ) ( throws: abort )
|
2000-09-16 19:49:52 +00:00
|
|
|
kernel_options standard_kernel_search
|
First tackle at trying to handle the New Deal on kernels.
Load the first of the following kernels to be found:
${kernel} if ${kernel} is an absolute path
/boot/${kernel}/${kernel}
/boot/${kernel}/${bootfile}
${kernel}/${kernel}
${kernel}/${bootfile}
${kernel}
${bootfile}
The last instance of ${kernel} and ${bootfile} will be treated as a
list of semicolon separated file names, and each will be tried in turn,
from left to right.
Also, for each filename loader(8) will try filename, filename.ko,
filename.gz, filename.ko.gz, in that order, but that's not related
to this code.
This resulted in a major reorganization of the code, and much of what
was accumulating on loader.4th was rightly transfered to support.4th.
The semantics of boot-conf and boot also changed. Both will try to load
a kernel the same as above.
After a kernel was loaded, the variable module_path may get changed. Such
change will happen if the kernel was found with a directory prefix. In
that case, the module path will be set to ${directory};${module_path}.
Next, the modules are loaded as usual.
This is intended so kernel="xyzzy" in /boot/loader.conf will load
/boot/xyzzy/kernel.ko, load system modules from /boot/xyzzy/, and
load third party modules from /boot/modules or /modules. If that doesn't
work, it's a bug.
Also, fix a breakage of "boot" which was recently introduced. Boot without
any arguments would fail. No longer. Also, boot will only unload/reload
if the first argument is a path. If no argument exists or the first
argument is a flag, boot will use whatever is already loaded. I hope this
is POLA. That behavior is markedly different from that of boot-conf, which
will always unload/reload.
The semantics introduced here are experimental. Even if the code works,
we might decide this is not the prefered behavior. If you feel so, send
your feedback. (Yeah, this belongs in a HEADS UP or something, but I've
been working for the past 16 hours on this stuff, so gimme a break.)
2000-09-09 04:52:34 +00:00
|
|
|
abort" Unable to load a kernel!"
|
|
|
|
;
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
|
2015-06-02 22:23:20 +00:00
|
|
|
: load_xen ( -- flag )
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
s" xen_kernel" getenv dup -1 <> if
|
2015-06-02 22:23:20 +00:00
|
|
|
1 1 load ( c-addr/u flag N -- flag )
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
else
|
|
|
|
drop
|
2015-06-02 22:23:20 +00:00
|
|
|
0 ( -1 -- flag )
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
then
|
|
|
|
;
|
|
|
|
|
|
|
|
: load_xen_throw ( -- ) ( throws: abort )
|
|
|
|
load_xen
|
|
|
|
abort" Unable to load Xen!"
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: set_defaultoptions ( -- )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
s" kernel_options" getenv dup -1 = if
|
|
|
|
drop
|
|
|
|
else
|
|
|
|
s" temp_options" setenv
|
|
|
|
then
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ pick the i-th argument, i starts at 0
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
: argv[] ( aN uN ... a1 u1 N i -- aN uN ... a1 u1 N ai+1 ui+1 )
|
2009-01-05 20:09:54 +00:00
|
|
|
2dup = if 0 0 exit then \ out of range
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
dup >r
|
|
|
|
1+ 2* ( skip N and ui )
|
|
|
|
pick
|
|
|
|
r>
|
|
|
|
1+ 2* ( skip N and ai )
|
|
|
|
pick
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: drop_args ( aN uN ... a1 u1 N -- )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
0 ?do 2drop loop
|
|
|
|
;
|
|
|
|
|
|
|
|
: argc
|
|
|
|
dup
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: queue_argv ( aN uN ... a1 u1 N a u -- a u aN uN ... a1 u1 N+1 )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
>r
|
|
|
|
over 2* 1+ -roll
|
|
|
|
r>
|
|
|
|
over 2* 1+ -roll
|
|
|
|
1+
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: unqueue_argv ( aN uN ... a1 u1 N -- aN uN ... a2 u2 N-1 a1 u1 )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
1- -rot
|
|
|
|
;
|
|
|
|
|
2009-01-05 20:09:54 +00:00
|
|
|
\ compute the length of the buffer including the spaces between words
|
|
|
|
: strlen(argv) ( aN uN .. a1 u1 N -- aN uN .. a1 u1 N len )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
dup 0= if 0 exit then
|
|
|
|
0 >r \ Size
|
|
|
|
0 >r \ Index
|
|
|
|
begin
|
|
|
|
argc r@ <>
|
|
|
|
while
|
|
|
|
r@ argv[]
|
|
|
|
nip
|
|
|
|
r> r> rot + 1+
|
|
|
|
>r 1+ >r
|
|
|
|
repeat
|
|
|
|
r> drop
|
|
|
|
r>
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: concat_argv ( aN uN ... a1 u1 N -- a u )
|
2009-01-05 20:09:54 +00:00
|
|
|
strlen(argv) allocate if ENOMEM throw then
|
|
|
|
0 2>r ( save addr 0 on return stack )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
|
|
|
|
begin
|
2009-01-05 20:09:54 +00:00
|
|
|
dup
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
while
|
2009-01-05 20:09:54 +00:00
|
|
|
unqueue_argv ( ... N a1 u1 )
|
|
|
|
2r> 2swap ( old a1 u1 )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
strcat
|
2009-01-05 20:09:54 +00:00
|
|
|
s" " strcat ( append one space ) \ XXX this gives a trailing space
|
|
|
|
2>r ( store string on the result stack )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
repeat
|
2000-09-16 21:04:49 +00:00
|
|
|
drop_args
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
2r>
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: set_tempoptions ( addrN lenN ... addr1 len1 N -- addr len 1 | 0 )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
\ Save the first argument, if it exists and is not a flag
|
|
|
|
argc if
|
|
|
|
0 argv[] drop c@ [char] - <> if
|
2000-09-16 21:04:49 +00:00
|
|
|
unqueue_argv 2>r \ Filename
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
1 >r \ Filename present
|
|
|
|
else
|
|
|
|
0 >r \ Filename not present
|
|
|
|
then
|
|
|
|
else
|
|
|
|
0 >r \ Filename not present
|
|
|
|
then
|
|
|
|
|
|
|
|
\ If there are other arguments, assume they are flags
|
|
|
|
?dup if
|
2000-09-16 21:04:49 +00:00
|
|
|
concat_argv
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
2dup s" temp_options" setenv
|
2009-01-05 20:09:54 +00:00
|
|
|
drop free if EFREE throw then
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
else
|
2000-09-16 21:04:49 +00:00
|
|
|
set_defaultoptions
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
then
|
|
|
|
|
|
|
|
\ Bring back the filename, if one was provided
|
|
|
|
r> if 2r> 1 else 0 then
|
|
|
|
;
|
|
|
|
|
2000-09-16 21:04:49 +00:00
|
|
|
: get_arguments ( -- addrN lenN ... addr1 len1 N )
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
0
|
|
|
|
begin
|
|
|
|
\ Get next word on the command line
|
|
|
|
parse-word
|
|
|
|
?dup while
|
2000-09-16 21:04:49 +00:00
|
|
|
queue_argv
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
repeat
|
|
|
|
drop ( empty string )
|
|
|
|
;
|
|
|
|
|
2000-09-16 20:20:44 +00:00
|
|
|
: load_kernel_and_modules ( args -- flag )
|
2000-09-16 21:04:49 +00:00
|
|
|
set_tempoptions
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
argc >r
|
|
|
|
s" temp_options" getenv dup -1 <> if
|
2000-09-16 21:04:49 +00:00
|
|
|
queue_argv
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
else
|
|
|
|
drop
|
|
|
|
then
|
loader: implement multiboot support for Xen Dom0
Implement a subset of the multiboot specification in order to boot Xen
and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot
implementation is tailored to boot Xen and FreeBSD Dom0, and it will
most surely fail to boot any other multiboot compilant kernel.
In order to detect and boot the Xen microkernel, two new file formats
are added to the bootloader, multiboot and multiboot_obj. Multiboot
support must be tested before regular ELF support, since Xen is a
multiboot kernel that also uses ELF. After a multiboot kernel is
detected, all the other loaded kernels/modules are parsed by the
multiboot_obj format.
The layout of the loaded objects in memory is the following; first the
Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to
long mode by itself), after that the FreeBSD kernel is loaded as a RAW
file (Xen will parse and load it using it's internal ELF loader), and
finally the metadata and the modules are loaded using the native
FreeBSD way. After everything is loaded we jump into Xen's entry point
using a small trampoline. The order of the multiboot modules passed to
Xen is the following, the first module is the RAW FreeBSD kernel, and
the second module is the metadata and the FreeBSD modules.
Since Xen will relocate the memory position of the second
multiboot module (the one that contains the metadata and native
FreeBSD modules), we need to stash the original modulep address inside
of the metadata itself in order to recalculate its position once
booted. This also means the metadata must come before the loaded
modules, so after loading the FreeBSD kernel a portion of memory is
reserved in order to place the metadata before booting.
In order to tell the loader to boot Xen and then the FreeBSD kernel the
following has to be added to the /boot/loader.conf file:
xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga"
xen_kernel="/boot/xen"
The first argument contains the command line that will be passed to the Xen
kernel, while the second argument is the path to the Xen kernel itself. This
can also be done manually from the loader command line, by for example
typing the following set of commands:
OK unload
OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga
OK load kernel
OK load zfs
OK load if_tap
OK load ...
OK boot
Sponsored by: Citrix Systems R&D
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D517
For the Forth bits:
Submitted by: Julien Grall <julien.grall AT citrix.com>
2015-01-15 16:27:20 +00:00
|
|
|
load_xen
|
|
|
|
?dup 0= if ( success )
|
|
|
|
r> if ( a path was passed )
|
|
|
|
load_directory_or_file
|
|
|
|
else
|
|
|
|
standard_kernel_search
|
|
|
|
then
|
|
|
|
?dup 0= if ['] load_modules catch then
|
Factorize, reorganize, and move code around.
The boot-conf and boot code had various bugs, and some of it was big,
ugly, unwieldy, and, sometimes, plain incorrect. I'm just about
completely replaced these ugly parts with something much more manageable.
Minor changes were made to the well-factorized parts of it, to accomodate
the new code.
Of note:
* make sure boot-conf has the exact same behavior wrt boot order
as start.
* Correct both boot and boot-conf so they'll work correctly when
compiled in, as they both had some bugs, minor and major.
* Remove all the crud from loader.4th back into support.4th, for
the first time since boot-conf was first improved. Hurray!
I'm fairly satisfied with the code at this time. Time to see about those
man pages...
2000-09-15 08:05:52 +00:00
|
|
|
then
|
|
|
|
;
|
|
|
|
|
2015-04-01 01:54:28 +00:00
|
|
|
only forth definitions
|