systems.pas 25 KB

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