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 #include <machine/psl.h>
38 struct arch_switch archsw; /* MI/MD interface boundary */
42 uint32_t acells, scells;
44 static char bootargs[128];
46 #define HEAP_SIZE 0x800000
47 static char heap[HEAP_SIZE]; // In BSS, so uses no space
49 #define OF_puts(fd, text) OF_write(fd, text, strlen(text))
51 static __inline register_t
56 __asm __volatile ("mfmsr %0" : "=r"(value));
64 bzero(heap, HEAP_SIZE);
66 setheap(heap, (void *)((uintptr_t)heap + HEAP_SIZE));
78 memoryp = OF_instance_to_package(memory);
80 sz = OF_getprop(memoryp, "reg", ®, sizeof(reg));
83 for (i = 0; i < sz; i += (acells + scells)) {
85 memsz += (uint64_t)reg[i + acells] << 32;
86 memsz += reg[i + acells + scells - 1];
93 extern int ppc64_cas(void);
100 if ((cas = getenv("cas")) && cas[0] == '1')
101 if (ppc64_cas() != 0)
103 return (ofw_autoload());
108 main(int (*openfirm)(void *))
118 * Initialise the Open Firmware routines by giving them the entry point.
122 root = OF_finddevice("/");
125 OF_getprop(root, "#address-cells", &acells, sizeof(acells));
126 OF_getprop(root, "#size-cells", &scells, sizeof(scells));
129 * Initialise the heap as early as possible. Once this is done,
130 * alloc() is usable. The stack is buried inside us, so this is
141 * March through the device switch probing for things.
143 for (i = 0; devsw[i] != NULL; i++)
144 if (devsw[i]->dv_init != NULL)
145 (devsw[i]->dv_init)();
147 printf("\n%s", bootprog_info);
148 printf("Memory: %lldKB\n", memsize() / 1024);
150 OF_getprop(chosen, "bootpath", bootpath, 64);
151 ch = strchr(bootpath, ':');
153 printf("Booted from: %s\n", bootpath);
158 * Only parse the first bootarg if present. It should
159 * be simple to handle extra arguments
161 OF_getprop(chosen, "bootargs", bootargs, sizeof(bootargs));
163 parse(&bargc, &bargv, bootargs);
165 env_setenv("currdev", EV_VOLATILE, bargv[0], ofw_setcurrdev,
168 env_setenv("currdev", EV_VOLATILE, bootpath,
169 ofw_setcurrdev, env_nounset);
170 env_setenv("loaddev", EV_VOLATILE, bootpath, env_noset,
172 setenv("LINES", "24", 1); /* optional */
175 * On non-Apple hardware, where it works reliably, pass flattened
176 * device trees to the kernel by default instead of OF CI pointers.
177 * Apple hardware is the only virtual-mode OF implementation in
178 * existence, so far as I am aware, so use that as a flag.
180 if (!(mfmsr() & PSL_DR))
181 setenv("usefdt", "1", 1);
183 archsw.arch_getdev = ofw_getdev;
184 archsw.arch_copyin = ofw_copyin;
185 archsw.arch_copyout = ofw_copyout;
186 archsw.arch_readin = ofw_readin;
188 setenv("cas", "1", 0);
189 archsw.arch_autoload = ppc64_autoload;
191 archsw.arch_autoload = ofw_autoload;
194 interact(); /* doesn't return */
201 COMMAND_SET(halt, "halt", "halt the system", command_halt);
204 command_halt(int argc, char *argv[])
211 COMMAND_SET(memmap, "memmap", "print memory map", command_memmap);
214 command_memmap(int argc, char **argv)