systems.pas 27 KB

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