📄 init.c
字号:
//
// Copyright(C) Renesas Technology Corp. 2005. All rights reserved.
//
// NK Kernel for ITS-DS7
//
// FILE : init.c
// CREATED : 2005.08.10
// MODIFIED : 2005.11.14
// AUTHOR : Renesas Technology Corp.
// HARDWARE : RENESAS ITS-DS7
// HISTORY :
// 2005.08.10
// - Created release code.
// (based on SMDK2410/MAINSTONEII for WCE5.0)
// 2005.11.14
// - Modified Changed debugserial routine of oal to debug serial common routines.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
// File: init.c
//
// Renesas ITS-DS7 board initialization code.
//
#include <bsp.h>
#include "nkintr.h"
#include "pehdr.h"
#include "romldr.h"
#include "platform.h"
#include "sh7770.h"
#include "drv_glob.h"
#define DEBUG 1
#ifdef MODULE_CERTIFY
#include "key1024.c" // OEMLoadInit/OEMLoadModule implementation and
// the public key used for module signature verification
#endif
#define pDriverGlobals ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)
#define NOT_FIXEDUP (DWORD*)-1
extern ROMChain_t *OEMRomChain;
extern ROMHDR * volatile const pTOC; // Gets replaced by RomLoader with real address
extern void InitClock();
extern BOOL (*pfnOEMIsRom)(LPVOID pvAddr, DWORD cbSize);
void InitRomChain();
void InitPeripheral();
void InitDebugSerial();
DWORD *pdwXIPLoc = NOT_FIXEDUP;
//------------------------------------------------------------------------------
//
// Function Name: OEMIsROM
//
// Description: Validates ROM address.
//
//------------------------------------------------------------------------------
BOOL OEMIsRom( LPVOID pvAddr, DWORD cbSize )
{
DWORD CachedAddr;
ASSERT( pvAddr );
// Use cached addresses
CachedAddr = (DWORD )pvAddr & ~0x20000000;
// Both addresses must fall within Flash range
return((CachedAddr >= (AREA_0+CACHED_BASE) ) && ((CachedAddr + cbSize) < (AREA_1+CACHED_BASE)));
}
BOOL OEMGetExtensionDRAM(LPDWORD lpMemStart, LPDWORD lpMemLen) {
return FALSE; // no extension DRAM
}
//------------------------------------------------------------------------------
//
// Function: OEMInit
//
// This is Windows CE OAL initialization function. It is called from kernel
// after basic initialization is made.
//
void OEMInit()
{
OALMSG(OAL_FUNC, (L"+OEMInit\r\n"));
// Reserve 128kB memory for Watson Dumps
dwNKDrWatsonSize = (128 * 1024);
// Initialize optional kernel functions.
//
pOEMIsProcessorFeaturePresent = OALIsProcessorFeaturePresent;
#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Windows CE Firmware Init\r\n"));
NKDbgPrintfW(TEXT("Version %s\r\n"),TEXT(VERSION));
#endif
#ifdef ERASE_OBJECTSTORE
// Erasing the Object Store
// Signal a cold boot by setting the first three DWORD variables
// starting at pTOC->ulRAMFree, to 0.
NKDbgPrintfW(TEXT("pTOC->ulRAMFree = 0x%x\r\n"), pTOC->ulRAMFree);
memset((void *)(pTOC->ulRAMFree | UNCACHED_BASE), 0, sizeof(DWORD)*3);
#endif
/*
* The call to InitClock must be done after all the HalSleep invocations, as
* HalSleep use the SH4 Timer 0 to wait the specified number of microseconds
* and InitClock sets up Timer 0 to generate kernel tick interrupts.
*/
// Setup kernel ROM checking
pfnOEMIsRom = OEMIsRom;
#ifdef MODULE_CERTIFY
//
// Set the module signature verification hooks
//
pOEMLoadInit = OEMLoadInit;
pOEMLoadModule = OEMLoadModule;
//
// Init the signature verification public key
//
InitPubKey(g_bSignPublicKeyBlob,sizeof(g_bSignPublicKeyBlob));
#endif
// initialize clock
InitClock();
// initialize interrupts
OALIntrInit();
// initialize pKDIoControl is hardware debugging is supported
pKDIoControl = OEMKDIoControl;
//
// Initialize KITL
//
OALKitlStart();
// Initialize the rom chain
InitRomChain();
#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Windows CE Firmware Init Done.\r\n"));
NKDbgPrintfW(TEXT("Version %s\r\n"), TEXT(VERSION));
#endif
OALMSG(OAL_FUNC, (L"-OEMInit\r\n"));
}
void InitRomChain()
{
// Added for MultiXIP stuff
static ROMChain_t s_pNextRom[MAX_ROM] = {0};
DWORD dwRomCount = 0;
DWORD dwChainCount = 0;
DWORD * pdwCurXIP;
DWORD dwNumXIPs;
PXIPCHAIN_ENTRY pChainEntry = NULL;
//#ifdef DEBUG
TCHAR szXIPName[XIP_NAMELEN];
int i; // loop ctr
//#endif
//#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Looking for rom chain\r\n"));
//#endif
if(pdwXIPLoc == NOT_FIXEDUP){
//#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Rom chain NOT found\r\n"));
//#endif
return; // no chain or not fixed up properly
}
//#ifdef DEBUG
lpWriteDebugStringFunc(TEXT("Rom chain found\r\n"));
//#endif
// set the top bit to mark it as a virtual address
pdwCurXIP = (DWORD*)(((DWORD)pdwXIPLoc) | 0x80000000);
// first DWORD is number of XIPs
dwNumXIPs = (*pdwCurXIP);
if(dwNumXIPs > MAX_ROM){
lpWriteDebugStringFunc(TEXT("ERROR: Number of XIPs exceeds MAX\r\n"));
return;
}
pChainEntry = (PXIPCHAIN_ENTRY)(pdwCurXIP + 1);
while(dwChainCount < dwNumXIPs)
{
if ((pChainEntry->usFlags & ROMXIP_OK_TO_LOAD) && // flags indicates valid XIP
*(LPDWORD)(((DWORD)(pChainEntry->pvAddr)) + ROM_SIGNATURE_OFFSET) == ROM_SIGNATURE)
{
s_pNextRom[dwRomCount].pTOC = *(ROMHDR **)(((DWORD)(pChainEntry->pvAddr)) + ROM_SIGNATURE_OFFSET + 4);
s_pNextRom[dwRomCount].pNext = NULL;
//#ifdef DEBUG
lpWriteDebugStringFunc( _T("XIP found: ") );
for (i = 0; pChainEntry->szName[i] != '\0'; ++i)
{
szXIPName[i] = (TCHAR)pChainEntry->szName[i];
}
szXIPName[i] = TEXT('\0');
lpWriteDebugStringFunc( szXIPName );
lpWriteDebugStringFunc( _T("\r\n") );
//#endif
if (dwRomCount != 0)
{
s_pNextRom[dwRomCount-1].pNext = &s_pNextRom[dwRomCount];
}
else
{
OEMRomChain = s_pNextRom;
}
dwRomCount++;
}
else
{
lpWriteDebugStringFunc( _T("Invalid XIP found\r\n") );
}
++pChainEntry;
dwChainCount++;
}
//#ifdef DEBUG
{
ROMChain_t *pchain = OEMRomChain;
lpWriteDebugStringFunc( _T("chain contents...\r\n") );
while(pchain){
lpWriteDebugStringFunc( _T("found item\r\n") );
pchain = pchain->pNext;
}
}
//#endif
}
VOID OEMInitDebugSerial(void)
{
InitDebugSerial();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -