systems.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. );
  304. psysteminfo = ^tsysteminfo;
  305. { using packed causes bus errors on processors which require alignment }
  306. tsysteminfo = record
  307. system : tsystem;
  308. name : string[34];
  309. shortname : string[9];
  310. flags : set of tsystemflags;
  311. cpu : tsystemcpu;
  312. unit_env : string[16];
  313. extradefines : string[40];
  314. exeext,
  315. defext,
  316. scriptext,
  317. smartext,
  318. unitext,
  319. unitlibext,
  320. asmext,
  321. objext,
  322. resext : string[4];
  323. resobjext : string[7];
  324. sharedlibext : string[10];
  325. staticlibext,
  326. staticlibprefix : string[4];
  327. sharedlibprefix : string[4];
  328. sharedClibext : string[10];
  329. staticClibext,
  330. staticClibprefix : string[4];
  331. sharedClibprefix : string[4];
  332. importlibprefix : string[10];
  333. importlibext : string[4];
  334. Cprefix : string[2];
  335. newline : string[2];
  336. dirsep : char;
  337. assem : tasm;
  338. assemextern : tasm; { external assembler, used by -a }
  339. link : tabstractlinkerclass;
  340. linkextern : tabstractlinkerclass; { external linker, used by -s }
  341. ar : tar;
  342. res : tres;
  343. dbg : tdbg;
  344. script : tscripttype;
  345. endian : tendian;
  346. alignment : talignmentinfo;
  347. {
  348. Offset from the argument pointer register to the first
  349. argument's address. On some machines it may depend on
  350. the data type of the function.
  351. (see also FIRST_PARM_OFFSET in GCC source)
  352. }
  353. first_parm_offset : longint;
  354. stacksize : longint;
  355. abi : tabi;
  356. end;
  357. const
  358. { alias for supported_target field in tasminfo }
  359. system_any = system_none;
  360. systems_wince = [system_arm_wince,system_i386_wince];
  361. systems_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
  362. system_arm_linux,system_sparc_linux,system_alpha_linux,system_m68k_linux,
  363. system_x86_6432_linux,system_mips_linux,system_mipsel_linux];
  364. { all real windows systems, no cripple ones like wince, wdosx et. al. }
  365. systems_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64];
  366. { all windows systems }
  367. systems_all_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64,
  368. system_arm_wince,system_i386_wince];
  369. { all darwin systems }
  370. systems_darwin = [system_powerpc_darwin,system_i386_darwin,
  371. system_powerpc64_darwin,system_x86_64_darwin,
  372. system_arm_darwin];
  373. {all solaris systems }
  374. systems_solaris = [system_sparc_solaris, system_i386_solaris,
  375. system_x86_64_solaris];
  376. { systems supporting Objective-C }
  377. systems_objc_supported = systems_darwin;
  378. { systems using the non-fragile Objective-C ABI }
  379. systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin];
  380. { all embedded systems }
  381. systems_embedded = [system_i386_embedded,system_m68k_embedded,
  382. system_alpha_embedded,system_powerpc_embedded,
  383. system_sparc_embedded,system_vm_embedded,
  384. system_iA64_embedded,system_x86_64_embedded,
  385. system_mips_embedded,system_arm_embedded,
  386. system_powerpc64_embedded];
  387. { all systems supporting exports from programs or units }
  388. systems_unit_program_exports = [system_i386_win32,
  389. system_i386_wdosx,
  390. system_i386_Netware,
  391. system_i386_netwlibc,
  392. system_arm_wince,
  393. system_x86_64_win64,
  394. system_ia64_win64]+systems_linux;
  395. { all systems for which weak linking has been tested/is supported }
  396. systems_weak_linking = systems_darwin + systems_solaris;
  397. systems_internal_sysinit = [system_i386_linux,system_i386_win32];
  398. { all symbian systems }
  399. systems_symbian = [system_i386_symbian,system_arm_symbian];
  400. { all native nt systems }
  401. systems_nativent = [system_i386_nativent];
  402. { all systems for which istack must be at a 16 byte boundary
  403. when calling a function }
  404. systems_need_16_byte_stack_alignment = [
  405. system_i386_darwin,
  406. system_x86_64_darwin,
  407. system_x86_64_win64,
  408. system_x86_64_linux,
  409. system_x86_64_freebsd,
  410. system_x86_64_solaris];
  411. cpu2str : array[TSystemCpu] of string[10] =
  412. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  413. 'mips','arm', 'powerpc64', 'avr', 'mipsel');
  414. abi2str : array[tabi] of string[10] =
  415. ('DEFAULT','SYSV','AIX','EABI','ARMEB');
  416. var
  417. targetinfos : array[tsystem] of psysteminfo;
  418. arinfos : array[tar] of parinfo;
  419. resinfos : array[tres] of presinfo;
  420. asminfos : array[tasm] of pasminfo;
  421. dbginfos : array[tdbg] of pdbginfo;
  422. source_info : tsysteminfo;
  423. target_cpu : tsystemcpu;
  424. target_info : tsysteminfo;
  425. target_asm : tasminfo;
  426. target_ar : tarinfo;
  427. target_res : tresinfo;
  428. target_dbg : tdbginfo;
  429. target_cpu_string,
  430. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  431. target_full_string : string[24];
  432. function set_target(t:tsystem):boolean;
  433. function set_target_asm(t:tasm):boolean;
  434. function set_target_ar(t:tar):boolean;
  435. function set_target_res(t:tres):boolean;
  436. function set_target_dbg(t:tdbg):boolean;
  437. function find_system_by_string(const s : string) : tsystem;
  438. function find_asm_by_string(const s : string) : tasm;
  439. function find_dbg_by_string(const s : string) : tdbg;
  440. procedure set_source_info(const ti : tsysteminfo);
  441. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  442. procedure RegisterTarget(const r:tsysteminfo);
  443. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  444. procedure RegisterAr(const r:tarinfo);
  445. { Register the external linker. This routine is called to setup the
  446. class to use for the linker. It returns the tsysteminfo structure
  447. updated with the correct linker class for external linking.
  448. }
  449. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  450. { Register the internal linker. This routine is called to setup the
  451. class to use for the linker. It returns the tsysteminfo structure
  452. updated with the correct linker class for internal linking.
  453. If internal linking is not supported, this class can be set
  454. to nil.
  455. }
  456. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  457. procedure InitSystems;
  458. {$ifdef FreeBSD}
  459. function GetOSRelDate:Longint;
  460. {$endif}
  461. implementation
  462. uses
  463. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  464. {****************************************************************************
  465. OS runtime version detection utility routine
  466. ****************************************************************************}
  467. {$ifdef FreeBSD}
  468. function GetOSRelDate:Longint;
  469. var
  470. mib : array[0..1] of cint;
  471. rval : cint;
  472. len : size_t;
  473. i : longint;
  474. v : longint;
  475. oerrno : cint;
  476. S : AnsiString;
  477. Begin
  478. s:='ab';
  479. SetLength(S,50);
  480. mib[0] := CTL_KERN;
  481. mib[1] := KERN_OSRELDATE;
  482. len := 4;
  483. oerrno:= fpgeterrno;
  484. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  485. Begin
  486. if (fpgeterrno = ESysENOMEM) Then
  487. fpseterrno(oerrno);
  488. GetOSRelDate:=0;
  489. End
  490. else
  491. GetOSRelDate:=v;
  492. End;
  493. {$endif}
  494. {****************************************************************************
  495. Target setting
  496. ****************************************************************************}
  497. function set_target(t:tsystem):boolean;
  498. begin
  499. set_target:=false;
  500. if assigned(targetinfos[t]) then
  501. begin
  502. target_info:=targetinfos[t]^;
  503. set_target_asm(target_info.assem);
  504. set_target_ar(target_info.ar);
  505. set_target_res(target_info.res);
  506. set_target_dbg(target_info.dbg);
  507. target_cpu:=target_info.cpu;
  508. target_os_string:=lower(target_info.shortname);
  509. target_cpu_string:=cpu2str[target_cpu];
  510. target_full_string:=target_cpu_string+'-'+target_os_string;
  511. set_target:=true;
  512. exit;
  513. end;
  514. end;
  515. function set_target_asm(t:tasm):boolean;
  516. begin
  517. set_target_asm:=false;
  518. if assigned(asminfos[t]) and
  519. ((target_info.system in asminfos[t]^.supported_targets) or
  520. (system_any in asminfos[t]^.supported_targets)) then
  521. begin
  522. target_asm:=asminfos[t]^;
  523. set_target_asm:=true;
  524. exit;
  525. end;
  526. end;
  527. function set_target_ar(t:tar):boolean;
  528. begin
  529. result:=false;
  530. if assigned(arinfos[t]) then
  531. begin
  532. target_ar:=arinfos[t]^;
  533. result:=true;
  534. exit;
  535. end;
  536. end;
  537. function set_target_res(t:tres):boolean;
  538. begin
  539. result:=false;
  540. if assigned(resinfos[t]) then
  541. begin
  542. target_res:=resinfos[t]^;
  543. result:=true;
  544. exit;
  545. end
  546. else
  547. FillByte(target_res,sizeof(target_res),0);
  548. end;
  549. function set_target_dbg(t:tdbg):boolean;
  550. begin
  551. result:=false;
  552. if assigned(dbginfos[t]) then
  553. begin
  554. target_dbg:=dbginfos[t]^;
  555. result:=true;
  556. exit;
  557. end;
  558. end;
  559. function find_system_by_string(const s : string) : tsystem;
  560. var
  561. hs : string;
  562. t : tsystem;
  563. begin
  564. result:=system_none;
  565. hs:=upper(s);
  566. for t:=low(tsystem) to high(tsystem) do
  567. if assigned(targetinfos[t]) and
  568. (upper(targetinfos[t]^.shortname)=hs) then
  569. begin
  570. result:=t;
  571. exit;
  572. end;
  573. end;
  574. function find_asm_by_string(const s : string) : tasm;
  575. var
  576. hs : string;
  577. t : tasm;
  578. begin
  579. result:=as_none;
  580. hs:=upper(s);
  581. for t:=low(tasm) to high(tasm) do
  582. if assigned(asminfos[t]) and
  583. (asminfos[t]^.idtxt=hs) then
  584. begin
  585. result:=t;
  586. exit;
  587. end;
  588. end;
  589. function find_dbg_by_string(const s : string) : tdbg;
  590. var
  591. hs : string;
  592. t : tdbg;
  593. begin
  594. result:=dbg_none;
  595. hs:=upper(s);
  596. for t:=low(tdbg) to high(tdbg) do
  597. if assigned(dbginfos[t]) and
  598. (dbginfos[t]^.idtxt=hs) then
  599. begin
  600. result:=t;
  601. exit;
  602. end;
  603. end;
  604. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  605. begin
  606. with d do
  607. begin
  608. { general update rules:
  609. minimum: if higher then update
  610. maximum: if lower then update or if undefined then update }
  611. if s.procalign>procalign then
  612. procalign:=s.procalign;
  613. if s.loopalign>loopalign then
  614. loopalign:=s.loopalign;
  615. if s.jumpalign>jumpalign then
  616. jumpalign:=s.jumpalign;
  617. if s.constalignmin>constalignmin then
  618. constalignmin:=s.constalignmin;
  619. if (constalignmax=0) or
  620. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  621. constalignmax:=s.constalignmax;
  622. if s.varalignmin>varalignmin then
  623. varalignmin:=s.varalignmin;
  624. if (varalignmax=0) or
  625. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  626. varalignmax:=s.varalignmax;
  627. if s.localalignmin>localalignmin then
  628. localalignmin:=s.localalignmin;
  629. if (localalignmax=0) or
  630. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  631. localalignmax:=s.localalignmax;
  632. if s.recordalignmin>recordalignmin then
  633. recordalignmin:=s.recordalignmin;
  634. if (recordalignmax=0) or
  635. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  636. recordalignmax:=s.recordalignmax;
  637. if (maxCrecordalign=0) or
  638. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  639. maxCrecordalign:=s.maxCrecordalign;
  640. end;
  641. end;
  642. {****************************************************************************
  643. Target registration
  644. ****************************************************************************}
  645. procedure RegisterTarget(const r:tsysteminfo);
  646. var
  647. t : tsystem;
  648. begin
  649. t:=r.system;
  650. if assigned(targetinfos[t]) then
  651. writeln('Warning: Target is already registered!')
  652. else
  653. Getmem(targetinfos[t],sizeof(tsysteminfo));
  654. targetinfos[t]^:=r;
  655. end;
  656. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  657. var
  658. t : tres;
  659. begin
  660. t:=r.id;
  661. if not assigned(resinfos[t]) then
  662. Getmem(resinfos[t],sizeof(tresinfo));
  663. resinfos[t]^:=r;
  664. resinfos[t]^.resourcefileclass:=rcf;
  665. end;
  666. procedure RegisterAr(const r:tarinfo);
  667. var
  668. t : tar;
  669. begin
  670. t:=r.id;
  671. if assigned(arinfos[t]) then
  672. writeln('Warning: ar is already registered!')
  673. else
  674. Getmem(arinfos[t],sizeof(tarinfo));
  675. arinfos[t]^:=r;
  676. end;
  677. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  678. begin
  679. system_info.linkextern := c;
  680. end;
  681. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  682. begin
  683. system_info.link := c;
  684. end;
  685. procedure DeregisterInfos;
  686. var
  687. assem : tasm;
  688. target : tsystem;
  689. ar : tar;
  690. res : tres;
  691. dbg : tdbg;
  692. begin
  693. for target:=low(tsystem) to high(tsystem) do
  694. if assigned(targetinfos[target]) then
  695. begin
  696. freemem(targetinfos[target],sizeof(tsysteminfo));
  697. targetinfos[target]:=nil;
  698. end;
  699. for assem:=low(tasm) to high(tasm) do
  700. if assigned(asminfos[assem]) then
  701. begin
  702. freemem(asminfos[assem],sizeof(tasminfo));
  703. asminfos[assem]:=nil;
  704. end;
  705. for ar:=low(tar) to high(tar) do
  706. if assigned(arinfos[ar]) then
  707. begin
  708. freemem(arinfos[ar],sizeof(tarinfo));
  709. arinfos[ar]:=nil;
  710. end;
  711. for res:=low(tres) to high(tres) do
  712. if assigned(resinfos[res]) then
  713. begin
  714. freemem(resinfos[res],sizeof(tresinfo));
  715. resinfos[res]:=nil;
  716. end;
  717. for dbg:=low(tdbg) to high(tdbg) do
  718. if assigned(dbginfos[dbg]) then
  719. begin
  720. freemem(dbginfos[dbg],sizeof(tdbginfo));
  721. dbginfos[dbg]:=nil;
  722. end;
  723. end;
  724. {****************************************************************************
  725. Initialization of default target
  726. ****************************************************************************}
  727. procedure default_target(t:tsystem);
  728. begin
  729. set_target(t);
  730. if source_info.name='' then
  731. source_info:=target_info;
  732. end;
  733. procedure set_source_info(const ti : tsysteminfo);
  734. begin
  735. { can't use message() here (PFV) }
  736. if source_info.name<>'' then
  737. Writeln('Warning: Source OS Redefined!');
  738. source_info:=ti;
  739. end;
  740. procedure InitSystems;
  741. begin
  742. { Now default target, this is dependent on the target cpu define,
  743. when the define is the same as the source cpu then we use the source
  744. os, else we pick a default }
  745. {$ifdef i386}
  746. {$ifdef cpu86}
  747. default_target(source_info.system);
  748. {$define default_target_set}
  749. {$else cpu86}
  750. {$ifdef linux}
  751. default_target(system_i386_linux);
  752. {$define default_target_set}
  753. {$endif}
  754. {$ifdef freebsd}
  755. default_target(system_i386_freebsd);
  756. {$define default_target_set}
  757. {$endif}
  758. {$ifdef darwin}
  759. default_target(system_i386_darwin);
  760. {$define default_target_set}
  761. {$endif}
  762. {$endif cpu86}
  763. { default is linux }
  764. {$ifndef default_target_set}
  765. default_target(system_i386_linux);
  766. {$endif default_target_set}
  767. {$endif i386}
  768. {$ifdef x86_64}
  769. {$ifdef cpux86_64}
  770. default_target(source_info.system);
  771. {$define default_target_set}
  772. {$else cpux86_64}
  773. {$ifdef MSWindows}
  774. default_target(system_x86_64_win64);
  775. {$define default_target_set}
  776. {$endif}
  777. {$ifdef linux}
  778. default_target(system_x86_64_linux);
  779. {$define default_target_set}
  780. {$endif}
  781. {$ifdef freebsd}
  782. default_target(system_x86_64_freebsd);
  783. {$define default_target_set}
  784. {$endif}
  785. {$ifdef solaris}
  786. default_target(system_x86_64_solaris);
  787. {$define default_target_set}
  788. {$endif}
  789. {$ifdef darwin}
  790. default_target(system_x86_64_darwin);
  791. {$define default_target_set}
  792. {$endif}
  793. {$endif cpux86_64}
  794. { default is linux }
  795. {$ifndef default_target_set}
  796. default_target(system_x86_64_linux);
  797. {$endif default_target_set}
  798. {$endif x86_64}
  799. {$ifdef m68k}
  800. {$ifdef cpu68}
  801. default_target(source_info.target);
  802. {$else cpu68}
  803. default_target(system_m68k_linux);
  804. {$endif cpu68}
  805. {$endif m68k}
  806. {$ifdef alpha}
  807. {$ifdef cpualpha}
  808. default_target(source_info.system);
  809. {$else cpualpha}
  810. default_target(system_alpha_linux);
  811. {$endif cpualpha}
  812. {$endif alpha}
  813. {$ifdef powerpc}
  814. {$ifdef cpupowerpc}
  815. default_target(source_info.system);
  816. {$define default_target_set}
  817. {$else cpupowerpc}
  818. {$ifdef linux}
  819. default_target(system_powerpc_linux);
  820. {$define default_target_set}
  821. {$endif}
  822. {$ifdef darwin}
  823. default_target(system_powerpc_darwin);
  824. {$define default_target_set}
  825. {$endif}
  826. {$endif cpupowerpc}
  827. {$ifndef default_target_set}
  828. default_target(system_powerpc_linux);
  829. {$endif default_target_set}
  830. {$endif powerpc}
  831. {$ifdef POWERPC64}
  832. {$ifdef cpupowerpc64}
  833. default_target(source_info.system);
  834. {$define default_target_set}
  835. {$else cpupowerpc64}
  836. {$ifdef darwin}
  837. default_target(system_powerpc64_darwin);
  838. {$define default_target_set}
  839. {$endif}
  840. {$ifdef linux}
  841. default_target(system_powerpc64_linux);
  842. {$define default_target_set}
  843. {$endif}
  844. {$endif cpupowerpc64}
  845. {$ifndef default_target_set}
  846. default_target(system_powerpc64_linux);
  847. {$define default_target_set}
  848. {$endif}
  849. {$endif POWERPC64}
  850. {$ifdef sparc}
  851. {$ifdef cpusparc}
  852. default_target(source_info.system);
  853. {$else cpusparc}
  854. default_target(system_sparc_linux);
  855. {$endif cpusparc}
  856. {$endif sparc}
  857. {$ifdef arm}
  858. {$ifdef cpuarm}
  859. default_target(source_info.system);
  860. {$else cpuarm}
  861. {$ifdef WINDOWS}
  862. {$define default_target_set}
  863. default_target(system_arm_wince);
  864. {$endif}
  865. {$ifdef linux}
  866. {$define default_target_set}
  867. default_target(system_arm_linux);
  868. {$endif}
  869. {$ifdef darwin}
  870. {$define default_target_set}
  871. default_target(system_arm_darwin);
  872. {$endif}
  873. {$ifndef default_target_set}
  874. default_target(system_arm_linux);
  875. {$define default_target_set}
  876. {$endif}
  877. {$endif cpuarm}
  878. {$endif arm}
  879. {$ifdef avr}
  880. default_target(system_avr_embedded);
  881. {$endif avr}
  882. {$ifdef mips}
  883. {$ifdef mipsel}
  884. default_target(system_mipsel_linux);
  885. {$else mipsel}
  886. default_target(system_mips_linux);
  887. {$endif mipsel}
  888. {$endif mips}
  889. end;
  890. initialization
  891. source_info.name:='';
  892. finalization
  893. DeregisterInfos;
  894. end.