systems.pas 27 KB

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