2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/imgact.h>
44 #include <sys/ucontext.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>
55 #include <vm/vm_object.h>
56 #include <vm/vm_page.h>
57 #include <vm/vm_pager.h>
59 #include <machine/clock.h>
60 #include <machine/cpu.h>
61 #include <machine/cpuregs.h>
62 #include <machine/hwfunc.h>
63 #include <machine/md_var.h>
64 #include <machine/pmap.h>
65 #include <machine/trap.h>
67 #ifdef TICK_USE_YAMON_FREQ
68 #include <mips/malta/yamon.h>
71 #ifdef TICK_USE_MALTA_RTC
72 #include <mips/mips4k/malta/maltareg.h>
73 #include <dev/mc146818/mc146818reg.h>
77 #include <mips/malta/maltareg.h>
83 void lcd_puts(char *);
84 void malta_reset(void);
87 * Offsets to MALTA LCD characters.
89 static int malta_lcd_offs[] = {
101 * Put character to Malta LCD at given position.
104 malta_lcd_putc(int pos, char c)
109 if (pos < 0 || pos > 7)
111 addr = (void *)(MALTA_ASCII_BASE + malta_lcd_offs[pos]);
112 ch = (char *)MIPS_PHYS_TO_KSEG0(addr);
117 * Print given string on LCD.
120 malta_lcd_print(char *str)
127 for (i = 0; *str != '\0'; i++, str++)
128 malta_lcd_putc(i, *str);
134 malta_lcd_print("FreeBSD_");
143 #ifdef TICK_USE_MALTA_RTC
144 static __inline uint8_t
148 *((volatile uint8_t *)
149 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
150 return (*((volatile uint8_t *)
151 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))));
155 writertc(uint8_t addr, uint8_t val)
158 *((volatile uint8_t *)
159 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
160 *((volatile uint8_t *)
161 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))) = val;
170 for (i = 0; i < 10; i++) {
174 /* phys_avail regions are in bytes */
175 phys_avail[0] = MIPS_KSEG0_TO_PHYS((vm_offset_t)&end);
176 phys_avail[1] = ctob(realmem);
181 init_param2(physmem);
199 platform_identify(void)
205 * Perform a board-level soft-reset.
206 * Note that this is not emulated by gxemul.
213 c = (char *)MIPS_PHYS_TO_KSEG0(MALTA_SOFTRES);
218 platform_trap_enter(void)
224 platform_trap_exit(void)
230 platform_start(__register_t a0, __register_t a1, __register_t a2,
234 uint64_t platform_counter_freq;
236 char **argv = (char **)a1;
237 char **envp = (char **)a2;
238 unsigned int memsize = a3;
241 /* clear the BSS and SBSS segments */
242 kernend = round_page((vm_offset_t)&end);
243 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
246 printf("entry: platform_start()\n");
250 printf("cmd line: ");
251 for (i = 0; i < argc; i++)
252 printf("%s ", argv[i]);
256 for (i = 0; envp[i]; i += 2)
257 printf("\t%s = %s\n", envp[i], envp[i+1]);
259 printf("memsize = %08x\n", memsize);
262 realmem = btoc(memsize);
266 #if defined(TICK_USE_YAMON_FREQ)
268 * If we are running on a board which uses YAMON firmware,
269 * then query CPU pipeline clock from the syscon object.
270 * If unsuccessful, use hard-coded default.
272 platform_counter_freq = yamon_getcpufreq();
273 if (platform_counter_freq == 0)
274 platform_counter_freq = MIPS_DEFAULT_HZ;
276 #elif defined(TICK_USE_MALTA_RTC)
278 * If we are running on a board with the MC146818 RTC,
279 * use it to determine CPU pipeline clock frequency.
281 u_int64_t counterval[2];
283 /* Set RTC to binary mode. */
284 writertc(RTC_STATUSB, (rtcin(RTC_STATUSB) | RTCSB_BCD));
286 /* Busy-wait for falling edge of RTC update. */
287 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
289 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
291 counterval[0] = mips_rd_count();
293 /* Busy-wait for falling edge of RTC update. */
294 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
296 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
298 counterval[1] = mips_rd_count();
300 platform_counter_freq = counterval[1] - counterval[0];
304 mips_timer_init_params(platform_counter_freq, 0);