[fpc-pascal] Question on Calling Conventions (for: PascalScript on Win x64)
Alexander Hofmann
alexander.hofmann at new-h.de
Thu Sep 6 02:28:00 CEST 2012
Am 05.09.2012 20:18, schrieb Florian Klämpfl:
> Am 05.09.2012 18:27, schrieb Alexander Hofmann:
> o Called from FPC: rcx: 0 (nil), rdx: Class Reference, r8: Value of
> aOwner o Called from Script: rcx: Class Reference, rdx: 1 (!?), r8:
> Value of aOwner (at least so it seems)
>
> You need to adapt PascalScript appropriately then: probably similiar
> code to x86.inc:534+ needs to be added to x64.inc around 582.
>
>
You were right of course! I could have sweared I looked over the
differences of x86 and x64 numerous times, but.. .well.
After some copy'n'paste it work's like a charm. Seems The only
difference is in calling Virtual Constructors (it might not be the best
looking code, I could have omitted the Variable, but... well.)
Thanks for the hint!
By the way, it was possible to implement calling of Methods from within
the script, too. It seems as if FPC on x64 would paste Object's Methods
in one Register - as a Pointer to a "Record" containing references to
code and "self"? At least it worked out for me that way..
The diff is a bit longer; so I didn't want to paste it here, instead
it's here (in case someone's interested): http://pastebin.com/c8A81kju
Below is just the change for Virtual constructors:
Index: x64.inc
===================================================================
--- x64.inc (revision 38441)
+++ x64.inc (working copy)
@@ -14,7 +14,7 @@
_RCX, _RDX, _R8, _R9: IPointer;
var _XMM0: Double;
_XMM1, _XMM2, _XMM3: Double;
- aStack: Pointer; aItems: IntPtr); assembler; {$IFDEF
FPC}nostackframe;{$ENDIF}
+ aStack: Pointer; aItems: PtrUInt); assembler; {$IFDEF
FPC}nostackframe;{$ENDIF}
asm
(* Registers:
RCX: Address
@@ -37,7 +37,7 @@
mov rdx, aStack
jmp @compareitems
@work:
- push [rdx]
+ push qword ptr [rdx]
dec rcx
sub rdx,8
@compareitems:
@@ -280,6 +280,9 @@
CallData: TPSList;
I: Integer;
pp: ^Byte;
+{$IFDEF FPC}
+ IsVirtualCons: Boolean;
+{$ENDIF}
function rp(p: PPSVariantIFC): PPSVariantIFC;
begin
@@ -579,6 +582,18 @@
{$ENDIF}
_RAX := 0;
RegUsage := 0;
+ {$IFDEF FPC}
+ // FIX FOR FPC constructor calls
+ if (Integer(CallingConv) and 128) <> 0 then begin
+ IsVirtualCons := true;
+ end else
+ IsVirtualCons:= false;
+ if IsVirtualCons then begin
+ if not GetPtr(rp(Params[0])) then exit; // this goes first
+ StoreReg(IPointer(_Self));
+ Params.Delete(0);
+ end else
+ {$ENDIF}
if assigned(_Self) then begin
StoreReg(IPointer(_Self));
end;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120906/f0098c29/attachment.sig>
More information about the fpc-pascal
mailing list