[ros-diffs] [ion] 24651: - Implement more of the Ke386 ASM macros for MSVC. - Remove custom Set/Get Cr macros and use MSVC-compatible __read/__writecrX - Remove custom WbInvd macro and use MSVC-compatible __wbinvd.

ion at svn.reactos.org ion at svn.reactos.org
Wed Oct 25 19:15:12 CEST 2006


Author: ion
Date: Wed Oct 25 21:15:11 2006
New Revision: 24651

URL: http://svn.reactos.org/svn/reactos?rev=24651&view=rev
Log:
- Implement more of the Ke386 ASM macros for MSVC.
- Remove custom Set/Get Cr macros and use MSVC-compatible __read/__writecrX
- Remove custom WbInvd macro and use MSVC-compatible __wbinvd.

Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
    trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
    trunk/reactos/ntoskrnl/ex/sysinfo.c
    trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h
    trunk/reactos/ntoskrnl/ke/i386/cpu.c
    trunk/reactos/ntoskrnl/ke/i386/patpge.c
    trunk/reactos/ntoskrnl/mm/i386/page.c
    trunk/reactos/ntoskrnl/mm/i386/pfault.c

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/loader.c Wed Oct 25 21:15:11 2006
@@ -198,14 +198,14 @@
         PageDirectoryBaseAddress = (ULONG_PTR)&startup_pagedirectorytable_pae;
 
         /* Enable PAE */
-        Ke386SetCr4(Ke386GetCr4() | X86_CR4_PAE);
+        __writecr4(__readcr4() | X86_CR4_PAE);
     }
 
     /* Set the PDBR */
-    Ke386SetCr3(PageDirectoryBaseAddress);
+    __writecr3(PageDirectoryBaseAddress);
 
     /* Enable Paging and Write Protect*/
-    Ke386SetCr0(Ke386GetCr0() | X86_CR0_PG | X86_CR0_WP);
+    __writecr0(__readcr0() | X86_CR0_PG | X86_CR0_WP);
 
     /* Jump to Kernel */
     PagedJump = (ASMCODE)(PVOID)(KernelEntryPoint);

Modified: trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/wlmemory.c Wed Oct 25 21:15:11 2006
@@ -566,10 +566,10 @@
 	Ke386EraseFlags();
 
 	// Set the PDBR
-	Ke386SetCr3((ULONG_PTR)PDE);
+	__writecr3((ULONG_PTR)PDE);
 
 	// Enable paging by modifying CR0
-	Ke386SetCr0(Ke386GetCr0() | CR0_PG);
+	__writecr0(__readcr0() | CR0_PG);
 
 	// Set processor context
 	WinLdrSetProcessorContext(GdtIdt, KIP0PCRADDRESS, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));

Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ex/sysinfo.c (original)
+++ trunk/reactos/ntoskrnl/ex/sysinfo.c Wed Oct 25 21:15:11 2006
@@ -1689,7 +1689,7 @@
 {
     PAGED_CODE();
 
-    Ke386WbInvd();
+    __wbinvd();
     return STATUS_SUCCESS;
 }
 

Modified: trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/i386/intrin_i.h Wed Oct 25 21:15:11 2006
@@ -50,19 +50,12 @@
 
 #define _Ke386SetSeg(N,X)         __asm__ __volatile__("movl %0,%%" #N : :"r" (X));
 
-#define _Ke386GetCr(N)           ({ \
-                                     unsigned int __d; \
-                                     __asm__("movl %%cr" #N ",%0\n\t" :"=r" (__d)); \
-                                     __d; \
-                                 })
-
 #define _Ke386GetDr(N)           ({ \
                                      unsigned int __d; \
                                      __asm__("movl %%dr" #N ",%0\n\t" :"=r" (__d)); \
                                      __d; \
                                  })
 
-#define _Ke386SetCr(N,X)         __asm__ __volatile__("movl %0,%%cr" #N : :"r" (X));
 #define _Ke386SetDr(N,X)         __asm__ __volatile__("movl %0,%%dr" #N : :"r" (X));
 
 #define Ke386SetTr(X)         __asm__ __volatile__("ltr %%ax" : :"a" (X));
@@ -95,98 +88,21 @@
 
 #define Ke386HaltProcessor()     __asm__("hlt\n\t");
 #define Ke386FnInit()     __asm__("fninit\n\t");
