⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mips_machdep.c

📁 国产CPU-龙芯(loongson)BIOS源代码
💻 C
字号:
/*	$Id: mips_machdep.c,v 1.1.1.1 2003/11/08 08:41:42 wlin Exp $ *//* * Copyright (c) 2001 Opsycon AB  (www.opsycon.se) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <sys/param.h>#include <sys/kernel.h>#include <sys/syslog.h>#include <sys/systm.h>#include <sys/endian.h>#include <sys/device.h>#include <machine/cpu.h>#include <machine/pio.h>#include <machine/intr.h>#include <dev/pci/pcivar.h>#include <stdlib.h>#include <autoconf.h>#include <pmon.h>extern char end[];extern char edata[];extern int memorysize;extern char MipsException[], MipsExceptionEnd[];char hwethadr[6];static int clkenable;static unsigned long clkpertick;static unsigned long clkperusec;static unsigned long _softcompare;int copytoram __P((void *, void *));void clearbss __P((void));void clearbss(void){	u_int count;	u_int64_t *rdata;	/*	 *  Clear BSS.	 */	rdata = (u_int64_t *)CACHED_TO_UNCACHED(edata);	rdata = (u_int64_t *)edata;	while((int)rdata & (sizeof(*rdata) - 1)) {		*((char *)rdata)++ = 0;	}	count = (end - edata) / sizeof(*rdata);	while(count--) {		*rdata++ = 0;	}}	intcopytoram(void *rom, void *ram){	u_int count;	u_int64_t *rdata, *pdata;	/*	 *  Copy ROM to RAM memory. 	 */	pdata = (u_int64_t *)rom;	rdata = (u_int64_t *)CACHED_TO_UNCACHED(ram);	count = CACHED_TO_PHYS(end) - CACHED_TO_PHYS(ram);	while(count > 0) {		*rdata++ = *pdata++;		count -= sizeof(*rdata);	}	/*	 *  Verify copy ROM to RAM memory. 	 */	pdata = (u_int64_t *)rom;	rdata = (u_int64_t *)CACHED_TO_UNCACHED(ram);	count = CACHED_TO_PHYS(end) - CACHED_TO_PHYS(ram);	while(count > 0) {		if(*rdata++ != *pdata++) {			return((int)rdata - sizeof(*rdata));	/* non zero */		}		count -= sizeof(*rdata);	}	clearbss();	return(0);}/* *  Microtime returns the time that have elapsed since last 'tick'. *  To be able to do that we use the decrementer to figure out *  how much time have elapsed. */voidmicrotime (tvp)	struct timeval *tvp;{static struct timeval lasttime;	unsigned long count;	long cycles;	*tvp = time;	/* work out how far we've progressed since the last "tick" */	count = CPU_GetCOUNT();	cycles = count - (_softcompare - clkpertick);	if (cycles >= 0)		tvp->tv_usec += cycles / clkperusec;	else		log(LOG_INFO, "microtime: cnt=%u cmp=%u\n", count, _softcompare);	if (tvp->tv_usec >= 1000000) {		tvp->tv_sec += tvp->tv_usec / 1000000;		tvp->tv_usec %= 1000000;	}	if (tvp->tv_sec == lasttime.tv_sec &&	    tvp->tv_usec <= lasttime.tv_usec &&	    (tvp->tv_usec = lasttime.tv_usec + 1) > 1000000) {		tvp->tv_sec++;		tvp->tv_usec -= 1000000;	}	lasttime = *tvp;}voidstartrtclock(hz)	int hz;{	unsigned long freq;	freq = tgt_pipefreq() / 2;	/* TB ticker frequency */	/* get initial value of real time clock */	time.tv_sec = tgt_gettime ();	time.tv_usec = 0;	if(time.tv_sec < 0) { /* Bad clock ? */		time.tv_sec = 0;	}	clkpertick = freq / hz;	clkperusec = freq / 1000000;	_softcompare = CPU_GetCOUNT() + clkpertick;	clkenable = 0;	SBD_DISPLAY("RTCL",0);}voidenablertclock(){	clkenable = 1;}voidtgt_clkpoll (){	struct clockframe cframe;	unsigned long count;	long cycles, ticks;	if (!clkenable) {		return;	}	cframe.pc = 0;	cframe.sr = 0;	cframe.cr = 0;	/* poll the free-running clock */	count = CPU_GetCOUNT();	cycles = count - _softcompare;	if (cycles > 0) {		/* as we are polling, we could have missed a number of ticks */		ticks = (cycles / clkpertick) + 1;		_softcompare += ticks * clkpertick;        /* There is a race between reading count and setting compare         * whereby we could set compare to a value "below" the new         * clock value.  Check again to avoid an 80 sec. wait         */		cycles = CPU_GetCOUNT() - _softcompare;		while (cycles > 0) {			_softcompare += clkpertick; ticks++;			cycles = CPU_GetCOUNT() - _softcompare;		}		while(ticks--) {			hardclock(&cframe);		}	}}voidcpu_initclocks(){	printf("cpu_initclocks\n");}voidtgt_machreset(){	tgt_netreset();}voiddelay(microseconds)	int microseconds;{	int total, start;#if 1	start = CPU_GetCOUNT();	total = microseconds * clkperusec;	while(total > (CPU_GetCOUNT() - start));#else	total = microseconds * 200;	loopNinstr(total);#endif}u_int __res_randomid(void);u_int__res_randomid(){extern int ticks;	return(ticks * CPU_GetCOUNT());    /* Just something... */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -