Signed-off-by: Zebediah Figura z.figura12@gmail.com --- Fixes https://bugs.winehq.org/show_bug.cgi?id=42267
Inspired by a patch by Sebastian Lackner.
dlls/ntdll/large_int.c | 76 ++++++++++++++++++++++++++++++ dlls/ntdll/ntdll.spec | 4 +- dlls/ntdll/tests/large_int.c | 92 ++++++++++++++++++++++++++++++++++++- dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 4 +- 4 files changed, 171 insertions(+), 5 deletions(-)
diff --git a/dlls/ntdll/large_int.c b/dlls/ntdll/large_int.c index a0d465c..b7d074f 100644 --- a/dlls/ntdll/large_int.c +++ b/dlls/ntdll/large_int.c @@ -627,6 +627,44 @@ LONGLONG WINAPI _allshr( LONGLONG a, LONG b ) }
/****************************************************************************** + * _alldvrm (NTDLL.@) + * + * Divide two 64 bit integers. + * + * PARAMS + * a [I] Initial number. + * b [I] Number to divide a by. + * + * RETURNS + * Returns the quotient of a and b in edx:eax. + * Returns the remainder of a and b in ebx:ecx. + */ +__ASM_STDCALL_FUNC( _alldvrm, 16, + "pushl %ebp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") + __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") + "movl %esp,%ebp\n\t" + __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") + "pushl 20(%ebp)\n\t" + "pushl 16(%ebp)\n\t" + "pushl 12(%ebp)\n\t" + "pushl 8(%ebp)\n\t" + "call _allrem\n\t" + "movl %edx, %ebx\n\t" + "movl %eax, %ecx\n\t" + "pushl %ecx\n\t" + "pushl 20(%ebp)\n\t" + "pushl 16(%ebp)\n\t" + "pushl 12(%ebp)\n\t" + "pushl 8(%ebp)\n\t" + "call _alldiv\n\t" + "popl %ecx\n\t" + "leave\n\t" + __ASM_CFI(".cfi_def_cfa %esp,4\n\t") + __ASM_CFI(".cfi_same_value %ebp\n\t") + "ret $16" ) + +/****************************************************************************** * _aullrem (NTDLL.@) * * Calculate the remainder after dividing two 64 bit unsigned integers. @@ -660,4 +698,42 @@ ULONGLONG WINAPI _aullshr( ULONGLONG a, LONG b ) return a >> b; }
+/****************************************************************************** + * _aulldvrm (NTDLL.@) + * + * Divide two 64 bit unsigned integers. + * + * PARAMS + * a [I] Initial number. + * b [I] Number to divide a by. + * + * RETURNS + * Returns the quotient of a and b in edx:eax. + * Returns the remainder of a and b in ebx:ecx. + */ +__ASM_STDCALL_FUNC( _aulldvrm, 16, + "pushl %ebp\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") + __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") + "movl %esp,%ebp\n\t" + __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") + "pushl 20(%ebp)\n\t" + "pushl 16(%ebp)\n\t" + "pushl 12(%ebp)\n\t" + "pushl 8(%ebp)\n\t" + "call _aullrem\n\t" + "movl %edx, %ebx\n\t" + "movl %eax, %ecx\n\t" + "pushl %ecx\n\t" + "pushl 20(%ebp)\n\t" + "pushl 16(%ebp)\n\t" + "pushl 12(%ebp)\n\t" + "pushl 8(%ebp)\n\t" + "call _aulldiv\n\t" + "popl %ecx\n\t" + "leave\n\t" + __ASM_CFI(".cfi_def_cfa %esp,4\n\t") + __ASM_CFI(".cfi_same_value %ebp\n\t") + "ret $16" ) + #endif /* __i386__ */ diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 0107932..8744704 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1337,7 +1337,7 @@ @ cdecl -private __iscsymf(long) NTDLL___iscsymf @ cdecl -private __toascii(long) NTDLL___toascii @ stdcall -arch=i386 -ret64 _alldiv(int64 int64) -# @ stub _alldvrm +@ stdcall -arch=i386 -norelay _alldvrm(int64 int64) @ stdcall -arch=i386 -ret64 _allmul(int64 int64) @ stdcall -arch=i386 -norelay _alloca_probe() @ stdcall -arch=i386 -ret64 _allrem(int64 int64) @@ -1345,7 +1345,7 @@ @ stdcall -arch=i386 -ret64 _allshr(int64 long) @ cdecl -private -ret64 _atoi64(str) @ stdcall -arch=i386 -ret64 _aulldiv(int64 int64) -# @ stub _aulldvrm +@ stdcall -arch=i386 -norelay _aulldvrm(int64 int64) @ stdcall -arch=i386 -ret64 _aullrem(int64 int64) @ stdcall -arch=i386 -ret64 _aullshr(int64 long) @ stdcall -private -arch=i386 -norelay _chkstk() diff --git a/dlls/ntdll/tests/large_int.c b/dlls/ntdll/tests/large_int.c index da7afa4..70ea0b0 100644 --- a/dlls/ntdll/tests/large_int.c +++ b/dlls/ntdll/tests/large_int.c @@ -33,7 +33,8 @@ static VOID (WINAPI *pRtlFreeAnsiString)(PSTRING); static NTSTATUS (WINAPI *pRtlInt64ToUnicodeString)(ULONGLONG, ULONG, UNICODE_STRING *); static NTSTATUS (WINAPI *pRtlLargeIntegerToChar)(ULONGLONG *, ULONG, ULONG, PCHAR); static NTSTATUS (WINAPI *pRtlUnicodeStringToAnsiString)(STRING *, const UNICODE_STRING *, BOOLEAN); - +static LONGLONG (WINAPI *p_alldvrm)(LONGLONG, LONGLONG); +static ULONGLONG (WINAPI *p_aulldvrm)(ULONGLONG, ULONGLONG);
static void InitFunctionPtrs(void) { @@ -45,6 +46,8 @@ static void InitFunctionPtrs(void) pRtlInt64ToUnicodeString = (void *)GetProcAddress(hntdll, "RtlInt64ToUnicodeString"); pRtlLargeIntegerToChar = (void *)GetProcAddress(hntdll, "RtlLargeIntegerToChar"); pRtlUnicodeStringToAnsiString = (void *)GetProcAddress(hntdll, "RtlUnicodeStringToAnsiString"); + p_alldvrm = (void *)GetProcAddress(hntdll, "_alldvrm"); + p_aulldvrm = (void *)GetProcAddress(hntdll, "_aulldvrm"); } /* if */ }
@@ -434,6 +437,90 @@ static void test_RtlLargeIntegerToChar(void) largeint2str[0].base, largeint2str[0].MaximumLength, result, STATUS_ACCESS_VIOLATION); }
+#ifdef __i386__ +static LONGLONG _alldvrm_wrapper(LARGE_INTEGER a, LARGE_INTEGER b, LARGE_INTEGER *rem) +{ + /* _alldvrm() divides two LONGLONGs and returns the quotient in edx:eax and + * the remainder in ebx:ecx. */ + + LONGLONG ret; + + __asm__ __volatile__ ( + "pushl %%ebx\n\t" + "pushl %3\n\t" + "pushl %4\n\t" + "pushl %5\n\t" + "pushl %6\n\t" + "call *%7\n\t" + "movl %%ebx, %1\n\t" + "movl %%ecx, %2\n\t" + "popl %%ebx\n\t" + : "=A" (ret), "=r" (rem->HighPart), "=r" (rem->LowPart) + : "ri" (b.HighPart), "ri" (b.LowPart), "ri" (a.HighPart), "ri" (a.LowPart), "m" (p_alldvrm) + : "ebx", "ecx" + ); + + return ret; +} + +static ULONGLONG _aulldvrm_wrapper(ULARGE_INTEGER a, ULARGE_INTEGER b, ULARGE_INTEGER *rem) +{ + ULONGLONG ret; + + __asm__ __volatile__ ( + "pushl %%ebx\n\t" + "pushl %3\n\t" + "pushl %4\n\t" + "pushl %5\n\t" + "pushl %6\n\t" + "call *%7\n\t" + "movl %%ebx, %1\n\t" + "movl %%ecx, %2\n\t" + "popl %%ebx\n\t" + : "=A" (ret), "=r" (rem->HighPart), "=r" (rem->LowPart) + : "ri" (b.HighPart), "ri" (b.LowPart), "ri" (a.HighPart), "ri" (a.LowPart), "m" (p_aulldvrm) + : "ebx", "ecx" + ); + + return ret; +} + +static void test__alldvrm(void) +{ + ULARGE_INTEGER ua, ub, urem; + LARGE_INTEGER a, b, rem; + ULONGLONG uret; + LONGLONG ret; + + /* _alldvrm(0x0123456701234567, 3) */ + a.HighPart = a.LowPart = 0x01234567; + b.QuadPart = 3; + ret = _alldvrm_wrapper(a, b, &rem); + ok(ret == 0x61172255b66c77ULL, "got %x%08x\n", (DWORD)(ret >> 32), (DWORD)ret); + ok(rem.QuadPart == 2, "got %x%08x\n", rem.HighPart, rem.LowPart); + + /* _alldvrm(0x0123456701234567, -3) */ + a.HighPart = a.LowPart = 0x01234567; + b.QuadPart = -3; + ret = _alldvrm_wrapper(a, b, &rem); + ok(ret == 0xff9ee8ddaa499389ULL, "got %x%08x\n", (DWORD)(ret >> 32), (DWORD)ret); + ok(rem.QuadPart == 2, "got %x%08x\n", rem.HighPart, rem.LowPart); + + /* _aulldvrm(0x0123456701234567, 3) */ + ua.HighPart = ua.LowPart = 0x01234567; + ub.QuadPart = 3; + uret = _aulldvrm_wrapper(ua, ub, &urem); + ok(uret == 0x61172255b66c77ULL, "got %x%08x\n", (DWORD)(uret >> 32), (DWORD)uret); + ok(urem.QuadPart == 2, "got %x%08x\n", urem.HighPart, urem.LowPart); + + /* _aulldvrm(0x0123456701234567, -3) */ + ua.HighPart = ua.LowPart = 0x01234567; + ub.QuadPart = -3; + uret = _aulldvrm_wrapper(ua, ub, &urem); + ok(uret == 0, "got %x%08x\n", (DWORD)(uret >> 32), (DWORD)uret); + ok(urem.QuadPart == ua.QuadPart, "got %x%08x\n", urem.HighPart, urem.LowPart); +} +#endif /* __i386__ */
START_TEST(large_int) { @@ -445,4 +532,7 @@ START_TEST(large_int) test_RtlInt64ToUnicodeString(); if (pRtlLargeIntegerToChar) test_RtlLargeIntegerToChar(); +#ifdef __i386__ + test__alldvrm(); +#endif /* __i386__ */ } diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec index 26afa6f..49f529a 100644 --- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec +++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec @@ -1407,14 +1407,14 @@ @ cdecl -private -arch=i386 _CIsqrt() msvcrt._CIsqrt @ cdecl -private _abnormal_termination() msvcrt._abnormal_termination @ stdcall -private -arch=i386 -ret64 _alldiv(int64 int64) -@ stub _alldvrm +@ stdcall -private -arch=i386 -norelay _alldvrm(int64 int64) @ stdcall -private -arch=i386 -ret64 _allmul(int64 int64) @ stdcall -private -arch=i386 -norelay _alloca_probe() @ stdcall -private -arch=i386 -ret64 _allrem(int64 int64) @ stdcall -private -arch=i386 -ret64 _allshl(int64 long) @ stdcall -private -arch=i386 -ret64 _allshr(int64 long) @ stdcall -private -arch=i386 -ret64 _aulldiv(int64 int64) -@ stub _aulldvrm +@ stdcall -private -arch=i386 -norelay _aulldvrm(int64 int64) @ stdcall -private -arch=i386 -ret64 _aullrem(int64 int64) @ stdcall -private -arch=i386 -ret64 _aullshr(int64 long) @ stdcall -private -arch=i386 -norelay _chkstk()