systems.pas 32 KB

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