systems.pas 25 KB

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