2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
3 * Copyright (c) 2012-2014 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/bootinfo.h>
69 #include <machine/clock.h>
70 #include <machine/cpu.h>
71 #include <machine/cpuregs.h>
72 #include <machine/hwfunc.h>
73 #include <machine/md_var.h>
74 #include <machine/metadata.h>
75 #include <machine/pmap.h>
76 #include <machine/trap.h>
92 struct mem_region mr[FDT_MEM_REGIONS];
98 for (i = 0; i < 10; i++) {
102 /* phys_avail regions are in bytes */
103 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
104 phys_avail[1] = ctob(realmem);
106 dump_avail[0] = phys_avail[0];
107 dump_avail[1] = phys_avail[1];
112 if (fdt_get_mem_regions(mr, &mr_cnt, &val) == 0) {
116 KASSERT((phys_avail[0] >= mr[0].mr_start) && \
117 (phys_avail[0] < (mr[0].mr_start + mr[0].mr_size)),
118 ("First region is not within FDT memory range"));
120 /* Limit size of the first region */
121 phys_avail[1] = (mr[0].mr_start + MIN(mr[0].mr_size, ctob(realmem)));
122 dump_avail[1] = phys_avail[1];
124 /* Add the rest of regions */
125 for (i = 1, j = 2; i < mr_cnt; i++, j+=2) {
126 phys_avail[j] = mr[i].mr_start;
127 phys_avail[j+1] = (mr[i].mr_start + mr[i].mr_size);
128 dump_avail[j] = phys_avail[j];
129 dump_avail[j+1] = phys_avail[j+1];
135 init_param2(physmem);
142 if (boothowto & RB_KDB)
143 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
148 * Perform a board-level soft-reset.
154 /* XXX SMP will likely require us to do more. */
155 __asm__ __volatile__(
157 "li $k1, 0x00100000\n\t"
158 "or $k0, $k0, $k1\n\t"
161 __asm__ __volatile("wait");
165 /* Parse cmd line args as env - copied from xlp_machdep. */
166 /* XXX-BZ this should really be centrally provided for all (boot) code. */
168 _parse_bootargs(char *cmdline)
172 while ((v = strsep(&cmdline, " \n")) != NULL) {
179 case 'a': boothowto |= RB_ASKNAME; break;
180 /* Someone should simulate that ;-) */
181 case 'C': boothowto |= RB_CDROM; break;
182 case 'd': boothowto |= RB_KDB; break;
183 case 'D': boothowto |= RB_MULTIPLE; break;
184 case 'm': boothowto |= RB_MUTE; break;
185 case 'g': boothowto |= RB_GDB; break;
186 case 'h': boothowto |= RB_SERIAL; break;
187 case 'p': boothowto |= RB_PAUSE; break;
188 case 'r': boothowto |= RB_DFLTROOT; break;
189 case 's': boothowto |= RB_SINGLE; break;
190 case 'v': boothowto |= RB_VERBOSE; break;
205 platform_start(__register_t a0, __register_t a1, __register_t a2,
208 struct bootinfo *bootinfop;
210 uint64_t platform_counter_freq;
212 char **argv = (char **)a1;
213 char **envp = (char **)a2;
216 char buf[2048]; /* early stack supposedly big enough */
223 /* clear the BSS and SBSS segments */
224 kernend = (vm_offset_t)&end;
225 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
227 mips_postboot_fixup();
232 * Over time, we've changed out boot-time binary interface for the
233 * kernel. Miniboot simply provides a 'memsize' in a3, whereas the
234 * FreeBSD boot loader provides a 'bootinfo *' in a3. While slightly
235 * grody, we support both here by detecting 'pointer-like' values in
236 * a3 and assuming physical memory can never be that back.
238 * XXXRW: Pull more values than memsize out of bootinfop -- e.g.,
239 * module information.
241 if (a3 >= 0x9800000000000000ULL) {
242 bootinfop = (void *)a3;
243 memsize = bootinfop->bi_memsize;
244 preload_metadata = (caddr_t)bootinfop->bi_modulep;
252 * Find the dtb passed in by the boot loader (currently fictional).
254 kmdp = preload_search_by_type("elf kernel");
255 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
257 #if defined(FDT_DTB_STATIC)
259 * In case the device tree blob was not retrieved (from metadata) try
260 * to use the statically embedded one.
262 if (dtbp == (vm_offset_t)NULL)
263 dtbp = (vm_offset_t)&fdt_static_dtb;
265 #error "Non-static FDT not yet supported on BERI"
268 if (OF_install(OFW_FDT, 0) == FALSE)
270 if (OF_init((void *)dtbp) != 0)
274 * Configure more boot-time parameters passed in by loader.
276 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
277 init_static_kenv(MD_FETCH(kmdp, MODINFOMD_ENVP, char *), 0);
280 * Get bootargs from FDT if specified.
282 chosen = OF_finddevice("/chosen");
283 if (OF_getprop(chosen, "bootargs", buf, sizeof(buf)) != -1)
284 _parse_bootargs(buf);
288 * XXXRW: We have no way to compare wallclock time to cycle rate on
289 * BERI, so for now assume we run at the MALTA default (100MHz).
291 platform_counter_freq = MIPS_DEFAULT_HZ;
292 mips_timer_early_init(platform_counter_freq);
295 printf("entry: platform_start()\n");
299 printf("cmd line: ");
300 for (i = 0; i < argc; i++)
301 printf("%s ", argv[i]);
305 for (i = 0; envp[i]; i += 2)
306 printf("\t%s = %s\n", envp[i], envp[i+1]);
308 if (bootinfop != NULL)
309 printf("bootinfo found at %p\n", bootinfop);
311 printf("memsize = %p\n", (void *)memsize);
314 realmem = btoc(memsize);
317 mips_timer_init_params(platform_counter_freq, 0);