systems.pas 41 KB

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