2010-02-26 11:43:19 +00:00
|
|
|
#pragma once
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
|
|
|
|
#define Ke386SetGlobalDescriptorTable(X) \
|
|
|
|
__asm__("lgdt %0\n\t" \
|
|
|
|
: /* no outputs */ \
|
2009-09-21 15:20:18 +00:00
|
|
|
: "m" (*X));
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#define Ke386GetGlobalDescriptorTable(X) \
|
|
|
|
__asm__("sgdt %0\n\t" \
|
2009-09-21 15:20:18 +00:00
|
|
|
: "=m" (*X) \
|
2008-12-04 00:55:15 +00:00
|
|
|
: /* no input */ \
|
|
|
|
: "memory");
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2010-01-20 04:05:08 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386FxStore(IN PFX_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
asm volatile ("fxrstor (%0)" : : "r"(SaveArea));
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386FxSave(IN PFX_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
asm volatile ("fxsave (%0)" : : "r"(SaveArea));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386FnSave(IN PFLOATING_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
asm volatile ("fnsave (%0); wait" : : "r"(SaveArea));
|
|
|
|
}
|
|
|
|
|
2010-01-08 19:24:10 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386SaveFpuState(IN PFX_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
extern ULONG KeI386FxsrPresent;
|
|
|
|
if (KeI386FxsrPresent)
|
|
|
|
{
|
2010-04-29 16:39:52 +00:00
|
|
|
__asm__ __volatile__ ("fxsave %0\n" : : "m"(*SaveArea));
|
2010-01-08 19:24:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-29 16:39:52 +00:00
|
|
|
__asm__ __volatile__ ("fnsave %0\n wait\n" : : "m"(*SaveArea));
|
2010-01-08 19:24:10 +00:00
|
|
|
}
|
2010-01-09 15:07:44 +00:00
|
|
|
}
|
2010-01-08 19:24:10 +00:00
|
|
|
|
2009-09-27 10:09:38 +00:00
|
|
|
FORCEINLINE
|
|
|
|
USHORT
|
2015-09-03 23:57:39 +00:00
|
|
|
Ke386GetLocalDescriptorTable(VOID)
|
2009-09-27 10:09:38 +00:00
|
|
|
{
|
|
|
|
USHORT Ldt;
|
|
|
|
__asm__("sldt %0\n\t"
|
|
|
|
: "=m" (Ldt)
|
|
|
|
: /* no input */
|
2008-12-04 00:55:15 +00:00
|
|
|
: "memory");
|
2009-09-27 10:09:38 +00:00
|
|
|
return Ldt;
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#define Ke386SetLocalDescriptorTable(X) \
|
|
|
|
__asm__("lldt %w0\n\t" \
|
|
|
|
: /* no outputs */ \
|
|
|
|
: "q" (X));
|
|
|
|
|
|
|
|
#define Ke386SetTr(X) __asm__ __volatile__("ltr %%ax" : :"a" (X));
|
|
|
|
|
2009-09-27 10:09:38 +00:00
|
|
|
FORCEINLINE
|
|
|
|
USHORT
|
|
|
|
Ke386GetTr(VOID)
|
|
|
|
{
|
|
|
|
USHORT Tr;
|
|
|
|
__asm__("str %0\n\t"
|
|
|
|
: "=m" (Tr));
|
|
|
|
return Tr;
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#define _Ke386GetSeg(N) ({ \
|
|
|
|
unsigned int __d; \
|
|
|
|
__asm__("movl %%" #N ",%0\n\t" :"=r" (__d)); \
|
|
|
|
__d; \
|
2009-09-27 10:09:38 +00:00
|
|
|
})
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#define _Ke386SetSeg(N,X) __asm__ __volatile__("movl %0,%%" #N : :"r" (X));
|
|
|
|
|
|
|
|
#define Ke386FnInit() __asm__("fninit\n\t");
|
Trap Handlers in C Patch 1 of X (Patch by Sir_Richard <ros.arm@reactos.org>):
[NTOS]: The kernel normally does not save FPU state during Ring 0 transitions since the FPU should not be used. The one exception is when a kernel debugger is attached. Unfortunately, the latter check in ReactOS results in even "print on the serial line" to count as "debugger attached", and thus FPU state was almost always saved, slowing down traps significantly.
[NTOS]: The kernel also does not typically save DRx (debug) registers unless they were in use. During an exception dispatch, they are zeroed out, and later during trap exit, if any debug register is set, DR7 is updated to enable that hardware breakpoint. Unfortunately, the code to clear the debug registers had a bug: DR2 was never cleared. Because DR2 ended up being a random stack value during trap frame generation, this caused a bogus address to be added to DR2, and DR7 would then enable the 2nd hardware breakpoint. This caused the kernel to always save DRx state, which is slow, and worse, could cause random hardware breakpoints to fire.
[NTOS]: Start implementing trap handling in C. ASM trap handlers will now only be 5 lines of assembly including a function call to a C handler. All C handling code uses maximum two arguments and is all FASTCALL for efficiency.
[NTOS]: Implement C versions of TRAP_PROLOG and TRAP_EPILOG. Implement C version of Ki386EoiHelper. Implement C version of CommonDispatchException (and helper) and KiFatalSystemException. Implement C version of CHECK_FOR_APC_DELIVER. Implement trap debugging checks as a separate entity instead of always doing them.
[NTOS]: Add missing intrinsics for DS/ES/GS segment query.
The kernel is now ready for some trap handling to be done in C. Due to the FPU/Debug fixes and relaxation of paranoid debug checks, the C code will likely be faster than the original assembly.
svn path=/trunk/; revision=45000
2010-01-08 15:04:19 +00:00
|
|
|
#define Ke386ClearDirectionFlag() __asm__ __volatile__ ("cld")
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-09-26 16:41:35 +00:00
|
|
|
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
//
|
|
|
|
// CR Macros
|
|
|
|
//
|
|
|
|
#define Ke386SetCr2(X) __asm__ __volatile__("movl %0,%%cr2" : :"r" (X));
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
//
|
|
|
|
// Segment Macros
|
|
|
|
//
|
|
|
|
#define Ke386GetSs() _Ke386GetSeg(ss)
|
|
|
|
#define Ke386GetFs() _Ke386GetSeg(fs)
|
Trap Handlers in C Patch 1 of X (Patch by Sir_Richard <ros.arm@reactos.org>):
[NTOS]: The kernel normally does not save FPU state during Ring 0 transitions since the FPU should not be used. The one exception is when a kernel debugger is attached. Unfortunately, the latter check in ReactOS results in even "print on the serial line" to count as "debugger attached", and thus FPU state was almost always saved, slowing down traps significantly.
[NTOS]: The kernel also does not typically save DRx (debug) registers unless they were in use. During an exception dispatch, they are zeroed out, and later during trap exit, if any debug register is set, DR7 is updated to enable that hardware breakpoint. Unfortunately, the code to clear the debug registers had a bug: DR2 was never cleared. Because DR2 ended up being a random stack value during trap frame generation, this caused a bogus address to be added to DR2, and DR7 would then enable the 2nd hardware breakpoint. This caused the kernel to always save DRx state, which is slow, and worse, could cause random hardware breakpoints to fire.
[NTOS]: Start implementing trap handling in C. ASM trap handlers will now only be 5 lines of assembly including a function call to a C handler. All C handling code uses maximum two arguments and is all FASTCALL for efficiency.
[NTOS]: Implement C versions of TRAP_PROLOG and TRAP_EPILOG. Implement C version of Ki386EoiHelper. Implement C version of CommonDispatchException (and helper) and KiFatalSystemException. Implement C version of CHECK_FOR_APC_DELIVER. Implement trap debugging checks as a separate entity instead of always doing them.
[NTOS]: Add missing intrinsics for DS/ES/GS segment query.
The kernel is now ready for some trap handling to be done in C. Due to the FPU/Debug fixes and relaxation of paranoid debug checks, the C code will likely be faster than the original assembly.
svn path=/trunk/; revision=45000
2010-01-08 15:04:19 +00:00
|
|
|
#define Ke386GetDs() _Ke386GetSeg(ds)
|
|
|
|
#define Ke386GetEs() _Ke386GetSeg(es)
|
|
|
|
#define Ke386GetGs() _Ke386GetSeg(gs)
|
2006-11-08 11:47:44 +00:00
|
|
|
#define Ke386SetFs(X) _Ke386SetSeg(fs, X)
|
|
|
|
#define Ke386SetDs(X) _Ke386SetSeg(ds, X)
|
|
|
|
#define Ke386SetEs(X) _Ke386SetSeg(es, X)
|
2009-09-21 15:20:18 +00:00
|
|
|
#define Ke386SetSs(X) _Ke386SetSeg(ss, X)
|
|
|
|
#define Ke386SetGs(X) _Ke386SetSeg(gs, X)
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386FnInit(VOID)
|
|
|
|
{
|
|
|
|
__asm fninit;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2010-04-09 21:10:13 +00:00
|
|
|
__sgdt(OUT PVOID Descriptor)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2010-04-09 21:10:13 +00:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov eax, Descriptor
|
|
|
|
sgdt [eax]
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2011-02-11 13:48:41 +00:00
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
__fxsave(OUT PFX_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
__asm mov eax, SaveArea
|
|
|
|
__asm fxsave [eax]
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
__fxrstor(IN PFX_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
__asm mov eax, SaveArea
|
|
|
|
__asm fxrstor [eax]
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
__fnsave(OUT PFLOATING_SAVE_AREA SaveArea)
|
|
|
|
{
|
|
|
|
__asm mov eax, SaveArea
|
|
|
|
__asm fnsave [eax]
|
|
|
|
__asm wait;
|
|
|
|
}
|
|
|
|
|
2010-04-09 21:10:13 +00:00
|
|
|
#define Ke386GetGlobalDescriptorTable __sgdt
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2010-04-09 21:10:13 +00:00
|
|
|
__lgdt(IN PVOID Descriptor)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2010-04-09 21:10:13 +00:00
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov eax, Descriptor
|
|
|
|
lgdt [eax]
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2010-04-09 21:10:13 +00:00
|
|
|
#define Ke386SetGlobalDescriptorTable __lgdt
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
FORCEINLINE
|
2009-09-27 10:09:38 +00:00
|
|
|
USHORT
|
|
|
|
Ke386GetLocalDescriptorTable(VOID)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2009-09-27 10:09:38 +00:00
|
|
|
__asm sldt ax;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetLocalDescriptorTable(IN USHORT Descriptor)
|
|
|
|
{
|
|
|
|
__asm lldt Descriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetTr(IN USHORT Tr)
|
|
|
|
{
|
|
|
|
__asm ltr Tr;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
USHORT
|
2009-09-27 10:09:38 +00:00
|
|
|
Ke386GetTr(VOID)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2009-09-27 10:09:38 +00:00
|
|
|
__asm str ax;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
//
|
|
|
|
// CR Macros
|
|
|
|
//
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
- Add EXCEPTION_RECORD64 and LIST_ENTRY64, KeTryToAcquireSpinLockAtDpcLevel, BREAKPOINT_COMMAND_STRING, Ke386SetCr2, Ke386SetDr3, Ke386SetDr6.
- Remove non-kernel routines from kdfuncs.h and remove deprecated routines from ke.h.
- Implement KiRestoreProcessorControlState, KeFreezeExecution, KeThawExecution, ExAcquireTimeRefreshLock, ExReleaseTimeRefreshLock.
- Rename ModuleLoadList to PsLoadedModuleList. Add PsNtosImageBase and set value in it.
- Add skeleton wdbgexts.h with what's needed until now, this is a PSDK header.
- Add kddll.h for KDCOM/1394/USB2.DLL prototypes.
- Add windbgkd.h with KD protocol definitions. Used to be an NT5 DDK header, but was removed, so this goes into include\reactos.
svn path=/branches/alex-kd-branch/; revision=25833
2007-02-18 07:21:03 +00:00
|
|
|
Ke386SetCr2(IN ULONG Value)
|
|
|
|
{
|
|
|
|
__asm mov eax, Value;
|
|
|
|
__asm mov cr2, eax;
|
|
|
|
}
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
//
|
|
|
|
// Segment Macros
|
|
|
|
//
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
USHORT
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386GetSs(VOID)
|
|
|
|
{
|
|
|
|
__asm mov ax, ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
USHORT
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386GetFs(VOID)
|
|
|
|
{
|
|
|
|
__asm mov ax, fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
USHORT
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386GetDs(VOID)
|
|
|
|
{
|
|
|
|
__asm mov ax, ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
USHORT
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386GetEs(VOID)
|
|
|
|
{
|
|
|
|
__asm mov ax, es;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetSs(IN USHORT Value)
|
|
|
|
{
|
|
|
|
__asm mov ax, Value;
|
|
|
|
__asm mov ss, ax;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetFs(IN USHORT Value)
|
|
|
|
{
|
|
|
|
__asm mov ax, Value;
|
|
|
|
__asm mov fs, ax;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetDs(IN USHORT Value)
|
|
|
|
{
|
|
|
|
__asm mov ax, Value;
|
|
|
|
__asm mov ds, ax;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
Ke386SetEs(IN USHORT Value)
|
|
|
|
{
|
|
|
|
__asm mov ax, Value;
|
|
|
|
__asm mov es, ax;
|
|
|
|
}
|
|
|
|
|
2009-09-21 15:20:18 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386SetGs(IN USHORT Value)
|
|
|
|
{
|
|
|
|
__asm mov ax, Value;
|
|
|
|
__asm mov gs, ax;
|
|
|
|
}
|
|
|
|
|
2011-02-11 13:48:41 +00:00
|
|
|
extern ULONG KeI386FxsrPresent;
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
Ke386SaveFpuState(IN PVOID SaveArea)
|
|
|
|
{
|
|
|
|
if (KeI386FxsrPresent)
|
|
|
|
{
|
|
|
|
__fxsave(SaveArea);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__fnsave(SaveArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define Ke386FnSave __fnsave
|
|
|
|
#define Ke386FxSave __fxsave
|
|
|
|
// The name suggest, that the original author didn't understand what frstor means
|
|
|
|
#define Ke386FxStore __fxrstor
|
|
|
|
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
#else
|
|
|
|
#error Unknown compiler for inline assembler
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* EOF */
|