2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
3 * Copyright (c) 2012 Robert N. M. Watson
6 * This software was developed by SRI International and the University of
7 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8 * ("CTSRD"), as part of the DARPA CRASH research programme.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 #include "opt_platform.h"
37 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 #include <sys/imgact.h>
48 #include <sys/linker.h>
49 #include <sys/ucontext.h>
52 #include <sys/ptrace.h>
53 #include <sys/reboot.h>
54 #include <sys/signalvar.h>
55 #include <sys/sysent.h>
56 #include <sys/sysproto.h>
60 #include <dev/fdt/fdt_common.h>
61 #include <dev/ofw/openfirm.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_page.h>
68 #include <machine/clock.h>
69 #include <machine/cpu.h>
70 #include <machine/cpuregs.h>
71 #include <machine/hwfunc.h>
72 #include <machine/md_var.h>
73 #include <machine/metadata.h>
74 #include <machine/pmap.h>
75 #include <machine/trap.h>
91 for (i = 0; i < 10; i++) {
95 /* phys_avail regions are in bytes */
96 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
97 phys_avail[1] = ctob(realmem);
99 dump_avail[0] = phys_avail[0];
100 dump_avail[1] = phys_avail[1];
105 init_param2(physmem);
112 if (boothowto & RB_KDB)
113 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
118 * Perform a board-level soft-reset.
124 /* XXX SMP will likely require us to do more. */
125 __asm__ __volatile__(
127 "li $k1, 0x00100000\n\t"
128 "or $k0, $k0, $k1\n\t"
131 __asm__ __volatile("wait");
135 /* Parse cmd line args as env - copied from xlp_machdep. */
136 /* XXX-BZ this should really be centrally provided for all (boot) code. */
138 _parse_bootargs(char *cmdline)
142 while ((v = strsep(&cmdline, " \n")) != NULL) {
149 case 'a': boothowto |= RB_ASKNAME; break;
150 /* Someone should simulate that ;-) */
151 case 'C': boothowto |= RB_CDROM; break;
152 case 'd': boothowto |= RB_KDB; break;
153 case 'D': boothowto |= RB_MULTIPLE; break;
154 case 'm': boothowto |= RB_MUTE; break;
155 case 'g': boothowto |= RB_GDB; break;
156 case 'h': boothowto |= RB_SERIAL; break;
157 case 'p': boothowto |= RB_PAUSE; break;
158 case 'r': boothowto |= RB_DFLTROOT; break;
159 case 's': boothowto |= RB_SINGLE; break;
160 case 'v': boothowto |= RB_VERBOSE; break;
175 platform_start(__register_t a0, __register_t a1, __register_t a2,
179 uint64_t platform_counter_freq;
181 char **argv = (char **)a1;
182 char **envp = (char **)a2;
183 unsigned int memsize = a3;
185 char buf[2048]; /* early stack supposedly big enough */
192 /* clear the BSS and SBSS segments */
193 kernend = (vm_offset_t)&end;
194 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
196 mips_postboot_fixup();
202 * Find the dtb passed in by the boot loader (currently fictional).
204 kmdp = preload_search_by_type("elf kernel");
206 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
208 dtbp = (vm_offset_t)NULL;
210 #if defined(FDT_DTB_STATIC)
212 * In case the device tree blob was not retrieved (from metadata) try
213 * to use the statically embedded one.
215 if (dtbp == (vm_offset_t)NULL)
216 dtbp = (vm_offset_t)&fdt_static_dtb;
218 #error "Non-static FDT not yet supported on BERI"
221 if (OF_install(OFW_FDT, 0) == FALSE)
223 if (OF_init((void *)dtbp) != 0)
227 * Get bootargs from FDT if specified.
229 chosen = OF_finddevice("/chosen");
230 if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
231 _parse_bootargs(buf);
235 * XXXRW: We have no way to compare wallclock time to cycle rate on
236 * BERI, so for now assume we run at the MALTA default (100MHz).
238 platform_counter_freq = MIPS_DEFAULT_HZ;
239 mips_timer_early_init(platform_counter_freq);
242 printf("entry: platform_start()\n");
246 printf("cmd line: ");
247 for (i = 0; i < argc; i++)
248 printf("%s ", argv[i]);
252 for (i = 0; envp[i]; i += 2)
253 printf("\t%s = %s\n", envp[i], envp[i+1]);
255 printf("memsize = %08x\n", memsize);
258 realmem = btoc(memsize);
261 mips_timer_init_params(platform_counter_freq, 0);