2 * Copyright (c) 2000 Benno Rice <benno@jeamland.net>
3 * Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
34 #include "bootstrap.h"
36 struct arch_switch archsw; /* MI/MD interface boundary */
39 extern char bootprog_name[];
40 extern char bootprog_rev[];
41 extern char bootprog_date[];
42 extern char bootprog_maker[];
44 u_int32_t acells, scells;
46 static char bootargs[128];
48 #define HEAP_SIZE 0x80000
50 #define OF_puts(fd, text) OF_write(fd, text, strlen(text))
58 if ((base = ofw_alloc_heap(HEAP_SIZE)) == (void *)0xffffffff) {
59 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
60 OF_puts(stdout, "Heap memory claim failed!\n");
64 setheap(base, (void *)((int)base + HEAP_SIZE));
76 memoryp = OF_instance_to_package(memory);
78 sz = OF_getprop(memoryp, "reg", ®, sizeof(reg));
81 for (i = 0; i < sz; i += (acells + scells)) {
83 memsz += (uint64_t)reg[i + acells] << 32;
84 memsz += reg[i + acells + scells - 1];
91 main(int (*openfirm)(void *))
101 * Initalise the Open Firmware routines by giving them the entry point.
105 root = OF_finddevice("/");
108 OF_getprop(root, "#address-cells", &acells, sizeof(acells));
109 OF_getprop(root, "#size-cells", &scells, sizeof(scells));
112 * Initialise the heap as early as possible. Once this is done,
113 * alloc() is usable. The stack is buried inside us, so this is
124 * March through the device switch probing for things.
126 for (i = 0; devsw[i] != NULL; i++)
127 if (devsw[i]->dv_init != NULL)
128 (devsw[i]->dv_init)();
131 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
132 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
133 printf("Memory: %lldKB\n", memsize() / 1024);
135 OF_getprop(chosen, "bootpath", bootpath, 64);
136 ch = strchr(bootpath, ':');
138 printf("Booted from: %s\n", bootpath);
143 * Only parse the first bootarg if present. It should
144 * be simple to handle extra arguments
146 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs));
148 parse(&bargc, &bargv, bootargs);
150 env_setenv("currdev", EV_VOLATILE, bargv[0], ofw_setcurrdev,
153 env_setenv("currdev", EV_VOLATILE, bootpath,
154 ofw_setcurrdev, env_nounset);
155 env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
157 setenv("LINES", "24", 1); /* optional */
159 archsw.arch_getdev = ofw_getdev;
160 archsw.arch_copyin = ofw_copyin;
161 archsw.arch_copyout = ofw_copyout;
162 archsw.arch_readin = ofw_readin;
163 archsw.arch_autoload = ofw_autoload;
165 interact(); /* doesn't return */
172 COMMAND_SET(halt, "halt", "halt the system", command_halt);
175 command_halt(int argc, char *argv[])
182 COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
185 command_memmap(int argc, char **argv)