systems.pas 26 KB

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