-#define Ke386WbInvd()     __asm__("wbinvd\n\t");
-
-#elif defined(_MSC_VER)
-
-VOID
-FORCEINLINE
-Ke386WbInvd(VOID)
-{
-    __asm wbinvd;
-}
-
-VOID
-FORCEINLINE
-Ke386FnInit(VOID)
-{
-    __asm fninit;
-}
-
-VOID
-FORCEINLINE
-Ke386HaltProcessor(VOID)
-{
-    __asm hlt;
-}
-
-VOID
-FORCEINLINE
-Ke386GetInterruptDescriptorTable(OUT KDESCRIPTOR Descriptor)
-{
-    __asm sidt Descriptor;
-}
-
-VOID
-FORCEINLINE
-Ke386SetInterruptDescriptorTable(IN KDESCRIPTOR Descriptor)
-{
-    __asm lidt Descriptor;
-}
-
-VOID
-FORCEINLINE
-Ke386GetGlobalDescriptorTable(OUT KDESCRIPTOR Descriptor)
-{
-    __asm sgdt Descriptor;
-}
-
-VOID
-FORCEINLINE
-Ke386SetGlobalDescriptorTable(IN KDESCRIPTOR Descriptor)
-{
-    __asm lgdt Descriptor;
-}
-
-VOID
-FORCEINLINE
-Ke386GetLocalDescriptorTable(OUT USHORT Descriptor)
-{
-    __asm sldt Descriptor;
-}
-
-VOID
-FORCEINLINE
-Ke386SetLocalDescriptorTable(IN USHORT Descriptor)
-{
-    __asm lldt Descriptor;
-}
-
-#else
-#error Unknown compiler for inline assembler
-#endif
-
-//
-// CR Macros
-//
-#define Ke386GetCr0()               _Ke386GetCr(0)
-#define Ke386SetCr0(X)              _Ke386SetCr(0,X)
-#define Ke386GetCr2()               _Ke386GetCr(2)
-#define Ke386SetCr2(X)              _Ke386SetCr(2,X)
-#define Ke386GetCr3()               _Ke386GetCr(3)
-#define Ke386SetCr3(X)              _Ke386SetCr(3,X)
-#define Ke386GetCr4()               _Ke386GetCr(4)
-#define Ke386SetCr4(X)              _Ke386SetCr(4,X)
 
 //
 // DR Macros
 //
 #define Ke386GetDr0()               _Ke386GetDr(0)
+#define Ke386GetDr1()               _Ke386GetDr(1)
 #define Ke386SetDr0(X)              _Ke386SetDr(0,X)
 #define Ke386GetDr2()               _Ke386GetDr(2)
 #define Ke386SetDr2(X)              _Ke386SetDr(2,X)
+#define Ke386GetDr3()               _Ke386GetDr(3)
 #define Ke386GetDr4()               _Ke386GetDr(4)
 #define Ke386SetDr4(X)              _Ke386SetDr(4,X)
+#define Ke386GetDr6()               _Ke386GetDr(6)
+#define Ke386GetDr7()               _Ke386GetDr(7)
+#define Ke386SetDr7(X)              _Ke386SetDr(7,X)
 
 //
 // Segment Macros
@@ -197,6 +113,246 @@
 #define Ke386SetDs(X)               _Ke386SetSeg(ds, X)
 #define Ke386SetEs(X)               _Ke386SetSeg(es, X)
 
