From 3fa988b3957e914ad876116d4dd6531bf41d5743 Mon Sep 17 00:00:00 2001 From: dcs Date: Sat, 9 Sep 2000 04:52:34 +0000 Subject: 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.) --- sys/boot/forth/loader.4th | 126 ++++++---------------------------------------- 1 file changed, 14 insertions(+), 112 deletions(-) (limited to 'sys/boot/forth/loader.4th') diff --git a/sys/boot/forth/loader.4th b/sys/boot/forth/loader.4th index ef956e8..7a4dbcd 100644 --- a/sys/boot/forth/loader.4th +++ b/sys/boot/forth/loader.4th @@ -58,32 +58,6 @@ only forth definitions also support-functions also support-functions definitions -: bootpath s" /boot/" ; -: modulepath s" module_path" ; - -: saveenv ( addr len | 0 -1 -- addr' len | 0 -1 ) - dup -1 = if exit then - dup allocate abort" Out of memory" - swap 2dup 2>r - move - 2r> -; - -: 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 -; - : set-tempoptions ( addrN lenN ... addr1 len1 N -- addr len 1 | 0 ) \ No options, set the default ones dup 0= if @@ -166,105 +140,33 @@ also support-functions definitions also builtins -: load-kernel ( addr len -- addr len error? ) - s" temp_options" getenv dup -1 = if - drop 2dup 1 - else - 2over 2 - then - - 1 load -; - : load-conf ( args 1 | 0 "args" -- flag ) - 0 1 unload drop - 0= if ( interpreted ) get-arguments then set-tempoptions - - if ( there are arguments ) - load-kernel if ( load command failed ) - \ Set the environment variable module_path, and try loading - \ the kernel again. - - \ First, save module_path value - modulepath getenv saveenv dup -1 = if 0 swap then 2>r - - \ Sets the new value - 2dup modulepath setenv - - \ Try to load the kernel - s" load ${kernel} ${temp_options}" ['] evaluate catch - if ( load failed yet again ) - \ Remove garbage from the stack - 2drop - - \ Try prepending /boot/ - bootpath 2over nip over + allocate - if ( out of memory ) - 2drop 2drop - 2r> restoreenv - 100 exit - then - - 0 2swap strcat 2swap strcat - 2dup modulepath setenv - - drop free if ( freeing memory error ) - 2drop - 2r> restoreenv - 100 exit - then - - \ Now, once more, try to load the kernel - s" load ${kernel} ${temp_options}" ['] evaluate catch - if ( failed once more ) - 2drop - 2r> restoreenv - 100 exit - then - - else ( we found the kernel on the path passed ) - - 2drop ( discard command line arguments ) - - then ( could not load kernel from directory passed ) - - \ Load the remaining modules, if the kernel was loaded at all - ['] load_modules catch if 2r> restoreenv 100 exit then - - \ Return 0 to indicate success - 0 - - \ Keep new module_path - 2r> freeenv - - exit - then ( could not load kernel with name passed ) - - 2drop ( discard command line arguments ) - - else ( try just a straight-forward kernel load ) - s" load ${kernel} ${temp_options}" ['] evaluate catch - if ( kernel load failed ) 2drop 100 exit then - - then ( there are command line arguments ) - - \ Load the remaining modules, if the kernel was loaded at all - ['] load_modules catch if 100 exit then - - \ Return 0 to indicate success - 0 + s" temp_options" getenv -1 <> if 2swap 2 else 1 then + load_kernel_and_modules ; only forth also support-functions also builtins definitions : boot + \ Unload only if a path was passed + >in @ parse-word rot >in ! + if + c@ [char] - <> if + 0 1 unload drop + else + get-arguments 1 boot exit + then + else + 0 1 boot exit + then load-conf ?dup 0= if 0 1 boot then ; : boot-conf + 0 1 unload drop load-conf ?dup 0= if 0 1 autoboot then ; -- cgit v1.1