2
0

systems.pas 31 KB

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