systems.pas 25 KB

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