systems.pas 30 KB

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