~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to rtl/freebsd/syscalls.inc

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
 
    $Id: syscalls.inc,v 1.1.2.3 2000/09/19 09:58:49 marco Exp $
 
2
    $Id: syscalls.inc,v 1.13 2003/09/16 12:58:35 marco Exp $
3
3
    This file is part of the Free Pascal run time library.
4
4
    Copyright (c) 1999-2000 by Michael Van Canneyt,
5
5
    member of the Free Pascal development team.
24
24
                     --- Main:The System Call Self ---
25
25
*****************************************************************************}
26
26
 
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.
29
 
 
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}
32
 
 
33
 
{actualsyscall:
34
 
  _actualsyscall : int $0x80
35
 
                   jb someerror
36
 
                   ret
37
 
      someerror:   storeerrorsomewhere
38
 
                   ret
39
 
}
40
 
 
41
 
{
42
 
procedure actualsyscall; cdecl; EXTERNAL NAME '_actualsyscall';
43
 
}
44
 
 
45
 
procedure actualsyscall; assembler;
46
 
    asm
47
 
         int $0x80
48
 
         jb .LErrorcode
49
 
         xor %ebx,%ebx
50
 
         ret
51
 
.LErrorcode:
52
 
         mov %eax,%ebx
53
 
         mov $-1,%eax
54
 
   end;
55
 
 
56
 
 
57
 
function Do_SysCall(sysnr:LONGINT):longint; assembler;
58
 
 
59
 
asm
60
 
  movl  sysnr,%eax
61
 
  call  actualsyscall
62
 
  movw  %bx,Errno
63
 
end;
64
 
 
65
 
function Do_SysCall(sysnr,param1:longint):longint; assembler;
66
 
 
67
 
 asm
68
 
  movl  sysnr,%eax
69
 
  pushl Param1
70
 
  call  actualsyscall
71
 
  addl  $4,%esp
72
 
  movw  %bx,Errno
73
 
 end;
74
 
 
75
 
function Do_SysCall(sysnr,param1:integer):longint; assembler;
76
 
 
77
 
 asm
78
 
  movl  sysnr,%eax
79
 
  pushw Param1
80
 
  call  actualsyscall
81
 
  addl  $2,%esp
82
 
  movw  %bx,Errno
83
 
 end;
84
 
 
85
 
 
86
 
function Do_SysCall(sysnr,param1,param2:LONGINT):longint; assembler;
87
 
 
88
 
 asm
89
 
   movl  sysnr,%eax
90
 
   pushl param2
91
 
   pushl Param1
92
 
   call  actualsyscall
93
 
   addl  $8,%esp
94
 
   movw  %bx,Errno
95
 
 end;
96
 
 
97
 
function Do_SysCall(sysnr,param1,param2,param3:LONGINT):longint; assembler;
98
 
 
99
 
 asm
100
 
   movl  sysnr,%eax
101
 
   pushl param3
102
 
   pushl param2
103
 
   pushl Param1
104
 
   call  actualsyscall
105
 
   addl  $12,%esp
106
 
   movw  %bx,Errno
107
 
 end;
108
 
 
109
 
function Do_SysCall(sysnr,param1,param2,param3,param4:LONGINT):longint; assembler;
110
 
 
111
 
asm
112
 
   movl  sysnr,%eax
113
 
   pushl param4
114
 
   pushl param3
115
 
   pushl param2
116
 
   pushl Param1
117
 
   call  actualsyscall
118
 
   addl  $16,%esp
119
 
   movw  %bx,Errno
120
 
end;
121
 
 
122
 
 
123
 
function Do_SysCall(sysnr,param1,param2,param3,param4,param5:LONGINT):longint;  assembler;
124
 
 
125
 
 asm
126
 
   movl  sysnr,%eax
127
 
   pushl param5
128
 
   pushl param4
129
 
   pushl param3
130
 
   pushl param2
131
 
   pushl Param1
132
 
   call  actualsyscall
133
 
   addl  $20,%esp
134
 
   movw  %bx,Errno
135
 
 end;
136
 
 
137
 
function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:LONGINT):longint;  assembler;
138
 
 
139
 
asm
140
 
   movl  sysnr,%eax
141
 
   pushl param6
142
 
   pushl param5
143
 
   pushl param4
144
 
   pushl param3
145
 
   pushl param2
146
 
   pushl Param1
