systems.pas 27 KB

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