sysos2.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. {****************************************************************************
  2. Free Pascal -- OS/2 runtime library
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. Copyright (c) 1999-2000 by Daniel Mantione
  5. Free Pascal is distributed under the GNU Public License v2. So is this unit.
  6. The GNU Public License requires you to distribute the source code of this
  7. unit with any product that uses it. We grant you an exception to this, and
  8. that is, when you compile a program with the Free Pascal Compiler, you do not
  9. need to ship source code with that program, AS LONG AS YOU ARE USING
  10. UNMODIFIED CODE! If you modify this code, you MUST change the next line:
  11. <This an official, unmodified Free Pascal source code file.>
  12. Send us your modified files, we can work together if you want!
  13. Free Pascal 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. See the
  16. Library GNU General Public License for more details.
  17. You should have received a copy of the Library GNU General Public License
  18. along with Free Pascal; see the file COPYING.LIB. If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.
  21. ****************************************************************************}
  22. unit sysos2;
  23. {Changelog:
  24. People:
  25. DM - Daniel Mantione
  26. Date: Description of change: Changed by:
  27. - First released version 0.1. DM
  28. Coding style:
  29. My coding style is a bit unusual for Pascal. Nevertheless I friendly ask
  30. you to try to make your changes not look all to different. In general,
  31. set your IDE to use tab characters, optimal fill on and a tabsize of 4.}
  32. interface
  33. {Link the startup code.}
  34. {$l prt1.oo2}
  35. {$I SYSTEMH.INC}
  36. {$I heaph.inc}
  37. type Tos=(osDOS,osOS2,osDPMI);
  38. var os_mode:Tos;
  39. first_meg:pointer;
  40. type Psysthreadib=^Tsysthreadib;
  41. Pthreadinfoblock=^Tthreadinfoblock;
  42. Pprocessinfoblock=^Tprocessinfoblock;
  43. Tbytearray=array[0..$ffff] of byte;
  44. Pbytearray=^Tbytearray;
  45. Tsysthreadib=record
  46. tid,
  47. priority,
  48. version:longint;
  49. MCcount,
  50. MCforceflag:word;
  51. end;
  52. Tthreadinfoblock=record
  53. pexchain,
  54. stack,
  55. stacklimit:pointer;
  56. tib2:Psysthreadib;
  57. version,
  58. ordinal:longint;
  59. end;
  60. Tprocessinfoblock=record
  61. pid,
  62. parentpid,
  63. hmte:longint;
  64. cmd,
  65. env:Pbytearray;
  66. flstatus,
  67. ttype:longint;
  68. end;
  69. const UnusedHandle=$ffff;
  70. StdInputHandle=0;
  71. StdOutputHandle=1;
  72. StdErrorHandle=2;
  73. FileNameCaseSensitive : boolean = false;
  74. var
  75. { C-compatible arguments and environment }
  76. argc : longint;external name '_argc';
  77. argv : ppchar;external name '_argv';
  78. envp : ppchar;external name '_environ';
  79. implementation
  80. {$I SYSTEM.INC}
  81. procedure DosGetInfoBlocks (var Atib: PThreadInfoBlock;
  82. var Apib: PProcessInfoBlock); cdecl;
  83. external 'DOSCALLS' index 312;
  84. function DosSetRelMaxFH (var ReqCount, CurMaxFH: longint): longint; cdecl;
  85. external 'DOSCALLS' index 382;
  86. {This is the correct way to call external assembler procedures.}
  87. procedure syscall; external name '___SYSCALL';
  88. {***************************************************************************
  89. Runtime error checking related routines.
  90. ***************************************************************************}
  91. {$S-}
  92. procedure st1(stack_size:longint);[public,alias: 'STACKCHECK'];
  93. begin
  94. { called when trying to get local stack }
  95. { if the compiler directive $S is set }
  96. {$ASMMODE DIRECT}
  97. asm
  98. movl stack_size,%ebx
  99. movl %esp,%eax
  100. subl %ebx,%eax
  101. {$ifdef SYSTEMDEBUG}
  102. movl U_SYSOS2_LOWESTSTACK,%ebx
  103. cmpl %eax,%ebx
  104. jb Lis_not_lowest
  105. movl %eax,U_SYSOS2_LOWESTSTACK
  106. Lis_not_lowest:
  107. {$endif SYSTEMDEBUG}
  108. cmpb $2,U_SYSOS2_OS_MODE
  109. jne Lrunning_in_dos
  110. movl U_SYSOS2_STACKBOTTOM,%ebx
  111. jmp Lrunning_in_os2
  112. Lrunning_in_dos:
  113. movl __heap_brk,%ebx
  114. Lrunning_in_os2:
  115. cmpl %eax,%ebx
  116. jae Lshort_on_stack
  117. leave
  118. ret $4
  119. Lshort_on_stack:
  120. end ['EAX','EBX'];
  121. {$ASMMODE ATT}
  122. { this needs a local variable }
  123. { so the function called itself !! }
  124. { Writeln('low in stack ');}
  125. HandleError(202);
  126. end;
  127. {no stack check in system }
  128. {****************************************************************************
  129. Miscellaneous related routines.
  130. ****************************************************************************}
  131. procedure system_exit; assembler;
  132. asm
  133. movb $0x4c,%ah
  134. movb exitcode,%al
  135. call syscall
  136. end;
  137. {$asmmode direct}
  138. function paramcount:longint;assembler;
  139. asm
  140. movl _argc,%eax
  141. decl %eax
  142. end ['EAX'];
  143. function paramstr(l:longint):string;
  144. function args:pointer;assembler;
  145. asm
  146. movl _argv,%eax
  147. end ['EAX'];
  148. var p:^Pchar;
  149. begin
  150. if (l>=0) and (l<=paramcount) then
  151. begin
  152. p:=args;
  153. paramstr:=strpas(p[l]);
  154. end
  155. else paramstr:='';
  156. end;
  157. {$asmmode att}
  158. procedure randomize;
  159. var hl:longint;
  160. begin
  161. asm
  162. movb $0x2c,%ah
  163. call syscall
  164. movw %cx,-4(%ebp)
  165. movw %dx,-2(%ebp)
  166. end;
  167. randseed:=hl;
  168. end;
  169. {****************************************************************************
  170. Heap management releated routines.
  171. ****************************************************************************}
  172. { this function allows to extend the heap by calling
  173. syscall $7f00 resizes the brk area}
  174. function sbrk(size:longint):longint; assembler;
  175. asm
  176. movl size,%edx
  177. movw $0x7f00,%ax
  178. call syscall
  179. end;
  180. {$ASMMODE direct}
  181. function getheapstart:pointer;assembler;
  182. asm
  183. movl __heap_base,%eax
  184. end ['EAX'];
  185. function getheapsize:longint;assembler;
  186. asm
  187. movl HEAPSIZE,%eax
  188. end ['EAX'];
  189. {$ASMMODE ATT}
  190. {$i heap.inc}
  191. {****************************************************************************
  192. Low Level File Routines
  193. ****************************************************************************}
  194. procedure allowslash(p:Pchar);
  195. {Allow slash as backslash.}
  196. var i:longint;
  197. begin
  198. for i:=0 to strlen(p) do
  199. if p[i]='/' then p[i]:='\';
  200. end;
  201. procedure do_close(h:longint);
  202. begin
  203. { Only three standard handles under real OS/2 }
  204. if (h > 4) or
  205. (os_MODE = osOS2) and (h > 2) then
  206. begin
  207. asm
  208. movb $0x3e,%ah
  209. mov h,%ebx
  210. call syscall
  211. end;
  212. end;
  213. end;
  214. procedure do_erase(p:Pchar);
  215. begin
  216. allowslash(p);
  217. asm
  218. movl P,%edx
  219. movb $0x41,%ah
  220. call syscall
  221. jnc .LERASE1
  222. movw %ax,inoutres;
  223. .LERASE1:
  224. end;
  225. end;
  226. procedure do_rename(p1,p2:Pchar);
  227. begin
  228. allowslash(p1);
  229. allowslash(p2);
  230. asm
  231. movl P1, %edx
  232. movl P2, %edi
  233. movb $0x56,%ah
  234. call syscall
  235. jnc .LRENAME1
  236. movw %ax,inoutres;
  237. .LRENAME1:
  238. end;
  239. end;
  240. function do_read(h,addr,len:longint):longint; assembler;
  241. asm
  242. movl len,%ecx
  243. movl addr,%edx
  244. movl h,%ebx
  245. movb $0x3f,%ah
  246. call syscall
  247. jnc .LDOSREAD1
  248. movw %ax,inoutres;
  249. xorl %eax,%eax
  250. .LDOSREAD1:
  251. end;
  252. function do_write(h,addr,len:longint) : longint; assembler;
  253. asm
  254. movl len,%ecx
  255. movl addr,%edx
  256. movl h,%ebx
  257. movb $0x40,%ah
  258. call syscall
  259. jnc .LDOSWRITE1
  260. movw %ax,inoutres;
  261. .LDOSWRITE1:
  262. end;
  263. function do_filepos(handle:longint): longint; assembler;
  264. asm
  265. movw $0x4201,%ax
  266. movl handle,%ebx
  267. xorl %edx,%edx
  268. call syscall
  269. jnc .LDOSFILEPOS
  270. movw %ax,inoutres;
  271. xorl %eax,%eax
  272. .LDOSFILEPOS:
  273. end;
  274. procedure do_seek(handle,pos:longint); assembler;
  275. asm
  276. movw $0x4200,%ax
  277. movl handle,%ebx
  278. movl pos,%edx
  279. call syscall
  280. jnc .LDOSSEEK1
  281. movw %ax,inoutres;
  282. .LDOSSEEK1:
  283. end;
  284. function do_seekend(handle:longint):longint; assembler;
  285. asm
  286. movw $0x4202,%ax
  287. movl handle,%ebx
  288. xorl %edx,%edx
  289. call syscall
  290. jnc .Lset_at_end1
  291. movw %ax,inoutres;
  292. xorl %eax,%eax
  293. .Lset_at_end1:
  294. end;
  295. function do_filesize(handle:longint):longint;
  296. var aktfilepos:longint;
  297. begin
  298. aktfilepos:=do_filepos(handle);
  299. do_filesize:=do_seekend(handle);
  300. do_seek(handle,aktfilepos);
  301. end;
  302. procedure do_truncate(handle,pos:longint); assembler;
  303. asm
  304. (* DOS function 40h isn't safe for this according to EMX documentation
  305. movl $0x4200,%eax
  306. movl 8(%ebp),%ebx
  307. movl 12(%ebp),%edx
  308. call syscall
  309. jc .LTruncate1
  310. movl 8(%ebp),%ebx
  311. movl 12(%ebp),%edx
  312. movl %ebp,%edx
  313. xorl %ecx,%ecx
  314. movb $0x40,%ah
  315. call syscall
  316. *)
  317. movl $0x7F25,%eax
  318. movl Handle,%ebx
  319. movl Pos,%edx
  320. call syscall
  321. inc %eax
  322. movl %ecx, %eax
  323. jnz .LTruncate1
  324. (* File position is undefined after truncation, move to the end. *)
  325. movl $0x4202,%eax
  326. movl Handle,%ebx
  327. movl $0,%edx
  328. call syscall
  329. jnc .LTruncate2
  330. .LTruncate1:
  331. movw %ax,inoutres;
  332. .LTruncate2:
  333. end;
  334. const
  335. FileHandleCount: longint = 20;
  336. function Increase_File_Handle_Count: boolean;
  337. var Err: word;
  338. L1, L2: longint;
  339. begin
  340. if os_mode = osOS2 then
  341. begin
  342. L1 := 10;
  343. if DosSetRelMaxFH (L1, L2) <> 0 then
  344. Increase_File_Handle_Count := false
  345. else
  346. if L2 > FileHandleCount then
  347. begin
  348. FileHandleCount := L2;
  349. Increase_File_Handle_Count := true;
  350. end
  351. else
  352. Increase_File_Handle_Count := false;
  353. end
  354. else
  355. begin
  356. Inc (FileHandleCount, 10);
  357. Err := 0;
  358. asm
  359. movl $0x6700, %eax
  360. movl FileHandleCount, %ebx
  361. call syscall
  362. jnc .LIncFHandles
  363. movw %ax, Err
  364. .LIncFHandles:
  365. end;
  366. if Err <> 0 then
  367. begin
  368. Increase_File_Handle_Count := false;
  369. Dec (FileHandleCount, 10);
  370. end
  371. else
  372. Increase_File_Handle_Count := true;
  373. end;
  374. end;
  375. procedure do_open(var f;p:pchar;flags:longint);
  376. {
  377. filerec and textrec have both handle and mode as the first items so
  378. they could use the same routine for opening/creating.
  379. when (flags and $100) the file will be append
  380. when (flags and $1000) the file will be truncate/rewritten
  381. when (flags and $10000) there is no check for close (needed for textfiles)
  382. }
  383. (* var oflags:byte;
  384. *)
  385. var Action: longint;
  386. begin
  387. allowslash(p);
  388. { close first if opened }
  389. if ((flags and $10000)=0) then
  390. begin
  391. case filerec(f).mode of
  392. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  393. fmclosed:;
  394. else
  395. begin
  396. inoutres:=102; {not assigned}
  397. exit;
  398. end;
  399. end;
  400. end;
  401. { reset file handle }
  402. filerec(f).handle := UnusedHandle;
  403. Action := 0;
  404. (* oflags:=2;
  405. *)
  406. { convert filemode to filerec modes }
  407. case (flags and 3) of
  408. 0 : filerec(f).mode:=fminput;
  409. 1 : filerec(f).mode:=fmoutput;
  410. 2 : filerec(f).mode:=fminout;
  411. end;
  412. if (flags and $1000)<>0 then
  413. Action := $50000; (* Create / replace *)
  414. (* begin
  415. filerec(f).mode:=fmoutput;
  416. oflags:=2;
  417. end
  418. else
  419. if (flags and $100)<>0 then
  420. begin
  421. filerec(f).mode:=fmoutput;
  422. oflags:=2;
  423. end;
  424. *)
  425. { empty name is special }
  426. if p[0]=#0 then
  427. begin
  428. case FileRec(f).mode of
  429. fminput :
  430. FileRec(f).Handle:=StdInputHandle;
  431. fminout, { this is set by rewrite }
  432. fmoutput :
  433. FileRec(f).Handle:=StdOutputHandle;
  434. fmappend :
  435. begin
  436. FileRec(f).Handle:=StdOutputHandle;
  437. FileRec(f).mode:=fmoutput; {fool fmappend}
  438. end;
  439. end;
  440. exit;
  441. end;
  442. Action := Action or (Flags and $FF);
  443. (* DenyNone if sharing not specified. *)
  444. if Flags and 112 = 0 then
  445. (* begin
  446. if Flags and 3 = 0 then*)
  447. Action := Action or 64;
  448. (* else
  449. Action := Action or 32;
  450. end;*)
  451. asm
  452. movl $0x7f2b, %eax
  453. movl Action, %ecx
  454. movl p, %edx
  455. call syscall
  456. cmpl $0xffffffff, %eax
  457. jnz .LOPEN1
  458. movw %cx, InOutRes
  459. movw UnusedHandle, %ax
  460. .LOPEN1:
  461. movl f,%edx
  462. movw %ax,(%edx)
  463. end;
  464. if (InOutRes = 4) and Increase_File_Handle_Count then
  465. (* Trying again after increasing amount of file handles *)
  466. asm
  467. movl $0x7f2b, %eax
  468. movl Action, %ecx
  469. movl p, %edx
  470. call syscall
  471. jnc .LOPEN2
  472. movw %ax, InOutRes;
  473. movw UnusedHandle, %ax
  474. .LOPEN2:
  475. movl f,%edx
  476. movw %ax,(%edx)
  477. end;
  478. (*
  479. if (flags and $1000)<>0 then
  480. {Use create function.}
  481. asm
  482. movb $0x3c,%ah
  483. movl p,%edx
  484. xorw %cx,%cx
  485. call syscall
  486. jnc .LOPEN1
  487. movw %ax,inoutres;
  488. movw $0xffff,%ax
  489. .LOPEN1:
  490. movl f,%edx
  491. movw %ax,(%edx)
  492. end
  493. else
  494. {Use open function.}
  495. asm
  496. movb $0x3d,%ah
  497. movb oflags,%al
  498. movl p,%edx
  499. call syscall
  500. jnc .LOPEN2
  501. movw %ax,inoutres;
  502. movw $0xffff,%ax
  503. .LOPEN2:
  504. movl f,%edx
  505. movw %ax,(%edx)
  506. end;
  507. *)
  508. { for systems that have more handles }
  509. if FileRec (F).Handle > FileHandleCount then
  510. FileHandleCount := FileRec (F).Handle;
  511. if (flags and $100)<>0 then
  512. begin
  513. do_seekend(filerec(f).handle);
  514. FileRec (F).Mode := fmOutput; {fool fmappend}
  515. end;
  516. end;
  517. {$ASMMODE INTEL}
  518. function do_isdevice (Handle: longint): boolean; assembler;
  519. (*
  520. var HT, Attr: longint;
  521. begin
  522. if os_mode = osOS2 then
  523. begin
  524. if DosQueryHType (Handle, HT, Attr) <> 0 then HT := 1;
  525. end
  526. else
  527. *)
  528. asm
  529. mov ebx, Handle
  530. mov eax, 4400h
  531. call syscall
  532. mov eax, 1
  533. jc @IsDevEnd
  534. test edx, 80h
  535. jnz @IsDevEnd
  536. dec eax
  537. @IsDevEnd:
  538. end;
  539. (* do_isdevice := (Handle <= 5);*)
  540. {$ASMMODE ATT}
  541. {*****************************************************************************
  542. UnTyped File Handling
  543. *****************************************************************************}
  544. {$i file.inc}
  545. {*****************************************************************************
  546. Typed File Handling
  547. *****************************************************************************}
  548. {$i typefile.inc}
  549. {*****************************************************************************
  550. Text File Handling
  551. *****************************************************************************}
  552. {$DEFINE EOF_CTRLZ}
  553. {$i text.inc}
  554. {****************************************************************************
  555. Directory related routines.
  556. ****************************************************************************}
  557. {*****************************************************************************
  558. Directory Handling
  559. *****************************************************************************}
  560. procedure dosdir(func:byte;const s:string);
  561. var buffer:array[0..255] of char;
  562. begin
  563. move(s[1],buffer,length(s));
  564. buffer[length(s)]:=#0;
  565. allowslash(Pchar(@buffer));
  566. asm
  567. leal buffer,%edx
  568. movb func,%ah
  569. call syscall
  570. jnc .LDOS_DIRS1
  571. movw %ax,inoutres;
  572. .LDOS_DIRS1:
  573. end;
  574. end;
  575. procedure mkdir(const s : string);
  576. begin
  577. DosDir($39,s);
  578. end;
  579. procedure rmdir(const s : string);
  580. begin
  581. DosDir($3a,s);
  582. end;
  583. procedure chdir(const s : string);
  584. begin
  585. DosDir($3b,s);
  586. end;
  587. procedure getdir(drivenr : byte;var dir : shortstring);
  588. {Written by Michael Van Canneyt.}
  589. var temp:array[0..255] of char;
  590. sof:Pchar;
  591. i:byte;
  592. begin
  593. sof:=pchar(@dir[4]);
  594. { dir[1..3] will contain '[drivenr]:\', but is not }
  595. { supplied by DOS, so we let dos string start at }
  596. { dir[4] }
  597. { Get dir from drivenr : 0=default, 1=A etc... }
  598. asm
  599. movb drivenr,%dl
  600. movl sof,%esi
  601. mov $0x47,%ah
  602. call syscall
  603. end;
  604. { Now Dir should be filled with directory in ASCIIZ, }
  605. { starting from dir[4] }
  606. dir[0]:=#3;
  607. dir[2]:=':';
  608. dir[3]:='\';
  609. i:=4;
  610. {Conversion to Pascal string }
  611. while (dir[i]<>#0) do
  612. begin
  613. { convert path name to DOS }
  614. if dir[i]='/' then
  615. dir[i]:='\';
  616. dir[0]:=char(i);
  617. inc(i);
  618. end;
  619. { upcase the string (FPC function) }
  620. if not (FileNameCaseSensitive) then dir:=upcase(dir);
  621. if drivenr<>0 then { Drive was supplied. We know it }
  622. dir[1]:=char(65+drivenr-1)
  623. else
  624. begin
  625. { We need to get the current drive from DOS function 19H }
  626. { because the drive was the default, which can be unknown }
  627. asm
  628. movb $0x19,%ah
  629. call syscall
  630. addb $65,%al
  631. movb %al,i
  632. end;
  633. dir[1]:=char(i);
  634. end;
  635. end;
  636. {****************************************************************************
  637. System unit initialization.
  638. ****************************************************************************}
  639. function GetFileHandleCount: longint;
  640. var L1, L2: longint;
  641. begin
  642. L1 := 0; (* Don't change the amount, just check. *)
  643. if DosSetRelMaxFH (L1, L2) <> 0 then GetFileHandleCount := 50
  644. else GetFileHandleCount := L2;
  645. end;
  646. var pib:Pprocessinfoblock;
  647. tib:Pthreadinfoblock;
  648. begin
  649. {Determine the operating system we are running on.}
  650. asm
  651. movl $0,os_mode
  652. movw $0x7f0a,%ax
  653. call syscall
  654. testw $512,%bx {Bit 9 is OS/2 flag.}
  655. setnzb os_mode
  656. testw $4096,%bx
  657. jz .LnoRSX
  658. movl $2,os_mode
  659. .LnoRSX:
  660. end;
  661. {$ASMMODE DIRECT}
  662. {Enable the brk area by initializing it with the initial heap size.}
  663. asm
  664. movw $0x7f01,%ax
  665. movl HEAPSIZE,%edx
  666. addl __heap_base,%edx
  667. call ___SYSCALL
  668. cmpl $-1,%eax
  669. jnz Lheapok
  670. pushl $204
  671. {call RUNERROR$$WORD}
  672. Lheapok:
  673. end;
  674. {$ASMMODE ATT}
  675. {Now request, if we are running under DOS,
  676. read-access to the first meg. of memory.}
  677. if os_mode in [osDOS,osDPMI] then
  678. asm
  679. movw $0x7f13,%ax
  680. xorl %ebx,%ebx
  681. movl $0xfff,%ecx
  682. xorl %edx,%edx
  683. call syscall
  684. movl %eax,first_meg
  685. end
  686. else
  687. begin
  688. first_meg := nil;
  689. (* Initialize the amount of file handles *)
  690. FileHandleCount := GetFileHandleCount;
  691. end;
  692. {At 0.9.2, case for enumeration does not work.}
  693. case os_mode of
  694. osDOS:
  695. stackbottom:=0; {In DOS mode, heap_brk is also the
  696. stack bottom.}
  697. osOS2:
  698. begin
  699. dosgetinfoblocks(tib,pib);
  700. stackbottom:=longint(tib^.stack);
  701. end;
  702. osDPMI:
  703. stackbottom:=0; {Not sure how to get it, but seems to be
  704. always zero.}
  705. end;
  706. exitproc:=nil;
  707. {Initialize the heap.}
  708. initheap;
  709. { ... and exceptions }
  710. InitExceptions;
  711. { to test stack depth }
  712. loweststack:=maxlongint;
  713. OpenStdIO(Input,fmInput,StdInputHandle);
  714. OpenStdIO(Output,fmOutput,StdOutputHandle);
  715. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  716. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  717. { no I/O-Error }
  718. inoutres:=0;
  719. end.
  720. {
  721. $Log$
  722. Revision 1.32 2000-06-11 09:47:57 hajny
  723. * error handling and sharing corrected
  724. Revision 1.31 2000/06/05 18:53:30 hajny
  725. * FileHandleCount handling for OS/2 added
  726. Revision 1.30 2000/06/04 14:14:01 hajny
  727. * do_truncate corrected, do_open might work under W9x now
  728. Revision 1.29 2000/05/28 18:17:39 hajny
  729. do_isdevice corrected
  730. Revision 1.28 2000/05/21 15:58:50 hajny
  731. + FileNameCaseSensitive added
  732. Revision 1.27 2000/04/07 17:47:34 hajny
  733. * got rid of os.inc
  734. Revision 1.26 2000/02/09 16:59:34 peter
  735. * truncated log
  736. Revision 1.25 2000/02/09 12:39:11 peter
  737. * halt moved to system.inc
  738. Revision 1.24 2000/01/20 23:38:02 peter
  739. * support fm_inout as stdoutput for assign(f,'');rewrite(f,1); becuase
  740. rewrite opens always with filemode 2
  741. Revision 1.23 2000/01/16 23:10:15 peter
  742. * handle check fixed
  743. Revision 1.22 2000/01/16 22:25:38 peter
  744. * check handle for file closing
  745. Revision 1.21 2000/01/09 20:45:58 hajny
  746. * FPK changed to FPC
  747. Revision 1.20 2000/01/07 16:41:50 daniel
  748. * copyright 2000
  749. Revision 1.19 2000/01/07 16:32:33 daniel
  750. * copyright 2000 added
  751. Revision 1.18 2000/01/02 17:45:25 hajny
  752. * cdecl added for doscalls routines
  753. Revision 1.17 1999/09/10 15:40:35 peter
  754. * fixed do_open flags to be > $100, becuase filemode can be upto 255
  755. }