147
 
   call  actualsyscall
148
 
   addl  $24,%esp
149
 
   movw  %bx,Errno
150
 
end;
151
 
 
152
 
 
153
 
function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6,param7:LONGINT):longint;  assembler;
154
 
 
155
 
asm
156
 
   movl  sysnr,%eax
157
 
   pushl param7
158
 
   pushl param6
159
 
   pushl param5
160
 
   pushl param4
161
 
   pushl param3
162
 
   pushl param2
163
 
   pushl Param1
164
 
   call  actualsyscall
165
 
   addl  $28,%esp
166
 
   movw  %bx,Errno
167
 
end;
168
 
 
169
 
Function Sys_Time:longint;
170
 
 
171
 
VAR tv     : timeval;
172
 
    tz     : timezone;
173
 
    retval : longint;
174
 
 
175
 
begin
176
 
  Retval:=do_syscall(116,longint(@tv),longint(@tz));
177
 
  If retval=-1 then
178
 
   sys_time:=-1
179
 
  else
180
 
   sys_time:=tv.sec;
181
 
end;
182
 
 
183
 
{*****************************************************************************
184
 
               --- File:File handling related calls ---
185
 
*****************************************************************************}
186
 
 
187
 
 
188
 
Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
189
 
 
190
 
Begin
191
 
 sys_open:=do_syscall(syscall_nr_open,longint(f),flags,mode);
192
 
End;
193
 
 
194
 
Function Sys_Close(f:longint):longint;
195
 
 
196
 
begin
197
 
 sys_close:=do_syscall(syscall_nr_close,f);
198
 
end;
199
 
 
200
 
{
201
 
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
202
 
 
203
 
var returnvalue64 : array[0..1] of longint;
204
 
 
205
 
begin
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];
209
 
end;
210
 
 
211
 
}
212
 
 
213
 
Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint; assembler;
214
 
 
215
 
{this one is special for the return value being 64-bit..}
216
 
 
217
 
 asm
218
 
  pushl Whence
219
 
  pushl $0      // high dword
220
 
  pushl Off
221
 
  pushl $0
222
 
  pushl F
223
 
  pushl $0      // Your guess is as good as mine.
224
 
  pushl $0xc7   // Actual lseek syscall number.
225
 
  movl  $0xc6,%eax
226
 
  call  actualsyscall
227
 
  addl  $28,%esp
228
 
  mov   %ebx,Errno
229
 
 end;
230
 
 
231
 
Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
232
 
 
233
 
begin
234
 
  sys_read:=do_syscall(syscall_nr_read,F,longint(buffer),count);
235
 
end;
236
 
 
237
 
Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
238
 
 
239
 
begin
240
 
 sys_write:=do_syscall(syscall_nr_write,F,longint(buffer),count);
241
 
end;
242
 
 
243
 
Function Sys_Unlink(Filename:pchar):longint;
244
 
 
245
 
begin
246
 
  sys_unlink:=do_syscall(syscall_nr_unlink,longint(Filename));
247
 
end;
248
 
 
249
 
Function Sys_Rename(Oldname,Newname:pchar):longint;
250
 
 
251
 
begin
252
 
  sys_rename:=do_syscall(syscall_nr_rename,longint(oldname),longint(newname));
253
 
end;
254
 
 
255
 
Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
256
 
{
257
 
   We need this for getcwd
258
 
}
259
 
 
260
 
begin
261
 
 sys_stat:=do_syscall(syscall_nr_stat,longint(filename),longint(@buffer));
262
 
end;
263
 
 
264
 
Function Sys_Symlink(oldname,newname:pchar):longint;
265
 
{
266
 
  We need this for erase
267
 
}
268
 
 
269
 
begin
270
 
 sys_symlink:=do_syscall(syscall_nr_symlink,longint(oldname),longint(newname));
271
 
end;
272
 
 
273
 
 
274
 
Function Sys_ReadLink(name,linkname:pchar;maxlen:longint):longint;
275
 
 
276
 
begin
277
 
  sys_readlink:=do_syscall(syscall_nr_readlink, longint(name),longint(linkname),maxlen);
278
 
end;
279
 
 
280
 
 
281
 
 
282
 
{*****************************************************************************
283
 
               --- Directory:Directory related calls ---
284
 
*****************************************************************************}
285
 
 
286
 
