systems.pas 27 KB

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