idt_machdep.c revision 202027
1130803Smarcel/*-
2130803Smarcel * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved.
3130803Smarcel *
4130803Smarcel * Redistribution and use in source and binary forms, with or without
5130803Smarcel * modification, are permitted provided that the following conditions
6130803Smarcel * are met:
7130803Smarcel * 1. Redistributions of source code must retain the above copyright
8130803Smarcel *    notice, this list of conditions and the following disclaimer.
9130803Smarcel * 2. Redistributions in binary form must reproduce the above copyright
10130803Smarcel *    notice, this list of conditions and the following disclaimer in the
11130803Smarcel *    documentation and/or other materials provided with the distribution.
12130803Smarcel *
13130803Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14130803Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15130803Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16130803Smarcel * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
17130803Smarcel * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18130803Smarcel * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19130803Smarcel * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20130803Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21130803Smarcel * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22130803Smarcel * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23130803Smarcel * THE POSSIBILITY OF SUCH DAMAGE.
24130803Smarcel *
25130803Smarcel * $Id: $
26130803Smarcel *
27130803Smarcel */
28130803Smarcel
29130803Smarcel#include <sys/cdefs.h>
30130803Smarcel__FBSDID("$FreeBSD: head/sys/mips/idt/idt_machdep.c 202027 2010-01-10 19:39:08Z imp $");
31130803Smarcel
32130803Smarcel#include "opt_ddb.h"
33130803Smarcel
34130803Smarcel#include <sys/param.h>
35130803Smarcel#include <sys/conf.h>
36130803Smarcel#include <sys/kernel.h>
37130803Smarcel#include <sys/systm.h>
38130803Smarcel#include <sys/imgact.h>
39130803Smarcel#include <sys/bio.h>
40130803Smarcel#include <sys/buf.h>
41130803Smarcel#include <sys/bus.h>
42130803Smarcel#include <sys/cpu.h>
43130803Smarcel#include <sys/cons.h>
44130803Smarcel#include <sys/exec.h>
45130803Smarcel#include <sys/ucontext.h>
46130803Smarcel#include <sys/proc.h>
47130803Smarcel#include <sys/kdb.h>
48130803Smarcel#include <sys/ptrace.h>
49130803Smarcel#include <sys/reboot.h>
50130803Smarcel#include <sys/signalvar.h>
51130803Smarcel#include <sys/sysent.h>
52130803Smarcel#include <sys/sysproto.h>
53130803Smarcel#include <sys/user.h>
54130803Smarcel
55130803Smarcel#include <vm/vm.h>
56130803Smarcel#include <vm/vm_object.h>
57130803Smarcel#include <vm/vm_page.h>
58130803Smarcel#include <vm/vm_pager.h>
59130803Smarcel
60130803Smarcel#include <machine/cache.h>
61130803Smarcel#include <machine/clock.h>
62130803Smarcel#include <machine/cpu.h>
63130803Smarcel#include <machine/cpuinfo.h>
64130803Smarcel#include <machine/cpufunc.h>
65130803Smarcel#include <machine/cpuregs.h>
66130803Smarcel#include <machine/hwfunc.h>
67130803Smarcel#include <machine/intr_machdep.h>
68130803Smarcel#include <machine/locore.h>
69130803Smarcel#include <machine/md_var.h>
70130803Smarcel#include <machine/pte.h>
71130803Smarcel#include <machine/sigframe.h>
72130803Smarcel#include <machine/trap.h>
73#include <machine/vmparam.h>
74
75extern int	*edata;
76extern int	*end;
77
78void
79platform_cpu_init()
80{
81	/* Nothing special */
82}
83
84void
85platform_halt(void)
86{
87
88}
89
90
91void
92platform_identify(void)
93{
94
95}
96
97void
98platform_reset(void)
99{
100	volatile unsigned int * p = (void *)0xb8008000;
101	/*
102	 * TODO: we should take care of TLB stuff here. Otherwise
103	 * board does not boots properly next time
104	 */
105
106	/* Write 0x8000_0001 to the Reset register */
107	*p = 0x80000001;
108
109	__asm __volatile("li	$25, 0xbfc00000");
110	__asm __volatile("j	$25");
111}
112
113void
114platform_trap_enter(void)
115{
116
117}
118
119void
120platform_trap_exit(void)
121{
122
123}
124
125void
126platform_start(__register_t a0, __register_t a1,
127    __register_t a2 __unused, __register_t a3 __unused)
128{
129	uint64_t platform_counter_freq;
130	vm_offset_t kernend;
131	int argc = a0;
132	char **argv = (char **)a1;
133	int i, mem;
134
135
136	/* clear the BSS and SBSS segments */
137	kernend = round_page((vm_offset_t)&end);
138	memset(&edata, 0, kernend - (vm_offset_t)(&edata));
139
140	/* Initialize pcpu stuff */
141	mips_pcpu0_init();
142
143	/*
144	 * Looking for mem=XXM argument
145	 */
146	mem = 0; /* Just something to start with */
147	for (i=0; i < argc; i++) {
148		if (strncmp(argv[i], "mem=", 4) == 0) {
149			mem = strtol(argv[i] + 4, NULL, 0);
150			break;
151		}
152	}
153
154	bootverbose = 1;
155	if (mem > 0)
156		realmem = btoc(mem << 20);
157	else
158		realmem = btoc(32 << 20);
159
160	for (i = 0; i < 10; i++) {
161		phys_avail[i] = 0;
162	}
163
164	/* phys_avail regions are in bytes */
165	phys_avail[0] = MIPS_KSEG0_TO_PHYS((vm_offset_t)&end);
166	phys_avail[1] = ctob(realmem);
167
168	physmem = realmem;
169
170	/*
171	 * ns8250 uart code uses DELAY so ticker should be inititalized
172	 * before cninit. And tick_init_params refers to hz, so * init_param1
173	 * should be called first.
174	 */
175	init_param1();
176	/* TODO: parse argc,argv */
177	platform_counter_freq = 330000000UL;
178	mips_timer_init_params(platform_counter_freq, 1);
179	cninit();
180	/* Panic here, after cninit */
181	if (mem == 0)
182		panic("No mem=XX parameter in arguments");
183
184	printf("cmd line: ");
185	for (i=0; i < argc; i++)
186		printf("%s ", argv[i]);
187	printf("\n");
188
189	init_param2(physmem);
190	mips_cpu_init();
191	pmap_bootstrap();
192	mips_proc0_init();
193	mutex_init();
194#ifdef DDB
195	kdb_init();
196#endif
197}
198