systems.pas 33 KB

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