systems.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 = [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 = [system_i386_win32,system_x86_64_win64,system_ia64_win64];
  308. { all windows systems }
  309. system_all_windows = [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 = [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. systems_internal_sysinit = [system_i386_linux,system_i386_win32];
  320. cpu2str : array[TSystemCpu] of string =
  321. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  322. 'mips','arm', 'powerpc64');
  323. var
  324. targetinfos : array[tsystem] of psysteminfo;
  325. arinfos : array[tar] of parinfo;
  326. resinfos : array[tres] of presinfo;
  327. asminfos : array[tasm] of pasminfo;
  328. dbginfos : array[tdbg] of pdbginfo;
  329. source_info : tsysteminfo;
  330. target_cpu : tsystemcpu;
  331. target_info : tsysteminfo;
  332. target_asm : tasminfo;
  333. target_ar : tarinfo;
  334. target_res : tresinfo;
  335. target_dbg : tdbginfo;
  336. target_cpu_string,
  337. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  338. target_full_string : string[24];
  339. function set_target(t:tsystem):boolean;
  340. function set_target_asm(t:tasm):boolean;
  341. function set_target_ar(t:tar):boolean;
  342. function set_target_res(t:tres):boolean;
  343. function set_target_dbg(t:tdbg):boolean;
  344. function find_system_by_string(const s : string) : tsystem;
  345. function find_asm_by_string(const s : string) : tasm;
  346. function find_dbg_by_string(const s : string) : tdbg;
  347. procedure set_source_info(const ti : tsysteminfo);
  348. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  349. procedure RegisterTarget(const r:tsysteminfo);
  350. procedure RegisterRes(const r:tresinfo);
  351. procedure RegisterAr(const r:tarinfo);
  352. { Register the external linker. This routine is called to setup the
  353. class to use for the linker. It returns the tsysteminfo structure
  354. updated with the correct linker class for external linking.
  355. }
  356. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  357. { Register the internal linker. This routine is called to setup the
  358. class to use for the linker. It returns the tsysteminfo structure
  359. updated with the correct linker class for internal linking.
  360. If internal linking is not supported, this class can be set
  361. to nil.
  362. }
  363. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  364. procedure InitSystems;
  365. {$ifdef FreeBSD}
  366. function GetOSRelDate:Longint;
  367. {$endif}
  368. implementation
  369. uses
  370. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  371. {****************************************************************************
  372. OS runtime version detection utility routine
  373. ****************************************************************************}
  374. {$ifdef FreeBSD}
  375. function GetOSRelDate:Longint;
  376. var
  377. mib : array[0..1] of cint;
  378. rval : cint;
  379. len : size_t;
  380. i : longint;
  381. v : longint;
  382. oerrno : cint;
  383. S : AnsiString;
  384. Begin
  385. s:='ab';
  386. SetLength(S,50);
  387. mib[0] := CTL_KERN;
  388. mib[1] := KERN_OSRELDATE;
  389. len := 4;
  390. oerrno:= fpgeterrno;
  391. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  392. Begin
  393. if (fpgeterrno = ESysENOMEM) Then
  394. fpseterrno(oerrno);
  395. GetOSRelDate:=0;
  396. End
  397. else
  398. GetOSRelDate:=v;
  399. End;
  400. {$endif}
  401. {****************************************************************************
  402. Target setting
  403. ****************************************************************************}
  404. function set_target(t:tsystem):boolean;
  405. begin
  406. set_target:=false;
  407. if assigned(targetinfos[t]) then
  408. begin
  409. target_info:=targetinfos[t]^;
  410. set_target_asm(target_info.assem);
  411. set_target_ar(target_info.ar);
  412. set_target_res(target_info.res);
  413. set_target_dbg(target_info.dbg);
  414. target_cpu:=target_info.cpu;
  415. target_os_string:=lower(target_info.shortname);
  416. target_cpu_string:=cpu2str[target_cpu];
  417. target_full_string:=target_cpu_string+'-'+target_os_string;
  418. set_target:=true;
  419. exit;
  420. end;
  421. end;
  422. function set_target_asm(t:tasm):boolean;
  423. begin
  424. set_target_asm:=false;
  425. if assigned(asminfos[t]) and
  426. ((asminfos[t]^.supported_target=target_info.system) or
  427. (asminfos[t]^.supported_target=system_any)) then
  428. begin
  429. target_asm:=asminfos[t]^;
  430. set_target_asm:=true;
  431. exit;
  432. end;
  433. end;
  434. function set_target_ar(t:tar):boolean;
  435. begin
  436. result:=false;
  437. if assigned(arinfos[t]) then
  438. begin
  439. target_ar:=arinfos[t]^;
  440. result:=true;
  441. exit;
  442. end;
  443. end;
  444. function set_target_res(t:tres):boolean;
  445. begin
  446. result:=false;
  447. if assigned(resinfos[t]) then
  448. begin
  449. target_res:=resinfos[t]^;
  450. result:=true;
  451. exit;
  452. end;
  453. end;
  454. function set_target_dbg(t:tdbg):boolean;
  455. begin
  456. result:=false;
  457. if assigned(dbginfos[t]) then
  458. begin
  459. target_dbg:=dbginfos[t]^;
  460. result:=true;
  461. exit;
  462. end;
  463. end;
  464. function find_system_by_string(const s : string) : tsystem;
  465. var
  466. hs : string;
  467. t : tsystem;
  468. begin
  469. result:=system_none;
  470. hs:=upper(s);
  471. for t:=low(tsystem) to high(tsystem) do
  472. if assigned(targetinfos[t]) and
  473. (upper(targetinfos[t]^.shortname)=hs) then
  474. begin
  475. result:=t;
  476. exit;
  477. end;
  478. end;
  479. function find_asm_by_string(const s : string) : tasm;
  480. var
  481. hs : string;
  482. t : tasm;
  483. begin
  484. result:=as_none;
  485. hs:=upper(s);
  486. for t:=low(tasm) to high(tasm) do
  487. if assigned(asminfos[t]) and
  488. (asminfos[t]^.idtxt=hs) then
  489. begin
  490. result:=t;
  491. exit;
  492. end;
  493. end;
  494. function find_dbg_by_string(const s : string) : tdbg;
  495. var
  496. hs : string;
  497. t : tdbg;
  498. begin
  499. result:=dbg_none;
  500. hs:=upper(s);
  501. for t:=low(tdbg) to high(tdbg) do
  502. if assigned(dbginfos[t]) and
  503. (dbginfos[t]^.idtxt=hs) then
  504. begin
  505. result:=t;
  506. exit;
  507. end;
  508. end;
  509. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  510. begin
  511. with d do
  512. begin
  513. { general update rules:
  514. minimum: if higher then update
  515. maximum: if lower then update or if undefined then update }
  516. if s.procalign>procalign then
  517. procalign:=s.procalign;
  518. if s.loopalign>loopalign then
  519. loopalign:=s.loopalign;
  520. if s.jumpalign>jumpalign then
  521. jumpalign:=s.jumpalign;
  522. if s.constalignmin>constalignmin then
  523. constalignmin:=s.constalignmin;
  524. if (constalignmax=0) or
  525. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  526. constalignmax:=s.constalignmax;
  527. if s.varalignmin>varalignmin then
  528. varalignmin:=s.varalignmin;
  529. if (varalignmax=0) or
  530. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  531. varalignmax:=s.varalignmax;
  532. if s.localalignmin>localalignmin then
  533. localalignmin:=s.localalignmin;
  534. if (localalignmax=0) or
  535. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  536. localalignmax:=s.localalignmax;
  537. if s.recordalignmin>recordalignmin then
  538. recordalignmin:=s.recordalignmin;
  539. if (recordalignmax=0) or
  540. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  541. recordalignmax:=s.recordalignmax;
  542. if (maxCrecordalign=0) or
  543. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  544. maxCrecordalign:=s.maxCrecordalign;
  545. end;
  546. end;
  547. {****************************************************************************
  548. Target registration
  549. ****************************************************************************}
  550. procedure RegisterTarget(const r:tsysteminfo);
  551. var
  552. t : tsystem;
  553. begin
  554. t:=r.system;
  555. if assigned(targetinfos[t]) then
  556. writeln('Warning: Target is already registered!')
  557. else
  558. Getmem(targetinfos[t],sizeof(tsysteminfo));
  559. targetinfos[t]^:=r;
  560. end;
  561. procedure RegisterRes(const r:tresinfo);
  562. var
  563. t : tres;
  564. begin
  565. t:=r.id;
  566. if assigned(resinfos[t]) then
  567. writeln('Warning: resourcecompiler is already registered!')
  568. else
  569. Getmem(resinfos[t],sizeof(tresinfo));
  570. resinfos[t]^:=r;
  571. end;
  572. procedure RegisterAr(const r:tarinfo);
  573. var
  574. t : tar;
  575. begin
  576. t:=r.id;
  577. if assigned(arinfos[t]) then
  578. writeln('Warning: ar is already registered!')
  579. else
  580. Getmem(arinfos[t],sizeof(tarinfo));
  581. arinfos[t]^:=r;
  582. end;
  583. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  584. begin
  585. system_info.linkextern := c;
  586. end;
  587. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  588. begin
  589. system_info.link := c;
  590. end;
  591. procedure DeregisterInfos;
  592. var
  593. assem : tasm;
  594. target : tsystem;
  595. ar : tar;
  596. res : tres;
  597. dbg : tdbg;
  598. begin
  599. for target:=low(tsystem) to high(tsystem) do
  600. if assigned(targetinfos[target]) then
  601. begin
  602. freemem(targetinfos[target],sizeof(tsysteminfo));
  603. targetinfos[target]:=nil;
  604. end;
  605. for assem:=low(tasm) to high(tasm) do
  606. if assigned(asminfos[assem]) then
  607. begin
  608. freemem(asminfos[assem],sizeof(tasminfo));
  609. asminfos[assem]:=nil;
  610. end;
  611. for ar:=low(tar) to high(tar) do
  612. if assigned(arinfos[ar]) then
  613. begin
  614. freemem(arinfos[ar],sizeof(tarinfo));
  615. arinfos[ar]:=nil;
  616. end;
  617. for res:=low(tres) to high(tres) do
  618. if assigned(resinfos[res]) then
  619. begin
  620. freemem(resinfos[res],sizeof(tresinfo));
  621. resinfos[res]:=nil;
  622. end;
  623. for dbg:=low(tdbg) to high(tdbg) do
  624. if assigned(dbginfos[dbg]) then
  625. begin
  626. freemem(dbginfos[dbg],sizeof(tdbginfo));
  627. dbginfos[dbg]:=nil;
  628. end;
  629. end;
  630. {****************************************************************************
  631. Initialization of default target
  632. ****************************************************************************}
  633. procedure default_target(t:tsystem);
  634. begin
  635. set_target(t);
  636. if source_info.name='' then
  637. source_info:=target_info;
  638. end;
  639. procedure set_source_info(const ti : tsysteminfo);
  640. begin
  641. { can't use message() here (PFV) }
  642. if source_info.name<>'' then
  643. Writeln('Warning: Source OS Redefined!');
  644. source_info:=ti;
  645. end;
  646. procedure InitSystems;
  647. begin
  648. { Now default target, this is dependent on the target cpu define,
  649. when the define is the same as the source cpu then we use the source
  650. os, else we pick a default }
  651. {$ifdef i386}
  652. {$ifdef cpu86}
  653. default_target(source_info.system);
  654. {$else cpu86}
  655. {$ifdef linux}
  656. default_target(system_i386_linux);
  657. {$endif}
  658. {$ifdef freebsd}
  659. default_target(system_i386_freebsd);
  660. {$endif}
  661. {$ifdef darwin}
  662. default_target(system_i386_darwin);
  663. {$endif}
  664. {$endif cpu86}
  665. {$endif i386}
  666. {$ifdef x86_64}
  667. {$ifdef cpux86_64}
  668. default_target(source_info.system);
  669. {$define source_system_set}
  670. {$else cpux86_64}
  671. {$ifdef MSWindows}
  672. default_target(system_x86_64_win64);
  673. {$define source_system_set}
  674. {$endif}
  675. {$ifdef linux}
  676. default_target(system_x86_64_linux);
  677. {$define source_system_set}
  678. {$endif}
  679. {$ifdef freebsd}
  680. default_target(system_x86_64_freebsd);
  681. {$define source_system_set}
  682. {$endif}
  683. { default is linux }
  684. {$ifndef source_system_set}
  685. default_target(system_x86_64_linux);
  686. {$endif source_system_set}
  687. {$endif cpux86_64}
  688. {$endif x86_64}
  689. {$ifdef m68k}
  690. {$ifdef cpu68}
  691. default_target(source_info.target);
  692. {$else cpu68}
  693. default_target(system_m68k_linux);
  694. {$endif cpu68}
  695. {$endif m68k}
  696. {$ifdef alpha}
  697. {$ifdef cpualpha}
  698. default_target(source_info.system);
  699. {$else cpualpha}
  700. default_target(system_alpha_linux);
  701. {$endif cpualpha}
  702. {$endif alpha}
  703. {$ifdef powerpc}
  704. {$ifdef cpupowerpc}
  705. default_target(source_info.system);
  706. {$else cpupowerpc}
  707. {$ifdef linux}
  708. default_target(system_powerpc_linux);
  709. {$endif}
  710. {$ifdef darwin}
  711. default_target(system_powerpc_darwin);
  712. {$endif}
  713. {$endif cpupowerpc}
  714. {$endif powerpc}
  715. {$ifdef POWERPC64}
  716. {$ifdef cpupowerpc64}
  717. default_target(source_info.system);
  718. {$else cpupowerpc64}
  719. default_target(system_powerpc64_linux);
  720. {$endif cpupowerpc64}
  721. {$endif POWERPC64}
  722. {$ifdef sparc}
  723. {$ifdef cpusparc}
  724. default_target(source_info.system);
  725. {$else cpusparc}
  726. default_target(system_sparc_linux);
  727. {$endif cpusparc}
  728. {$endif sparc}
  729. {$ifdef arm}
  730. {$ifdef cpuarm}
  731. default_target(source_info.system);
  732. {$else cpuarm}
  733. default_target(system_arm_linux);
  734. {$endif cpuarm}
  735. {$endif arm}
  736. end;
  737. initialization
  738. source_info.name:='';
  739. finalization
  740. DeregisterInfos;
  741. end.