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