Author: greatlrd
Date: Sun Dec 10 20:39:01 2006
New Revision: 25117
URL: http://svn.reactos.org/svn/reactos?rev=25117&view=rev
Log:
commit the patch from bug 1874 even it does not use the RDMSR and WRMSR measure methood, we need use the RDMSR and WRMSR for dual core and CPU support it see Intel documentations AP-485, who u should do it. The patch is from HTO Bugfix detections of RTSC support for single and dual core by me, adding check if the CPU support RDMSR and WRMSR and send a true or false value to GetCpuSpeed, so we known which method we should use. HTO patch should be use when it is false. other wise we should use the RDMSR and WRMSR measure method
See issue #1874 for more details.
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/i386/hwcpu.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hwcpu.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/hwcpu.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hwcpu.c Sun Dec 10 20:39:01 2006
@@ -24,6 +24,12 @@
#define NDEBUG
#include <debug.h>
+#define HZ (100)
+#define CLOCK_TICK_RATE (1193182)
+#define LATCH (CLOCK_TICK_RATE / HZ)
+#define CALIBRATE_LATCH (5 * LATCH)
+#define CALIBRATE_TIME (5 * 1000020/HZ)
+
#define MP_FP_SIGNATURE 0x5F504D5F /* "_MP_" */
#define MP_CT_SIGNATURE 0x504D4350 /* "PCMP" */
@@ -73,17 +79,44 @@
/* FUNCTIONS ****************************************************************/
static ULONG
-GetCpuSpeed(VOID)
+GetCpuSpeed(BOOLEAN DualCoreSpeedMesure)
{
ULONGLONG Timestamp1;
ULONGLONG Timestamp2;
ULONGLONG Diff;
+ ULONG Count = 0;
+
+ /*
+ FIXME
+ if the DualCoreSpeedMesure is true we need
+ use the wrmsr and rdmsr to mesure the speed
+
+ The rdtc are outdate to use if cpu support
+ the wrmsr and rdmsr, see intel doc AP-485
+ for more informations and how to use it.
+
+ Follow code is good on cpu that does not
+ support dual core or have a mmx unit or
+ more.
+ */
+
+
+ /* Initialise timer channel 2 */
+ /* Set the Gate high, disable speaker */
+ WRITE_PORT_UCHAR((PUCHAR)0x61, (READ_PORT_UCHAR((PUCHAR)0x61) & ~0x02) | 0x01);
+ WRITE_PORT_UCHAR((PUCHAR)0x43, 0xB0); /* binary, mode 0, LSB/MSB, ch 2 */
+ WRITE_PORT_UCHAR((PUCHAR)0x42, CALIBRATE_LATCH & 0xff); /* LSB */
+ WRITE_PORT_UCHAR((PUCHAR)0x42, CALIBRATE_LATCH >> 8); /* MSB */
/* Read TSC (Time Stamp Counter) */
Timestamp1 = RDTSC();
- /* Wait for 0.1 seconds (= 100 milliseconds = 100000 microseconds)*/
- StallExecutionProcessor(100000);
+ /* Wait */
+ do
+ {
+ Count++;
+ }
+ while ((READ_PORT_UCHAR((PUCHAR)0x61) & 0x20) == 0);
/* Read TSC (Time Stamp Counter) again */
Timestamp2 = RDTSC();
@@ -98,7 +131,7 @@
Diff = Timestamp2 + (((ULONGLONG)-1) - Timestamp1);
}
- return (ULONG)(Diff / 100000);
+ return (ULONG)(Diff / CALIBRATE_TIME);
}
@@ -123,7 +156,7 @@
LONG Error;
BOOLEAN SupportTSC = FALSE;
ULONG CpuSpeed;
-
+ BOOLEAN DualCoreSpeedMesure = FALSE;
/* Create the CPU instance key */
Error = RegCreateKey(CpuKey,
@@ -169,8 +202,12 @@
(unsigned int)((eax >> 4) & 0x0F),
(unsigned int)(eax & 0x0F));
FeatureSet = edx;
- if (((eax >> 8) & 0x0F) >= 5)
+
+ if ((FeatureSet & 0x10) == 0x10)
SupportTSC = TRUE;
+
+ if ((FeatureSet & 0x20) == 0x20)
+ DualCoreSpeedMesure = TRUE;
/* Check if Extended CPUID information is supported */
GetCpuid(0x80000000, &eax, &ebx, &ecx, &edx);
@@ -283,7 +320,7 @@
/* Set '~MHz' value (CPU only) */
if (SupportTSC)
{
- CpuSpeed = GetCpuSpeed();
+ CpuSpeed = GetCpuSpeed(DualCoreSpeedMesure);
Error = RegSetValue(CpuInstKey,
L"~MHz",
@@ -467,9 +504,19 @@
/* FIXME: Set 'Update Status' value (CPU only) */
/* Set '~MHz' value (CPU only) */
- if (((CpuEntry->CpuSignature >> 8) & 0x0F) >= 5)
- {
- CpuSpeed = GetCpuSpeed();
+
+
+ if ((CpuEntry->FeatureFlags & 0x10) == 0x10)
+ {
+ if ((CpuEntry->FeatureFlags & 0x20) == 0x20)
+ {
+ CpuSpeed = GetCpuSpeed(TRUE);
+ }
+ else
+ {
+ DbgPrint((DPRINT_HWDETECT, "Does not support MSR that are need for mesure the speed correct\n", (int)Error));
+ CpuSpeed = GetCpuSpeed(FALSE);
+ }
Error = RegSetValue(CpuInstKey,
L"~MHz",
@@ -477,10 +524,11 @@
(PCHAR)&CpuSpeed,
sizeof(ULONG));
if (Error != ERROR_SUCCESS)
- {
- DbgPrint((DPRINT_HWDETECT, "RegSetValue() failed (Error %u)\n", (int)Error));
- }
- }
+ {
+
+ DbgPrint((DPRINT_HWDETECT, "RegSetValue() failed (Error %u)\n", (int)Error));
+ }
+ }
}
Author: greatlrd
Date: Sun Dec 10 13:44:39 2006
New Revision: 25112
URL: http://svn.reactos.org/svn/reactos?rev=25112&view=rev
Log:
fixed some check in createsurface so user can not easy crash it.
Modified:
trunk/reactos/dll/directx/ddraw/main/ddraw_main.c
Modified: trunk/reactos/dll/directx/ddraw/main/ddraw_main.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ddraw/main/ddr…
==============================================================================
--- trunk/reactos/dll/directx/ddraw/main/ddraw_main.c (original)
+++ trunk/reactos/dll/directx/ddraw/main/ddraw_main.c Sun Dec 10 13:44:39 2006
@@ -187,16 +187,57 @@
DDHAL_CREATESURFACEDATA mDdCreateSurface;
LPDDRAWI_DDRAWSURFACE_MORE SurfaceMore;
+ /*
+ * check if pUnkOuter is NULL if it is not fail
+ * for accrdiong msdn and own test this member is not
+ * set.
+ */
+
if (pUnkOuter!=NULL)
{
return CLASS_E_NOAGGREGATION;
}
- if (sizeof(DDSURFACEDESC2)!=pDDSD->dwSize && sizeof(DDSURFACEDESC)!=pDDSD->dwSize)
+ /* Check so it is vaild pointer we got of ppSurf */
+ if (IsBadWritePtr( ppSurf, sizeof( LPDIRECTDRAWSURFACE7 )) )
+ {
+ return DDERR_INVALIDPARAMS;
+ }
+
+ /* Check so it is vaild pointer we got of pDDSD
+ */
+ if (IsBadWritePtr( pDDSD, sizeof( LPDDSURFACEDESC2 )) )
+ {
+ return DDERR_INVALIDPARAMS;
+ }
+
+ if (IsBadReadPtr(pDDSD, sizeof( LPDDSURFACEDESC2 )) )
+ {
+ return DDERR_INVALIDPARAMS;
+ }
+
+ /* Check if it version 1 or version 2 of the DDSURFACEDESC struct
+ * both struct are vaild.
+ */
+ if (sizeof(DDSURFACEDESC2)!=pDDSD->dwSize)
{
return DDERR_UNSUPPORTED;
}
+
+
+ /* here we need start fixing bugs
+ * the code above is 100% correct behovir
+ * checked how ms ddraw behivor
+ */
+
+ /* FIXME
+ * Alloc memory for the ppSurf pointer
+ * we expect it is NULL, But we maybe should add a NULL check
+ * for it, so we do not over write it, and also add a pointer vaildate
+ * for it.
+ */
+
That = (LPDDRAWI_DDRAWSURFACE_INT)DxHeapMemAlloc(sizeof(DDRAWI_DDRAWSURFACE_INT));
if (That == NULL)
@@ -204,26 +245,34 @@
return E_OUTOFMEMORY;
}
- That->lpLcl = (LPDDRAWI_DDRAWSURFACE_LCL)DxHeapMemAlloc(sizeof(DDRAWI_DDRAWSURFACE_LCL));
-
- if (That == NULL)
- {
+ /* FIXME
+ Alloc memory for the local surface struct we need
+ we should check if NULL or not see comment above
+ */
+ That->lpLcl = (LPDDRAWI_DDRAWSURFACE_LCL)DxHeapMemAlloc(sizeof(DDRAWI_DDRAWSURFACE_LCL));
+ if (That->lpLcl == NULL)
+ {
+ /* shall we free it if it fail ?? */
+ DxHeapMemFree(That);
return E_OUTOFMEMORY;
}
- SurfaceMore = DxHeapMemAlloc(sizeof(DDRAWI_DDRAWSURFACE_MORE));
- if (SurfaceMore == NULL)
- {
+ /* Alloc memory for DDRAWI_DDRAWSURFACE_MORE */
+ That->lpLcl->lpSurfMore = DxHeapMemAlloc(sizeof(DDRAWI_DDRAWSURFACE_MORE));
+ if (That->lpLcl->lpSurfMore == NULL)
+ {
+ /* shall we free it if it fail ?? */
+ DxHeapMemFree(That->lpLcl);
+ DxHeapMemFree(That);
return DDERR_OUTOFMEMORY;
}
- That->lpVtbl = &DirectDrawSurface7_Vtable;
+ /* setup some value */
*ppSurf = (LPDIRECTDRAWSURFACE7)That;
-
+ That->lpVtbl = &DirectDrawSurface7_Vtable;
That->lpLcl->lpGbl = &ddSurfGbl;
- That->lpLcl->lpGbl->lpDD = &ddgbl;
- That->lpLcl->lpSurfMore = SurfaceMore;
+ That->lpLcl->lpGbl->lpDD = &ddgbl;
That->lpLcl->lpSurfMore->dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
That->lpLcl->lpSurfMore->lpDD_int = This;
That->lpLcl->lpSurfMore->lpDD_lcl = This->lpLcl;
@@ -232,6 +281,14 @@
/* this two line should be move to startup code */
That->lpLcl->lpGbl->lpDD = This->lpLcl->lpGbl;
That->lpLcl->lpGbl->lpDDHandle = This->lpLcl->lpGbl;
+
+
+ /* setup the callback struct right
+ * maybe we should fill in
+ * xx.lpDD, xx.function, xx.ddRVal
+ * in startup and do a cache of it
+ * to save time ??
+ */
mDdCanCreateSurface.lpDD = This->lpLcl->lpGbl;
mDdCanCreateSurface.bIsDifferentPixelFormat = FALSE; //isDifferentPixelFormat;