systems.pas 32 KB

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