* Redone the syscalls

This commit is contained in:
marco 2000-02-27 23:45:39 +00:00
parent e55c2abd01
commit a8e778f685

View File

@ -30,6 +30,143 @@
For now I do them in assembler, which makes it easier to test them (copy and For now I do them in assembler, which makes it easier to test them (copy and
paste to and AS source). Ultimately I hope to design something like this} paste to and AS source). Ultimately I hope to design something like this}
{actualsyscall:
_actualsyscall : int $0x80
jb someerror
ret
someerror: storeerrorsomewhere
ret
}
function Do_SysCall(sysnr,param1:LONGINT):longint;
var retval:longint;
begin
asm
movl sysnr,%eax
pushl Param1
call _actualsyscall
addl $4,%esp
mov %eax,Retval
end;
if RetVal<0 then
begin
ErrNo:=-RetVal;
DoSysCall:=-1;
end
else
begin
DoSysCall:=Retval;
errno:=0
end;
end;
function Do_SysCall(sysnr,param1,param2:LONGINT):longint;
var retval:longint;
begin
asm
movl sysnr,%eax
pushl param2
pushl Param1
call _actualsyscall
addl $8,%esp
mov %eax,Retval
end;
if RetVal<0 then
begin
ErrNo:=-RetVal;
DoSysCall:=-1;
end
else
begin
DoSysCall:=Retval;
errno:=0
end;
end;
function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint;
var retval:longint;
begin
asm
movl sysnr,%eax
pushl param3
pushl param2
pushl Param1
call _actualsyscall
addl $12,%esp
mov %eax,Retval
end;
if RetVal<0 then
begin
ErrNo:=-RetVal;
DoSysCall:=-1;
end
else
begin
DoSysCall:=Retval;
errno:=0
end;
end;
function Do_SysCall(sysnr,param1,param2:longint;param3:word):longint;
var retval:longint;
begin
asm
movl sysnr,%eax
pushw param3
pushl param2
pushl Param1
call _actualsyscall
addl $12,%esp
mov %eax,Retval
end;
if RetVal<0 then
begin
ErrNo:=-RetVal;
DoSysCall:=-1;
end
else
begin
DoSysCall:=Retval;
errno:=0
end;
end;
function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint;
var retval:longint;
begin
asm
movl sysnr,%eax
pushl param4
pushl param3
pushl param2
pushl Param1
call _actualsyscall
addl $16,%esp
mov %eax,Retval
end;
if RetVal<0 then
begin
ErrNo:=-RetVal;
DoSysCall:=-1;
end
else
begin
DoSysCall:=Retval;
errno:=0
end;
end;
{ {
Function SysCall( callnr:longint;var regs : SysCallregs ):longint; Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
{ {
@ -41,37 +178,14 @@ begin
do_SysCall(callnr,regs); do_SysCall(callnr,regs);
if regs.reg1<0 then if regs.reg1<0 then
begin begin
{$IFDEF SYSCALL_DEBUG}
If DoSysCallDebug then
debugtxt:=' syscall error: ';
{$endif}
ErrNo:=-regs.reg1; ErrNo:=-regs.reg1;
SysCall:=-1; SysCall:=-1;
end end
else else
begin begin
{$IFDEF SYSCALL_DEBUG}
if DoSysCallDebug then
debugtxt:=' syscall returned: ';
{$endif}
SysCall:=regs.reg1; SysCall:=regs.reg1;
errno:=0 errno:=0
end; end;
{$IFDEF SYSCALL_DEBUG}
if DoSysCallDebug then
begin
inc(lastcnt);
if (callnr<>lastcall) or (regs.reg1<>lasteax) then
begin
if lastcnt>1 then
writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
lastcall:=callnr;
lasteax:=regs.reg1;
lastcnt:=0;
writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
end;
end;
{$endif}
end; end;
} }
@ -104,22 +218,16 @@ end;
Function Sys_Time:longint; Function Sys_Time:longint;
VAR tv : timeval; VAR tv : timeval;
tz : timezone; tz : timezone;
retval : longint; retval : longint;
begin
asm
lea tz,%ebx
pushl %ebx
lea tv,%ecx
pushl %ecx
mov $116,%eax
int $0x80
add $8,%esp
mov %eax,retval
end;
sys_time:=checkreturnvalue(retval,tv.sec); begin
Retval:=DoSyscall(116,longint(tv),longint(tz));
If retval=-1 then
sys_time:=-1
else
sys_time:=tv.sec;
end; end;
{***************************************************************************** {*****************************************************************************
@ -129,117 +237,44 @@ end;
Function Sys_Open(f:pchar;flags:longint;mode:integer):longint; Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
var retval: LONGINT;
Begin Begin
asm sys_open:=DoSyscall(5,longint(f),flags,mode);
pushw mode
pushl flags
pushl f
movl $5,%eax
int $0x80
add $10,%esp
mov %eax,retval
end;
sys_open:=checkreturnvalue(retval,retval);
End; End;
Function Sys_Close(f:longint):longint; Function Sys_Close(f:longint):longint;
var retval: LONGINT;
begin begin
asm sys_close:=DoSyscall(6,f);
pushl f
movl $6,%eax
int $0x80
addl $4,%esp
mov %eax,retval
end;
Sys_Close:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint; Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
var retval: LONGINT;
begin begin
asm sys_lseek:=DoSyscall(199,F,Off,Whence);
pushl Whence
pushl Off
pushl F
mov $199,%eax
int $0x80
addl $12,%eax
mov %eax,retval
end;
Sys_Lseek:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Read(f:longint;buffer:pchar;count:longint):longint; Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
var retval: LONGINT;
begin begin
asm sys_read:=DoSyscall(3,F,longint(buffer),count);
pushl Count
pushl Buffer
pushl F
mov $3,%eax
int $0x80
addl $12,%eax
mov %eax,retval
end;
Sys_Read:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Write(f:longint;buffer:pchar;count:longint):longint; Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
var retval: LONGINT;
begin begin
asm sys_write:=DoSyscall(4,F,longint(buffer),count);
pushl Count
pushl Buffer
pushl F
mov $4,%eax
int $0x80
addl $12,%eax
mov %eax,retval
end;
Sys_Write:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Unlink(Filename:pchar):longint; Function Sys_Unlink(Filename:pchar):longint;
var retval: LONGINT;
begin begin
asm sys_unlink:=DoSyscall(10,longint(Filename));
pushl FileName
mov $10,%eax
int $0x80
addl $4,%eax
mov %eax,retval
end;
Sys_UnLink:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Rename(Oldname,Newname:pchar):longint; Function Sys_Rename(Oldname,Newname:pchar):longint;
var retval: LONGINT;
begin begin
asm sys_rename:=DoSyscall(38,longint(oldname),longint(newname));
pushl NewName
pushl OldName
mov $38,%eax
int $0x80
addl $8,%eax
mov %eax,retval
end;
Sys_Rename:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Stat(Filename:pchar;var Buffer: stat):longint; Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
@ -247,36 +282,17 @@ Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
We need this for getcwd We need this for getcwd
} }
var retval: LONGINT;
begin begin
asm sys_stat:=DoSyscall(188,longint(filename),longint(@buffer));
pushl buffer
pushl FileName
mov $188,%eax
int $0x80
addl $8,%eax
mov %eax,retval
end;
Sys_Stat:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Symlink(oldname,newname:pchar):longint; Function Sys_Symlink(oldname,newname:pchar):longint;
{ {
We need this for erase We need this for erase
} }
var retval : longint;
begin begin
asm sys_symlink:=DoSyscall(57,longint(oldname),longint(newname));
pushl newname
pushl oldname
mov $57,%eax
int $0x80
addl $8,%eax
mov %eax,retval
end;
Sys_Symlink:=checkreturnvalue(retval,retval);
end; end;
{***************************************************************************** {*****************************************************************************
@ -285,49 +301,21 @@ end;
Function Sys_Chdir(Filename:pchar):longint; Function Sys_Chdir(Filename:pchar):longint;
var retval : longint;
begin begin
asm sys_chdir(12,longint(filename));
pushl FileName
mov $12,%eax
int $0x80
addl $4,%eax
mov %eax,retval
end;
Sys_ChDir:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Mkdir(Filename:pchar;mode:longint):longint; Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
var retval : longint;
begin {Mode is 16-bit on F-BSD} begin {Mode is 16-bit on F-BSD}
asm asm
mov mode,%eax sys_mkdir:=dosyscall(longint(filename),mode shl 8);
pushw %ax
pushl FileName
mov $136,%eax
int $0x80
addl $6,%eax
mov %eax,retval
end;
Sys_MkDir:=checkreturnvalue(retval,retval);
end; end;
Function Sys_Rmdir(Filename:pchar):longint; Function Sys_Rmdir(Filename:pchar):longint;
var retval : longint;
begin begin
asm sys_rmdir:=Dosyscall(137,longint(filename));
pushl FileName
mov $137,%eax
int $0x80
addl $4,%eax
mov %eax,retval
end;
Sys_RmDir:=checkreturnvalue(retval,retval);
end; end;
{ we need this for getcwd, NOT touched for BSD version } { we need this for getcwd, NOT touched for BSD version }
@ -376,18 +364,7 @@ Function Sys_ReadDir(p:pdir):pdirent;
var var
retval : longint; retval : longint;
begin begin
retval:=SIZEOF(dirent) ; retval:=dosyscall(272,longint(@p.fd),longint(@p.buf),sizeof(dirent));
asm
mov p,%esi
push retval
push tdir.buf(%esi)
push tdir.fd(%esi)
mov $272,%eax
int $0x80
addl $12,%esp
mov %eax,retval
end;
retval:=checkreturnvalue(retval,retval);
if retval=0 then if retval=0 then
sys_readdir:=nil sys_readdir:=nil
else else
@ -400,22 +377,17 @@ end;
Procedure Sys_Exit(ExitCode:longint); Procedure Sys_Exit(ExitCode:longint);
var retval : longint;
begin begin
asm asm
pushl ExitCode sys_exit:=dosyscall(1,exitcode);
mov $1,%eax
int $0x80
addl $4,%eax
mov %eax,retval
end;
checkreturnvalue(retval,retval); {is nonsense :-)}
end; end;
{ {
$Log$ $Log$
Revision 1.5 2000-02-04 16:53:26 marco Revision 1.6 2000-02-27 23:45:39 marco
* Redone the syscalls
Revision 1.5 2000/02/04 16:53:26 marco
* Finished Linux (and rest syscalls) roughly. Some things still need to be * Finished Linux (and rest syscalls) roughly. Some things still need to be
tested, and checked (off_t calls specially) tested, and checked (off_t calls specially)