system.pp 19 KB

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