systems.pas 28 KB

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