123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- {
- $Id$
- This file is part of the Free Pascal Run time library.
- Copyright (c) 1993,97 by the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- For details about the copyright.
- This program 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.
- **********************************************************************}
- {****************************************************************************
- Local types
- ****************************************************************************}
- {
- TextRec and FileRec are put in a separate file to make it available to other
- units without putting it explicitly in systemh.
- This way we keep TP compatibility, and the TextRec definition is available
- for everyone who needs it.
- }
- {$i filerec.inc}
- {$i textrec.inc}
- type
- FileFunc = Procedure(var t : TextRec);
- var
- { For Error Handling.}
- DoError : Boolean;
- ErrorBase : Longint;
- {****************************************************************************
- Include processor specific routines
- ****************************************************************************}
- {$IFDEF I386}
- {$IFDEF M68K}
- {$Error Can't determine processor type !}
- {$ENDIF}
- {$I i386.inc} { Case dependent, don't change }
- {$ELSE}
- {$IFDEF M68K}
- {$I m68k.inc} { Case dependent, don't change }
- {$ELSE}
- {$Error Can't determine processor type !}
- {$ENDIF}
- {$ENDIF}
- {****************************************************************************
- Routines which have compiler magic
- ****************************************************************************}
- {$I innr.inc}
- Function lo(i : Integer) : byte; [INTERNPROC: In_lo_Word];
- Function lo(w : Word) : byte; [INTERNPROC: In_lo_Word];
- Function lo(l : Longint) : Word; [INTERNPROC: In_lo_long];
- Function hi(i : Integer) : byte; [INTERNPROC: In_hi_Word];
- Function hi(w : Word) : byte; [INTERNPROC: In_hi_Word];
- Function hi(l : Longint) : Word; [INTERNPROC: In_hi_long];
- Procedure Inc(var i : Cardinal); [INTERNPROC: In_Inc_DWord];
- Procedure Inc(var i : Longint); [INTERNPROC: In_Inc_DWord];
- Procedure Inc(var i : Integer); [INTERNPROC: In_Inc_Word];
- Procedure Inc(var i : Word); [INTERNPROC: In_Inc_Word];
- Procedure Inc(var i : shortint); [INTERNPROC: In_Inc_byte];
- Procedure Inc(var i : byte); [INTERNPROC: In_Inc_byte];
- Procedure Inc(var c : Char); [INTERNPROC: In_Inc_byte];
- Procedure Inc(var p : PChar); [INTERNPROC: In_Inc_DWord];
- Procedure Dec(var i : Cardinal); [INTERNPROC: In_Dec_DWord];
- Procedure Dec(var i : Longint); [INTERNPROC: In_Dec_DWord];
- Procedure Dec(var i : Integer); [INTERNPROC: In_Dec_Word];
- Procedure Dec(var i : Word); [INTERNPROC: In_Dec_Word];
- Procedure Dec(var i : shortint); [INTERNPROC: In_Dec_byte];
- Procedure Dec(var i : byte); [INTERNPROC: In_Dec_byte];
- Procedure Dec(var c : Char); [INTERNPROC: In_Dec_byte];
- Procedure Dec(var p : PChar); [INTERNPROC: In_Dec_DWord];
- Function chr(b : byte) : Char; [INTERNPROC: In_chr_byte];
- Function Length(s : string) : byte; [INTERNPROC: In_Length_string];
- Procedure Reset(var f : TypedFile); [INTERNPROC: In_Reset_TypedFile];
- Procedure Rewrite(var f : TypedFile); [INTERNPROC: In_Rewrite_TypedFile];
- {****************************************************************************
- Math Routines
- ****************************************************************************}
- function Hi(b : byte): byte;
- begin
- Hi := b shr 4
- end;
- function Lo(b : byte): byte;
- begin
- Lo := b and $0f
- end;
- Procedure Inc(var i : Cardinal;a: Longint);
- Begin
- I:=I+A;
- End;
- Procedure Dec(var i : Cardinal;a: Longint);
- Begin
- I:=I-A;
- End;
- Procedure Inc(var i : Longint;a : Longint);
- Begin
- i:=i+a;
- End;
- Procedure Dec(var i : Longint;a : Longint);
- Begin
- i:=i-a;
- End;
- Procedure Dec(var i : Word;a : Longint);
- Begin
- i:=i-a;
- End;
- Procedure Inc(var i : Word;a : Longint);
- Begin
- i:=i+a;
- End;
- Procedure Dec(var i : Integer;a : Longint);
- Begin
- i:=i-a;
- End;
- Procedure Inc(var i : Integer;a : Longint);
- Begin
- i:=i+a;
- End;
- Procedure Dec(var i : byte;a : Longint);
- Begin
- i:=i-a;
- End;
- Procedure Inc(var i : byte;a : Longint);
- Begin
- i:=i+a;
- End;
- Procedure Dec(var i : shortint;a : Longint);
- Begin
- i:=i-a;
- End;
- Procedure Inc(var i : shortint;a : Longint);
- Begin
- i:=i+a;
- End;
- Procedure Dec(var c : Char;a : Longint);
- Begin
- byte(c):=byte(c)-a;
- End;
- Procedure Inc(var c : Char;a : Longint);
- Begin
- Byte(c):=byte(c)+a;
- End;
- Procedure Dec(var p : PChar;a : Longint);
- Begin
- longint(p):=longint(p)-a;
- End;
- Procedure Inc(var p : PChar;a : Longint);
- Begin
- longint(p):=longint(p)+a;
- End;
- Function swap (X : Word) : Word;
- Begin
- swap:=(X and $ff) shl 8 + (X shr 8)
- End;
- Function Swap (X : Integer) : Integer;
- Begin
- Swap:=Integer(Swap(Word(X)));
- End;
- Function swap (X : Longint) : Longint;
- Begin
- Swap:=(X and $ffff) shl 16 + (X shr 16)
- End;
- Function Swap (X : Cardinal) : Cardinal;
- Begin
- Swap:=Swap(Longint(X));
- End;
- {$R-}
- Function Random : real;
- {
- I am not sure about the accuracy of such a value (PM)
- }
- Begin
- Random:=abs(Randseed);
- Random:=Random/(maxLongint+1.0);
- Randseed:=Randseed*134775813+1;
- Random:=(abs(Randseed)+Random)/(maxLongint+2.0);
- End;
- { Include processor specific routines }
- {$I math.inc}
- {****************************************************************************
- Set Handling
- ****************************************************************************}
- { Include set support which is processor specific}
- {$I set.inc}
- {****************************************************************************
- Memory Management
- ****************************************************************************}
- Function Ptr(sel,off : Longint) : pointer;
- Begin
- sel:=0;
- {$IFDEF DoMapping}
- {$IFDEF DoS}
- ptr:=pointer($e0000000+sel shl 4+off);
- {$ELSE}
- ptr:=pointer(sel shl 4+off);
- {$ENDIF}
- {$ELSE}
- ptr:=pointer(off);
- {$ENDIF}
- End;
- Function Addr (Var X) : Pointer;
- Begin
- Addr:=@(X);
- End;
- Function CSeg : Word;
- Begin
- Cseg:=0;
- End;
- Function DSeg : Word;
- Begin
- Dseg:=0;
- End;
- Function SSeg : Word;
- Begin
- Sseg:=0;
- End;
- {****************************************************************************
- Subroutines for short strings are in sstrings.inc
- ****************************************************************************}
- {$i sstrings.inc}
- {*****************************************************************************
- Miscellaneous
- *****************************************************************************}
- Function IOResult:Word;
- Begin
- IOResult:=InOutRes;
- InOutRes:=0;
- End;
- procedure fillchar(var x;count : longint;value : char);
- begin
- fillchar(x,count,byte(value));
- end;
- {*****************************************************************************
- Init / Exit / ExitProc
- *****************************************************************************}
- Procedure RunError;
- Begin
- RunError (0);
- End;
- Procedure Halt;
- Begin
- Halt(0);
- End;
- Procedure Initexception;[Public,Alias: 'INITEXCEPTION'];
- Begin
- Writeln('Exception occurred during program initialization.');
- halt(216);
- End;
- Procedure dump_stack(bp : Longint);
- Procedure dump_frame(addr : Longint);
- Begin
- {To be used by symify}
- Writeln(stderr,' 0x',HexStr(addr,8));
- Flush(stderr);
- End;
- var
- i, prevbp : Longint;
- Begin
- prevbp:=bp-1;
- i:=0;
- while bp > prevbp Do
- Begin
- dump_frame(get_addr(bp));
- Inc(i);
- If i>max_frame_dump Then
- exit;
- prevbp:=bp;
- bp:=get_next_frame(bp);
- End;
- End;
- Procedure Do_exit;[Public,Alias: '__EXIT'];
- {
- Don't call this direct, the call is generated by the compiler
- }
- var
- current_exit : Procedure;
- Begin
- while exitProc<>nil Do
- Begin
- InOutRes:=0;
- current_exit:=tProcedure(exitProc);
- exitProc:=nil;
- current_exit();
- End;
- If DoError Then
- Begin
- Writeln('Run time error ',Errorcode,' at 0x',hexstr(Longint(Erroraddr),8));
- dump_stack(ErrorBase);
- End;
- { this is wrong at least for dos !!!
- in dos input output and stderr must be left open !! }
- {$ifndef DOS}
- {$ifndef GO32V2}
- Close(Output);
- Close(StdErr);
- {$endif GO32V2}
- {$endif DOS}
- End;
- Type
- PExitProcInfo = ^TExitProcInfo;
- TExitProcInfo = Record
- Next : PExitProcInfo;
- SaveExit : Pointer;
- Proc : TProcedure;
- End;
- const
- ExitProcList: PExitProcInfo = nil;
- Procedure DoExitProc;
- var
- P : PExitProcInfo;
- Proc : TProcedure;
- Begin
- P:=ExitProcList;
- ExitProcList:=P^.Next;
- ExitProc:=P^.SaveExit;
- Proc:=P^.Proc;
- DisPose(P);
- Proc();
- End;
- Procedure AddExitProc(Proc: TProcedure);
- var
- P : PExitProcInfo;
- Begin
- New(P);
- P^.Next:=ExitProcList;
- P^.SaveExit:=ExitProc;
- P^.Proc:=Proc;
- ExitProcList:=P;
- ExitProc:=@DoExitProc;
- End;
- {
- $Log$
- Revision 1.5 1998-05-12 10:42:45 peter
- * moved getopts to inc/, all supported OS's need argc,argv exported
- + strpas, strlen are now exported in the systemunit
- * removed logs
- * removed $ifdef ver_above
- Revision 1.4 1998/04/16 12:30:47 peter
- + inc(pchar), dec(pchar), incc(pchar,a),dec(pchar,a)
- Revision 1.3 1998/04/08 07:53:32 michael
- + Changed Random() function. Moved from system to processor dependent files (from Pedro Gimeno)
- }
|