systems.pas 31 KB

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