diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index 402974c..048da3e 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -12,12 +12,7 @@ target_compile_definitions(corkdebug PRIVATE _CRT_SECURE_NO_WARNINGS=1) add_library( detect486 OBJECT - detect486.asm -) - -add_library( - cas OBJECT - cas.asm + detect486.c ) include(CheckSymbolExists) @@ -31,7 +26,7 @@ add_library( comdlg32.c corkel32.def ) -target_link_libraries(corkel32 PRIVATE corkdebug detect486 cas) +target_link_libraries(corkel32 PRIVATE corkdebug detect486) target_compile_definitions(corkel32 PRIVATE _CRT_SECURE_NO_WARNINGS=1) # NTDLL => CORNT diff --git a/wrappers/cas.asm b/wrappers/cas.asm deleted file mode 100644 index 6e95593..0000000 --- a/wrappers/cas.asm +++ /dev/null @@ -1,17 +0,0 @@ -.486 -.MODEL FLAT - -.CODE - -OPTION PROLOGUE:NONE -OPTION EPILOGUE:NONE - -_InterlockedCompareExchange_486@12 PROC - mov ecx, DWORD PTR [esp + 4] ; dest - mov edx, DWORD PTR [esp + 8] ; exchange - mov eax, DWORD PTR [esp + 12] ; compare - lock cmpxchg DWORD PTR [ecx], edx - ret 12 -_InterlockedCompareExchange_486@12 ENDP - -END diff --git a/wrappers/cas.h b/wrappers/cas.h deleted file mode 100644 index c2a0ef3..0000000 --- a/wrappers/cas.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CAS -#define CAS - -#ifndef STDCALL -#define STDCALL __stdcall -#endif - -long STDCALL InterlockedCompareExchange_486(long* dest, long exchange, long compare); - -#endif // CAS diff --git a/wrappers/detect486.asm b/wrappers/detect486.asm deleted file mode 100644 index dbd4686..0000000 --- a/wrappers/detect486.asm +++ /dev/null @@ -1,28 +0,0 @@ -.386 -.MODEL FLAT, STDCALL - -.CODE - -is_cpu_486_or_newer PROC - pushfd - pop eax - mov ebx, eax - xor eax, 40000h ; toggle the AC bit in EFLAGS (only available in 486 or newer) - push eax - popfd - pushfd - pop eax - cmp eax, ebx - jz is_386 - push ebx - popfd - xor eax, eax - inc eax - ret - -is_386: - xor eax, eax - ret -is_cpu_486_or_newer ENDP - -END diff --git a/wrappers/detect486.c b/wrappers/detect486.c new file mode 100644 index 0000000..435158b --- /dev/null +++ b/wrappers/detect486.c @@ -0,0 +1,26 @@ +#include "detect486.h" + +int __declspec(naked) is_cpu_486_or_newer(void) +{ + __asm { + pushfd + pop eax + mov ebx, eax + xor eax, 40000h ; toggle the AC bit in EFLAGS (only available in 486 or newer) + push eax + popfd + pushfd + pop eax + cmp eax, ebx + jz is_386 + push ebx + popfd + xor eax, eax + inc eax + ret + + is_386: + xor eax, eax + ret + } +} diff --git a/wrappers/detect486.h b/wrappers/detect486.h index 2670d23..c5522fe 100644 --- a/wrappers/detect486.h +++ b/wrappers/detect486.h @@ -1,10 +1,6 @@ #ifndef DETECT_486 #define DETECT_486 -#ifndef STDCALL -#define STDCALL __stdcall -#endif - -int STDCALL is_cpu_486_or_newer(void); +int is_cpu_486_or_newer(void); #endif // DETECT_486 diff --git a/wrappers/kernel32.c b/wrappers/kernel32.c index aa3d271..25e777f 100644 --- a/wrappers/kernel32.c +++ b/wrappers/kernel32.c @@ -1,7 +1,6 @@ #include #include -#include "cas.h" #include "debug.h" #include "detect486.h" @@ -155,6 +154,17 @@ BOOL WINAPI CORKEL32_DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVO return e; } +static LONG __declspec(naked) WINAPI InterlockedCompareExchange_486(LONG* dest, LONG xchg, LONG compare) +{ + __asm { + mov ecx, DWORD PTR [esp + 4] ; dest + mov edx, DWORD PTR [esp + 8] ; xchg + mov eax, DWORD PTR [esp + 12] ; compare + lock cmpxchg DWORD PTR [ecx], edx + ret 12 + } +} + // Reimplemented LONG WINAPI CORKEL32_InterlockedCompareExchange(LONG* dest, LONG xchg, LONG compare) {