Skip to content

Commit

Permalink
Implement assembly functions using inline __asm
Browse files Browse the repository at this point in the history
This avoids having to rely on MASM.
  • Loading branch information
friendlyanon committed May 1, 2024
1 parent 16298c1 commit 63c4752
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 68 deletions.
9 changes: 2 additions & 7 deletions wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions wrappers/cas.asm

This file was deleted.

10 changes: 0 additions & 10 deletions wrappers/cas.h

This file was deleted.

28 changes: 0 additions & 28 deletions wrappers/detect486.asm

This file was deleted.

26 changes: 26 additions & 0 deletions wrappers/detect486.c
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 1 addition & 5 deletions wrappers/detect486.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion wrappers/kernel32.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdio.h>
#include <windows.h>

#include "cas.h"
#include "debug.h"
#include "detect486.h"

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 63c4752

Please sign in to comment.