systems.pas 25 KB

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