/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2001. Samsung Electronics, co. ltd All rights reserved.
--*/
#include "windows.h"
#include "nkintr.h"
#include "oalintr.h"
#include "shx.h"
#include "p2.h"
#include "p2debug.h"
#include "tchaud.h"
#include "drv_glob.h"
#include <memory.h>
#ifdef MODULE_CERTIFY
#include "key1024.c" // OEMLoadInit/OEMLoadModule implementation and the public key used for module signature verification.
#endif
//#include "timer.h"
#include <S2410.h>
#include <pehdr.h>
#include <romldr.h>
extern const unsigned short ScreenBitmap[];
/*
@doc EXTERNAL KERNEL HAL
@module cfwp2.c - P2 HW Support |
OEM support Functions for the Windows CE P2 Platform.
@xref <f OEMInit> <f OEMInterruptEnable> <f OEMInterruptDisable>
<f OEMInterruptDone> <l HAL Overview.Windows CE Kernel OEM Interface>
@topic Windows CE Kernel OEM Interface |
This defines the HAL layer - OEM and platform dependent pieces of
code which we expect the OEM to deliver to us. There are three pieces
of OEM deliverable code - the bootstrap loader & monitor (for
debugging), the HAL portions which are interfaces between the kernel
and the firmware, and the driver interface. This topic covers just
the HAL portion.
The philosophy is to keep the HAL layer as simple as possible. The
HAL should not be confused with the machine or CPU independence. HAL
is specific for a particular CPU and platform. It includes interfaces
for the following devices:<nl>
Real Time Clock<nl>
Interval Timer (used for the scheduler operation) <nl>
Interrupt handlers and support <nl>
Note that it does not include abstractions for devices like the DMA
controller etc. since the kernel does not use one. Also note that the
list could change for different CPU's and platforms - for instance,
some chips might include a lot of peripheral devices (like the
interval timer) on the CPU chip itself, removing the need for a
separate interface for them.
The interfaces for the real time clock and interval timer are still
being developed. But they should in general be extremely simple and
straightforward. For details on the interrupt support model in the
kernel look at <l Interrupt Support Overview.Kernel Interrupt Support>
@xref <l Interrupt Support Overview.Kernel Interrupt Support>
<f OEMInit> <f OEMInterruptEnable> <f OEMInterruptDisable>
<f OEMInterruptDone> <f HookInterrupt>
*/
unsigned long OEMClockFreq; // OEM clock frequency is used only in OAL
//
// Kernel global variables used by GetIdleTime( ) to determine CPU utilization
//
extern DWORD idleconv; // translation constant in 1 ms units
extern DWORD curridlehigh, curridlelow; // 64-bit idle time in ms
extern int P2ISR();
extern void InitClock();
extern void HalCpuInit();
extern void HalTimerInit();
extern void HalSleep(DWORD);
extern void TIMERINIT();
extern void InitDebugEther(void);
static void HzhInitPIO(void);
static void InitDisplay(void);
static void OEMInitInterrupts(void);
static void InitSDMMC(void);
typedef volatile WORD *PVWORD; /* pointer to a volatile word */
typedef volatile DWORD *PVDWORD; /* pointer to a volatile dword */
#define REG(base, id) (*(PVWORD)((base)+(id)))
#define REG32(base, id) (*(PVDWORD)((base)+(id)))
/*
#if (CE_MAJOR_VER == 0x0003)
//Cedar
// The kernel exports...
#ifdef AddrCurMSec
// Some kernels export a pointer to the CurMSec variable.
static volatile DWORD * pCurMSec = (volatile DWORD *) AddrCurMSec;
static volatile DWORD * pDiffMSec = (volatile DWORD *) AddrDiffMSec;
#else
extern volatile DWORD CurMSec;
extern volatile DWORD DiffMSec;
static volatile DWORD * pCurMSec = &CurMSec;
static volatile DWORD * pDiffMSec = &DiffMSec;
#endif
extern DWORD dwSleepMin;
extern DWORD dwPartialDiffMSec;
extern DWORD ticksleft;
#else
// dougfir or later
//
#ifdef AddrCurMSec
// Some kernels export a pointer to the CurMSec variable.
static volatile DWORD * pCurMSec = (volatile DWORD *) AddrCurMSec;
#else
extern volatile DWORD CurMSec;
static volatile DWORD * pCurMSec = &CurMSec;
#endif
extern DWORD dwReschedTime;
#endif
*/
// dougfir or later
//
#ifdef AddrCurMSec
// Some kernels export a pointer to the CurMSec variable.
static volatile DWORD * pCurMSec = (volatile DWORD *) AddrCurMSec;
#else
extern volatile DWORD CurMSec;
static volatile DWORD * pCurMSec = &CurMSec;
#endif
extern DWORD dwReschedTime;
extern BOOL fIntrTime;
extern BOOL bProfileTimerRunning;
volatile ULARGE_INTEGER CurTicks = { 0, 0 };
volatile ULARGE_INTEGER * pCurTicks = &CurTicks;
extern DWORD dwReschedIncrement;
extern DWORD OEMCount1ms;
#define NOT_FIXEDUP (DWORD*)-1
DWORD *pdwXIPLoc = NOT_FIXEDUP;
extern ROMChain_t *OEMRomChain;
/*
@func void | InitRomChain | Collects chain information for all image regions for the kernel.
@rdesc N/A.
@comm
@xref
*/
void InitRomChain(void)
{
static ROMChain_t s_pNextRom[MAX_ROM] = {0};
DWORD dwRomCount = 0;
DWORD dwChainCount = 0;
DWORD *pdwCurXIP;
DWORD dwNumXIPs;
PXIPCHAIN_ENTRY pChainEntry = NULL;
if(pdwXIPLoc == NOT_FIXEDUP)
{
return; // no chain or not fixed up properly
}
// 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\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;
if (dwRomCount != 0)
{
s_pNextRom[dwRomCount-1].pNext = &s_pNextRom[dwRomCount];
}
else
{
OEMRomChain = s_pNextRom;
}
dwRomCount++;
}
else
{
lpWriteDebugStringFunc( _T("Invalid XIP found\n") );
}
++pChainEntry;
dwChainCount++;
}
}
#define FROM_BCD(n) ((((n) >> 4) * 10) + ((n) & 0xf))
//------------------------------------------------------------------------------
//
// @func void | OEMInit | Initialize Hardware Interfaces
// @rdesc none
// @comm OEMInit is called by the kernel after it has performed minimal
// initialization. Interrupts are disabled and the kernel is not
// ready to handle exceptions. The only kernel service available
// to this function is <f HookInterrupt>. This should be used to
// install ISR's for all the hardware interrupts to be handled by
// the firmware. Note that ISR's must be installed for any interrupt
// that is to be routed to a device driver - otherwise the
// <f InterruptInitialize> call from the driver will fail.
// @xref <l Overview.Windows CE Kernel OEM Interface> <f HookInterrupt>
//