system.pp 19 KB

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