systems.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains information about the target systems supported
  4. (these are not processor specific)
  5. This program is free software; you can redistribute it and/or modify
  6. iu under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge- MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit systems;
  19. {$i fpcdefs.inc}
  20. interface
  21. type
  22. tendian = (endian_little,endian_big);
  23. (*
  24. IMPORTANT NOTE:
  25. The value of this enumeration is stored in PPU files.
  26. Therefore adding new CPU targets should not change the
  27. values of the pre-existing targets. (CEC)
  28. FURTHERMORE : Make sure that this branch values, are
  29. consistant with the main branch version always.
  30. *)
  31. tsystemcpu=
  32. (
  33. cpu_no, { 0 }
  34. cpu_i386, { 1 }
  35. cpu_m68k, { 2 }
  36. cpu_alpha, { 3 }
  37. cpu_powerpc, { 4 }
  38. cpu_sparc, { 5 }
  39. cpu_vm, { 6 }
  40. cpu_iA64, { 7 }
  41. cpu_x86_64, { 8 }
  42. cpu_mips, { 9 }
  43. cpu_arm, { 10 }
  44. cpu_powerpc64 { 11 }
  45. );
  46. tasmmode= (asmmode_none
  47. { standard assembler (cpu dependant) with full parsing }
  48. ,asmmode_standard
  49. ,asmmode_i386_att
  50. ,asmmode_i386_intel
  51. ,asmmode_ppc_gas
  52. ,asmmode_ppc_motorola
  53. ,asmmode_arm_gas
  54. ,asmmode_sparc_gas
  55. ,asmmode_x86_64_gas
  56. ,asmmode_m68k_mot
  57. ,asmmode_x86_64_intel
  58. );
  59. (* IMPORTANT NOTE:
  60. the integer value of this enum is stored in PPU
  61. files to recognize the target, so if you add new targets
  62. allways add them at end PM
  63. FURTHERMORE : Make sure that this branch values are
  64. consistant with the main branch version always. (CEC)
  65. *)
  66. type
  67. tsystem =
  68. (
  69. system_none, { 0 }
  70. obsolete_system_i386_GO32V1,{ 1 }
  71. system_i386_GO32V2, { 2 }
  72. system_i386_linux, { 3 }
  73. system_i386_OS2, { 4 }
  74. system_i386_Win32, { 5 }
  75. system_i386_freebsd, { 6 }
  76. system_m68k_Amiga, { 7 }
  77. system_m68k_Atari, { 8 }
  78. system_m68k_Mac, { 9 }
  79. system_m68k_linux, { 10 }
  80. system_m68k_PalmOS, { 11 }
  81. system_alpha_linux, { 12 }
  82. system_powerpc_linux, { 13 }
  83. system_powerpc_macos, { 14 }
  84. system_i386_solaris, { 15 }
  85. system_i386_beos, { 16 }
  86. system_i386_netbsd, { 17 }
  87. system_m68k_netbsd, { 18 }
  88. system_i386_Netware, { 19 }
  89. system_i386_qnx, { 20 }
  90. system_i386_wdosx, { 21 }
  91. system_sparc_solaris, { 22 }
  92. system_sparc_linux, { 23 }
  93. system_i386_openbsd, { 24 }
  94. system_m68k_openbsd, { 25 }
  95. system_x86_64_linux, { 26 }
  96. system_powerpc_darwin, { 27 }
  97. system_i386_EMX, { 28 }
  98. system_powerpc_netbsd, { 29 }
  99. system_powerpc_openbsd, { 30 }
  100. system_arm_linux, { 31 }
  101. system_i386_watcom, { 32 }
  102. system_powerpc_MorphOS, { 33 }
  103. system_x86_64_freebsd, { 34 }
  104. system_i386_netwlibc, { 35 }
  105. system_powerpc_Amiga, { 36 }
  106. system_x86_64_win64, { 37 }
  107. system_arm_wince, { 38 }
  108. system_ia64_win64, { 39 }
  109. system_i386_wince, { 40 }
  110. system_x86_6432_linux, { 41 }
  111. system_arm_gba, { 42 }
  112. system_powerpc64_linux, { 43 }
  113. system_i386_darwin, { 44 }
  114. system_arm_palmos { 45 }
  115. );
  116. tasm = (as_none
  117. ,as_gas { standard gnu assembler }
  118. ,as_i386_as_aout
  119. ,as_i386_nasmcoff
  120. ,as_i386_nasmwin32
  121. ,as_i386_nasmwdosx
  122. ,as_i386_nasmelf
  123. ,as_i386_nasmobj
  124. ,as_i386_nasmbeos
  125. ,as_i386_tasm
  126. ,as_i386_masm
  127. ,as_i386_wasm
  128. ,as_i386_coff
  129. ,as_i386_pecoff
  130. ,as_i386_elf32
  131. ,as_i386_pecoffwdosx
  132. ,as_m68k_mit
  133. ,as_powerpc_mpw
  134. ,as_darwin
  135. ,as_x86_64_masm
  136. ,as_x86_64_pecoff
  137. ,as_i386_pecoffwince
  138. ,as_arm_pecoffwince
  139. ,as_x86_64_elf64
  140. ,as_sparc_elf32
  141. ,as_ggas { gnu assembler called "gas" instead of "as" }
  142. );
  143. tar = (ar_none
  144. ,ar_gnu_ar
  145. ,ar_mpw_ar
  146. ,ar_gnu_ar_scripted
  147. ,ar_gnu_gar
  148. );
  149. tres = (res_none
  150. ,res_gnu_windres,res_emxbind
  151. ,res_m68k_palmos,res_m68k_mpw
  152. ,res_powerpc_mpw,res_elf
  153. ,res_gnu_wince_windres
  154. );
  155. tdbg = (dbg_none
  156. ,dbg_stabs,dbg_dwarf2,dbg_dwarf3
  157. );
  158. tscripttype = (script_none
  159. ,script_dos,script_unix,script_amiga,
  160. script_mpw
  161. );
  162. tabi = (abi_default
  163. ,abi_powerpc_sysv,abi_powerpc_aix
  164. );
  165. {*****************************************************************************
  166. Structures
  167. *****************************************************************************}
  168. type
  169. { Abstract linker class which is implemented in link module }
  170. TAbstractLinker = class
  171. end;
  172. TAbstractLinkerClass = class of TAbstractLinker;
  173. { Abstract assembler class which is implemented in assemble module }
  174. TAbstractAssembler = class
  175. end;
  176. TAbstractAssemblerClass = class of TAbstractAssembler;
  177. palignmentinfo = ^talignmentinfo;
  178. talignmentinfo = record
  179. procalign,
  180. loopalign,
  181. jumpalign,
  182. constalignmin,
  183. constalignmax,
  184. varalignmin,
  185. varalignmax,
  186. localalignmin,
  187. localalignmax,
  188. recordalignmin,
  189. recordalignmax,
  190. maxCrecordalign : longint;
  191. end;
  192. tasmflags = (af_none,
  193. af_outputbinary,af_allowdirect,
  194. af_needar,af_smartlink_sections,
  195. af_labelprefix_only_inside_procedure,
  196. af_supports_dwarf
  197. );
  198. pasminfo = ^tasminfo;
  199. tasminfo = record
  200. id : tasm;
  201. idtxt : string[12];
  202. asmbin : string[8];
  203. asmcmd : string[50];
  204. supported_target : tsystem;
  205. flags : set of tasmflags;
  206. labelprefix : string[3];
  207. comment : string[3];
  208. end;
  209. parinfo = ^tarinfo;
  210. tarinfo = record
  211. id : tar;
  212. arcmd : string[50];
  213. arfinishcmd : string[10];
  214. end;
  215. presinfo = ^tresinfo;
  216. tresinfo = record
  217. id : tres;
  218. resbin : string[8];
  219. rescmd : string[50];
  220. end;
  221. pdbginfo = ^tdbginfo;
  222. tdbginfo = record
  223. id : tdbg;
  224. idtxt : string[12];
  225. end;
  226. tsystemflags = (tf_none,
  227. tf_under_development,
  228. tf_need_export,
  229. tf_needs_isconsole,
  230. tf_code_small,
  231. tf_static_reg_based,
  232. tf_needs_symbol_size,
  233. tf_smartlink_sections,
  234. tf_needs_dwarf_cfi,
  235. tf_use_8_3,
  236. tf_pic_uses_got,
  237. tf_library_needs_pic,
  238. tf_needs_symbol_type,
  239. tf_section_threadvars,
  240. tf_files_case_sensitive,
  241. tf_files_case_aware,
  242. tf_p_ext_support,
  243. tf_has_dllscanner,
  244. tf_use_function_relative_addresses,
  245. tf_winlikewidestring
  246. );
  247. psysteminfo = ^tsysteminfo;
  248. { using packed causes bus errors on processors which require alignment }
  249. tsysteminfo = record
  250. system : tsystem;
  251. name : string[34];
  252. shortname : string[9];
  253. flags : set of tsystemflags;
  254. cpu : tsystemcpu;
  255. unit_env : string[16];
  256. extradefines : string[40];
  257. exeext,
  258. defext,
  259. scriptext,
  260. smartext,
  261. unitext,
  262. unitlibext,
  263. asmext,
  264. objext,
  265. resext,
  266. resobjext : string[4];
  267. sharedlibext : string[10];
  268. staticlibext,
  269. staticlibprefix : string[4];
  270. sharedlibprefix : string[4];
  271. sharedClibext : string[10];
  272. staticClibext,
  273. staticClibprefix : string[4];
  274. sharedClibprefix : string[4];
  275. Cprefix : string[2];
  276. newline : string[2];
  277. dirsep : char;
  278. assem : tasm;
  279. assemextern : tasm; { external assembler, used by -a }
  280. link : tabstractlinkerclass;
  281. linkextern : tabstractlinkerclass; { external linker, used by -s }
  282. ar : tar;
  283. res : tres;
  284. dbg : tdbg;
  285. script : tscripttype;
  286. endian : tendian;
  287. alignment : talignmentinfo;
  288. {
  289. Offset from the argument pointer register to the first
  290. argument's address. On some machines it may depend on
  291. the data type of the function.
  292. (see also FIRST_PARM_OFFSET in GCC source)
  293. }
  294. first_parm_offset : longint;
  295. stacksize : longint;
  296. abi : tabi;
  297. end;
  298. const
  299. { alias for supported_target field in tasminfo }
  300. system_any = system_none;
  301. system_wince : set of tsystem = [system_arm_wince,system_i386_wince];
  302. system_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,
  303. system_arm_linux,system_sparc_linux,system_alpha_linux,system_m68k_linux,
  304. system_x86_6432_linux];
  305. { all real windows systems, no cripple ones like wince, wdosx et. al. }
  306. system_windows : set of tsystem = [system_i386_win32,system_x86_64_win64,system_ia64_win64];
  307. { all windows systems }
  308. system_all_windows : set of tsystem = [system_i386_win32,system_x86_64_win64,system_ia64_win64,
  309. system_arm_wince,system_i386_wince];
  310. { all systems supporting exports from programs or units }
  311. system_unit_program_exports : set of tsystem = [system_i386_win32,
  312. system_i386_wdosx,
  313. system_i386_Netware,
  314. system_i386_netwlibc,
  315. system_arm_wince,
  316. system_x86_64_win64,
  317. system_ia64_win64]+system_linux;
  318. cpu2str : array[TSystemCpu] of string =
  319. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  320. 'mips','arm', 'powerpc64');
  321. var
  322. targetinfos : array[tsystem] of psysteminfo;
  323. arinfos : array[tar] of parinfo;
  324. resinfos : array[tres] of presinfo;
  325. asminfos : array[tasm] of pasminfo;
  326. dbginfos : array[tdbg] of pdbginfo;
  327. source_info : tsysteminfo;
  328. target_cpu : tsystemcpu;
  329. target_info : tsysteminfo;
  330. target_asm : tasminfo;
  331. target_ar : tarinfo;
  332. target_res : tresinfo;
  333. target_dbg : tdbginfo;
  334. target_cpu_string,
  335. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  336. target_full_string : string[24];
  337. function set_target(t:tsystem):boolean;
  338. function set_target_asm(t:tasm):boolean;
  339. function set_target_ar(t:tar):boolean;
  340. function set_target_res(t:tres):boolean;
  341. function set_target_dbg(t:tdbg):boolean;
  342. function find_system_by_string(const s : string) : tsystem;
  343. function find_asm_by_string(const s : string) : tasm;
  344. function find_dbg_by_string(const s : string) : tdbg;
  345. procedure set_source_info(const ti : tsysteminfo);
  346. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  347. procedure RegisterTarget(const r:tsysteminfo);
  348. procedure RegisterRes(const r:tresinfo);
  349. procedure RegisterAr(const r:tarinfo);
  350. { Register the external linker. This routine is called to setup the
  351. class to use for the linker. It returns the tsysteminfo structure
  352. updated with the correct linker class for external linking.
  353. }
  354. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  355. { Register the internal linker. This routine is called to setup the
  356. class to use for the linker. It returns the tsysteminfo structure
  357. updated with the correct linker class for internal linking.
  358. If internal linking is not supported, this class can be set
  359. to nil.
  360. }
  361. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  362. procedure InitSystems;
  363. {$ifdef FreeBSD}
  364. function GetOSRelDate:Longint;
  365. {$endif}
  366. implementation
  367. uses
  368. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  369. {****************************************************************************
  370. OS runtime version detection utility routine
  371. ****************************************************************************}
  372. {$ifdef FreeBSD}
  373. function GetOSRelDate:Longint;
  374. var
  375. mib : array[0..1] of cint;
  376. rval : cint;
  377. len : size_t;
  378. i : longint;
  379. v : longint;
  380. oerrno : cint;
  381. S : AnsiString;
  382. Begin
  383. s:='ab';
  384. SetLength(S,50);
  385. mib[0] := CTL_KERN;
  386. mib[1] := KERN_OSRELDATE;
  387. len := 4;
  388. oerrno:= fpgeterrno;
  389. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  390. Begin
  391. if (fpgeterrno = ESysENOMEM) Then
  392. fpseterrno(oerrno);
  393. GetOSRelDate:=0;
  394. End
  395. else
  396. GetOSRelDate:=v;
  397. End;
  398. {$endif}
  399. {****************************************************************************
  400. Target setting
  401. ****************************************************************************}
  402. function set_target(t:tsystem):boolean;
  403. begin
  404. set_target:=false;
  405. if assigned(targetinfos[t]) then
  406. begin
  407. target_info:=targetinfos[t]^;
  408. set_target_asm(target_info.assem);
  409. set_target_ar(target_info.ar);
  410. set_target_res(target_info.res);
  411. set_target_dbg(target_info.dbg);
  412. target_cpu:=target_info.cpu;
  413. target_os_string:=lower(target_info.shortname);
  414. target_cpu_string:=cpu2str[target_cpu];
  415. target_full_string:=target_cpu_string+'-'+target_os_string;
  416. set_target:=true;
  417. exit;
  418. end;
  419. end;
  420. function set_target_asm(t:tasm):boolean;
  421. begin
  422. set_target_asm:=false;
  423. if assigned(asminfos[t]) and
  424. ((asminfos[t]^.supported_target=target_info.system) or
  425. (asminfos[t]^.supported_target=system_any)) then
  426. begin
  427. target_asm:=asminfos[t]^;
  428. set_target_asm:=true;
  429. exit;
  430. end;
  431. end;
  432. function set_target_ar(t:tar):boolean;
  433. begin
  434. result:=false;
  435. if assigned(arinfos[t]) then
  436. begin
  437. target_ar:=arinfos[t]^;
  438. result:=true;
  439. exit;
  440. end;
  441. end;
  442. function set_target_res(t:tres):boolean;
  443. begin
  444. result:=false;
  445. if assigned(resinfos[t]) then
  446. begin
  447. target_res:=resinfos[t]^;
  448. result:=true;
  449. exit;
  450. end;
  451. end;
  452. function set_target_dbg(t:tdbg):boolean;
  453. begin
  454. result:=false;
  455. if assigned(dbginfos[t]) then
  456. begin
  457. target_dbg:=dbginfos[t]^;
  458. result:=true;
  459. exit;
  460. end;
  461. end;
  462. function find_system_by_string(const s : string) : tsystem;
  463. var
  464. hs : string;
  465. t : tsystem;
  466. begin
  467. result:=system_none;
  468. hs:=upper(s);
  469. for t:=low(tsystem) to high(tsystem) do
  470. if assigned(targetinfos[t]) and
  471. (upper(targetinfos[t]^.shortname)=hs) then
  472. begin
  473. result:=t;
  474. exit;
  475. end;
  476. end;
  477. function find_asm_by_string(const s : string) : tasm;
  478. var
  479. hs : string;
  480. t : tasm;
  481. begin
  482. result:=as_none;
  483. hs:=upper(s);
  484. for t:=low(tasm) to high(tasm) do
  485. if assigned(asminfos[t]) and
  486. (asminfos[t]^.idtxt=hs) then
  487. begin
  488. result:=t;
  489. exit;
  490. end;
  491. end;
  492. function find_dbg_by_string(const s : string) : tdbg;
  493. var
  494. hs : string;
  495. t : tdbg;
  496. begin
  497. result:=dbg_none;
  498. hs:=upper(s);
  499. for t:=low(tdbg) to high(tdbg) do
  500. if assigned(dbginfos[t]) and
  501. (dbginfos[t]^.idtxt=hs) then
  502. begin
  503. result:=t;
  504. exit;
  505. end;
  506. end;
  507. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  508. begin
  509. with d do
  510. begin
  511. { general update rules:
  512. minimum: if higher then update
  513. maximum: if lower then update or if undefined then update }
  514. if s.procalign>procalign then
  515. procalign:=s.procalign;
  516. if s.loopalign>loopalign then
  517. loopalign:=s.loopalign;
  518. if s.jumpalign>jumpalign then
  519. jumpalign:=s.jumpalign;
  520. if s.constalignmin>constalignmin then
  521. constalignmin:=s.constalignmin;
  522. if (constalignmax=0) or
  523. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  524. constalignmax:=s.constalignmax;
  525. if s.varalignmin>varalignmin then
  526. varalignmin:=s.varalignmin;
  527. if (varalignmax=0) or
  528. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  529. varalignmax:=s.varalignmax;
  530. if s.localalignmin>localalignmin then
  531. localalignmin:=s.localalignmin;
  532. if (localalignmax=0) or
  533. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  534. localalignmax:=s.localalignmax;
  535. if s.recordalignmin>recordalignmin then
  536. recordalignmin:=s.recordalignmin;
  537. if (recordalignmax=0) or
  538. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  539. recordalignmax:=s.recordalignmax;
  540. if (maxCrecordalign=0) or
  541. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  542. maxCrecordalign:=s.maxCrecordalign;
  543. end;
  544. end;
  545. {****************************************************************************
  546. Target registration
  547. ****************************************************************************}
  548. procedure RegisterTarget(const r:tsysteminfo);
  549. var
  550. t : tsystem;
  551. begin
  552. t:=r.system;
  553. if assigned(targetinfos[t]) then
  554. writeln('Warning: Target is already registered!')
  555. else
  556. Getmem(targetinfos[t],sizeof(tsysteminfo));
  557. targetinfos[t]^:=r;
  558. end;
  559. procedure RegisterRes(const r:tresinfo);
  560. var
  561. t : tres;
  562. begin
  563. t:=r.id;
  564. if assigned(resinfos[t]) then
  565. writeln('Warning: resourcecompiler is already registered!')
  566. else
  567. Getmem(resinfos[t],sizeof(tresinfo));
  568. resinfos[t]^:=r;
  569. end;
  570. procedure RegisterAr(const r:tarinfo);
  571. var
  572. t : tar;
  573. begin
  574. t:=r.id;
  575. if assigned(arinfos[t]) then
  576. writeln('Warning: ar is already registered!')
  577. else
  578. Getmem(arinfos[t],sizeof(tarinfo));
  579. arinfos[t]^:=r;
  580. end;
  581. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  582. begin
  583. system_info.linkextern := c;
  584. end;
  585. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  586. begin
  587. system_info.link := c;
  588. end;
  589. procedure DeregisterInfos;
  590. var
  591. assem : tasm;
  592. target : tsystem;
  593. ar : tar;
  594. res : tres;
  595. dbg : tdbg;
  596. begin
  597. for target:=low(tsystem) to high(tsystem) do
  598. if assigned(targetinfos[target]) then
  599. begin
  600. freemem(targetinfos[target],sizeof(tsysteminfo));
  601. targetinfos[target]:=nil;
  602. end;
  603. for assem:=low(tasm) to high(tasm) do
  604. if assigned(asminfos[assem]) then
  605. begin
  606. freemem(asminfos[assem],sizeof(tasminfo));
  607. asminfos[assem]:=nil;
  608. end;
  609. for ar:=low(tar) to high(tar) do
  610. if assigned(arinfos[ar]) then
  611. begin
  612. freemem(arinfos[ar],sizeof(tarinfo));
  613. arinfos[ar]:=nil;
  614. end;
  615. for res:=low(tres) to high(tres) do
  616. if assigned(resinfos[res]) then
  617. begin
  618. freemem(resinfos[res],sizeof(tresinfo));
  619. resinfos[res]:=nil;
  620. end;
  621. for dbg:=low(tdbg) to high(tdbg) do
  622. if assigned(dbginfos[dbg]) then
  623. begin
  624. freemem(dbginfos[dbg],sizeof(tdbginfo));
  625. dbginfos[dbg]:=nil;
  626. end;
  627. end;
  628. {****************************************************************************
  629. Initialization of default target
  630. ****************************************************************************}
  631. procedure default_target(t:tsystem);
  632. begin
  633. set_target(t);
  634. if source_info.name='' then
  635. source_info:=target_info;
  636. end;
  637. procedure set_source_info(const ti : tsysteminfo);
  638. begin
  639. { can't use message() here (PFV) }
  640. if source_info.name<>'' then
  641. Writeln('Warning: Source OS Redefined!');
  642. source_info:=ti;
  643. end;
  644. procedure InitSystems;
  645. begin
  646. { Now default target, this is dependent on the target cpu define,
  647. when the define is the same as the source cpu then we use the source
  648. os, else we pick a default }
  649. {$ifdef i386}
  650. {$ifdef cpu86}
  651. default_target(source_info.system);
  652. {$else cpu86}
  653. {$ifdef linux}
  654. default_target(system_i386_linux);
  655. {$endif}
  656. {$ifdef freebsd}
  657. default_target(system_i386_freebsd);
  658. {$endif}
  659. {$ifdef darwin}
  660. default_target(system_i386_darwin);
  661. {$endif}
  662. {$endif cpu86}
  663. {$endif i386}
  664. {$ifdef x86_64}
  665. {$ifdef cpux86_64}
  666. default_target(source_info.system);
  667. {$define source_system_set}
  668. {$else cpux86_64}
  669. {$ifdef MSWindows}
  670. default_target(system_x86_64_win64);
  671. {$define source_system_set}
  672. {$endif}
  673. {$ifdef linux}
  674. default_target(system_x86_64_linux);
  675. {$define source_system_set}
  676. {$endif}
  677. {$ifdef freebsd}
  678. default_target(system_x86_64_freebsd);
  679. {$define source_system_set}
  680. {$endif}
  681. { default is linux }
  682. {$ifndef source_system_set}
  683. default_target(system_x86_64_linux);
  684. {$endif source_system_set}
  685. {$endif cpux86_64}
  686. {$endif x86_64}
  687. {$ifdef m68k}
  688. {$ifdef cpu68}
  689. default_target(source_info.target);
  690. {$else cpu68}
  691. default_target(system_m68k_linux);
  692. {$endif cpu68}
  693. {$endif m68k}
  694. {$ifdef alpha}
  695. {$ifdef cpualpha}
  696. default_target(source_info.system);
  697. {$else cpualpha}
  698. default_target(system_alpha_linux);
  699. {$endif cpualpha}
  700. {$endif alpha}
  701. {$ifdef powerpc}
  702. {$ifdef cpupowerpc}
  703. default_target(source_info.system);
  704. {$else cpupowerpc}
  705. {$ifdef linux}
  706. default_target(system_powerpc_linux);
  707. {$endif}
  708. {$ifdef darwin}
  709. default_target(system_powerpc_darwin);
  710. {$endif}
  711. {$endif cpupowerpc}
  712. {$endif powerpc}
  713. {$ifdef POWERPC64}
  714. {$ifdef cpupowerpc64}
  715. default_target(source_info.system);
  716. {$else cpupowerpc64}
  717. default_target(system_powerpc64_linux);
  718. {$endif cpupowerpc64}
  719. {$endif POWERPC64}
  720. {$ifdef sparc}
  721. {$ifdef cpusparc}
  722. default_target(source_info.system);
  723. {$else cpusparc}
  724. default_target(system_sparc_linux);
  725. {$endif cpusparc}
  726. {$endif sparc}
  727. {$ifdef arm}
  728. {$ifdef cpuarm}
  729. default_target(source_info.system);
  730. {$else cpuarm}
  731. default_target(system_arm_linux);
  732. {$endif cpuarm}
  733. {$endif arm}
  734. end;
  735. initialization
  736. source_info.name:='';
  737. finalization
  738. DeregisterInfos;
  739. end.