* moved to FV

This commit is contained in:
peter 2001-01-29 21:56:39 +00:00
parent d9b97cc5bf
commit 2847f1e5d4
2 changed files with 0 additions and 696 deletions

View File

@ -1,361 +0,0 @@
{
$Id$
This unit provides compiler-independent mechanisms to call special
functions, i.e. local functions/procedures, constructors, methods,
destructors, etc. As there are no procedural variables for these
special functions, there is no Pascal way to call them directly.
Copyright (c) 1997 Matthias K"oppe <mkoeppe@csmd.cs.uni-magdeburg.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************}
unit CallSpec;
{
As of this version, the following compilers are supported. Please
port CallSpec to other compilers (including earlier versions) and
send your code to the above address.
Compiler Comments
--------------------------- -------------------------------------
Turbo Pascal 6.0
Borland/Turbo Pascal 7.0
FPC Pascal 0.99.8
}
interface
{$i platform.inc}
{
The frame pointer points to the local variables of a procedure.
Use CurrentFramePointer to address the locals of the current procedure;
use PreviousFramePointer to addess the locals of the calling procedure.
}
type
{$ifdef BIT_16}
FramePointer = Word;
{$endif}
{$ifdef BIT_32}
FramePointer = pointer;
{$endif}
function CurrentFramePointer: FramePointer;
function PreviousFramePointer: FramePointer;
{ This version of CallSpec supports four classes of special functions.
(Please write if you need other classes.)
For each, two types of argument lists are allowed:
`Void' indicates special functions with no explicit arguments.
Sample: constructor T.Init;
`Pointer' indicates special functions with one explicit pointer argument.
Sample: constructor T.Load(var S: TStream);
}
{ Constructor calls.
Ctor Pointer to the constructor.
Obj Pointer to the instance. NIL if new instance to be allocated.
VMT Pointer to the VMT (obtained by TypeOf()).
returns Pointer to the instance.
}
function CallVoidConstructor(Ctor: pointer; Obj: pointer; VMT: pointer): pointer;
function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;
{ Method calls.
Method Pointer to the method.
Obj Pointer to the instance. NIL if new instance to be allocated.
returns Pointer to the instance.
}
function CallVoidMethod(Method: pointer; Obj: pointer): pointer;
function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;
{ Local-function/procedure calls.
Func Pointer to the local function (which must be far-coded).
Frame Frame pointer of the wrapping function.
}
function CallVoidLocal(Func: pointer; Frame: FramePointer): pointer;
function CallPointerLocal(Func: pointer; Frame: FramePointer; Param1: pointer): pointer;
{ Calls of functions/procedures local to methods.
Func Pointer to the local function (which must be far-coded).
Frame Frame pointer of the wrapping method.
Obj Pointer to the object that the method belongs to.
}
function CallVoidMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer): pointer;
function CallPointerMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer; Param1: pointer): pointer;
implementation
{$ifdef PPC_FPC}
{$ASMMODE ATT}
{ This indicates an FPC version which uses the same call scheme for
method-local and procedure-local procedures, but which expects the
ESI register be loaded with the Self pointer in method-local procs. }
type
VoidLocal = function(_EBP: FramePointer): pointer;
PointerLocal = function(_EBP: FramePointer; Param1: pointer): pointer;
VoidMethodLocal = function(_EBP: FRAMEPOINTER): pointer;
PointerMethodLocal = function(_EBP: FRAMEPOINTER; Param1: pointer): pointer;
VoidConstructor = function(VMT: pointer; Obj: pointer): pointer;
PointerConstructor = function(VMT: pointer; Obj: pointer; Param1: pointer): pointer;
VoidMethod = function(Obj: pointer): pointer;
PointerMethod = function(Obj: pointer; Param1: pointer): pointer;
function CallVoidConstructor(Ctor: pointer; Obj: pointer; VMT: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallVoidConstructor := VoidConstructor(Ctor)(VMT, Obj)
end;
function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallPointerConstructor := PointerConstructor(Ctor)(VMT, Obj, Param1)
end;
function CallVoidMethod(Method: pointer; Obj: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallVoidMethod := VoidMethod(Method)(Obj)
end;
function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallPointerMethod := PointerMethod(Method)(Obj, Param1)
end;
function CallVoidLocal(Func: pointer; Frame: FramePointer): pointer;
begin
CallVoidLocal := VoidLocal(Func)(Frame)
end;
function CallPointerLocal(Func: pointer; Frame: FramePointer; Param1: pointer): pointer;
begin
CallPointerLocal := PointerLocal(Func)(Frame, Param1)
end;
function CallVoidMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallVoidMethodLocal := VoidMethodLocal(Func)(Frame)
end;
function CallPointerMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer; Param1: pointer): pointer;
begin
{ load the object pointer }
asm
movl Obj, %esi
end;
CallPointerMethodLocal := PointerMethodLocal(Func)(Frame, Param1)
end;
function CurrentFramePointer: FramePointer;assembler;
asm
movl %ebp,%eax
end ['EAX'];
function PreviousFramePointer: FramePointer;assembler;
asm
movl (%ebp), %eax
end ['EAX'];
{$endif PPC_FPC}
{$ifdef PPC_BP}
type
VoidConstructor = function(VmtOfs: Word; Obj: pointer): pointer;
PointerConstructor = function(Param1: pointer; VmtOfs: Word; Obj: pointer): pointer;
VoidMethod = function(Obj: pointer): pointer;
PointerMethod = function(Param1: pointer; Obj: pointer): pointer;
function CallVoidConstructor(Ctor: pointer; Obj: pointer; VMT: pointer): pointer;
begin
CallVoidConstructor := VoidConstructor(Ctor)(Ofs(VMT^), Obj)
end;
function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;
begin
CallPointerConstructor := PointerConstructor(Ctor)(Param1, Ofs(VMT^), Obj)
end;
function CallVoidMethod(Method: pointer; Obj: pointer): pointer;
begin
CallVoidMethod := VoidMethod(Method)(Obj)
end;
function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;
begin
CallPointerMethod := PointerMethod(Method)(Param1, Obj)
end;
function CallVoidLocal(Func: pointer; Frame: FramePointer): pointer; assembler;
asm
{$IFDEF Windows}
MOV AX,[Frame]
AND AL,0FEH
PUSH AX
{$ELSE}
push [Frame]
{$ENDIF}
call dword ptr Func
end;
function CallPointerLocal(Func: pointer; Frame: FramePointer; Param1: pointer): pointer; assembler;
asm
mov ax, word ptr Param1
mov dx, word ptr Param1+2
push dx
push ax
{$IFDEF Windows}
MOV AX,[Frame]
AND AL,0FEH
PUSH AX
{$ELSE}
push [Frame]
{$ENDIF}
call dword ptr Func
end;
function CallVoidMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer): pointer; assembler;
asm
{$IFDEF Windows}
MOV AX,[Frame]
AND AL,0FEH
PUSH AX
{$ELSE}
push [Frame]
{$ENDIF}
call dword ptr Func
end;
function CallPointerMethodLocal(Func: pointer; Frame: FramePointer; Obj: pointer; Param1: pointer): pointer; assembler;
asm
mov ax, word ptr Param1
mov dx, word ptr Param1+2
push dx
push ax
{$IFDEF Windows}
MOV AX,[Frame]
AND AL,0FEH
PUSH AX
{$ELSE}
push [Frame]
{$ENDIF}
call dword ptr Func
end;
function CurrentFramePointer: FramePointer; assembler;
asm
mov ax, bp
end;
function PreviousFramePointer: FramePointer; assembler;
asm
mov ax, ss:[bp]
end;
{$endif PPC_BP}
end.
{
$Log$
Revision 1.1 2001-01-29 11:31:26 marco
* added from API. callspec renamed to .pp
Revision 1.1 2000/07/13 06:29:38 michael
+ Initial import
Revision 1.1 2000/01/06 01:20:30 peter
* moved out of packages/ back to topdir
Revision 1.1 1999/12/23 19:36:47 peter
* place unitfiles in target dirs
Revision 1.1 1999/11/24 23:36:37 peter
* moved to packages dir
Revision 1.2 1998/12/16 21:57:16 peter
* fixed currentframe,previousframe
+ testcall to test the callspec unit
Revision 1.1 1998/12/04 12:48:24 peter
* moved some dirs
Revision 1.5 1998/12/04 09:53:44 peter
* removed objtemp global var
Revision 1.4 1998/11/24 17:14:24 peter
* fixed esi loading
Date Version Who Comments
---------- -------- ------- -------------------------------------
19-Sep-97 0.1 mkoeppe Initial version.
22-Sep-97 0.11 fk 0.9.3 support added, self isn't expected
on the stack in local procedures of methods
23-Sep-97 0.12 mkoeppe Cleaned up 0.9.3 conditionals.
03-Oct-97 0.13 mkoeppe Fixed esi load in FPC 0.9
22-Oct-98 0.14 pfv 0.99.8 support for FPC
}

