systems.pas 27 KB

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