systems.pas 27 KB

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