systems.pas 23 KB

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