mirror of
https://github.com/reactos/reactos.git
synced 2025-06-05 09:20:30 +00:00
[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. svn path=/trunk/; revision=54097
This commit is contained in:
parent
a38e883762
commit
d0d304b342
4 changed files with 37 additions and 22 deletions
|
@ -14,7 +14,6 @@ list(APPEND SOURCE
|
||||||
avltable.c
|
avltable.c
|
||||||
bitmap.c
|
bitmap.c
|
||||||
bootdata.c
|
bootdata.c
|
||||||
byteswap.c
|
|
||||||
compress.c
|
compress.c
|
||||||
condvar.c
|
condvar.c
|
||||||
crc32.c
|
crc32.c
|
||||||
|
@ -71,10 +70,12 @@ if(ARCH MATCHES i386)
|
||||||
i386/except.c
|
i386/except.c
|
||||||
i386/interlck.S
|
i386/interlck.S
|
||||||
i386/rtlmem.s
|
i386/rtlmem.s
|
||||||
|
i386/rtlswap.s
|
||||||
i386/res_asm.s
|
i386/res_asm.s
|
||||||
i386/thread.c)
|
i386/thread.c)
|
||||||
elseif(ARCH MATCHES amd64)
|
elseif(ARCH MATCHES amd64)
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
|
byteswap.c
|
||||||
amd64/debug_asm.S
|
amd64/debug_asm.S
|
||||||
amd64/except_asm.S
|
amd64/except_asm.S
|
||||||
amd64/slist.S
|
amd64/slist.S
|
||||||
|
@ -83,10 +84,12 @@ elseif(ARCH MATCHES amd64)
|
||||||
mem.c)
|
mem.c)
|
||||||
elseif(ARCH MATCHES arm)
|
elseif(ARCH MATCHES arm)
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
|
byteswap.c
|
||||||
arm/debug_asm.S
|
arm/debug_asm.S
|
||||||
mem.c)
|
mem.c)
|
||||||
elseif(ARCH MATCHES powerpc)
|
elseif(ARCH MATCHES powerpc)
|
||||||
list(APPEND SOURCE
|
list(APPEND SOURCE
|
||||||
|
byteswap.c
|
||||||
powerpc/debug.c
|
powerpc/debug.c
|
||||||
powerpc/except.c
|
powerpc/except.c
|
||||||
powerpc/interlocked.c
|
powerpc/interlocked.c
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <debug.h>
|
#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 RtlUlonglongByteSwap
|
||||||
#undef RtlUlongByteSwap
|
#undef RtlUlongByteSwap
|
||||||
#undef RtlUshortByteSwap
|
#undef RtlUshortByteSwap
|
||||||
|
@ -31,7 +36,7 @@ FASTCALL
|
||||||
RtlUshortByteSwap(
|
RtlUshortByteSwap(
|
||||||
IN USHORT Source)
|
IN USHORT Source)
|
||||||
{
|
{
|
||||||
#if defined(_M_IX86) || defined(_M_AMD64)
|
#if defined(_M_AMD64)
|
||||||
return _byteswap_ushort(Source);
|
return _byteswap_ushort(Source);
|
||||||
#else
|
#else
|
||||||
return (Source >> 8) | (Source << 8);
|
return (Source >> 8) | (Source << 8);
|
||||||
|
@ -55,7 +60,7 @@ FASTCALL
|
||||||
RtlUlongByteSwap(
|
RtlUlongByteSwap(
|
||||||
IN ULONG Source)
|
IN ULONG Source)
|
||||||
{
|
{
|
||||||
#if defined(_M_IX86) || defined(_M_AMD64)
|
#if defined(_M_AMD64)
|
||||||
return _byteswap_ulong(Source);
|
return _byteswap_ulong(Source);
|
||||||
#else
|
#else
|
||||||
return ((ULONG)RtlUshortByteSwap((USHORT)Source) << 16) | RtlUshortByteSwap((USHORT)(Source >> 16));
|
return ((ULONG)RtlUshortByteSwap((USHORT)Source) << 16) | RtlUshortByteSwap((USHORT)(Source >> 16));
|
||||||
|
@ -80,7 +85,7 @@ ULONGLONG FASTCALL
|
||||||
RtlUlonglongByteSwap(
|
RtlUlonglongByteSwap(
|
||||||
IN ULONGLONG Source)
|
IN ULONGLONG Source)
|
||||||
{
|
{
|
||||||
#if defined(_M_IX86) || defined(_M_AMD64)
|
#if defined(_M_AMD64)
|
||||||
return _byteswap_uint64(Source);
|
return _byteswap_uint64(Source);
|
||||||
#else
|
#else
|
||||||
return ((ULONGLONG) RtlUlongByteSwap (Source) << 32) | RtlUlongByteSwap (Source>>32);
|
return ((ULONGLONG) RtlUlongByteSwap (Source) << 32) | RtlUlongByteSwap (Source>>32);
|
||||||
|
|
|
@ -4,50 +4,55 @@
|
||||||
* PURPOSE: Byte swap functions
|
* PURPOSE: Byte swap functions
|
||||||
* FILE: lib/rtl/i386/rtlswap.S
|
* FILE: lib/rtl/i386/rtlswap.S
|
||||||
* PROGRAMER: Alex Ionescu (alex.ionescu@reactos.org)
|
* PROGRAMER: Alex Ionescu (alex.ionescu@reactos.org)
|
||||||
|
* Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.intel_syntax noprefix
|
#include <asm.inc>
|
||||||
|
|
||||||
.globl @RtlUshortByteSwap@4
|
PUBLIC @RtlUshortByteSwap@4
|
||||||
.globl @RtlUlongByteSwap@4
|
PUBLIC @RtlUlongByteSwap@4
|
||||||
.globl @RtlUlonglongByteSwap@8
|
PUBLIC @RtlUlonglongByteSwap@8
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
.code
|
||||||
|
|
||||||
.func @RtlUshortByteSwap@4, @RtlUshortByteSwap@4
|
|
||||||
@RtlUshortByteSwap@4:
|
@RtlUshortByteSwap@4:
|
||||||
|
FUNC RtlUshortByteSwap
|
||||||
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
||||||
|
|
||||||
/* Swap high and low bits */
|
/* Swap high and low bits */
|
||||||
mov ah, cl
|
mov ah, cl
|
||||||
mov al, ch
|
mov al, ch
|
||||||
ret
|
ret
|
||||||
.endfunc
|
ENDFUNC RtlUshortByteSwap
|
||||||
|
|
||||||
.func @RtlUlongByteSwap@4, @RtlUlongByteSwap@4
|
|
||||||
@RtlUlongByteSwap@4:
|
@RtlUlongByteSwap@4:
|
||||||
|
FUNC RtlUlongByteSwap
|
||||||
|
FPO 0, 0, 0, 0, 0, FRAME_FPO
|
||||||
|
|
||||||
/* Swap high and low bits */
|
/* Swap high and low bits */
|
||||||
mov eax, ecx
|
mov eax, ecx
|
||||||
bswap eax
|
bswap eax
|
||||||
ret
|
ret
|
||||||
.endfunc
|
ENDFUNC RtlUlongByteSwap
|
||||||
|
|
||||||
.func @RtlUlonglongByteSwap@8, @RtlUlonglongByteSwap@8
|
|
||||||
@RtlUlonglongByteSwap@8:
|
@RtlUlonglongByteSwap@8:
|
||||||
|
FUNC RtlUlonglongByteSwap
|
||||||
|
FPO 0, 2, 0, 0, 0, FRAME_FPO
|
||||||
|
|
||||||
/* Get 64-bit integer */
|
/* Get 64-bit integer */
|
||||||
mov edx, [esp+8]
|
mov eax, [esp+8]
|
||||||
mov eax, [esp+4]
|
mov edx, [esp+4]
|
||||||
|
|
||||||
/* Swap it */
|
/* Swap it */
|
||||||
bswap edx
|
bswap edx
|
||||||
bswap eax
|
bswap eax
|
||||||
|
|
||||||
/* Return it */
|
/* Return it (NOTE: this might look wrong, since fastcall functions
|
||||||
mov ecx, eax
|
should clean up the stack, even if the first parameter is an ULONGLONG,
|
||||||
mov eax, edx
|
and therefore put on tthe stack instead of in ecx and edx,
|
||||||
mov edx, ecx
|
but thats exactly how the function behaves on Windows! */
|
||||||
ret
|
ret
|
||||||
.endfunc
|
ENDFUNC RtlUlonglongByteSwap
|
||||||
|
|
||||||
|
|
||||||
|
END
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
</directory>
|
</directory>
|
||||||
</if>
|
</if>
|
||||||
<if property="ARCH" value="powerpc">
|
<if property="ARCH" value="powerpc">
|
||||||
|
<file>byteswap.c</file>
|
||||||
<directory name="powerpc">
|
<directory name="powerpc">
|
||||||
<file>debug.c</file>
|
<file>debug.c</file>
|
||||||
<file>except.c</file>
|
<file>except.c</file>
|
||||||
|
@ -30,12 +31,14 @@
|
||||||
</directory>
|
</directory>
|
||||||
</if>
|
</if>
|
||||||
<if property="ARCH" value="arm">
|
<if property="ARCH" value="arm">
|
||||||
|
<file>byteswap.c</file>
|
||||||
<directory name="arm">
|
<directory name="arm">
|
||||||
<file>debug_asm.S</file>
|
<file>debug_asm.S</file>
|
||||||
</directory>
|
</directory>
|
||||||
<file>mem.c</file>
|
<file>mem.c</file>
|
||||||
</if>
|
</if>
|
||||||
<if property="ARCH" value="amd64">
|
<if property="ARCH" value="amd64">
|
||||||
|
<file>byteswap.c</file>
|
||||||
<directory name="amd64">
|
<directory name="amd64">
|
||||||
<file>debug_asm.S</file>
|
<file>debug_asm.S</file>
|
||||||
<file>except_asm.S</file>
|
<file>except_asm.S</file>
|
||||||
|
@ -51,7 +54,6 @@
|
||||||
<file>assert.c</file>
|
<file>assert.c</file>
|
||||||
<file>atom.c</file>
|
<file>atom.c</file>
|
||||||
<file>avltable.c</file>
|
<file>avltable.c</file>
|
||||||
<file>byteswap.c</file>
|
|
||||||
<file>bitmap.c</file>
|
<file>bitmap.c</file>
|
||||||
<file>bootdata.c</file>
|
<file>bootdata.c</file>
|
||||||
<file>compress.c</file>
|
<file>compress.c</file>
|
||||||
|
|
Loading…
Reference in a new issue