From d610c156c648570db549ce44ace074b44fcb1aa8 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 6 Dec 2008 18:31:33 +0000 Subject: [PATCH] - move CONTEXT stuff from wdm.h to winddk.h / armddk.h - inlcude intrin.h in wdm.h - avoid redefining PCONTEXT - use intrinsics for BitScanForward/Reverse svn path=/trunk/; revision=37902 --- reactos/include/ddk/wdm.h | 129 +-------------------------- reactos/include/ddk/winddk.h | 56 ++++++++++++ reactos/include/psdk/winnt.h | 29 +----- reactos/include/reactos/arm/armddk.h | 47 ++++++++++ 4 files changed, 111 insertions(+), 150 deletions(-) diff --git a/reactos/include/ddk/wdm.h b/reactos/include/ddk/wdm.h index 9daef60342a..72e901e51ff 100644 --- a/reactos/include/ddk/wdm.h +++ b/reactos/include/ddk/wdm.h @@ -9,7 +9,11 @@ #include #include +#ifdef __GNUC__ +#include "intrin.h" +#endif +typedef struct _CONTEXT *PCONTEXT; // // Resource list definitions @@ -582,131 +586,6 @@ typedef struct _SE_IMPERSONATION_STATE { #define SERVICE_DEMAND_START 0x00000003 #define SERVICE_DISABLED 0x00000004 - - -// -// Architecture Defined Contexts -// -#if defined(_M_IX86) -#define SIZE_OF_80387_REGISTERS 80 -#define CONTEXT_i386 0x10000 -#define CONTEXT_i486 0x10000 -#define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L) -#define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L) -#define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L) -#define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L) -#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L) -#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L) -#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS) -#define MAXIMUM_SUPPORTED_EXTENSION 512 - -#define EXCEPTION_READ_FAULT 0 -#define EXCEPTION_WRITE_FAULT 1 -#define EXCEPTION_EXECUTE_FAULT 8 - -typedef struct _FLOATING_SAVE_AREA { - ULONG ControlWord; - ULONG StatusWord; - ULONG TagWord; - ULONG ErrorOffset; - ULONG ErrorSelector; - ULONG DataOffset; - ULONG DataSelector; - UCHAR RegisterArea[SIZE_OF_80387_REGISTERS]; - ULONG Cr0NpxState; -} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA; - -typedef struct _CONTEXT { - ULONG ContextFlags; - ULONG Dr0; - ULONG Dr1; - ULONG Dr2; - ULONG Dr3; - ULONG Dr6; - ULONG Dr7; - FLOATING_SAVE_AREA FloatSave; - ULONG SegGs; - ULONG SegFs; - ULONG SegEs; - ULONG SegDs; - ULONG Edi; - ULONG Esi; - ULONG Ebx; - ULONG Edx; - ULONG Ecx; - ULONG Eax; - ULONG Ebp; - ULONG Eip; - ULONG SegCs; - ULONG EFlags; - ULONG Esp; - ULONG SegSs; - UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]; -} CONTEXT, *PCONTEXT; - -#elif defined(_M_AMD64) -#error FIXME-TODO: 64-bit -#elif defined(_M_ARM) - -// -// FIXME: Move to armddk.h? -// - -/* The following flags control the contents of the CONTEXT structure. */ - -#define CONTEXT_ARM 0x0000040 -#define CONTEXT_CONTROL (CONTEXT_ARM | 0x00000001L) -#define CONTEXT_INTEGER (CONTEXT_ARM | 0x00000002L) - -#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER) - -typedef struct _CONTEXT { - /* The flags values within this flag control the contents of - a CONTEXT record. - - If the context record is used as an input parameter, then - for each portion of the context record controlled by a flag - whose value is set, it is assumed that that portion of the - context record contains valid context. If the context record - is being used to modify a thread's context, then only that - portion of the threads context will be modified. - - If the context record is used as an IN OUT parameter to capture - the context of a thread, then only those portions of the thread's - context corresponding to set flags will be returned. - - The context record is never used as an OUT only parameter. */ - - ULONG ContextFlags; - - /* This section is specified/returned if the ContextFlags word contains - the flag CONTEXT_INTEGER. */ - ULONG R0; - ULONG R1; - ULONG R2; - ULONG R3; - ULONG R4; - ULONG R5; - ULONG R6; - ULONG R7; - ULONG R8; - ULONG R9; - ULONG R10; - ULONG R11; - ULONG R12; - - ULONG Sp; - ULONG Lr; - ULONG Pc; - ULONG Psr; -} CONTEXT, *PCONTEXT; - -#else -#error "Undefined processor architecture" -#endif - - - // // Exception Records // diff --git a/reactos/include/ddk/winddk.h b/reactos/include/ddk/winddk.h index d663f2ff8ab..c9ebed2f237 100644 --- a/reactos/include/ddk/winddk.h +++ b/reactos/include/ddk/winddk.h @@ -215,6 +215,10 @@ struct _COMPRESSED_DATA_INFO; #define KERNEL_LARGE_STACK_SIZE 61440 #define KERNEL_LARGE_STACK_COMMIT 12288 +#define EXCEPTION_READ_FAULT 0 +#define EXCEPTION_WRITE_FAULT 1 +#define EXCEPTION_EXECUTE_FAULT 8 + #define DPFLTR_ERROR_LEVEL 0 #define DPFLTR_WARNING_LEVEL 1 #define DPFLTR_TRACE_LEVEL 2 @@ -5448,6 +5452,58 @@ typedef VOID #ifdef _X86_ +#define SIZE_OF_80387_REGISTERS 80 +#define CONTEXT_i386 0x10000 +#define CONTEXT_i486 0x10000 +#define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L) +#define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L) +#define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L) +#define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L) +#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L) +#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L) +#define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS) +#define MAXIMUM_SUPPORTED_EXTENSION 512 + +typedef struct _FLOATING_SAVE_AREA { + ULONG ControlWord; + ULONG StatusWord; + ULONG TagWord; + ULONG ErrorOffset; + ULONG ErrorSelector; + ULONG DataOffset; + ULONG DataSelector; + UCHAR RegisterArea[SIZE_OF_80387_REGISTERS]; + ULONG Cr0NpxState; +} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA; + +typedef struct _CONTEXT { + ULONG ContextFlags; + ULONG Dr0; + ULONG Dr1; + ULONG Dr2; + ULONG Dr3; + ULONG Dr6; + ULONG Dr7; + FLOATING_SAVE_AREA FloatSave; + ULONG SegGs; + ULONG SegFs; + ULONG SegEs; + ULONG SegDs; + ULONG Edi; + ULONG Esi; + ULONG Ebx; + ULONG Edx; + ULONG Ecx; + ULONG Eax; + ULONG Ebp; + ULONG Eip; + ULONG SegCs; + ULONG EFlags; + ULONG Esp; + ULONG SegSs; + UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]; +} CONTEXT; + // // Types to use to contain PFNs and their counts. // diff --git a/reactos/include/psdk/winnt.h b/reactos/include/psdk/winnt.h index 0cd1d7a81b9..ca7f90a6486 100644 --- a/reactos/include/psdk/winnt.h +++ b/reactos/include/psdk/winnt.h @@ -2229,7 +2229,7 @@ typedef struct DECLSPEC_ALIGN(16) _CONTEXT { DWORD64 LastBranchFromRip; DWORD64 LastExceptionToRip; DWORD64 LastExceptionFromRip; -} CONTEXT, *PCONTEXT; +} CONTEXT; typedef struct _KNONVOLATILE_CONTEXT_POINTERS { @@ -2299,7 +2299,7 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS { NTSYSAPI VOID __cdecl -RtlRestoreContext(PCONTEXT ContextRecord, +RtlRestoreContext(struct _CONTEXT *ContextRecord, struct _EXCEPTION_RECORD *ExceptionRecord); NTSYSAPI @@ -4796,29 +4796,8 @@ InterlockedBitTestAndReset(IN LONG volatile *Base, #endif } -static __inline__ BOOLEAN -BitScanReverse(OUT ULONG *Index, - IN ULONG Mask) -{ - BOOLEAN BitPosition = 0; -#if defined(_M_IX86) - __asm__ __volatile__("bsrl %2,%0\n\t" - "setnz %1\n\t" - :"=&r" (*Index), "=q" (BitPosition) - :"rm" (Mask) - :"memory"); - return BitPosition; -#else - /* Slow implementation for now */ - for( *Index = 31; *Index; (*Index)-- ) { - if( (1<<*Index) & Mask ) { - return TRUE; - } - } - - return FALSE; -#endif -} +#define BitScanForward _BitScanForward +#define BitScanReverse _BitScanReverse #endif diff --git a/reactos/include/reactos/arm/armddk.h b/reactos/include/reactos/arm/armddk.h index d62a7f8a834..3f07112f008 100644 --- a/reactos/include/reactos/arm/armddk.h +++ b/reactos/include/reactos/arm/armddk.h @@ -58,6 +58,53 @@ typedef struct _KFLOATING_SAVE ULONG Reserved; } KFLOATING_SAVE, *PKFLOATING_SAVE; +/* The following flags control the contents of the CONTEXT structure. */ +#define CONTEXT_ARM 0x0000040 +#define CONTEXT_CONTROL (CONTEXT_ARM | 0x00000001L) +#define CONTEXT_INTEGER (CONTEXT_ARM | 0x00000002L) +#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER) + +typedef struct _CONTEXT { + /* The flags values within this flag control the contents of + a CONTEXT record. + + If the context record is used as an input parameter, then + for each portion of the context record controlled by a flag + whose value is set, it is assumed that that portion of the + context record contains valid context. If the context record + is being used to modify a thread's context, then only that + portion of the threads context will be modified. + + If the context record is used as an IN OUT parameter to capture + the context of a thread, then only those portions of the thread's + context corresponding to set flags will be returned. + + The context record is never used as an OUT only parameter. */ + + ULONG ContextFlags; + + /* This section is specified/returned if the ContextFlags word contains + the flag CONTEXT_INTEGER. */ + ULONG R0; + ULONG R1; + ULONG R2; + ULONG R3; + ULONG R4; + ULONG R5; + ULONG R6; + ULONG R7; + ULONG R8; + ULONG R9; + ULONG R10; + ULONG R11; + ULONG R12; + + ULONG Sp; + ULONG Lr; + ULONG Pc; + ULONG Psr; +} CONTEXT; + // // Processor Control Region // On ARM, it's actually readable from user-mode, much like KUSER_SHARED_DATA