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>
58 #include <machine/clock.h>
59 #include <machine/cpu.h>
60 #include <machine/cpuregs.h>
61 #include <machine/hwfunc.h>
62 #include <machine/md_var.h>
63 #include <machine/pmap.h>
64 #include <machine/trap.h>
66 #ifdef TICK_USE_YAMON_FREQ
67 #include <mips/malta/yamon.h>
70 #ifdef TICK_USE_MALTA_RTC
71 #include <mips/mips4k/malta/maltareg.h>
72 #include <dev/mc146818/mc146818reg.h>
76 #include <mips/malta/maltareg.h>
82 void lcd_puts(char *);
83 void malta_reset(void);
86 * Temporary boot environment used at startup.
88 static char boot1_env[4096];
91 * Offsets to MALTA LCD characters.
93 static int malta_lcd_offs[] = {
107 /* Nothing special */
111 * Put character to Malta LCD at given position.
114 malta_lcd_putc(int pos, char c)
119 if (pos < 0 || pos > 7)
121 addr = (void *)(MALTA_ASCII_BASE + malta_lcd_offs[pos]);
122 ch = (char *)MIPS_PHYS_TO_KSEG0(addr);
127 * Print given string on LCD.
130 malta_lcd_print(char *str)
137 for (i = 0; *str != '\0'; i++, str++)
138 malta_lcd_putc(i, *str);
144 malta_lcd_print("FreeBSD_");
153 #ifdef TICK_USE_MALTA_RTC
154 static __inline uint8_t
158 *((volatile uint8_t *)
159 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
160 return (*((volatile uint8_t *)
161 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))));
165 writertc(uint8_t addr, uint8_t val)
168 *((volatile uint8_t *)
169 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
170 *((volatile uint8_t *)
171 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))) = val;
180 for (i = 0; i < 10; i++) {
184 /* phys_avail regions are in bytes */
185 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
186 phys_avail[1] = ctob(realmem);
188 dump_avail[0] = phys_avail[0];
189 dump_avail[1] = phys_avail[1];
194 init_param2(physmem);
201 if (boothowto & RB_KDB)
202 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
207 * Perform a board-level soft-reset.
208 * Note that this is not emulated by gxemul.
215 c = (char *)MIPS_PHYS_TO_KSEG0(MALTA_SOFTRES);
222 uint64_t platform_counter_freq = 0;
224 #if defined(TICK_USE_YAMON_FREQ)
226 * If we are running on a board which uses YAMON firmware,
227 * then query CPU pipeline clock from the syscon object.
228 * If unsuccessful, use hard-coded default.
230 platform_counter_freq = yamon_getcpufreq();
232 #elif defined(TICK_USE_MALTA_RTC)
234 * If we are running on a board with the MC146818 RTC,
235 * use it to determine CPU pipeline clock frequency.
237 u_int64_t counterval[2];
239 /* Set RTC to binary mode. */
240 writertc(RTC_STATUSB, (rtcin(RTC_STATUSB) | RTCSB_BCD));
242 /* Busy-wait for falling edge of RTC update. */
243 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
245 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
247 counterval[0] = mips_rd_count();
249 /* Busy-wait for falling edge of RTC update. */
250 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
252 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
254 counterval[1] = mips_rd_count();
256 platform_counter_freq = counterval[1] - counterval[0];
259 if (platform_counter_freq == 0)
260 platform_counter_freq = MIPS_DEFAULT_HZ;
262 return (platform_counter_freq);
266 platform_start(__register_t a0, __register_t a1, __register_t a2,
270 uint64_t platform_counter_freq;
272 int32_t *argv = (int32_t*)a1;
273 int32_t *envp = (int32_t*)a2;
274 unsigned int memsize = a3;
277 /* clear the BSS and SBSS segments */
278 kernend = (vm_offset_t)&end;
279 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
281 mips_postboot_fixup();
284 platform_counter_freq = malta_cpu_freq();
285 mips_timer_early_init(platform_counter_freq);
286 init_static_kenv(boot1_env, sizeof(boot1_env));
289 printf("entry: platform_start()\n");
293 * YAMON uses 32bit pointers to strings so
294 * convert them to proper type manually
297 printf("cmd line: ");
298 for (i = 0; i < argc; i++)
299 printf("%s ", (char*)(intptr_t)argv[i]);
303 for (i = 0; envp[i]; i += 2)
304 printf("\t%s = %s\n", (char*)(intptr_t)envp[i],
305 (char*)(intptr_t)envp[i+1]);
307 printf("memsize = %08x\n", memsize);
310 realmem = btoc(memsize);
313 mips_timer_init_params(platform_counter_freq, 0);