Author: tkreuzer
Date: Wed Oct 12 21:11:02 2011
New Revision: 54097
URL:
http://svn.reactos.org/svn/reactos?rev=54097&view=rev
Log:
[RTL]
On x86 builds use the asm versions of the byte swap functions. This is neccessary for
RtlUlonglongByteswap, because the function breaks the calling convention on Windows, not
cleaning up the stack. Make the asm compatible to ML and improve it a bit. Investigated by
Thomas Faber.
Modified:
trunk/reactos/lib/rtl/CMakeLists.txt
trunk/reactos/lib/rtl/byteswap.c
trunk/reactos/lib/rtl/i386/rtlswap.S
trunk/reactos/lib/rtl/rtl.rbuild
Modified: trunk/reactos/lib/rtl/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/CMakeLists.txt?rev…
==============================================================================
--- trunk/reactos/lib/rtl/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/CMakeLists.txt [iso-8859-1] Wed Oct 12 21:11:02 2011
@@ -14,7 +14,6 @@
avltable.c
bitmap.c
bootdata.c
- byteswap.c
compress.c
condvar.c
crc32.c
@@ -71,10 +70,12 @@
i386/except.c
i386/interlck.S
i386/rtlmem.s
+ i386/rtlswap.s
i386/res_asm.s
i386/thread.c)
elseif(ARCH MATCHES amd64)
list(APPEND SOURCE
+ byteswap.c
amd64/debug_asm.S
amd64/except_asm.S
amd64/slist.S
@@ -83,10 +84,12 @@
mem.c)
elseif(ARCH MATCHES arm)
list(APPEND SOURCE
+ byteswap.c
arm/debug_asm.S
mem.c)
elseif(ARCH MATCHES powerpc)
list(APPEND SOURCE
+ byteswap.c
powerpc/debug.c
powerpc/except.c
powerpc/interlocked.c
Modified: trunk/reactos/lib/rtl/byteswap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/byteswap.c?rev=540…
==============================================================================
--- trunk/reactos/lib/rtl/byteswap.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/byteswap.c [iso-8859-1] Wed Oct 12 21:11:02 2011
@@ -11,6 +11,11 @@
#define NDEBUG
#include <debug.h>
+
+#if defined(_M_IX86)
+/* RtlUlonglongByteSwap is broken and cannot be done in C on x86 */
+#error "Use rtlswap.S!"
+#endif
#undef RtlUlonglongByteSwap
#undef RtlUlongByteSwap
@@ -31,7 +36,7 @@
RtlUshortByteSwap(
IN USHORT Source)
{
-#if defined(_M_IX86) || defined(_M_AMD64)
+#if defined(_M_AMD64)
return _byteswap_ushort(Source);
#else
return (Source >> 8) | (Source << 8);
@@ -55,7 +60,7 @@
RtlUlongByteSwap(
IN ULONG Source)
{
-#if defined(_M_IX86) || defined(_M_AMD64)
+#if defined(_M_AMD64)
return _byteswap_ulong(Source);
#else
return ((ULONG)RtlUshortByteSwap((USHORT)Source) << 16) |
RtlUshortByteSwap((USHORT)(Source >> 16));
@@ -80,7 +85,7 @@
RtlUlonglongByteSwap(
IN ULONGLONG Source)
{
-#if defined(_M_IX86) || defined(_M_AMD64)
+#if defined(_M_AMD64)
return _byteswap_uint64(Source);
#else
return ((ULONGLONG) RtlUlongByteSwap (Source) << 32) | RtlUlongByteSwap
(Source>>32);
Modified: trunk/reactos/lib/rtl/i386/rtlswap.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/i386/rtlswap.S?rev…
==============================================================================
--- trunk/reactos/lib/rtl/i386/rtlswap.S [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/i386/rtlswap.S [iso-8859-1] Wed Oct 12 21:11:02 2011
@@ -4,50 +4,55 @@
* PURPOSE: Byte swap functions
* FILE: lib/rtl/i386/rtlswap.S
* PROGRAMER: Alex Ionescu (alex.ionescu(a)reactos.org)
+ * Timo Kreuzer (timo.kreuzer(a)reactos.org)
*/
-.intel_syntax noprefix
+#include <asm.inc>
-.globl @RtlUshortByteSwap@4
-.globl @RtlUlongByteSwap@4
-.globl @RtlUlonglongByteSwap@8
+PUBLIC @RtlUshortByteSwap@4
+PUBLIC @RtlUlongByteSwap@4
+PUBLIC @RtlUlonglongByteSwap@8
/* FUNCTIONS ***************************************************************/
+.code
-.func @RtlUshortByteSwap@4, @RtlUshortByteSwap@4
@RtlUshortByteSwap@4:
+FUNC RtlUshortByteSwap
+ FPO 0, 0, 0, 0, 0, FRAME_FPO
/* Swap high and low bits */
mov ah, cl
mov al, ch
ret
-.endfunc
+ENDFUNC RtlUshortByteSwap
-.func @RtlUlongByteSwap@4, @RtlUlongByteSwap@4
@RtlUlongByteSwap@4:
+FUNC RtlUlongByteSwap
+ FPO 0, 0, 0, 0, 0, FRAME_FPO
/* Swap high and low bits */
mov eax, ecx
bswap eax
ret
-.endfunc
+ENDFUNC RtlUlongByteSwap
-.func @RtlUlonglongByteSwap@8, @RtlUlonglongByteSwap@8
@RtlUlonglongByteSwap@8:
+FUNC RtlUlonglongByteSwap
+ FPO 0, 2, 0, 0, 0, FRAME_FPO
/* Get 64-bit integer */
- mov edx, [esp+8]
- mov eax, [esp+4]
+ mov eax, [esp+8]
+ mov edx, [esp+4]
/* Swap it */
bswap edx
bswap eax
- /* Return it */
- mov ecx, eax
- mov eax, edx
- mov edx, ecx
+ /* Return it (NOTE: this might look wrong, since fastcall functions
+ should clean up the stack, even if the first parameter is an ULONGLONG,
+ and therefore put on tthe stack instead of in ecx and edx,
+ but thats exactly how the function behaves on Windows! */
ret
-.endfunc
+ENDFUNC RtlUlonglongByteSwap
-
+END
Modified: trunk/reactos/lib/rtl/rtl.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rtl.rbuild?rev=540…
==============================================================================
--- trunk/reactos/lib/rtl/rtl.rbuild [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/rtl.rbuild [iso-8859-1] Wed Oct 12 21:11:02 2011
@@ -20,6 +20,7 @@
</directory>
</if>
<if property="ARCH" value="powerpc">
+ <file>byteswap.c</file>
<directory name="powerpc">
<file>debug.c</file>
<file>except.c</file>
@@ -30,12 +31,14 @@
</directory>
</if>
<if property="ARCH" value="arm">
+ <file>byteswap.c</file>
<directory name="arm">
<file>debug_asm.S</file>
</directory>
<file>mem.c</file>
</if>
<if property="ARCH" value="amd64">
+ <file>byteswap.c</file>
<directory name="amd64">
<file>debug_asm.S</file>
<file>except_asm.S</file>
@@ -51,7 +54,6 @@
<file>assert.c</file>
<file>atom.c</file>
<file>avltable.c</file>
- <file>byteswap.c</file>
<file>bitmap.c</file>
<file>bootdata.c</file>
<file>compress.c</file>