systems.pas 30 KB

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