mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-24 04:39:10 +02:00
* Change rest of compiler to system unit swapendian routines.
- Remove endian swapping routines from cutils. git-svn-id: trunk@7859 -
This commit is contained in:
parent
b7b45919d0
commit
9b50dc572b
@ -44,14 +44,6 @@ interface
|
||||
{# Returns the maximum value between @var(a) and @var(b) }
|
||||
function max(a,b : longint) : longint;{$ifdef USEINLINE}inline;{$endif}
|
||||
function max(a,b : int64) : int64;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Returns the value in @var(x) swapped to different endian }
|
||||
Function SwapInt64(x : int64): int64;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Returns the value in @var(x) swapped to different endian }
|
||||
function SwapLong(x : longint): longint;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Returns the value in @va(x) swapped to different endian }
|
||||
function SwapWord(x : word): word;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Returns the value in @va(x) swapped to different endian }
|
||||
Function SwapQWord(x : qword) : qword;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Return value @var(i) aligned on @var(a) boundary }
|
||||
function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif}
|
||||
{# Return @var(b) with the bit order reversed }
|
||||
@ -199,45 +191,6 @@ implementation
|
||||
max:=b;
|
||||
end;
|
||||
|
||||
|
||||
Function SwapLong(x : longint): longint;{$ifdef USEINLINE}inline;{$endif}
|
||||
var
|
||||
y : word;
|
||||
z : word;
|
||||
Begin
|
||||
y := x shr 16;
|
||||
y := word(longint(y) shl 8) or (y shr 8);
|
||||
z := x and $FFFF;
|
||||
z := word(longint(z) shl 8) or (z shr 8);
|
||||
SwapLong := (longint(z) shl 16) or longint(y);
|
||||
End;
|
||||
|
||||
|
||||
Function SwapInt64(x : int64): int64;{$ifdef USEINLINE}inline;{$endif}
|
||||
Begin
|
||||
result:=swaplong(longint(hi(x)));
|
||||
result:=result or (swaplong(longint(lo(x))) shl 32);
|
||||
End;
|
||||
|
||||
|
||||
Function SwapQWord(x : qword) : qword;{$ifdef USEINLINE}inline;{$endif}
|
||||
Begin
|
||||
result:=swaplong(longint(hi(x)));
|
||||
result:=result or (swaplong(longint(lo(x))) shl 32);
|
||||
End;
|
||||
|
||||
|
||||
Function SwapWord(x : word): word;{$ifdef USEINLINE}inline;{$endif}
|
||||
var
|
||||
z : byte;
|
||||
Begin
|
||||
z := x shr 8;
|
||||
x := x and $ff;
|
||||
x := (x shl 8);
|
||||
SwapWord := x or z;
|
||||
End;
|
||||
|
||||
|
||||
function reverse_byte(b: byte): byte;
|
||||
const
|
||||
reverse_nible:array[0..15] of 0..15 =
|
||||
|
@ -536,7 +536,7 @@ implementation
|
||||
end
|
||||
else
|
||||
begin
|
||||
location.value:=cardinal(SwapLong(pLongint(value_set)^));
|
||||
location.value:=swapendian(Pcardinal(value_set)^);
|
||||
location.value:= reverse_byte (location.value and $ff) or
|
||||
(reverse_byte((location.value shr 8) and $ff) shl 8) or
|
||||
(reverse_byte((location.value shr 16) and $ff) shl 16) or
|
||||
|
@ -327,19 +327,19 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.e_type:=swapword(e_type);
|
||||
result.e_machine:=swapword(e_machine);
|
||||
result.e_version:=swaplong(e_version);
|
||||
result.e_entry:=swaplong(e_entry);
|
||||
result.e_phoff:=swaplong(e_phoff);
|
||||
result.e_shoff:=swaplong(e_shoff);
|
||||
result.e_flags:=swaplong(e_flags);
|
||||
result.e_ehsize:=swapword(e_ehsize);
|
||||
result.e_phentsize:=swapword(e_phentsize);
|
||||
result.e_phnum:=swapword(e_phnum);
|
||||
result.e_shentsize:=swapword(e_shentsize);
|
||||
result.e_shnum:=swapword(e_shnum);
|
||||
result.e_shstrndx:=swapword(e_shstrndx);
|
||||
result.e_type:=swapendian(e_type);
|
||||
result.e_machine:=swapendian(e_machine);
|
||||
result.e_version:=swapendian(e_version);
|
||||
result.e_entry:=swapendian(e_entry);
|
||||
result.e_phoff:=swapendian(e_phoff);
|
||||
result.e_shoff:=swapendian(e_shoff);
|
||||
result.e_flags:=swapendian(e_flags);
|
||||
result.e_ehsize:=swapendian(e_ehsize);
|
||||
result.e_phentsize:=swapendian(e_phentsize);
|
||||
result.e_phnum:=swapendian(e_phnum);
|
||||
result.e_shentsize:=swapendian(e_shentsize);
|
||||
result.e_shnum:=swapendian(e_shnum);
|
||||
result.e_shstrndx:=swapendian(e_shstrndx);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -350,19 +350,19 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.e_type:=swapword(e_type);
|
||||
result.e_machine:=swapword(e_machine);
|
||||
result.e_version:=swaplong(e_version);
|
||||
result.e_entry:=swapqword(e_entry);
|
||||
result.e_phoff:=swapqword(e_phoff);
|
||||
result.e_shoff:=swapqword(e_shoff);
|
||||
result.e_flags:=swaplong(e_flags);
|
||||
result.e_ehsize:=swapword(e_ehsize);
|
||||
result.e_phentsize:=swapword(e_phentsize);
|
||||
result.e_phnum:=swapword(e_phnum);
|
||||
result.e_shentsize:=swapword(e_shentsize);
|
||||
result.e_shnum:=swapword(e_shnum);
|
||||
result.e_shstrndx:=swapword(e_shstrndx);
|
||||
result.e_type:=swapendian(e_type);
|
||||
result.e_machine:=swapendian(e_machine);
|
||||
result.e_version:=swapendian(e_version);
|
||||
result.e_entry:=swapendian(e_entry);
|
||||
result.e_phoff:=swapendian(e_phoff);
|
||||
result.e_shoff:=swapendian(e_shoff);
|
||||
result.e_flags:=swapendian(e_flags);
|
||||
result.e_ehsize:=swapendian(e_ehsize);
|
||||
result.e_phentsize:=swapendian(e_phentsize);
|
||||
result.e_phnum:=swapendian(e_phnum);
|
||||
result.e_shentsize:=swapendian(e_shentsize);
|
||||
result.e_shnum:=swapendian(e_shnum);
|
||||
result.e_shstrndx:=swapendian(e_shstrndx);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -373,16 +373,16 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.sh_name:=SwapLong(sh_name);
|
||||
result.sh_type:=SwapLong(sh_type);
|
||||
result.sh_flags:=SwapLong(sh_flags);
|
||||
result.sh_addr:=SwapLong(sh_addr);
|
||||
result.sh_offset:=SwapLong(sh_offset);
|
||||
result.sh_size:=SwapLong(sh_size);
|
||||
result.sh_link:=SwapLong(sh_link);
|
||||
result.sh_info:=SwapLong(sh_info);
|
||||
result.sh_addralign:=SwapLong(sh_addralign);
|
||||
result.sh_entsize:=SwapLong(sh_entsize);
|
||||
result.sh_name:=swapendian(sh_name);
|
||||
result.sh_type:=swapendian(sh_type);
|
||||
result.sh_flags:=swapendian(sh_flags);
|
||||
result.sh_addr:=swapendian(sh_addr);
|
||||
result.sh_offset:=swapendian(sh_offset);
|
||||
result.sh_size:=swapendian(sh_size);
|
||||
result.sh_link:=swapendian(sh_link);
|
||||
result.sh_info:=swapendian(sh_info);
|
||||
result.sh_addralign:=swapendian(sh_addralign);
|
||||
result.sh_entsize:=swapendian(sh_entsize);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -393,16 +393,16 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.sh_name:=SwapLong(sh_name);
|
||||
result.sh_type:=SwapLong(sh_type);
|
||||
result.sh_flags:=SwapQWord(sh_flags);
|
||||
result.sh_addr:=SwapQWord(sh_addr);
|
||||
result.sh_offset:=SwapQWord(sh_offset);
|
||||
result.sh_size:=SwapQWord(sh_size);
|
||||
result.sh_link:=SwapLong(sh_link);
|
||||
result.sh_info:=SwapLong(sh_info);
|
||||
result.sh_addralign:=SwapQWord(sh_addralign);
|
||||
result.sh_entsize:=SwapQWord(sh_entsize);
|
||||
result.sh_name:=swapendian(sh_name);
|
||||
result.sh_type:=swapendian(sh_type);
|
||||
result.sh_flags:=swapendian(sh_flags);
|
||||
result.sh_addr:=swapendian(sh_addr);
|
||||
result.sh_offset:=swapendian(sh_offset);
|
||||
result.sh_size:=swapendian(sh_size);
|
||||
result.sh_link:=swapendian(sh_link);
|
||||
result.sh_info:=swapendian(sh_info);
|
||||
result.sh_addralign:=swapendian(sh_addralign);
|
||||
result.sh_entsize:=swapendian(sh_entsize);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -413,10 +413,10 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.st_name:=SwapLong(st_name);
|
||||
result.st_value:=SwapLong(st_value);
|
||||
result.st_size:=SwapLong(st_size);
|
||||
result.st_shndx:=SwapWord(st_shndx);
|
||||
result.st_name:=swapendian(st_name);
|
||||
result.st_value:=swapendian(st_value);
|
||||
result.st_size:=swapendian(st_size);
|
||||
result.st_shndx:=swapendian(st_shndx);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -427,10 +427,10 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.st_name:=SwapLong(st_name);
|
||||
result.st_value:=SwapQWord(st_value);
|
||||
result.st_size:=SwapQWord(st_size);
|
||||
result.st_shndx:=SwapWord(st_shndx);
|
||||
result.st_name:=swapendian(st_name);
|
||||
result.st_value:=swapendian(st_value);
|
||||
result.st_size:=swapendian(st_size);
|
||||
result.st_shndx:=swapendian(st_shndx);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -441,8 +441,8 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.address:=SwapLong(address);
|
||||
result.info:=SwapLong(info);
|
||||
result.address:=swapendian(address);
|
||||
result.info:=swapendian(info);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -453,8 +453,8 @@ implementation
|
||||
if source_info.endian<>target_info.endian then
|
||||
with h do
|
||||
begin
|
||||
result.address:=SwapQWord(address);
|
||||
result.info:=SwapQWord(info);
|
||||
result.address:=swapendian(address);
|
||||
result.info:=swapendian(info);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -704,7 +704,7 @@ var
|
||||
begin
|
||||
if change_endian then
|
||||
for i:=0 to 7 do
|
||||
SetLongintArray(b)[i]:=getlongint;
|
||||
SetLongintArray(b)[i]:=getlongint
|
||||
else
|
||||
getdata(b,32);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user