systems.pas 30 KB

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