systems.pas 25 KB

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