systems.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. {
  2. Copyright (c) 1998-2008 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 2 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. {$i systems.inc}
  22. {*****************************************************************************
  23. Structures
  24. *****************************************************************************}
  25. type
  26. { Abstract linker class which is implemented in link module }
  27. TAbstractLinker = class
  28. end;
  29. TAbstractLinkerClass = class of TAbstractLinker;
  30. { Abstract assembler class which is implemented in assemble module }
  31. TAbstractAssembler = class
  32. end;
  33. TAbstractAssemblerClass = class of TAbstractAssembler;
  34. TAbstractResourceFile = class
  35. constructor create(const fn : ansistring);virtual;abstract;
  36. end;
  37. TAbstractResourceFileClass = class of TAbstractResourceFile;
  38. palignmentinfo = ^talignmentinfo;
  39. { this is written to ppus during token recording for generics so it must be packed }
  40. talignmentinfo = packed record
  41. procalign,
  42. loopalign,
  43. jumpalign,
  44. constalignmin,
  45. constalignmax,
  46. varalignmin,
  47. varalignmax,
  48. localalignmin,
  49. localalignmax,
  50. recordalignmin,
  51. recordalignmax,
  52. maxCrecordalign : longint;
  53. end;
  54. tasmflags = (af_none,
  55. af_outputbinary,af_allowdirect,
  56. af_needar,af_smartlink_sections,
  57. af_labelprefix_only_inside_procedure,
  58. af_supports_dwarf,
  59. af_no_debug,
  60. af_stabs_use_function_absolute_addresses
  61. );
  62. pasminfo = ^tasminfo;
  63. tasminfo = record
  64. id : tasm;
  65. idtxt : string[12];
  66. asmbin : string[8];
  67. asmcmd : string[50];
  68. supported_targets : set of tsystem;
  69. flags : set of tasmflags;
  70. labelprefix : string[3];
  71. comment : string[3];
  72. end;
  73. parinfo = ^tarinfo;
  74. tarinfo = record
  75. id : tar;
  76. arcmd : string[50];
  77. arfinishcmd : string[10];
  78. end;
  79. presinfo = ^tresinfo;
  80. tresinfo = record
  81. id : tres;
  82. { Compiler for resource (.rc or .res) to obj }
  83. resbin : string[10];
  84. rescmd : string[50];
  85. { Optional compiler for resource script (.rc) to binary resource (.res). }
  86. { If it is not provided resbin and rescmd will be used. }
  87. rcbin : string[10];
  88. rccmd : string[50];
  89. resourcefileclass : TAbstractResourceFileClass;
  90. resflags : set of tresinfoflags;
  91. end;
  92. pdbginfo = ^tdbginfo;
  93. tdbginfo = record
  94. id : tdbg;
  95. idtxt : string[12];
  96. end;
  97. tsystemflags = (tf_none,
  98. tf_under_development,
  99. tf_need_export,
  100. tf_needs_isconsole,
  101. tf_code_small,
  102. tf_static_reg_based,
  103. tf_needs_symbol_size,
  104. tf_smartlink_sections,
  105. tf_smartlink_library,
  106. tf_needs_dwarf_cfi,
  107. tf_use_8_3,
  108. tf_pic_uses_got,
  109. tf_library_needs_pic,
  110. tf_needs_symbol_type,
  111. tf_section_threadvars,
  112. tf_files_case_sensitive,
  113. tf_files_case_aware,
  114. tf_p_ext_support,
  115. tf_has_dllscanner,
  116. tf_use_function_relative_addresses,
  117. tf_winlikewidestring,
  118. tf_dwarf_relative_addresses, // use offsets where the Dwarf spec requires this instead of absolute addresses (the latter is needed by Linux binutils)
  119. tf_dwarf_only_local_labels, // only use local labels inside the Dwarf debug_info section (needed for e.g. Darwin)
  120. tf_requires_proper_alignment,
  121. tf_no_pic_supported,
  122. tf_pic_default,
  123. { the os does some kind of stack checking and it can be converted into a rte 202 }
  124. tf_no_generic_stackcheck,
  125. tf_has_winlike_resources,
  126. tf_safecall_clearstack, // With this flag set, after safecall calls the caller cleans up the stack
  127. tf_safecall_exceptions // Exceptions in safecall calls are not raised, but passed to the caller as an ordinal (hresult) in the function result.
  128. // The original result (if it exists) is passed as an extra parameter
  129. );
  130. psysteminfo = ^tsysteminfo;
  131. { using packed causes bus errors on processors which require alignment }
  132. tsysteminfo = record
  133. system : tsystem;
  134. name : string[34];
  135. shortname : string[9];
  136. flags : set of tsystemflags;
  137. cpu : tsystemcpu;
  138. unit_env : string[16];
  139. extradefines : string[40];
  140. exeext,
  141. defext,
  142. scriptext,
  143. smartext,
  144. unitext,
  145. unitlibext,
  146. asmext,
  147. objext,
  148. resext : string[4];
  149. resobjext : string[7];
  150. sharedlibext : string[10];
  151. staticlibext,
  152. staticlibprefix : string[4];
  153. sharedlibprefix : string[4];
  154. sharedClibext : string[10];
  155. staticClibext,
  156. staticClibprefix : string[4];
  157. sharedClibprefix : string[4];
  158. importlibprefix : string[10];
  159. importlibext : string[4];
  160. Cprefix : string[2];
  161. newline : string[2];
  162. dirsep : char;
  163. assem : tasm;
  164. assemextern : tasm; { external assembler, used by -a }
  165. link : tabstractlinkerclass;
  166. linkextern : tabstractlinkerclass; { external linker, used by -s }
  167. ar : tar;
  168. res : tres;
  169. dbg : tdbg;
  170. script : tscripttype;
  171. endian : tendian;
  172. alignment : talignmentinfo;
  173. {
  174. Offset from the argument pointer register to the first
  175. argument's address. On some machines it may depend on
  176. the data type of the function.
  177. (see also FIRST_PARM_OFFSET in GCC source)
  178. }
  179. first_parm_offset : longint;
  180. stacksize : longint;
  181. abi : tabi;
  182. end;
  183. const
  184. { alias for supported_target field in tasminfo }
  185. system_any = system_none;
  186. systems_wince = [system_arm_wince,system_i386_wince];
  187. systems_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
  188. system_arm_linux,system_sparc_linux,system_alpha_linux,system_m68k_linux,
  189. system_x86_6432_linux,system_mips_linux,system_mipsel_linux];
  190. { all real windows systems, no cripple ones like wince, wdosx et. al. }
  191. systems_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64];
  192. { all windows systems }
  193. systems_all_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64,
  194. system_arm_wince,system_i386_wince];
  195. { all darwin systems }
  196. systems_darwin = [system_powerpc_darwin,system_i386_darwin,
  197. system_powerpc64_darwin,system_x86_64_darwin,
  198. system_arm_darwin,system_i386_iphonesim];
  199. {all solaris systems }
  200. systems_solaris = [system_sparc_solaris, system_i386_solaris,
  201. system_x86_64_solaris];
  202. { all embedded systems }
  203. systems_embedded = [system_i386_embedded,system_m68k_embedded,
  204. system_alpha_embedded,system_powerpc_embedded,
  205. system_sparc_embedded,system_vm_embedded,
  206. system_iA64_embedded,system_x86_64_embedded,
  207. system_mips_embedded,system_arm_embedded,
  208. system_powerpc64_embedded,system_avr_embedded];
  209. { all systems that allow section directive }
  210. systems_allow_section = systems_embedded;
  211. systems_allow_section_no_semicolon = systems_allow_section
  212. {$ifdef TEST_TLS_DIRECTORY}
  213. + systems_windows
  214. {$endif TEST_TLS_DIRECTORY}
  215. ;
  216. { all symbian systems }
  217. systems_symbian = [system_i386_symbian,system_arm_symbian];
  218. { all classic Mac OS targets }
  219. systems_macos = [system_m68k_Mac,system_powerpc_Macos];
  220. { all OS/2 targets }
  221. systems_os2 = [system_i386_OS2,system_i386_emx];
  222. { all native nt systems }
  223. systems_nativent = [system_i386_nativent];
  224. { systems supporting Objective-C }
  225. systems_objc_supported = systems_darwin;
  226. { systems using the non-fragile Objective-C ABI }
  227. systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin,system_i386_iphonesim];
  228. { all systems supporting exports from programs or units }
  229. systems_unit_program_exports = [system_i386_win32,
  230. system_i386_wdosx,
  231. system_i386_Netware,
  232. system_i386_netwlibc,
  233. system_arm_wince,
  234. system_x86_64_win64,
  235. system_ia64_win64]+systems_linux;
  236. { all systems for which weak linking has been tested/is supported }
  237. systems_weak_linking = systems_darwin + systems_solaris;
  238. systems_internal_sysinit = [system_i386_linux,system_i386_win32];
  239. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  240. { If anyone wants to use interrupt for
  241. a specific target, add a
  242. $define FPC_HAS_SYSTEMS_INTERRUPT_TABLE
  243. to fpcdefs.inc to reactivate
  244. the corresponding code }
  245. systems_interrupt_table = [{system_arm_embedded}];
  246. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  247. { all systems for which istack must be at a 16 byte boundary
  248. when calling a function }
  249. systems_need_16_byte_stack_alignment = [
  250. system_i386_darwin,
  251. system_i386_iphonesim,
  252. system_x86_64_darwin,
  253. system_x86_64_win64,
  254. system_x86_64_linux,
  255. system_x86_64_freebsd,
  256. system_x86_64_solaris];
  257. cpu2str : array[TSystemCpu] of string[10] =
  258. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  259. 'mips','arm', 'powerpc64', 'avr', 'mipsel');
  260. abi2str : array[tabi] of string[10] =
  261. ('DEFAULT','SYSV','AIX','EABI','ARMEB');
  262. var
  263. targetinfos : array[tsystem] of psysteminfo;
  264. arinfos : array[tar] of parinfo;
  265. resinfos : array[tres] of presinfo;
  266. asminfos : array[tasm] of pasminfo;
  267. dbginfos : array[tdbg] of pdbginfo;
  268. source_info : tsysteminfo;
  269. target_cpu : tsystemcpu;
  270. target_info : tsysteminfo;
  271. target_asm : tasminfo;
  272. target_ar : tarinfo;
  273. target_res : tresinfo;
  274. target_dbg : tdbginfo;
  275. target_cpu_string,
  276. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  277. target_full_string : string[24];
  278. function set_target(t:tsystem):boolean;
  279. function set_target_asm(t:tasm):boolean;
  280. function set_target_ar(t:tar):boolean;
  281. function set_target_res(t:tres):boolean;
  282. function set_target_dbg(t:tdbg):boolean;
  283. function find_system_by_string(const s : string) : tsystem;
  284. function find_asm_by_string(const s : string) : tasm;
  285. function find_dbg_by_string(const s : string) : tdbg;
  286. procedure set_source_info(const ti : tsysteminfo);
  287. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  288. procedure RegisterTarget(const r:tsysteminfo);
  289. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  290. procedure RegisterAr(const r:tarinfo);
  291. { Register the external linker. This routine is called to setup the
  292. class to use for the linker. It returns the tsysteminfo structure
  293. updated with the correct linker class for external linking.
  294. }
  295. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  296. { Register the internal linker. This routine is called to setup the
  297. class to use for the linker. It returns the tsysteminfo structure
  298. updated with the correct linker class for internal linking.
  299. If internal linking is not supported, this class can be set
  300. to nil.
  301. }
  302. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  303. procedure InitSystems;
  304. {$ifdef FreeBSD}
  305. function GetOSRelDate:Longint;
  306. {$endif}
  307. implementation
  308. uses
  309. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  310. {****************************************************************************
  311. OS runtime version detection utility routine
  312. ****************************************************************************}
  313. {$ifdef FreeBSD}
  314. function GetOSRelDate:Longint;
  315. var
  316. mib : array[0..1] of cint;
  317. rval : cint;
  318. len : size_t;
  319. i : longint;
  320. v : longint;
  321. oerrno : cint;
  322. S : AnsiString;
  323. Begin
  324. s:='ab';
  325. SetLength(S,50);
  326. mib[0] := CTL_KERN;
  327. mib[1] := KERN_OSRELDATE;
  328. len := 4;
  329. oerrno:= fpgeterrno;
  330. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  331. Begin
  332. if (fpgeterrno = ESysENOMEM) Then
  333. fpseterrno(oerrno);
  334. GetOSRelDate:=0;
  335. End
  336. else
  337. GetOSRelDate:=v;
  338. End;
  339. {$endif}
  340. {****************************************************************************
  341. Target setting
  342. ****************************************************************************}
  343. function set_target(t:tsystem):boolean;
  344. begin
  345. set_target:=false;
  346. if assigned(targetinfos[t]) then
  347. begin
  348. target_info:=targetinfos[t]^;
  349. set_target_asm(target_info.assem);
  350. set_target_ar(target_info.ar);
  351. set_target_res(target_info.res);
  352. set_target_dbg(target_info.dbg);
  353. target_cpu:=target_info.cpu;
  354. target_os_string:=lower(target_info.shortname);
  355. target_cpu_string:=cpu2str[target_cpu];
  356. target_full_string:=target_cpu_string+'-'+target_os_string;
  357. set_target:=true;
  358. exit;
  359. end;
  360. end;
  361. function set_target_asm(t:tasm):boolean;
  362. begin
  363. set_target_asm:=false;
  364. if assigned(asminfos[t]) and
  365. ((target_info.system in asminfos[t]^.supported_targets) or
  366. (system_any in asminfos[t]^.supported_targets)) then
  367. begin
  368. target_asm:=asminfos[t]^;
  369. set_target_asm:=true;
  370. exit;
  371. end;
  372. end;
  373. function set_target_ar(t:tar):boolean;
  374. begin
  375. result:=false;
  376. if assigned(arinfos[t]) then
  377. begin
  378. target_ar:=arinfos[t]^;
  379. result:=true;
  380. exit;
  381. end;
  382. end;
  383. function set_target_res(t:tres):boolean;
  384. begin
  385. result:=false;
  386. if assigned(resinfos[t]) then
  387. begin
  388. target_res:=resinfos[t]^;
  389. result:=true;
  390. exit;
  391. end
  392. else
  393. FillByte(target_res,sizeof(target_res),0);
  394. end;
  395. function set_target_dbg(t:tdbg):boolean;
  396. begin
  397. result:=false;
  398. if assigned(dbginfos[t]) then
  399. begin
  400. target_dbg:=dbginfos[t]^;
  401. result:=true;
  402. exit;
  403. end;
  404. end;
  405. function find_system_by_string(const s : string) : tsystem;
  406. var
  407. hs : string;
  408. t : tsystem;
  409. begin
  410. result:=system_none;
  411. hs:=upper(s);
  412. for t:=low(tsystem) to high(tsystem) do
  413. if assigned(targetinfos[t]) and
  414. (upper(targetinfos[t]^.shortname)=hs) then
  415. begin
  416. result:=t;
  417. exit;
  418. end;
  419. end;
  420. function find_asm_by_string(const s : string) : tasm;
  421. var
  422. hs : string;
  423. t : tasm;
  424. begin
  425. result:=as_none;
  426. hs:=upper(s);
  427. for t:=low(tasm) to high(tasm) do
  428. if assigned(asminfos[t]) and
  429. (asminfos[t]^.idtxt=hs) then
  430. begin
  431. result:=t;
  432. exit;
  433. end;
  434. end;
  435. function find_dbg_by_string(const s : string) : tdbg;
  436. var
  437. hs : string;
  438. t : tdbg;
  439. begin
  440. result:=dbg_none;
  441. hs:=upper(s);
  442. for t:=low(tdbg) to high(tdbg) do
  443. if assigned(dbginfos[t]) and
  444. (dbginfos[t]^.idtxt=hs) then
  445. begin
  446. result:=t;
  447. exit;
  448. end;
  449. end;
  450. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  451. begin
  452. result:=true;
  453. with d do
  454. begin
  455. if (s.procalign in [1,2,4,8,16,32,64,128]) or (s.procalign=256) then
  456. procalign:=s.procalign
  457. else if s.procalign<>0 then
  458. result:=false;
  459. if (s.loopalign in [1,2,4,8,16,32,64,128]) or (s.loopalign=256) then
  460. loopalign:=s.loopalign
  461. else if s.loopalign<>0 then
  462. result:=false;
  463. if (s.jumpalign in [1,2,4,8,16,32,64,128]) or (s.jumpalign=256) then
  464. jumpalign:=s.jumpalign
  465. else if s.jumpalign<>0 then
  466. result:=false;
  467. { general update rules:
  468. minimum: if higher then update
  469. maximum: if lower then update or if undefined then update }
  470. if s.constalignmin>constalignmin then
  471. constalignmin:=s.constalignmin;
  472. if (constalignmax=0) or
  473. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  474. constalignmax:=s.constalignmax;
  475. if s.varalignmin>varalignmin then
  476. varalignmin:=s.varalignmin;
  477. if (varalignmax=0) or
  478. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  479. varalignmax:=s.varalignmax;
  480. if s.localalignmin>localalignmin then
  481. localalignmin:=s.localalignmin;
  482. if (localalignmax=0) or
  483. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  484. localalignmax:=s.localalignmax;
  485. if s.recordalignmin>recordalignmin then
  486. recordalignmin:=s.recordalignmin;
  487. if (recordalignmax=0) or
  488. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  489. recordalignmax:=s.recordalignmax;
  490. if (maxCrecordalign=0) or
  491. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  492. maxCrecordalign:=s.maxCrecordalign;
  493. end;
  494. end;
  495. {****************************************************************************
  496. Target registration
  497. ****************************************************************************}
  498. procedure RegisterTarget(const r:tsysteminfo);
  499. var
  500. t : tsystem;
  501. begin
  502. t:=r.system;
  503. if assigned(targetinfos[t]) then
  504. writeln('Warning: Target is already registered!')
  505. else
  506. Getmem(targetinfos[t],sizeof(tsysteminfo));
  507. targetinfos[t]^:=r;
  508. end;
  509. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  510. var
  511. t : tres;
  512. begin
  513. t:=r.id;
  514. if not assigned(resinfos[t]) then
  515. Getmem(resinfos[t],sizeof(tresinfo));
  516. resinfos[t]^:=r;
  517. resinfos[t]^.resourcefileclass:=rcf;
  518. end;
  519. procedure RegisterAr(const r:tarinfo);
  520. var
  521. t : tar;
  522. begin
  523. t:=r.id;
  524. if assigned(arinfos[t]) then
  525. writeln('Warning: ar is already registered!')
  526. else
  527. Getmem(arinfos[t],sizeof(tarinfo));
  528. arinfos[t]^:=r;
  529. end;
  530. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  531. begin
  532. system_info.linkextern := c;
  533. end;
  534. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  535. begin
  536. system_info.link := c;
  537. end;
  538. procedure DeregisterInfos;
  539. var
  540. assem : tasm;
  541. target : tsystem;
  542. ar : tar;
  543. res : tres;
  544. dbg : tdbg;
  545. begin
  546. for target:=low(tsystem) to high(tsystem) do
  547. if assigned(targetinfos[target]) then
  548. begin
  549. freemem(targetinfos[target],sizeof(tsysteminfo));
  550. targetinfos[target]:=nil;
  551. end;
  552. for assem:=low(tasm) to high(tasm) do
  553. if assigned(asminfos[assem]) then
  554. begin
  555. freemem(asminfos[assem],sizeof(tasminfo));
  556. asminfos[assem]:=nil;
  557. end;
  558. for ar:=low(tar) to high(tar) do
  559. if assigned(arinfos[ar]) then
  560. begin
  561. freemem(arinfos[ar],sizeof(tarinfo));
  562. arinfos[ar]:=nil;
  563. end;
  564. for res:=low(tres) to high(tres) do
  565. if assigned(resinfos[res]) then
  566. begin
  567. freemem(resinfos[res],sizeof(tresinfo));
  568. resinfos[res]:=nil;
  569. end;
  570. for dbg:=low(tdbg) to high(tdbg) do
  571. if assigned(dbginfos[dbg]) then
  572. begin
  573. freemem(dbginfos[dbg],sizeof(tdbginfo));
  574. dbginfos[dbg]:=nil;
  575. end;
  576. end;
  577. {****************************************************************************
  578. Initialization of default target
  579. ****************************************************************************}
  580. procedure default_target(t:tsystem);
  581. begin
  582. set_target(t);
  583. if source_info.name='' then
  584. source_info:=target_info;
  585. end;
  586. procedure set_source_info(const ti : tsysteminfo);
  587. begin
  588. { can't use message() here (PFV) }
  589. if source_info.name<>'' then
  590. Writeln('Warning: Source OS Redefined!');
  591. source_info:=ti;
  592. end;
  593. procedure InitSystems;
  594. begin
  595. { Now default target, this is dependent on the target cpu define,
  596. when the define is the same as the source cpu then we use the source
  597. os, else we pick a default }
  598. {$ifdef i386}
  599. {$ifdef cpu86}
  600. default_target(source_info.system);
  601. {$define default_target_set}
  602. {$else cpu86}
  603. {$ifdef linux}
  604. default_target(system_i386_linux);
  605. {$define default_target_set}
  606. {$endif}
  607. {$ifdef freebsd}
  608. default_target(system_i386_freebsd);
  609. {$define default_target_set}
  610. {$endif}
  611. {$ifdef darwin}
  612. default_target(system_i386_darwin);
  613. {$define default_target_set}
  614. {$endif}
  615. {$endif cpu86}
  616. { default is linux }
  617. {$ifndef default_target_set}
  618. default_target(system_i386_linux);
  619. {$endif default_target_set}
  620. {$endif i386}
  621. {$ifdef x86_64}
  622. {$ifdef cpux86_64}
  623. default_target(source_info.system);
  624. {$define default_target_set}
  625. {$else cpux86_64}
  626. {$ifdef MSWindows}
  627. default_target(system_x86_64_win64);
  628. {$define default_target_set}
  629. {$endif}
  630. {$ifdef linux}
  631. default_target(system_x86_64_linux);
  632. {$define default_target_set}
  633. {$endif}
  634. {$ifdef freebsd}
  635. default_target(system_x86_64_freebsd);
  636. {$define default_target_set}
  637. {$endif}
  638. {$ifdef solaris}
  639. default_target(system_x86_64_solaris);
  640. {$define default_target_set}
  641. {$endif}
  642. {$ifdef darwin}
  643. default_target(system_x86_64_darwin);
  644. {$define default_target_set}
  645. {$endif}
  646. {$endif cpux86_64}
  647. { default is linux }
  648. {$ifndef default_target_set}
  649. default_target(system_x86_64_linux);
  650. {$endif default_target_set}
  651. {$endif x86_64}
  652. {$ifdef m68k}
  653. {$ifdef cpu68}
  654. default_target(source_info.target);
  655. {$else cpu68}
  656. default_target(system_m68k_linux);
  657. {$endif cpu68}
  658. {$endif m68k}
  659. {$ifdef alpha}
  660. {$ifdef cpualpha}
  661. default_target(source_info.system);
  662. {$else cpualpha}
  663. default_target(system_alpha_linux);
  664. {$endif cpualpha}
  665. {$endif alpha}
  666. {$ifdef powerpc}
  667. {$ifdef cpupowerpc}
  668. default_target(source_info.system);
  669. {$define default_target_set}
  670. {$else cpupowerpc}
  671. {$ifdef linux}
  672. default_target(system_powerpc_linux);
  673. {$define default_target_set}
  674. {$endif}
  675. {$ifdef darwin}
  676. default_target(system_powerpc_darwin);
  677. {$define default_target_set}
  678. {$endif}
  679. {$endif cpupowerpc}
  680. {$ifndef default_target_set}
  681. default_target(system_powerpc_linux);
  682. {$endif default_target_set}
  683. {$endif powerpc}
  684. {$ifdef POWERPC64}
  685. {$ifdef cpupowerpc64}
  686. default_target(source_info.system);
  687. {$define default_target_set}
  688. {$else cpupowerpc64}
  689. {$ifdef darwin}
  690. default_target(system_powerpc64_darwin);
  691. {$define default_target_set}
  692. {$endif}
  693. {$ifdef linux}
  694. default_target(system_powerpc64_linux);
  695. {$define default_target_set}
  696. {$endif}
  697. {$endif cpupowerpc64}
  698. {$ifndef default_target_set}
  699. default_target(system_powerpc64_linux);
  700. {$define default_target_set}
  701. {$endif}
  702. {$endif POWERPC64}
  703. {$ifdef sparc}
  704. {$ifdef cpusparc}
  705. default_target(source_info.system);
  706. {$else cpusparc}
  707. default_target(system_sparc_linux);
  708. {$endif cpusparc}
  709. {$endif sparc}
  710. {$ifdef arm}
  711. {$ifdef cpuarm}
  712. default_target(source_info.system);
  713. {$else cpuarm}
  714. {$ifdef WINDOWS}
  715. {$define default_target_set}
  716. default_target(system_arm_wince);
  717. {$endif}
  718. {$ifdef linux}
  719. {$define default_target_set}
  720. default_target(system_arm_linux);
  721. {$endif}
  722. {$ifdef darwin}
  723. {$define default_target_set}
  724. default_target(system_arm_darwin);
  725. {$endif}
  726. {$ifndef default_target_set}
  727. default_target(system_arm_linux);
  728. {$define default_target_set}
  729. {$endif}
  730. {$endif cpuarm}
  731. {$endif arm}
  732. {$ifdef avr}
  733. default_target(system_avr_embedded);
  734. {$endif avr}
  735. {$ifdef mips}
  736. {$ifdef mipsel}
  737. default_target(system_mipsel_linux);
  738. {$else mipsel}
  739. default_target(system_mips_linux);
  740. {$endif mipsel}
  741. {$endif mips}
  742. end;
  743. initialization
  744. source_info.name:='';
  745. finalization
  746. DeregisterInfos;
  747. end.