systems.pas 31 KB

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