This patch introduces a number of simplifications to the Forth

functions used in the bootloader. The goal is to make the code more
readable and smaller (especially because we have size issues
in the loader's environment).

High level description of the changes:
+ define some string manipulation functions to improve readability;
+ create functions to manipulate module descriptors, removing some
  duplicated code;
+ rename the error codes to ESOMETHING;
+ consistently use set_environment_variable (which evaluates
  $variables) when interpreting variable=value assignments;

I have tested the code, but there might be code paths that I have
not traversed so please let me know of any issues.

Details of this change:

--- loader.4th ---
+ add some module operators, to remove duplicated code while parsing
  module-related commands:

        set-module-flag
        enable-module
        disable-module
        toggle-module
        show-module

--- pnp.4th ---
+ move here the definition related to the pnp devices list, e.g.
  STAILQ_* , pnpident, pnpinfo

--- support.4th ---
+ rename error codes to capital e.g. ENOMEM EFREE ... and do obvious
  changes related to the renaming;
+ remove unused structures (those relevant to pnp are moved to pnp.4th)
+ various string functions
  - strlen removed (it is an internal function)
  - strchr, defined as the C function
  - strtype -- type a string to output
  - strref -- assign a reference to the string on the stack
  - unquote -- remove quotes from a string

+ remove reset_line_buffer

+ move up the 'set_environment_variable' function (which now
  uses the interpreter, so $variables are evaluated).
  Use the function in various places

+ add a 'test_file function' for debugging purposes

MFC after:	4 weeks
This commit is contained in:
Luigi Rizzo 2009-01-05 20:09:54 +00:00
parent 6dccc756ea
commit 065188a630
3 changed files with 313 additions and 509 deletions

View File

@ -93,6 +93,7 @@ only forth definitions also support-functions
\
\ If a password was defined, execute autoboot and ask for
\ password if autoboot returns.
\ Do not exit unless the right password is given.
: check-password
password .addr @ if
@ -150,8 +151,7 @@ only forth definitions also support-functions
\ line, if interpreted, or given on the stack, if compiled in.
: (read-conf) ( addr len -- )
conf_files .addr @ ?dup if free abort" Fatal error freeing memory" then
strdup conf_files .len ! conf_files .addr !
conf_files string=
include_conf_files \ Will recurse on new loader_conf_files definitions
;
@ -165,110 +165,26 @@ only forth definitions also support-functions
then
; immediate
\ ***** enable-module
\
\ Turn a module loading on.
\ show, enable, disable, toggle module loading. They all take module from
\ the next word
: enable-module ( <module> -- )
bl parse module_options @ >r
begin
r@
while
2dup
r@ module.name dup .addr @ swap .len @
compare 0= if
2drop
r@ module.name dup .addr @ swap .len @ type
true r> module.flag !
." will be loaded." cr
exit
then
r> module.next @ >r
repeat
r> drop
type ." wasn't found." cr
: set-module-flag ( module_addr val -- ) \ set and print flag
over module.flag !
dup module.name strtype
module.flag @ if ." will be loaded" else ." will not be loaded" then cr
;
\ ***** disable-module
\
\ Turn a module loading off.
: enable-module find-module ?dup if true set-module-flag then ;
: disable-module ( <module> -- )
bl parse module_options @ >r
begin
r@
while
2dup
r@ module.name dup .addr @ swap .len @
compare 0= if
2drop
r@ module.name dup .addr @ swap .len @ type
false r> module.flag !
." will not be loaded." cr
exit
then
r> module.next @ >r
repeat
r> drop
type ." wasn't found." cr
;
: disable-module find-module ?dup if false set-module-flag then ;
\ ***** toggle-module
\
\ Turn a module loading on/off.
: toggle-module ( <module> -- )
bl parse module_options @ >r
begin
r@
while
2dup
r@ module.name dup .addr @ swap .len @
compare 0= if
2drop
r@ module.name dup .addr @ swap .len @ type
r@ module.flag @ 0= dup r> module.flag !
if
." will be loaded." cr
else
." will not be loaded." cr
then
exit
then
r> module.next @ >r
repeat
r> drop
type ." wasn't found." cr
;
: toggle-module find-module ?dup if dup module.flag @ 0= set-module-flag then ;
\ ***** show-module
\
\ Show loading information about a module.
: show-module ( <module> -- )
bl parse module_options @ >r
begin
r@
while
2dup
r@ module.name dup .addr @ swap .len @
compare 0= if
2drop
." Name: " r@ module.name dup .addr @ swap .len @ type cr
." Path: " r@ module.loadname dup .addr @ swap .len @ type cr
." Type: " r@ module.type dup .addr @ swap .len @ type cr
." Flags: " r@ module.args dup .addr @ swap .len @ type cr
." Before load: " r@ module.beforeload dup .addr @ swap .len @ type cr
." After load: " r@ module.afterload dup .addr @ swap .len @ type cr
." Error: " r@ module.loaderror dup .addr @ swap .len @ type cr
." Status: " r> module.flag @ if ." Load" else ." Don't load" then cr
exit
then
r> module.next @ >r
repeat
r> drop
type ." wasn't found." cr
;
: show-module ( <module> -- ) find-module ?dup if show-one-module then ;
\ Words to be used inside configuration files

View File

@ -24,6 +24,39 @@
\
\ $FreeBSD$
\ The following pnp code is used in pnp.4th and pnp.c
structure: STAILQ_HEAD
ptr stqh_first \ type*
ptr stqh_last \ type**
;structure
structure: STAILQ_ENTRY
ptr stqe_next \ type*
;structure
structure: pnphandler
ptr pnph.name
ptr pnph.enumerate
;structure
structure: pnpident
ptr pnpid.ident \ char*
sizeof STAILQ_ENTRY cells member: pnpid.link \ pnpident
;structure
structure: pnpinfo \ sync with sys/boot/config/bootstrap.h
ptr pnpi.desc
int pnpi.revision
ptr pnpi.module \ (char*) module args
int pnpi.argc
ptr pnpi.argv
ptr pnpi.handler \ pnphandler
sizeof STAILQ_HEAD member: pnpi.ident \ pnpident
sizeof STAILQ_ENTRY member: pnpi.link \ pnpinfo
;structure
\ end of pnp support
pnpdevices drop
: enumerate

File diff suppressed because it is too large Load Diff