2
$Id: system.pp,v 1.12 2004/04/22 21:10:56 peter Exp $
3
This file is part of the Free Pascal run time library.
4
Copyright (c) 1999-2000 by the Free Pascal development team.
6
This is a prototype file to show all function that need to be implemented
7
for a new operating system (provided the processor specific
8
function are already implemented !)
10
See the file COPYING.FPC, included in this distribution,
11
for details about the copyright.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
**********************************************************************}
18
{ no stack check in system }
20
{$DEFINE SHORT_LINEBREAK}
26
{ include system-independent routine headers }
33
{ include heap support headers }
37
{Platform specific information}
41
DirectorySeparator = '/';
44
{ FileNameCaseSensitive is defined separately below!!! }
47
FileNameCaseSensitive : boolean = true;
49
sLineBreak : string[1] = LineEnding;
50
DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
56
errno : longint; // MvdV: yuckie
59
StdInputHandle:longint;
60
StdOutputHandle:longint;
61
StdErrorHandle:longint;
67
function sys_unlink (a:cardinal;name:pchar):longint; cdecl; external name 'sys_unlink';
68
function sys_rename (a:cardinal;p1:pchar;b:cardinal;p2:pchar):longint; cdecl; external name 'sys_rename';
69
function sys_create_area (name:pchar; var start:pointer; a,b,c,d:longint):longint; cdecl; external name 'sys_create_area';
70
function sys_resize_area (handle:cardinal; size:longint):longint; cdecl; external name 'sys_resize_area';
71
function sys_mkdir (a:cardinal; name:pchar; mode:cardinal):longint; cdecl; external name 'sys_mkdir';
72
function sys_chdir (a:cardinal; name:pchar):longint; cdecl; external name 'sys_chdir';
73
function sys_rmdir (a:cardinal; name:pchar):longint; cdecl; external name 'sys_rmdir';
78
{*****************************************************************************
79
System Dependent Exit code
80
*****************************************************************************}
81
procedure prthaltproc;external name '_haltproc';
83
procedure system_exit;
90
{*****************************************************************************
92
*****************************************************************************}
93
{ cheking the stack is done system independend in 1.1
94
procedure int_stackcheck(stack_size:longint);[public,alias:'FPC_STACKCHECK'];
96
called when trying to get local stack if the compiler directive $S
97
is set this function must preserve esi !!!! because esi is set by
98
the calling proc for methods it must preserve all registers !!
100
With a 2048 byte safe area used to write to StdIo without crossing
107
{*****************************************************************************
109
*****************************************************************************}
112
function paramcount : longint;
114
paramcount := argc - 1;
117
{ argument number l }
118
function paramstr(l : longint) : string;
120
if (l>=0) and (l+1<=argc) then
121
paramstr:=strpas(argv[l])
126
{ set randseed to a new pseudo random value }
129
{regs.realeax:=$2c00;
130
sysrealintr($21,regs);
131
hl:=regs.realedx and $ffff;
132
randseed:=hl*$10000+ (regs.realecx and $ffff);}
136
{*****************************************************************************
138
*****************************************************************************}
140
var myheapstart:pointer;
142
myheaprealsize:longint;
146
{ first address of heap }
147
function getheapstart:pointer;
149
getheapstart:=myheapstart;
152
{ current length of heap }
153
function getheapsize:longint;
155
getheapsize:=myheapsize;
158
{ function to allocate size bytes more for the program }
159
{ must return the first address of new data space or nil if fail }
160
function Sbrk(size : longint):pointer;
161
var newsize,newrealsize:longint;
163
if (myheapsize+size)<=myheaprealsize then begin
164
Sbrk:=myheapstart+myheapsize;
165
myheapsize:=myheapsize+size;
168
newsize:=myheapsize+size;
169
newrealsize:=(newsize and $FFFFF000)+$1000;
170
if sys_resize_area(heap_handle,newrealsize)=0 then begin
171
Sbrk:=myheapstart+myheapsize;
173
myheaprealsize:=newrealsize;
180
{ include standard heap management }
184
{****************************************************************************
185
Low level File Routines
186
All these functions can set InOutRes on errors
187
****************************************************************************}
191
{ close a file from the handle value }
192
procedure do_close(handle : longint);
194
{ writeln ('CLOSE ',handle);}
195
if handle<=2 then exit;
196
InOutRes:=sys_close(handle);
200
procedure do_erase(p : pchar);
202
if sys_unlink($FF000000,p)<>0 then InOutRes:=1
206
procedure do_rename(p1,p2 : pchar);
208
InOutRes:=sys_rename($FF000000,p1,$FF000000,p2);
211
function do_write(h:longint;addr:pointer;len : longint) : longint;
214
sys_write ('WRITE handle=%d ',h);
215
printf ('addr=%x ',addr);
216
printf ('len=%d',len);
219
do_write:=sys_write (h,addr,len,zero);
220
if (do_write<0) then begin
223
end else InOutRes:=0;
226
function do_read(h:longint;addr:pointer;len : longint) : longint;
229
printf ('READ handle=%d ',h);
230
printf ('addr=%x ',addr);
231
printf ('len=%d',len);
233
do_read:=sys_read (h,addr,len,zero);
234
if (do_read<0) then begin
237
end else InOutRes:=0;
240
function do_filepos(handle : longint) : longint;
242
do_filepos:=sys_lseek(handle,0,1); {1=SEEK_CUR}
243
if (do_filepos<0) then begin
244
InOutRes:=do_filepos;
246
end else InOutRes:=0;
249
procedure do_seek(handle,pos : longint);
251
InOutRes:=sys_lseek(handle,pos,0);
252
if InOutRes>0 then InOutRes:=0;
255
function do_seekend(handle:longint):longint;
257
do_seekend:=sys_lseek (handle,0,2); {2=SEEK_END}
258
if do_seekend<0 then begin
259
InOutRes:=do_seekend;
261
end else InOutRes:=0;
264
function do_filesize(handle : longint) : longint;
267
cur:=sys_lseek (handle,0,1); {1=SEEK_CUR}
273
do_filesize:=sys_lseek (handle,0,2); {2=SEEK_END}
274
if do_filesize<0 then begin
275
InOutRes:=do_filesize;
279
cur:=sys_lseek (handle,cur,0); {0=SEEK_POS}
287
{ truncate at a given position }
288
procedure do_truncate (handle,pos:longint);
293
procedure do_open(var f;p:pchar;flags:longint);
295
filerec and textrec have both handle and mode as the first items so
296
they could use the same routine for opening/creating.
297
when (flags and $100) the file will be append
298
when (flags and $1000) the file will be truncate/rewritten
299
when (flags and $10000) there is no check for close (needed for textfiles)
304
{ printf ('OPEN %d ',longint(f));
305
printf (' %s',longint(p));
306
printf (' %x',flags);}
309
case (flags and $3) of
310
$0: begin m:=m or O_RDONLY; mode:=fminput; end;
311
$1: begin m:=m or O_WRONLY; mode:=fmoutput;end;
312
$2: begin m:=m or O_RDWR; mode:=fminout; end;
315
if (flags and $100)<>0 then m:=m or O_APPEND;
316
if (flags and $1000)<>0 then m:=m or O_TRUNC or O_CREAT;
318
{ if (flags and $10000)<>0 then m:=m or O_TEXT else m:=m or O_BINARY;}
320
h:=sys_open($FF000000,p,m,0,0);
322
if h<0 then InOutRes:=h
325
if InOutRes=0 then begin
326
FileRec(f).handle:=h;
327
FileRec(f).mode:=mode;
331
function do_isdevice(handle:longint):boolean;
338
{*****************************************************************************
339
UnTyped File Handling
340
*****************************************************************************}
344
{*****************************************************************************
346
*****************************************************************************}
350
{*****************************************************************************
352
*****************************************************************************}
354
{ should we consider #26 as the end of a file ? }
355
{?? $DEFINE EOF_CTRLZ}
359
{*****************************************************************************
361
*****************************************************************************}
362
procedure mkdir(const s : string);[IOCheck];
366
InOutRes:=sys_mkdir ($FF000000,@t[1],493);
369
procedure rmdir(const s : string);[IOCheck];
373
InOutRes:=sys_rmdir ($FF000000,@t[1]);
376
procedure chdir(const s : string);[IOCheck];
380
InOutRes:=sys_chdir ($FF000000,@t[1]);
383
{*****************************************************************************
385
*****************************************************************************}
386
type dirent = packed record
392
d_name:array[0..255] of char;
396
dev:longint; {"device" that this file resides on}
397
ino:int64; {this file's inode #, unique per device}
398
mode:dword; {mode bits (rwx for user, group, etc)}
399
nlink:longint; {number of hard links to this file}
400
uid:dword; {user id of the owner of this file}
401
gid:dword; {group id of the owner of this file}
402
size:int64; {size of this file (in bytes)}
403
rdev:longint; {device type (not used)}
404
blksize:longint; {preferref block size for i/o}
405
atime:longint; {last access time}
406
mtime:longint; {last modification time}
407
ctime:longint; {last change time, not creation time}
408
crtime:longint; {creation time}
412
function sys_stat (a:cardinal;path:pchar;info:pstat;n:longint):longint; cdecl; external name 'sys_stat';
414
function FStat(Path:String;Var Info:stat):Boolean;
416
Get all information on a file, and return it in Info.
423
FStat:=(sys_stat($FF000000,p,@Info,0)=0);
427
function sys_opendir (a:cardinal;path:pchar;b:longint):longint; cdecl; external name 'sys_opendir';
428
function sys_readdir (fd:longint;var de:dirent;a:longint;b:byte):longint; cdecl; external name 'sys_readdir';
430
function parentdir(fd:longint;dev:longint;ino:int64;var err:longint):string;
437
if sys_readdir(fd,ent,$11C,1)=0 then begin
442
len:=StrLen(@ent.d_name);
443
Move(ent.d_name,name[1],len);
445
{ writeln ('NAME: "',name,'" = ',ent.d_dev,',',ent.d_ino);}
446
if (dev=ent.d_dev) and (ino=ent.d_ino) then begin
456
function getdir2:string;
472
FStat(cur+'..',info2);
473
{ writeln ('"." = ',info.dev,',',info.ino);}
474
if ((info.dev=info2.dev) and (info.ino=info2.ino)) then begin
475
if res='' then getdir2:='/' else getdir2:=res;
480
fd:=sys_opendir ($FF000000,@tmp[1],0);
482
name:=parentdir(fd,info.dev,info.ino,err);
483
until (err<>0) or (name<>'');
494
procedure getdir(drivenr : byte;var dir : shortstring);
501
{*****************************************************************************
502
SystemUnit Initialization
503
*****************************************************************************}
505
procedure SysInitStdIO;
507
{ Setup stdin, stdout and stderr, for GUI apps redirect stderr,stdout to be
508
displayed in and messagebox }
512
OpenStdIO(Input,fmInput,StdInputHandle);
513
OpenStdIO(Output,fmOutput,StdOutputHandle);
514
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
515
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
522
myheaprealsize:=$2000;
524
heap_handle:=sys_create_area('fpcheap',myheapstart,0,myheaprealsize,0,3);//!!
525
if heap_handle>0 then begin
527
end else system_exit;
535
(* This should be changed to a real value during *)
536
(* thread driver initialization if appropriate. *)
544
Revision 1.12 2004/04/22 21:10:56 peter
545
* do_read/do_write addr argument changed to pointer
547
Revision 1.11 2004/01/20 23:09:14 hajny
548
* ExecuteProcess fixes, ProcessID and ThreadID added
550
Revision 1.10 2003/10/25 23:42:35 hajny
551
* THandle in sysutils common using System.THandle
553
Revision 1.9 2003/09/27 11:52:35 peter
554
* sbrk returns pointer
556
Revision 1.8 2003/01/08 22:32:28 marco
557
* Small fixes and quick merge with 1.0.x. At least the compiler builds now,
558
but it could crash hard, since there are lots of unimplemented funcs.
560
Revision 1.7 2003/01/05 20:22:24 florian
561
- removed stack check, it's system independend in 1.1
563
Revision 1.6 2003/01/05 20:06:30 florian
564
+ fixed missing SysInitStdIO
566
Revision 1.5 2002/10/13 09:25:31 florian
567
+ call to initvariantmanager inserted
569
Revision 1.4 2002/09/07 16:01:17 peter
570
* old logs removed and tabs fixed
b'\\ No newline at end of file'