Function Sys_Chdir(Filename:pchar):longint;
287
 
 
288
 
begin
289
 
 sys_chdir:=do_syscall(syscall_nr_chdir,longint(filename));
290
 
end;
291
 
 
292
 
Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
293
 
 
294
 
begin {Mode is 16-bit on F-BSD}
295
 
  sys_mkdir:=do_syscall(syscall_nr_mkdir,longint(filename),mode );
296
 
end;
297
 
 
298
 
Function Sys_Rmdir(Filename:pchar):longint;
299
 
 
300
 
begin
301
 
 sys_rmdir:=do_syscall(syscall_nr_rmdir,longint(filename));
302
 
end;
303
 
 
304
 
 
305
 
const DIRBLKSIZ=1024;
306
 
 
307
 
 
308
 
{ we need this for getcwd, NOT touched for BSD version }
309
 
Function OpenDir(f:pchar):pdir;
310
 
 
311
 
var
312
 
  fd:longint;
313
 
  st:stat;
314
 
  ptr:pdir;
315
 
begin
316
 
  opendir:=nil;
317
 
  if sys_stat(f,st)<0 then
318
 
   exit;
319
 
{ Is it a dir ? }
320
 
  if not((st.mode and $f000)=$4000)then
321
 
   begin
322
 
     errno:=sys_enotdir;
323
 
     exit
324
 
   end;
325
 
{ Open it}
326
 
  fd:=sys_open(f,OPEN_RDONLY,438);
327
 
  if fd<0 then
328
 
   exit;
329
 
  new(ptr);
330
 
  if ptr=nil then
331
 
   exit;
332
 
  Getmem(ptr^.buf,2*DIRBLKSIZ);
333
 
  if ptr^.buf=nil then
334
 
   exit;
335
 
  ptr^.fd:=fd;
336
 
  ptr^.loc:=-1;
337
 
  ptr^.rewind:=longint(ptr^.buf);
338
 
  ptr^.size:=0;
339
 
//  ptr^.dd_max:=sizeof(ptr^.buf^);
340
 
  opendir:=ptr;
341
 
end;
342
 
 
343
 
function CloseDir(p:pdir):integer;
344
 
begin
345
 
  closedir:=sys_close(p^.fd);
346
 
  Freemem(p^.buf);
347
 
  dispose(p);
348
 
end;
349
 
 
350
 
 
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?}
357
 
 
358
 
function readbuffer:longint;
359
 
 
360
 
var retval :longint;
361
 
 
362
 
begin
363
 
   retval:=do_syscall(syscall_nr_getdents,longint(p^.fd),longint(@p^.buf^),DIRBLKSIZ {sizeof(getdentsbuffer)});
364
 
   p^.rewind:=longint(p^.buf);
365
 
   if retval=0 then
366
 
    begin
367
 
     p^.rewind:=0;
368
 
     p^.loc:=0;
369
 
    end
370
 
   else
371
 
    P^.loc:=retval;
372
 
 readbuffer:=retval;
373
 
end;
374
 
 
375
 
var
376
 
    l              : pdirent;
377
 
    novalid        : boolean;
378
 
 
379
 
begin
380
 
 if (p^.buf=nil) or (p^.loc=0) THEN
381
 
  exit(nil);
382
 
 if p^.loc=-1 then         {First readdir on this pdir. Initial fill of buffer}
383
 
  begin
384
 
   if readbuffer()=0 Then    {nothing to be read}
385
 
    exit(nil)
386
 
  end;
387
 
 l:=nil;
388
 
 repeat
389
 
  novalid:=false;
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
396
 
     novalid:=true;
397
 
   end
398
 
  else
399
 
   novalid:=true;
400
 
  if novalid then
401
 
   begin {block entirely searched or reclen=0}
402
 
    if p^.loc<>0 THEN             {blocks left?}
403
 
     if readbuffer()<>0 then        {succesful read?}
404
 
      novalid:=false;
405
 
   end;
406
 
 until (l<>nil) or novalid;
407
 
 Sys_ReadDir:=l;
408
 
end;
409
 
 
410
 
 
411
 
{*****************************************************************************
412
 
        --- Process:Process & program handling - related calls ---
413
 
*****************************************************************************}
414
 
 
415
 
 
416
 
Function sys_GetPid:LongInt;
417
 
{
418
 
  Get Process ID.
419
 
}
420
 
 
421
 
