machdep.c revision 1.74
11.74Sdyoung/* $NetBSD: machdep.c,v 1.74 2011/07/19 15:44:52 dyoung 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.74Sdyoung__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.74 2011/07/19 15:44:52 dyoung 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.74Sdyoung#include <sys/bus.h> 861.1Sitojun 871.37Such#include <uvm/uvm_extern.h> 881.1Sitojun 891.1Sitojun#include <dev/cons.h> 901.40Such 911.37Such#include <sh3/bscreg.h> 921.33Such#include <sh3/cpgreg.h> 931.33Such#include <sh3/cache_sh3.h> 941.40Such#include <sh3/cache_sh4.h> 951.40Such#include <sh3/exception.h> 961.40Such 971.40Such#include <machine/intr.h> 981.73She#include <machine/pcb.h> 991.40Such 1001.40Such#ifdef DDB 1011.40Such#include <machine/db_machdep.h> 1021.40Such#include <ddb/db_extern.h> 1031.40Such#endif 1041.1Sitojun 1051.71Snonaka#ifdef KLOADER 1061.71Snonaka#include <machine/kloader.h> 1071.71Snonaka#endif 1081.71Snonaka 1091.46Sragge#include "ksyms.h" 1101.46Sragge 1111.1Sitojun/* the following is used externally (sysctl_hw) */ 1121.37Suchchar machine[] = MACHINE; /* evbsh3 */ 1131.37Suchchar machine_arch[] = MACHINE_ARCH; /* sh3eb or sh3el */ 1141.1Sitojun 1151.71Snonaka#ifdef KLOADER 1161.71Snonakastruct kloader_bootinfo kbootinfo; 1171.71Snonaka#endif 1181.71Snonaka 1191.64Sdslvoid initSH3(void *); 1201.64Sdslvoid LoadAndReset(const char *); 1211.64Sdslvoid XLoadAndReset(char *); 1221.1Sitojun 1231.1Sitojun/* 1241.1Sitojun * Machine-dependent startup code 1251.1Sitojun * 1261.1Sitojun * This is called from main() in kern/main.c. 1271.1Sitojun */ 1281.1Sitojunvoid 1291.67Sceggercpu_startup(void) 1301.1Sitojun{ 1311.1Sitojun 1321.39Such sh_startup(); 1331.1Sitojun} 1341.1Sitojun 1351.1Sitojun/* 1361.1Sitojun * machine dependent system variables. 1371.1Sitojun */ 1381.49Satatatstatic int 1391.49Satatatsysctl_machdep_loadandreset(SYSCTLFN_ARGS) 1401.1Sitojun{ 1411.54She const char *osimage; 1421.49Satatat int error; 1431.1Sitojun 1441.54She error = sysctl_lookup(SYSCTLFN_CALL(__UNCONST(rnode))); 1451.49Satatat if (error || newp == NULL) 1461.49Satatat return (error); 1471.49Satatat 1481.54She osimage = (const char *)(*(const u_long *)newp); 1491.49Satatat LoadAndReset(osimage); 1501.49Satatat /* not reach here */ 1511.49Satatat return (0); 1521.49Satatat} 1531.49Satatat 1541.49SatatatSYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") 1551.49Satatat{ 1561.49Satatat 1571.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1581.51Satatat CTLFLAG_PERMANENT, 1591.49Satatat CTLTYPE_NODE, "machdep", NULL, 1601.49Satatat NULL, 0, NULL, 0, 1611.49Satatat CTL_MACHDEP, CTL_EOL); 1621.49Satatat 1631.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1641.51Satatat CTLFLAG_PERMANENT, 1651.49Satatat CTLTYPE_STRUCT, "console_device", NULL, 1661.49Satatat sysctl_consdev, 0, NULL, sizeof(dev_t), 1671.49Satatat CTL_MACHDEP, CPU_CONSDEV, CTL_EOL); 1681.49Satatat/* 1691.49Satatat<atatat> okay...your turn to play. 1701.49Satatat<atatat> pick a number. 1711.49Satatat<kjk> 98752. 1721.49Satatat*/ 1731.51Satatat sysctl_createv(clog, 0, NULL, NULL, 1741.51Satatat CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE, 1751.49Satatat CTLTYPE_INT, "load_and_reset", NULL, 1761.49Satatat sysctl_machdep_loadandreset, 98752, NULL, 0, 1771.49Satatat CTL_MACHDEP, CPU_LOADANDRESET, CTL_EOL); 1781.1Sitojun} 1791.1Sitojun 1801.1Sitojunvoid 1811.65Sdslcpu_reboot(int howto, char *bootstr) 1821.1Sitojun{ 1831.37Such static int waittime = -1; 1841.1Sitojun 1851.1Sitojun if (cold) { 1861.1Sitojun howto |= RB_HALT; 1871.1Sitojun goto haltsys; 1881.1Sitojun } 1891.1Sitojun 1901.71Snonaka#ifdef KLOADER 1911.71Snonaka if ((howto & RB_HALT) == 0) { 1921.71Snonaka if ((howto & RB_STRING) && (bootstr != NULL)) { 1931.71Snonaka kloader_reboot_setup(bootstr); 1941.71Snonaka } 1951.71Snonaka#ifdef KLOADER_KERNEL_PATH 1961.71Snonaka else { 1971.71Snonaka kloader_reboot_setup(KLOADER_KERNEL_PATH); 1981.71Snonaka } 1991.71Snonaka#endif 2001.71Snonaka } 2011.71Snonaka#endif 2021.71Snonaka 2031.1Sitojun boothowto = howto; 2041.1Sitojun if ((howto & RB_NOSYNC) == 0 && waittime < 0) { 2051.1Sitojun waittime = 0; 2061.1Sitojun vfs_shutdown(); 2071.1Sitojun /* 2081.1Sitojun * If we've been adjusting the clock, the todr 2091.1Sitojun * will be out of synch; adjust it now. 2101.1Sitojun */ 2111.1Sitojun /* resettodr(); */ 2121.1Sitojun } 2131.1Sitojun 2141.1Sitojun /* Disable interrupts. */ 2151.1Sitojun splhigh(); 2161.1Sitojun 2171.1Sitojun /* Do a dump if requested. */ 2181.1Sitojun if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) 2191.1Sitojun dumpsys(); 2201.1Sitojun 2211.1Sitojunhaltsys: 2221.1Sitojun doshutdownhooks(); 2231.1Sitojun 2241.61Sdyoung pmf_system_shutdown(boothowto); 2251.61Sdyoung 2261.1Sitojun if (howto & RB_HALT) { 2271.1Sitojun printf("\n"); 2281.1Sitojun printf("The operating system has halted.\n"); 2291.1Sitojun printf("Please press any key to reboot.\n\n"); 2301.1Sitojun cngetc(); 2311.1Sitojun } 2321.71Snonaka#ifdef KLOADER 2331.71Snonaka else { 2341.71Snonaka delay(1 * 1000 * 1000); 2351.71Snonaka kloader_reboot(); 2361.71Snonaka printf("\n"); 2371.71Snonaka printf("Failed to load a new kernel.\n"); 2381.71Snonaka printf("Please press any key to reboot.\n\n"); 2391.71Snonaka cngetc(); 2401.71Snonaka } 2411.71Snonaka#endif 2421.1Sitojun 2431.1Sitojun printf("rebooting...\n"); 2441.1Sitojun cpu_reset(); 2451.1Sitojun for(;;) 2461.71Snonaka continue; 2471.1Sitojun /*NOTREACHED*/ 2481.1Sitojun} 2491.1Sitojun 2501.1Sitojunvoid 2511.37SuchinitSH3(void *pc) /* XXX return address */ 2521.1Sitojun{ 2531.57Suebayasi extern char edata[], end[]; 2541.37Such vaddr_t kernend; 2551.3Smsaitoh 2561.37Such /* Clear bss */ 2571.57Suebayasi memset(edata, 0, end - edata); 2581.3Smsaitoh 2591.37Such /* Initilize CPU ops. */ 2601.30Such#if defined(SH3) && defined(SH4) 2611.30Such#error "don't define both SH3 and SH4" 2621.30Such#elif defined(SH3) 2631.40Such#if defined(SH7708) 2641.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708); 2651.40Such#elif defined(SH7708S) 2661.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708S); 2671.40Such#elif defined(SH7708R) 2681.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7708R); 2691.40Such#elif defined(SH7709) 2701.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709); 2711.40Such#elif defined(SH7709A) 2721.40Such sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7709A); 2731.68Snonaka#elif defined(SH7706) 2741.68Snonaka sh_cpu_init(CPU_ARCH_SH3, CPU_PRODUCT_7706); 2751.40Such#else 2761.40Such#error "unsupported SH3 variants" 2771.40Such#endif 2781.30Such#elif defined(SH4) 2791.40Such#if defined(SH7750) 2801.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750); 2811.40Such#elif defined(SH7750S) 2821.40Such sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750S); 2831.68Snonaka#elif defined(SH7750R) 2841.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7750R); 2851.68Snonaka#elif defined(SH7751) 2861.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751); 2871.68Snonaka#elif defined(SH7751R) 2881.68Snonaka sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751R); 2891.40Such#else 2901.40Such#error "unsupported SH4 variants" 2911.40Such#endif 2921.30Such#else 2931.30Such#error "define SH3 or SH4" 2941.30Such#endif 2951.41Such /* Console */ 2961.41Such consinit(); 2971.41Such 2981.71Snonaka#ifdef KLOADER 2991.71Snonaka /* copy boot parameter for kloader */ 3001.71Snonaka kloader_bootinfo_set(&kbootinfo, 0, NULL, NULL, true); 3011.71Snonaka#endif 3021.71Snonaka 3031.41Such /* Load memory to UVM */ 3041.57Suebayasi kernend = atop(round_page(SH3_P1SEG_TO_PHYS(end))); 3051.41Such physmem = atop(IOM_RAM_SIZE); 3061.41Such uvm_page_physload( 3071.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 3081.41Such kernend, atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), 3091.41Such VM_FREELIST_DEFAULT); 3101.40Such 3111.41Such /* Initialize proc0 u-area */ 3121.41Such sh_proc0_init(); 3131.41Such 3141.41Such /* Initialize pmap and start to address translation */ 3151.41Such pmap_bootstrap(); 3161.1Sitojun 3171.68Snonaka /* 3181.3Smsaitoh * XXX We can't return here, because we change stack pointer. 3191.3Smsaitoh * So jump to return address directly. 3201.3Smsaitoh */ 3211.56Sperry __asm volatile ( 3221.37Such "jmp @%0;" 3231.41Such "mov %1, r15" 3241.44Sthorpej :: "r"(pc),"r"(lwp0.l_md.md_pcb->pcb_sf.sf_r7_bank)); 3251.1Sitojun} 3261.1Sitojun 3271.1Sitojun/* 3281.1Sitojun * consinit: 3291.1Sitojun * initialize the system console. 3301.1Sitojun * XXX - shouldn't deal with this initted thing, but then, 3311.1Sitojun * it shouldn't be called from init386 either. 3321.1Sitojun */ 3331.1Sitojunvoid 3341.67Sceggerconsinit(void) 3351.1Sitojun{ 3361.1Sitojun static int initted; 3371.1Sitojun 3381.1Sitojun if (initted) 3391.1Sitojun return; 3401.1Sitojun initted = 1; 3411.1Sitojun 3421.1Sitojun cninit(); 3431.1Sitojun} 3441.1Sitojun 3451.18Smsaitoh#if !defined(DONT_INIT_BSC) 3461.1Sitojun/* 3471.1Sitojun * InitializeBsc 3481.50Swiz * : BSC(Bus State Controller) 3491.1Sitojun */ 3501.64Sdslvoid InitializeBsc(void); 3511.1Sitojun 3521.1Sitojunvoid 3531.67SceggerInitializeBsc(void) 3541.1Sitojun{ 3551.1Sitojun 3561.1Sitojun /* 3571.1Sitojun * Drive RAS,CAS in stand by mode and bus release mode 3581.1Sitojun * Area0 = Normal memory, Area5,6=Normal(no burst) 3591.1Sitojun * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory 3601.1Sitojun * Area4 = Normal Memory 3611.1Sitojun * Area6 = Normal memory 3621.1Sitojun */ 3631.33Such#if defined(SH3) 3641.33Such _reg_write_2(SH3_BCR1, BSC_BCR1_VAL); 3651.33Such#elif defined(SH4) 3661.33Such _reg_write_4(SH4_BCR1, BSC_BCR1_VAL); 3671.33Such#endif 3681.1Sitojun 3691.1Sitojun /* 3701.1Sitojun * Bus Width 3711.1Sitojun * Area4: Bus width = 16bit 3721.1Sitojun * Area6,5 = 16bit 3731.1Sitojun * Area1 = 8bit 3741.1Sitojun * Area2,3: Bus width = 32bit 3751.1Sitojun */ 3761.33Such _reg_write_2(SH_(BCR2), BSC_BCR2_VAL); 3771.1Sitojun 3781.1Sitojun /* 3791.1Sitojun * Idle cycle number in transition area and read to write 3801.1Sitojun * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 3811.1Sitojun * Area1 = 3, Area0 = 3 3821.1Sitojun */ 3831.33Such#if defined(SH3) 3841.33Such _reg_write_2(SH3_WCR1, BSC_WCR1_VAL); 3851.33Such#elif defined(SH4) 3861.33Such _reg_write_4(SH4_WCR1, BSC_WCR1_VAL); 3871.33Such#endif 3881.1Sitojun 3891.1Sitojun /* 3901.1Sitojun * Wait cycle 3911.1Sitojun * Area 6 = 6 3921.1Sitojun * Area 5 = 2 3931.1Sitojun * Area 4 = 10 3941.1Sitojun * Area 3 = 3 3951.1Sitojun * Area 2,1 = 3 3961.1Sitojun * Area 0 = 6 3971.1Sitojun */ 3981.33Such#if defined(SH3) 3991.33Such _reg_write_2(SH3_WCR2, BSC_WCR2_VAL); 4001.33Such#elif defined(SH4) 4011.33Such _reg_write_4(SH4_WCR2, BSC_WCR2_VAL); 4021.33Such#endif 4031.1Sitojun 4041.13Smsaitoh#if defined(SH4) && defined(BSC_WCR3_VAL) 4051.33Such _reg_write_4(SH4_WCR3, BSC_WCR3_VAL); 4061.1Sitojun#endif 4071.1Sitojun 4081.1Sitojun /* 4091.1Sitojun * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, 4101.1Sitojun * write pre-charge=1cycle 4111.1Sitojun * CAS before RAS refresh RAS assert time = 3 cycle 4121.1Sitojun * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON 4131.1Sitojun * CAS before RAS refresh ON, EDO DRAM 4141.1Sitojun */ 4151.33Such#if defined(SH3) 4161.33Such _reg_write_2(SH3_MCR, BSC_MCR_VAL); 4171.33Such#elif defined(SH4) 4181.33Such _reg_write_4(SH4_MCR, BSC_MCR_VAL); 4191.33Such#endif 4201.1Sitojun 4211.11Smsaitoh#if defined(BSC_SDMR2_VAL) 4221.33Such _reg_write_1(BSC_SDMR2_VAL, 0); 4231.11Smsaitoh#endif 4241.11Smsaitoh 4251.11Smsaitoh#if defined(BSC_SDMR3_VAL) 4261.19Smsaitoh#if !(defined(COMPUTEXEVB) && defined(SH7709A)) 4271.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 4281.1Sitojun#else 4291.33Such _reg_write_2(0x1a000000, 0); /* ADDSET */ 4301.33Such _reg_write_1(BSC_SDMR3_VAL, 0); 4311.33Such _reg_write_2(0x18000000, 0); /* ADDRST */ 4321.33Such#endif /* !(COMPUTEXEVB && SH7709A) */ 4331.33Such#endif /* BSC_SDMR3_VAL */ 4341.1Sitojun 4351.1Sitojun /* 4361.1Sitojun * PCMCIA Control Register 4371.1Sitojun * OE/WE assert delay 3.5 cycle 4381.1Sitojun * OE/WE negate-address delay 3.5 cycle 4391.1Sitojun */ 4401.1Sitojun#ifdef BSC_PCR_VAL 4411.33Such _reg_write_2(SH_(PCR), BSC_PCR_VAL); 4421.1Sitojun#endif 4431.1Sitojun 4441.1Sitojun /* 4451.1Sitojun * Refresh Timer Control/Status Register 4461.1Sitojun * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt 4471.1Sitojun * Count Limit = 1024 4481.1Sitojun * In following statement, the reason why high byte = 0xa5(a4 in RFCR) 4491.1Sitojun * is the rule of SH3 in writing these register. 4501.1Sitojun */ 4511.33Such _reg_write_2(SH_(RTCSR), BSC_RTCSR_VAL); 4521.1Sitojun 4531.1Sitojun /* 4541.1Sitojun * Refresh Timer Counter 4551.1Sitojun * Initialize to 0 4561.1Sitojun */ 4571.9Smsaitoh#ifdef BSC_RTCNT_VAL 4581.33Such _reg_write_2(SH_(RTCNT), BSC_RTCNT_VAL); 4591.9Smsaitoh#endif 4601.1Sitojun 4611.1Sitojun /* set Refresh Time Constant Register */ 4621.33Such _reg_write_2(SH_(RTCOR), BSC_RTCOR_VAL); 4631.1Sitojun 4641.1Sitojun /* init Refresh Count Register */ 4651.1Sitojun#ifdef BSC_RFCR_VAL 4661.33Such _reg_write_2(SH_(RFCR), BSC_RFCR_VAL); 4671.1Sitojun#endif 4681.1Sitojun 4691.33Such /* 4701.33Such * Clock Pulse Generator 4711.33Such */ 4721.1Sitojun /* Set Clock mode (make internal clock double speed) */ 4731.33Such _reg_write_2(SH_(FRQCR), FRQCR_VAL); 4741.1Sitojun 4751.33Such /* 4761.33Such * Cache 4771.33Such */ 4781.33Such#ifndef CACHE_DISABLE 4791.1Sitojun /* Cache ON */ 4801.33Such _reg_write_4(SH_(CCR), 0x1); 4811.1Sitojun#endif 4821.1Sitojun} 4831.33Such#endif /* !DONT_INIT_BSC */ 4841.9Smsaitoh 4851.8Smsaitoh 4861.8Smsaitoh /* XXX This value depends on physical available memory */ 4871.8Smsaitoh#define OSIMAGE_BUF_ADDR (IOM_RAM_BEGIN + 0x00400000) 4881.8Smsaitoh 4891.1Sitojunvoid 4901.65SdslLoadAndReset(const char *osimage) 4911.1Sitojun{ 4921.1Sitojun void *buf_addr; 4931.1Sitojun u_long size; 4941.54She const u_long *src; 4951.1Sitojun u_long *dest; 4961.1Sitojun u_long csum = 0; 4971.1Sitojun u_long csum2 = 0; 4981.1Sitojun u_long size2; 4991.1Sitojun 5001.3Smsaitoh printf("LoadAndReset: copy start\n"); 5011.1Sitojun buf_addr = (void *)OSIMAGE_BUF_ADDR; 5021.1Sitojun 5031.54She size = *(const u_long *)osimage; 5041.54She src = (const u_long *)osimage; 5051.1Sitojun dest = buf_addr; 5061.1Sitojun 5071.3Smsaitoh size = (size + sizeof(u_long) * 2 + 3) >> 2; 5081.1Sitojun size2 = size; 5091.1Sitojun 5101.3Smsaitoh while (size--) { 5111.1Sitojun csum += *src; 5121.1Sitojun *dest++ = *src++; 5131.1Sitojun } 5141.1Sitojun 5151.1Sitojun dest = buf_addr; 5161.1Sitojun while (size2--) 5171.1Sitojun csum2 += *dest++; 5181.1Sitojun 5191.3Smsaitoh printf("LoadAndReset: copy end[%lx,%lx]\n", csum, csum2); 5201.1Sitojun printf("start XLoadAndReset\n"); 5211.1Sitojun 5221.1Sitojun /* mask all externel interrupt (XXX) */ 5231.1Sitojun 5241.1Sitojun XLoadAndReset(buf_addr); 5251.40Such} 5261.40Such 5271.40Suchvoid 5281.40Suchintc_intr(int ssr, int spc, int ssp) 5291.40Such{ 5301.40Such struct intc_intrhand *ih; 5311.40Such struct clockframe cf; 5321.40Such int s, evtcode; 5331.40Such 5341.72Smatt curcpu()->ci_data.cpu_nintr++; 5351.72Smatt 5361.40Such switch (cpu_product) { 5371.40Such case CPU_PRODUCT_7708: 5381.40Such case CPU_PRODUCT_7708S: 5391.40Such case CPU_PRODUCT_7708R: 5401.40Such evtcode = _reg_read_4(SH3_INTEVT); 5411.40Such break; 5421.40Such case CPU_PRODUCT_7709: 5431.40Such case CPU_PRODUCT_7709A: 5441.68Snonaka case CPU_PRODUCT_7706: 5451.40Such evtcode = _reg_read_4(SH7709_INTEVT2); 5461.40Such break; 5471.40Such case CPU_PRODUCT_7750: 5481.40Such case CPU_PRODUCT_7750S: 5491.68Snonaka case CPU_PRODUCT_7750R: 5501.68Snonaka case CPU_PRODUCT_7751: 5511.68Snonaka case CPU_PRODUCT_7751R: 5521.40Such evtcode = _reg_read_4(SH4_INTEVT); 5531.40Such break; 5541.52Smatt default: 5551.52Smatt#ifdef DIAGNOSTIC 5561.52Smatt panic("intr_intc: cpu_product %d unhandled!", cpu_product); 5571.52Smatt#endif 5581.52Smatt return; 5591.40Such } 5601.40Such 5611.40Such ih = EVTCODE_IH(evtcode); 5621.40Such KDASSERT(ih->ih_func); 5631.40Such /* 5641.40Such * On entry, all interrrupts are disabled, 5651.40Such * and exception is enabled for P3 access. (kernel stack is P3, 5661.40Such * SH3 may or may not cause TLB miss when access stack.) 5671.40Such * Enable higher level interrupt here. 5681.40Such */ 5691.40Such s = _cpu_intr_resume(ih->ih_level); 5701.40Such 5711.40Such switch (evtcode) { 5721.40Such default: 5731.40Such (*ih->ih_func)(ih->ih_arg); 5741.40Such break; 5751.40Such case SH_INTEVT_TMU0_TUNI0: 5761.40Such cf.spc = spc; 5771.40Such cf.ssr = ssr; 5781.40Such cf.ssp = ssp; 5791.40Such (*ih->ih_func)(&cf); 5801.40Such break; 5811.40Such case SH_INTEVT_NMI: 5821.40Such printf("NMI ignored.\n"); 5831.40Such break; 5841.40Such } 5851.42Such} 586