Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha/stand/standtest start on a glorified system-e...



details:   https://anonhg.NetBSD.org/src/rev/7a9a6eefdf1e
branches:  trunk
changeset: 471772:7a9a6eefdf1e
user:      cgd <cgd%NetBSD.org@localhost>
date:      Sun Apr 11 03:38:51 1999 +0000

description:
start on a glorified system-examination console program.

diffstat:

 sys/arch/alpha/stand/standtest/Makefile |   26 ++
 sys/arch/alpha/stand/standtest/test.c   |  398 ++++++++++++++++++++++++++++++++
 sys/arch/alpha/stand/standtest/version  |    8 +
 3 files changed, 432 insertions(+), 0 deletions(-)

diffs (truncated from 444 to 300 lines):

diff -r 3376017baee6 -r 7a9a6eefdf1e sys/arch/alpha/stand/standtest/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/stand/standtest/Makefile   Sun Apr 11 03:38:51 1999 +0000
@@ -0,0 +1,26 @@
+# $NetBSD: Makefile,v 1.1 1999/04/11 03:38:51 cgd Exp $
+
+PROG=  test
+BINDIR=        /stand
+
+SRCS = start.S test.c prom.c prom_disp.S
+
+RELOC = ${STANDPROG_LOAD_ADDRESS}
+
+CPPFLAGS += ${STANDPROG_CPPFLAGS}
+
+CLEANFILES+= vers.c vers.o ${PROG}.sym
+
+# XXX HACK!
+${PROG}: ${PROG}.sym
+       rm -f ${PROG}
+       cp ${PROG}.sym ${PROG}
+
+SAMISCMAKEFLAGS= SA_INCLUDE_NET=no SA_USE_CREAD=no
+.include "../Makefile.bootprogs"
+
+${PROG}.sym: ${OBJS} ${LIBSA} ${LIBKERN}
+       sh ${.CURDIR}/../common/newvers.sh ${.CURDIR}/version
+       ${COMPILE.c} vers.c
+       ${LD} -Ttext ${RELOC} -N -e start -o ${PROG}.sym \
+           ${OBJS} vers.o ${LIBSA} ${LIBKERN}
diff -r 3376017baee6 -r 7a9a6eefdf1e sys/arch/alpha/stand/standtest/test.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/stand/standtest/test.c     Sun Apr 11 03:38:51 1999 +0000
@@ -0,0 +1,398 @@
+/* $NetBSD: test.c,v 1.1 1999/04/11 03:38:51 cgd Exp $ */
+
+/*
+ * Copyright (c) 1999 Christopher G. Demetriou.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christopher G. Demetriou
+ *     for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+#include <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+#include <machine/autoconf.h>
+#include <machine/rpb.h>
+
+#include "../common/common.h"
+
+struct cmdtab {
+       const char *cmd;
+       void (*fn)(const char *buf);
+};
+
+int            done;
+unsigned long  arg_pfn, arg_ptb, arg_bim, arg_bip, arg_biv;
+
+const char *advance_past_space(const char *buf);
+int    dispatch_cmd(const char *buf, const struct cmdtab *cmds);
+#define                DISPATCH_CMD_NOCMD      0
+#define                DISPATCH_CMD_MATCHED    1
+#define                DISPATCH_CMD_NOMATCH    2
+#define                DISPATCH_CMD_AMBIGUOUS  3
+void   print_cmds(const struct cmdtab *cmds, const char *match,
+           size_t matchlen);
+void   print_stringarray(const char *s, size_t maxlen);
+
+void   toplevel_db(const char *buf);
+void   toplevel_dl(const char *buf);
+void   toplevel_dq(const char *buf);
+void   toplevel_dw(const char *buf);
+void   toplevel_halt(const char *buf);
+void   toplevel_help(const char *buf);
+void   toplevel_show(const char *buf);
+
+void   show_args(const char *buf);
+void   show_bootinfo(const char *buf);
+void   show_pt(const char *buf);
+void   show_rpb(const char *buf);
+
+void
+main(pfn, ptb, bim, bip, biv)
+       unsigned long pfn;      /* first free PFN number */
+       unsigned long ptb;      /* PFN of current level 1 page table */
+       unsigned long bim;      /* bootinfo magic */
+       unsigned long bip;      /* bootinfo pointer */
+       unsigned long biv;      /* bootinfo version */
+{
+       char input_buf[512];
+       const struct cmdtab toplevel_cmds[] = {
+           {   "?",            toplevel_help,  },
+#if 0 /* XXX notyet */
+           {   "db",           toplevel_db,    },
+           {   "dl",           toplevel_dl,    },
+           {   "dq",           toplevel_dq,    },
+           {   "dw",           toplevel_dw,    },
+#endif
+           {   "quit",         toplevel_halt,  },
+           {   "show",         toplevel_show,  },
+           {   NULL,                           },
+       };
+
+       printf("\n");
+       printf("NetBSD/alpha " NETBSD_VERS
+           " Standalone Test Program, Revision %s\n", bootprog_rev);
+       printf("(%s, %s)\n", bootprog_maker, bootprog_date);
+       printf("\n");
+
+       arg_pfn = pfn;
+       arg_ptb = ptb;
+       arg_bim = bim;
+       arg_bip = bip;
+       arg_biv = biv;
+
+       printf("Enter '?' for help.\n");
+       printf("\n");
+
+       do {
+               printf("test> ");
+               gets(input_buf);
+
+               dispatch_cmd(input_buf, toplevel_cmds);
+       } while (!done);
+
+       printf("\n");
+       printf("halting...\n");
+       halt();
+}
+
+const char *
+advance_past_space(const char *buf)
+{
+
+       /* advance past white space. */
+       while (isspace(*buf))
+               buf++;
+
+       if (*buf == '\0')
+               return NULL;
+       return buf;
+}
+
+int
+dispatch_cmd(const char *buf, const struct cmdtab *cmds)
+{
+       const struct cmdtab *try, *winner;
+       size_t nonwhitespace, i;
+       unsigned int nmatches;
+       const char *pre, *post;
+       int rv;
+
+       /* advance past white space. */
+       buf = advance_past_space(buf);
+       if (buf == NULL)
+               return (DISPATCH_CMD_NOCMD);
+
+       /* find how much non-white space there is. */
+       nonwhitespace = 0;
+       while ((buf[nonwhitespace] != '\0') && !isspace(buf[nonwhitespace]))
+               nonwhitespace++;
+
+       /* at this point, nonwhitespace should always be non-zero */
+       if (nonwhitespace == 0) {
+               printf("assertion failed: dispatch_cmd: nonwhitespace == 0\n");
+               halt();
+       }
+
+       /* see how many matches there were. */
+       for (nmatches = 0, try = cmds;
+           try != NULL && try->cmd != NULL;
+           try++) {
+               if (strncmp(buf, try->cmd, nonwhitespace) == 0) {
+                       winner = try;
+                       nmatches++;
+               }
+       }
+
+       if (nmatches == 1) {
+               (*winner->fn)(buf + nonwhitespace);
+               return (DISPATCH_CMD_MATCHED);
+       } else if (nmatches == 0) {
+               pre = "invalid command word";
+               post = "allowed words";
+               rv = DISPATCH_CMD_NOMATCH;
+       } else {
+               pre = "ambiguous command word";
+               post = "matches";
+               rv = DISPATCH_CMD_AMBIGUOUS;
+       }
+
+       printf("%s \"", pre);
+       print_stringarray(buf, nonwhitespace);
+       printf("\", %s:\n", post);
+
+       /* print commands.  if no match, print all commands. */
+       print_cmds(cmds, buf, rv == DISPATCH_CMD_NOMATCH ? 0 : nonwhitespace);
+       return (rv);
+}
+
+void
+print_cmds(const struct cmdtab *cmds, const char *match, size_t matchlen)
+{
+       const struct cmdtab *try;
+
+       printf("    ");
+       for (try = cmds; try != NULL && try->cmd != NULL; try++) {
+               if (strncmp(match, try->cmd, matchlen) == 0)
+                       printf("%s%s", try != cmds ? ", " : "", try->cmd);
+       }
+       printf("\n");
+}
+
+void
+print_stringarray(const char *s, size_t maxlen)
+{
+       size_t i;
+
+       for (i = 0; (i < maxlen) && (*s != '\0'); i++, s++)
+               putchar(*s);
+}
+
+void
+warn_ignored_args(const char *buf, const char *cmd)
+{
+
+       if (advance_past_space(buf) != NULL)
+               printf("WARNING: extra arguments to \"%s\" command ignored\n",
+                   cmd);
+}
+
+/*
+ * Top-level Commands
+ */
+
+void
+toplevel_db(const char *buf)
+{
+
+       printf("\"db\" not yet implemented\n");
+}
+
+void
+toplevel_dl(const char *buf)
+{
+
+       printf("\"dl\" not yet implemented\n");
+}
+
+void
+toplevel_dq(const char *buf)
+{
+
+       printf("\"dq\" not yet implemented\n");
+}
+
+void
+toplevel_dw(const char *buf)
+{
+
+       printf("\"dw\" not yet implemented\n");
+}
+
+void
+toplevel_halt(const char *buf)
+{
+
+       warn_ignored_args(buf, "halt");
+
+       done = 1;
+}
+
+void
+toplevel_help(const char *buf)
+{
+
+       warn_ignored_args(buf, "?");



Home | Main Index | Thread Index | Old Index