systems.pas 24 KB

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