bootstrap.h

help.common
interp.c
	Rename the 'source' command to 'include' in order to avoid conflict
	with the ANS Forth command of the same name. (kern/9473)

interp_forth.c:
	Changes from kern/9412 (EXCEPTION word), kern/9442 (TIB buffer
	sizing) and an improved version of kern/9460 (set
	version numbers).

load_aout.c:
	Trim some obsolete #if 0'ed cruft.

pnp.c:
	Tidy the pnpscan output, turn off the module scanning until we
	sort out how to do it right.

PR:		kern/9412 kern/9442 kern/9460 kern/9473
Submitted by:	PRs from Daniel Sobral <dcs@newsguy.com>
This commit is contained in:
Mike Smith 1999-01-22 23:50:14 +00:00
parent b7b98418bd
commit b7fd9e91ed
6 changed files with 87 additions and 141 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bootstrap.h,v 1.17 1999/01/15 00:31:45 abial Exp $
* $Id: bootstrap.h,v 1.18 1999/01/16 03:25:24 jdp Exp $
*/
#include <sys/types.h>
@ -56,7 +56,7 @@ extern char command_errbuf[]; /* XXX blah, length */
/* interp.c */
extern void interact(void);
extern int source(char *filename);
extern int include(char *filename);
/* interp_parse.c */
extern int parse(int *argc, char ***argv, char *str);

View File

@ -231,9 +231,9 @@
See the set command for a list of some variables.
################################################################################
# Tsource DRead commands from a script file
# Tinclude DRead commands from a script file
source <filename>
include <filename>
The entire contents of <filename> are read into memory before executing
commands, so it is safe to source a file from removable media.
@ -241,6 +241,8 @@
A number of modifiers may be prefixed to commands within a script file
to alter their behaviour:
# Ignore the line (use for comments).
@ Suppresses the printing of the command when executed.
- Prevents the script from terminating if the command returns

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: interp.c,v 1.11 1999/01/13 21:59:58 abial Exp $
* $Id: interp.c,v 1.12 1999/01/15 00:31:45 abial Exp $
*/
/*
* Simple commandline interpreter, toplevel and misc.
@ -99,8 +99,8 @@ interact(void)
/*
* Read our default configuration
*/
if(source("/boot/loader.rc")!=CMD_OK)
source("/boot/boot.conf");
if(include("/boot/loader.rc")!=CMD_OK)
include("/boot/boot.conf");
printf("\n");
/*
* Before interacting, we might want to autoboot.
@ -141,34 +141,34 @@ interact(void)
* Commands may be prefixed with '@' (so they aren't displayed) or '-' (so
* that the script won't stop if they fail).
*/
COMMAND_SET(source, "source", "read commands from a file", command_source);
COMMAND_SET(include, "include", "read commands from a file", command_include);
static int
command_source(int argc, char *argv[])
command_include(int argc, char *argv[])
{
int i;
int res;
res=CMD_OK;
for (i = 1; (i < argc) && (res == CMD_OK); i++)
res=source(argv[i]);
res = include(argv[i]);
return(res);
}
struct sourceline
struct includeline
{
char *text;
int flags;
int line;
#define SL_QUIET (1<<0)
#define SL_IGNOREERR (1<<1)
struct sourceline *next;
struct includeline *next;
};
int
source(char *filename)
include(char *filename)
{
struct sourceline *script, *se, *sp;
struct includeline *script, *se, *sp;
char input[256]; /* big enough? */
int argc,res;
char **argv, *cp;
@ -203,8 +203,8 @@ source(char *filename)
flags |= SL_IGNOREERR;
}
/* Allocate script line structure and copy line, flags */
sp = malloc(sizeof(struct sourceline) + strlen(cp) + 1);
sp->text = (char *)sp + sizeof(struct sourceline);
sp = malloc(sizeof(struct includeline) + strlen(cp) + 1);
sp->text = (char *)sp + sizeof(struct includeline);
strcpy(sp->text, cp);
sp->flags = flags;
sp->line = line;

View File

