systems.pas 29 KB

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