systems.pas 30 KB

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