@ -23,14 +23,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: interp_forth.c,v 1.8 1998/12/22 11:41:51 abial Exp $
* $Id: interp_forth.c,v 1.9 1999/01/04 18:39:24 peter Exp $
*/
#include <sys/param.h> /* to pick up __FreeBSD_version */
#include <string.h>
#include <stand.h>
#include "bootstrap.h"
#include "ficl.h"
extern char bootprog_rev[];
/* #define BFORTH_DEBUG */
#ifdef BFORTH_DEBUG
@ -39,6 +42,13 @@
# define DEBUG(fmt, args...)
#endif
/*
* Eventually, all builtin commands throw codes must be defined
* elsewhere, possibly bootstrap.h. For now, just this code, used
* just in this file, it is getting defined.
*/
#define BF_PARSE 100
/*
* BootForth Interface to Ficl Forth interpreter.
*/
@ -73,7 +83,7 @@ bf_command(FICL_VM *vm)
/* Get remainder of invocation */
tail = vmGetInBuf(vm);
for (cp = tail, len = 0; *cp != 0 && *cp != '\n'; cp++, len++)
for (cp = tail, len = 0; cp != vm->tib.end && *cp != 0 && *cp != '\n'; cp++, len++)
;
line = malloc(strlen(name) + len + 2);
@ -90,17 +100,22 @@ bf_command(FICL_VM *vm)
if (!parse(&argc, &argv, line)) {
result = (cmd)(argc, argv);
free(argv);
/* ** Let's deal with it elsewhere **
if(result != 0) {
vmTextOut(vm,argv[0],0);
vmTextOut(vm,": ",0);
vmTextOut(vm,command_errmsg,1);
}
*/
} else {
/* ** Let's deal with it elsewhere **
vmTextOut(vm, "parse error\n", 1);
result=1;
*/
result=BF_PARSE;
}
free(line);
stackPushINT32(vm->pStack,!result);
/* This is going to be thrown!!! */
stackPushINT32(vm->pStack,result);
}
/*
@ -110,14 +125,26 @@ void
bf_init(void)
{
struct bootblk_command **cmdp;
char create_buf[41]; /* 31 characters-long builtins */
int fd;
ficlInitSystem(4000); /* Default dictionary ~4000 cells */
bf_vm = ficlNewVM();
/* Builtin word "creator" */
ficlExec(bf_vm, ": builtin: >in @ ' swap >in ! create , does> @ execute throw ;", -1);
/* make all commands appear as Forth words */
SET_FOREACH(cmdp, Xcommand_set)
SET_FOREACH(cmdp, Xcommand_set) {
ficlBuild((*cmdp)->c_name, bf_command, FW_DEFAULT);
sprintf(create_buf, "builtin: %s", (*cmdp)->c_name);
ficlExec(bf_vm, create_buf, -1);
}
/* Export some version numbers so that code can detect the loader/host version */
ficlSetEnv("FreeBSD_version", __FreeBSD_version);
ficlSetEnv("loader_version",
(bootprog_rev[0] - '0') * 10 + (bootprog_rev[2] - '0'));
/* try to load and run init file if present */
if ((fd = open("/boot/boot.4th", O_RDONLY)) != -1) {
@ -134,9 +161,29 @@ bf_run(char *line)
{
int result;
result = ficlExec(bf_vm, line);
result = ficlExec(bf_vm, line, -1);
DEBUG("ficlExec '%s' = %d", line, result);
switch (result) {
case VM_OUTOFTEXT:
case VM_ABORTQ:
case VM_QUIT:
case VM_ERREXIT:
break;
case VM_USEREXIT:
printf("No where to leave to!\n");
break;
case VM_ABORT:
printf("Aborted!\n");
break;
case BF_PARSE:
printf("Parse error!\n");
break;
default:
/* Hopefully, all other codes filled this buffer */
printf("%s\n", command_errmsg);
}
if (result == VM_USEREXIT)
panic("interpreter exit");
setenv("interpret", bf_vm->state ? "" : "ok", 1);
}

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: load_aout.c,v 1.11 1998/12/22 11:41:51 abial Exp $
* $Id: load_aout.c,v 1.12 1999/01/22 21:33:52 rnordier Exp $
*/
#include <sys/param.h>
@ -254,105 +254,3 @@ aout_loadimage(struct loaded_module *mp, int fd, vm_offset_t loadaddr, struct ex
}
#if 0
#define AOUT_RELOC(mp, off) ((mp)->m_addr + (vm_offset_t)(off))
/*
* The goal here is to find the one symbol in the loaded object
* which fits the format "kld_identifier_<something>. If there's
* more than one, we fail.
*/
static vm_offset_t
aout_findkldident(struct loaded_module *mp, struct exec *ehdr)
{
/* XXX much of this can go when we can address the load area directly */
vm_offset_t sp, ep, cand, stringbase, result;
struct _dynamic dynamic;
struct section_dispatch_table sdt;
struct nzlist nzl;
char *np;
int match;
/* Get the _DYNAMIC object, which we assume is first in the data segment */
archsw.arch_copyout(AOUT_RELOC(mp, ehdr->a_text), &dynamic, sizeof(dynamic));
archsw.arch_copyout(AOUT_RELOC(mp, dynamic.d_un.d_sdt), &sdt, sizeof(struct section_dispatch_table));
dynamic.d_un.d_sdt = &sdt; /* fix up SDT pointer */
if (dynamic.d_version != LD_VERSION_BSD)
return(0);
stringbase = AOUT_RELOC(mp, LD_STRINGS(&dynamic));
/* start pointer */
sp = AOUT_RELOC(mp, LD_SYMBOL(&dynamic));
/* end pointer */
ep = sp + LD_STABSZ(&dynamic);
/*
* Walk the entire table comparing names.
*/
match = 0;
result = 0;
for (cand = sp; cand < ep; cand += sizeof(struct nzlist)) {
/* get the entry, check for a name */
archsw.arch_copyout(cand, &nzl, sizeof(struct nzlist));
/* is this symbol worth looking at? */
if ((nzl.nz_strx == 0) || /* no name */
(nzl.nz_value == 0) || /* not a definition */
((nzl.nz_type == N_UNDF+N_EXT) &&
(nzl.nz_value != 0) &&
(nzl.nz_other == AUX_FUNC))) /* weak function */
continue;
np = strdupout(stringbase + nzl.nz_strx);
match = (np[0] == '_') && !strncmp(KLD_IDENT_SYMNAME, np + 1, strlen(KLD_IDENT_SYMNAME));
free(np);
if (match) {
/* duplicates? */
if (result)
return(0);
result = AOUT_RELOC(mp, nzl.nz_value);
}
}
return(result);
}
/*
* Perform extra housekeeping associated with loading a KLD module.
*
* XXX if this returns an error, it seems the heap becomes corrupted.
*/
static int
aout_fixupkldmod(struct loaded_module *mp, struct exec *ehdr)
{
struct kld_module_identifier kident;
struct kld_module_dependancy *kdeps;
vm_offset_t vp;
size_t dsize;
/* Find the KLD identifier */
if ((vp = aout_findkldident(mp, ehdr)) == 0) {
printf("bad a.out module format\n");
return(EFTYPE);
}
archsw.arch_copyout(vp, &kident, sizeof(struct kld_module_identifier));
/* Name the module using the name from the KLD data */
if (mod_findmodule(kident.ki_name, NULL) != NULL) {
printf("module '%s' already loaded\n", kident.ki_name);
return(EPERM);
}
mp->m_name = strdup(kident.ki_name);
/* Save the module identifier */
mod_addmetadata(mp, MODINFOMD_KLDIDENT, sizeof(struct kld_module_identifier), &kident);
/* Look for dependancy data, add to metadata list */
if (kident.ki_ndeps > 0) {
dsize = kident.ki_ndeps * kident.ki_depsize;
kdeps = malloc(dsize);
archsw.arch_copyout(AOUT_RELOC(mp, kident.ki_deps), kdeps, dsize);
mod_addmetadata(mp, MODINFOMD_KLDDEP, dsize, kdeps);
free(kdeps);
}
return(0);
}
#endif

View File

@ -21,12 +21,12 @@ static int pnp_readconf(char *path);
static int pnp_scankernel(void);
/*
* Perform complete enumeration sweep, and load required module(s) if possible.
* Perform complete enumeration sweep
*/
COMMAND_SET(pnpscan, "pnpscan", "scan for PnP devices", pnp_scan);
int
static int
pnp_scan(int argc, char *argv[])
{
struct pnpinfo *pi;
@ -57,19 +57,15 @@ pnp_scan(int argc, char *argv[])
/* forget anything we think we knew */
pnp_discard();
if (verbose)
pager_open();
/* iterate over all of the handlers */
for (hdlr = 0; pnphandlers[hdlr] != NULL; hdlr++) {
if (verbose) {
pager_output("Probing ");
pager_output(pnphandlers[hdlr]->pp_name);
pager_output("...\n");
}
if (verbose)
printf("Probing %s...\n", pnphandlers[hdlr]->pp_name);
pnphandlers[hdlr]->pp_enumerate();
}
if (verbose) {
pager_open();
pager_output("PNP scan summary:\n");
for (pi = pnp_devices.stqh_first; pi != NULL; pi = pi->pi_link.stqe_next) {
pager_output(pi->pi_ident.stqh_first->id_ident); /* first ident should be canonical */
if (pi->pi_desc != NULL) {
@ -83,11 +79,14 @@ pnp_scan(int argc, char *argv[])
return(CMD_OK);
}
#if 0
/*
* Try to load outstanding modules (eg. after disk change)
*/
int
pnp_reload(char *fname)
COMMAND_SET(pnpload, "pnpload", "load modules for PnP devices", pnp_load);
static int
pnp_load(int argc, char *argv[])
{
struct pnpinfo *pi;
char *modfname;
@ -125,9 +124,9 @@ pnp_reload(char *fname)
}
return(CMD_OK);
}
#endif
/*
* Throw away anything we think we know about PnP devices on (list)
* Throw away anything we think we know about PnP devices.
*/
static void
pnp_discard(void)
@ -140,7 +139,7 @@ pnp_discard(void)
pnp_freeinfo(pi);
}
}
#if 0
/*
* The PnP configuration database consists of a flat text file with
* entries one per line. Valid lines are:
@ -292,7 +291,7 @@ pnp_scankernel(void)
{
return(CMD_OK);
}
#endif
/*
* Add a unique identifier to (pi)
*/