systems.pas 24 KB

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