systems.pas 24 KB

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