Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   x86 ASM => 64 bit (https://www.delphipraxis.net/170857-x86-asm-%3D-64-bit.html)

Ryzinski 6. Okt 2012 13:08

x86 ASM => 64 bit
 
When converting 32 bit ASM to 64 bits is something i can't convert.

push dword [esi]

Delphi-Quellcode:
function zend_get_parameters(ht: Integer; param_count: Integer;
  Params: array of ppzval): Integer; assembler; register;
asm
  push esi
  mov esi, ecx
  mov ecx, [ebp+8]
  cmp ecx, 0
  je @first
@toploop:
  {$IFDEF VERSION6}
  push [esi][ecx * 4]
  {$ELSE}
  push dword [esi][ecx * 4]
  {$ENDIF}
  loop @toploop
@first:
  push dword [esi]// <<<<<<<<<<<<< Invalid combination of opcode and operands
  push edx  
  push eax  
  call ZendGetParameters
  mov ecx, [ebp+8]
  add ecx, 3
@toploop2:
  pop edx
  loop @toploop2
  pop esi  
end;

himitsu 6. Okt 2012 13:31

AW: x86 ASM => 64 bit
 
Du kannst 32 Bit-Assembler-Code nicht einfach so unter 64 Bit nutzen.
Vorallem da sich dort die CPU-Register und deren Verwendung komplett verändert hat.
Außerdem muß der Code natürlich auch noch an die andere Pointer-Größe angepaßt werden.

Ryzinski 6. Okt 2012 14:09

AW: x86 ASM => 64 bit
 
i think be better to just convert asm to delphi

Maybe with IDA PRO HexRays => C => Delphi

himitsu 6. Okt 2012 14:33

AW: x86 ASM => 64 bit
 
Ich weiß nicht, ob ich es richtig übersetzt hab,
aber ich würde empfehlen garnicht erst zu versuchen dieses Assembler weiter zu nutzen.

Stattdessen sollte man eher versuchen die neue RTTI zu verwenden:
Delphi-Quellcode:
uses
  System.TypInfo, System.RTTI;

function zend_get_parameters(ht: Integer; param_count: Integer; Params: array of ppzval): Integer;
var
  Args: TArray<TValue>;
  i: Integer;
begin
  SetLength(Args, Length(Params) + 2);
  Args[0].From<Integer>(ht);
  Args[1].From<Integer>(param_count);
  for i := 0 to High(Params) do
    Args[i + 2].From<ppzval>(Params[i]);
  Result := Invoke(@ZendGetParameters, Args, ccCdecl, TypeInfo(Result)).AsInteger;
end;
Code nicht getestet und ich bin mir auch nicht sicher, ob das mit den übergebenen Parametern so stimmt.
Bis auf "Args" bin ich mir aber relativ sicher, daß es so stimmen sollte.

Ryzinski 6. Okt 2012 14:39

AW: x86 ASM => 64 bit
 
http://code.google.com/p/php5delphi/

I would pay someone to update this to XE3/64 Bits and latest PHP. Send offers on my PM.

Ryzinski 7. Okt 2012 20:24

AW: x86 ASM => 64 bit
 
Where does this code fall in bellow code

Delphi-Quellcode:
@toploop:
  {$IFDEF VERSION6}
  push [esi][ecx * 4]
  {$ELSE}
  push dword [esi][ecx * 4]
  {$ENDIF}
  loop @toploop

Delphi-Quellcode:
uses
  Windows, SysUtils, ZendTypes,RTTI,System.TypInfo;

function zend_get_parameters(ht: Integer; param_count: Integer; Params: array of ppzval): Integer;
var
  Args: TArray<TValue>;
  i: Integer;
begin
  SetLength(Args, Length(Params) + 2);
  Args[0].From<Integer>(ht);
  Args[1].From<Integer>(param_count);

  for i := 0 to High(Params) do
  Args[i + 2].From<ppzval>(Params[i]); // Statement expected, but expression of type 'TValue' found

  Result := Invoke(@ZendGetParameters, Args, ccCdecl, TypeInfo(Result)).AsInteger; //TYPEINFO standard function expects a type identifier
end;

Medium 8. Okt 2012 00:48

AW: x86 ASM => 64 bit
 
Probably nowhere really, since this was meant to be an alternative doing it the "proper pascal way", not a mere translation. The latter being, if possible, quite cumbersome anyways. The alternative is way less "hacky", and will adapt to any target the compiler supports, and still give the result you intended.

I must admit that I have not looked at both ways well enough to confirm that it'll exactly do as wished for, but I assume himitsu knows well what he does. (He usually does anyways :))

Ryzinski 8. Okt 2012 06:04

AW: x86 ASM => 64 bit
 
I see no point in using ASM these days in Delphi. Maybe in Delphi 2010 sure.

himitsu 8. Okt 2012 10:15

AW: x86 ASM => 64 bit
 
Ich hatte mir am Wochenende das Ganze mal etwas angesehn.

Es wird, auf jeden Fall, ein ganzes Stückchen an Arbeit werden, dieses auf Win64 umzustellen.
- das Assembler muß ja raus, oder zumindestens angepaßt werden (aber besser gleich ganz raus)
- ein Großteil der Assemblercodes war eh schwachsinnig und man hätte es, mit wesentlich weniger Code, gleich direkt in Pascal machen können (Geschwindigkeit war dabei scheinbar kein Grund und ich weiß nicht, wieso man das so machte)
- das Schlimmste sind, an zuvielen vielen Stellen, die "unschönen" Casts zwischen Pointer/THandle und Integer, oder Dergleichen
- auch bei der Unicode-Anpassung wurden scheinbar gleich ein paar ungünstige Dinge eingebaut
- und bei einigen Codestellen fragt man sich sowieso, was derjenige damals für Drogen genommen hatte :angle2: (aber vor solchen Jugendsünden ist wohl kaum einer gewahrt)


Schön ist es auch, daß dieses Projekt schon bei mindestens 3 großen Codeplattformen verteilt wurde und es eigentlich keine Zentrale anlaufstelle mehr gibt.

Ich weiß auch nicht, wer da nicht aufgepasst hat, aber:
Zitat:

php5delphi
Es heißt vermutlich nicht PHP4+Delphi, bzw. PHP5+Delphi, sondern PHP (for) Delphi.
Bei einer der Quellen hatte man versucht die PHP5-Anpassungen unabhängig fortzuführen, aber das ist inzwischen auch wieder eingeschlafen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:30 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz