systems.pas 27 KB

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