system.pp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  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. { two debug conditionnals can be used
  14. - SYSTEMDEBUG
  15. -for STACK checks
  16. -for non closed files at exit (or at any time with GDB)
  17. - SYSTEM_DEBUG_STARTUP
  18. specifically for
  19. - proxy command line (DJGPP feature)
  20. - list of args
  21. - list of env variables (PM) }
  22. {$ifndef NO_EXCEPTIONS_IN_SYSTEM}
  23. {$define EXCEPTIONS_IN_SYSTEM}
  24. {$endif NO_EXCEPTIONS_IN_SYSTEM}
  25. { include system-independent routine headers }
  26. {$I systemh.inc}
  27. { include heap support headers }
  28. {$I heaph.inc}
  29. {Platform specific information}
  30. type
  31. THandle = Longint;
  32. const
  33. LineEnding = #13#10;
  34. { LFNSupport is a variable here, defined below!!! }
  35. DirectorySeparator = '\';
  36. DriveSeparator = ':';
  37. PathSeparator = ';';
  38. { FileNameCaseSensitive is defined separately below!!! }
  39. const
  40. { Default filehandles }
  41. UnusedHandle = -1;
  42. StdInputHandle = 0;
  43. StdOutputHandle = 1;
  44. StdErrorHandle = 2;
  45. FileNameCaseSensitive : boolean = false;
  46. sLineBreak = LineEnding;
  47. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  48. { Default memory segments (Tp7 compatibility) }
  49. seg0040 = $0040;
  50. segA000 = $A000;
  51. segB000 = $B000;
  52. segB800 = $B800;
  53. var
  54. { Mem[] support }
  55. mem : array[0..$7fffffff] of byte absolute $0:$0;
  56. memw : array[0..$7fffffff div sizeof(word)] of word absolute $0:$0;
  57. meml : array[0..$7fffffff div sizeof(longint)] of longint absolute $0:$0;
  58. { C-compatible arguments and environment }
  59. argc : longint;
  60. argv : ppchar;
  61. envp : ppchar;
  62. dos_argv0 : pchar;
  63. {$ifndef RTLLITE}
  64. { System info }
  65. LFNSupport : boolean;
  66. {$ELSE RTLLITE}
  67. const
  68. LFNSupport = false;
  69. {$endif RTLLITE}
  70. type
  71. { Dos Extender info }
  72. p_stub_info = ^t_stub_info;
  73. t_stub_info = packed record
  74. magic : array[0..15] of char;
  75. size : longint;
  76. minstack : longint;
  77. memory_handle : longint;
  78. initial_size : longint;
  79. minkeep : word;
  80. ds_selector : word;
  81. ds_segment : word;
  82. psp_selector : word;
  83. cs_selector : word;
  84. env_size : word;
  85. basename : array[0..7] of char;
  86. argv0 : array [0..15] of char;
  87. dpmi_server : array [0..15] of char;
  88. end;
  89. p_go32_info_block = ^t_go32_info_block;
  90. t_go32_info_block = packed record
  91. size_of_this_structure_in_bytes : longint; {offset 0}
  92. linear_address_of_primary_screen : longint; {offset 4}
  93. linear_address_of_secondary_screen : longint; {offset 8}
  94. linear_address_of_transfer_buffer : longint; {offset 12}
  95. size_of_transfer_buffer : longint; {offset 16}
  96. pid : longint; {offset 20}
  97. master_interrupt_controller_base : byte; {offset 24}
  98. slave_interrupt_controller_base : byte; {offset 25}
  99. selector_for_linear_memory : word; {offset 26}
  100. linear_address_of_stub_info_structure : longint; {offset 28}
  101. linear_address_of_original_psp : longint; {offset 32}
  102. run_mode : word; {offset 36}
  103. run_mode_info : word; {offset 38}
  104. end;
  105. var
  106. stub_info : p_stub_info;
  107. go32_info_block : t_go32_info_block;
  108. {$ifdef SYSTEMDEBUG}
  109. const
  110. accept_sbrk : boolean = true;
  111. {$endif}
  112. {
  113. necessary for objects.pas, should be removed (at least from the interface
  114. to the implementation)
  115. }
  116. type
  117. trealregs=record
  118. realedi,realesi,realebp,realres,
  119. realebx,realedx,realecx,realeax : longint;
  120. realflags,
  121. reales,realds,realfs,realgs,
  122. realip,realcs,realsp,realss : word;
  123. end;
  124. function do_write(h,addr,len : longint) : longint;
  125. function do_read(h,addr,len : longint) : longint;
  126. procedure syscopyfromdos(addr : longint; len : longint);
  127. procedure syscopytodos(addr : longint; len : longint);
  128. procedure sysrealintr(intnr : word;var regs : trealregs);
  129. function tb : longint;
  130. implementation
  131. { include system independent routines }
  132. {$I system.inc}
  133. const
  134. carryflag = 1;
  135. type
  136. tseginfo=packed record
  137. offset : pointer;
  138. segment : word;
  139. end;
  140. var
  141. old_int00 : tseginfo;cvar;
  142. old_int75 : tseginfo;cvar;
  143. {$asmmode ATT}
  144. {*****************************************************************************
  145. Go32 Helpers
  146. *****************************************************************************}
  147. function far_strlen(selector : word;linear_address : longint) : longint;assembler;
  148. asm
  149. movl linear_address,%edx
  150. movl %edx,%ecx
  151. movw selector,%gs
  152. .Larg19:
  153. movb %gs:(%edx),%al
  154. testb %al,%al
  155. je .Larg20
  156. incl %edx
  157. jmp .Larg19
  158. .Larg20:
  159. movl %edx,%eax
  160. subl %ecx,%eax
  161. end;
  162. function tb : longint;
  163. begin
  164. tb:=go32_info_block.linear_address_of_transfer_buffer;
  165. end;
  166. function tb_segment : longint;
  167. begin
  168. tb_segment:=go32_info_block.linear_address_of_transfer_buffer shr 4;
  169. end;
  170. function tb_offset : longint;
  171. begin
  172. tb_offset:=go32_info_block.linear_address_of_transfer_buffer and $f;
  173. end;
  174. function tb_size : longint;
  175. begin
  176. tb_size:=go32_info_block.size_of_transfer_buffer;
  177. end;
  178. function dos_selector : word;
  179. begin
  180. dos_selector:=go32_info_block.selector_for_linear_memory;
  181. end;
  182. function get_ds : word;assembler;
  183. asm
  184. movw %ds,%ax
  185. end;
  186. function get_cs : word;assembler;
  187. asm
  188. movw %cs,%ax
  189. end;
  190. procedure sysseg_move(sseg : word;source : longint;dseg : word;dest : longint;count : longint);
  191. begin
  192. if count=0 then
  193. exit;
  194. if (sseg<>dseg) or ((sseg=dseg) and (source>dest)) then
  195. asm
  196. pushl %esi
  197. pushl %edi
  198. pushw %es
  199. pushw %ds
  200. cld
  201. movl count,%ecx
  202. movl source,%esi
  203. movl dest,%edi
  204. movw dseg,%ax
  205. movw %ax,%es
  206. movw sseg,%ax
  207. movw %ax,%ds
  208. movl %ecx,%eax
  209. shrl $2,%ecx
  210. rep
  211. movsl
  212. movl %eax,%ecx
  213. andl $3,%ecx
  214. rep
  215. movsb
  216. popw %ds
  217. popw %es
  218. popl %edi
  219. popl %esi
  220. end
  221. else if (source<dest) then
  222. { copy backward for overlapping }
  223. asm
  224. pushl %esi
  225. pushl %edi
  226. pushw %es
  227. pushw %ds
  228. std
  229. movl count,%ecx
  230. movl source,%esi
  231. movl dest,%edi
  232. movw dseg,%ax
  233. movw %ax,%es
  234. movw sseg,%ax
  235. movw %ax,%ds
  236. addl %ecx,%esi
  237. addl %ecx,%edi
  238. movl %ecx,%eax
  239. andl $3,%ecx
  240. orl %ecx,%ecx
  241. jz .LSEG_MOVE1
  242. { calculate esi and edi}
  243. decl %esi
  244. decl %edi
  245. rep
  246. movsb
  247. incl %esi
  248. incl %edi
  249. .LSEG_MOVE1:
  250. subl $4,%esi
  251. subl $4,%edi
  252. movl %eax,%ecx
  253. shrl $2,%ecx
  254. rep
  255. movsl
  256. cld
  257. popw %ds
  258. popw %es
  259. popl %edi
  260. popl %esi
  261. end;
  262. end;
  263. var
  264. _args : ppchar;external name '_args';
  265. procedure setup_arguments;
  266. type
  267. arrayword = array [0..255] of word;
  268. var
  269. psp : word;
  270. proxy_s : string[50];
  271. proxy_argc,proxy_seg,proxy_ofs,lin : longint;
  272. rm_argv : ^arrayword;
  273. argv0len : longint;
  274. useproxy : boolean;
  275. hp : ppchar;
  276. doscmd : string[129]; { Dos commandline copied from PSP, max is 128 chars +1 for terminating zero }
  277. arglen,
  278. count : longint;
  279. argstart,
  280. pc,arg : pchar;
  281. quote : char;
  282. argvlen : longint;
  283. function atohex(s : pchar) : longint;
  284. var
  285. rv : longint;
  286. v : byte;
  287. begin
  288. rv:=0;
  289. while (s^<>#0) do
  290. begin
  291. v:=byte(s^)-byte('0');
  292. if (v > 9) then
  293. dec(v,7);
  294. v:=v and 15; { in case it's lower case }
  295. rv:=(rv shl 4) or v;
  296. inc(longint(s));
  297. end;
  298. atohex:=rv;
  299. end;
  300. procedure allocarg(idx,len:longint);
  301. begin
  302. if idx>=argvlen then
  303. begin
  304. argvlen:=(idx+8) and (not 7);
  305. sysreallocmem(argv,argvlen*sizeof(pointer));
  306. end;
  307. { use realloc to reuse already existing memory }
  308. if len<>0 then
  309. sysreallocmem(argv[idx],len+1);
  310. end;
  311. begin
  312. count:=0;
  313. argc:=1;
  314. argv:=nil;
  315. argvlen:=0;
  316. { load commandline from psp }
  317. psp:=stub_info^.psp_selector;
  318. sysseg_move(psp, 128, get_ds, longint(@doscmd), 128);
  319. doscmd[length(doscmd)+1]:=#0;
  320. {$IfDef SYSTEM_DEBUG_STARTUP}
  321. Writeln(stderr,'Dos command line is #',doscmd,'# size = ',length(doscmd));
  322. {$EndIf }
  323. { create argv[0] }
  324. argv0len:=strlen(dos_argv0);
  325. allocarg(count,argv0len);
  326. move(dos_argv0^,argv[count]^,argv0len);
  327. inc(count);
  328. { setup cmdline variable }
  329. cmdline:=Getmem(argv0len+length(doscmd)+2);
  330. move(dos_argv0^,cmdline^,argv0len);
  331. cmdline[argv0len]:=' ';
  332. inc(argv0len);
  333. move(doscmd[1],cmdline[argv0len],length(doscmd));
  334. cmdline[argv0len+length(doscmd)+1]:=#0;
  335. { parse dos commandline }
  336. pc:=@doscmd[1];
  337. while pc^<>#0 do
  338. begin
  339. { skip leading spaces }
  340. while pc^ in [#1..#32] do
  341. inc(pc);
  342. if pc^=#0 then
  343. break;
  344. { calc argument length }
  345. quote:=' ';
  346. argstart:=pc;
  347. arglen:=0;
  348. while (pc^<>#0) do
  349. begin
  350. case pc^ of
  351. #1..#32 :
  352. begin
  353. if quote<>' ' then
  354. inc(arglen)
  355. else
  356. break;
  357. end;
  358. '"' :
  359. begin
  360. if quote<>'''' then
  361. begin
  362. if pchar(pc+1)^<>'"' then
  363. begin
  364. if quote='"' then
  365. quote:=' '
  366. else
  367. quote:='"';
  368. end
  369. else
  370. inc(pc);
  371. end
  372. else
  373. inc(arglen);
  374. end;
  375. '''' :
  376. begin
  377. if quote<>'"' then
  378. begin
  379. if pchar(pc+1)^<>'''' then
  380. begin
  381. if quote='''' then
  382. quote:=' '
  383. else
  384. quote:='''';
  385. end
  386. else
  387. inc(pc);
  388. end
  389. else
  390. inc(arglen);
  391. end;
  392. else
  393. inc(arglen);
  394. end;
  395. inc(pc);
  396. end;
  397. { copy argument }
  398. allocarg(count,arglen);
  399. quote:=' ';
  400. pc:=argstart;
  401. arg:=argv[count];
  402. while (pc^<>#0) do
  403. begin
  404. case pc^ of
  405. #1..#32 :
  406. begin
  407. if quote<>' ' then
  408. begin
  409. arg^:=pc^;
  410. inc(arg);
  411. end
  412. else
  413. break;
  414. end;
  415. '"' :
  416. begin
  417. if quote<>'''' then
  418. begin
  419. if pchar(pc+1)^<>'"' then
  420. begin
  421. if quote='"' then
  422. quote:=' '
  423. else
  424. quote:='"';
  425. end
  426. else
  427. inc(pc);
  428. end
  429. else
  430. begin
  431. arg^:=pc^;
  432. inc(arg);
  433. end;
  434. end;
  435. '''' :
  436. begin
  437. if quote<>'"' then
  438. begin
  439. if pchar(pc+1)^<>'''' then
  440. begin
  441. if quote='''' then
  442. quote:=' '
  443. else
  444. quote:='''';
  445. end
  446. else
  447. inc(pc);
  448. end
  449. else
  450. begin
  451. arg^:=pc^;
  452. inc(arg);
  453. end;
  454. end;
  455. else
  456. begin
  457. arg^:=pc^;
  458. inc(arg);
  459. end;
  460. end;
  461. inc(pc);
  462. end;
  463. arg^:=#0;
  464. {$IfDef SYSTEM_DEBUG_STARTUP}
  465. Writeln(stderr,'dos arg ',count,' #',arglen,'#',argv[count],'#');
  466. {$EndIf SYSTEM_DEBUG_STARTUP}
  467. inc(count);
  468. end;
  469. argc:=count;
  470. { check for !proxy for long commandlines passed using environment }
  471. hp:=envp;
  472. useproxy:=false;
  473. while assigned(hp^) do
  474. begin
  475. if (hp^[0]=' ') then
  476. begin
  477. proxy_s:=strpas(hp^);
  478. if Copy(proxy_s,1,7)=' !proxy' then
  479. begin
  480. proxy_s[13]:=#0;
  481. proxy_s[18]:=#0;
  482. proxy_s[23]:=#0;
  483. argv[2]:=@proxy_s[9];
  484. argv[3]:=@proxy_s[14];
  485. argv[4]:=@proxy_s[19];
  486. useproxy:=true;
  487. break;
  488. end;
  489. end;
  490. inc(hp);
  491. end;
  492. { check for !proxy for long commandlines passed using commandline }
  493. if (not useproxy) and
  494. (argc > 1) and (far_strlen(get_ds,longint(argv[1])) = 6) then
  495. begin
  496. move(argv[1]^,proxy_s[1],6);
  497. proxy_s[0] := #6;
  498. if (proxy_s = '!proxy') then
  499. useproxy:=true;
  500. end;
  501. { use proxy when found }
  502. if useproxy then
  503. begin
  504. proxy_argc:=atohex(argv[2]);
  505. proxy_seg:=atohex(argv[3]);
  506. proxy_ofs:=atohex(argv[4]);
  507. {$IfDef SYSTEM_DEBUG_STARTUP}
  508. Writeln(stderr,'proxy command line found');
  509. writeln(stderr,'argc: ',proxy_argc,' seg: ',proxy_seg,' ofs: ',proxy_ofs);
  510. {$EndIf SYSTEM_DEBUG_STARTUP}
  511. rm_argv:=SysGetmem(proxy_argc*sizeof(word));
  512. sysseg_move(dos_selector,proxy_seg*16+proxy_ofs, get_ds,longint(rm_argv),proxy_argc*sizeof(word));
  513. for count:=0 to proxy_argc - 1 do
  514. begin
  515. lin:=proxy_seg*16+rm_argv^[count];
  516. arglen:=far_strlen(dos_selector,lin);
  517. allocarg(count,arglen);
  518. sysseg_move(dos_selector,lin,get_ds,longint(argv[count]),arglen+1);
  519. {$IfDef SYSTEM_DEBUG_STARTUP}
  520. Writeln(stderr,'arg ',count,' #',rm_argv^[count],'#',arglen,'#',argv[count],'#');
  521. {$EndIf SYSTEM_DEBUG_STARTUP}
  522. end;
  523. SysFreemem(rm_argv);
  524. argc:=proxy_argc;
  525. end;
  526. { create an nil entry }
  527. allocarg(argc,0);
  528. { free unused memory }
  529. sysreallocmem(argv,(argc+1)*sizeof(pointer));
  530. _args:=argv;
  531. end;
  532. function strcopy(dest,source : pchar) : pchar;assembler;
  533. asm
  534. pushl %esi
  535. pushl %edi
  536. cld
  537. movl 12(%ebp),%edi
  538. movl $0xffffffff,%ecx
  539. xorb %al,%al
  540. repne
  541. scasb
  542. not %ecx
  543. movl 8(%ebp),%edi
  544. movl 12(%ebp),%esi
  545. movl %ecx,%eax
  546. shrl $2,%ecx
  547. rep
  548. movsl
  549. movl %eax,%ecx
  550. andl $3,%ecx
  551. rep
  552. movsb
  553. movl 8(%ebp),%eax
  554. popl %edi
  555. popl %esi
  556. end;
  557. var
  558. __stubinfo : p_stub_info;external name '__stubinfo';
  559. ___dos_argv0 : pchar;external name '___dos_argv0';
  560. procedure setup_environment;
  561. var env_selector : word;
  562. env_count : longint;
  563. dos_env,cp : pchar;
  564. begin
  565. stub_info:=__stubinfo;
  566. dos_env := sysgetmem(stub_info^.env_size);
  567. env_count:=0;
  568. sysseg_move(stub_info^.psp_selector,$2c, get_ds, longint(@env_selector), 2);
  569. sysseg_move(env_selector, 0, get_ds, longint(dos_env), stub_info^.env_size);
  570. cp:=dos_env;
  571. while cp ^ <> #0 do
  572. begin
  573. inc(env_count);
  574. while (cp^ <> #0) do inc(longint(cp)); { skip to NUL }
  575. inc(longint(cp)); { skip to next character }
  576. end;
  577. envp := sysgetmem((env_count+1) * sizeof(pchar));
  578. if (envp = nil) then exit;
  579. cp:=dos_env;
  580. env_count:=0;
  581. while cp^ <> #0 do
  582. begin
  583. envp[env_count] := sysgetmem(strlen(cp)+1);
  584. strcopy(envp[env_count], cp);
  585. {$IfDef SYSTEM_DEBUG_STARTUP}
  586. Writeln(stderr,'env ',env_count,' = "',envp[env_count],'"');
  587. {$EndIf SYSTEM_DEBUG_STARTUP}
  588. inc(env_count);
  589. while (cp^ <> #0) do
  590. inc(longint(cp)); { skip to NUL }
  591. inc(longint(cp)); { skip to next character }
  592. end;
  593. envp[env_count]:=nil;
  594. longint(cp):=longint(cp)+3;
  595. dos_argv0 := sysgetmem(strlen(cp)+1);
  596. if (dos_argv0 = nil) then halt;
  597. strcopy(dos_argv0, cp);
  598. { update ___dos_argv0 also }
  599. ___dos_argv0:=dos_argv0
  600. end;
  601. procedure syscopytodos(addr : longint; len : longint);
  602. begin
  603. if len > tb_size then
  604. HandleError(217);
  605. sysseg_move(get_ds,addr,dos_selector,tb,len);
  606. end;
  607. procedure syscopyfromdos(addr : longint; len : longint);
  608. begin
  609. if len > tb_size then
  610. HandleError(217);
  611. sysseg_move(dos_selector,tb,get_ds,addr,len);
  612. end;
  613. procedure sysrealintr(intnr : word;var regs : trealregs);
  614. begin
  615. regs.realsp:=0;
  616. regs.realss:=0;
  617. asm
  618. pushl %ebx
  619. pushl %edi
  620. movw intnr,%bx
  621. xorl %ecx,%ecx
  622. movl regs,%edi
  623. movw $0x300,%ax
  624. int $0x31
  625. popl %edi
  626. popl %ebx
  627. end;
  628. end;
  629. procedure set_pm_interrupt(vector : byte;const intaddr : tseginfo);
  630. begin
  631. asm
  632. pushl %ebx
  633. movl intaddr,%eax
  634. movl (%eax),%edx
  635. movw 4(%eax),%cx
  636. movl $0x205,%eax
  637. movb vector,%bl
  638. int $0x31
  639. popl %ebx
  640. end;
  641. end;
  642. procedure get_pm_interrupt(vector : byte;var intaddr : tseginfo);
  643. begin
  644. asm
  645. pushl %ebx
  646. movb vector,%bl
  647. movl $0x204,%eax
  648. int $0x31
  649. movl intaddr,%eax
  650. movl %edx,(%eax)
  651. movw %cx,4(%eax)
  652. popl %ebx
  653. end;
  654. end;
  655. procedure getinoutres(def : word);
  656. var
  657. regs : trealregs;
  658. begin
  659. regs.realeax:=$5900;
  660. regs.realebx:=$0;
  661. sysrealintr($21,regs);
  662. InOutRes:=lo(regs.realeax);
  663. case InOutRes of
  664. 19 : InOutRes:=150;
  665. 21 : InOutRes:=152;
  666. 32 : InOutRes:=5;
  667. end;
  668. if InOutRes=0 then
  669. InOutRes:=Def;
  670. end;
  671. { Keep Track of open files }
  672. const
  673. max_files = 50;
  674. var
  675. openfiles : array [0..max_files-1] of boolean;
  676. {$ifdef SYSTEMDEBUG}
  677. opennames : array [0..max_files-1] of pchar;
  678. const
  679. free_closed_names : boolean = true;
  680. {$endif SYSTEMDEBUG}
  681. {*****************************************************************************
  682. System Dependent Exit code
  683. *****************************************************************************}
  684. procedure ___exit(exitcode:longint);cdecl;external name '___exit';
  685. procedure do_close(handle : longint);forward;
  686. Procedure system_exit;
  687. var
  688. h : byte;
  689. begin
  690. for h:=0 to max_files-1 do
  691. if openfiles[h] then
  692. begin
  693. {$ifdef SYSTEMDEBUG}
  694. writeln(stderr,'file ',opennames[h],' not closed at exit');
  695. {$endif SYSTEMDEBUG}
  696. if h>=5 then
  697. do_close(h);
  698. end;
  699. { halt is not allways called !! }
  700. { not on normal exit !! PM }
  701. set_pm_interrupt($00,old_int00);
  702. {$ifndef EXCEPTIONS_IN_SYSTEM}
  703. set_pm_interrupt($75,old_int75);
  704. {$endif EXCEPTIONS_IN_SYSTEM}
  705. ___exit(exitcode);
  706. end;
  707. procedure new_int00;
  708. begin
  709. HandleError(200);
  710. end;
  711. {$ifndef EXCEPTIONS_IN_SYSTEM}
  712. procedure new_int75;
  713. begin
  714. asm
  715. xorl %eax,%eax
  716. outb %al,$0x0f0
  717. movb $0x20,%al
  718. outb %al,$0x0a0
  719. outb %al,$0x020
  720. end;
  721. HandleError(200);
  722. end;
  723. {$endif EXCEPTIONS_IN_SYSTEM}
  724. var
  725. __stkbottom : pointer;external name '__stkbottom';
  726. {*****************************************************************************
  727. ParamStr/Randomize
  728. *****************************************************************************}
  729. function paramcount : longint;
  730. begin
  731. paramcount := argc - 1;
  732. end;
  733. function paramstr(l : longint) : string;
  734. begin
  735. if (l>=0) and (l+1<=argc) then
  736. paramstr:=strpas(argv[l])
  737. else
  738. paramstr:='';
  739. end;
  740. procedure randomize;
  741. var
  742. hl : longint;
  743. regs : trealregs;
  744. begin
  745. regs.realeax:=$2c00;
  746. sysrealintr($21,regs);
  747. hl:=lo(regs.realedx);
  748. randseed:=hl*$10000+ lo(regs.realecx);
  749. end;
  750. {*****************************************************************************
  751. Heap Management
  752. *****************************************************************************}
  753. var
  754. int_heap : longint;external name 'HEAP';
  755. int_heapsize : longint;external name 'HEAPSIZE';
  756. function getheapstart:pointer;
  757. begin
  758. getheapstart:=@int_heap;
  759. end;
  760. function getheapsize:longint;
  761. begin
  762. getheapsize:=int_heapsize;
  763. end;
  764. function ___sbrk(size:longint):longint;cdecl;external name '___sbrk';
  765. function Sbrk(size : longint):pointer;assembler;
  766. asm
  767. {$ifdef SYSTEMDEBUG}
  768. cmpb $1,accept_sbrk
  769. je .Lsbrk
  770. movl $0,%eax
  771. jmp .Lsbrk_fail
  772. .Lsbrk:
  773. {$endif}
  774. movl size,%eax
  775. pushl %eax
  776. call ___sbrk
  777. addl $4,%esp
  778. {$ifdef SYSTEMDEBUG}
  779. .Lsbrk_fail:
  780. {$endif}
  781. end;
  782. { include standard heap management }
  783. {$I heap.inc}
  784. {****************************************************************************
  785. Low level File Routines
  786. ****************************************************************************}
  787. procedure AllowSlash(p:pchar);
  788. var
  789. i : longint;
  790. begin
  791. { allow slash as backslash }
  792. for i:=0 to strlen(p) do
  793. if p[i]='/' then p[i]:='\';
  794. end;
  795. procedure do_close(handle : longint);
  796. var
  797. regs : trealregs;
  798. begin
  799. if Handle<=4 then
  800. exit;
  801. regs.realebx:=handle;
  802. if handle<max_files then
  803. begin
  804. openfiles[handle]:=false;
  805. {$ifdef SYSTEMDEBUG}
  806. if assigned(opennames[handle]) and free_closed_names then
  807. begin
  808. sysfreememsize(opennames[handle],strlen(opennames[handle])+1);
  809. opennames[handle]:=nil;
  810. end;
  811. {$endif SYSTEMDEBUG}
  812. end;
  813. regs.realeax:=$3e00;
  814. sysrealintr($21,regs);
  815. if (regs.realflags and carryflag) <> 0 then
  816. GetInOutRes(lo(regs.realeax));
  817. end;
  818. procedure do_erase(p : pchar);
  819. var
  820. regs : trealregs;
  821. begin
  822. AllowSlash(p);
  823. syscopytodos(longint(p),strlen(p)+1);
  824. regs.realedx:=tb_offset;
  825. regs.realds:=tb_segment;
  826. if LFNSupport then
  827. regs.realeax:=$7141
  828. else
  829. regs.realeax:=$4100;
  830. regs.realesi:=0;
  831. regs.realecx:=0;
  832. sysrealintr($21,regs);
  833. if (regs.realflags and carryflag) <> 0 then
  834. GetInOutRes(lo(regs.realeax));
  835. end;
  836. procedure do_rename(p1,p2 : pchar);
  837. var
  838. regs : trealregs;
  839. begin
  840. AllowSlash(p1);
  841. AllowSlash(p2);
  842. if strlen(p1)+strlen(p2)+3>tb_size then
  843. HandleError(217);
  844. sysseg_move(get_ds,longint(p2),dos_selector,tb,strlen(p2)+1);
  845. sysseg_move(get_ds,longint(p1),dos_selector,tb+strlen(p2)+2,strlen(p1)+1);
  846. regs.realedi:=tb_offset;
  847. regs.realedx:=tb_offset + strlen(p2)+2;
  848. regs.realds:=tb_segment;
  849. regs.reales:=tb_segment;
  850. if LFNSupport then
  851. regs.realeax:=$7156
  852. else
  853. regs.realeax:=$5600;
  854. regs.realecx:=$ff; { attribute problem here ! }
  855. sysrealintr($21,regs);
  856. if (regs.realflags and carryflag) <> 0 then
  857. GetInOutRes(lo(regs.realeax));
  858. end;
  859. function do_write(h,addr,len : longint) : longint;
  860. var
  861. regs : trealregs;
  862. size,
  863. writesize : longint;
  864. begin
  865. writesize:=0;
  866. while len > 0 do
  867. begin
  868. if len>tb_size then
  869. size:=tb_size
  870. else
  871. size:=len;
  872. syscopytodos(addr+writesize,size);
  873. regs.realecx:=size;
  874. regs.realedx:=tb_offset;
  875. regs.realds:=tb_segment;
  876. regs.realebx:=h;
  877. regs.realeax:=$4000;
  878. sysrealintr($21,regs);
  879. if (regs.realflags and carryflag) <> 0 then
  880. begin
  881. GetInOutRes(lo(regs.realeax));
  882. exit(writesize);
  883. end;
  884. inc(writesize,lo(regs.realeax));
  885. dec(len,lo(regs.realeax));
  886. { stop when not the specified size is written }
  887. if lo(regs.realeax)<size then
  888. break;
  889. end;
  890. Do_Write:=WriteSize;
  891. end;
  892. function do_read(h,addr,len : longint) : longint;
  893. var
  894. regs : trealregs;
  895. size,
  896. readsize : longint;
  897. begin
  898. readsize:=0;
  899. while len > 0 do
  900. begin
  901. if len>tb_size then
  902. size:=tb_size
  903. else
  904. size:=len;
  905. regs.realecx:=size;
  906. regs.realedx:=tb_offset;
  907. regs.realds:=tb_segment;
  908. regs.realebx:=h;
  909. regs.realeax:=$3f00;
  910. sysrealintr($21,regs);
  911. if (regs.realflags and carryflag) <> 0 then
  912. begin
  913. GetInOutRes(lo(regs.realeax));
  914. do_read:=0;
  915. exit;
  916. end;
  917. syscopyfromdos(addr+readsize,lo(regs.realeax));
  918. inc(readsize,lo(regs.realeax));
  919. dec(len,lo(regs.realeax));
  920. { stop when not the specified size is read }
  921. if lo(regs.realeax)<size then
  922. break;
  923. end;
  924. do_read:=readsize;
  925. end;
  926. function do_filepos(handle : longint) : longint;
  927. var
  928. regs : trealregs;
  929. begin
  930. regs.realebx:=handle;
  931. regs.realecx:=0;
  932. regs.realedx:=0;
  933. regs.realeax:=$4201;
  934. sysrealintr($21,regs);
  935. if (regs.realflags and carryflag) <> 0 then
  936. Begin
  937. GetInOutRes(lo(regs.realeax));
  938. do_filepos:=0;
  939. end
  940. else
  941. do_filepos:=lo(regs.realedx) shl 16+lo(regs.realeax);
  942. end;
  943. procedure do_seek(handle,pos : longint);
  944. var
  945. regs : trealregs;
  946. begin
  947. regs.realebx:=handle;
  948. regs.realecx:=pos shr 16;
  949. regs.realedx:=pos and $ffff;
  950. regs.realeax:=$4200;
  951. sysrealintr($21,regs);
  952. if (regs.realflags and carryflag) <> 0 then
  953. GetInOutRes(lo(regs.realeax));
  954. end;
  955. function do_seekend(handle:longint):longint;
  956. var
  957. regs : trealregs;
  958. begin
  959. regs.realebx:=handle;
  960. regs.realecx:=0;
  961. regs.realedx:=0;
  962. regs.realeax:=$4202;
  963. sysrealintr($21,regs);
  964. if (regs.realflags and carryflag) <> 0 then
  965. Begin
  966. GetInOutRes(lo(regs.realeax));
  967. do_seekend:=0;
  968. end
  969. else
  970. do_seekend:=lo(regs.realedx) shl 16+lo(regs.realeax);
  971. end;
  972. function do_filesize(handle : longint) : longint;
  973. var
  974. aktfilepos : longint;
  975. begin
  976. aktfilepos:=do_filepos(handle);
  977. do_filesize:=do_seekend(handle);
  978. do_seek(handle,aktfilepos);
  979. end;
  980. { truncate at a given position }
  981. procedure do_truncate (handle,pos:longint);
  982. var
  983. regs : trealregs;
  984. begin
  985. do_seek(handle,pos);
  986. regs.realecx:=0;
  987. regs.realedx:=tb_offset;
  988. regs.realds:=tb_segment;
  989. regs.realebx:=handle;
  990. regs.realeax:=$4000;
  991. sysrealintr($21,regs);
  992. if (regs.realflags and carryflag) <> 0 then
  993. GetInOutRes(lo(regs.realeax));
  994. end;
  995. const
  996. FileHandleCount : longint = 20;
  997. function Increase_file_handle_count : boolean;
  998. var
  999. regs : trealregs;
  1000. begin
  1001. Inc(FileHandleCount,10);
  1002. regs.realebx:=FileHandleCount;
  1003. regs.realeax:=$6700;
  1004. sysrealintr($21,regs);
  1005. if (regs.realflags and carryflag) <> 0 then
  1006. begin
  1007. Increase_file_handle_count:=false;
  1008. Dec (FileHandleCount, 10);
  1009. end
  1010. else
  1011. Increase_file_handle_count:=true;
  1012. end;
  1013. procedure do_open(var f;p:pchar;flags:longint);
  1014. {
  1015. filerec and textrec have both handle and mode as the first items so
  1016. they could use the same routine for opening/creating.
  1017. when (flags and $100) the file will be append
  1018. when (flags and $1000) the file will be truncate/rewritten
  1019. when (flags and $10000) there is no check for close (needed for textfiles)
  1020. }
  1021. var
  1022. regs : trealregs;
  1023. action : longint;
  1024. begin
  1025. AllowSlash(p);
  1026. { close first if opened }
  1027. if ((flags and $10000)=0) then
  1028. begin
  1029. case filerec(f).mode of
  1030. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  1031. fmclosed : ;
  1032. else
  1033. begin
  1034. inoutres:=102; {not assigned}
  1035. exit;
  1036. end;
  1037. end;
  1038. end;
  1039. { reset file handle }
  1040. filerec(f).handle:=UnusedHandle;
  1041. action:=$1;
  1042. { convert filemode to filerec modes }
  1043. case (flags and 3) of
  1044. 0 : filerec(f).mode:=fminput;
  1045. 1 : filerec(f).mode:=fmoutput;
  1046. 2 : filerec(f).mode:=fminout;
  1047. end;
  1048. if (flags and $1000)<>0 then
  1049. action:=$12; {create file function}
  1050. { empty name is special }
  1051. if p[0]=#0 then
  1052. begin
  1053. case FileRec(f).mode of
  1054. fminput :
  1055. FileRec(f).Handle:=StdInputHandle;
  1056. fminout, { this is set by rewrite }
  1057. fmoutput :
  1058. FileRec(f).Handle:=StdOutputHandle;
  1059. fmappend :
  1060. begin
  1061. FileRec(f).Handle:=StdOutputHandle;
  1062. FileRec(f).mode:=fmoutput; {fool fmappend}
  1063. end;
  1064. end;
  1065. exit;
  1066. end;
  1067. { real dos call }
  1068. syscopytodos(longint(p),strlen(p)+1);
  1069. if LFNSupport then
  1070. regs.realeax:=$716c
  1071. else
  1072. regs.realeax:=$6c00;
  1073. regs.realedx:=action;
  1074. regs.realds:=tb_segment;
  1075. regs.realesi:=tb_offset;
  1076. regs.realebx:=$2000+(flags and $ff);
  1077. regs.realecx:=$20;
  1078. sysrealintr($21,regs);
  1079. if (regs.realflags and carryflag) <> 0 then
  1080. if lo(regs.realeax)=4 then
  1081. if Increase_file_handle_count then
  1082. begin
  1083. { Try again }
  1084. if LFNSupport then
  1085. regs.realeax:=$716c
  1086. else
  1087. regs.realeax:=$6c00;
  1088. regs.realedx:=action;
  1089. regs.realds:=tb_segment;
  1090. regs.realesi:=tb_offset;
  1091. regs.realebx:=$2000+(flags and $ff);
  1092. regs.realecx:=$20;
  1093. sysrealintr($21,regs);
  1094. end;
  1095. if (regs.realflags and carryflag) <> 0 then
  1096. begin
  1097. GetInOutRes(lo(regs.realeax));
  1098. exit;
  1099. end
  1100. else
  1101. begin
  1102. filerec(f).handle:=lo(regs.realeax);
  1103. { for systems that have more then 20 by default ! }
  1104. if lo(regs.realeax)>FileHandleCount then
  1105. FileHandleCount:=lo(regs.realeax);
  1106. end;
  1107. if lo(regs.realeax)<max_files then
  1108. begin
  1109. {$ifdef SYSTEMDEBUG}
  1110. if openfiles[lo(regs.realeax)] and
  1111. assigned(opennames[lo(regs.realeax)]) then
  1112. begin
  1113. Writeln(stderr,'file ',opennames[lo(regs.realeax)],'(',lo(regs.realeax),') not closed but handle reused!');
  1114. sysfreememsize(opennames[lo(regs.realeax)],strlen(opennames[lo(regs.realeax)])+1);
  1115. end;
  1116. {$endif SYSTEMDEBUG}
  1117. openfiles[lo(regs.realeax)]:=true;
  1118. {$ifdef SYSTEMDEBUG}
  1119. opennames[lo(regs.realeax)] := sysgetmem(strlen(p)+1);
  1120. move(p^,opennames[lo(regs.realeax)]^,strlen(p)+1);
  1121. {$endif SYSTEMDEBUG}
  1122. end;
  1123. { append mode }
  1124. if ((flags and $100) <> 0) and
  1125. (FileRec (F).Handle <> UnusedHandle) then
  1126. begin
  1127. do_seekend(filerec(f).handle);
  1128. filerec(f).mode:=fmoutput; {fool fmappend}
  1129. end;
  1130. end;
  1131. function do_isdevice(handle:longint):boolean;
  1132. var
  1133. regs : trealregs;
  1134. begin
  1135. regs.realebx:=handle;
  1136. regs.realeax:=$4400;
  1137. sysrealintr($21,regs);
  1138. do_isdevice:=(regs.realedx and $80)<>0;
  1139. if (regs.realflags and carryflag) <> 0 then
  1140. GetInOutRes(lo(regs.realeax));
  1141. end;
  1142. {*****************************************************************************
  1143. UnTyped File Handling
  1144. *****************************************************************************}
  1145. {$i file.inc}
  1146. {*****************************************************************************
  1147. Typed File Handling
  1148. *****************************************************************************}
  1149. {$i typefile.inc}
  1150. {*****************************************************************************
  1151. Text File Handling
  1152. *****************************************************************************}
  1153. {$DEFINE EOF_CTRLZ}
  1154. {$i text.inc}
  1155. {*****************************************************************************
  1156. Generic Handling
  1157. *****************************************************************************}
  1158. {$ifdef TEST_GENERIC}
  1159. {$i generic.inc}
  1160. {$endif TEST_GENERIC}
  1161. {*****************************************************************************
  1162. Directory Handling
  1163. *****************************************************************************}
  1164. procedure DosDir(func:byte;const s:string);
  1165. var
  1166. buffer : array[0..255] of char;
  1167. regs : trealregs;
  1168. begin
  1169. move(s[1],buffer,length(s));
  1170. buffer[length(s)]:=#0;
  1171. AllowSlash(pchar(@buffer));
  1172. { True DOS does not like backslashes at end
  1173. Win95 DOS accepts this !!
  1174. but "\" and "c:\" should still be kept and accepted hopefully PM }
  1175. if (length(s)>0) and (buffer[length(s)-1]='\') and
  1176. Not ((length(s)=1) or ((length(s)=3) and (s[2]=':'))) then
  1177. buffer[length(s)-1]:=#0;
  1178. syscopytodos(longint(@buffer),length(s)+1);
  1179. regs.realedx:=tb_offset;
  1180. regs.realds:=tb_segment;
  1181. if LFNSupport then
  1182. regs.realeax:=$7100+func
  1183. else
  1184. regs.realeax:=func shl 8;
  1185. sysrealintr($21,regs);
  1186. if (regs.realflags and carryflag) <> 0 then
  1187. GetInOutRes(lo(regs.realeax));
  1188. end;
  1189. procedure mkdir(const s : string);[IOCheck];
  1190. begin
  1191. If (s='') or (InOutRes <> 0) then
  1192. exit;
  1193. DosDir($39,s);
  1194. end;
  1195. procedure rmdir(const s : string);[IOCheck];
  1196. begin
  1197. if (s = '.' ) then
  1198. InOutRes := 16;
  1199. If (s='') or (InOutRes <> 0) then
  1200. exit;
  1201. DosDir($3a,s);
  1202. end;
  1203. procedure chdir(const s : string);[IOCheck];
  1204. var
  1205. regs : trealregs;
  1206. begin
  1207. If (s='') or (InOutRes <> 0) then
  1208. exit;
  1209. { First handle Drive changes }
  1210. if (length(s)>=2) and (s[2]=':') then
  1211. begin
  1212. regs.realedx:=(ord(s[1]) and (not 32))-ord('A');
  1213. regs.realeax:=$0e00;
  1214. sysrealintr($21,regs);
  1215. regs.realeax:=$1900;
  1216. sysrealintr($21,regs);
  1217. if byte(regs.realeax)<>byte(regs.realedx) then
  1218. begin
  1219. Inoutres:=15;
  1220. exit;
  1221. end;
  1222. { DosDir($3b,'c:') give Path not found error on
  1223. pure DOS PM }
  1224. if length(s)=2 then
  1225. exit;
  1226. end;
  1227. { do the normal dos chdir }
  1228. DosDir($3b,s);
  1229. end;
  1230. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  1231. var
  1232. temp : array[0..255] of char;
  1233. i : longint;
  1234. regs : trealregs;
  1235. begin
  1236. regs.realedx:=drivenr;
  1237. regs.realesi:=tb_offset;
  1238. regs.realds:=tb_segment;
  1239. if LFNSupport then
  1240. regs.realeax:=$7147
  1241. else
  1242. regs.realeax:=$4700;
  1243. sysrealintr($21,regs);
  1244. if (regs.realflags and carryflag) <> 0 then
  1245. Begin
  1246. GetInOutRes (lo(regs.realeax));
  1247. Dir := char (DriveNr + 64) + ':\';
  1248. exit;
  1249. end
  1250. else
  1251. syscopyfromdos(longint(@temp),251);
  1252. { conversion to Pascal string including slash conversion }
  1253. i:=0;
  1254. while (temp[i]<>#0) do
  1255. begin
  1256. if temp[i]='/' then
  1257. temp[i]:='\';
  1258. dir[i+4]:=temp[i];
  1259. inc(i);
  1260. end;
  1261. dir[2]:=':';
  1262. dir[3]:='\';
  1263. dir[0]:=char(i+3);
  1264. { upcase the string }
  1265. if not FileNameCaseSensitive then
  1266. dir:=upcase(dir);
  1267. if drivenr<>0 then { Drive was supplied. We know it }
  1268. dir[1]:=char(65+drivenr-1)
  1269. else
  1270. begin
  1271. { We need to get the current drive from DOS function 19H }
  1272. { because the drive was the default, which can be unknown }
  1273. regs.realeax:=$1900;
  1274. sysrealintr($21,regs);
  1275. i:= (regs.realeax and $ff) + ord('A');
  1276. dir[1]:=chr(i);
  1277. end;
  1278. end;
  1279. {*****************************************************************************
  1280. SystemUnit Initialization
  1281. *****************************************************************************}
  1282. function CheckLFN:boolean;
  1283. var
  1284. regs : TRealRegs;
  1285. RootName : pchar;
  1286. begin
  1287. { Check LFN API on drive c:\ }
  1288. RootName:='C:\';
  1289. syscopytodos(longint(RootName),strlen(RootName)+1);
  1290. { Call 'Get Volume Information' ($71A0) }
  1291. regs.realeax:=$71a0;
  1292. regs.reales:=tb_segment;
  1293. regs.realedi:=tb_offset;
  1294. regs.realecx:=32;
  1295. regs.realds:=tb_segment;
  1296. regs.realedx:=tb_offset;
  1297. regs.realflags:=carryflag;
  1298. sysrealintr($21,regs);
  1299. { If carryflag=0 and LFN API bit in ebx is set then use Long file names }
  1300. CheckLFN:=(regs.realflags and carryflag=0) and (regs.realebx and $4000=$4000);
  1301. end;
  1302. {$ifdef EXCEPTIONS_IN_SYSTEM}
  1303. {$define IN_SYSTEM}
  1304. {$i dpmiexcp.pp}
  1305. {$endif EXCEPTIONS_IN_SYSTEM}
  1306. procedure SysInitStdIO;
  1307. begin
  1308. OpenStdIO(Input,fmInput,StdInputHandle);
  1309. OpenStdIO(Output,fmOutput,StdOutputHandle);
  1310. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  1311. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  1312. end;
  1313. var
  1314. temp_int : tseginfo;
  1315. Begin
  1316. StackLength := InitialStkLen;
  1317. StackBottom := __stkbottom;
  1318. { To be set if this is a GUI or console application }
  1319. IsConsole := TRUE;
  1320. { To be set if this is a library and not a program }
  1321. IsLibrary := FALSE;
  1322. { save old int 0 and 75 }
  1323. get_pm_interrupt($00,old_int00);
  1324. get_pm_interrupt($75,old_int75);
  1325. temp_int.segment:=get_cs;
  1326. temp_int.offset:=@new_int00;
  1327. set_pm_interrupt($00,temp_int);
  1328. {$ifndef EXCEPTIONS_IN_SYSTEM}
  1329. temp_int.offset:=@new_int75;
  1330. set_pm_interrupt($75,temp_int);
  1331. {$endif EXCEPTIONS_IN_SYSTEM}
  1332. { Setup heap }
  1333. InitHeap;
  1334. SysInitExceptions;
  1335. { Setup stdin, stdout and stderr }
  1336. SysInitStdIO;
  1337. { Setup environment and arguments }
  1338. Setup_Environment;
  1339. Setup_Arguments;
  1340. { Use LFNSupport LFN }
  1341. LFNSupport:=CheckLFN;
  1342. if LFNSupport then
  1343. FileNameCaseSensitive:=true;
  1344. { Reset IO Error }
  1345. InOutRes:=0;
  1346. {$ifdef EXCEPTIONS_IN_SYSTEM}
  1347. InitDPMIExcp;
  1348. InstallDefaultHandlers;
  1349. {$endif EXCEPTIONS_IN_SYSTEM}
  1350. {$ifdef HASVARIANT}
  1351. initvariantmanager;
  1352. {$endif HASVARIANT}
  1353. End.
  1354. {
  1355. $Log$
  1356. Revision 1.28 2003-11-03 09:42:27 marco
  1357. * Peter's Cardinal<->Longint fixes patch
  1358. Revision 1.27 2003/10/16 15:43:13 peter
  1359. * THandle is platform dependent
  1360. Revision 1.26 2003/10/03 21:46:25 peter
  1361. * stdcall fixes
  1362. Revision 1.25 2003/09/29 18:39:59 hajny
  1363. * append fix applied to GO32v2, OS/2 and EMX
  1364. Revision 1.24 2003/09/27 11:52:35 peter
  1365. * sbrk returns pointer
  1366. Revision 1.23 2002/10/14 19:39:16 peter
  1367. * threads unit added for thread support
  1368. Revision 1.22 2002/10/13 09:28:44 florian
  1369. + call to initvariantmanager inserted
  1370. Revision 1.21 2002/09/07 21:32:08 carl
  1371. - removed unused defines
  1372. Revision 1.20 2002/09/07 16:01:19 peter
  1373. * old logs removed and tabs fixed
  1374. Revision 1.19 2002/07/01 16:29:05 peter
  1375. * sLineBreak changed to normal constant like Kylix
  1376. Revision 1.18 2002/05/05 10:23:54 peter
  1377. * fixed memw and meml array sizes
  1378. Revision 1.17 2002/04/21 15:52:58 carl
  1379. + initialize some global variables
  1380. Revision 1.16 2002/04/12 17:34:05 carl
  1381. + generic stack checking
  1382. Revision 1.15 2002/03/11 19:10:33 peter
  1383. * Regenerated with updated fpcmake
  1384. }