systems.pas 28 KB

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