main.c revision 39450
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 *	$Id: main.c,v 1.5 1998/09/17 23:52:15 msmith Exp $
27 */
28
29/*
30 * MD bootstrap main() and assorted miscellaneous
31 * commands.
32 */
33
34#include <stand.h>
35#include <string.h>
36
37#include "bootstrap.h"
38#include "libi386/libi386.h"
39#include "btxv86.h"
40
41struct arch_switch	archsw;		/* MI/MD interface boundary */
42
43/* from vers.c */
44extern	char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
45
46/* XXX debugging */
47extern char end[];
48
49void
50main(void)
51{
52    struct i386_devdesc	currdev;
53    int			i;
54
55    /*
56     * Initialise the heap as early as possible.  Once this is done, malloc() is usable.
57     *
58     * XXX better to locate end of memory and use that
59     */
60    setheap((void *)end, (void *)(end + (384 * 1024)));
61
62    /*
63     * XXX Chicken-and-egg problem; we want to have console output early, but some
64     * console attributes may depend on reading from eg. the boot device, which we
65     * can't do yet.
66     *
67     * We can use printf() etc. once this is done.
68     */
69    cons_probe();
70
71    /*
72     * March through the device switch probing for things.
73     */
74    for (i = 0; devsw[i] != NULL; i++)
75	if (devsw[i]->dv_init != NULL)
76	    (devsw[i]->dv_init)();
77
78    printf("\n");
79    printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
80    printf("(%s, %s)\n", bootprog_maker, bootprog_date);
81    printf("memory: %d/%dkB\n", getbasemem(), getextmem());
82#if 0
83    printf("diskbuf at %p, %d sectors\n", &diskbuf, diskbuf_size);
84    printf("using %d bytes of stack at %p\n",  (&stacktop - &stackbase), &stacktop);
85#endif
86
87    /* We're booting from a BIOS disk, try to spiff this */
88    currdev.d_dev = devsw[0];				/* XXX presumes that biosdisk is first in devsw */
89    currdev.d_type = currdev.d_dev->dv_type;
90    currdev.d_kind.biosdisk.unit = 0;			/* XXX wrong, need to get from bootinfo etc. */
91    currdev.d_kind.biosdisk.slice = -1;			/* XXX should be able to detect this, default to autoprobe */
92    currdev.d_kind.biosdisk.partition = 0;		/* default to 'a' */
93
94    /* Create i386-specific variables */
95
96    env_setenv("currdev", EV_VOLATILE, i386_fmtdev(&currdev), i386_setcurrdev, env_nounset);
97    env_setenv("loaddev", EV_VOLATILE,  i386_fmtdev(&currdev), env_noset, env_nounset);
98    setenv("LINES", "24", 1);				/* optional */
99
100    archsw.arch_autoload = i386_autoload;
101    archsw.arch_getdev = i386_getdev;
102    archsw.arch_copyin = i386_copyin;
103    archsw.arch_copyout = i386_copyout;
104    archsw.arch_readin = i386_readin;
105    /*
106     * XXX should these be in the MI source?
107     */
108#if 0
109    legacy_config();		/* read old /boot.config file */
110#endif
111    interact();			/* doesn't return */
112}
113
114COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
115
116static int
117command_reboot(int argc, char *argv[])
118{
119
120    printf("Rebooting...\n");
121    delay(1000000);
122    __exit(0);
123}
124
125/* provide this for panic, as it's not in the startup code */
126void
127exit(int code)
128{
129    __exit(code);
130}
131
132#if 0 /* XXX learn to ask BTX */
133
134COMMAND_SET(stack, "stack", "show stack usage", command_stack);
135
136extern char stackbase, stacktop;
137
138static int
139command_stack(int argc, char *argv[])
140{
141    char	*cp;
142
143    for (cp = &stackbase; cp < &stacktop; cp++)
144	if (*cp != 0)
145	    break;
146
147    printf("%d bytes of stack used\n", &stacktop - cp);
148    return(CMD_OK);
149}
150#endif
151
152COMMAND_SET(heap, "heap", "show heap usage", command_heap);
153
154static int
155command_heap(int argc, char *argv[])
156{
157    printf("heap base at %p, top at %p, used %d\n", end, sbrk(0), sbrk(0) - end);
158    return(CMD_OK);
159}
160