begin
422
 
 sys_GetPID:=do_syscall(syscall_nr_getpid);
423
 
end;
424
 
 
425
 
Procedure Sys_Exit(ExitCode:longint);
426
 
 
427
 
begin
428
 
  do_syscall(syscall_nr_exit,exitcode);
429
 
end;
430
 
 
431
 
{
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.
436
 
}
437
 
 
438
 
 
439
 
 
440
 
Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
441
 
{
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.
446
 
}
447
 
 
448
 
begin
449
 
  do_syscall(syscall_nr_sigaction,longint(signum),longint(act),longint(oldact));
450
 
 {$ifdef linuxunit}
451
 
  LinuxError:=Errno;
 
27
{
 
28
Function fpmmap(adr:pointer;len:TSize;prot:cint;flags:cint;fdes:cint;off:TOff):cint;  // moved from sysunix.inc, used in sbrk
 
29
begin
 
30
 {$ifdef LITTLE_ENDIAN}
 
31
  fpmmap:=do_syscall(syscall_nr_mmap,Adr,Len,Prot,Flags,fdes,lo(off),0);
 
32
 {$else}
 
33
  fpmmap:=do_syscall(syscall_nr_mmap,TSysParam(Adr),TSysParam(Len),Prot,Flags,fdes,0,lo(off));
452
34
 {$endif}
453
35
end;
454
 
 
 
36
}
455
37
 
456
38
{
457
39
  $Log: syscalls.inc,v $
458
 
  Revision 1.1.2.3  2000/09/19 09:58:49  marco
459
 
   * Mkdir fix
460
 
 
461
 
  Revision 1.1.2.2  2000/09/18 12:14:41  marco
462
 
   * An addw in the do_syscall(integer) caused warnings. Fixed
463
 
 
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
466
 
 
467
 
  Revision 1.1.2.1  2000/09/10 16:12:14  marco
468
 
  Initial signals, sockets and clone
469
 
 
470
 
  Revision 1.1  2000/07/13 06:30:32  michael
471
 
  + Initial import
472
 
 
473
 
  Revision 1.15  2000/04/16 16:08:53  marco
474
 
   * Fixes (mainly opendir/Readdir/closedir)
475
 
 
476
 
  Revision 1.14  2000/04/14 17:04:13  marco
477
 
   * Working!
478
 
 
479
 
  Revision 1.13  2000/04/10 15:46:52  marco
480
 
   * worked all day. probably a lot changed
481
 
 
482
 
  Revision 1.11  2000/04/05 13:58:40  marco
483
 
   * syscall variablenames reintroduced.
484
 
 
485
 
  Revision 1.10  2000/03/16 16:18:12  marco
486
 
   * Last changes before next test. ppc386 -h works with these srcs.
487
 
 
488
 
  Revision 1.9  2000/03/02 15:34:07  marco
489
 
   * added a syscall for 5 longints
490
 
 
491
 
  Revision 1.8  2000/03/01 20:03:57  marco
492
 
   * small fixes for syslinux
493
 
 
494
 
  Revision 1.7  2000/03/01 17:28:40  marco
495
 
   * some changes due to updating linux.pp to new syscall
496
 
 
497
 
  Revision 1.6  2000/02/27 23:45:39  marco
498
 
   * Redone the syscalls
499
 
 
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)
503
 
 
504
 
  Revision 1.4  2000/02/03 17:04:47  marco
505
 
   * additions fixes due to port linux
506
 
 
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
509
 
        emulator
510
 
 
511
 
  Revision 1.2  2000/02/02 16:35:10  marco
512
 
   * Ported more functions. Half done now.
513
 
 
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
 
42
 
 
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.
 
45
 
 
46
  Revision 1.11  2003/06/01 16:35:28  marco
 
47
   * Several small fixes to harmonize the *BSD rtls and Linux.
 
48
 
 
49
  Revision 1.10  2003/01/05 19:02:29  marco
 
50
   * Should now work with baseunx. (gmake all works)
 
51
 
 
52
  Revision 1.9  2002/09/07 16:01:17  peter
 
53
    * old logs removed and tabs fixed
 
54
 
 
55
  Revision 1.8  2002/05/06 07:27:39  marco
 
56
   * Fixed a readdir bug, already fixed in januari in 1.0.x
516
57
 
517
58
}