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