📄 ppc_machdep.c
字号:
/* $Id: ppc_machdep.c,v 1.1.1.3 2003/03/18 22:34:31 anoncvs Exp $ *//* * Copyright (c) 2000 Opsycon AB (www.opsycon.se) * Copyright (c) 2000 Rtmx, Inc (www.rtmx.com) * * 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 for Rtmx, Inc by * Opsycon Open System Consulting 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 <machine/cpu.h>#include <machine/pio.h>#include <machine/intr.h>#include <dev/pci/pcivar.h>#include <include/palomarii.h>#include <pmon/dev/cpc700.h>#include <pmon.h>struct bat battable[16]; /* Translation table, PMON */extern u_int8_t etext[];extern u_int8_t edata[];extern u_int8_t end[];extern int trapcode, trapsize;extern int isitrap, isisize;extern int dsitrap, dsisize;extern int memorysize;char hwethadr[6] = {0x00, 0xa0, 0xf7, 0x10, 0x20, 0x30};static int clkenable;static unsigned long clkpertick;static unsigned long clkperusec;static unsigned long _softcompare;void initppc __P((int));int copytoram __P((void *, void *));extern void tgt_rtinit(void);extern void configure(void);extern void config_init(void);intcopytoram(void *rom, void *ram){ u_int32_t *rdata, *pdata; u_int count; /* * Copy ROM to RAM memory. */ pdata = (u_int32_t *)rom; rdata = (u_int32_t *)ram; count = (int)end - (int)ram; while(count > 0) { *rdata++ = *pdata++; count -= 4; } /* * Verify copy ROM to RAM memory. */ pdata = (u_int32_t *)rom; rdata = (u_int32_t *)ram; count = (int)end - (int)ram; while(count > 0) { if(*rdata++ != *pdata++) { break; } count -= 4; } if(count > 0) { /* Copy failed */ return(1); } /* * Clear BSS. */ rdata = (u_int32_t *)edata; count = (end - edata) / 4; while(count--) { *rdata++ = 0; } return(0);}voidinitppc(msize) int msize;{ int i, exc, scratch; memorysize = msize; /* * Set up an initial mapping using BAT registers. * First clear all to avoid any old setting overlap. */ __asm__ volatile ("mtibatu 0,%0" :: "r"(0)); __asm__ volatile ("mtibatu 1,%0" :: "r"(0)); __asm__ volatile ("mtibatu 2,%0" :: "r"(0)); __asm__ volatile ("mtibatu 3,%0" :: "r"(0)); __asm__ volatile ("mtdbatu 0,%0" :: "r"(0)); __asm__ volatile ("mtdbatu 1,%0" :: "r"(0)); __asm__ volatile ("mtdbatu 2,%0" :: "r"(0)); __asm__ volatile ("mtdbatu 3,%0" :: "r"(0)); /* * IBAT0 and DBAT0 points at first 256Mb of RAM. */ __asm__ volatile ("mtibatl 0,%0; mtibatu 0,%1" :: "r"(BATL(0x00000000, BAT_M)), "r"(BATU(0x00000000, BAT_256M))); __asm__ volatile ("mtdbatl 0,%0; mtdbatu 0,%1" :: "r"(BATL(0x00000000, BAT_M)), "r"(BATU(0x00000000, BAT_256M))); /* * Then map ISA/PCI I/O space and PCI Mem space. */ __asm__ volatile ("mtdbatl 1,%0; mtdbatu 1,%1" :: "r"(BATL(CPC700_PCI_MEM_BASE, BAT_I)), "r"(BATU(CPC700_PCI_MEM_BASE, BAT_256M))); __asm__ volatile ("mtdbatl 2,%0; mtdbatu 2,%1" :: "r"(BATL(PLD_IO_BASE, BAT_I)), "r"(BATU(PLD_IO_BASE, BAT_4M)));/*XXX*/ __asm__ volatile ("mtdbatl 3,%0; mtdbatu 3,%1" :: "r"(BATL(0xf0000000, BAT_I)), "r"(BATU(0xf0000000, BAT_256M))); savebat(&trapbat); /* * Set up bat table for linear mapping of entire space. */ for(i = 0; i < 16; i++) { battable[i].batu = BATU(i << 28, BAT_256M); battable[i].batl = BATL(i << 28, BAT_M); } /* * Set up trap vectors */ for (exc = EX_BEGIN; exc <= EX_END; exc += 0x100) { switch(exc) { case EX_DSI: bcopy((void *)&dsitrap, (void *)exc, (size_t)&dsisize); break; case EX_ISI: bcopy((void *)&isitrap, (void *)exc, (size_t)&isisize); break; default: bcopy((void *)&trapcode, (void *)exc, (size_t)&trapsize); break; } } syncicache((void *)EX_BEGIN, EX_END + 0x100 - EX_BEGIN); /* * Now turn on translation. */ __asm__ volatile ("eieio; mfmsr %0; ori %0,%0,%1; mtmsr %0; sync;isync" : "=r"(scratch) : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI)); /* * Init Real-Time Clock */ tgt_rtinit(); /* * Probe clock frequencys so delays will work properly. */ tgt_cpufreq(); /* * Init PMON and debug */ dbginit(NULL); /* * Launch! */ main();}/* * Put all machine dependent initialization here. This call * is done after console has been initialized so it's safe * to output configuration and debug information with printf. */voidtgt_devconfig(){ _pci_devinit(1); /* PCI device initialization */ config_init(); configure();}voidtgt_devinit(){ _pci_businit(1); /* PCI bus initialization */}/* * 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 = get_count(); 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_cpufreq () / 4; /* 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 = get_count() + clkpertick; clkenable = 0;}voidenablertclock(){ clkenable = 1;}voidtgt_clkpoll (){ struct clockframe cframe; unsigned long count; long cycles, ticks; if (!clkenable) { return; } cframe.srr1 = 0; cframe.srr0 = 0; cframe.pri = 7; cframe.depth = 0; /* poll the free-running clock */ count = get_count (); 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 = get_count() - _softcompare; while (cycles > 0) { _softcompare += clkpertick; ticks++; cycles = get_count() - _softcompare; } while(ticks--) { hardclock(&cframe); } }}voidcpu_initclocks(){ printf("cpu_initclocks\n");}voidtgt_machreset(){ tgt_netreset();}voidtgt_reboot(){ outb(PALOMAR_WD_TIME, 1); outb(PALOMAR_WD_TIME + 1, 1); outb(PALOMAR_CNTL_SET, PALOMAR_BIT_EN_WD); while(1);}voiddelay(microseconds) unsigned int microseconds;{ int total, start;#if 1 start = get_count(); total = microseconds * clkperusec; while(total > (get_count() - start));#else total = microseconds * 200; loopNinstr(total);#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -