systems.pas 30 KB

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