systems.pas 29 KB

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