View File

@ -1,335 +0,0 @@
{
$Id$
Include file to sort out compilers/platforms/targets
Copyright (c) 1997 Balazs Scheidler (bazsi@tas.vein.hu)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
This include file defines some conditional defines to allow us to select
the compiler/platform/target in a consequent way.
OS_XXXX The operating system used (XXXX may be one of:
DOS, OS2, Linux, Windows, Go32, FreeBSD,Linux)
PPC_XXXX The compiler used: BP, FPK, Virtual, Speed
BIT_XX The number of bits of the target platform: 16 or 32
PROC_XXXX The mode of the target processor (Real or Protected)
This shouldn't be used, except for i386 specific parts.
ASM_XXXX This is the assembler type: BP, ISO-ANSI, FPK
****************************************************************************
Changelog:
Date Version Who Comments
02 Jul 97 0.1 Bazsi Initial implementation~
28 Aug 97 0.2 LdeB Fixed OS2 platform sort out
29 Aug 97 0.3 LdeB Added assembler type change
29 Aug 97 0.4 LdeB OS_DOS removed from Windows
23 Oct 97 0.5 LdeB Delphi & Speed compilers added
05 May 98 0.6 LdeB Virtual pascal 2.0 added
19 May 98 0.7 LdeB Delphi2/3 definitions altered
6 Aug 98 0.8 CEC/LdeB FPC only support - fixed for Win32
10 Aug 98 0.9 LdeB BP_VMTLink def/Undef for object reg.
27 Aug 98 1.0 LdeB Fixed Atari etc not $UNDEF OS_DOS.
25 Oct 98 1.1 pfv Delphi4
13 nov 00 1.2 mvdv Unix renamefest Addition of FreeBSD
and change of Linux conditional
meaning
****************************************************************************
This is how the IFDEF and UNDEF statements below should translate.
PLATFORM SYSTEM COMPILER COMP ID CPU MODE BITS ASSEMBLER
-------- ------ -------- ------- -------- ---- ---------
DOS OS_DOS BP/TP7 PPC_BP PROC_Real BIT_16 ASM_BP
FPC PPC_FPC PROC_Protected BIT_32 ASM_FPC
DPMI OS_DOS BP/TP7 PPC_BP PROC_Protected BIT_16 ASM_BP
LINUX OS_LINUX FPC PPC_FPC PROC_Protected BIT_32 ASM_FPC
FREEBSD OS_FREEBSD FPC PPC_FPC PROC_Protected BIT_32 ASM_FPC
WINDOWS OS_WINDOWS BP/TP7 PPC_BP PROC_Protected BIT_16 ASM_BP
DELPHI PPC_DELPHI PROC_Protected BIT_16 ASM_BP
DELPHI2 PPC_DELPHI&2 PROC_Protected BIT_16 ASM_BP
WIN95/NT OS_WINDOWS DELPHI2 PPC_DELPHI&2 PROC_Protected BIT_32 ASM_BP
DELPHI3 PPC_DELPHI&3 PROC_Protected BIT_32 ASM_BP
DELPHI4 PPC_DELPHI&3 PROC_Protected BIT_32 ASM_BP
VIRTUAL PPC_VIRTUAL PROC_Protected BIT 32 ASM_BP
OS2 OS_OS2 BPOS2 PPC_BPOS2 PROC_Protected BIT_16 ASM_BP
VIRTUAL PPC_VIRTUAL PROC_Protected BIT_32 ASM_BP
SPEED PPC_SPEED PROC_Protected BIT_32 ASM_BP
FPC PPC_FPC PROC_Protected BIT_32 ASM_FPC
****************************************************************************}
{****************************************************************************
FOR ALL COMPILERS BP_VMTLink will be defined but FPC and Delphi3 undefine it
****************************************************************************}
{****************************************************************************
FOR FPC THESE ARE THE TRANSLATIONS
PLATFORM SYSTEM COMPILER HANDLE SIZE ASM CPU
-------- ------ -------- ----------- ---- ---
DOS OS_DOS,
OS_GO32 FPC 32-bit AT&T CPU86
WIN32 OS_WINDOWS FPC 32-bit AT&T ----
LINUX OS_LINUX,
OS_UNIX FPC 32-bit AT&T ----
FREEBSD OS_FREEBSD,
OS_BSD,
OS_UNIX FPC 32-bit AT&T ----
OS2 OS_OS2 FPC ????? AT&T CPU86
ATARI OS_ATARI FPC 32-bit Internal CPU68
MACOS OS_MAC FPC ????? Internal CPU68
AMIGA OS_AMIGA FPC 32-bit Internal CPU68
Note: All Unices have OS_UNIX in common. All BSD's (Open,Net,Free) have
OS_BSD in common.
****************************************************************************}
{---------------------------------------------------------------------------}
{ Initial assume BORLAND 16 BIT DOS COMPILER - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$DEFINE OS_DOS}
{$DEFINE PROC_Real}
{$DEFINE BIT_16}
{$DEFINE PPC_BP}
{$DEFINE ASM_BP}
{$DEFINE BP_VMTLink}
{---------------------------------------------------------------------------}
{ BORLAND 16 BIT DPMI changes protected mode - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF DPMI}
{$UNDEF PROC_Real}
{$DEFINE PROC_Protected}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC 32 BIT COMPILER changes ASM, 32 bits etc - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF FPC}
{$UNDEF PROC_Real}
{$DEFINE PROC_Protected}
{$UNDEF BIT_16}
{$DEFINE BIT_32}
{$UNDEF PPC_BP}
{$DEFINE PPC_FPC}
{$UNDEF ASM_BP}
{$DEFINE ASM_FPC}
{$UNDEF BP_VMTLink}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC LINUX COMPILER changes operating system - Updated 12nov00 MvdV }
{ Note: Other linux compilers would need to change other details }
{---------------------------------------------------------------------------}
{$IFDEF UNIX}
{$UNDEF OS_DOS}
{$DEFINE OS_UNIX}
{$IFNDEF BSD} {Work around. BSD still defines "linux"
in 1.1 for now}
{$DEFINE OS_LINUX}
{$ELSE}
{$DEFINE OS_FREEBSD}
{$DEFINE OS_BSD}
{$ENDIF}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC GO32V2 COMPILER changes operating system - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF GO32V2}
{$DEFINE OS_GO32}
{$ENDIF}
{---------------------------------------------------------------------------}
{ 32 BIT WINDOWS COMPILERS changes bit size - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF WIN32}
{$IFNDEF WINDOWS}
{$DEFINE WINDOWS}
{$ENDIF}
{$UNDEF BIT_16}
{$DEFINE BIT_32}
{$ENDIF}
{---------------------------------------------------------------------------}
{ WINDOWS COMPILERS change op system and proc mode - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF WINDOWS}
{$UNDEF OS_DOS}
{$DEFINE OS_WINDOWS}
{$UNDEF PROC_Real}
{$DEFINE PROC_Protected}
{$ENDIF}
{---------------------------------------------------------------------------}
{ DELPHI1 COMPILER changes compiler type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF VER80}
{$UNDEF PPC_BP}
{$DEFINE PPC_DELPHI}
{$ENDIF}
{---------------------------------------------------------------------------}
{ DELPHI2 COMPILER changes compiler type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF VER90}
{$UNDEF PPC_BP}
{$DEFINE PPC_DELPHI}
{$DEFINE PPC_DELPHI2}
{$ENDIF}
{---------------------------------------------------------------------------}
{ DELPHI3 COMPILER changes compiler type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF VER100}
{$UNDEF PPC_BP}
{$DEFINE PPC_DELPHI}
{$DEFINE PPC_DELPHI3}
{$UNDEF BP_VMTLink}
{$ENDIF}
{---------------------------------------------------------------------------}
{ DELPHI4 COMPILER changes compiler type - Updated 25Oct98 pfv }
{---------------------------------------------------------------------------}
{$IFDEF VER120}
{$UNDEF PPC_BP}
{$DEFINE PPC_DELPHI}
{$DEFINE PPC_DELPHI3}
{$DEFINE PPC_DELPHI4}
{$UNDEF BP_VMTLink}
{$ENDIF}
{---------------------------------------------------------------------------}
{ OS2 COMPILERS change compiler type and mode - Updated 27Aug98 LdB }
{ Note: Assumes BPOS2 16BIT OS2 patch except for FPC which undefines this }
{---------------------------------------------------------------------------}
{$IFDEF OS2}
{$UNDEF OS_DOS}
{$DEFINE OS_OS2}
{$UNDEF PROC_Real}
{$DEFINE PROC_Protected}
{$UNDEF PPC_BP}
{$DEFINE PPC_BPOS2}
{$IFDEF FPC}
{$UNDEF PPC_BPOS2}
{$ENDIF}
{$ENDIF}
{---------------------------------------------------------------------------}
{ VIRTUAL PASCAL changes compiler type/32 bit - Updated 27Aug98 LdB }
{ Note: VP2 can compile win 32 code so changes op system as needed }
{---------------------------------------------------------------------------}
{$IFDEF VirtualPascal}
{$UNDEF BIT_16}
{$DEFINE BIT_32}
{$IFDEF PPC_BPOS2}
{$UNDEF PPC_BPOS2}
{$ENDIF}
{$DEFINE PPC_VIRTUAL}
{$IFDEF WIN32}
{$UNDEF PPC_BP}
{$UNDEF OS_OS2}
{$DEFINE OS_WINDOWS}
{$ENDIF}
{$ENDIF}
{---------------------------------------------------------------------------}
{ SPEED COMPILER changes compiler type/32 bit - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF Speed}
{$UNDEF BIT_16}
{$DEFINE BIT_32}
{$UNDEF PPC_BPOS2}
{$DEFINE PPC_SPEED}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC AMIGA COMPILER changes op system and CPU type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF AMIGA}
{$UNDEF OS_DOS}
{$DEFINE OS_AMIGA}
{$IFDEF CPU86}
{$UNDEF CPU86}
{$ENDIF}
{$IFNDEF CPU68}
{$DEFINE CPU68}
{$ENDIF}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC ATARI COMPILER changes op system and CPU type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF ATARI}
{$UNDEF OS_DOS}
{$DEFINE OS_ATARI}
{$IFDEF CPU86}
{$UNDEF CPU86}
{$ENDIF}
{$IFNDEF CPU68}
{$DEFINE CPU68}
{$ENDIF}
{$ENDIF}
{---------------------------------------------------------------------------}
{ FPC MAC COMPILER changes op system and CPU type - Updated 27Aug98 LdB }
{---------------------------------------------------------------------------}
{$IFDEF MACOS}
{$UNDEF OS_DOS}
{$DEFINE OS_MAC}
{$IFDEF CPU86}
{$UNDEF CPU86}
{$ENDIF}
{$IFNDEF CPU68}
{$DEFINE CPU68}
{$ENDIF}
{$ENDIF}
{
$Log$
Revision 1.1 2001-01-29 11:31:26 marco
* added from API. callspec renamed to .pp
Revision 1.3 2000/11/13 14:35:57 marco
* Unix Renamefest for defines.
Revision 1.2 2000/07/13 11:32:24 michael
+ removed logs
}