1 /* $NetBSD: test.c,v 1.3 2002/06/08 16:51:38 yamt Exp $ */
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <lib/libsa/stand.h>
34 #include <lib/libkern/libkern.h>
35 #include <machine/autoconf.h>
36 #include <machine/rpb.h>
38 #include "../common/common.h"
42 void (*fn
)(const char *buf
);
46 unsigned long arg_pfn
, arg_ptb
, arg_bim
, arg_bip
, arg_biv
;
48 const char *advance_past_space(const char *buf
);
49 const char *cvt_number(const char *buf
, u_int64_t
*nump
);
50 int dispatch_cmd(const char *buf
, const struct cmdtab
*cmds
);
51 #define DISPATCH_CMD_NOCMD 0
52 #define DISPATCH_CMD_MATCHED 1
53 #define DISPATCH_CMD_NOMATCH 2
54 #define DISPATCH_CMD_AMBIGUOUS 3
55 void print_cmds(const struct cmdtab
*cmds
, const char *match
,
57 void print_stringarray(const char *s
, size_t maxlen
);
59 void toplevel_dpb(const char *buf
);
60 void toplevel_dpl(const char *buf
);
61 void toplevel_dpq(const char *buf
);
62 void toplevel_dpw(const char *buf
);
63 void toplevel_dvb(const char *buf
);
64 void toplevel_dvl(const char *buf
);
65 void toplevel_dvq(const char *buf
);
66 void toplevel_dvw(const char *buf
);
67 void toplevel_halt(const char *buf
);
68 void toplevel_help(const char *buf
);
69 void toplevel_show(const char *buf
);
71 void show_args(const char *buf
);
72 void show_bootinfo(const char *buf
);
73 void show_pt(const char *buf
);
74 void show_rpb(const char *buf
);
77 main(unsigned long pfn
, unsigned long ptb
, unsigned long bim
, unsigned long bip
, unsigned long biv
)
78 /* pfn: first free PFN number */
79 /* ptb: PFN of current level 1 page table */
80 /* bim: bootinfo magic */
81 /* bip: bootinfo pointer */
82 /* biv: bootinfo version */
85 static const struct cmdtab toplevel_cmds
[] = {
86 { "?", toplevel_help
, },
87 #if 0 /* XXX notyet */
88 { "dpb", toplevel_dpb
, },
89 { "dpl", toplevel_dpl
, },
90 { "dpq", toplevel_dpq
, },
91 { "dpw", toplevel_dpw
, },
92 { "dvb", toplevel_dvb
, },
93 { "dvl", toplevel_dvl
, },
94 { "dvq", toplevel_dvq
, },
95 { "dvw", toplevel_dvw
, },
97 { "quit", toplevel_halt
, },
98 { "show", toplevel_show
, },
103 printf("NetBSD/alpha " NETBSD_VERS
104 " Standalone Test Program, Revision %s\n", bootprog_rev
);
105 printf("(%s, %s)\n", bootprog_maker
, bootprog_date
);
114 printf("Enter '?' for help.\n");
121 dispatch_cmd(input_buf
, toplevel_cmds
);
125 printf("halting...\n");
130 advance_past_space(const char *buf
)
133 /* advance past white space. */
134 while (isspace(*buf
))
143 cvt_number(const char *buf
, u_int64_t
*nump
)
155 if (c
== 'x' || c
== 'X') {
163 for (c
= *buf
; c
!= '\0' && !isspace(c
); c
= *(++buf
)) {
166 if (c
< '0' || c
> '9')
175 dispatch_cmd(const char *buf
, const struct cmdtab
*cmds
)
177 const struct cmdtab
*try, *winner
;
178 size_t nonwhitespace
, i
;
179 unsigned int nmatches
;
180 const char *pre
, *post
;
183 /* advance past white space. */
184 buf
= advance_past_space(buf
);
186 return (DISPATCH_CMD_NOCMD
);
188 /* find how much non-white space there is. */
190 while ((buf
[nonwhitespace
] != '\0') && !isspace(buf
[nonwhitespace
]))
193 /* at this point, nonwhitespace should always be non-zero */
194 if (nonwhitespace
== 0) {
195 printf("assertion failed: dispatch_cmd: nonwhitespace == 0\n");
199 /* see how many matches there were. */
200 for (nmatches
= 0, try = cmds
;
201 try != NULL
&& try->cmd
!= NULL
;
203 if (strncmp(buf
, try->cmd
, nonwhitespace
) == 0) {
210 (*winner
->fn
)(buf
+ nonwhitespace
);
211 return (DISPATCH_CMD_MATCHED
);
212 } else if (nmatches
== 0) {
213 pre
= "invalid command word";
214 post
= "allowed words";
215 rv
= DISPATCH_CMD_NOMATCH
;
217 pre
= "ambiguous command word";
219 rv
= DISPATCH_CMD_AMBIGUOUS
;
222 printf("%s \"", pre
);
223 print_stringarray(buf
, nonwhitespace
);
224 printf("\", %s:\n", post
);
226 /* print commands. if no match, print all commands. */
227 print_cmds(cmds
, buf
, rv
== DISPATCH_CMD_NOMATCH
? 0 : nonwhitespace
);
232 print_cmds(const struct cmdtab
*cmds
, const char *match
, size_t matchlen
)
234 const struct cmdtab
*try;
237 for (try = cmds
; try != NULL
&& try->cmd
!= NULL
; try++) {
238 if (strncmp(match
, try->cmd
, matchlen
) == 0)
239 printf("%s%s", try != cmds
? ", " : "", try->cmd
);
245 print_stringarray(const char *s
, size_t maxlen
)
249 for (i
= 0; (i
< maxlen
) && (*s
!= '\0'); i
++, s
++)
254 warn_ignored_args(const char *buf
, const char *cmd
)
257 if (advance_past_space(buf
) != NULL
)
258 printf("WARNING: extra arguments to \"%s\" command ignored\n",
268 toplevel_dpb(const char *buf
)
270 u_int64_t startaddr
, count
= 1;
272 buf
= advance_past_space(buf
);
274 printf("\"dpb\" must be given starting address\n");
277 buf
= cvt_number(buf
, &startaddr
);
278 if (*buf
!= '\0' && !isspace(*buf
)) {
279 printf("bad character '%c' in starting address\n");
283 buf
= advance_past_space(buf
);
285 buf
= cvt_number(buf
, &count
);
286 if (*buf
!= '\0' && !isspace(*buf
)) {
287 printf("bad character '%c' in count\n");
290 buf
= advance_past_space(buf
);
292 printf("extra args at end of \"dpb\" command\n");
297 printf("startaddr = 0x%lx, count = 0x%lx\n", startaddr
, count
);
298 printf("\"dpb\" not yet implemented\n");
302 toplevel_dpl(const char *buf
)
305 printf("\"dpl\" not yet implemented\n");
309 toplevel_dpq(const char *buf
)
312 printf("\"dpq\" not yet implemented\n");
316 toplevel_dpw(const char *buf
)
319 printf("\"dpw\" not yet implemented\n");
323 toplevel_dvb(const char *buf
)
326 printf("\"dvb\" not yet implemented\n");
330 toplevel_dvl(const char *buf
)
333 printf("\"dvl\" not yet implemented\n");
337 toplevel_dvq(const char *buf
)
340 printf("\"dvq\" not yet implemented\n");
344 toplevel_dvw(const char *buf
)
347 printf("\"dvw\" not yet implemented\n");
351 toplevel_halt(const char *buf
)
354 warn_ignored_args(buf
, "halt");
360 toplevel_help(const char *buf
)
363 warn_ignored_args(buf
, "?");
365 printf("Standalone Test Program Commands:\n");
366 printf(" ? print help\n");
367 printf(" quit return to console\n");
368 #if 0 /* XXX notyet */
369 printf(" dpb startaddr [count] display physical memory "
371 printf(" dpw startaddr [count] display physical memory "
373 printf(" dpl startaddr [count] display physical memory "
375 printf(" dpq startaddr [count] display physical memory "
377 printf(" dvb startaddr [count] display virtual memory "
379 printf(" dvw startaddr [count] display virtual memory "
381 printf(" dvl startaddr [count] display virtual memory "
383 printf(" dvq startaddr [count] display virtual memory "
386 printf(" show args show test program arguments\n");
387 printf(" show bootinfo show bootstrap bootinfo\n");
388 #if 0 /* XXX notyet */
389 printf(" show pt [startaddr [endaddr]]\n");
390 printf(" show page tables\n");
391 printf(" show rpb show the HWRPB\n");
393 printf("If optional \"count\" argument is omitted, 1 is used.\n");
394 printf("If optional \"startaddr\" argument is omitted, "
396 printf("If optional \"endaddr\" argument is omitted, "
397 "0xffffffffffffffff is used.\n");
402 toplevel_show(const char *buf
)
404 static const struct cmdtab show_cmds
[] = {
405 { "args", show_args
, },
406 { "bootinfo", show_bootinfo
, },
407 #if 0 /* XXX notyet */
409 { "rpb", show_rpb
, },
414 if (dispatch_cmd(buf
, show_cmds
) == DISPATCH_CMD_NOCMD
) {
415 printf("no subcommand given. allowed subcommands:\n");
416 print_cmds(show_cmds
, NULL
, 0);
426 show_args(const char *buf
)
429 warn_ignored_args(buf
, "show args");
431 printf("first free page frame number: 0x%lx\n", arg_pfn
);
432 printf("page table base page frame number: 0x%lx\n", arg_ptb
);
433 printf("bootinfo magic number: 0x%lx\n", arg_bim
);
434 printf("bootinfo pointer: 0x%lx\n", arg_bip
);
435 printf("bootinfo version: 0x%lx\n", arg_biv
);
439 show_bootinfo(const char *buf
)
443 warn_ignored_args(buf
, "show bootinfo");
445 if (arg_bim
!= BOOTINFO_MAGIC
) {
446 printf("bootinfo magic number not present; no bootinfo\n");
453 biv
= *(u_long
*)bip
;
457 printf("bootinfo version: %d\n", biv
);
458 printf("bootinfo pointer: %p\n", (void *)bip
);
459 printf("bootinfo data:\n");
463 const struct bootinfo_v1
*v1p
;
466 v1p
= (const struct bootinfo_v1
*)bip
;
467 printf(" ssym: 0x%lx\n", v1p
->ssym
);
468 printf(" esym: 0x%lx\n", v1p
->esym
);
469 printf(" boot flags: \"");
470 print_stringarray(v1p
->boot_flags
, sizeof v1p
->boot_flags
);
472 printf(" booted kernel: \"", v1p
->esym
);
473 print_stringarray(v1p
->booted_kernel
,
474 sizeof v1p
->booted_kernel
);
476 printf(" hwrpb: %p\n", v1p
->hwrpb
);
477 printf(" hwrpbsize: 0x%lx\n", v1p
->hwrpbsize
);
478 printf(" cngetc: %p\n", v1p
->cngetc
);
479 printf(" cnputc: %p\n", v1p
->cnputc
);
480 printf(" cnpollc: %p\n", v1p
->cnpollc
);
481 for (i
= 0; i
< (sizeof v1p
->pad
/ sizeof v1p
->pad
[0]); i
++) {
482 printf(" pad[%d]: 0x%lx\n", i
, v1p
->pad
[i
]);
487 printf(" unknown bootinfo version, cannot print data\n");
493 show_pt(const char *buf
)
496 /* has additional args! */
497 printf("\"show pt\" not yet implemented\n");
501 show_rpb(const char *buf
)
504 warn_ignored_args(buf
, "show pt");
506 printf("\"show rpb\" not yet implemented\n");