1178173Simp/*- 2178173Simp * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved. 3178173Simp * 4178173Simp * Redistribution and use in source and binary forms, with or without 5178173Simp * modification, are permitted provided that the following conditions 6178173Simp * are met: 7178173Simp * 1. Redistributions of source code must retain the above copyright 8178173Simp * notice, this list of conditions and the following disclaimer. 9178173Simp * 2. Redistributions in binary form must reproduce the above copyright 10178173Simp * notice, this list of conditions and the following disclaimer in the 11178173Simp * documentation and/or other materials provided with the distribution. 12178173Simp * 13178173Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14178173Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15178173Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16178173Simp * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 17178173Simp * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18178173Simp * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19178173Simp * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20178173Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21178173Simp * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 22178173Simp * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23178173Simp * THE POSSIBILITY OF SUCH DAMAGE. 24178173Simp * 25178173Simp * $Id: $ 26178173Simp * 27178173Simp */ 28178173Simp 29178173Simp#include <sys/cdefs.h> 30178173Simp__FBSDID("$FreeBSD$"); 31178173Simp 32178173Simp#include "opt_ddb.h" 33178173Simp 34178173Simp#include <sys/param.h> 35178173Simp#include <sys/conf.h> 36178173Simp#include <sys/kernel.h> 37178173Simp#include <sys/systm.h> 38178173Simp#include <sys/imgact.h> 39178173Simp#include <sys/bio.h> 40178173Simp#include <sys/buf.h> 41178173Simp#include <sys/bus.h> 42178173Simp#include <sys/cpu.h> 43178173Simp#include <sys/cons.h> 44178173Simp#include <sys/exec.h> 45178173Simp#include <sys/ucontext.h> 46178173Simp#include <sys/proc.h> 47178173Simp#include <sys/kdb.h> 48178173Simp#include <sys/ptrace.h> 49178173Simp#include <sys/reboot.h> 50178173Simp#include <sys/signalvar.h> 51178173Simp#include <sys/sysent.h> 52178173Simp#include <sys/sysproto.h> 53178173Simp#include <sys/user.h> 54178173Simp 55178173Simp#include <vm/vm.h> 56178173Simp#include <vm/vm_object.h> 57178173Simp#include <vm/vm_page.h> 58178173Simp 59178173Simp#include <machine/cache.h> 60178173Simp#include <machine/clock.h> 61178173Simp#include <machine/cpu.h> 62178173Simp#include <machine/cpuinfo.h> 63178173Simp#include <machine/cpufunc.h> 64178173Simp#include <machine/cpuregs.h> 65178173Simp#include <machine/hwfunc.h> 66178173Simp#include <machine/intr_machdep.h> 67178173Simp#include <machine/locore.h> 68178173Simp#include <machine/md_var.h> 69178173Simp#include <machine/pte.h> 70178173Simp#include <machine/sigframe.h> 71178173Simp#include <machine/trap.h> 72178173Simp#include <machine/vmparam.h> 73178173Simp 74178173Simpextern int *edata; 75178173Simpextern int *end; 76178173Simp 77178173Simpvoid 78202027Simpplatform_cpu_init() 79202027Simp{ 80202027Simp /* Nothing special */ 81202027Simp} 82202027Simp 83202027Simpvoid 84178173Simpplatform_reset(void) 85178173Simp{ 86178173Simp volatile unsigned int * p = (void *)0xb8008000; 87178173Simp /* 88178173Simp * TODO: we should take care of TLB stuff here. Otherwise 89178173Simp * board does not boots properly next time 90178173Simp */ 91178173Simp 92178173Simp /* Write 0x8000_0001 to the Reset register */ 93178173Simp *p = 0x80000001; 94178173Simp 95178173Simp __asm __volatile("li $25, 0xbfc00000"); 96178173Simp __asm __volatile("j $25"); 97178173Simp} 98178173Simp 99178173Simpvoid 100178173Simpplatform_start(__register_t a0, __register_t a1, 101178173Simp __register_t a2 __unused, __register_t a3 __unused) 102178173Simp{ 103178173Simp uint64_t platform_counter_freq; 104178173Simp vm_offset_t kernend; 105178173Simp int argc = a0; 106178173Simp char **argv = (char **)a1; 107178173Simp int i, mem; 108178173Simp 109178173Simp 110178173Simp /* clear the BSS and SBSS segments */ 111202954Sgonzo kernend = (vm_offset_t)&end; 112178173Simp memset(&edata, 0, kernend - (vm_offset_t)(&edata)); 113178173Simp 114202954Sgonzo mips_postboot_fixup(); 115202954Sgonzo 116202027Simp /* Initialize pcpu stuff */ 117202027Simp mips_pcpu0_init(); 118202027Simp 119178173Simp /* 120178173Simp * Looking for mem=XXM argument 121178173Simp */ 122178173Simp mem = 0; /* Just something to start with */ 123178173Simp for (i=0; i < argc; i++) { 124178173Simp if (strncmp(argv[i], "mem=", 4) == 0) { 125178173Simp mem = strtol(argv[i] + 4, NULL, 0); 126178173Simp break; 127178173Simp } 128178173Simp } 129178173Simp 130178173Simp bootverbose = 1; 131178173Simp if (mem > 0) 132178173Simp realmem = btoc(mem << 20); 133178173Simp else 134178173Simp realmem = btoc(32 << 20); 135178173Simp 136178173Simp for (i = 0; i < 10; i++) { 137178173Simp phys_avail[i] = 0; 138178173Simp } 139178173Simp 140178173Simp /* phys_avail regions are in bytes */ 141202954Sgonzo phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); 142178173Simp phys_avail[1] = ctob(realmem); 143178173Simp 144216318Sgonzo dump_avail[0] = phys_avail[0]; 145216320Sgonzo dump_avail[1] = phys_avail[1]; 146216318Sgonzo 147178173Simp physmem = realmem; 148178173Simp 149178173Simp /* 150178173Simp * ns8250 uart code uses DELAY so ticker should be inititalized 151178173Simp * before cninit. And tick_init_params refers to hz, so * init_param1 152178173Simp * should be called first. 153178173Simp */ 154178173Simp init_param1(); 155178173Simp /* TODO: parse argc,argv */ 156178173Simp platform_counter_freq = 330000000UL; 157178173Simp mips_timer_init_params(platform_counter_freq, 1); 158178173Simp cninit(); 159178173Simp /* Panic here, after cninit */ 160178173Simp if (mem == 0) 161178173Simp panic("No mem=XX parameter in arguments"); 162178173Simp 163178173Simp printf("cmd line: "); 164178173Simp for (i=0; i < argc; i++) 165178173Simp printf("%s ", argv[i]); 166178173Simp printf("\n"); 167178173Simp 168178173Simp init_param2(physmem); 169178173Simp mips_cpu_init(); 170178173Simp pmap_bootstrap(); 171178173Simp mips_proc0_init(); 172178173Simp mutex_init(); 173178173Simp kdb_init(); 174202849Simp#ifdef KDB 175202849Simp if (boothowto & RB_KDB) 176202849Simp kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 177178173Simp#endif 178178173Simp} 179