system.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team.
  4. Watcom
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit System;
  12. INTERFACE
  13. {$define FPC_IS_SYSTEM}
  14. {$ifndef NO_EXCEPTIONS_IN_SYSTEM}
  15. {$define EXCEPTIONS_IN_SYSTEM}
  16. {$endif NO_EXCEPTIONS_IN_SYSTEM}
  17. {$define FPC_ANSI_TEXTFILEREC}
  18. { include system-independent routine headers }
  19. { wasm does not support SSE instructions }
  20. {$define FASTMOVE_DISABLE_SSE}
  21. {$include systemh.inc}
  22. const
  23. LineEnding = #13#10;
  24. { LFNSupport is a variable here, defined below!!! }
  25. DirectorySeparator = '\';
  26. DriveSeparator = ':';
  27. ExtensionSeparator = '.';
  28. PathSeparator = ';';
  29. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  30. AllowDriveSeparators : set of AnsiChar = [':'];
  31. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  32. maxExitCode = 255;
  33. MaxPathLen = 256;
  34. const
  35. { Default filehandles }
  36. UnusedHandle = -1;
  37. StdInputHandle = 0;
  38. StdOutputHandle = 1;
  39. StdErrorHandle = 2;
  40. FileNameCaseSensitive : boolean = false;
  41. FileNameCasePreserving: boolean = false;
  42. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  43. sLineBreak = LineEnding;
  44. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  45. { Default memory segments (Tp7 compatibility) }
  46. seg0040 = $0040;
  47. segA000 = $A000;
  48. segB000 = $B000;
  49. segB800 = $B800;
  50. var
  51. { Mem[] support }
  52. mem : array[0..$7fffffff-1] of byte absolute $0:$0;
  53. memw : array[0..($7fffffff div sizeof(word)) -1] of word absolute $0:$0;
  54. meml : array[0..($7fffffff div sizeof(longint)) -1] of longint absolute $0:$0;
  55. { C-compatible arguments and environment }
  56. argc : longint;
  57. argv : PPAnsiChar;
  58. envp : PPAnsiChar;
  59. dos_argv0 : PAnsiChar;
  60. AllFilesMask: string [3];
  61. {$ifndef RTLLITE}
  62. { System info }
  63. LFNSupport : boolean;
  64. {$ELSE RTLLITE}
  65. Const
  66. LFNSupport = false;
  67. {$endif RTLLITE}
  68. {
  69. necessary for objects.pas, should be removed (at least from the interface
  70. to the implementation)
  71. }
  72. type
  73. trealregs=record
  74. realedi,realesi,realebp,realres,
  75. realebx,realedx,realecx,realeax : longint;
  76. realflags,
  77. reales,realds,realfs,realgs,
  78. realip,realcs,realsp,realss : word;
  79. end;
  80. function do_write(h:longint;addr:pointer;len : longint) : longint;
  81. function do_read(h:longint;addr:pointer;len : longint) : longint;
  82. procedure syscopyfromdos(addr : sizeuint; len : longint);
  83. procedure syscopytodos(addr : sizeuint; len : longint);
  84. procedure sysrealintr(intnr : word;var regs : trealregs);
  85. var tb:longint;
  86. tb_segment:word;
  87. const tb_offset=0;
  88. tb_size=8192;
  89. IMPLEMENTATION
  90. { include system independent routines }
  91. {$include system.inc}
  92. {$asmmode ATT}
  93. var psp_selector:word; external name 'PSP_SELECTOR';
  94. procedure setup_arguments;
  95. type
  96. arrayword = array [0..255] of word;
  97. var
  98. proxy_s : string[50];
  99. proxy_argc,proxy_seg,proxy_ofs,lin : longint;
  100. rm_argv : ^arrayword;
  101. argv0len : longint;
  102. useproxy : boolean;
  103. hp : PPAnsiChar;
  104. doscmd : string[129]; { Dos commandline copied from PSP, max is 128 chars +1 for terminating zero }
  105. arglen,
  106. count : longint;
  107. argstart,
  108. pc,arg : PAnsiChar;
  109. quote : AnsiChar;
  110. argvlen : longint;
  111. function atohex(s : PAnsiChar) : longint;
  112. var
  113. rv : longint;
  114. v : byte;
  115. begin
  116. rv:=0;
  117. while (s^<>#0) do
  118. begin
  119. v:=byte(s^)-byte('0');
  120. if (v > 9) then
  121. dec(v,7);
  122. v:=v and 15; { in case it's lower case }
  123. rv:=(rv shl 4) or v;
  124. inc(longint(s));
  125. end;
  126. atohex:=rv;
  127. end;
  128. procedure allocarg(idx,len:longint);
  129. var oldargvlen:longint;
  130. begin
  131. if idx>=argvlen then
  132. begin
  133. oldargvlen:=argvlen;
  134. argvlen:=(idx+8) and (not 7);
  135. sysreallocmem(argv,argvlen*sizeof(pointer));
  136. fillchar(argv[oldargvlen],(argvlen-oldargvlen)*sizeof(pointer),0);
  137. argv[idx]:=nil;
  138. end;
  139. ArgV [Idx] := SysAllocMem (Succ (Len));
  140. end;
  141. begin
  142. count:=0;
  143. argc:=1;
  144. argv:=nil;
  145. argvlen:=0;
  146. { load commandline from psp }
  147. sysseg_move(psp_selector, 128, get_ds, longint(@doscmd), 128);
  148. doscmd[length(doscmd)+1]:=#0;
  149. {$IfDef SYSTEM_DEBUG_STARTUP}
  150. Writeln(stderr,'Dos command line is #',doscmd,'# size = ',length(doscmd));
  151. {$EndIf }
  152. { create argv[0] }
  153. argv0len:=strlen(dos_argv0);
  154. allocarg(count,argv0len);
  155. move(dos_argv0^,argv[count]^,argv0len);
  156. inc(count);
  157. { setup cmdline variable }
  158. cmdline:=Getmem(argv0len+length(doscmd)+2);
  159. move(dos_argv0^,cmdline^,argv0len);
  160. cmdline[argv0len]:=' ';
  161. inc(argv0len);
  162. move(doscmd[1],cmdline[argv0len],length(doscmd));
  163. cmdline[argv0len+length(doscmd)+1]:=#0;
  164. { parse dos commandline }
  165. pc:=@doscmd[1];
  166. while pc^<>#0 do
  167. begin
  168. { skip leading spaces }
  169. while pc^ in [#1..#32] do
  170. inc(pc);
  171. if pc^=#0 then
  172. break;
  173. { calc argument length }
  174. quote:=' ';
  175. argstart:=pc;
  176. arglen:=0;
  177. while (pc^<>#0) do
  178. begin
  179. case pc^ of
  180. #1..#32 :
  181. begin
  182. if quote<>' ' then
  183. inc(arglen)
  184. else
  185. break;
  186. end;
  187. '"' :
  188. begin
  189. if quote<>'''' then
  190. begin
  191. if PAnsiChar(pc+1)^<>'"' then
  192. begin
  193. if quote='"' then
  194. quote:=' '
  195. else
  196. quote:='"';
  197. end
  198. else
  199. inc(pc);
  200. end
  201. else
  202. inc(arglen);
  203. end;
  204. '''' :
  205. begin
  206. if quote<>'"' then
  207. begin
  208. if PAnsiChar(pc+1)^<>'''' then
  209. begin
  210. if quote='''' then
  211. quote:=' '
  212. else
  213. quote:='''';
  214. end
  215. else
  216. inc(pc);
  217. end
  218. else
  219. inc(arglen);
  220. end;
  221. else
  222. inc(arglen);
  223. end;
  224. inc(pc);
  225. end;
  226. { copy argument }
  227. allocarg(count,arglen);
  228. quote:=' ';
  229. pc:=argstart;
  230. arg:=argv[count];
  231. while (pc^<>#0) do
  232. begin
  233. case pc^ of
  234. #1..#32 :
  235. begin
  236. if quote<>' ' then
  237. begin
  238. arg^:=pc^;
  239. inc(arg);
  240. end
  241. else
  242. break;
  243. end;
  244. '"' :
  245. begin
  246. if quote<>'''' then
  247. begin
  248. if PAnsiChar(pc+1)^<>'"' then
  249. begin
  250. if quote='"' then
  251. quote:=' '
  252. else
  253. quote:='"';
  254. end
  255. else
  256. inc(pc);
  257. end
  258. else
  259. begin
  260. arg^:=pc^;
  261. inc(arg);
  262. end;
  263. end;
  264. '''' :
  265. begin
  266. if quote<>'"' then
  267. begin
  268. if PAnsiChar(pc+1)^<>'''' then
  269. begin
  270. if quote='''' then
  271. quote:=' '
  272. else
  273. quote:='''';
  274. end
  275. else
  276. inc(pc);
  277. end
  278. else
  279. begin
  280. arg^:=pc^;
  281. inc(arg);
  282. end;
  283. end;
  284. else
  285. begin
  286. arg^:=pc^;
  287. inc(arg);
  288. end;
  289. end;
  290. inc(pc);
  291. end;
  292. arg^:=#0;
  293. {$IfDef SYSTEM_DEBUG_STARTUP}
  294. Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
  295. {$EndIf SYSTEM_DEBUG_STARTUP}
  296. inc(count);
  297. end;
  298. argc:=count;
  299. { check for !proxy for long commandlines passed using environment }
  300. hp:=envp;
  301. useproxy:=false;
  302. while assigned(hp^) do
  303. begin
  304. if (hp^[0]=' ') then
  305. begin
  306. proxy_s:=strpas(hp^);
  307. if Copy(proxy_s,1,7)=' !proxy' then
  308. begin
  309. proxy_s[13]:=#0;
  310. proxy_s[18]:=#0;
  311. proxy_s[23]:=#0;
  312. argv[2]:=@proxy_s[9];
  313. argv[3]:=@proxy_s[14];
  314. argv[4]:=@proxy_s[19];
  315. useproxy:=true;
  316. break;
  317. end;
  318. end;
  319. inc(hp);
  320. end;
  321. { check for !proxy for long commandlines passed using commandline }
  322. if (not useproxy) and
  323. (argc > 1) and (far_strlen(get_ds,longint(argv[1])) = 6) then
  324. begin
  325. move(argv[1]^,proxy_s[1],6);
  326. proxy_s[0] := #6;
  327. if (proxy_s = '!proxy') then
  328. useproxy:=true;
  329. end;
  330. { use proxy when found }
  331. if useproxy then
  332. begin
  333. proxy_argc:=atohex(argv[2]);
  334. proxy_seg:=atohex(argv[3]);
  335. proxy_ofs:=atohex(argv[4]);
  336. {$IfDef SYSTEM_DEBUG_STARTUP}
  337. Writeln(stderr,'proxy command line found');
  338. writeln(stderr,'argc: ',proxy_argc,' seg: ',proxy_seg,' ofs: ',proxy_ofs);
  339. {$EndIf SYSTEM_DEBUG_STARTUP}
  340. rm_argv:=SysGetmem(proxy_argc*sizeof(word));
  341. sysseg_move(dos_selector,proxy_seg*16+proxy_ofs, get_ds,longint(rm_argv),proxy_argc*sizeof(word));
  342. for count:=0 to proxy_argc - 1 do
  343. begin
  344. lin:=proxy_seg*16+rm_argv^[count];
  345. arglen:=far_strlen(dos_selector,lin);
  346. allocarg(count,arglen);
  347. sysseg_move(dos_selector,lin,get_ds,longint(argv[count]),arglen+1);
  348. {$IfDef SYSTEM_DEBUG_STARTUP}
  349. Writeln(stderr,'arg ',count,' #',rm_argv^[count],'#',arglen,'#',argv[count],'#');
  350. {$EndIf SYSTEM_DEBUG_STARTUP}
  351. end;
  352. SysFreemem(rm_argv);
  353. argc:=proxy_argc;
  354. end;
  355. { create an nil entry }
  356. allocarg(argc,0);
  357. { free unused memory }
  358. sysreallocmem(argv,(argc+1)*sizeof(pointer));
  359. end;
  360. function strcopy(dest,source : PAnsiChar) : PAnsiChar;assembler;
  361. var
  362. saveeax,saveesi,saveedi : longint;
  363. asm
  364. movl %edi,saveedi
  365. movl %esi,saveesi
  366. {$ifdef REGCALL}
  367. movl %eax,saveeax
  368. movl %edx,%edi
  369. {$else}
  370. movl source,%edi
  371. {$endif}
  372. testl %edi,%edi
  373. jz .LStrCopyDone
  374. leal 3(%edi),%ecx
  375. andl $-4,%ecx
  376. movl %edi,%esi
  377. subl %edi,%ecx
  378. {$ifdef REGCALL}
  379. movl %eax,%edi
  380. {$else}
  381. movl dest,%edi
  382. {$endif}
  383. jz .LStrCopyAligned
  384. .LStrCopyAlignLoop:
  385. movb (%esi),%al
  386. incl %edi
  387. incl %esi
  388. testb %al,%al
  389. movb %al,-1(%edi)
  390. jz .LStrCopyDone
  391. decl %ecx
  392. jnz .LStrCopyAlignLoop
  393. .balign 16
  394. .LStrCopyAligned:
  395. movl (%esi),%eax
  396. movl %eax,%edx
  397. leal 0x0fefefeff(%eax),%ecx
  398. notl %edx
  399. addl $4,%esi
  400. andl %edx,%ecx
  401. andl $0x080808080,%ecx
  402. jnz .LStrCopyEndFound
  403. movl %eax,(%edi)
  404. addl $4,%edi
  405. jmp .LStrCopyAligned
  406. .LStrCopyEndFound:
  407. testl $0x0ff,%eax
  408. jz .LStrCopyByte
  409. testl $0x0ff00,%eax
  410. jz .LStrCopyWord
  411. testl $0x0ff0000,%eax
  412. jz .LStrCopy3Bytes
  413. movl %eax,(%edi)
  414. jmp .LStrCopyDone
  415. .LStrCopy3Bytes:
  416. xorb %dl,%dl
  417. movw %ax,(%edi)
  418. movb %dl,2(%edi)
  419. jmp .LStrCopyDone
  420. .LStrCopyWord:
  421. movw %ax,(%edi)
  422. jmp .LStrCopyDone
  423. .LStrCopyByte:
  424. movb %al,(%edi)
  425. .LStrCopyDone:
  426. {$ifdef REGCALL}
  427. movl saveeax,%eax
  428. {$else}
  429. movl dest,%eax
  430. {$endif}
  431. movl saveedi,%edi
  432. movl saveesi,%esi
  433. end;
  434. var
  435. env_selector:word; external name 'ENV_SELECTOR';
  436. env_size:longint; external name 'ENV_SIZE';
  437. procedure setup_environment;
  438. var env_count : longint;
  439. dos_env,cp : PAnsiChar;
  440. begin
  441. env_count:=0;
  442. dos_env:=getmem(env_size);
  443. sysseg_move(env_selector,$0, get_ds, longint(dos_env), env_size);
  444. cp:=dos_env;
  445. while cp ^ <> #0 do
  446. begin
  447. inc(env_count);
  448. while (cp^ <> #0) do inc(longint(cp)); { skip to NUL }
  449. inc(longint(cp)); { skip to next character }
  450. end;
  451. envp := sysgetmem((env_count+1) * sizeof(PAnsiChar));
  452. if (envp = nil) then exit;
  453. cp:=dos_env;
  454. env_count:=0;
  455. while cp^ <> #0 do
  456. begin
  457. envp[env_count] := sysgetmem(strlen(cp)+1);
  458. strcopy(envp[env_count], cp);
  459. {$IfDef SYSTEM_DEBUG_STARTUP}
  460. Writeln(stderr,'env ',env_count,' = "',envp[env_count],'"');
  461. {$EndIf SYSTEM_DEBUG_STARTUP}
  462. inc(env_count);
  463. while (cp^ <> #0) do
  464. inc(longint(cp)); { skip to NUL }
  465. inc(longint(cp)); { skip to next character }
  466. end;
  467. envp[env_count]:=nil;
  468. longint(cp):=longint(cp)+3;
  469. dos_argv0 := sysgetmem(strlen(cp)+1);
  470. if (dos_argv0 = nil) then halt;
  471. strcopy(dos_argv0, cp);
  472. end;
  473. procedure syscopytodos(addr : sizeuint; len : longint);
  474. begin
  475. if len > tb_size then
  476. HandleError(217);
  477. sysseg_move(get_ds,addr,dos_selector,tb,len);
  478. end;
  479. procedure syscopyfromdos(addr : sizeuint; len : longint);
  480. begin
  481. if len > tb_size then
  482. HandleError(217);
  483. sysseg_move(dos_selector,tb,get_ds,addr,len);
  484. end;
  485. procedure sysrealintr(intnr : word;var regs : trealregs);
  486. begin
  487. regs.realsp:=0;
  488. regs.realss:=0;
  489. asm
  490. pushl %edi
  491. pushl %ebx
  492. pushw %fs
  493. movw intnr,%bx
  494. xorl %ecx,%ecx
  495. movl regs,%edi
  496. movw $0x300,%ax
  497. int $0x31
  498. popw %fs
  499. popl %ebx
  500. popl %edi
  501. end;
  502. end;
  503. procedure set_pm_interrupt(vector : byte;const intaddr : tseginfo);
  504. begin
  505. asm
  506. pushl %ebx
  507. movl intaddr,%eax
  508. movl (%eax),%edx
  509. movw 4(%eax),%cx
  510. movl $0x205,%eax
  511. movb vector,%bl
  512. int $0x31
  513. popl %ebx
  514. end;
  515. end;
  516. procedure get_pm_interrupt(vector : byte;var intaddr : tseginfo);
  517. begin
  518. asm
  519. pushl %ebx
  520. movb vector,%bl
  521. movl $0x204,%eax
  522. int $0x31
  523. movl intaddr,%eax
  524. movl %edx,(%eax)
  525. movw %cx,4(%eax)
  526. popl %ebx
  527. end;
  528. end;
  529. {*****************************************************************************
  530. System Dependent Exit code
  531. *****************************************************************************}
  532. procedure ___exit(exitcode:longint);cdecl;external name '___exit';
  533. Procedure system_exit;
  534. var
  535. h : byte;
  536. begin
  537. for h:=0 to max_files-1 do
  538. if openfiles[h] then
  539. begin
  540. {$ifdef SYSTEMDEBUG}
  541. writeln(stderr,'file ',opennames[h],' not closed at exit');
  542. {$endif SYSTEMDEBUG}
  543. if h>=5 then
  544. do_close(h);
  545. end;
  546. { halt is not allways called !! }
  547. { not on normal exit !! PM }
  548. set_pm_interrupt($00,old_int00);
  549. {$ifndef EXCEPTIONS_IN_SYSTEM}
  550. set_pm_interrupt($75,old_int75);
  551. {$endif EXCEPTIONS_IN_SYSTEM}
  552. ___exit(exitcode);
  553. end;
  554. procedure new_int00;
  555. begin
  556. HandleError(200);
  557. end;
  558. {$ifndef EXCEPTIONS_IN_SYSTEM}
  559. procedure new_int75;
  560. begin
  561. asm
  562. xorl %eax,%eax
  563. outb %al,$0x0f0
  564. movb $0x20,%al
  565. outb %al,$0x0a0
  566. outb %al,$0x020
  567. end;
  568. HandleError(200);
  569. end;
  570. {$endif EXCEPTIONS_IN_SYSTEM}
  571. var
  572. __stkbottom : pointer;//###########external name '__stkbottom';
  573. {*****************************************************************************
  574. ParamStr/Randomize
  575. *****************************************************************************}
  576. function paramcount : longint;
  577. begin
  578. paramcount := argc - 1;
  579. end;
  580. function paramstr(l : longint) : shortstring;
  581. begin
  582. if (l>=0) and (l+1<=argc) then
  583. paramstr:=strpas(argv[l])
  584. else
  585. paramstr:='';
  586. end;
  587. procedure randomize;
  588. var
  589. hl : longint;
  590. regs : trealregs;
  591. begin
  592. regs.realeax:=$2c00;
  593. sysrealintr($21,regs);
  594. hl:=lo(regs.realedx);
  595. randseed:=hl*$10000+ lo(regs.realecx);
  596. end;
  597. { include standard heap management }
  598. { include heap.inc}
  599. (*
  600. {*****************************************************************************
  601. UnTyped File Handling
  602. *****************************************************************************}
  603. {$i file.inc}
  604. {*****************************************************************************
  605. Typed File Handling
  606. *****************************************************************************}
  607. {$i typefile.inc}
  608. {*****************************************************************************
  609. Text File Handling
  610. *****************************************************************************}
  611. {$i text.inc}
  612. {*****************************************************************************
  613. Generic Handling
  614. *****************************************************************************}
  615. {$ifdef TEST_GENERIC}
  616. {$i generic.inc}
  617. {$endif TEST_GENERIC}
  618. *)
  619. {*****************************************************************************
  620. SystemUnit Initialization
  621. *****************************************************************************}
  622. function CheckLFN:boolean;
  623. var
  624. regs : TRealRegs;
  625. RootName : PAnsiChar;
  626. begin
  627. { Check LFN API on drive c:\ }
  628. RootName:='C:\';
  629. syscopytodos(longint(RootName),strlen(RootName)+1);
  630. { Call 'Get Volume Information' ($71A0) }
  631. regs.realeax:=$71a0;
  632. regs.reales:=tb_segment;
  633. regs.realedi:=tb_offset;
  634. regs.realecx:=32;
  635. regs.realds:=tb_segment;
  636. regs.realedx:=tb_offset;
  637. regs.realflags:=carryflag;
  638. sysrealintr($21,regs);
  639. { If carryflag=0 and LFN API bit in ebx is set then use Long file names }
  640. CheckLFN:=(regs.realflags and carryflag=0) and (regs.realebx and $4000=$4000);
  641. end;
  642. {$ifdef EXCEPTIONS_IN_SYSTEM}
  643. {$define IN_SYSTEM}
  644. {$i dpmiexcp.pp}
  645. {$endif EXCEPTIONS_IN_SYSTEM}
  646. procedure SysInitStdIO;
  647. begin
  648. OpenStdIO(Input,fmInput,StdInputHandle);
  649. OpenStdIO(Output,fmOutput,StdOutputHandle);
  650. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  651. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  652. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  653. end;
  654. function GetProcessID: SizeUInt;
  655. begin
  656. GetProcessID := 1;
  657. end;
  658. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  659. begin
  660. result := stklen;
  661. end;
  662. var
  663. temp_int : tseginfo;
  664. Begin
  665. alloc_tb;
  666. StackLength := InitialStkLen;
  667. StackBottom := __stkbottom;
  668. { To be set if this is a GUI or console application }
  669. IsConsole := TRUE;
  670. { To be set if this is a library and not a program }
  671. IsLibrary := FALSE;
  672. { save old int 0 and 75 }
  673. get_pm_interrupt($00,old_int00);
  674. get_pm_interrupt($75,old_int75);
  675. temp_int.segment:=get_cs;
  676. temp_int.offset:=@new_int00;
  677. set_pm_interrupt($00,temp_int);
  678. {$ifndef EXCEPTIONS_IN_SYSTEM}
  679. temp_int.offset:=@new_int75;
  680. set_pm_interrupt($75,temp_int);
  681. {$endif EXCEPTIONS_IN_SYSTEM}
  682. { Setup heap }
  683. InitHeap;
  684. SysInitExceptions;
  685. initunicodestringmanager;
  686. { Setup stdin, stdout and stderr }
  687. SysInitStdIO;
  688. { Setup environment and arguments }
  689. Setup_Environment;
  690. Setup_Arguments;
  691. { Use LFNSupport LFN }
  692. LFNSupport:=CheckLFN;
  693. if LFNSupport then
  694. begin
  695. FileNameCasePreserving:=true;
  696. AllFilesMask := '*';
  697. end
  698. else
  699. AllFilesMask := '*.*';
  700. { Reset IO Error }
  701. InOutRes:=0;
  702. ThreadID := 1;
  703. {$ifdef EXCEPTIONS_IN_SYSTEM}
  704. InitDPMIExcp;
  705. InstallDefaultHandlers;
  706. {$endif EXCEPTIONS_IN_SYSTEM}
  707. End.