{ $Id$ This file is part of the Free Pascal run time library. Copyright (c) 1993,97 by the Free Pascal development team. Processor dependent implementation for the system unit for intel i386+ 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. **********************************************************************} {$ASMMODE ATT} {**************************************************************************** Move / Fill ****************************************************************************} procedure Move(var source;var dest;count:longint); begin asm movl dest,%edi movl source,%esi movl %edi,%eax movl count,%ebx { Check for back or forward } sub %esi,%eax jz .LMoveEnd { Do nothing when source=dest } jc .LFMove { Do forward, dest0 then begin {$ifndef RTLLITE} writeln('IO-Error ',l,' at 0x',HexStr(addr,8)); {$else} writeln('IO-Error ',l,' at ',addr); {$endif} halt(byte(l)); end; asm popal end; end; procedure int_re_overflow;[public,alias: 'RE_OVERFLOW']; var addr : longint; begin { Overflow was shortly before the return address } asm movl 4(%ebp),%edi movl %edi,addr end; {$ifndef RTLLITE} writeln('Overflow at 0x',HexStr(addr,8)); {$else} writeln('Overflow at ',addr); {$endif} RunError(215); end; function abs(l:longint):longint;assembler; asm movl l,%eax orl %eax,%eax jns .LMABS1 negl %eax .LMABS1: end ['EAX']; function odd(l:longint):boolean;assembler; asm movl l,%eax andl $1,%eax setnz %al end ['EAX']; function sqr(l:longint):longint;assembler; asm mov l,%eax imull %eax,%eax end ['EAX']; procedure int_str(l : longint;var s : string); var buffer : array[0..11] of byte; begin { Workaround: } if l=$80000000 then begin s:='-2147483648'; exit; end; asm movl 8(%ebp),%eax // load Integer movl 12(%ebp),%edi // Load String address xorl %ecx,%ecx // String length=0 xorl %ebx,%ebx // Buffer length=0 movl $0x0a,%esi // load 10 as dividing constant. or %eax,%eax // Sign ? jns .LM2 neg %eax movb $0x2d,1(%edi) // put '-' in String incl %ecx .LM2: cdq idivl %esi,%eax addb $0x30,%dl // convert Rest to ASCII. movb %dl,-12(%ebp,%ebx) incl %ebx cmpl $0,%eax jnz .LM2 // copy String .LM3: movb -13(%ebp,%ebx),%al // -13 because EBX is decreased only // later. movb %al,1(%edi,%ecx) incl %ecx decl %ebx jnz .LM3 movb %cl,(%edi) // Copy String length end; end; procedure int_str(c : cardinal;var s : string); var buffer : array[0..14] of byte; begin asm movl 8(%ebp),%eax // load CARDINAL movl 12(%ebp),%edi // Load String address xorl %ecx,%ecx // String length=0 xorl %ebx,%ebx // Buffer length=0 movl $0x0a,%esi // load 10 as dividing constant. .LM4: xorl %edx,%edx divl %esi,%eax addb $0x30,%dl // convert Rest to ASCII. movb %dl,-12(%ebp,%ebx) incl %ebx cmpl $0,%eax jnz .LM4 { now copy the string } .LM5: movb -13(%ebp,%ebx),%al // -13 because EBX is decreased only // later. movb %al,1(%edi,%ecx) incl %ecx decl %ebx jnz .LM5 movb %cl,(%edi) // Copy String length end; end; {$IFNDEF NEW_READWRITE} procedure f1;[public,alias: 'FLUSH_STDOUT']; begin asm pushal end; FileFunc(textrec(output).flushfunc)(textrec(output)); asm popal end; end; {$ENDIF NEW_READWRITE} Function Sptr : Longint; begin asm movl %esp,%eax addl $8,%eax movl %eax,-4(%ebp) end ['EAX']; end; {$I386_ATT} {can be removed} {$I386_DIRECT} {can be removed} {$ASMMODE ATT} { $Log$ Revision 1.16 1998-07-02 12:55:04 carl * Put back DoError, DO NOT TOUCH! Revision 1.15 1998/07/02 12:19:32 carl + IO-Error and Overflow now print address in hex Revision 1.14 1998/07/01 15:29:58 peter * better readln/writeln Revision 1.13 1998/06/26 08:20:57 daniel - Doerror removed. Revision 1.12 1998/05/31 14:15:47 peter * force to use ATT or direct parsing Revision 1.11 1998/05/30 14:30:21 peter * force att reading Revision 1.10 1998/05/25 10:40:49 peter * remake3 works again on tflily Revision 1.5 1998/04/29 13:28:19 peter * some cleanup and i386_att usage Revision 1.4 1998/04/10 15:41:54 florian + some small comments added Revision 1.3 1998/04/10 15:25:23 michael - Removed so-called better random function Revision 1.2 1998/04/08 07:53:31 michael + Changed Random() function. Moved from system to processor dependent files (from Pedro Gimeno) }