24
24
--- Main:The System Call Self ---
25
25
*****************************************************************************}
27
{ The system designed for Linux can't be used for FreeBSD so easily, since
28
FreeBSD pushes arguments, instead of loading them to registers.
30
For now I do them in assembler, which makes it easier to test them (copy and
31
paste to and AS source). Ultimately I hope to design something like this}
34
_actualsyscall : int $0x80
37
someerror: storeerrorsomewhere
42
procedure actualsyscall; cdecl; EXTERNAL NAME '_actualsyscall';
45
procedure actualsyscall; assembler;
57
function Do_SysCall(sysnr:LONGINT):longint; assembler;
65
function Do_SysCall(sysnr,param1:longint):longint; assembler;
75
function Do_SysCall(sysnr,param1:integer):longint; assembler;
86
function Do_SysCall(sysnr,param1,param2:LONGINT):longint; assembler;
97
function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint; assembler;
109
function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint; assembler;
123
function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint; assembler;
137
function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:LONGINT):longint; assembler;
153
function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:LONGINT):longint; assembler;
169
Function Sys_Time:longint;
176
Retval:=do_syscall(116,longint(@tv),longint(@tz));
183
{*****************************************************************************
184
--- File:File handling related calls ---
185
*****************************************************************************}
188
Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
191
sys_open:=do_syscall(syscall_nr_open,longint(f),flags,mode);
194
Function Sys_Close(f:longint):longint;
197
sys_close:=do_syscall(syscall_nr_close,f);
201
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
203
var returnvalue64 : array[0..1] of longint;
206
{Lseek's offset is 64-bit, the highword is the 0}
207
do_syscall(syscall_nr_lseek,longint(@returnvalue64),F,Off,0,Whence);
208
sys_lseek:=returnvalue64[0];
213
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint; assembler;
215
{this one is special for the return value being 64-bit..}
219
pushl $0 // high dword
223
pushl $0 // Your guess is as good as mine.
224
pushl $0xc7 // Actual lseek syscall number.
231
Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
234
sys_read:=do_syscall(syscall_nr_read,F,longint(buffer),count);
237
Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
240
sys_write:=do_syscall(syscall_nr_write,F,longint(buffer),count);
243
Function Sys_Unlink(Filename:pchar):longint;
246
sys_unlink:=do_syscall(syscall_nr_unlink,longint(Filename));
249
Function Sys_Rename(Oldname,Newname:pchar):longint;
252
sys_rename:=do_syscall(syscall_nr_rename,longint(oldname),longint(newname));
255
Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
257
We need this for getcwd
261
sys_stat:=do_syscall(syscall_nr_stat,longint(filename),longint(@buffer));
264
Function Sys_Symlink(oldname,newname:pchar):longint;
266
We need this for erase
270
sys_symlink:=do_syscall(syscall_nr_symlink,longint(oldname),longint(newname));
274
Function Sys_ReadLink(name,linkname:pchar;maxlen:longint):longint;
277
sys_readlink:=do_syscall(syscall_nr_readlink, longint(name),longint(linkname),maxlen);
282
{*****************************************************************************
283
--- Directory:Directory related calls ---
284
*****************************************************************************}
286
Function Sys_Chdir(Filename:pchar):longint;
289
sys_chdir:=do_syscall(syscall_nr_chdir,longint(filename));
292
Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
294
begin {Mode is 16-bit on F-BSD}
295
sys_mkdir:=do_syscall(syscall_nr_mkdir,longint(filename),mode );
298
Function Sys_Rmdir(Filename:pchar):longint;
301
sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(filename));
305
const DIRBLKSIZ=1024;
308
{ we need this for getcwd, NOT touched for BSD version }
309
Function OpenDir(f:pchar):pdir;
317
if sys_stat(f,st)<0 then
320
if not((st.mode and $f000)=$4000)then
326
fd:=sys_open(f,OPEN_RDONLY,438);
332
Getmem(ptr^.buf,2*DIRBLKSIZ);
337
ptr^.rewind:=longint(ptr^.buf);
339
// ptr^.dd_max:=sizeof(ptr^.buf^);
343
function CloseDir(p:pdir):integer;
345
closedir:=sys_close(p^.fd);
351
Function Sys_ReadDir(p:pdir):pdirent;
352
{Different from Linux, Readdir on BSD is based on Getdents, due to the
353
missing of the readdir syscall.
354
Getdents requires the buffer to be larger than the blocksize.
355
This usually the sectorsize =512 bytes, but maybe tapedrives and harddisks
356
with blockmode have this higher?}
358
function readbuffer:longint;
363
retval:=do_syscall(syscall_nr_getdents,longint(p^.fd),longint(@p^.buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
364
p^.rewind:=longint(p^.buf);
380
if (p^.buf=nil) or (p^.loc=0) THEN
382
if p^.loc=-1 then {First readdir on this pdir. Initial fill of buffer}
384
if readbuffer()=0 Then {nothing to be read}
390
if (pdirent(p^.rewind)^.reclen<>0) then
391
begin {valid direntry?}
392
if pdirent(P^.rewind)^.ino<>0 then
393
l:=pdirent(p^.rewind);
394
inc(p^.rewind,pdirent(p^.rewind)^.reclen);
395
if p^.rewind>=(longint(p^.buf)+dirblksiz) then
401
begin {block entirely searched or reclen=0}
402
if p^.loc<>0 THEN {blocks left?}
403
if readbuffer()<>0 then {succesful read?}
406
until (l<>nil) or novalid;
411
{*****************************************************************************
412
--- Process:Process & program handling - related calls ---
413
*****************************************************************************}
416
Function sys_GetPid:LongInt;
422
sys_GetPID:=do_syscall(syscall_nr_getpid);
425
Procedure Sys_Exit(ExitCode:longint);
428
do_syscall(syscall_nr_exit,exitcode);
432
Change action of process upon receipt of a signal.
433
Signum specifies the signal (all except SigKill and SigStop).
434
If Act is non-nil, it is used to specify the new action.
435
If OldAct is non-nil the previous action is saved there.
440
Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
442
Change action of process upon receipt of a signal.
443
Signum specifies the signal (all except SigKill and SigStop).
444
If Act is non-nil, it is used to specify the new action.
445
If OldAct is non-nil the previous action is saved there.
449
do_syscall(syscall_nr_sigaction,longint(signum),longint(act),longint(oldact));
28
Function fpmmap(adr:pointer;len:TSize;prot:cint;flags:cint;fdes:cint;off:TOff):cint; // moved from sysunix.inc, used in sbrk
30
{$ifdef LITTLE_ENDIAN}
31
fpmmap:=do_syscall(syscall_nr_mmap,Adr,Len,Prot,Flags,fdes,lo(off),0);
33
fpmmap:=do_syscall(syscall_nr_mmap,TSysParam(Adr),TSysParam(Len),Prot,Flags,fdes,0,lo(off));
457
39
$Log: syscalls.inc,v $
458
Revision 1.1.2.3 2000/09/19 09:58:49 marco
461
Revision 1.1.2.2 2000/09/18 12:14:41 marco
462
* An addw in the do_syscall(integer) caused warnings. Fixed
464
Revision 1.1.2.1 2000/09/16 11:19:08 marco
465
* Moved files from BSD to FreeBSD directory, with some small changes
467
Revision 1.1.2.1 2000/09/10 16:12:14 marco
468
Initial signals, sockets and clone
470
Revision 1.1 2000/07/13 06:30:32 michael
473
Revision 1.15 2000/04/16 16:08:53 marco
474
* Fixes (mainly opendir/Readdir/closedir)
476
Revision 1.14 2000/04/14 17:04:13 marco
479
Revision 1.13 2000/04/10 15:46:52 marco
480
* worked all day. probably a lot changed
482
Revision 1.11 2000/04/05 13:58:40 marco
483
* syscall variablenames reintroduced.
485
Revision 1.10 2000/03/16 16:18:12 marco
486
* Last changes before next test. ppc386 -h works with these srcs.
488
Revision 1.9 2000/03/02 15:34:07 marco
489
* added a syscall for 5 longints
491
Revision 1.8 2000/03/01 20:03:57 marco
492
* small fixes for syslinux
494
Revision 1.7 2000/03/01 17:28:40 marco
495
* some changes due to updating linux.pp to new syscall
497
Revision 1.6 2000/02/27 23:45:39 marco
498
* Redone the syscalls
500
Revision 1.5 2000/02/04 16:53:26 marco
501
* Finished Linux (and rest syscalls) roughly. Some things still need to be
502
tested, and checked (off_t calls specially)
504
Revision 1.4 2000/02/03 17:04:47 marco
505
* additions fixes due to port linux
507
Revision 1.3 2000/02/02 18:07:27 marco
508
* Ported except for readdir which is 200 lines C code in FBSD linux
511
Revision 1.2 2000/02/02 16:35:10 marco
512
* Ported more functions. Half done now.
514
Revision 1.1 2000/02/02 15:41:56 marco
515
* Initial BSD version. Still needs a lot of work.
40
Revision 1.13 2003/09/16 12:58:35 marco
41
* fixje voor mmap parameter typering veranderingen
43
Revision 1.12 2003/09/14 20:15:01 marco
44
* Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
46
Revision 1.11 2003/06/01 16:35:28 marco
47
* Several small fixes to harmonize the *BSD rtls and Linux.
49
Revision 1.10 2003/01/05 19:02:29 marco
50
* Should now work with baseunx. (gmake all works)
52
Revision 1.9 2002/09/07 16:01:17 peter
53
* old logs removed and tabs fixed
55
Revision 1.8 2002/05/06 07:27:39 marco
56
* Fixed a readdir bug, already fixed in januari in 1.0.x