Tcl Source Code

Artifact [403ead907c]
Login

Artifact 403ead907c3235f4ee99f8f18e9f4b451302f932:

Attachment "3059922_2.patch" to ticket [3059922fff] added by nijtmans 2010-12-14 18:47:04.
Index: win/tclWin32Dll.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWin32Dll.c,v
retrieving revision 1.71
diff -u -r1.71 tclWin32Dll.c
--- win/tclWin32Dll.c	19 Nov 2010 20:47:09 -0000	1.71
+++ win/tclWin32Dll.c	14 Dec 2010 11:28:48 -0000
@@ -718,12 +718,42 @@
     unsigned int index,		/* Which CPUID value to retrieve. */
     unsigned int *regsPtr)	/* Registers after the CPUID. */
 {
-#if defined(__GNUC__) && !defined(_WIN64)
-    EXCEPTION_REGISTRATION registration;
-#endif
     int status = TCL_ERROR;
 
-#if defined(__GNUC__) && !defined(_WIN64)
+#if defined(__GNUC__)
+#   if defined(_WIN64)
+    /*
+     * Execute the CPUID instruction with the given index, and store results
+     * off 'regPtr'.
+     */
+
+    __asm__ __volatile__(
+	/*
+	 * Do the CPUID instruction, and save the results in the 'regsPtr'
+	 * area.
+	 */
+
+	"movl	%[rptr],	%%edi"		"\n\t"
+	"movl	%[index],	%%eax"		"\n\t"
+	"cpuid"					"\n\t"
+	"movl	%%eax,		0x0(%%edi)"	"\n\t"
+	"movl	%%ebx,		0x4(%%edi)"	"\n\t"
+	"movl	%%ecx,		0x8(%%edi)"	"\n\t"
+	"movl	%%edx,		0xc(%%edi)"	"\n\t"
+
+	:
+	/* No outputs */
+	:
+	[index]		"m"	(index),
+	[rptr]		"m"	(regsPtr)
+	:
+	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
+    status = TCL_OK;
+
+#   else
+
+    EXCEPTION_REGISTRATION registration;
+
     /*
      * Execute the CPUID instruction with the given index, and store results
      * off 'regPtr'.
@@ -805,7 +835,51 @@
 	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
     status = registration.status;
 
-#elif defined(_MSC_VER) && !defined(_WIN64)
+#   endif
+#elif defined(_MSC_VER)
+#   ifdef defined(_WIN64)
+    /*
+     * Define a structure in the stack frame to hold the registers.
+     */
+
+    struct {
+	DWORD dw0;
+	DWORD dw1;
+	DWORD dw2;
+	DWORD dw3;
+    } regs;
+    regs.dw0 = index;
+
+    /*
+     * Execute the CPUID instruction and save regs in the stack frame.
+     */
+
+    _asm {
+	push    ebx
+	push    ecx
+	push    edx
+	mov	    eax, regs.dw0
+	cpuid
+	mov	    regs.dw0, eax
+	mov	    regs.dw1, ebx
+	mov	    regs.dw2, ecx
+	mov	    regs.dw3, edx
+	pop	    edx
+	pop	    ecx
+	pop	    ebx
+    }
+
+    /*
+     * Copy regs back out to the caller.
+     */
+
+    regsPtr[0] = regs.dw0;
+    regsPtr[1] = regs.dw1;
+    regsPtr[2] = regs.dw2;
+    regsPtr[3] = regs.dw3;
+
+    status = TCL_OK;
+#   else
     /*
      * Define a structure in the stack frame to hold the registers.
      */
@@ -851,7 +925,7 @@
     } __except(EXCEPTION_EXECUTE_HANDLER) {
 	/* do nothing */
     }
-
+#   endif
 #else
     /*
      * Don't know how to do assembly code for this compiler and/or