systems.pas 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. { all symbian systems }
  256. systems_symbian = [system_i386_symbian,system_arm_symbian];
  257. { all classic Mac OS targets }
  258. systems_macos = [system_m68k_macos,system_powerpc_macos];
  259. { all OS/2 targets }
  260. systems_os2 = [system_i386_OS2,system_i386_emx];
  261. { AROS systems }
  262. systems_aros = [system_i386_aros,system_x86_64_aros,system_arm_aros];
  263. { all amiga like systems }
  264. systems_amigalike = [system_m68k_amiga,system_powerpc_morphos,system_powerpc_amiga]+systems_aros;
  265. { all native nt systems }
  266. systems_nativent = [system_i386_nativent];
  267. { systems supporting Objective-C }
  268. systems_objc_supported = systems_darwin;
  269. { systems using the non-fragile Objective-C ABI }
  270. systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim];
  271. { systems supporting "blocks" }
  272. systems_blocks_supported = systems_darwin;
  273. { all systems supporting exports from programs or units }
  274. systems_unit_program_exports = [system_i386_win32,
  275. system_i386_wdosx,
  276. system_i386_Netware,
  277. system_i386_netwlibc,
  278. system_arm_wince,
  279. system_x86_64_win64,
  280. system_i8086_win16]+systems_linux+systems_android;
  281. { all systems that reference symbols in other binaries using indirect imports }
  282. systems_indirect_var_imports = systems_all_windows+[system_i386_nativent];
  283. { all systems that support indirect entry information }
  284. systems_indirect_entry_information = systems_darwin+[system_i386_win32,system_x86_64_win64,system_x86_64_linux];
  285. { all systems for which weak linking has been tested/is supported }
  286. systems_weak_linking = systems_darwin + systems_solaris + systems_linux + systems_android;
  287. systems_internal_sysinit = [system_i386_linux,system_i386_win32,system_x86_64_win64,
  288. system_powerpc64_linux,system_m68k_atari,system_sparc64_linux]+systems_darwin+systems_amigalike;
  289. { all systems that use garbage collection for reference-counted types }
  290. systems_garbage_collected_managed_types = [
  291. system_jvm_java32,
  292. system_jvm_android32
  293. ];
  294. { all systems that use a managed vm (-> no real pointers, internal VMT
  295. format, ...) }
  296. systems_managed_vm = [
  297. system_jvm_java32,
  298. system_jvm_android32
  299. ];
  300. { all systems based on the JVM }
  301. systems_jvm = [
  302. system_jvm_java32,
  303. system_jvm_android32
  304. ];
  305. { all systems where typed constants have to be translated into node
  306. trees that initialise the data instead of into data sections }
  307. systems_typed_constants_node_init = [
  308. system_jvm_java32,
  309. system_jvm_android32
  310. ];
  311. { all systems that don't use a built-in framepointer for accessing nested
  312. variables, but emulate it by wrapping nested variables in records
  313. whose address is passed around }
  314. systems_fpnestedstruct = [
  315. {$ifndef llvm}
  316. system_jvm_java32,
  317. system_jvm_android32
  318. {$else not llvm}
  319. low(tsystem)..high(tsystem)
  320. {$endif not llvm}
  321. ];
  322. { all systems where a value parameter passed by reference must be copied
  323. on the caller side rather than on the callee side }
  324. systems_caller_copy_addr_value_para = [system_aarch64_darwin,system_aarch64_linux];
  325. { pointer checking (requires special code in FPC_CHECKPOINTER,
  326. and can never work for libc-based targets or any other program
  327. linking to an external library)
  328. }
  329. systems_support_checkpointer = systems_linux
  330. + [system_i386_win32]
  331. + [system_i386_GO32V2]
  332. + [system_i386_os2]
  333. + [system_i386_beos,system_i386_haiku]
  334. + [system_powerpc_morphos];
  335. cpu2str : array[TSystemCpu] of string[10] =
  336. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  337. 'mips','arm', 'powerpc64', 'avr', 'mipsel','jvm', 'i8086',
  338. 'aarch64', 'wasm', 'sparc64');
  339. abiinfo : array[tabi] of tabiinfo = (
  340. (name: 'DEFAULT'; supported: true),
  341. (name: 'SYSV' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  342. (name: 'AIX' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  343. (name: 'DARWIN' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  344. (name: 'ELFV2' ; supported:{$if defined(powerpc64)}true{$else}false{$endif}),
  345. (name: 'EABI' ; supported:{$ifdef FPC_ARMEL}true{$else}false{$endif}),
  346. (name: 'ARMEB' ; supported:{$ifdef FPC_ARMEB}true{$else}false{$endif}),
  347. (name: 'EABIHF' ; supported:{$ifdef FPC_ARMHF}true{$else}false{$endif}),
  348. (name: 'OLDWIN32GNU'; supported:{$ifdef I386}true{$else}false{$endif}),
  349. (name: 'AARCH64IOS'; supported:{$ifdef aarch64}true{$else}false{$endif})
  350. );
  351. var
  352. targetinfos : array[tsystem] of psysteminfo;
  353. arinfos : array[tar] of parinfo;
  354. resinfos : array[tres] of presinfo;
  355. asminfos : array[tasm] of pasminfo;
  356. dbginfos : array[tdbg] of pdbginfo;
  357. source_info : tsysteminfo;
  358. target_cpu : tsystemcpu;
  359. target_info : tsysteminfo;
  360. target_asm : tasminfo;
  361. target_ar : tarinfo;
  362. target_res : tresinfo;
  363. target_dbg : tdbginfo;
  364. target_cpu_string,
  365. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  366. target_full_string : string[24];
  367. function set_target(t:tsystem):boolean;
  368. function set_target_asm(t:tasm):boolean;
  369. function set_target_ar(t:tar):boolean;
  370. function set_target_res(t:tres):boolean;
  371. function set_target_dbg(t:tdbg):boolean;
  372. function find_system_by_string(const s : string) : tsystem;
  373. function find_asm_by_string(const s : string) : tasm;
  374. function find_dbg_by_string(const s : string) : tdbg;
  375. procedure set_source_info(const ti : tsysteminfo);
  376. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  377. procedure RegisterTarget(const r:tsysteminfo);
  378. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  379. procedure RegisterAr(const r:tarinfo);
  380. procedure InitSystems;
  381. {$ifdef FreeBSD}
  382. function GetOSRelDate:Longint;
  383. {$endif}
  384. implementation
  385. uses
  386. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  387. {****************************************************************************
  388. OS runtime version detection utility routine
  389. ****************************************************************************}
  390. {$ifdef FreeBSD}
  391. function GetOSRelDate:Longint;
  392. { FPSysCtl first argument was of type pchar
  393. up to commit 35566 from 2017/03/11
  394. and corrected to pcint in that commit.
  395. But the following code needs to work with
  396. both old 3.0.X definition and new definition using pcint type.
  397. Problem solved using a special type called
  398. FPSysCtlFirstArgType. }
  399. {$ifdef VER3_0}
  400. type
  401. FPSysCtlFirstArgType = PChar;
  402. {$else}
  403. type
  404. FPSysCtlFirstArgType = pcint;
  405. {$endif}
  406. var
  407. mib : array[0..1] of cint;
  408. rval : cint;
  409. len : size_t;
  410. i : longint;
  411. v : longint;
  412. oerrno : cint;
  413. S : AnsiString;
  414. Begin
  415. s:='ab';
  416. SetLength(S,50);
  417. mib[0] := CTL_KERN;
  418. mib[1] := KERN_OSRELDATE;
  419. len := 4;
  420. oerrno:= fpgeterrno;
  421. if (FPsysctl(FPSysCtlFirstArgType(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  422. Begin
  423. if (fpgeterrno = ESysENOMEM) Then
  424. fpseterrno(oerrno);
  425. GetOSRelDate:=0;
  426. End
  427. else
  428. GetOSRelDate:=v;
  429. End;
  430. {$endif}
  431. {****************************************************************************
  432. Target setting
  433. ****************************************************************************}
  434. function set_target(t:tsystem):boolean;
  435. begin
  436. set_target:=false;
  437. if assigned(targetinfos[t]) then
  438. begin
  439. target_info:=targetinfos[t]^;
  440. set_target_asm(target_info.assem);
  441. set_target_ar(target_info.ar);
  442. set_target_res(target_info.res);
  443. set_target_dbg(target_info.dbg);
  444. target_cpu:=target_info.cpu;
  445. target_os_string:=lower(target_info.shortname);
  446. target_cpu_string:=cpu2str[target_cpu];
  447. target_full_string:=target_cpu_string+'-'+target_os_string;
  448. set_target:=true;
  449. exit;
  450. end;
  451. end;
  452. function set_target_asm(t:tasm):boolean;
  453. begin
  454. set_target_asm:=false;
  455. if assigned(asminfos[t]) and
  456. ((target_info.system in asminfos[t]^.supported_targets) or
  457. (system_any in asminfos[t]^.supported_targets)) then
  458. begin
  459. target_asm:=asminfos[t]^;
  460. set_target_asm:=true;
  461. exit;
  462. end;
  463. end;
  464. function set_target_ar(t:tar):boolean;
  465. begin
  466. result:=false;
  467. if assigned(arinfos[t]) then
  468. begin
  469. target_ar:=arinfos[t]^;
  470. result:=true;
  471. exit;
  472. end;
  473. end;
  474. function set_target_res(t:tres):boolean;
  475. begin
  476. result:=false;
  477. if assigned(resinfos[t]) then
  478. begin
  479. target_res:=resinfos[t]^;
  480. result:=true;
  481. exit;
  482. end
  483. else
  484. FillByte(target_res,sizeof(target_res),0);
  485. end;
  486. function set_target_dbg(t:tdbg):boolean;
  487. begin
  488. result:=false;
  489. { no debugging support for llvm yet }
  490. {$ifndef llvm}
  491. if assigned(dbginfos[t]) then
  492. begin
  493. target_dbg:=dbginfos[t]^;
  494. result:=true;
  495. exit;
  496. end;
  497. {$endif}
  498. end;
  499. function find_system_by_string(const s : string) : tsystem;
  500. var
  501. hs : string;
  502. t : tsystem;
  503. begin
  504. result:=system_none;
  505. hs:=upper(s);
  506. for t:=low(tsystem) to high(tsystem) do
  507. if assigned(targetinfos[t]) and
  508. (upper(targetinfos[t]^.shortname)=hs) then
  509. begin
  510. result:=t;
  511. exit;
  512. end;
  513. end;
  514. function find_asm_by_string(const s : string) : tasm;
  515. var
  516. hs : string;
  517. t : tasm;
  518. begin
  519. result:=as_none;
  520. hs:=upper(s);
  521. for t:=low(tasm) to high(tasm) do
  522. if assigned(asminfos[t]) and
  523. (asminfos[t]^.idtxt=hs) then
  524. begin
  525. result:=t;
  526. exit;
  527. end;
  528. end;
  529. function find_dbg_by_string(const s : string) : tdbg;
  530. var
  531. hs : string;
  532. t : tdbg;
  533. begin
  534. result:=dbg_none;
  535. hs:=upper(s);
  536. for t:=low(tdbg) to high(tdbg) do
  537. if assigned(dbginfos[t]) and
  538. (dbginfos[t]^.idtxt=hs) then
  539. begin
  540. result:=t;
  541. exit;
  542. end;
  543. end;
  544. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  545. begin
  546. result:=true;
  547. with d do
  548. begin
  549. if (s.procalign in [1,2,4,8,16,32,64,128]) or (s.procalign=256) then
  550. procalign:=s.procalign
  551. else if s.procalign<>0 then
  552. result:=false;
  553. if (s.loopalign in [1,2,4,8,16,32,64,128]) or (s.loopalign=256) then
  554. loopalign:=s.loopalign
  555. else if s.loopalign<>0 then
  556. result:=false;
  557. if (s.jumpalign in [1,2,4,8,16,32,64,128]) or (s.jumpalign=256) then
  558. jumpalign:=s.jumpalign
  559. else if s.jumpalign<>0 then
  560. result:=false;
  561. { general update rules:
  562. minimum: if higher then update
  563. maximum: if lower then update or if undefined then update }
  564. if s.constalignmin>constalignmin then
  565. constalignmin:=s.constalignmin;
  566. if (constalignmax=0) or
  567. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  568. constalignmax:=s.constalignmax;
  569. if s.varalignmin>varalignmin then
  570. varalignmin:=s.varalignmin;
  571. if (varalignmax=0) or
  572. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  573. varalignmax:=s.varalignmax;
  574. if s.localalignmin>localalignmin then
  575. localalignmin:=s.localalignmin;
  576. if (localalignmax=0) or
  577. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  578. localalignmax:=s.localalignmax;
  579. if s.recordalignmin>recordalignmin then
  580. recordalignmin:=s.recordalignmin;
  581. if (recordalignmax=0) or
  582. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  583. recordalignmax:=s.recordalignmax;
  584. if (maxCrecordalign=0) or
  585. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  586. maxCrecordalign:=s.maxCrecordalign;
  587. end;
  588. end;
  589. {****************************************************************************
  590. Target registration
  591. ****************************************************************************}
  592. procedure RegisterTarget(const r:tsysteminfo);
  593. var
  594. t : tsystem;
  595. begin
  596. t:=r.system;
  597. if assigned(targetinfos[t]) then
  598. writeln('Warning: Target is already registered!')
  599. else
  600. new(targetinfos[t]);
  601. targetinfos[t]^:=r;
  602. end;
  603. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  604. var
  605. t : tres;
  606. begin
  607. t:=r.id;
  608. if not assigned(resinfos[t]) then
  609. new(resinfos[t]);
  610. resinfos[t]^:=r;
  611. resinfos[t]^.resourcefileclass:=rcf;
  612. end;
  613. procedure RegisterAr(const r:tarinfo);
  614. var
  615. t : tar;
  616. begin
  617. t:=r.id;
  618. if assigned(arinfos[t]) then
  619. writeln('Warning: ar is already registered!')
  620. else
  621. new(arinfos[t]);
  622. arinfos[t]^:=r;
  623. end;
  624. procedure DeregisterInfos;
  625. var
  626. assem : tasm;
  627. target : tsystem;
  628. ar : tar;
  629. res : tres;
  630. dbg : tdbg;
  631. begin
  632. for target:=low(tsystem) to high(tsystem) do
  633. if assigned(targetinfos[target]) then
  634. begin
  635. freemem(targetinfos[target],sizeof(tsysteminfo));
  636. targetinfos[target]:=nil;
  637. end;
  638. for assem:=low(tasm) to high(tasm) do
  639. if assigned(asminfos[assem]) then
  640. begin
  641. freemem(asminfos[assem],sizeof(tasminfo));
  642. asminfos[assem]:=nil;
  643. end;
  644. for ar:=low(tar) to high(tar) do
  645. if assigned(arinfos[ar]) then
  646. begin
  647. freemem(arinfos[ar],sizeof(tarinfo));
  648. arinfos[ar]:=nil;
  649. end;
  650. for res:=low(tres) to high(tres) do
  651. if assigned(resinfos[res]) then
  652. begin
  653. freemem(resinfos[res],sizeof(tresinfo));
  654. resinfos[res]:=nil;
  655. end;
  656. for dbg:=low(tdbg) to high(tdbg) do
  657. if assigned(dbginfos[dbg]) then
  658. begin
  659. freemem(dbginfos[dbg],sizeof(tdbginfo));
  660. dbginfos[dbg]:=nil;
  661. end;
  662. end;
  663. {****************************************************************************
  664. Initialization of default target
  665. ****************************************************************************}
  666. procedure default_target(t:tsystem);
  667. begin
  668. set_target(t);
  669. if source_info.name='' then
  670. source_info:=target_info;
  671. end;
  672. procedure set_source_info(const ti : tsysteminfo);
  673. begin
  674. { can't use message() here (PFV) }
  675. if source_info.name<>'' then
  676. Writeln('Warning: Source OS Redefined!');
  677. source_info:=ti;
  678. end;
  679. procedure InitSystems;
  680. begin
  681. { Now default target, this is dependent on the target cpu define,
  682. when the define is the same as the source cpu then we use the source
  683. os, else we pick a default }
  684. {$ifdef i386}
  685. {$ifdef cpui386}
  686. default_target(source_info.system);
  687. {$define default_target_set}
  688. {$else cpui386}
  689. {$ifdef linux}
  690. default_target(system_i386_linux);
  691. {$define default_target_set}
  692. {$endif}
  693. {$ifdef freebsd}
  694. default_target(system_i386_freebsd);
  695. {$define default_target_set}
  696. {$endif}
  697. {$ifdef openbsd}
  698. default_target(system_i386_openbsd);
  699. {$define default_target_set}
  700. {$endif}
  701. {$ifdef darwin}
  702. default_target(system_i386_darwin);
  703. {$define default_target_set}
  704. {$endif}
  705. {$ifdef android}
  706. {$define default_target_set}
  707. default_target(system_i386_android);
  708. {$endif}
  709. {$ifdef solaris}
  710. {$define default_target_set}
  711. default_target(system_i386_solaris);
  712. {$endif}
  713. {$endif cpui386}
  714. { default is linux }
  715. {$ifndef default_target_set}
  716. default_target(system_i386_linux);
  717. {$endif default_target_set}
  718. {$endif i386}
  719. {$ifdef x86_64}
  720. {$ifdef cpux86_64}
  721. default_target(source_info.system);
  722. {$define default_target_set}
  723. {$else cpux86_64}
  724. {$ifdef MSWindows}
  725. default_target(system_x86_64_win64);
  726. {$define default_target_set}
  727. {$endif}
  728. {$ifdef linux}
  729. default_target(system_x86_64_linux);
  730. {$define default_target_set}
  731. {$endif}
  732. {$ifdef dragonfly}
  733. default_target(system_x86_64_dragonfly);
  734. {$define default_target_set}
  735. {$endif}
  736. {$ifdef freebsd}
  737. default_target(system_x86_64_freebsd);
  738. {$define default_target_set}
  739. {$endif}
  740. {$ifdef openbsd}
  741. default_target(system_x86_64_openbsd);
  742. {$define default_target_set}
  743. {$endif}
  744. {$ifdef netbsd}
  745. default_target(system_x86_64_netbsd);
  746. {$define default_target_set}
  747. {$endif}
  748. {$ifdef solaris}
  749. default_target(system_x86_64_solaris);
  750. {$define default_target_set}
  751. {$endif}
  752. {$ifdef darwin}
  753. default_target(system_x86_64_darwin);
  754. {$define default_target_set}
  755. {$endif}
  756. {$endif cpux86_64}
  757. { default is linux }
  758. {$ifndef default_target_set}
  759. default_target(system_x86_64_linux);
  760. {$endif default_target_set}
  761. {$endif x86_64}
  762. {$ifdef m68k}
  763. {$ifdef cpu68}
  764. default_target(source_info.system);
  765. {$else cpu68}
  766. default_target(system_m68k_linux);
  767. {$endif cpu68}
  768. {$endif m68k}
  769. {$ifdef powerpc}
  770. {$ifdef cpupowerpc32}
  771. default_target(source_info.system);
  772. {$define default_target_set}
  773. {$else cpupowerpc}
  774. {$ifdef linux}
  775. default_target(system_powerpc_linux);
  776. {$define default_target_set}
  777. {$endif}
  778. {$ifdef darwin}
  779. default_target(system_powerpc_darwin);
  780. {$define default_target_set}
  781. {$endif}
  782. {$endif cpupowerpc}
  783. {$ifdef aix}
  784. default_target(system_powerpc_aix);
  785. {$define default_target_set}
  786. {$endif}
  787. {$ifndef default_target_set}
  788. default_target(system_powerpc_linux);
  789. {$endif default_target_set}
  790. {$endif powerpc}
  791. {$ifdef POWERPC64}
  792. {$ifdef cpupowerpc64}
  793. default_target(source_info.system);
  794. {$define default_target_set}
  795. {$else cpupowerpc64}
  796. {$ifdef darwin}
  797. default_target(system_powerpc64_darwin);
  798. {$define default_target_set}
  799. {$endif}
  800. {$ifdef linux}
  801. default_target(system_powerpc64_linux);
  802. {$define default_target_set}
  803. {$endif}
  804. {$ifdef aix}
  805. default_target(system_powerpc64_aix);
  806. {$define default_target_set}
  807. {$endif}
  808. {$endif cpupowerpc64}
  809. {$ifndef default_target_set}
  810. default_target(system_powerpc64_linux);
  811. {$define default_target_set}
  812. {$endif}
  813. {$endif POWERPC64}
  814. {$ifdef sparc}
  815. {$ifdef cpusparc}
  816. default_target(source_info.system);
  817. {$else cpusparc}
  818. {$ifdef solaris}
  819. {$define default_target_set}
  820. default_target(system_sparc_solaris);
  821. {$endif}
  822. {$ifndef default_target_set}
  823. default_target(system_sparc_linux);
  824. {$endif ndef default_target_set}
  825. {$endif cpusparc}
  826. {$endif sparc}
  827. {$ifdef sparc64}
  828. {$ifdef cpusparc64}
  829. default_target(source_info.system);
  830. {$else cpusparc64}
  831. {$ifdef solaris}
  832. {$define default_target_set}
  833. default_target(system_sparc64_solaris);
  834. {$endif}
  835. {$ifndef default_target_set}
  836. default_target(system_sparc64_linux);
  837. {$endif ndef default_target_set}
  838. {$endif cpusparc64}
  839. {$endif sparc64}
  840. {$ifdef arm}
  841. {$ifdef cpuarm}
  842. default_target(source_info.system);
  843. {$else cpuarm}
  844. {$ifdef WINDOWS}
  845. {$define default_target_set}
  846. default_target(system_arm_wince);
  847. {$endif}
  848. {$ifdef linux}
  849. {$define default_target_set}
  850. default_target(system_arm_linux);
  851. {$endif}
  852. {$ifdef android}
  853. {$define default_target_set}
  854. default_target(system_arm_android);
  855. {$endif}
  856. {$ifdef darwin}
  857. {$define default_target_set}
  858. default_target(system_arm_darwin);
  859. {$endif}
  860. {$ifndef default_target_set}
  861. default_target(system_arm_linux);
  862. {$define default_target_set}
  863. {$endif}
  864. {$endif cpuarm}
  865. {$endif arm}
  866. {$ifdef avr}
  867. default_target(system_avr_embedded);
  868. {$endif avr}
  869. {$ifdef mips}
  870. {$ifdef mipsel}
  871. {$ifdef cpumipsel}
  872. default_target(source_info.system);
  873. {$else cpumipsel}
  874. default_target(system_mipsel_linux);
  875. {$endif cpumipsel}
  876. {$else mipsel}
  877. default_target(system_mipseb_linux);
  878. {$endif mipsel}
  879. {$endif mips}
  880. {$ifdef jvm}
  881. default_target(system_jvm_java32);
  882. {$endif jvm}
  883. {$ifdef i8086}
  884. default_target(system_i8086_msdos);
  885. {$endif i8086}
  886. {$ifdef aarch64}
  887. {$ifdef cpuaarch64}
  888. default_target(source_info.system);
  889. {$else cpuaarch64}
  890. {$ifdef darwin}
  891. {$define default_target_set}
  892. default_target(system_aarch64_darwin);
  893. {$endif darwin}
  894. {$ifndef default_target_set}
  895. default_target(system_aarch64_linux);
  896. {$define default_target_set}
  897. {$endif}
  898. {$endif cpuaarch64}
  899. {$endif aarch64}
  900. {$ifdef wasm}
  901. default_target(system_wasm_wasm32);
  902. {$endif}
  903. end;
  904. initialization
  905. source_info.name:='';
  906. finalization
  907. DeregisterInfos;
  908. end.