Error out if no volumes are specified instead of core-dumping.
[dragonfly.git] / sys / boot / ofw / common / main.c
blobddefee27ff5d06454f05db5be5993bf75e106528
1 /*-
2 * Copyright (c) 2000 Benno Rice <benno@jeamland.net>
3 * Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
27 * $FreeBSD: src/sys/boot/ofw/common/main.c,v 1.3 2002/11/10 19:17:35 jake Exp $
28 * $DragonFly: src/sys/boot/ofw/common/main.c,v 1.1 2003/11/10 06:08:37 dillon Exp $
31 #include <stand.h>
32 #include "openfirm.h"
33 #include "libofw.h"
34 #include "bootstrap.h"
36 struct arch_switch archsw; /* MI/MD interface boundary */
38 extern char end[];
39 extern char bootprog_name[];
40 extern char bootprog_rev[];
41 extern char bootprog_date[];
42 extern char bootprog_maker[];
44 phandle_t chosen;
46 #define HEAP_SIZE 0x40000
48 void
49 init_heap(void)
51 void *base;
53 if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) {
54 printf("Heap memory claim failed!\n");
55 OF_enter();
58 setheap(base, base + (HEAP_SIZE / sizeof(base)));
61 uint32_t
62 memsize(void)
64 ihandle_t meminstance;
65 phandle_t memory;
66 struct ofw_reg reg;
68 OF_getprop(chosen, "memory", &meminstance, sizeof(meminstance));
69 memory = OF_instance_to_package(meminstance);
71 OF_getprop(memory, "reg", &reg, sizeof(reg));
73 return (reg.size);
76 int
77 main(int (*openfirm)(void *))
79 int i;
80 char bootpath[64];
81 char *ch;
84 * Initalise the OpenFirmware routines by giving them the entry point.
86 OF_init(openfirm);
88 chosen = OF_finddevice("/chosen");
91 * Set up console.
93 cons_probe();
96 * Initialise the heap as early as possible. Once this is done,
97 * alloc() is usable. The stack is buried inside us, so this is
98 * safe.
100 init_heap();
103 * Initialise the block cache
105 bcache_init(32, 512); /* 16k XXX tune this */
108 * March through the device switch probing for things.
110 for (i = 0; devsw[i] != NULL; i++)
111 if (devsw[i]->dv_init != NULL)
112 (devsw[i]->dv_init)();
114 printf("\n");
115 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
116 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
117 printf("Memory: %dKB\n", memsize() / 1024);
119 OF_getprop(chosen, "bootpath", bootpath, 64);
120 ch = index(bootpath, ':');
121 *ch = '\0';
122 printf("Booted from: %s\n", bootpath);
124 printf("\n");
126 env_setenv("currdev", EV_VOLATILE, bootpath,
127 ofw_setcurrdev, env_nounset);
128 env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
129 env_nounset);
130 setenv("LINES", "24", 1); /* optional */
132 archsw.arch_getdev = ofw_getdev;
133 archsw.arch_copyin = ofw_copyin;
134 archsw.arch_copyout = ofw_copyout;
135 archsw.arch_readin = ofw_readin;
136 archsw.arch_autoload = ofw_autoload;
138 interact(); /* doesn't return */
140 OF_exit();
142 return 0;
145 COMMAND_SET(halt, "halt", "halt the system", command_halt);
147 static int
148 command_halt(int argc, char *argv[])
151 OF_exit();
152 return (CMD_OK);
155 COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
158 command_memmap(int argc, char **argv)
161 ofw_memmap();
162 return (CMD_OK);