systems.pas 27 KB

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