2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
5 * Copyright (c) 2012-2014 Robert N. M. Watson
8 * This software was developed by SRI International and the University of
9 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
10 * ("CTSRD"), as part of the DARPA CRASH research programme.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 #include "opt_platform.h"
39 #include <sys/param.h>
41 #include <sys/kernel.h>
42 #include <sys/systm.h>
43 #include <sys/imgact.h>
50 #include <sys/linker.h>
51 #include <sys/ucontext.h>
54 #include <sys/ptrace.h>
55 #include <sys/reboot.h>
56 #include <sys/signalvar.h>
57 #include <sys/sysent.h>
58 #include <sys/sysproto.h>
62 #include <dev/fdt/fdt_common.h>
63 #include <dev/ofw/openfirm.h>
64 #include <dev/ofw/ofw_subr.h>
68 #include <vm/vm_object.h>
69 #include <vm/vm_page.h>
71 #include <machine/bootinfo.h>
72 #include <machine/clock.h>
73 #include <machine/cpu.h>
74 #include <machine/cpuregs.h>
75 #include <machine/hwfunc.h>
76 #include <machine/md_var.h>
77 #include <machine/metadata.h>
78 #include <machine/pmap.h>
79 #include <machine/trap.h>
95 struct mem_region mr[FDT_MEM_REGIONS];
101 for (i = 0; i < 10; i++) {
105 /* phys_avail regions are in bytes */
106 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
107 phys_avail[1] = ctob(realmem);
109 dump_avail[0] = phys_avail[0];
110 dump_avail[1] = phys_avail[1];
115 if (fdt_get_mem_regions(mr, &mr_cnt, &val) == 0) {
119 KASSERT((phys_avail[0] >= mr[0].mr_start) && \
120 (phys_avail[0] < (mr[0].mr_start + mr[0].mr_size)),
121 ("First region is not within FDT memory range"));
123 /* Limit size of the first region */
124 phys_avail[1] = (mr[0].mr_start + MIN(mr[0].mr_size, ctob(realmem)));
125 dump_avail[1] = phys_avail[1];
127 /* Add the rest of regions */
128 for (i = 1, j = 2; i < mr_cnt; i++, j+=2) {
129 phys_avail[j] = mr[i].mr_start;
130 phys_avail[j+1] = (mr[i].mr_start + mr[i].mr_size);
131 dump_avail[j] = phys_avail[j];
132 dump_avail[j+1] = phys_avail[j+1];
138 init_param2(physmem);
145 if (boothowto & RB_KDB)
146 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
151 * Perform a board-level soft-reset.
157 /* XXX SMP will likely require us to do more. */
158 __asm__ __volatile__(
160 "li $k1, 0x00100000\n\t"
161 "or $k0, $k0, $k1\n\t"
164 __asm__ __volatile("wait");
168 platform_start(__register_t a0, __register_t a1, __register_t a2,
171 struct bootinfo *bootinfop;
173 uint64_t platform_counter_freq;
175 char **argv = (char **)a1;
176 char **envp = (char **)a2;
184 /* clear the BSS and SBSS segments */
185 kernend = (vm_offset_t)&end;
186 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
188 mips_postboot_fixup();
193 * Over time, we've changed out boot-time binary interface for the
194 * kernel. Miniboot simply provides a 'memsize' in a3, whereas the
195 * FreeBSD boot loader provides a 'bootinfo *' in a3. While slightly
196 * grody, we support both here by detecting 'pointer-like' values in
197 * a3 and assuming physical memory can never be that back.
199 * XXXRW: Pull more values than memsize out of bootinfop -- e.g.,
200 * module information.
202 if (a3 >= 0x9800000000000000ULL) {
203 bootinfop = (void *)a3;
204 memsize = bootinfop->bi_memsize;
205 preload_metadata = (caddr_t)bootinfop->bi_modulep;
213 * Find the dtb passed in by the boot loader (currently fictional).
215 kmdp = preload_search_by_type("elf kernel");
216 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
218 #if defined(FDT_DTB_STATIC)
220 * In case the device tree blob was not retrieved (from metadata) try
221 * to use the statically embedded one.
223 if (dtbp == (vm_offset_t)NULL)
224 dtbp = (vm_offset_t)&fdt_static_dtb;
226 #error "Non-static FDT not yet supported on BERI"
229 if (OF_install(OFW_FDT, 0) == FALSE)
231 if (OF_init((void *)dtbp) != 0)
235 * Configure more boot-time parameters passed in by loader.
237 boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
238 init_static_kenv(MD_FETCH(kmdp, MODINFOMD_ENVP, char *), 0);
241 * Get bootargs from FDT if specified.
243 ofw_parse_bootargs();
247 * XXXRW: We have no way to compare wallclock time to cycle rate on
248 * BERI, so for now assume we run at the MALTA default (100MHz).
250 platform_counter_freq = MIPS_DEFAULT_HZ;
251 mips_timer_early_init(platform_counter_freq);
254 printf("entry: platform_start()\n");
258 printf("cmd line: ");
259 for (i = 0; i < argc; i++)
260 printf("%s ", argv[i]);
264 for (i = 0; envp[i]; i += 2)
265 printf("\t%s = %s\n", envp[i], envp[i+1]);
267 if (bootinfop != NULL)
268 printf("bootinfo found at %p\n", bootinfop);
270 printf("memsize = %p\n", (void *)memsize);
273 realmem = btoc(memsize);
276 mips_timer_init_params(platform_counter_freq, 0);