systems.pas 32 KB

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