📄 syslib.c
字号:
* example, 1.1/0. BSP_REV is concatenated to BSP_VERSION and returned.** RETURNS: A pointer to the BSP version/revision string.*/char * sysBspRev (void) { return (BSP_VERSION BSP_REV); }/********************************************************************************* sysHwInit - initialize the system hardware** This routine initializes various features of the i386/i486 board.* It is called from usrInit() in usrConfig.c.** NOTE: This routine should not be called directly by the user application.** RETURNS: N/A*/void sysHwInit (void) { PHYS_MEM_DESC *pMmu; int ix = 0;#if (CPU == PENTIUM) /* enable MTRR (Memory Type Range Registers) */ if ((sysCpuId.feature & CPUID_MTRR) == CPUID_MTRR) { pentiumMtrrDisable (); /* disable MTRR */#ifdef INCLUDE_MTRR_GET (void) pentiumMtrrGet (&sysMtrr); /* get MTRR initialized by BIOS */#else (void) pentiumMtrrSet (&sysMtrr); /* set your own MTRR */#endif /* INCLUDE_MTRR_GET */ pentiumMtrrEnable (); /* enable MTRR */ }#ifdef INCLUDE_PMC /* enable PMC (Performance Monitoring Counters) */ if ((sysProcessor == X86CPU_PENTIUMPRO) && ((sysCpuId.feature & CPUID_MSR) == CPUID_MSR)) { pentiumPmcStop (); /* stop PMC0 and PMC1 */ pentiumPmcReset (); /* reset PMC0 and PMC1 */ /* * select events of your interest, such as: * PMC_HW_INT_RX - number of hardware interrupts received * PMC_MISALIGN_MEM_REF - number of misaligned data memory references */ (void) pentiumPmcStart (PMC_EN | PMC_OS | PMC_UMASK_00 | PMC_HW_INT_RX, PMC_EN | PMC_OS | PMC_UMASK_00 | PMC_MISALIGN_MEM_REF); }#endif /* INCLUDE_PMC */ /* enable MCA (Machine Check Architecture) */ if ((sysCpuId.feature & CPUID_MCE) == CPUID_MCE) {#ifdef INCLUDE_SHOW_ROUTINES IMPORT FUNCPTR excMcaInfoShow; /* * if excMcaInfoShow is not NULL, it is called in the default * exception handler when Machine Check Exception happened */ excMcaInfoShow = (FUNCPTR) pentiumMcaShow;#endif /* INCLUDE_SHOW_ROUTINES */ if ((sysCpuId.feature & CPUID_MCA) == CPUID_MCA) { UINT32 zero[2] = {0x00000000,0x00000000}; UINT32 one[2] = {0xffffffff,0xffffffff}; UINT32 cap[2]; int mcaBanks; int ix; /* enable all MCA features if MCG_CTL register is present */ pentiumMsrGet (MSR_MCG_CAP, (long long int *)&cap); if (cap[0] & MCG_CTL_P) pentiumMsrSet (MSR_MCG_CTL, (long long int *)&one); mcaBanks = cap[0] & MCG_COUNT; /* get number of banks */ /* enable logging of all errors except for the MC0_CTL register */ for (ix = 1; ix < mcaBanks; ix++) pentiumMsrSet (MSR_MC0_CTL+(ix * 4), (long long int *)&one); /* clear all errors */ for (ix = 0; ix < mcaBanks; ix++) pentiumMsrSet (MSR_MC0_STATUS+(ix * 4), (long long int *)&zero); } pentiumCr4Set (pentiumCr4Get () | CR4_MCE); /* enable MC exception */ }#endif /* (CPU == PENTIUM) */ /* initialize the number of active mappings (sysPhysMemDescNumEnt) */ pMmu = &sysPhysMemDesc[0]; for (ix = 0; ix < NELEMENTS (sysPhysMemDesc); ix++) if (pMmu->virtualAddr != (void *)DUMMY_VIRT_ADDR) pMmu++; else break; sysPhysMemDescNumEnt = ix; /* initialize the PIC (Programmable Interrupt Controller) */ sysIntInitPIC (); intEoiGet = sysIntEoiGet; /* function pointer used in intConnect () */ /* initialize PCI and related devices */#ifdef INCLUDE_PCI pciConfigLibInit (PCI_MECHANISM_1, PCI_CONFIG_ADDR, PCI_CONFIG_DATA, NONE); pciIntLibInit (); /* * PCI-to-PCI bridge initialization should be done here, if it is. * It is not necessary for Intel 430HX PCISET, which splits * the extended memory area as follows: * - Flash BIOS area from 4GByte to (4GB - 512KB) * - DRAM memory from 1MB to a maximum of 512MB * - PCI memory space from the top of DRAM to (4GB - 512KB) */#if defined (INCLUDE_FEI) || defined (INCLUDE_FEI_END) sys557PciInit ();#endif /* INCLUDE_FEI || INCLUDE_FEI_END */#ifdef INCLUDE_LN_97X_END sysLan97xPciInit ();#endif /* INCLUDE_LN_97X_END */#ifdef INCLUDE_EL_3C90X_END sysEl3c90xPciInit ();#endif /* INCLUDE_EL_3C90X_END */#ifdef INCLUDE_SCSI#ifdef INCLUDE_AIC_7880 sysAic7880PciInit ();#endif /* INCLUDE_AIC_7880 */#endif /* INCLUDE_SCSI */#endif /* INCLUDE_PCI */ /* initializes the serial devices */ sysSerialHwInit (); /* initialize serial data structure */ }/********************************************************************************* sysHwInit2 - additional system configuration and initialization** This routine connects system interrupts and does any additional* configuration necessary.** RETURNS: N/A*/void sysHwInit2 (void) {#if defined (INCLUDE_ADD_BOOTMEM) /* * We memAddToPool some upper memory into any low memory * x86 "rom" images pool. The x86 low memory images reside * from 0x8000 to 0xa0000. By memAddToPool'ing some upper * memory here, we allow devices a larger pool to swim within. * (SPR#21338). This is no longer performed in bootConfig.c */#if (ADDED_BOOTMEM_SIZE != 0x0) /* * if &end (compiler symbol) is in lower memory, then we assume * this is a low memory image, and add some upper memory to the pool. */ if ((int)&end < 0x100000) { /* Only do this if there is enough memory. Default is 4MB min. */ if ((int)memTopPhys >= (0x00200000 + ADDED_BOOTMEM_SIZE)) { memAddToPool ((char *)memTopPhys - ADDED_BOOTMEM_SIZE, ADDED_BOOTMEM_SIZE); } }#endif /* (ADDED_BOOTMEM_SIZE !=0) */#endif /* INCLUDE_ADD_BOOTMEM defined */ /* connect sys clock interrupt and auxiliary clock interrupt*/#ifdef INCLUDE_APIC_TIMER (void)intConnect (INUM_TO_IVEC (TIMER_INT_VEC), sysClkInt, 0);#ifdef PIT0_FOR_AUX (void)intConnect (INUM_TO_IVEC (PIT0_INT_VEC), sysAuxClkInt, 0);#else (void)intConnect (INUM_TO_IVEC (RTC_INT_VEC), sysAuxClkInt, 0);#endif /* PIT0_FOR_AUX */#else (void)intConnect (INUM_TO_IVEC (PIT0_INT_VEC), sysClkInt, 0); (void)intConnect (INUM_TO_IVEC (RTC_INT_VEC), sysAuxClkInt, 0);#endif /* INCLUDE_APIC_TIMER */ /* connect serial interrupt */ sysSerialHwInit2(); /* connect stray(spurious/phantom) interrupt */ #if defined(VIRTUAL_WIRE_MODE) (void)intConnect (INUM_TO_IVEC (SPURIOUS_INT_VEC), sysStrayInt, 0); (void)intConnect (INUM_TO_IVEC (LPT_INT_VEC), sysStrayInt, 0);#elif defined(SYMMETRIC_IO_MODE) (void)intConnect (INUM_TO_IVEC (SPURIOUS_INT_VEC), sysStrayInt, 0);#else (void)intConnect (INUM_TO_IVEC (LPT_INT_VEC), sysStrayInt, 0);#endif /* defined(VIRTUAL_WIRE_MODE) */#ifdef INCLUDE_PC_CONSOLE /* connect keyboard Controller 8042 chip interrupt */ (void) intConnect (INUM_TO_IVEC (KBD_INT_VEC), kbdIntr, 0);#endif /* INCLUDE_PC_CONSOLE */ }/********************************************************************************* sysPhysMemTop - get the address of the top of physical memory** This routine returns the address of the first missing byte of memory,* which indicates the top of physical memory.** Memory probing begins at the end of BSS; at every 4K boundary a byte* is read until it finds one that cannot be read, or 4MB have been probed,* whichever is first.** RETURNS: The address of the top of physical memory.** INTERNAL* This routine is used by sysHwInit() to differentiate between models.* It is highly questionable whether vxMemProbe() can be used during the* initial stage of booting.*/char *sysPhysMemTop (void) {#define TEST_PATTERN 0x12345678#define SYS_PAGE_SIZE 0x10000#define N_TIMES 3 static char *memTop = NULL; /* top of memory */ int delta = SYS_PAGE_SIZE; BOOL found = FALSE; PHYS_MEM_DESC *pMmu; int temp[N_TIMES]; char gdtr[6]; char *p; int ix; if (memTop != NULL) return (memTop); /* if (&end) is in upper memory, we assume it is VxWorks image. * if not, it is Boot image */ if ((int)&end > 0x100000) p = (char *)(((int)&end + (delta - 1)) & (~ (delta - 1))); else p = (char *)0x100000; /* find out the actual size of the memory (max 1GB) */ for (; (int)p < 0x40000000; p += delta) { for (ix=0; ix<N_TIMES; ix++) /* save and write */ { temp[ix] = *((int *)p + ix); *((int *)p + ix) = TEST_PATTERN; } cacheFlush (DATA_CACHE, p, 4 * sizeof(int)); /* for 486, Pentium */ if (*(int *)p != TEST_PATTERN) /* compare */ { p -= delta; delta /= 2; /* make delta half */ if (delta <= 0) /* exit if delta is 0 */ { /* page aligned addr */ memTop = (char *)((int)p & ~(VM_PAGE_SIZE - 1)); found = TRUE; break; } } for (ix=0; ix<N_TIMES; ix++) /* restore */ *((int *)p + ix) = temp[ix]; } if (!found) /* we are fooled by write-back external cache */ memTop = (char *)(LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE); /* copy the global descriptor table from RAM/ROM to RAM */ bcopy ((char *)sysGdt, (char *)pSysGdt, GDT_ENTRIES * sizeof(GDT)); *(short *)&gdtr[0] = GDT_ENTRIES * sizeof(GDT) - 1; *(int *)&gdtr[2] = (int)pSysGdt;/* * We assume that there are no memory mapped IO addresses * above the "memTop" if INCLUDE_PCI is not defined. * Thus we set the "limit" to get the General Protection Fault * when the memory above the "memTop" is accessed. */#ifndef INCLUDE_PCI { GDT *pGdt = pSysGdt; int limit = (((int)memTop) / 0x1000 - 1); for (ix=1; ix < GDT_ENTRIES; ix++) { pGdt++; pGdt->limit00 = limit & 0x0ffff; pGdt->limit01 = ((limit & 0xf0000) >> 16) | (pGdt->limit01 & 0xf0); } }#endif /* INCLUDE_PCI */ /* load the global descriptor table. set the MMU table */ sysLoadGdt (gdtr);#if (VM_PAGE_SIZE == PAGE_SIZE_4KB) pMmu = &sysPhysMemDesc[3]; /* 4th entry: above 1.5MB upper memory */ pMmu->len = (UINT)memTop - (UINT)pMmu->physicalAddr;#else /* (VM_PAGE_SIZE == PAGE_SIZE_4KB) */ pMmu = &sysPhysMemDesc[1]; /* 2nd entry: above 4MB upper memory */ pMmu->len = (UINT)memTop - (UINT)pMmu->physicalAddr;#endif /* (VM_PAGE_SIZE == PAGE_SIZE_4KB) */ memTopPhys = memTop; /* set the real memory size */ return (memTop); }/********************************************************************************* sysMemTop - get the address of the top of VxWorks memory** This routine returns a pointer to the first byte of memory not* controlled or used by VxWorks.** The user can reserve memory space by defining the macro USER_RESERVED_MEM* in config.h. This routine returns the address of the reserved memory* area. The value of USER_RESERVED_MEM is in bytes.** RETURNS: The address of the top of VxWorks memory.*/char * sysMemTop (void) { static char * memTop = NULL; if (memTop == NULL) { memTop = sysPhysMemTop () - USER_RESERVED_MEM; if ((int)&end < 0x100000) /* this is for bootrom */ memTop = (char *)0xa0000; } return (memTop); }/********************************************************************************* sysToMonitor - transfer control to the ROM monitor** This routine transfers control to the ROM monitor. It is usually called* only by reboot() -- which services ^X -- and by bus errors at interrupt* level. However, in some circumstances, the user may wish to introduce a* new <startType> to enable special boot ROM facilities.** RETURNS: Does not return.*/STATUS sysToMonitor ( int startType /* passed to ROM to tell it how to boot */ ) { FUNCPTR pEntry; int ix; int iy; int iz; char buf[ROM_SIGNATURE_SIZE]; short *pSrc; short *pDst; VM_ENABLE (FALSE); /* disbale MMU */ /* decide a destination RAM address and the entry point */ if ((int)&end > 0x100000) { pDst = (short *)RAM_HIGH_ADRS; /* copy it in lower mem */ pEntry = (FUNCPTR)(RAM_HIGH_ADRS + ROM_WARM_HIGH); } else { pDst = (short *)RAM_LOW_ADRS; /* copy it in upper mem */ pEntry = (FUNCPTR)(RAM_LOW_ADRS + ROM_WARM_LOW); } /* disable 16-bit memory access */#ifdef INCLUDE_ULTRA sysOutByte (IO_ADRS_ULTRA + 4, sysInByte (IO_ADRS_ULTRA + 4) | 0x80); sysOutByte (IO_ADRS_ULTRA + 5, sysInByte (IO_ADRS_ULTRA + 5) & ~0x80);#endif /* INCLUDE_ULTRA */#ifdef INCLUDE_ELC sysOutByte (IO_ADRS_ELC + 5, sysInByte (IO_ADRS_ELC + 5) & ~0x80);#endif /* INCLUDE_ELC */ /* copy EPROM to RAM and jump, if there is a VxWorks EPROM */ for (ix = 0; ix < NELEMENTS(sysRomBase); ix++) { bcopyBytes ((char *)sysRomBase[ix], buf, ROM_SIGNATURE_SIZE); if (strncmp (sysRomSignature, buf, ROM_SIGNATURE_SIZE) == 0) { for (iy = 0; iy < 1024; iy++) { *sysRomBase[ix] = iy; /* map the moveable window */ pSrc = (short *)((int)sysRomBase[ix] + 0x200); for (iz = 0; iz < 256; iz++) *pDst++ = *pSrc++; } sysClkDisable (); /* disable the system clock interrupt */ sysIntInitPIC (); /* reset the used interrupt controllers */ (*pEntry) (startType); } }#ifdef INCLUDE_FD if (sysWarmType == SYS_WARM_FD) { IMPORT int dosFsDrvNum; fdDrv (FD_INT_VEC, FD_INT_LVL); /* initialize floppy disk */ if (dosFsDrvNum == ERROR) dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ if (usrFdConfig (sysWarmFdDrive, sysWarmFdType, "/vxboot/") == ERROR) { printErr ("usrFdConfig failed.\n"); return (ERROR); } }#endif /* INCLUDE_FD */#ifdef INCLUDE_ATA if (sysWarmType == SYS_WARM_ATA) { ATA_RESOURCE *pAtaResource = &ataResources[sysWarmAtaCtrl]; IMPORT int dosFsDrvNum; if (ataDrv (sysWarmAtaCtrl, pAtaResource->drives, pAtaResource->intVector, pAtaResource->intLevel, pAtaResource->configType, pAtaResource->semTimeout, pAtaResource->wdgTimeout) == ERROR) /* initialize ATA/IDE disk */ { printErr ("Could not initialize.\n"); return (ERROR); } if (dosFsDrvNum == ERROR) dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ if (usrAtaConfig (sysWarmAtaCtrl, sysWarmAtaDrive, "/vxboot/") == ERROR) { printErr ("usrAtaConfig failed.\n"); return (ERROR); } }#endif /* INCLUDE_ATA */#ifdef INCLUDE_TFFS if (sysWarmType == SYS_WARM_TFFS) { IMPORT int dosFsDrvNum; tffsDrv (); /* initialize TFFS */ if (dosFsDrvNum == ERROR)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -