Ver Fonte

+ Support files for system-dependent file related calls

michael há 27 anos atrás
pai
commit
0e2d38d46e
3 ficheiros alterados com 318 adições e 0 exclusões
  1. 78 0
      fcl/linux/oscalls.inc
  2. 148 0
      fcl/linux/osfile.inc
  3. 92 0
      fcl/template/osfile.inc

+ 78 - 0
fcl/linux/oscalls.inc

@@ -0,0 +1,78 @@
+{
+    $Id$
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 1998 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.
+
+ **********************************************************************}
+
+{
+  Implementation of some system calls.
+}
+
+Type SysCallRegs = Record
+       reg1,reg2,reg3,reg4,reg5,reg6 : Longint;
+     end;
+
+
+Const
+  { Needed call numbers }
+  syscall_nr_read      = 3; 
+  syscall_nr_write     = 4;
+  syscall_nr_open      = 5;
+  syscall_nr_close     = 6;
+  syscall_nr_lseek     = 19;
+  syscall_nr_ftruncate = 93;
+
+
+  { Things for OPEN call - after linux/fcntl.h }
+  Open_Accmode  = 3;
+  Open_RdOnly   = 0;
+  Open_WrOnly   = 1;
+  Open_RdWr     = 2;
+  Open_Creat    = 1 shl 6;
+  Open_Excl     = 2 shl 6;
+  Open_NoCtty   = 4 shl 6;
+  Open_Trunc    = 1 shl 9;
+  Open_Append   = 2 shl 9;
+  Open_NonBlock = 4 shl 9;
+  Open_NDelay   = Open_NonBlock;
+  Open_Sync     = 1 shl 12;
+
+
+Procedure Do_SysCall( callnr:longint;var regs : SysCallregs );assembler;
+{
+  This function puts the registers in place, does the call, and then
+  copies back the registers as they are after the SysCall.
+}
+{$ASMMODE ATT}
+asm
+{ load the registers... }
+  movl 12(%ebp),%eax
+  movl 4(%eax),%ebx
+  movl 8(%eax),%ecx
+  movl 12(%eax),%edx
+  movl 16(%eax),%esi
+  movl 20(%eax),%edi
+{ set the call number }
+  movl 8(%ebp),%eax
+{ Go ! }
+  int $0x80
+{ Put back the registers... }
+  pushl %eax
+  movl 12(%ebp),%eax
+  movl %edi,20(%eax)
+  movl %esi,16(%eax)
+  movl %edx,12(%eax)
+  movl %ecx,8(%eax)
+  movl %ebx,4(%eax)
+  popl %ebx
+  movl %ebx,(%eax)
+end;
+{$ASMMODE DEFAULT}

+ 148 - 0
fcl/linux/osfile.inc

