systems.pas 27 KB

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