Recent

Author Topic: The following is a compilation of Delphi, added to the Lazarus project error  (Read 517 times)

myisjwj

  • Jr. Member
  • **
  • Posts: 83
The following is a compilation of Delphi, added to the Lazarus project only 32-bit cpu available, 64-bit error
Code: Pascal  [Select][+][-]
  1. function StdWndProc(Window: HWND; Message: UINT; WParam: WPARAM; LParam: WPARAM): LRESULT; stdcall;
  2. {$IF Defined(CPUX86)}
  3. { In    ECX = Address of method pointer }
  4. { Out   EAX = Result }
  5. asm
  6.         XOR     EAX,EAX
  7.         PUSH    EAX
  8.         PUSH    LParam
  9.         PUSH    WParam
  10.         PUSH    Message
  11.         MOV     EDX,ESP
  12.         MOV     EAX,[ECX].Longint[4]
  13.         CALL    [ECX].Pointer
  14.         ADD     ESP,12
  15.         POP     EAX
  16. end;
  17. {$ELSEIF Defined(CPUX64)}
  18. { In    R11 = Address of method pointer }
  19. { Out   RAX = Result }
  20. var
  21.   Msg: TMessage;
  22. asm
  23.         .PARAMS 2 //Error: Not a directive or local symbol .PARAMS; Error: Unrecognized opcode .PARAMS;Assembler syntax error
  24.         MOV     Msg.Msg,Message
  25.         MOV     Msg.WParam,WParam
  26.         MOV     Msg.LParam,LParam
  27.         MOV     Msg.Result,0 //Error: Invalid reference syntax
  28.         LEA     RDX,Msg //Unknown identifier "RDX"
  29.         MOV     RCX,[R11].TMethod.Data//Unknown identifier "RCX";Error: Assembler syntax error in operand;Error: Unknown identifier "R11";Error: Assembler syntax error in operand;Error: Unknown identifier ".TMethod";Error: Assembler syntax error in operand;Error: Unknown identifier "DATA"
  30.         CALL    [R11].TMethod.Code //Error: Assembler syntax error in operand; Error: Unknown identifier "R11"; Error: Assembler syntax error in operand; Error: Unknown identifier ".TMethod"; Error: Assembler syntax error in operand; Error: Unknown identifier "CODE"
  31.         MOV     RAX,Msg.Result//Error: Unknown identifier "RAX"
  32. end;
  33.  
  34. {$ENDIF CPUX64}

How to rewrite the 64-bit assembly

Fibonacci

  • Hero Member
  • *****
  • Posts: 614
  • Internal Error Hunter
{$asmmode intel}

myisjwj

  • Jr. Member
  • **
  • Posts: 83
Thank you very much Fibonacci O:-)
Added {$asmmode intel} other lines do not report errors. But the first line
.PARAMS 2
Still report an error
Error: Not a directive or local symbol .PARAMS

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
That is mitigated by the closing [register..register] in FPC, but it is indeed an incompatibility. Name the registers used (predates delphi)
It solves the same problem.
(then again, why? because the compiler does a better job here - not always -.
Pointless use of assembler.)
« Last Edit: November 06, 2024, 02:15:09 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11947
  • FPC developer.
The win64 stackframe has rules about the shadow store, allocating stack space for register parameters (if not leaf?). https://www.ired.team/miscellaneous-reversing-forensics/windows-kernel-internals/windows-x64-calling-convention-stack-frame

There already is a bugreport for some of the many missing x64 pseudo directives. https://gitlab.com/freepascal.org/fpc/source/-/issues/31012

Thaddy

  • Hero Member
  • *****
  • Posts: 16199
  • Censorship about opinions does not belong here.
So declaring a local field of size 32 bytes together with nostackframe will do that?
Something along the lines:
Code: Pascal  [Select][+][-]
  1. type
  2.   TstackallocMem = packed array[0..31] of byte;
  3.  
  4. procedure testme(a,b:integer);assembler;nostackframe;
  5. var
  6.    tm:TstackallocMem;// 32 packed bytes on top of stack? this can be seen by compiling with -al in the s file
  7. asm
  8. .....
  9. end;
Not tested, but something along that line should work. But again, this is a silly use of assembler given what the compiler already generates in -O3 or higher and using pure Pascal. Almost identical....It is just setting up the function call, why bother doing that in assembler?
It is certainly not "faster"...Speed by assembler to setup just a function call is a misconception.
Or is there some other reason, where it really does matter? Such cases exist, but not here:You have to show us a better use-case.
And using pure Pascal has the advantage that it is really FPU agnostic.
That said, Marcov is much better versed in all kind of asm trickery with a background in image manipulation.
But don't use assembler just to set up a function call!, that is, well, clueless and pointless. It really is...
« Last Edit: November 07, 2024, 09:32:32 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11947
  • FPC developer.
It might in Delphi, since it introduced those options.

 

TinyPortal © 2005-2018