@@ -0,0 +1,148 @@
+{
+    $Id$
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 1998 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.
+
+ **********************************************************************}
+{
+ This file implements the system-dependent calls needed for the 
+ classes unit.
+}
+
+{
+  oscalls contains a copy of the needed functions from syscalls.inc
+  to make things go faster.
+}
+
+{$i oscalls.inc}
+
+Function OSCreateFile (Const Filename : string; Mode : Longint) : longint;
+{
+  Creates a file with name FileName, using mode MODE
+  --> Filename : String giving the path to the file.
+      Mode     : Mode can be
+                 fmCreate    : Create file;
+                 fmOpenRead  : open for reading;
+                 fmOpenWrite : open for writing;
+  <-- File Handle, or -1 on error.
+}
+
+var
+  regs : SysCallregs;
+  NewName : string;
+
+Begin
+  // Convert mode. The  meaning of fmcreate isn't 
+  // entirely clear..
+  if (mode and fmcreate) = fmcreate then
+    mode:=OPEN_CREAT or OPEN_RDWR;
+  //!! This MUST be changed when using ansistrings !!!
+  NewName:=FileName+#0;
+  regs.reg2:=longint(@NewName[1]);
+  regs.reg3:=Mode;
+  regs.reg4:=438;        { 666 octal }
+  Do_SysCall(SysCall_nr_open,regs);
+  Result:=regs.reg1;
+  Writeln ('Create result : ', regs.reg1);
+  If Result<0 then Result:=-1;
+End;
+
+Function OSReadHandle(Handle : Longint;Var Buffer; Count : Longint): Longint;
+{
+  Read from a handle
+  --> Handle : file,pipe,etc Handle to read from.
+      Buffer : Location where to put the read bytes.
+      Count  : Number of bytes that should be read
+  <-- Number of bytes actually read, or -1 on error.   
+}
+var sr : syscallregs;
+
+begin
+  sr.reg2:=Handle;
+  sr.reg3:=Longint(@Buffer);
+  sr.reg4:=Count;
+  Do_Syscall (syscall_nr_read,sr);
+  Result:=sr.reg1;
+  If Result<-1 then Result:=-1;  
+end;
+
+Function OSWriteHandle(Handle : Longint;var Buffer; Count : longint) : Longint;
+{ 
+  Write to a handle
+  --> Handle : file,pipe,etc Handle to write to.
+      Buffer : Location where to get the bytes.
+      Count  : Number of bytes that should be written.
+  <-- Number of bytes actually written, or -1 on error.   
+}
+Var sr: syscallregs;
+
+begin
+  sr.reg2:=Handle;
+  sr.reg3:=Longint(@Buffer);
+  sr.reg4:=Count;
+  Do_Syscall (syscall_nr_write,sr);
+  Result:=sr.reg1;
+  If Result<-1 then Result:=-1;  
+end;
+
+
+Function OSSetHandleSize (Handle,Size : Longint) : longint;
+{
+  Set size of handle (for files only)
+  --> Handle : Handle to set size for.
+      Size   : Size to be set.
+  <-- 0 on succes or -1 on error.
+}
+Var sr: syscallregs;
+
+begin
+  sr.reg2:=Handle;
+  sr.reg3:=Size;
+  Do_Syscall (SysCall_nr_Ftruncate,sr);
+  Result:=sr.reg1;
+  If Result<-1 then Result:=-1;
+end;
+
+Function OSSeekHandle (Handle,OffSet,Origin : longint) : longint;
+{
+  Seek Handle position starting from Origin
+  --> Handle : Handle of file to do seek on.
+      Offset : Position to seek.
+      Origin : Where to start seek: 
+               soFromBeginning 
+               soFromCurrent
+               soFromEnd 
+  <-- -1 on error, else the new fileposition in bytes from the origin.
+}
+var sr : syscallregs;
+
+begin
+  sr.reg2:=Handle;
+  sr.reg3:=Offset;
+  sr.reg4:=Origin;
+  Do_Syscall(Syscall_nr_lseek,sr);
+  Result:=sr.reg1;
+  If Result<-1 then Result:=-1;
+end;
+
+Function OSCloseHandle (Handle : longint) : longint;
+{
+  Close file associated with HAndle.
+  --> Handle : Handle of file to do seek on.
+  <-- 0 on succes, -1 on error.
+}
+Var sr : syscallregs;
+
+begin
+  sr.reg2:=Handle;
+  Do_Syscall (syscall_nr_close,sr);
+  Result:=sr.reg1;
+  If Result<-1 then Result:=-1;
+end;

+ 92 - 0
fcl/template/osfile.inc

@@ -0,0 +1,92 @@
+{
+    $Id$
+    This file is part of the Free Component Library (FCL)
+    Copyright (c) 1998 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.
+
+ **********************************************************************}
+{
+
+ This file implements the system-dependent calls needed for the 
+ classes unit.
+ 
+}
+
+Function OSCreateFile (Const Filename : string; Mode : Longint) : longint;
+{
+  Creates a file with name FileName, using mode MODE
+  --> Filename : String giving the path to the file.
+      Mode     : Mode can be
+                 fmCreate    : Create file;
+                 fmOpenRead  : open for reading;
+                 fmOpenWrite : open for writing;
+  <-- File Handle, or -1 on error.
+}
+begin
+end;
+
+Function OSReadHandle(Handle : Longint;Var Buffer; Count : Longint): Longint;
+{
+  Read from a handle
+  --> Handle : file,pipe,etc Handle to read from.
+      Buffer : Location where to put the read bytes.
+      Count  : Number of bytes that should be read
+  <-- Number of bytes actually read, or -1 on error.   
+}
+
+begin
+end;
+
+Function OSWriteHandle(Handle : Longint;var Buffer; Count : longint) : Longint;
+{ 
+  Write to a handle
+  --> Handle : file,pipe,etc Handle to write to.
+      Buffer : Location where to get the bytes.
+      Count  : Number of bytes that should be written.
+  <-- Number of bytes actually written, or -1 on error.   
+}
+begin
+end;
+
+
+Function OSSetHandleSize (Handle,Size : Longint) : longint;
+{
+  Set size of handle (for files only)
+  --> Handle : Handle to set size for.
+      Size   : Size to be set.
+  <-- 0 on success, or -1 on error.
+}
+begin
+end;
+
+Function OSSeekHandle (FHandle,OffSet,Origin : longint) : longint;
+{
+  Seek Handle position starting from Origin
+  --> Handle : Handle of file to do seek on.
+      Offset : Position to seek.
+      Origin : Where to start seek: 
+               soFromBeginning 
+               soFromCurrent
+               soFromEnd 
+  <-- 0 on succes, -1 on error.
+}
+
+begin
+end;
+
+
+Function OSCloseHandle (Handle : longint) : longint;
+{
+  Close file associated with HAndle.
+  --> Handle : Handle of file to do seek on.
+  <-- 0 on succes, -1 on error.
+}
+
+begin
+end;