systems.pas 25 KB

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