systems.pas 23 KB

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