systems.pas 26 KB

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