systems.pas 35 KB

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