systems.pas 23 KB

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