+#elif defined(_MSC_VER)
+
+VOID
+FORCEINLINE
+Ke386FnInit(VOID)
+{
+    __asm fninit;
+}
+
+VOID
+FORCEINLINE
+Ke386HaltProcessor(VOID)
+{
+    __asm hlt;
+}
+
+VOID
+FORCEINLINE
+Ke386GetInterruptDescriptorTable(OUT KDESCRIPTOR Descriptor)
+{
+    __asm sidt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386SetInterruptDescriptorTable(IN KDESCRIPTOR Descriptor)
+{
+    __asm lidt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386GetGlobalDescriptorTable(OUT KDESCRIPTOR Descriptor)
+{
+    __asm sgdt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386SetGlobalDescriptorTable(IN KDESCRIPTOR Descriptor)
+{
+    __asm lgdt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386GetLocalDescriptorTable(OUT USHORT Descriptor)
+{
+    __asm sldt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386SetLocalDescriptorTable(IN USHORT Descriptor)
+{
+    __asm lldt Descriptor;
+}
+
+VOID
+FORCEINLINE
+Ke386SaveFlags(IN ULONG Flags)
+{
+    __asm pushf;
+    __asm pop Flags;
+}
+
+VOID
+FORCEINLINE
+Ke386RestoreFlags(IN ULONG Flags)
+{
+    __asm push Flags;
+    __asm popf;
+}
+
+VOID
+FORCEINLINE
+Ke386SetTr(IN USHORT Tr)
+{
+    __asm ltr Tr;
+}
+
+USHORT
+FORCEINLINE
+Ke386GetTr(IN USHORT Tr)
+{
+    __asm str Tr;
+}
+
+//
+// DR Macros
+//
+ULONG
+FORCEINLINE
+Ke386GetDr0(VOID)
+{
+    __asm mov eax, dr0;
+}
+
+ULONG
+FORCEINLINE
+Ke386GetDr1(VOID)
+{
+    __asm mov eax, dr1;
+}
+
+ULONG
+FORCEINLINE
+Ke386GetDr2(VOID)
+{
+    __asm mov eax, dr2;
+}
+
+ULONG
+FORCEINLINE
+Ke386GetDr3(VOID)
+{
+    __asm mov eax, dr3;
+}
+
+ULONG
+FORCEINLINE
+Ke386GetDr6(VOID)
+{
+    __asm mov eax, dr6;
+}
+
+ULONG
+FORCEINLINE
+Ke386GetDr7(VOID)
+{
+    __asm mov eax, dr7;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDr0(IN ULONG Value)
+{
+    __asm mov eax, Value;
+    __asm mov dr0, eax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDr2(IN ULONG Value)
+{
+    __asm mov eax, Value;
+    __asm mov dr2, eax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDr3(IN ULONG Value)
+{
+    __asm mov eax, Value;
+    __asm mov dr3, eax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDr6(IN ULONG Value)
+{
+    __asm mov eax, Value;
+    __asm mov dr6, eax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDr7(IN ULONG Value)
+{
+    __asm mov eax, Value;
+    __asm mov dr7, eax;
+}
+
+//
+// Segment Macros
+//
+USHORT
+FORCEINLINE
+Ke386GetSs(VOID)
+{
+    __asm mov ax, ss;
+}
+
+USHORT
+FORCEINLINE
+Ke386GetFs(VOID)
+{
+    __asm mov ax, fs;
+}
+
+USHORT
+FORCEINLINE
+Ke386GetDs(VOID)
+{
+    __asm mov ax, ds;
+}
+
+USHORT
+FORCEINLINE
+Ke386GetEs(VOID)
+{
+    __asm mov ax, es;
+}
+
+VOID
+FORCEINLINE
+Ke386SetSs(IN USHORT Value)
+{
+    __asm mov ax, Value;
+    __asm mov ss, ax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetFs(IN USHORT Value)
+{
+    __asm mov ax, Value;
+    __asm mov fs, ax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetDs(IN USHORT Value)
+{
+    __asm mov ax, Value;
+    __asm mov ds, ax;
+}
+
+VOID
+FORCEINLINE
+Ke386SetEs(IN USHORT Value)
+{
+    __asm mov ax, Value;
+    __asm mov es, ax;
+}
+
+#else
+#error Unknown compiler for inline assembler
 #endif
 
+#endif
+
 /* EOF */

Modified: trunk/reactos/ntoskrnl/ke/i386/cpu.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/cpu.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/cpu.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/cpu.c Wed Oct 25 21:15:11 2006
@@ -511,13 +511,13 @@
     ULONG Cr0;
 
     /* Save current CR0 */
-    Cr0 = Ke386GetCr0();
+    Cr0 = __readcr0();
 
     /* If this is a 486, enable Write-Protection */
     if (KeGetCurrentPrcb()->CpuType > 3) Cr0 |= CR0_WP;
 
     /* Set new Cr0 */
-    Ke386SetCr0(Cr0);
+    __writecr0(Cr0);
 }
 
 VOID
@@ -601,7 +601,7 @@
     /* Initialize the TSS used for handling double faults. */
     Tss = (PKTSS)KiDoubleFaultTSS;
     KiInitializeTSS(Tss);
-    Tss->CR3 = _Ke386GetCr(3);
+    Tss->CR3 = __readcr3();
     Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
     Tss->Eip = PtrToUlong(KiTrap8);
     Tss->Cs = KGDT_R0_CODE;
@@ -630,7 +630,7 @@
     /* Initialize the actual TSS */
     Tss = (PKTSS)KiNMITSS;
     KiInitializeTSS(Tss);
-    Tss->CR3 = _Ke386GetCr(3);
+    Tss->CR3 = __readcr3();
     Tss->Esp0 = PtrToUlong(KiDoubleFaultStack);
     Tss->Eip = PtrToUlong(KiTrap2);
     Tss->Cs = KGDT_R0_CODE;
@@ -655,7 +655,7 @@
 KeFlushCurrentTb(VOID)
 {
     /* Flush the TLB by resetting CR3 */
-    _Ke386SetCr(3, _Ke386GetCr(3));
+    __writecr3((ULONGLONG)__readcr3);
 }
 
 VOID
@@ -663,19 +663,19 @@
 KiSaveProcessorControlState(IN PKPROCESSOR_STATE ProcessorState)
 {
     /* Save the CR registers */
-    ProcessorState->SpecialRegisters.Cr0 = _Ke386GetCr(0);
-    ProcessorState->SpecialRegisters.Cr2 = _Ke386GetCr(2);
-    ProcessorState->SpecialRegisters.Cr3 = _Ke386GetCr(3);
-    ProcessorState->SpecialRegisters.Cr4 = _Ke386GetCr(4);
+    ProcessorState->SpecialRegisters.Cr0 = __readcr0();
+    ProcessorState->SpecialRegisters.Cr2 = __readcr2();
+    ProcessorState->SpecialRegisters.Cr3 = __readcr3();
+    ProcessorState->SpecialRegisters.Cr4 = __readcr4();
 
     /* Save the DR registers */
-    ProcessorState->SpecialRegisters.KernelDr0 = _Ke386GetDr(0);
-    ProcessorState->SpecialRegisters.KernelDr1 = _Ke386GetDr(1);
-    ProcessorState->SpecialRegisters.KernelDr2 = _Ke386GetDr(2);
-    ProcessorState->SpecialRegisters.KernelDr3 = _Ke386GetDr(3);
-    ProcessorState->SpecialRegisters.KernelDr6 = _Ke386GetDr(6);
-    ProcessorState->SpecialRegisters.KernelDr7 = _Ke386GetDr(7);
-    _Ke386SetDr(7, 0);
+    ProcessorState->SpecialRegisters.KernelDr0 = Ke386GetDr0();
+    ProcessorState->SpecialRegisters.KernelDr1 = Ke386GetDr1();
+    ProcessorState->SpecialRegisters.KernelDr2 = Ke386GetDr2();
+    ProcessorState->SpecialRegisters.KernelDr3 = Ke386GetDr3();
+    ProcessorState->SpecialRegisters.KernelDr6 = Ke386GetDr6();
+    ProcessorState->SpecialRegisters.KernelDr7 = Ke386GetDr7();
+    Ke386SetDr7(0);
 
     /* Save GDT, IDT, LDT and TSS */
     Ke386GetGlobalDescriptorTable(ProcessorState->SpecialRegisters.Gdtr);
@@ -724,7 +724,7 @@
 Ki386EnableDE(IN ULONG_PTR Context)
 {
     /* Enable DE */
-    Ke386SetCr4(Ke386GetCr4() | CR4_DE);
+    __writecr4(__readcr4() | CR4_DE);
     return 0;
 }
 
@@ -733,7 +733,7 @@
 Ki386EnableFxsr(IN ULONG_PTR Context)
 {
     /* Enable FXSR */
-    Ke386SetCr4(Ke386GetCr4() | CR4_FXSR);
+    __writecr4(__readcr4() | CR4_FXSR);
     return 0;
 }
 

Modified: trunk/reactos/ntoskrnl/ke/i386/patpge.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/patpge.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ke/i386/patpge.c (original)
+++ trunk/reactos/ntoskrnl/ke/i386/patpge.c Wed Oct 25 21:15:11 2006
@@ -38,15 +38,15 @@
     }
 
     /* Now get CR4 and make sure PGE is masked out */
-    Cr4 = Ke386GetCr4();
-    Ke386SetCr4(Cr4 & ~CR4_PGE);
+    Cr4 = __readcr4();
+    __writecr4(Cr4 & ~CR4_PGE);
 
     /* Flush the TLB */
-    Cr3 = Ke386GetCr3();
-    Ke386SetCr3(Cr3);
+    Cr3 = __readcr3();
+    __writecr3(Cr3);
 
     /* Now enable PGE */
-    Ke386SetCr4(Cr4 | CR4_PGE);
+    __writecr4(Cr4 | CR4_PGE);
     Ke386GlobalPagesEnabled = TRUE;
 
     /* Restore interrupts */

Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/i386/page.c (original)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c Wed Oct 25 21:15:11 2006
@@ -122,7 +122,7 @@
 PULONG
 MmGetPageDirectory(VOID)
 {
-   return (PULONG)Ke386GetCr3();
+   return (PULONG)__readcr3();
 }
 
 static ULONG

Modified: trunk/reactos/ntoskrnl/mm/i386/pfault.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/pfault.c?rev=24651&r1=24650&r2=24651&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/i386/pfault.c (original)
+++ trunk/reactos/ntoskrnl/mm/i386/pfault.c Wed Oct 25 21:15:11 2006
@@ -37,7 +37,7 @@
    ASSERT(ExceptionNr == 14);
    
    /* get the faulting address */
-   cr2 = Ke386GetCr2();
+   cr2 = __readcr2();
    Tf->DbgArgPointer = cr2;
 
    /* it's safe to enable interrupts after cr2 has been saved */




More information about the Ros-diffs mailing list