systems.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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,
  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 : string[4];
  151. objext : string[6];
  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. { stack alignment }
  186. stackalign : byte;
  187. abi : tabi;
  188. end;
  189. const
  190. { alias for supported_target field in tasminfo }
  191. system_any = system_none;
  192. systems_wince = [system_arm_wince,system_i386_wince];
  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;
  256. { all systems for which weak linking has been tested/is supported }
  257. systems_weak_linking = systems_darwin + systems_solaris + systems_linux;
  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');
  291. abi2str : array[tabi] of string[10] =
  292. ('DEFAULT','SYSV','AIX','EABI','ARMEB','EABIHF');
  293. var
  294. targetinfos : array[tsystem] of psysteminfo;
  295. arinfos : array[tar] of parinfo;
  296. resinfos : array[tres] of presinfo;
  297. asminfos : array[tasm] of pasminfo;
  298. dbginfos : array[tdbg] of pdbginfo;
  299. source_info : tsysteminfo;
  300. target_cpu : tsystemcpu;
  301. target_info : tsysteminfo;
  302. target_asm : tasminfo;
  303. target_ar : tarinfo;
  304. target_res : tresinfo;
  305. target_dbg : tdbginfo;
  306. target_cpu_string,
  307. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  308. target_full_string : string[24];
  309. function set_target(t:tsystem):boolean;
  310. function set_target_asm(t:tasm):boolean;
  311. function set_target_ar(t:tar):boolean;
  312. function set_target_res(t:tres):boolean;
  313. function set_target_dbg(t:tdbg):boolean;
  314. function find_system_by_string(const s : string) : tsystem;
  315. function find_asm_by_string(const s : string) : tasm;
  316. function find_dbg_by_string(const s : string) : tdbg;
  317. procedure set_source_info(const ti : tsysteminfo);
  318. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  319. procedure RegisterTarget(const r:tsysteminfo);
  320. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  321. procedure RegisterAr(const r:tarinfo);
  322. { Register the external linker. This routine is called to setup the
  323. class to use for the linker. It returns the tsysteminfo structure
  324. updated with the correct linker class for external linking.
  325. }
  326. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  327. { Register the internal linker. This routine is called to setup the
  328. class to use for the linker. It returns the tsysteminfo structure
  329. updated with the correct linker class for internal linking.
  330. If internal linking is not supported, this class can be set
  331. to nil.
  332. }
  333. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  334. procedure InitSystems;
  335. {$ifdef FreeBSD}
  336. function GetOSRelDate:Longint;
  337. {$endif}
  338. implementation
  339. uses
  340. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  341. {****************************************************************************
  342. OS runtime version detection utility routine
  343. ****************************************************************************}
  344. {$ifdef FreeBSD}
  345. function GetOSRelDate:Longint;
  346. var
  347. mib : array[0..1] of cint;
  348. rval : cint;
  349. len : size_t;
  350. i : longint;
  351. v : longint;
  352. oerrno : cint;
  353. S : AnsiString;
  354. Begin
  355. s:='ab';
  356. SetLength(S,50);
  357. mib[0] := CTL_KERN;
  358. mib[1] := KERN_OSRELDATE;
  359. len := 4;
  360. oerrno:= fpgeterrno;
  361. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  362. Begin
  363. if (fpgeterrno = ESysENOMEM) Then
  364. fpseterrno(oerrno);
  365. GetOSRelDate:=0;
  366. End
  367. else
  368. GetOSRelDate:=v;
  369. End;
  370. {$endif}
  371. {****************************************************************************
  372. Target setting
  373. ****************************************************************************}
  374. function set_target(t:tsystem):boolean;
  375. begin
  376. set_target:=false;
  377. if assigned(targetinfos[t]) then
  378. begin
  379. target_info:=targetinfos[t]^;
  380. set_target_asm(target_info.assem);
  381. set_target_ar(target_info.ar);
  382. set_target_res(target_info.res);
  383. set_target_dbg(target_info.dbg);
  384. target_cpu:=target_info.cpu;
  385. target_os_string:=lower(target_info.shortname);
  386. target_cpu_string:=cpu2str[target_cpu];
  387. target_full_string:=target_cpu_string+'-'+target_os_string;
  388. set_target:=true;
  389. exit;
  390. end;
  391. end;
  392. function set_target_asm(t:tasm):boolean;
  393. begin
  394. set_target_asm:=false;
  395. if assigned(asminfos[t]) and
  396. ((target_info.system in asminfos[t]^.supported_targets) or
  397. (system_any in asminfos[t]^.supported_targets)) then
  398. begin
  399. target_asm:=asminfos[t]^;
  400. set_target_asm:=true;
  401. exit;
  402. end;
  403. end;
  404. function set_target_ar(t:tar):boolean;
  405. begin
  406. result:=false;
  407. if assigned(arinfos[t]) then
  408. begin
  409. target_ar:=arinfos[t]^;
  410. result:=true;
  411. exit;
  412. end;
  413. end;
  414. function set_target_res(t:tres):boolean;
  415. begin
  416. result:=false;
  417. if assigned(resinfos[t]) then
  418. begin
  419. target_res:=resinfos[t]^;
  420. result:=true;
  421. exit;
  422. end
  423. else
  424. FillByte(target_res,sizeof(target_res),0);
  425. end;
  426. function set_target_dbg(t:tdbg):boolean;
  427. begin
  428. result:=false;
  429. if assigned(dbginfos[t]) then
  430. begin
  431. target_dbg:=dbginfos[t]^;
  432. result:=true;
  433. exit;
  434. end;
  435. end;
  436. function find_system_by_string(const s : string) : tsystem;
  437. var
  438. hs : string;
  439. t : tsystem;
  440. begin
  441. result:=system_none;
  442. hs:=upper(s);
  443. for t:=low(tsystem) to high(tsystem) do
  444. if assigned(targetinfos[t]) and
  445. (upper(targetinfos[t]^.shortname)=hs) then
  446. begin
  447. result:=t;
  448. exit;
  449. end;
  450. end;
  451. function find_asm_by_string(const s : string) : tasm;
  452. var
  453. hs : string;
  454. t : tasm;
  455. begin
  456. result:=as_none;
  457. hs:=upper(s);
  458. for t:=low(tasm) to high(tasm) do
  459. if assigned(asminfos[t]) and
  460. (asminfos[t]^.idtxt=hs) then
  461. begin
  462. result:=t;
  463. exit;
  464. end;
  465. end;
  466. function find_dbg_by_string(const s : string) : tdbg;
  467. var
  468. hs : string;
  469. t : tdbg;
  470. begin
  471. result:=dbg_none;
  472. hs:=upper(s);
  473. for t:=low(tdbg) to high(tdbg) do
  474. if assigned(dbginfos[t]) and
  475. (dbginfos[t]^.idtxt=hs) then
  476. begin
  477. result:=t;
  478. exit;
  479. end;
  480. end;
  481. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  482. begin
  483. result:=true;
  484. with d do
  485. begin
  486. if (s.procalign in [1,2,4,8,16,32,64,128]) or (s.procalign=256) then
  487. procalign:=s.procalign
  488. else if s.procalign<>0 then
  489. result:=false;
  490. if (s.loopalign in [1,2,4,8,16,32,64,128]) or (s.loopalign=256) then
  491. loopalign:=s.loopalign
  492. else if s.loopalign<>0 then
  493. result:=false;
  494. if (s.jumpalign in [1,2,4,8,16,32,64,128]) or (s.jumpalign=256) then
  495. jumpalign:=s.jumpalign
  496. else if s.jumpalign<>0 then
  497. result:=false;
  498. { general update rules:
  499. minimum: if higher then update
  500. maximum: if lower then update or if undefined then update }
  501. if s.constalignmin>constalignmin then
  502. constalignmin:=s.constalignmin;
  503. if (constalignmax=0) or
  504. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  505. constalignmax:=s.constalignmax;
  506. if s.varalignmin>varalignmin then
  507. varalignmin:=s.varalignmin;
  508. if (varalignmax=0) or
  509. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  510. varalignmax:=s.varalignmax;
  511. if s.localalignmin>localalignmin then
  512. localalignmin:=s.localalignmin;
  513. if (localalignmax=0) or
  514. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  515. localalignmax:=s.localalignmax;
  516. if s.recordalignmin>recordalignmin then
  517. recordalignmin:=s.recordalignmin;
  518. if (recordalignmax=0) or
  519. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  520. recordalignmax:=s.recordalignmax;
  521. if (maxCrecordalign=0) or
  522. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  523. maxCrecordalign:=s.maxCrecordalign;
  524. end;
  525. end;
  526. {****************************************************************************
  527. Target registration
  528. ****************************************************************************}
  529. procedure RegisterTarget(const r:tsysteminfo);
  530. var
  531. t : tsystem;
  532. begin
  533. t:=r.system;
  534. if assigned(targetinfos[t]) then
  535. writeln('Warning: Target is already registered!')
  536. else
  537. Getmem(targetinfos[t],sizeof(tsysteminfo));
  538. targetinfos[t]^:=r;
  539. end;
  540. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  541. var
  542. t : tres;
  543. begin
  544. t:=r.id;
  545. if not assigned(resinfos[t]) then
  546. Getmem(resinfos[t],sizeof(tresinfo));
  547. resinfos[t]^:=r;
  548. resinfos[t]^.resourcefileclass:=rcf;
  549. end;
  550. procedure RegisterAr(const r:tarinfo);
  551. var
  552. t : tar;
  553. begin
  554. t:=r.id;
  555. if assigned(arinfos[t]) then
  556. writeln('Warning: ar is already registered!')
  557. else
  558. Getmem(arinfos[t],sizeof(tarinfo));
  559. arinfos[t]^:=r;
  560. end;
  561. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  562. begin
  563. system_info.linkextern := c;
  564. end;
  565. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  566. begin
  567. system_info.link := c;
  568. end;
  569. procedure DeregisterInfos;
  570. var
  571. assem : tasm;
  572. target : tsystem;
  573. ar : tar;
  574. res : tres;
  575. dbg : tdbg;
  576. begin
  577. for target:=low(tsystem) to high(tsystem) do
  578. if assigned(targetinfos[target]) then
  579. begin
  580. freemem(targetinfos[target],sizeof(tsysteminfo));
  581. targetinfos[target]:=nil;
  582. end;
  583. for assem:=low(tasm) to high(tasm) do
  584. if assigned(asminfos[assem]) then
  585. begin
  586. freemem(asminfos[assem],sizeof(tasminfo));
  587. asminfos[assem]:=nil;
  588. end;
  589. for ar:=low(tar) to high(tar) do
  590. if assigned(arinfos[ar]) then
  591. begin
  592. freemem(arinfos[ar],sizeof(tarinfo));
  593. arinfos[ar]:=nil;
  594. end;
  595. for res:=low(tres) to high(tres) do
  596. if assigned(resinfos[res]) then
  597. begin
  598. freemem(resinfos[res],sizeof(tresinfo));
  599. resinfos[res]:=nil;
  600. end;
  601. for dbg:=low(tdbg) to high(tdbg) do
  602. if assigned(dbginfos[dbg]) then
  603. begin
  604. freemem(dbginfos[dbg],sizeof(tdbginfo));
  605. dbginfos[dbg]:=nil;
  606. end;
  607. end;
  608. {****************************************************************************
  609. Initialization of default target
  610. ****************************************************************************}
  611. procedure default_target(t:tsystem);
  612. begin
  613. set_target(t);
  614. if source_info.name='' then
  615. source_info:=target_info;
  616. end;
  617. procedure set_source_info(const ti : tsysteminfo);
  618. begin
  619. { can't use message() here (PFV) }
  620. if source_info.name<>'' then
  621. Writeln('Warning: Source OS Redefined!');
  622. source_info:=ti;
  623. end;
  624. procedure InitSystems;
  625. begin
  626. { Now default target, this is dependent on the target cpu define,
  627. when the define is the same as the source cpu then we use the source
  628. os, else we pick a default }
  629. {$ifdef i386}
  630. {$ifdef cpu86}
  631. default_target(source_info.system);
  632. {$define default_target_set}
  633. {$else cpu86}
  634. {$ifdef linux}
  635. default_target(system_i386_linux);
  636. {$define default_target_set}
  637. {$endif}
  638. {$ifdef freebsd}
  639. default_target(system_i386_freebsd);
  640. {$define default_target_set}
  641. {$endif}
  642. {$ifdef openbsd}
  643. default_target(system_i386_openbsd);
  644. {$define default_target_set}
  645. {$endif}
  646. {$ifdef darwin}
  647. default_target(system_i386_darwin);
  648. {$define default_target_set}
  649. {$endif}
  650. {$endif cpu86}
  651. { default is linux }
  652. {$ifndef default_target_set}
  653. default_target(system_i386_linux);
  654. {$endif default_target_set}
  655. {$endif i386}
  656. {$ifdef x86_64}
  657. {$ifdef cpux86_64}
  658. default_target(source_info.system);
  659. {$define default_target_set}
  660. {$else cpux86_64}
  661. {$ifdef MSWindows}
  662. default_target(system_x86_64_win64);
  663. {$define default_target_set}
  664. {$endif}
  665. {$ifdef linux}
  666. default_target(system_x86_64_linux);
  667. {$define default_target_set}
  668. {$endif}
  669. {$ifdef freebsd}
  670. default_target(system_x86_64_freebsd);
  671. {$define default_target_set}
  672. {$endif}
  673. {$ifdef openbsd}
  674. default_target(system_x86_64_openbsd);
  675. {$define default_target_set}
  676. {$endif}
  677. {$ifdef netbsd}
  678. default_target(system_x86_64_netbsd);
  679. {$define default_target_set}
  680. {$endif}
  681. {$ifdef solaris}
  682. default_target(system_x86_64_solaris);
  683. {$define default_target_set}
  684. {$endif}
  685. {$ifdef darwin}
  686. default_target(system_x86_64_darwin);
  687. {$define default_target_set}
  688. {$endif}
  689. {$endif cpux86_64}
  690. { default is linux }
  691. {$ifndef default_target_set}
  692. default_target(system_x86_64_linux);
  693. {$endif default_target_set}
  694. {$endif x86_64}
  695. {$ifdef m68k}
  696. {$ifdef cpu68}
  697. default_target(source_info.system);
  698. {$else cpu68}
  699. default_target(system_m68k_linux);
  700. {$endif cpu68}
  701. {$endif m68k}
  702. {$ifdef alpha}
  703. {$ifdef cpualpha}
  704. default_target(source_info.system);
  705. {$else cpualpha}
  706. default_target(system_alpha_linux);
  707. {$endif cpualpha}
  708. {$endif alpha}
  709. {$ifdef powerpc}
  710. {$ifdef cpupowerpc}
  711. default_target(source_info.system);
  712. {$define default_target_set}
  713. {$else cpupowerpc}
  714. {$ifdef linux}
  715. default_target(system_powerpc_linux);
  716. {$define default_target_set}
  717. {$endif}
  718. {$ifdef darwin}
  719. default_target(system_powerpc_darwin);
  720. {$define default_target_set}
  721. {$endif}
  722. {$endif cpupowerpc}
  723. {$ifdef aix}
  724. default_target(system_powerpc_aix);
  725. {$define default_target_set}
  726. {$endif}
  727. {$ifndef default_target_set}
  728. default_target(system_powerpc_linux);
  729. {$endif default_target_set}
  730. {$endif powerpc}
  731. {$ifdef POWERPC64}
  732. {$ifdef cpupowerpc64}
  733. default_target(source_info.system);
  734. {$define default_target_set}
  735. {$else cpupowerpc64}
  736. {$ifdef darwin}
  737. default_target(system_powerpc64_darwin);
  738. {$define default_target_set}
  739. {$endif}
  740. {$ifdef linux}
  741. default_target(system_powerpc64_linux);
  742. {$define default_target_set}
  743. {$endif}
  744. {$ifdef aix}
  745. default_target(system_powerpc64_aix);
  746. {$define default_target_set}
  747. {$endif}
  748. {$endif cpupowerpc64}
  749. {$ifndef default_target_set}
  750. default_target(system_powerpc64_linux);
  751. {$define default_target_set}
  752. {$endif}
  753. {$endif POWERPC64}
  754. {$ifdef sparc}
  755. {$ifdef cpusparc}
  756. default_target(source_info.system);
  757. {$else cpusparc}
  758. default_target(system_sparc_linux);
  759. {$endif cpusparc}
  760. {$endif sparc}
  761. {$ifdef arm}
  762. {$ifdef cpuarm}
  763. default_target(source_info.system);
  764. {$else cpuarm}
  765. {$ifdef WINDOWS}
  766. {$define default_target_set}
  767. default_target(system_arm_wince);
  768. {$endif}
  769. {$ifdef linux}
  770. {$define default_target_set}
  771. default_target(system_arm_linux);
  772. {$endif}
  773. {$ifdef darwin}
  774. {$define default_target_set}
  775. default_target(system_arm_darwin);
  776. {$endif}
  777. {$ifndef default_target_set}
  778. default_target(system_arm_linux);
  779. {$define default_target_set}
  780. {$endif}
  781. {$endif cpuarm}
  782. {$endif arm}
  783. {$ifdef avr}
  784. default_target(system_avr_embedded);
  785. {$endif avr}
  786. {$ifdef mips}
  787. {$ifdef mipsel}
  788. default_target(system_mipsel_linux);
  789. {$else mipsel}
  790. default_target(system_mipseb_linux);
  791. {$endif mipsel}
  792. {$endif mips}
  793. {$ifdef jvm}
  794. default_target(system_jvm_java32);
  795. {$endif jvm}
  796. end;
  797. initialization
  798. source_info.name:='';
  799. finalization
  800. DeregisterInfos;
  801. end.