[fpc-pascal] Porting Delphi ASM code to FPC

Graeme Geldenhuys graemeg at opensoft.homeip.net
Mon Aug 24 11:02:10 CEST 2009


Hi,

I have ported the DUnit2 testing framework from Delphi to FPC. DUnit2
works perfectly under 32bit FPC, but I am getting a compiler error when
trying to compile DUnit2 with 64bit FPC.  The error 'Unknown identifier
"EAX"' occurs in the first line of function CallerAddr(...).

I know that using ASM is not portable in FPC. CallerAddr() is used is
the raise <exception> at <address> call in method Fail(...) shown below.

Is there an existing function in FPC that does the same as
CallerAddr(..), but in a cross platform way? Alternatively, how can I
solve this compiler error under 64bit FPC (currently testing under 64bit
Linux).


function CallerAddr: Pointer; assembler;
const
  CallerIP = $4;
asm
   mov   eax, ebp
   call  IsBadPointer
   test  eax,eax
   jne   @@Error

   mov   eax, [ebp].CallerIP
   sub   eax, 5   // 5 bytes for call

   push  eax
   call  IsBadPointer
   test  eax,eax
   pop   eax
   je    @@Finish

@@Error:
   xor eax, eax
@@Finish:
end;


procedure TTestProc.Fail(const ErrorMsg: string; const ErrorAddress:
Pointer);
begin
//  raise ETestFailure.Create(ErrorMsg);
  if ErrorAddress = nil then
    raise ETestFailure.Create(ErrorMsg) at CallerAddr
  else
    raise ETestFailure.Create(ErrorMsg) at ErrorAddress;
end;



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/




More information about the fpc-pascal mailing list