1/*-
2 * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include "opt_ddb.h"
31
32#include <sys/param.h>
33#include <sys/conf.h>
34#include <sys/kernel.h>
35#include <sys/systm.h>
36#include <sys/imgact.h>
37#include <sys/bio.h>
38#include <sys/buf.h>
39#include <sys/bus.h>
40#include <sys/cpu.h>
41#include <sys/cons.h>
42#include <sys/exec.h>
43#include <sys/ucontext.h>
44#include <sys/proc.h>
45#include <sys/kdb.h>
46#include <sys/ptrace.h>
47#include <sys/reboot.h>
48#include <sys/signalvar.h>
49#include <sys/sysent.h>
50#include <sys/sysproto.h>
51#include <sys/user.h>
52
53#include <vm/vm.h>
54#include <vm/vm_object.h>
55#include <vm/vm_page.h>
56#include <vm/vm_pager.h>
57
58#include <machine/cache.h>
59#include <machine/clock.h>
60#include <machine/cpu.h>
61#include <machine/cpuinfo.h>
62#include <machine/cpufunc.h>
63#include <machine/cpuregs.h>
64#include <machine/hwfunc.h>
65#include <machine/intr_machdep.h>
66#include <machine/locore.h>
67#include <machine/md_var.h>
68#include <machine/pte.h>
69#include <machine/sigframe.h>
70#include <machine/trap.h>
71#include <machine/vmparam.h>
72
73extern int	*edata;
74extern int	*end;
75
76void
77platform_cpu_init()
78{
79	/* Nothing special */
80}
81
82static void
83mips_init(void)
84{
85	int i;
86
87	printf("entry: mips_init()\n");
88
89	bootverbose = 1;
90	realmem = btoc(16 << 20);
91
92	for (i = 0; i < 10; i++) {
93		phys_avail[i] = 0;
94	}
95
96	/* phys_avail regions are in bytes */
97	phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
98	phys_avail[1] = ctob(realmem);
99
100	dump_avail[0] = phys_avail[0];
101	dump_avail[1] = phys_avail[1];
102
103	physmem = realmem;
104
105	init_param1();
106	init_param2(physmem);
107	mips_cpu_init();
108	pmap_bootstrap();
109	mips_proc0_init();
110	mutex_init();
111
112	kdb_init();
113#ifdef KDB
114	if (boothowto & RB_KDB)
115		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
116#endif
117}
118
119void
120platform_halt(void)
121{
122
123}
124
125
126void
127platform_identify(void)
128{
129
130}
131
132void
133platform_reset(void)
134{
135
136	__asm __volatile("li	$25, 0xbfc00000");
137	__asm __volatile("j	$25");
138}
139
140void
141platform_trap_enter(void)
142{
143
144}
145
146void
147platform_trap_exit(void)
148{
149
150}
151
152void
153platform_start(__register_t a0 __unused, __register_t a1 __unused,
154    __register_t a2 __unused, __register_t a3 __unused)
155{
156	vm_offset_t kernend;
157	uint64_t platform_counter_freq = 175 * 1000 * 1000;
158
159	/* clear the BSS and SBSS segments */
160	kernend = (vm_offset_t)&end;
161	memset(&edata, 0, kernend - (vm_offset_t)(&edata));
162
163	mips_postboot_fixup();
164
165	/* Initialize pcpu stuff */
166	mips_pcpu0_init();
167
168	cninit();
169	mips_init();
170	/* Set counter_freq for tick_init_params() */
171	platform_counter_freq = 175 * 1000 * 1000;
172
173	mips_timer_init_params(platform_counter_freq, 0);
174}
175