2
0

systems.pas 26 KB

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