systems.pas 28 KB

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