systems.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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 : string[4];
  147. objext : string[6];
  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. system_jvm_java32];
  210. { all systems that allow section directive }
  211. systems_allow_section = systems_embedded;
  212. systems_allow_section_no_semicolon = systems_allow_section
  213. {$ifdef TEST_TLS_DIRECTORY}
  214. + systems_windows
  215. {$endif TEST_TLS_DIRECTORY}
  216. ;
  217. { all symbian systems }
  218. systems_symbian = [system_i386_symbian,system_arm_symbian];
  219. { all classic Mac OS targets }
  220. systems_macos = [system_m68k_Mac,system_powerpc_Macos];
  221. { all OS/2 targets }
  222. systems_os2 = [system_i386_OS2,system_i386_emx];
  223. { all native nt systems }
  224. systems_nativent = [system_i386_nativent];
  225. { systems supporting Objective-C }
  226. systems_objc_supported = systems_darwin;
  227. { systems using the non-fragile Objective-C ABI }
  228. systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin,system_i386_iphonesim];
  229. { all systems supporting exports from programs or units }
  230. systems_unit_program_exports = [system_i386_win32,
  231. system_i386_wdosx,
  232. system_i386_Netware,
  233. system_i386_netwlibc,
  234. system_arm_wince,
  235. system_x86_64_win64,
  236. system_ia64_win64]+systems_linux;
  237. { all systems for which weak linking has been tested/is supported }
  238. systems_weak_linking = systems_darwin + systems_solaris;
  239. systems_internal_sysinit = [system_i386_linux,system_i386_win32];
  240. {$ifdef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  241. { If anyone wants to use interrupt for
  242. a specific target, add a
  243. $define FPC_HAS_SYSTEMS_INTERRUPT_TABLE
  244. to fpcdefs.inc to reactivate
  245. the corresponding code }
  246. systems_interrupt_table = [{system_arm_embedded}];
  247. {$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
  248. { all systems for which istack must be at a 16 byte boundary
  249. when calling a function }
  250. systems_need_16_byte_stack_alignment = [
  251. system_i386_darwin,
  252. system_i386_iphonesim,
  253. system_x86_64_darwin,
  254. system_x86_64_win64,
  255. system_x86_64_linux,
  256. system_x86_64_freebsd,
  257. system_x86_64_solaris];
  258. { all systems that use garbage collection for reference-counted types }
  259. systems_garbage_collected_managed_types = [
  260. system_jvm_java32
  261. ];
  262. { all systems that use a managed vm (-> no real pointers, internal VMT
  263. format, ...) }
  264. systems_managed_vm = [
  265. system_jvm_java32
  266. ];
  267. { all systems where typed constants have to be translated into node
  268. trees that initialise the data instead of into data sections }
  269. systems_typed_constants_node_init = [
  270. system_jvm_java32
  271. ];
  272. { all systems that don't use a built-in framepointer for accessing nested
  273. variables, but emulate it by wrapping nested variables in records
  274. whose address is passed around }
  275. systems_fpnestedstruct = [
  276. system_jvm_java32
  277. ];
  278. cpu2str : array[TSystemCpu] of string[10] =
  279. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  280. 'mips','arm', 'powerpc64', 'avr', 'mipsel','jvm');
  281. abi2str : array[tabi] of string[10] =
  282. ('DEFAULT','SYSV','AIX','EABI','ARMEB');
  283. var
  284. targetinfos : array[tsystem] of psysteminfo;
  285. arinfos : array[tar] of parinfo;
  286. resinfos : array[tres] of presinfo;
  287. asminfos : array[tasm] of pasminfo;
  288. dbginfos : array[tdbg] of pdbginfo;
  289. source_info : tsysteminfo;
  290. target_cpu : tsystemcpu;
  291. target_info : tsysteminfo;
  292. target_asm : tasminfo;
  293. target_ar : tarinfo;
  294. target_res : tresinfo;
  295. target_dbg : tdbginfo;
  296. target_cpu_string,
  297. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  298. target_full_string : string[24];
  299. function set_target(t:tsystem):boolean;
  300. function set_target_asm(t:tasm):boolean;
  301. function set_target_ar(t:tar):boolean;
  302. function set_target_res(t:tres):boolean;
  303. function set_target_dbg(t:tdbg):boolean;
  304. function find_system_by_string(const s : string) : tsystem;
  305. function find_asm_by_string(const s : string) : tasm;
  306. function find_dbg_by_string(const s : string) : tdbg;
  307. procedure set_source_info(const ti : tsysteminfo);
  308. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  309. procedure RegisterTarget(const r:tsysteminfo);
  310. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  311. procedure RegisterAr(const r:tarinfo);
  312. { Register the external linker. This routine is called to setup the
  313. class to use for the linker. It returns the tsysteminfo structure
  314. updated with the correct linker class for external linking.
  315. }
  316. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  317. { Register the internal linker. This routine is called to setup the
  318. class to use for the linker. It returns the tsysteminfo structure
  319. updated with the correct linker class for internal linking.
  320. If internal linking is not supported, this class can be set
  321. to nil.
  322. }
  323. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  324. procedure InitSystems;
  325. {$ifdef FreeBSD}
  326. function GetOSRelDate:Longint;
  327. {$endif}
  328. implementation
  329. uses
  330. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  331. {****************************************************************************
  332. OS runtime version detection utility routine
  333. ****************************************************************************}
  334. {$ifdef FreeBSD}
  335. function GetOSRelDate:Longint;
  336. var
  337. mib : array[0..1] of cint;
  338. rval : cint;
  339. len : size_t;
  340. i : longint;
  341. v : longint;
  342. oerrno : cint;
  343. S : AnsiString;
  344. Begin
  345. s:='ab';
  346. SetLength(S,50);
  347. mib[0] := CTL_KERN;
  348. mib[1] := KERN_OSRELDATE;
  349. len := 4;
  350. oerrno:= fpgeterrno;
  351. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  352. Begin
  353. if (fpgeterrno = ESysENOMEM) Then
  354. fpseterrno(oerrno);
  355. GetOSRelDate:=0;
  356. End
  357. else
  358. GetOSRelDate:=v;
  359. End;
  360. {$endif}
  361. {****************************************************************************
  362. Target setting
  363. ****************************************************************************}
  364. function set_target(t:tsystem):boolean;
  365. begin
  366. set_target:=false;
  367. if assigned(targetinfos[t]) then
  368. begin
  369. target_info:=targetinfos[t]^;
  370. set_target_asm(target_info.assem);
  371. set_target_ar(target_info.ar);
  372. set_target_res(target_info.res);
  373. set_target_dbg(target_info.dbg);
  374. target_cpu:=target_info.cpu;
  375. target_os_string:=lower(target_info.shortname);
  376. target_cpu_string:=cpu2str[target_cpu];
  377. target_full_string:=target_cpu_string+'-'+target_os_string;
  378. set_target:=true;
  379. exit;
  380. end;
  381. end;
  382. function set_target_asm(t:tasm):boolean;
  383. begin
  384. set_target_asm:=false;
  385. if assigned(asminfos[t]) and
  386. ((target_info.system in asminfos[t]^.supported_targets) or
  387. (system_any in asminfos[t]^.supported_targets)) then
  388. begin
  389. target_asm:=asminfos[t]^;
  390. set_target_asm:=true;
  391. exit;
  392. end;
  393. end;
  394. function set_target_ar(t:tar):boolean;
  395. begin
  396. result:=false;
  397. if assigned(arinfos[t]) then
  398. begin
  399. target_ar:=arinfos[t]^;
  400. result:=true;
  401. exit;
  402. end;
  403. end;
  404. function set_target_res(t:tres):boolean;
  405. begin
  406. result:=false;
  407. if assigned(resinfos[t]) then
  408. begin
  409. target_res:=resinfos[t]^;
  410. result:=true;
  411. exit;
  412. end
  413. else
  414. FillByte(target_res,sizeof(target_res),0);
  415. end;
  416. function set_target_dbg(t:tdbg):boolean;
  417. begin
  418. result:=false;
  419. if assigned(dbginfos[t]) then
  420. begin
  421. target_dbg:=dbginfos[t]^;
  422. result:=true;
  423. exit;
  424. end;
  425. end;
  426. function find_system_by_string(const s : string) : tsystem;
  427. var
  428. hs : string;
  429. t : tsystem;
  430. begin
  431. result:=system_none;
  432. hs:=upper(s);
  433. for t:=low(tsystem) to high(tsystem) do
  434. if assigned(targetinfos[t]) and
  435. (upper(targetinfos[t]^.shortname)=hs) then
  436. begin
  437. result:=t;
  438. exit;
  439. end;
  440. end;
  441. function find_asm_by_string(const s : string) : tasm;
  442. var
  443. hs : string;
  444. t : tasm;
  445. begin
  446. result:=as_none;
  447. hs:=upper(s);
  448. for t:=low(tasm) to high(tasm) do
  449. if assigned(asminfos[t]) and
  450. (asminfos[t]^.idtxt=hs) then
  451. begin
  452. result:=t;
  453. exit;
  454. end;
  455. end;
  456. function find_dbg_by_string(const s : string) : tdbg;
  457. var
  458. hs : string;
  459. t : tdbg;
  460. begin
  461. result:=dbg_none;
  462. hs:=upper(s);
  463. for t:=low(tdbg) to high(tdbg) do
  464. if assigned(dbginfos[t]) and
  465. (dbginfos[t]^.idtxt=hs) then
  466. begin
  467. result:=t;
  468. exit;
  469. end;
  470. end;
  471. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  472. begin
  473. result:=true;
  474. with d do
  475. begin
  476. if (s.procalign in [1,2,4,8,16,32,64,128]) or (s.procalign=256) then
  477. procalign:=s.procalign
  478. else if s.procalign<>0 then
  479. result:=false;
  480. if (s.loopalign in [1,2,4,8,16,32,64,128]) or (s.loopalign=256) then
  481. loopalign:=s.loopalign
  482. else if s.loopalign<>0 then
  483. result:=false;
  484. if (s.jumpalign in [1,2,4,8,16,32,64,128]) or (s.jumpalign=256) then
  485. jumpalign:=s.jumpalign
  486. else if s.jumpalign<>0 then
  487. result:=false;
  488. { general update rules:
  489. minimum: if higher then update
  490. maximum: if lower then update or if undefined then update }
  491. if s.constalignmin>constalignmin then
  492. constalignmin:=s.constalignmin;
  493. if (constalignmax=0) or
  494. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  495. constalignmax:=s.constalignmax;
  496. if s.varalignmin>varalignmin then
  497. varalignmin:=s.varalignmin;
  498. if (varalignmax=0) or
  499. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  500. varalignmax:=s.varalignmax;
  501. if s.localalignmin>localalignmin then
  502. localalignmin:=s.localalignmin;
  503. if (localalignmax=0) or
  504. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  505. localalignmax:=s.localalignmax;
  506. if s.recordalignmin>recordalignmin then
  507. recordalignmin:=s.recordalignmin;
  508. if (recordalignmax=0) or
  509. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  510. recordalignmax:=s.recordalignmax;
  511. if (maxCrecordalign=0) or
  512. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  513. maxCrecordalign:=s.maxCrecordalign;
  514. end;
  515. end;
  516. {****************************************************************************
  517. Target registration
  518. ****************************************************************************}
  519. procedure RegisterTarget(const r:tsysteminfo);
  520. var
  521. t : tsystem;
  522. begin
  523. t:=r.system;
  524. if assigned(targetinfos[t]) then
  525. writeln('Warning: Target is already registered!')
  526. else
  527. Getmem(targetinfos[t],sizeof(tsysteminfo));
  528. targetinfos[t]^:=r;
  529. end;
  530. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  531. var
  532. t : tres;
  533. begin
  534. t:=r.id;
  535. if not assigned(resinfos[t]) then
  536. Getmem(resinfos[t],sizeof(tresinfo));
  537. resinfos[t]^:=r;
  538. resinfos[t]^.resourcefileclass:=rcf;
  539. end;
  540. procedure RegisterAr(const r:tarinfo);
  541. var
  542. t : tar;
  543. begin
  544. t:=r.id;
  545. if assigned(arinfos[t]) then
  546. writeln('Warning: ar is already registered!')
  547. else
  548. Getmem(arinfos[t],sizeof(tarinfo));
  549. arinfos[t]^:=r;
  550. end;
  551. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  552. begin
  553. system_info.linkextern := c;
  554. end;
  555. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  556. begin
  557. system_info.link := c;
  558. end;
  559. procedure DeregisterInfos;
  560. var
  561. assem : tasm;
  562. target : tsystem;
  563. ar : tar;
  564. res : tres;
  565. dbg : tdbg;
  566. begin
  567. for target:=low(tsystem) to high(tsystem) do
  568. if assigned(targetinfos[target]) then
  569. begin
  570. freemem(targetinfos[target],sizeof(tsysteminfo));
  571. targetinfos[target]:=nil;
  572. end;
  573. for assem:=low(tasm) to high(tasm) do
  574. if assigned(asminfos[assem]) then
  575. begin
  576. freemem(asminfos[assem],sizeof(tasminfo));
  577. asminfos[assem]:=nil;
  578. end;
  579. for ar:=low(tar) to high(tar) do
  580. if assigned(arinfos[ar]) then
  581. begin
  582. freemem(arinfos[ar],sizeof(tarinfo));
  583. arinfos[ar]:=nil;
  584. end;
  585. for res:=low(tres) to high(tres) do
  586. if assigned(resinfos[res]) then
  587. begin
  588. freemem(resinfos[res],sizeof(tresinfo));
  589. resinfos[res]:=nil;
  590. end;
  591. for dbg:=low(tdbg) to high(tdbg) do
  592. if assigned(dbginfos[dbg]) then
  593. begin
  594. freemem(dbginfos[dbg],sizeof(tdbginfo));
  595. dbginfos[dbg]:=nil;
  596. end;
  597. end;
  598. {****************************************************************************
  599. Initialization of default target
  600. ****************************************************************************}
  601. procedure default_target(t:tsystem);
  602. begin
  603. set_target(t);
  604. if source_info.name='' then
  605. source_info:=target_info;
  606. end;
  607. procedure set_source_info(const ti : tsysteminfo);
  608. begin
  609. { can't use message() here (PFV) }
  610. if source_info.name<>'' then
  611. Writeln('Warning: Source OS Redefined!');
  612. source_info:=ti;
  613. end;
  614. procedure InitSystems;
  615. begin
  616. { Now default target, this is dependent on the target cpu define,
  617. when the define is the same as the source cpu then we use the source
  618. os, else we pick a default }
  619. {$ifdef i386}
  620. {$ifdef cpu86}
  621. default_target(source_info.system);
  622. {$define default_target_set}
  623. {$else cpu86}
  624. {$ifdef linux}
  625. default_target(system_i386_linux);
  626. {$define default_target_set}
  627. {$endif}
  628. {$ifdef freebsd}
  629. default_target(system_i386_freebsd);
  630. {$define default_target_set}
  631. {$endif}
  632. {$ifdef darwin}
  633. default_target(system_i386_darwin);
  634. {$define default_target_set}
  635. {$endif}
  636. {$endif cpu86}
  637. { default is linux }
  638. {$ifndef default_target_set}
  639. default_target(system_i386_linux);
  640. {$endif default_target_set}
  641. {$endif i386}
  642. {$ifdef x86_64}
  643. {$ifdef cpux86_64}
  644. default_target(source_info.system);
  645. {$define default_target_set}
  646. {$else cpux86_64}
  647. {$ifdef MSWindows}
  648. default_target(system_x86_64_win64);
  649. {$define default_target_set}
  650. {$endif}
  651. {$ifdef linux}
  652. default_target(system_x86_64_linux);
  653. {$define default_target_set}
  654. {$endif}
  655. {$ifdef freebsd}
  656. default_target(system_x86_64_freebsd);
  657. {$define default_target_set}
  658. {$endif}
  659. {$ifdef solaris}
  660. default_target(system_x86_64_solaris);
  661. {$define default_target_set}
  662. {$endif}
  663. {$ifdef darwin}
  664. default_target(system_x86_64_darwin);
  665. {$define default_target_set}
  666. {$endif}
  667. {$endif cpux86_64}
  668. { default is linux }
  669. {$ifndef default_target_set}
  670. default_target(system_x86_64_linux);
  671. {$endif default_target_set}
  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. {$define default_target_set}
  691. {$else cpupowerpc}
  692. {$ifdef linux}
  693. default_target(system_powerpc_linux);
  694. {$define default_target_set}
  695. {$endif}
  696. {$ifdef darwin}
  697. default_target(system_powerpc_darwin);
  698. {$define default_target_set}
  699. {$endif}
  700. {$endif cpupowerpc}
  701. {$ifndef default_target_set}
  702. default_target(system_powerpc_linux);
  703. {$endif default_target_set}
  704. {$endif powerpc}
  705. {$ifdef POWERPC64}
  706. {$ifdef cpupowerpc64}
  707. default_target(source_info.system);
  708. {$define default_target_set}
  709. {$else cpupowerpc64}
  710. {$ifdef darwin}
  711. default_target(system_powerpc64_darwin);
  712. {$define default_target_set}
  713. {$endif}
  714. {$ifdef linux}
  715. default_target(system_powerpc64_linux);
  716. {$define default_target_set}
  717. {$endif}
  718. {$endif cpupowerpc64}
  719. {$ifndef default_target_set}
  720. default_target(system_powerpc64_linux);
  721. {$define default_target_set}
  722. {$endif}
  723. {$endif POWERPC64}
  724. {$ifdef sparc}
  725. {$ifdef cpusparc}
  726. default_target(source_info.system);
  727. {$else cpusparc}
  728. default_target(system_sparc_linux);
  729. {$endif cpusparc}
  730. {$endif sparc}
  731. {$ifdef arm}
  732. {$ifdef cpuarm}
  733. default_target(source_info.system);
  734. {$else cpuarm}
  735. {$ifdef WINDOWS}
  736. {$define default_target_set}
  737. default_target(system_arm_wince);
  738. {$endif}
  739. {$ifdef linux}
  740. {$define default_target_set}
  741. default_target(system_arm_linux);
  742. {$endif}
  743. {$ifdef darwin}
  744. {$define default_target_set}
  745. default_target(system_arm_darwin);
  746. {$endif}
  747. {$ifndef default_target_set}
  748. default_target(system_arm_linux);
  749. {$define default_target_set}
  750. {$endif}
  751. {$endif cpuarm}
  752. {$endif arm}
  753. {$ifdef avr}
  754. default_target(system_avr_embedded);
  755. {$endif avr}
  756. {$ifdef mips}
  757. {$ifdef mipsel}
  758. default_target(system_mipsel_linux);
  759. {$else mipsel}
  760. default_target(system_mips_linux);
  761. {$endif mipsel}
  762. {$endif mips}
  763. {$ifdef jvm}
  764. default_target(system_jvm_java32);
  765. {$endif jvm}
  766. end;
  767. initialization
  768. source_info.name:='';
  769. finalization
  770. DeregisterInfos;
  771. end.