systems.pas 30 KB

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