📄 syslib.c
字号:
* space above <pPage>. */ const UINT32 pageNoUsed = ((UINT32) pPage / pageSize); const UINT32 pageNoTotal = (PHYS_MEM_MAX / pageSize) - pageNoUsed; UINT32 delta = HALF (pageNoTotal); int temp[4]; /* find out the actual size of the memory (up to PHYS_MEM_MAX) */ for (pPage += (pageSize * delta); delta != 0; delta >>= 1) { WRITE_MEMORY_TEST_PATTERN ((int *) pPage, &temp[0]); if (*((int *) pPage) != TEST_PATTERN_A) { /* The test pattern was not written, so assume that <pPage> is the * base address of a page beyond available memory. Test the * next lowest page. If the test pattern is writable there, assume * that <pPage> is the address of the first byte beyond the last * addressable page. */ UINT8 * pPrevPage = (UINT8 *)((UINT32) pPage - pageSize); WRITE_MEMORY_TEST_PATTERN ((int *) pPrevPage, &temp[0]); if (*((int *) pPrevPage) == TEST_PATTERN_A) { RESTORE_MEMORY_TEST_ADDRS ((int *) pPrevPage, &temp[0]); memTopPhys = pPage; found = TRUE; break; } pPage -= (pageSize * HALF (delta)); } else { /* The test pattern was written, so assume that <pPage> is the base * address of a page in available memory. Test the next highest * page. If the test pattern is not writable there, assume that * <pNextPage> is the address of the first byte beyond that last * addressable page. */ UINT8 * pNextPage = (UINT8 *)((UINT32) pPage + pageSize); RESTORE_MEMORY_TEST_ADDRS ((int *) pPage, &temp[0]); WRITE_MEMORY_TEST_PATTERN ((int *) pNextPage, &temp[0]); if (*((int *) pNextPage) != TEST_PATTERN_A) { memTopPhys = pNextPage; found = TRUE; break; } RESTORE_MEMORY_TEST_ADDRS ((int *) pNextPage, &temp[0]); pPage += (pageSize * HALF (delta)); } } }#endif /* LOCAL_MEM_AUTOSIZE */ if (!found) { memTopPhys = (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 "memTopPhys" if INCLUDE_PCI is not defined. * Thus we set the "limit" to get the General Protection Fault * when the memory above the "memTopPhys" is accessed. */#if !defined (INCLUDE_PCI) && \ !defined (INCLUDE_MMU_BASIC) && !defined (INCLUDE_MMU_FULL) { int ix; GDT * pGdt = pSysGdt; int limit = (((UINT32) memTopPhys) >> 12) - 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);#ifdef FAST_REBOOT /* * save the brand new bootrom image that will be protected by MMU. * The last 2 bytes of ROM_SIZE are for the checksum. * - compression would minimize the DRAM usage. * - when restore, jumping to the saved image would be faster. */ memTopPhys -= ROM_SIZE; bcopy ((char *)ROM_BASE_ADRS, memTopPhys, ROM_SIZE); *(UINT16 *)(memTopPhys + ROM_SIZE - 2) = checksum ((UINT16 *)memTopPhys, ROM_SIZE - 2); memRom = memTopPhys; /* remember it */#endif /* FAST_REBOOT */ /* set the MMU descriptor table */ (UINT32)memTopPhys &= ~(VM_PAGE_SIZE - 1); /* VM_PAGE_SIZE aligned */#if (VM_PAGE_SIZE == PAGE_SIZE_4KB) pMmu = &sysPhysMemDesc[4]; /* 5th entry: above 1.5MB upper memory */ pMmu->len = (UINT32) memTopPhys - (UINT32) pMmu->physicalAddr;#else /* (VM_PAGE_SIZE == PAGE_SIZE_4KB) */ pMmu = &sysPhysMemDesc[2]; /* 3rd entry: above 8MB upper memory */ pMmu->len = (UINT32) memTopPhys - (UINT32) pMmu->physicalAddr;#endif /* (VM_PAGE_SIZE == PAGE_SIZE_4KB) */ return (memTopPhys); }/********************************************************************************* 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 ((UINT32)(&end) < 0x100000) /* this is for bootrom */ memTop = (char *)EBDA_START; /* preserve the MP table */ else if ((UINT32)(&end) < RAM_LOW_ADRS) /* bootrom in upper mem */ memTop = (char *)(RAM_LOW_ADRS & 0xfff00000); } 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; INT16 * pDst; VM_ENABLE (FALSE); /* disbale MMU */#if (CPU == PENTIUM) || (CPU == PENTIUM2) || (CPU == PENTIUM3) || \ (CPU == PENTIUM4) pentiumMsrInit (); /* initialize MSRs */#endif /* (CPU == PENTIUM) || (CPU == PENTIUM[234]) */ /* decide a destination RAM address and the entry point */ if ((UINT32)(&end) > RAM_LOW_ADRS) { 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); }#ifdef FAST_REBOOT /* restore the saved brand new bootrom image, then jump */ if ((memRom != NULL) && (*(UINT16 *)(memRom + ROM_SIZE - 2) == checksum ((UINT16 *)memRom, ROM_SIZE - 2))) { INT32 ix; INT32 * dst = (INT32 *) ROM_TEXT_ADRS; INT32 * src = (INT32 *) memRom; pEntry = (FUNCPTR)(ROM_TEXT_ADRS + ROM_WARM_HIGH); for (ix = 0; ix < (ROM_SIZE >> 2); ix++) *dst++ = *src++; goto sysToMonitorJump; }#endif /* FAST_REBOOT */ /* disable 16-bit memory access */#ifdef INCLUDE_ELC sysOutByte (IO_ADRS_ELC + 5, sysInByte (IO_ADRS_ELC + 5) & ~0x80);#endif /* INCLUDE_ELC */#ifdef INCLUDE_ROMCARD { INT32 ix; INT32 iy; INT32 iz; char buf[ROM_SIGNATURE_SIZE]; short *pSrc; /* 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++; } goto sysToMonitorJump; /* jump to the entry point */ } } }#endif /* INCLUDE_ROMCARD */#ifdef INCLUDE_IACSFL { unsigned int * romSize = (unsigned int *)0xffffffe0; unsigned int * dest = (unsigned int *) pDst; unsigned int * src = (unsigned int *) (0 - *romSize); int i = 0; for (i = 0; i < (*romSize >> 2); i++) *dest++ = *src++; goto sysToMonitorJump; }#endif /* INCLUDE_IACSFL */#if (defined(INCLUDE_FD) || defined(INCLUDE_ATA) || defined(INCLUDE_TFFS)) if ((sysWarmType == SYS_WARM_FD) || (sysWarmType == SYS_WARM_ATA) || (sysWarmType == SYS_WARM_TFFS)) { u_char * pChar; /* check to see if device exists, if so don't create it */ if (NULL != dosFsVolDescGet(BOOTROM_DIR, &pChar)) { goto bootDevExists; /* avoid attempt to recreate device */ } }#endif /* defined(INCLUDE_FD) || defined(INCLUDE_ATA) || defined(INCLUDE_TFFS) */#ifdef INCLUDE_FD if (sysWarmType == SYS_WARM_FD) { IMPORT int dosFsDrvNum; fdDrv (INT_NUM_GET (FD_INT_LVL), FD_INT_LVL); /* initialize floppy */ if (dosFsDrvNum == ERROR) dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ if (usrFdConfig (sysWarmFdDrive, sysWarmFdType, BOOTROM_DIR) == 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 (ERROR == usrAtaConfig (sysWarmAtaCtrl, sysWarmAtaDrive, BOOTROM_DIR)) { 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) dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */ if (usrTffsConfig (sysWarmTffsDrive, FALSE, BOOTROM_DIR) == ERROR) { printErr ("usrTffsConfig failed.\n"); return (ERROR); } }#endif /* INCLUDE_TFFS */#if (defined(INCLUDE_FD) || defined(INCLUDE_ATA) || defined(INCLUDE_TFFS))bootDevExists: /* reboot device exists */ if ((sysWarmType == SYS_WARM_FD) || (sysWarmType == SYS_WARM_ATA) || (sysWarmType == SYS_WARM_TFFS)) { int fd; BOOL hasAoutHdr = FALSE; if ((fd = open (BOOTROM_BIN, O_RDONLY, 0644)) == ERROR) { printErr ("Error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -