machdep.c revision 1.71
11.71Snonaka/* $NetBSD: machdep.c,v 1.71 2010/04/06 15:54:30 nonaka Exp $ */ 21.1Sitojun 31.1Sitojun/*- 41.1Sitojun * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 51.1Sitojun * All rights reserved. 61.1Sitojun * 71.1Sitojun * This code is derived from software contributed to The NetBSD Foundation 81.1Sitojun * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace 91.1Sitojun * Simulation Facility, NASA Ames Research Center. 101.1Sitojun * 111.1Sitojun * Redistribution and use in source and binary forms, with or without 121.1Sitojun * modification, are permitted provided that the following conditions 131.1Sitojun * are met: 141.1Sitojun * 1. Redistributions of source code must retain the above copyright 151.1Sitojun * notice, this list of conditions and the following disclaimer. 161.1Sitojun * 2. Redistributions in binary form must reproduce the above copyright 171.1Sitojun * notice, this list of conditions and the following disclaimer in the 181.1Sitojun * documentation and/or other materials provided with the distribution. 191.1Sitojun * 201.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 211.1Sitojun * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 221.1Sitojun * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 231.1Sitojun * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 241.1Sitojun * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 251.1Sitojun * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 261.1Sitojun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 271.1Sitojun * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 281.1Sitojun * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 291.1Sitojun * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 301.1Sitojun * POSSIBILITY OF SUCH DAMAGE. 311.1Sitojun */ 321.1Sitojun 331.1Sitojun/*- 341.1Sitojun * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. 351.1Sitojun * All rights reserved. 361.1Sitojun * 371.1Sitojun * This code is derived from software contributed to Berkeley by 381.1Sitojun * William Jolitz. 391.1Sitojun * 401.1Sitojun * Redistribution and use in source and binary forms, with or without 411.1Sitojun * modification, are permitted provided that the following conditions 421.1Sitojun * are met: 431.1Sitojun * 1. Redistributions of source code must retain the above copyright 441.1Sitojun * notice, this list of conditions and the following disclaimer. 451.1Sitojun * 2. Redistributions in binary form must reproduce the above copyright 461.1Sitojun * notice, this list of conditions and the following disclaimer in the 471.1Sitojun * documentation and/or other materials provided with the distribution. 481.48Sagc * 3. Neither the name of the University nor the names of its contributors 491.1Sitojun * may be used to endorse or promote products derived from this software 501.1Sitojun * without specific prior written permission. 511.1Sitojun * 521.1Sitojun * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 531.1Sitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 541.1Sitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 551.1Sitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 561.1Sitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 571.1Sitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 581.1Sitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 591.1Sitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 601.1Sitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 611.1Sitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 621.1Sitojun * SUCH DAMAGE. 631.1Sitojun * 641.1Sitojun * @(#)machdep.c 7.4 (Berkeley) 6/3/91 651.1Sitojun */ 661.47Slukem 671.47Slukem#include <sys/cdefs.h> 681.71Snonaka__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.71 2010/04/06 15:54:30 nonaka Exp $"); 691.1Sitojun 701.1Sitojun#include "opt_ddb.h" 711.26Slukem#include "opt_kgdb.h" 721.1Sitojun#include "opt_memsize.h" 731.1Sitojun#include "opt_initbsc.h" 741.71Snonaka#include "opt_kloader.h" 751.71Snonaka#include "opt_kloader_kernel_path.h" 761.1Sitojun 771.1Sitojun#include <sys/param.h> 781.1Sitojun#include <sys/systm.h> 791.1Sitojun#include <sys/kernel.h> 801.37Such#include <sys/mount.h> 811.1Sitojun#include <sys/reboot.h> 821.37Such#include <sys/sysctl.h> 831.46Sragge#include <sys/ksyms.h> 841.61Sdyoung#include <sys/device.h> 851.1Sitojun 861.37Such#include <uvm/uvm_extern.h> 871.1Sitojun 881.1Sitojun#include <dev/cons.h> 891.40Such 901.37Such#include <sh3/bscreg.h> 911.33Such#include <sh3/cpgreg.h> 921.33Such#include <sh3/cache_sh3.h> 931.40Such#include <sh3/cache_sh4.h> 941.40Such#include <sh3/exception.h> 951.40Such 961.40Such#include <machine/bus.h> 971.40Such#include <machine/intr.h> 981.40Such 991.40Such#ifdef DDB 1001.40Such#include <machine/db_machdep.h> 1011.40Such#include <ddb/db_extern.h> 1021.40Such#endif 1031.1Sitojun 1041.71Snonaka#ifdef KLOADER 1051.71Snonaka#include <machine/kloader.h> 1061.71Snonaka#endif 1071.71Snonaka 1081.46Sragge#include "ksyms.h" 1091.46Sragge 1101.1Sitojun/* the following is used externally (sysctl_hw) */ 1111.37Suchchar machine[] = MACHINE; /* evbsh3 */ 1121.37Suchchar machine_arch[] = MACHINE_ARCH; /* sh3eb or sh3el */ 1131.1Sitojun 1141.71Snonaka#ifdef KLOADER 1151.71Snonakastruct kloader_bootinfo kbootinfo; 1161.71Snonaka#endif 1171.71Snonaka 1181.64Sdslvoid initSH3(void *); 1191.64Sdslvoid LoadAndReset(const char *); 1201.64Sdslvoid XLoadAndReset(char *); 1211.1Sitojun 1221.1Sitojun/* 1231.1Sitojun * Machine-dependent startup code 1241.1Sitojun * 1251.1Sitojun * This is called from main() in kern/main.c. 1261.1Sitojun */ 1271.1Sitojunvoid 1281.67Sceggercpu_startup(void) 1291.1Sitojun{ 1301.1Sitojun 1311.39Such sh_startup(); 1321.1Sitojun} 1331.1Sitojun 1341.1Sitojun/* 1351.1Sitojun * machine dependent system variables. 1361.1Sitojun */ 1371.49Satatatstatic int 1381.49Satatatsysctl_machdep_loadandreset(SYSCTLFN_ARGS) 1391.1Sitojun{ 1401.54She const char *osimage; 1411.49Satatat int error; 1421.1Sitojun 1431.54She error = sysctl_lookup(SYSCTLFN_CALL(__UNCONST(rnode))); 1441.49Satatat if (error || newp == NULL) 1451.49Satatat return (error); 1461.49Satatat 1471.54She osimage = (const char *)(*(const u_long *)newp); 1481.49Satatat LoadAndReset(osimage); 1491.49Satatat /* not reach here */ 1501.49Satatat return (0); 1511.49Satatat} 1521.49Satatat 1531.49SatatatSYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") 1541.49Satatat{ 1551.49Satatat 1561.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1571.51Satatat CTLFLAG_PERMANENT, 1581.49Satatat CTLTYPE_NODE, "machdep", NULL, 1591.49Satatat NULL, 0, NULL, 0, 1601.49Satatat CTL_MACHDEP, CTL_EOL); 1611.49Satatat 1621.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1631.51Satatat CTLFLAG_PERMANENT, 1641.49Satatat CTLTYPE_STRUCT, "console_device", NULL, 1651.49Satatat sysctl_consdev, 0, NULL, sizeof(dev_t), 1661.49Satatat CTL_MACHDEP, CPU_CONSDEV, CTL_EOL); 1671.49Satatat/* 1681.49Satatat<atatat> okay...your turn to play. 1691.49Satatat<atatat> pick a number. 1701.49Satatat<kjk> 98752. 1711.49Satatat*/ 1721.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1731.51Satatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE, 1741.49Satatat CTLTYPE_INT, "load_and_reset", NULL, 1751.49Satatat sysctl_machdep_loadandreset, 98752, NULL, 0, 1761.49Satatat CTL_MACHDEP, CPU_LOADANDRESET, CTL_EOL); 1771.1Sitojun} 1781.1Sitojun 1791.1Sitojunvoid 1801.65Sdslcpu_reboot(int howto, char *bootstr) 1811.1Sitojun{ 1821.37Such static int waittime = -1; 1831.1Sitojun 1841.1Sitojun if (cold) { 1851.1Sitojun howto |= RB_HALT; 1861.1Sitojun goto haltsys; 1871.1Sitojun } 1881.1Sitojun 1891.71Snonaka#ifdef KLOADER 1901.71Snonaka if ((howto & RB_HALT) == 0) { 1911.71Snonaka if ((howto & RB_STRING) && (bootstr != NULL)) { 1921.71Snonaka kloader_reboot_setup(bootstr); 1931.71Snonaka } 1941.71Snonaka#ifdef KLOADER_KERNEL_PATH 1951.71Snonaka else { 1961.71Snonaka kloader_reboot_setup(KLOADER_KERNEL_PATH); 1971.71Snonaka } 1981.71Snonaka#endif 1991.71Snonaka } 2001.71Snonaka#endif 2011.71Snonaka 2021.1Sitojun boothowto = howto; 2031.1Sitojun if ((howto & RB_NOSYNC) == 0 && waittime < 0) { 2041.1Sitojun waittime = 0; 2051.1Sitojun vfs_shutdown(); 2061.1Sitojun /* 2071.1Sitojun * If we've been adjusting the clock, the todr 2081.1Sitojun * will be out of synch; adjust it now. 2091.1Sitojun */ 2101.1Sitojun /* resettodr(); */ 2111.1Sitojun } 2121.1Sitojun 2131.1Sitojun /* Disable interrupts. */ 2141.1Sitojun splhigh(); 2151.1Sitojun 2161.1Sitojun /* Do a dump if requested. */ 2171.1Sitojun if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 2181.1Sitojun dumpsys(); 2191.1Sitojun 2201.1Sitojunhaltsys: 2211.1Sitojun doshutdownhooks(); 2221.1Sitojun 2231.61Sdyoung pmf_system_shutdown(boothowto); 2241.61Sdyoung 2251.1Sitojun if (howto & RB_HALT) { 2261.1Sitojun printf("\n"); 2271.1Sitojun printf("The operating system has halted.\n"); 2281.1Sitojun printf("Please press any key to reboot.\n\n"); 2291.1Sitojun cngetc(); 2301.1Sitojun } 2311.71Snonaka#ifdef KLOADER 2321.71Snonaka else { 2331.71Snonaka delay(1 * 1000 * 1000); 2341.71Snonaka kloader_reboot(); 2351.71Snonaka printf("\n"); 2361.71Snonaka printf("Failed to load a new kernel.\n"); 2371.71Snonaka printf("Please press any key to reboot.\n\n"); 2381.71Snonaka cngetc(); 2391.71Snonaka } 2401.71Snonaka#endif 2411.1Sitojun 2421.1Sitojun printf("rebooting...\n"); 2431.1Sitojun cpu_reset(); 2441.1Sitojun for(;;) 2451.71Snonaka continue; 2461.1Sitojun /*NOTREACHED*/ 2471.1Sitojun} 2481.1Sitojun 2491.1Sitojunvoid 2501.37SuchinitSH3(void *pc) /* XXX return address */ 2511.1Sitojun{ 2521.57Suebayasi extern char edata[], end[]; 2531.37Such vaddr_t kernend; 2541.3Smsaitoh 2551.37Such /* Clear bss */ 2561.57Suebayasi memset(edata, 0, end - edata); 2571.3Smsaitoh 2581.37Such /* Initilize CPU ops. */ 2591.30Such#if defined(SH3) && defined(SH4) 2601.30Such#error "don't define both SH3 and SH4" 2611.30Such#elif defined(SH3) 2621.40Such#if defined(SH7708) 2631.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708); 2641.40Such#elif defined(SH7708S) 2651.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708S); 2661.40Such#elif defined(SH7708R) 2671.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708R); 2681.40Such#elif defined(SH7709) 2691.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709); 2701.40Such#elif defined(SH7709A) 2711.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); 2721.68Snonaka#elif defined(SH7706) 2731.68Snonaka sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7706); 2741.40Such#else 2751.40Such#error "unsupported SH3 variants" 2761.40Such#endif 2771.30Such#elif defined(SH4) 2781.40Such#if defined(SH7750) 2791.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); 2801.40Such#elif defined(SH7750S) 2811.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750S); 2821.68Snonaka#elif defined(SH7750R) 2831.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750R); 2841.68Snonaka#elif defined(SH7751) 2851.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751); 2861.68Snonaka#elif defined(SH7751R) 2871.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751R); 2881.40Such#else 2891.40Such#error "unsupported SH4 variants" 2901.40Such#endif 2911.30Such#else 2921.30Such#error "define SH3 or SH4" 2931.30Such#endif 2941.41Such /* Console */ 2951.41Such consinit(); 2961.41Such 2971.71Snonaka#ifdef KLOADER 2981.71Snonaka /* copy boot parameter for kloader */ 2991.71Snonaka kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true); 3001.71Snonaka#endif 3011.71Snonaka 3021.41Such /* Load memory to UVM */ 3031.57Suebayasi kernend = atop(round_page(SH3_P1SEG_TO_PHYS(end))); 3041.41Such physmem = atop(IOM_RAM_SIZE); 3051.41Such uvm_page_physload( 3061.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 3071.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 3081.41Such VM_FREELIST_DEFAULT); 3091.40Such 3101.41Such /* Initialize proc0 u-area */ 3111.41Such sh_proc0_init(); 3121.41Such 3131.41Such /* Initialize pmap and start to address translation */ 3141.41Such pmap_bootstrap(); 3151.1Sitojun 3161.68Snonaka /* 3171.3Smsaitoh * XXX We can't return here, because we change stack pointer. 3181.3Smsaitoh * So jump to return address directly. 3191.3Smsaitoh */ 3201.56Sperry __asm volatile ( 3211.37Such "jmp @%0;" 3221.41Such "mov %1, r15" 3231.44Sthorpej :: "r"(pc),"r"(lwp0.l_md.md_pcb->pcb_sf.sf_r7_bank)); 3241.1Sitojun} 3251.1Sitojun 3261.1Sitojun/* 3271.1Sitojun * consinit: 3281.1Sitojun * initialize the system console. 3291.1Sitojun * XXX - shouldn't deal with this initted thing, but then, 3301.1Sitojun * it shouldn't be called from init386 either. 3311.1Sitojun */ 3321.1Sitojunvoid 3331.67Sceggerconsinit(void) 3341.1Sitojun{ 3351.1Sitojun static int initted; 3361.1Sitojun 3371.1Sitojun if (initted) 3381.1Sitojun return; 3391.1Sitojun initted = 1; 3401.1Sitojun 3411.1Sitojun cninit(); 3421.1Sitojun} 3431.1Sitojun 3441.18Smsaitoh#if !defined(DONT_INIT_BSC) 3451.1Sitojun/* 3461.1Sitojun * InitializeBsc 3471.50Swiz * : BSC(Bus State Controller) 3481.1Sitojun */ 3491.64Sdslvoid InitializeBsc(void); 3501.1Sitojun 3511.1Sitojunvoid 3521.67SceggerInitializeBsc(void) 3531.1Sitojun{ 3541.1Sitojun 3551.1Sitojun /* 3561.1Sitojun * Drive RAS,CAS in stand by mode and bus release mode 3571.1Sitojun * Area0 = Normal memory, Area5,6=Normal(no burst) 3581.1Sitojun * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory 3591.1Sitojun * Area4 = Normal Memory 3601.1Sitojun * Area6 = Normal memory 3611.1Sitojun */ 3621.33Such#if defined(SH3) 3631.33Such _reg_write_2(SH3_BCR1, BSC_BCR1_VAL); 3641.33Such#elif defined(SH4) 3651.33Such _reg_write_4(SH4_BCR1, BSC_BCR1_VAL); 3661.33Such#endif 3671.1Sitojun 3681.1Sitojun /* 3691.1Sitojun * Bus Width 3701.1Sitojun * Area4: Bus width = 16bit 3711.1Sitojun * Area6,5 = 16bit 3721.1Sitojun * Area1 = 8bit 3731.1Sitojun * Area2,3: Bus width = 32bit 3741.1Sitojun */ 3751.33Such _reg_write_2(SH_(BCR2), BSC_BCR2_VAL); 3761.1Sitojun 3771.1Sitojun /* 3781.1Sitojun * Idle cycle number in transition area and read to write 3791.1Sitojun * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 3801.1Sitojun * Area1 = 3, Area0 = 3 3811.1Sitojun */ 3821.33Such#if defined(SH3) 3831.33Such _reg_write_2(SH3_WCR1, BSC_WCR1_VAL); 3841.33Such#elif defined(SH4) 3851.33Such _reg_write_4(SH4_WCR1, BSC_WCR1_VAL); 3861.33Such#endif 3871.1Sitojun 3881.1Sitojun /* 3891.1Sitojun * Wait cycle 3901.1Sitojun * Area 6 = 6 3911.1Sitojun * Area 5 = 2 3921.1Sitojun * Area 4 = 10 3931.1Sitojun * Area 3 = 3 3941.1Sitojun * Area 2,1 = 3 3951.1Sitojun * Area 0 = 6 3961.1Sitojun */ 3971.33Such#if defined(SH3) 3981.33Such _reg_write_2(SH3_WCR2, BSC_WCR2_VAL); 3991.33Such#elif defined(SH4) 4001.33Such _reg_write_4(SH4_WCR2, BSC_WCR2_VAL); 4011.33Such#endif 4021.1Sitojun 4031.13Smsaitoh#if defined(SH4) && defined(BSC_WCR3_VAL) 4041.33Such _reg_write_4(SH4_WCR3, BSC_WCR3_VAL); 4051.1Sitojun#endif 4061.1Sitojun 4071.1Sitojun /* 4081.1Sitojun * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, 4091.1Sitojun * write pre-charge=1cycle 4101.1Sitojun * CAS before RAS refresh RAS assert time = 3 cycle 4111.1Sitojun * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON 4121.1Sitojun * CAS before RAS refresh ON, EDO DRAM 4131.1Sitojun */ 4141.33Such#if defined(SH3) 4151.33Such _reg_write_2(SH3_MCR, BSC_MCR_VAL); 4161.33Such#elif defined(SH4) 4171.33Such _reg_write_4(SH4_MCR, BSC_MCR_VAL); 4181.33Such#endif 4191.1Sitojun 4201.11Smsaitoh#if defined(BSC_SDMR2_VAL) 4211.33Such _reg_write_1(BSC_SDMR2_VAL, 0); 4221.11Smsaitoh#endif 4231.11Smsaitoh 4241.11Smsaitoh#if defined(BSC_SDMR3_VAL) 4251.19Smsaitoh#if !(defined(COMPUTEXEVB) && defined(SH7709A)) 4261.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 4271.1Sitojun#else 4281.33Such _reg_write_2(0x1a000000, 0); /* ADDSET */ 4291.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 4301.33Such _reg_write_2(0x18000000, 0); /* ADDRST */ 4311.33Such#endif /* !(COMPUTEXEVB && SH7709A) */ 4321.33Such#endif /* BSC_SDMR3_VAL */ 4331.1Sitojun 4341.1Sitojun /* 4351.1Sitojun * PCMCIA Control Register 4361.1Sitojun * OE/WE assert delay 3.5 cycle 4371.1Sitojun * OE/WE negate-address delay 3.5 cycle 4381.1Sitojun */ 4391.1Sitojun#ifdef BSC_PCR_VAL 4401.33Such _reg_write_2(SH_(PCR), BSC_PCR_VAL); 4411.1Sitojun#endif 4421.1Sitojun 4431.1Sitojun /* 4441.1Sitojun * Refresh Timer Control/Status Register 4451.1Sitojun * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt 4461.1Sitojun * Count Limit = 1024 4471.1Sitojun * In following statement, the reason why high byte = 0xa5(a4 in RFCR) 4481.1Sitojun * is the rule of SH3 in writing these register. 4491.1Sitojun */ 4501.33Such _reg_write_2(SH_(RTCSR), BSC_RTCSR_VAL); 4511.1Sitojun 4521.1Sitojun /* 4531.1Sitojun * Refresh Timer Counter 4541.1Sitojun * Initialize to 0 4551.1Sitojun */ 4561.9Smsaitoh#ifdef BSC_RTCNT_VAL 4571.33Such _reg_write_2(SH_(RTCNT), BSC_RTCNT_VAL); 4581.9Smsaitoh#endif 4591.1Sitojun 4601.1Sitojun /* set Refresh Time Constant Register */ 4611.33Such _reg_write_2(SH_(RTCOR), BSC_RTCOR_VAL); 4621.1Sitojun 4631.1Sitojun /* init Refresh Count Register */ 4641.1Sitojun#ifdef BSC_RFCR_VAL 4651.33Such _reg_write_2(SH_(RFCR), BSC_RFCR_VAL); 4661.1Sitojun#endif 4671.1Sitojun 4681.33Such /* 4691.33Such * Clock Pulse Generator 4701.33Such */ 4711.1Sitojun /* Set Clock mode (make internal clock double speed) */ 4721.33Such _reg_write_2(SH_(FRQCR), FRQCR_VAL); 4731.1Sitojun 4741.33Such /* 4751.33Such * Cache 4761.33Such */ 4771.33Such#ifndef CACHE_DISABLE 4781.1Sitojun /* Cache ON */ 4791.33Such _reg_write_4(SH_(CCR), 0x1); 4801.1Sitojun#endif 4811.1Sitojun} 4821.33Such#endif /* !DONT_INIT_BSC */ 4831.9Smsaitoh 4841.8Smsaitoh 4851.8Smsaitoh /* XXX This value depends on physical available memory */ 4861.8Smsaitoh#define OSIMAGE_BUF_ADDR (IOM_RAM_BEGIN + 0x00400000) 4871.8Smsaitoh 4881.1Sitojunvoid 4891.65SdslLoadAndReset(const char *osimage) 4901.1Sitojun{ 4911.1Sitojun void *buf_addr; 4921.1Sitojun u_long size; 4931.54She const u_long *src; 4941.1Sitojun u_long *dest; 4951.1Sitojun u_long csum = 0; 4961.1Sitojun u_long csum2 = 0; 4971.1Sitojun u_long size2; 4981.1Sitojun 4991.3Smsaitoh printf("LoadAndReset: copy start\n"); 5001.1Sitojun buf_addr = (void *)OSIMAGE_BUF_ADDR; 5011.1Sitojun 5021.54She size = *(const u_long *)osimage; 5031.54She src = (const u_long *)osimage; 5041.1Sitojun dest = buf_addr; 5051.1Sitojun 5061.3Smsaitoh size = (size + sizeof(u_long) * 2 + 3) >> 2; 5071.1Sitojun size2 = size; 5081.1Sitojun 5091.3Smsaitoh while (size--) { 5101.1Sitojun csum += *src; 5111.1Sitojun *dest++ = *src++; 5121.1Sitojun } 5131.1Sitojun 5141.1Sitojun dest = buf_addr; 5151.1Sitojun while (size2--) 5161.1Sitojun csum2 += *dest++; 5171.1Sitojun 5181.3Smsaitoh printf("LoadAndReset: copy end[%lx,%lx]\n", csum, csum2); 5191.1Sitojun printf("start XLoadAndReset\n"); 5201.1Sitojun 5211.1Sitojun /* mask all externel interrupt (XXX) */ 5221.1Sitojun 5231.1Sitojun XLoadAndReset(buf_addr); 5241.40Such} 5251.40Such 5261.40Suchvoid 5271.40Suchintc_intr(int ssr, int spc, int ssp) 5281.40Such{ 5291.40Such struct intc_intrhand *ih; 5301.40Such struct clockframe cf; 5311.40Such int s, evtcode; 5321.40Such 5331.40Such switch (cpu_product) { 5341.40Such case CPU_PRODUCT_7708: 5351.40Such case CPU_PRODUCT_7708S: 5361.40Such case CPU_PRODUCT_7708R: 5371.40Such evtcode = _reg_read_4(SH3_INTEVT); 5381.40Such break; 5391.40Such case CPU_PRODUCT_7709: 5401.40Such case CPU_PRODUCT_7709A: 5411.68Snonaka case CPU_PRODUCT_7706: 5421.40Such evtcode = _reg_read_4(SH7709_INTEVT2); 5431.40Such break; 5441.40Such case CPU_PRODUCT_7750: 5451.40Such case CPU_PRODUCT_7750S: 5461.68Snonaka case CPU_PRODUCT_7750R: 5471.68Snonaka case CPU_PRODUCT_7751: 5481.68Snonaka case CPU_PRODUCT_7751R: 5491.40Such evtcode = _reg_read_4(SH4_INTEVT); 5501.40Such break; 5511.52Smatt default: 5521.52Smatt#ifdef DIAGNOSTIC 5531.52Smatt panic("intr_intc: cpu_product %d unhandled!", cpu_product); 5541.52Smatt#endif 5551.52Smatt return; 5561.40Such } 5571.40Such 5581.40Such ih = EVTCODE_IH(evtcode); 5591.40Such KDASSERT(ih->ih_func); 5601.40Such /* 5611.40Such * On entry, all interrrupts are disabled, 5621.40Such * and exception is enabled for P3 access. (kernel stack is P3, 5631.40Such * SH3 may or may not cause TLB miss when access stack.) 5641.40Such * Enable higher level interrupt here. 5651.40Such */ 5661.40Such s = _cpu_intr_resume(ih->ih_level); 5671.40Such 5681.40Such switch (evtcode) { 5691.40Such default: 5701.40Such (*ih->ih_func)(ih->ih_arg); 5711.40Such break; 5721.40Such case SH_INTEVT_TMU0_TUNI0: 5731.40Such cf.spc = spc; 5741.40Such cf.ssr = ssr; 5751.40Such cf.ssp = ssp; 5761.40Such (*ih->ih_func)(&cf); 5771.40Such break; 5781.40Such case SH_INTEVT_NMI: 5791.40Such printf("NMI ignored.\n"); 5801.40Such break; 5811.40Such } 5821.42Such} 583