systems.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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_has_winlike_resources,
  123. tf_safecall_clearstack, // With this flag set, after safecall calls the caller cleans up the stack
  124. tf_safecall_exceptions, // Exceptions in safecall calls are not raised, but passed to the caller as an ordinal (hresult) in the function result.
  125. // The original result (if it exists) is passed as an extra parameter
  126. tf_no_backquote_support,
  127. { do not generate an object file when smartlinking is turned on,
  128. this is usefull for architectures which require a small code footprint }
  129. tf_no_objectfiles_when_smartlinking,
  130. { indicates that the default value of the ts_cld target switch is 'on' for this target }
  131. tf_cld,
  132. { indicates that the default value of the ts_x86_far_procs_push_odd_bp target switch is 'on' for this target }
  133. tf_x86_far_procs_push_odd_bp,
  134. { indicates that this target can use dynamic packages otherwise an
  135. error will be generated if a package file is compiled }
  136. tf_supports_packages
  137. );
  138. psysteminfo = ^tsysteminfo;
  139. { using packed causes bus errors on processors which require alignment }
  140. tsysteminfo = record
  141. system : tsystem;
  142. name : string[34];
  143. shortname : string[9];
  144. flags : set of tsystemflags;
  145. cpu : tsystemcpu;
  146. unit_env : string[16];
  147. extradefines : string[40];
  148. exeext,
  149. defext,
  150. scriptext,
  151. smartext,
  152. unitext,
  153. unitlibext,
  154. asmext : string[4];
  155. objext : string[6];
  156. resext : string[4];
  157. resobjext : string[7];
  158. sharedlibext : string[10];
  159. staticlibext,
  160. staticlibprefix : string[4];
  161. sharedlibprefix : string[4];
  162. sharedClibext : string[10];
  163. staticClibext,
  164. staticClibprefix : string[4];
  165. sharedClibprefix : string[4];
  166. importlibprefix : string[10];
  167. importlibext : string[4];
  168. Cprefix : string[2];
  169. newline : string[2];
  170. dirsep : char;
  171. assem : tasm;
  172. assemextern : tasm; { external assembler, used by -a }
  173. link : tlink;
  174. linkextern : tlink; { external linker, used by -s }
  175. ar : tar;
  176. res : tres;
  177. dbg : tdbg;
  178. script : tscripttype;
  179. endian : tendian;
  180. alignment : talignmentinfo;
  181. {
  182. Offset from the argument pointer register to the first
  183. argument's address. On some machines it may depend on
  184. the data type of the function.
  185. (see also FIRST_PARM_OFFSET in GCC source)
  186. }
  187. first_parm_offset : longint;
  188. stacksize : longint;
  189. { stack alignment }
  190. stackalign : byte;
  191. abi : tabi;
  192. { llvm -- varies wildly in length and is empty for many targets ->
  193. ansistring instead of shortstring; tsysteminfo records aren't
  194. copied very often anyway. These strings come from the file
  195. lib/Basic/Targets.cpp in the clang (cfe 3.3) source tree, sometimes
  196. adapted to match our (custom) stack alignment requirements }
  197. llvmdatalayout: ansistring;
  198. end;
  199. tabiinfo = record
  200. name: string[11];
  201. supported: boolean;
  202. end;
  203. const
  204. { alias for supported_target field in tasminfo }
  205. system_any = system_none;
  206. systems_wince = [system_arm_wince,system_i386_wince];
  207. systems_android = [system_arm_android, system_i386_android, system_mipsel_android];
  208. systems_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
  209. system_arm_linux,system_sparc_linux,system_m68k_linux,
  210. system_x86_6432_linux,system_mipseb_linux,system_mipsel_linux,system_aarch64_linux];
  211. systems_dragonfly = [system_x86_64_dragonfly];
  212. systems_freebsd = [system_i386_freebsd,
  213. system_x86_64_freebsd];
  214. systems_netbsd = [system_i386_netbsd,
  215. system_m68k_netbsd,
  216. system_powerpc_netbsd,
  217. system_x86_64_netbsd];
  218. systems_openbsd = [system_i386_openbsd,
  219. system_m68k_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,system_vm_embedded,
  241. 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_spc32_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_Mac,system_powerpc_Macos];
  259. { all OS/2 targets }
  260. systems_os2 = [system_i386_OS2,system_i386_emx];
  261. { all native nt systems }
  262. systems_nativent = [system_i386_nativent];
  263. { systems supporting Objective-C }
  264. systems_objc_supported = systems_darwin;
  265. { systems using the non-fragile Objective-C ABI }
  266. systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim];
  267. { systems supporting "blocks" }
  268. systems_blocks_supported = systems_darwin;
  269. { all systems supporting exports from programs or units }
  270. systems_unit_program_exports = [system_i386_win32,
  271. system_i386_wdosx,
  272. system_i386_Netware,
  273. system_i386_netwlibc,
  274. system_arm_wince,
  275. system_x86_64_win64,
  276. system_i8086_win16]+systems_linux+systems_android;
  277. { all systems that reference symbols in other binaries using indirect imports }
  278. systems_indirect_var_imports = systems_all_windows+[system_i386_nativent];
  279. { all systems for which weak linking has been tested/is supported }
  280. systems_weak_linking = systems_darwin + systems_solaris + systems_linux + systems_android;
  281. systems_internal_sysinit = [system_i386_linux,system_i386_win32,
  282. system_powerpc64_linux];
  283. { all systems that use garbage collection for reference-counted types }
  284. systems_garbage_collected_managed_types = [
  285. system_jvm_java32,
  286. system_jvm_android32
  287. ];
  288. { all systems that use a managed vm (-> no real pointers, internal VMT
  289. format, ...) }
  290. systems_managed_vm = [
  291. system_jvm_java32,
  292. system_jvm_android32
  293. ];
  294. { all systems based on the JVM }
  295. systems_jvm = [
  296. system_jvm_java32,
  297. system_jvm_android32
  298. ];
  299. { all systems where typed constants have to be translated into node
  300. trees that initialise the data instead of into data sections }
  301. systems_typed_constants_node_init = [
  302. system_jvm_java32,
  303. system_jvm_android32
  304. ];
  305. { all systems that don't use a built-in framepointer for accessing nested
  306. variables, but emulate it by wrapping nested variables in records
  307. whose address is passed around }
  308. systems_fpnestedstruct = [
  309. {$ifndef llvm}
  310. system_jvm_java32,
  311. system_jvm_android32
  312. {$else not llvm}
  313. low(tsystem)..high(tsystem)
  314. {$endif not llvm}
  315. ];
  316. { all systems where a value parameter passed by reference must be copied
  317. on the caller side rather than on the callee side }
  318. systems_caller_copy_addr_value_para = [system_aarch64_darwin,system_aarch64_linux];
  319. { pointer checking (requires special code in FPC_CHECKPOINTER,
  320. and can never work for libc-based targets or any other program
  321. linking to an external library)
  322. }
  323. systems_support_checkpointer = [system_i386_linux,system_powerpc_linux]
  324. + [system_i386_win32]
  325. + [system_i386_GO32V2]
  326. + [system_i386_os2]
  327. + [system_i386_beos,system_i386_haiku]
  328. + [system_powerpc_morphos];
  329. cpu2str : array[TSystemCpu] of string[10] =
  330. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  331. 'mips','arm', 'powerpc64', 'avr', 'mipsel','jvm', 'i8086',
  332. 'aarch64','spc32');
  333. abiinfo : array[tabi] of tabiinfo = (
  334. (name: 'DEFAULT'; supported: true),
  335. (name: 'SYSV' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  336. (name: 'AIX' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  337. (name: 'DARWIN' ; supported:{$if defined(powerpc) or defined(powerpc64)}true{$else}false{$endif}),
  338. (name: 'ELFV2' ; supported:{$if defined(powerpc64)}true{$else}false{$endif}),
  339. (name: 'EABI' ; supported:{$ifdef FPC_ARMEL}true{$else}false{$endif}),
  340. (name: 'ARMEB' ; supported:{$ifdef FPC_ARMEB}true{$else}false{$endif}),
  341. (name: 'EABIHF' ; supported:{$ifdef FPC_ARMHF}true{$else}false{$endif}),
  342. (name: 'OLDWIN32GNU'; supported:{$ifdef I386}true{$else}false{$endif}),
  343. (name: 'AARCH64IOS'; supported:{$ifdef aarch64}true{$else}false{$endif})
  344. );
  345. var
  346. targetinfos : array[tsystem] of psysteminfo;
  347. arinfos : array[tar] of parinfo;
  348. resinfos : array[tres] of presinfo;
  349. asminfos : array[tasm] of pasminfo;
  350. dbginfos : array[tdbg] of pdbginfo;
  351. source_info : tsysteminfo;
  352. target_cpu : tsystemcpu;
  353. target_info : tsysteminfo;
  354. target_asm : tasminfo;
  355. target_ar : tarinfo;
  356. target_res : tresinfo;
  357. target_dbg : tdbginfo;
  358. target_cpu_string,
  359. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  360. target_full_string : string[24];
  361. function set_target(t:tsystem):boolean;
  362. function set_target_asm(t:tasm):boolean;
  363. function set_target_ar(t:tar):boolean;
  364. function set_target_res(t:tres):boolean;
  365. function set_target_dbg(t:tdbg):boolean;
  366. function find_system_by_string(const s : string) : tsystem;
  367. function find_asm_by_string(const s : string) : tasm;
  368. function find_dbg_by_string(const s : string) : tdbg;
  369. procedure set_source_info(const ti : tsysteminfo);
  370. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  371. procedure RegisterTarget(const r:tsysteminfo);
  372. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  373. procedure RegisterAr(const r:tarinfo);
  374. procedure InitSystems;
  375. {$ifdef FreeBSD}
  376. function GetOSRelDate:Longint;
  377. {$endif}
  378. implementation
  379. uses
  380. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  381. {****************************************************************************
  382. OS runtime version detection utility routine
  383. ****************************************************************************}
  384. {$ifdef FreeBSD}
  385. function GetOSRelDate:Longint;
  386. var
  387. mib : array[0..1] of cint;
  388. rval : cint;
  389. len : size_t;
  390. i : longint;
  391. v : longint;
  392. oerrno : cint;
  393. S : AnsiString;
  394. Begin
  395. s:='ab';
  396. SetLength(S,50);
  397. mib[0] := CTL_KERN;
  398. mib[1] := KERN_OSRELDATE;
  399. len := 4;
  400. oerrno:= fpgeterrno;
  401. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  402. Begin
  403. if (fpgeterrno = ESysENOMEM) Then
  404. fpseterrno(oerrno);
  405. GetOSRelDate:=0;
  406. End
  407. else
  408. GetOSRelDate:=v;
  409. End;
  410. {$endif}
  411. {****************************************************************************
  412. Target setting
  413. ****************************************************************************}
  414. function set_target(t:tsystem):boolean;
  415. begin
  416. set_target:=false;
  417. if assigned(targetinfos[t]) then
  418. begin
  419. target_info:=targetinfos[t]^;
  420. set_target_asm(target_info.assem);
  421. set_target_ar(target_info.ar);
  422. set_target_res(target_info.res);
  423. set_target_dbg(target_info.dbg);
  424. target_cpu:=target_info.cpu;
  425. target_os_string:=lower(target_info.shortname);
  426. target_cpu_string:=cpu2str[target_cpu];
  427. target_full_string:=target_cpu_string+'-'+target_os_string;
  428. set_target:=true;
  429. exit;
  430. end;
  431. end;
  432. function set_target_asm(t:tasm):boolean;
  433. begin
  434. set_target_asm:=false;
  435. if assigned(asminfos[t]) and
  436. ((target_info.system in asminfos[t]^.supported_targets) or
  437. (system_any in asminfos[t]^.supported_targets)) then
  438. begin
  439. target_asm:=asminfos[t]^;
  440. set_target_asm:=true;
  441. exit;
  442. end;
  443. end;
  444. function set_target_ar(t:tar):boolean;
  445. begin
  446. result:=false;
  447. if assigned(arinfos[t]) then
  448. begin
  449. target_ar:=arinfos[t]^;
  450. result:=true;
  451. exit;
  452. end;
  453. end;
  454. function set_target_res(t:tres):boolean;
  455. begin
  456. result:=false;
  457. if assigned(resinfos[t]) then
  458. begin
  459. target_res:=resinfos[t]^;
  460. result:=true;
  461. exit;
  462. end
  463. else
  464. FillByte(target_res,sizeof(target_res),0);
  465. end;
  466. function set_target_dbg(t:tdbg):boolean;
  467. begin
  468. result:=false;
  469. if assigned(dbginfos[t]) then
  470. begin
  471. target_dbg:=dbginfos[t]^;
  472. result:=true;
  473. exit;
  474. end;
  475. end;
  476. function find_system_by_string(const s : string) : tsystem;
  477. var
  478. hs : string;
  479. t : tsystem;
  480. begin
  481. result:=system_none;
  482. hs:=upper(s);
  483. for t:=low(tsystem) to high(tsystem) do
  484. if assigned(targetinfos[t]) and
  485. (upper(targetinfos[t]^.shortname)=hs) then
  486. begin
  487. result:=t;
  488. exit;
  489. end;
  490. end;
  491. function find_asm_by_string(const s : string) : tasm;
  492. var
  493. hs : string;
  494. t : tasm;
  495. begin
  496. result:=as_none;
  497. hs:=upper(s);
  498. for t:=low(tasm) to high(tasm) do
  499. if assigned(asminfos[t]) and
  500. (asminfos[t]^.idtxt=hs) then
  501. begin
  502. result:=t;
  503. exit;
  504. end;
  505. end;
  506. function find_dbg_by_string(const s : string) : tdbg;
  507. var
  508. hs : string;
  509. t : tdbg;
  510. begin
  511. result:=dbg_none;
  512. hs:=upper(s);
  513. for t:=low(tdbg) to high(tdbg) do
  514. if assigned(dbginfos[t]) and
  515. (dbginfos[t]^.idtxt=hs) then
  516. begin
  517. result:=t;
  518. exit;
  519. end;
  520. end;
  521. function UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo) : boolean;
  522. begin
  523. result:=true;
  524. with d do
  525. begin
  526. if (s.procalign in [1,2,4,8,16,32,64,128]) or (s.procalign=256) then
  527. procalign:=s.procalign
  528. else if s.procalign<>0 then
  529. result:=false;
  530. if (s.loopalign in [1,2,4,8,16,32,64,128]) or (s.loopalign=256) then
  531. loopalign:=s.loopalign
  532. else if s.loopalign<>0 then
  533. result:=false;
  534. if (s.jumpalign in [1,2,4,8,16,32,64,128]) or (s.jumpalign=256) then
  535. jumpalign:=s.jumpalign
  536. else if s.jumpalign<>0 then
  537. result:=false;
  538. { general update rules:
  539. minimum: if higher then update
  540. maximum: if lower then update or if undefined then update }
  541. if s.constalignmin>constalignmin then
  542. constalignmin:=s.constalignmin;
  543. if (constalignmax=0) or
  544. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  545. constalignmax:=s.constalignmax;
  546. if s.varalignmin>varalignmin then
  547. varalignmin:=s.varalignmin;
  548. if (varalignmax=0) or
  549. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  550. varalignmax:=s.varalignmax;
  551. if s.localalignmin>localalignmin then
  552. localalignmin:=s.localalignmin;
  553. if (localalignmax=0) or
  554. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  555. localalignmax:=s.localalignmax;
  556. if s.recordalignmin>recordalignmin then
  557. recordalignmin:=s.recordalignmin;
  558. if (recordalignmax=0) or
  559. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  560. recordalignmax:=s.recordalignmax;
  561. if (maxCrecordalign=0) or
  562. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  563. maxCrecordalign:=s.maxCrecordalign;
  564. end;
  565. end;
  566. {****************************************************************************
  567. Target registration
  568. ****************************************************************************}
  569. procedure RegisterTarget(const r:tsysteminfo);
  570. var
  571. t : tsystem;
  572. begin
  573. t:=r.system;
  574. if assigned(targetinfos[t]) then
  575. writeln('Warning: Target is already registered!')
  576. else
  577. new(targetinfos[t]);
  578. targetinfos[t]^:=r;
  579. end;
  580. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  581. var
  582. t : tres;
  583. begin
  584. t:=r.id;
  585. if not assigned(resinfos[t]) then
  586. new(resinfos[t]);
  587. resinfos[t]^:=r;
  588. resinfos[t]^.resourcefileclass:=rcf;
  589. end;
  590. procedure RegisterAr(const r:tarinfo);
  591. var
  592. t : tar;
  593. begin
  594. t:=r.id;
  595. if assigned(arinfos[t]) then
  596. writeln('Warning: ar is already registered!')
  597. else
  598. new(arinfos[t]);
  599. arinfos[t]^:=r;
  600. end;
  601. procedure DeregisterInfos;
  602. var
  603. assem : tasm;
  604. target : tsystem;
  605. ar : tar;
  606. res : tres;
  607. dbg : tdbg;
  608. begin
  609. for target:=low(tsystem) to high(tsystem) do
  610. if assigned(targetinfos[target]) then
  611. begin
  612. freemem(targetinfos[target],sizeof(tsysteminfo));
  613. targetinfos[target]:=nil;
  614. end;
  615. for assem:=low(tasm) to high(tasm) do
  616. if assigned(asminfos[assem]) then
  617. begin
  618. freemem(asminfos[assem],sizeof(tasminfo));
  619. asminfos[assem]:=nil;
  620. end;
  621. for ar:=low(tar) to high(tar) do
  622. if assigned(arinfos[ar]) then
  623. begin
  624. freemem(arinfos[ar],sizeof(tarinfo));
  625. arinfos[ar]:=nil;
  626. end;
  627. for res:=low(tres) to high(tres) do
  628. if assigned(resinfos[res]) then
  629. begin
  630. freemem(resinfos[res],sizeof(tresinfo));
  631. resinfos[res]:=nil;
  632. end;
  633. for dbg:=low(tdbg) to high(tdbg) do
  634. if assigned(dbginfos[dbg]) then
  635. begin
  636. freemem(dbginfos[dbg],sizeof(tdbginfo));
  637. dbginfos[dbg]:=nil;
  638. end;
  639. end;
  640. {****************************************************************************
  641. Initialization of default target
  642. ****************************************************************************}
  643. procedure default_target(t:tsystem);
  644. begin
  645. set_target(t);
  646. if source_info.name='' then
  647. source_info:=target_info;
  648. end;
  649. procedure set_source_info(const ti : tsysteminfo);
  650. begin
  651. { can't use message() here (PFV) }
  652. if source_info.name<>'' then
  653. Writeln('Warning: Source OS Redefined!');
  654. source_info:=ti;
  655. end;
  656. procedure InitSystems;
  657. begin
  658. { Now default target, this is dependent on the target cpu define,
  659. when the define is the same as the source cpu then we use the source
  660. os, else we pick a default }
  661. {$ifdef i386}
  662. {$ifdef cpui386}
  663. default_target(source_info.system);
  664. {$define default_target_set}
  665. {$else cpui386}
  666. {$ifdef linux}
  667. default_target(system_i386_linux);
  668. {$define default_target_set}
  669. {$endif}
  670. {$ifdef freebsd}
  671. default_target(system_i386_freebsd);
  672. {$define default_target_set}
  673. {$endif}
  674. {$ifdef openbsd}
  675. default_target(system_i386_openbsd);
  676. {$define default_target_set}
  677. {$endif}
  678. {$ifdef darwin}
  679. default_target(system_i386_darwin);
  680. {$define default_target_set}
  681. {$endif}
  682. {$ifdef android}
  683. {$define default_target_set}
  684. default_target(system_i386_android);
  685. {$endif}
  686. {$ifdef solaris}
  687. {$define default_target_set}
  688. default_target(system_i386_solaris);
  689. {$endif}
  690. {$endif cpui386}
  691. { default is linux }
  692. {$ifndef default_target_set}
  693. default_target(system_i386_linux);
  694. {$endif default_target_set}
  695. {$endif i386}
  696. {$ifdef x86_64}
  697. {$ifdef cpux86_64}
  698. default_target(source_info.system);
  699. {$define default_target_set}
  700. {$else cpux86_64}
  701. {$ifdef MSWindows}
  702. default_target(system_x86_64_win64);
  703. {$define default_target_set}
  704. {$endif}
  705. {$ifdef linux}
  706. default_target(system_x86_64_linux);
  707. {$define default_target_set}
  708. {$endif}
  709. {$ifdef dragonfly}
  710. default_target(system_x86_64_dragonfly);
  711. {$define default_target_set}
  712. {$endif}
  713. {$ifdef freebsd}
  714. default_target(system_x86_64_freebsd);
  715. {$define default_target_set}
  716. {$endif}
  717. {$ifdef openbsd}
  718. default_target(system_x86_64_openbsd);
  719. {$define default_target_set}
  720. {$endif}
  721. {$ifdef netbsd}
  722. default_target(system_x86_64_netbsd);
  723. {$define default_target_set}
  724. {$endif}
  725. {$ifdef solaris}
  726. default_target(system_x86_64_solaris);
  727. {$define default_target_set}
  728. {$endif}
  729. {$ifdef darwin}
  730. default_target(system_x86_64_darwin);
  731. {$define default_target_set}
  732. {$endif}
  733. {$endif cpux86_64}
  734. { default is linux }
  735. {$ifndef default_target_set}
  736. default_target(system_x86_64_linux);
  737. {$endif default_target_set}
  738. {$endif x86_64}
  739. {$ifdef m68k}
  740. {$ifdef cpu68}
  741. default_target(source_info.system);
  742. {$else cpu68}
  743. default_target(system_m68k_linux);
  744. {$endif cpu68}
  745. {$endif m68k}
  746. {$ifdef powerpc}
  747. {$ifdef cpupowerpc32}
  748. default_target(source_info.system);
  749. {$define default_target_set}
  750. {$else cpupowerpc}
  751. {$ifdef linux}
  752. default_target(system_powerpc_linux);
  753. {$define default_target_set}
  754. {$endif}
  755. {$ifdef darwin}
  756. default_target(system_powerpc_darwin);
  757. {$define default_target_set}
  758. {$endif}
  759. {$endif cpupowerpc}
  760. {$ifdef aix}
  761. default_target(system_powerpc_aix);
  762. {$define default_target_set}
  763. {$endif}
  764. {$ifndef default_target_set}
  765. default_target(system_powerpc_linux);
  766. {$endif default_target_set}
  767. {$endif powerpc}
  768. {$ifdef POWERPC64}
  769. {$ifdef cpupowerpc64}
  770. default_target(source_info.system);
  771. {$define default_target_set}
  772. {$else cpupowerpc64}
  773. {$ifdef darwin}
  774. default_target(system_powerpc64_darwin);
  775. {$define default_target_set}
  776. {$endif}
  777. {$ifdef linux}
  778. default_target(system_powerpc64_linux);
  779. {$define default_target_set}
  780. {$endif}
  781. {$ifdef aix}
  782. default_target(system_powerpc64_aix);
  783. {$define default_target_set}
  784. {$endif}
  785. {$endif cpupowerpc64}
  786. {$ifndef default_target_set}
  787. default_target(system_powerpc64_linux);
  788. {$define default_target_set}
  789. {$endif}
  790. {$endif POWERPC64}
  791. {$ifdef sparc}
  792. {$ifdef cpusparc}
  793. default_target(source_info.system);
  794. {$else cpusparc}
  795. {$ifdef solaris}
  796. {$define default_target_set}
  797. default_target(system_sparc_solaris);
  798. {$endif}
  799. {$ifndef default_target_set}
  800. default_target(system_sparc_linux);
  801. {$endif ndef default_target_set}
  802. {$endif cpusparc}
  803. {$endif sparc}
  804. {$ifdef arm}
  805. {$ifdef cpuarm}
  806. default_target(source_info.system);
  807. {$else cpuarm}
  808. {$ifdef WINDOWS}
  809. {$define default_target_set}
  810. default_target(system_arm_wince);
  811. {$endif}
  812. {$ifdef linux}
  813. {$define default_target_set}
  814. default_target(system_arm_linux);
  815. {$endif}
  816. {$ifdef android}
  817. {$define default_target_set}
  818. default_target(system_arm_android);
  819. {$endif}
  820. {$ifdef darwin}
  821. {$define default_target_set}
  822. default_target(system_arm_darwin);
  823. {$endif}
  824. {$ifndef default_target_set}
  825. default_target(system_arm_linux);
  826. {$define default_target_set}
  827. {$endif}
  828. {$endif cpuarm}
  829. {$endif arm}
  830. {$ifdef avr}
  831. default_target(system_avr_embedded);
  832. {$endif avr}
  833. {$ifdef mips}
  834. {$ifdef mipsel}
  835. {$ifdef cpumipsel}
  836. default_target(source_info.system);
  837. {$else cpumipsel}
  838. default_target(system_mipsel_linux);
  839. {$endif cpumipsel}
  840. {$else mipsel}
  841. default_target(system_mipseb_linux);
  842. {$endif mipsel}
  843. {$endif mips}
  844. {$ifdef jvm}
  845. default_target(system_jvm_java32);
  846. {$endif jvm}
  847. {$ifdef i8086}
  848. default_target(system_i8086_msdos);
  849. {$endif i8086}
  850. {$ifdef aarch64}
  851. {$ifdef cpuaarch64}
  852. default_target(source_info.system);
  853. {$else cpuaarch64}
  854. {$ifdef darwin}
  855. {$define default_target_set}
  856. default_target(system_aarch64_darwin);
  857. {$endif darwin}
  858. {$ifndef default_target_set}
  859. default_target(system_aarch64_linux);
  860. {$define default_target_set}
  861. {$endif}
  862. {$endif cpuaarch64}
  863. {$endif aarch64}
  864. {$ifdef spc32}
  865. default_target(system_spc32_embedded);
  866. {$endif spc32}
  867. end;
  868. initialization
  869. source_info.name:='';
  870. finalization
  871. DeregisterInfos;
  872. end.