1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/nkern/win32/nk_plat.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,187 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\include\nkern\win32\nk_plat.h
1.18 +//
1.19 +// WARNING: This file contains some APIs which are internal and are subject
1.20 +// to change without notice. Such APIs should therefore not be used
1.21 +// outside the Kernel and Hardware Services package.
1.22 +//
1.23 +
1.24 +/**
1.25 + @file
1.26 + @internalComponent
1.27 +*/
1.28 +
1.29 +#ifndef __NK_WIN32_H__
1.30 +#define __NK_WIN32_H__
1.31 +
1.32 +#define _CRTIMP // we want to use the win32 static runtime library
1.33 +
1.34 +#define WIN32_LEAN_AND_MEAN
1.35 +#define _WIN32_WINNT 0x0400
1.36 +#include <windows.h>
1.37 +
1.38 +typedef void (*TExcHandler)(TAny*,TAny*);
1.39 +
1.40 +struct TWin32ExcInfo
1.41 + {
1.42 + enum {EExcInKernel = 0x1};
1.43 +public:
1.44 + TExcHandler iHandler;
1.45 + TAny* iParam[2];
1.46 + TUint iFlags;
1.47 + // ExcType, iExcId, iFaultAddress, iEax, iEcx, iEdx, iEbx, iEsp, iEbp, iEsi, iEdi,
1.48 + // iSs, iDs, iEs, iFs, iGs, iEflags, iEip, iCs
1.49 + TUint32 iExcType; // filled in by EPOC
1.50 + TUint32 iExcCode;
1.51 + TUint32 iExcDataAddress;
1.52 + TUint32 iEax;
1.53 + TUint32 iEcx;
1.54 + TUint32 iEdx;
1.55 + TUint32 iEbx;
1.56 + TUint32 iEsp;
1.57 + TUint32 iEsi;
1.58 + TUint32 iEdi;
1.59 + TUint32 iSs;
1.60 + TUint32 iDs;
1.61 + TUint32 iEs;
1.62 + TUint32 iFs;
1.63 + TUint32 iGs;
1.64 + TUint32 iEflags;
1.65 + TUint32 iCs;
1.66 + TUint32 iEbp;
1.67 + TUint32 iEip;
1.68 + };
1.69 +
1.70 +enum TEmulThreadType
1.71 + {
1.72 + EThreadEvent, // an 'interrupt' thread, interacts with Win32 events
1.73 + EThreadNKern // a nKern thread, identified by a NThread control block
1.74 + };
1.75 +
1.76 +class NThread : public NThreadBase
1.77 + {
1.78 +public:
1.79 + typedef void (*TDivert)();
1.80 + enum TWakeup {ERelease,EResume,EResumeLocked,EIdle,EEscaped,EResumeDiverted};
1.81 + enum TSelectCpu {ECpuAll=-1,ECpuSingle=-2};
1.82 +public:
1.83 + TInt Create(SNThreadCreateInfo& aInfo, TBool aInitial);
1.84 + void Stillborn();
1.85 + void DoForceExit();
1.86 +//
1.87 + IMPORT_C static void Idle();
1.88 + IMPORT_C static void SetProperties(TBool aTrace, TInt aCpu);
1.89 + TBool WakeUp();
1.90 + TBool IsSafeToPreempt();
1.91 + void Divert(TDivert aDivert);
1.92 + void ApplyDiversion();
1.93 +
1.94 +private:
1.95 + static DWORD WINAPI StartThread(LPVOID aParam);
1.96 +//
1.97 + static void ExitSync();
1.98 + static void ExitAsync();
1.99 +//
1.100 + static void Exception();
1.101 + static LONG WINAPI ExceptionFilter(EXCEPTION_POINTERS* aExc);
1.102 +
1.103 +public:
1.104 + static void Diverted();
1.105 + // Has to be accessible to code user-side via emulator.lib
1.106 + static DWORD ExceptionHandler(EXCEPTION_RECORD* aException, CONTEXT* aContext);
1.107 +
1.108 +public:
1.109 + HANDLE iWinThread;
1.110 + DWORD iWinThreadId;
1.111 + HANDLE iScheduleLock; // event used for scheduling interlock
1.112 + TBool iDiverted; // flag to indicate that the thread is being diverted
1.113 + TDivert iDivert; // function to invoke after reschedule, may be null
1.114 + TAny* iDivertReturn; // return address from diversion
1.115 + TInt iInKernel; // flag to indicate if the thread is running 'in' the kernel
1.116 + TWakeup iWakeup; // indicates how to wake up the thread
1.117 + TLinAddr iUserStackBase;
1.118 + };
1.119 +
1.120 +IMPORT_C HANDLE CreateWin32Thread(TEmulThreadType aType, LPTHREAD_START_ROUTINE aThreadFunc, LPVOID aPtr, TBool aRun);
1.121 +IMPORT_C void StartOfInterrupt();
1.122 +IMPORT_C void EndOfInterrupt();
1.123 +
1.124 +void SchedulerInit(NThread& aInit);
1.125 +void SchedulerRegister(NThread& aSelf);
1.126 +NThread* SchedulerThread();
1.127 +NThread& CheckedCurrentThread();
1.128 +void SchedulerLock();
1.129 +void SchedulerUnlock();
1.130 +void SchedulerEscape();
1.131 +void SchedulerReenter();
1.132 +void Win32FindNonPreemptibleFunctions();
1.133 +
1.134 +inline void EnterKernel(TBool aCheck=TRUE)
1.135 + {
1.136 + if (++CheckedCurrentThread().iInKernel==1 && aCheck)
1.137 + {
1.138 + NThread& t = CheckedCurrentThread();
1.139 + __NK_ASSERT_ALWAYS(t.iCsCount==0);
1.140 + __NK_ASSERT_ALWAYS(t.iHeldFastMutex==0);
1.141 + __NK_ASSERT_ALWAYS(TheScheduler.iKernCSLocked==0);
1.142 + }
1.143 + }
1.144 +
1.145 +void LeaveKernel();
1.146 +
1.147 +IMPORT_C TInt __fastcall Dispatch(TInt aFunction, TInt* aArgs);
1.148 +
1.149 +typedef TInt (__cdecl *TExecHandler)(TInt,TInt,TInt,TInt);
1.150 +typedef void (__cdecl *TPreprocessHandler)(TInt*,TUint32);
1.151 +
1.152 +// Emulator nKern scheduling data
1.153 +class Win32Interrupt
1.154 + {
1.155 +public:
1.156 + void Init();
1.157 + TInt Mask();
1.158 + void Restore(TInt aLevel);
1.159 + void Begin();
1.160 + void End();
1.161 + inline TBool InInterrupt() const
1.162 + {return iInterrupted!=0;}
1.163 + void ForceReschedule();
1.164 + inline TBool InterruptsStatus(TBool aRequest) const
1.165 + {return aRequest?(iLevel==0):(iLevel!=0);}
1.166 +private:
1.167 + static void Reschedule(TAny*);
1.168 +private:
1.169 + TInt iLock;
1.170 + HANDLE iQ;
1.171 + DWORD iOwner;
1.172 + TInt iLevel;
1.173 + TBool iRescheduleOnExit;
1.174 + NThread* iInterrupted;
1.175 + NThread iScheduler;
1.176 + };
1.177 +
1.178 +extern TBool Win32AtomicSOAW; // flag to indicate availability of SignalObjectAndWait() API
1.179 +extern TBool Win32TraceThreadId;
1.180 +extern TInt Win32SingleCpu;
1.181 +extern Win32Interrupt Interrupt;
1.182 +
1.183 +// Emulator nKern exception data
1.184 +extern TAny* Win32ExcAddress;
1.185 +extern TAny* Win32ExcDataAddress;
1.186 +extern TUint Win32ExcCode;
1.187 +
1.188 +void FastCounterInit();
1.189 +
1.190 +#endif