2
0

systems.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. type
  22. tendian = (endian_little,endian_big);
  23. (*
  24. IMPORTANT NOTE:
  25. The value of this enumeration is stored in PPU files.
  26. Therefore adding new CPU targets should not change the
  27. values of the pre-existing targets. (CEC)
  28. FURTHERMORE : Make sure that this branch values, are
  29. consistant with the main branch version always.
  30. *)
  31. tsystemcpu=
  32. (
  33. cpu_no, { 0 }
  34. cpu_i386, { 1 }
  35. cpu_m68k, { 2 }
  36. cpu_alpha, { 3 }
  37. cpu_powerpc, { 4 }
  38. cpu_sparc, { 5 }
  39. cpu_vm, { 6 }
  40. cpu_iA64, { 7 }
  41. cpu_x86_64, { 8 }
  42. cpu_mips, { 9 }
  43. cpu_arm, { 10 }
  44. cpu_powerpc64, { 11 }
  45. cpu_avr { 12 }
  46. );
  47. tasmmode= (asmmode_none
  48. { standard assembler (cpu dependant) with full parsing }
  49. ,asmmode_standard
  50. ,asmmode_i386_att
  51. ,asmmode_i386_intel
  52. ,asmmode_ppc_gas
  53. ,asmmode_ppc_motorola
  54. ,asmmode_arm_gas
  55. ,asmmode_sparc_gas
  56. ,asmmode_x86_64_gas
  57. ,asmmode_m68k_mot
  58. ,asmmode_x86_64_intel
  59. ,asmmode_x86_64_att
  60. ,asmmode_avr_gas
  61. );
  62. (* IMPORTANT NOTE:
  63. the integer value of this enum is stored in PPU
  64. files to recognize the target, so if you add new targets
  65. allways add them at end PM
  66. FURTHERMORE : Make sure that this branch values are
  67. consistant with the main branch version always. (CEC)
  68. *)
  69. type
  70. tsystem =
  71. (
  72. system_none, { 0 }
  73. obsolete_system_i386_GO32V1,{ 1 }
  74. system_i386_GO32V2, { 2 }
  75. system_i386_linux, { 3 }
  76. system_i386_OS2, { 4 }
  77. system_i386_Win32, { 5 }
  78. system_i386_freebsd, { 6 }
  79. system_m68k_Amiga, { 7 }
  80. system_m68k_Atari, { 8 }
  81. system_m68k_Mac, { 9 }
  82. system_m68k_linux, { 10 }
  83. system_m68k_PalmOS, { 11 }
  84. system_alpha_linux, { 12 }
  85. system_powerpc_linux, { 13 }
  86. system_powerpc_macos, { 14 }
  87. system_i386_solaris, { 15 }
  88. system_i386_beos, { 16 }
  89. system_i386_netbsd, { 17 }
  90. system_m68k_netbsd, { 18 }
  91. system_i386_Netware, { 19 }
  92. system_i386_qnx, { 20 }
  93. system_i386_wdosx, { 21 }
  94. system_sparc_solaris, { 22 }
  95. system_sparc_linux, { 23 }
  96. system_i386_openbsd, { 24 }
  97. system_m68k_openbsd, { 25 }
  98. system_x86_64_linux, { 26 }
  99. system_powerpc_darwin, { 27 }
  100. system_i386_EMX, { 28 }
  101. system_powerpc_netbsd, { 29 }
  102. system_powerpc_openbsd, { 30 }
  103. system_arm_linux, { 31 }
  104. system_i386_watcom, { 32 }
  105. system_powerpc_MorphOS, { 33 }
  106. system_x86_64_freebsd, { 34 }
  107. system_i386_netwlibc, { 35 }
  108. system_powerpc_Amiga, { 36 }
  109. system_x86_64_win64, { 37 }
  110. system_arm_wince, { 38 }
  111. system_ia64_win64, { 39 }
  112. system_i386_wince, { 40 }
  113. system_x86_6432_linux, { 41 }
  114. system_arm_gba, { 42 }
  115. system_powerpc64_linux, { 43 }
  116. system_i386_darwin, { 44 }
  117. system_arm_palmos, { 45 }
  118. system_powerpc64_darwin, { 46 }
  119. system_arm_nds, { 47 }
  120. system_i386_embedded, { 48 }
  121. system_m68k_embedded, { 49 }
  122. system_alpha_embedded, { 50 }
  123. system_powerpc_embedded, { 51 }
  124. system_sparc_embedded, { 52 }
  125. system_vm_embedded, { 53 }
  126. system_iA64_embedded, { 54 }
  127. system_x86_64_embedded, { 55 }
  128. system_mips_embedded, { 56 }
  129. system_arm_embedded, { 57 }
  130. system_powerpc64_embedded, { 58 }
  131. system_i386_symbian, { 59 }
  132. system_arm_symbian, { 60 }
  133. system_x86_64_darwin, { 61 }
  134. system_avr_embedded, { 62 }
  135. system_i386_haiku, { 63 }
  136. system_arm_darwin { 64 }
  137. );
  138. type
  139. tasm = (as_none
  140. ,as_gas { standard gnu assembler }
  141. ,as_i386_as_aout
  142. ,as_i386_nasmcoff
  143. ,as_i386_nasmwin32
  144. ,as_i386_nasmwdosx
  145. ,as_i386_nasmelf
  146. ,as_i386_nasmobj
  147. ,as_i386_nasmbeos
  148. ,as_i386_tasm
  149. ,as_i386_masm
  150. ,as_i386_wasm
  151. ,as_i386_coff
  152. ,as_i386_pecoff
  153. ,as_i386_elf32
  154. ,as_i386_pecoffwdosx
  155. ,as_m68k_mit
  156. ,as_powerpc_mpw
  157. ,as_darwin
  158. ,as_x86_64_masm
  159. ,as_x86_64_pecoff
  160. ,as_i386_pecoffwince
  161. ,as_arm_pecoffwince
  162. ,as_x86_64_elf64
  163. ,as_sparc_elf32
  164. ,as_ggas { gnu assembler called "gas" instead of "as" }
  165. ,as_i386_nasmhaiku
  166. ,as_powerpc_vasm
  167. );
  168. tar = (ar_none
  169. ,ar_gnu_ar
  170. ,ar_mpw_ar
  171. ,ar_gnu_ar_scripted
  172. ,ar_gnu_gar
  173. );
  174. tres = (res_none
  175. ,res_gnu_windres,res_watcom_wrc_os2
  176. ,res_m68k_palmos,res_m68k_mpw
  177. ,res_powerpc_mpw,res_elf
  178. ,res_win64_gorc, res_macho, res_ext
  179. );
  180. tresinfoflags = (res_external_file,res_arch_in_file_name
  181. ,res_single_file);
  182. tdbg = (dbg_none
  183. ,dbg_stabs,dbg_dwarf2,dbg_dwarf3
  184. );
  185. tscripttype = (script_none
  186. ,script_dos,script_unix,script_amiga,
  187. script_mpw
  188. );
  189. tabi = (abi_default
  190. ,abi_powerpc_sysv,abi_powerpc_aix
  191. ,abi_eabi,abi_armeb
  192. );
  193. {*****************************************************************************
  194. Structures
  195. *****************************************************************************}
  196. type
  197. { Abstract linker class which is implemented in link module }
  198. TAbstractLinker = class
  199. end;
  200. TAbstractLinkerClass = class of TAbstractLinker;
  201. { Abstract assembler class which is implemented in assemble module }
  202. TAbstractAssembler = class
  203. end;
  204. TAbstractAssemblerClass = class of TAbstractAssembler;
  205. TAbstractResourceFile = class
  206. constructor create(const fn : ansistring);virtual;abstract;
  207. end;
  208. TAbstractResourceFileClass = class of TAbstractResourceFile;
  209. palignmentinfo = ^talignmentinfo;
  210. { this is written to ppus during token recording for generics so it must be packed }
  211. talignmentinfo = packed record
  212. procalign,
  213. loopalign,
  214. jumpalign,
  215. constalignmin,
  216. constalignmax,
  217. varalignmin,
  218. varalignmax,
  219. localalignmin,
  220. localalignmax,
  221. recordalignmin,
  222. recordalignmax,
  223. maxCrecordalign : longint;
  224. end;
  225. tasmflags = (af_none,
  226. af_outputbinary,af_allowdirect,
  227. af_needar,af_smartlink_sections,
  228. af_labelprefix_only_inside_procedure,
  229. af_supports_dwarf,
  230. af_no_debug
  231. );
  232. pasminfo = ^tasminfo;
  233. tasminfo = record
  234. id : tasm;
  235. idtxt : string[12];
  236. asmbin : string[8];
  237. asmcmd : string[50];
  238. supported_targets : set of tsystem;
  239. flags : set of tasmflags;
  240. labelprefix : string[3];
  241. comment : string[3];
  242. end;
  243. parinfo = ^tarinfo;
  244. tarinfo = record
  245. id : tar;
  246. arcmd : string[50];
  247. arfinishcmd : string[10];
  248. end;
  249. presinfo = ^tresinfo;
  250. tresinfo = record
  251. id : tres;
  252. { Compiler for resource (.rc or .res) to obj }
  253. resbin : string[10];
  254. rescmd : string[50];
  255. { Optional compiler for resource script (.rc) to binary resource (.res). }
  256. { If it is not provided resbin and rescmd will be used. }
  257. rcbin : string[10];
  258. rccmd : string[50];
  259. resourcefileclass : TAbstractResourceFileClass;
  260. resflags : set of tresinfoflags;
  261. end;
  262. pdbginfo = ^tdbginfo;
  263. tdbginfo = record
  264. id : tdbg;
  265. idtxt : string[12];
  266. end;
  267. tsystemflags = (tf_none,
  268. tf_under_development,
  269. tf_need_export,
  270. tf_needs_isconsole,
  271. tf_code_small,
  272. tf_static_reg_based,
  273. tf_needs_symbol_size,
  274. tf_smartlink_sections,
  275. tf_smartlink_library,
  276. tf_needs_dwarf_cfi,
  277. tf_use_8_3,
  278. tf_pic_uses_got,
  279. tf_library_needs_pic,
  280. tf_needs_symbol_type,
  281. tf_section_threadvars,
  282. tf_files_case_sensitive,
  283. tf_files_case_aware,
  284. tf_p_ext_support,
  285. tf_has_dllscanner,
  286. tf_use_function_relative_addresses,
  287. tf_winlikewidestring,
  288. tf_dwarf_relative_addresses, // use offsets where the Dwarf spec requires this instead of absolute addresses (the latter is needed by Linux binutils)
  289. tf_dwarf_only_local_labels, // only use local labels inside the Dwarf debug_info section (needed for e.g. Darwin)
  290. tf_requires_proper_alignment,
  291. tf_no_pic_supported,
  292. tf_pic_default,
  293. { the os does some kind of stack checking and it can be converted into a rte 202 }
  294. tf_no_generic_stackcheck,
  295. tf_has_winlike_resources
  296. );
  297. psysteminfo = ^tsysteminfo;
  298. { using packed causes bus errors on processors which require alignment }
  299. tsysteminfo = record
  300. system : tsystem;
  301. name : string[34];
  302. shortname : string[9];
  303. flags : set of tsystemflags;
  304. cpu : tsystemcpu;
  305. unit_env : string[16];
  306. extradefines : string[40];
  307. exeext,
  308. defext,
  309. scriptext,
  310. smartext,
  311. unitext,
  312. unitlibext,
  313. asmext,
  314. objext,
  315. resext : string[4];
  316. resobjext : string[7];
  317. sharedlibext : string[10];
  318. staticlibext,
  319. staticlibprefix : string[4];
  320. sharedlibprefix : string[4];
  321. sharedClibext : string[10];
  322. staticClibext,
  323. staticClibprefix : string[4];
  324. sharedClibprefix : string[4];
  325. importlibprefix : string[10];
  326. importlibext : string[4];
  327. Cprefix : string[2];
  328. newline : string[2];
  329. dirsep : char;
  330. assem : tasm;
  331. assemextern : tasm; { external assembler, used by -a }
  332. link : tabstractlinkerclass;
  333. linkextern : tabstractlinkerclass; { external linker, used by -s }
  334. ar : tar;
  335. res : tres;
  336. dbg : tdbg;
  337. script : tscripttype;
  338. endian : tendian;
  339. alignment : talignmentinfo;
  340. {
  341. Offset from the argument pointer register to the first
  342. argument's address. On some machines it may depend on
  343. the data type of the function.
  344. (see also FIRST_PARM_OFFSET in GCC source)
  345. }
  346. first_parm_offset : longint;
  347. stacksize : longint;
  348. abi : tabi;
  349. end;
  350. const
  351. { alias for supported_target field in tasminfo }
  352. system_any = system_none;
  353. system_wince = [system_arm_wince,system_i386_wince];
  354. system_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
  355. system_arm_linux,system_sparc_linux,system_alpha_linux,system_m68k_linux,
  356. system_x86_6432_linux];
  357. { all real windows systems, no cripple ones like wince, wdosx et. al. }
  358. system_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64];
  359. { all windows systems }
  360. system_all_windows = [system_i386_win32,system_x86_64_win64,system_ia64_win64,
  361. system_arm_wince,system_i386_wince];
  362. { all darwin systems }
  363. systems_darwin = [system_powerpc_darwin,system_i386_darwin,
  364. system_powerpc64_darwin,system_x86_64_darwin,
  365. system_arm_darwin];
  366. { all embedded systems }
  367. systems_embedded = [system_i386_embedded,system_m68k_embedded,
  368. system_alpha_embedded,system_powerpc_embedded,
  369. system_sparc_embedded,system_vm_embedded,
  370. system_iA64_embedded,system_x86_64_embedded,
  371. system_mips_embedded,system_arm_embedded,
  372. system_powerpc64_embedded];
  373. { all systems supporting exports from programs or units }
  374. system_unit_program_exports = [system_i386_win32,
  375. system_i386_wdosx,
  376. system_i386_Netware,
  377. system_i386_netwlibc,
  378. system_arm_wince,
  379. system_x86_64_win64,
  380. system_ia64_win64]+system_linux;
  381. { all systems for which weak linking has been tested/is supported }
  382. system_weak_linking = systems_darwin;
  383. system_internal_sysinit = [system_i386_linux,system_i386_win32];
  384. system_embedded = [system_i386_embedded,system_m68k_embedded,system_alpha_embedded,
  385. system_powerpc_embedded,system_sparc_embedded,system_vm_embedded,
  386. system_iA64_embedded,system_x86_64_embedded,system_mips_embedded,
  387. system_arm_embedded,system_powerpc64_embedded];
  388. { all symbian systems }
  389. systems_symbian = [system_i386_symbian,system_arm_symbian];
  390. cpu2str : array[TSystemCpu] of string[10] =
  391. ('','i386','m68k','alpha','powerpc','sparc','vm','ia64','x86_64',
  392. 'mips','arm', 'powerpc64', 'avr');
  393. abi2str : array[tabi] of string[10] =
  394. ('DEFAULT','SYSV','AIX','EABI','ARMEB');
  395. var
  396. targetinfos : array[tsystem] of psysteminfo;
  397. arinfos : array[tar] of parinfo;
  398. resinfos : array[tres] of presinfo;
  399. asminfos : array[tasm] of pasminfo;
  400. dbginfos : array[tdbg] of pdbginfo;
  401. source_info : tsysteminfo;
  402. target_cpu : tsystemcpu;
  403. target_info : tsysteminfo;
  404. target_asm : tasminfo;
  405. target_ar : tarinfo;
  406. target_res : tresinfo;
  407. target_dbg : tdbginfo;
  408. target_cpu_string,
  409. target_os_string : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  410. target_full_string : string[24];
  411. function set_target(t:tsystem):boolean;
  412. function set_target_asm(t:tasm):boolean;
  413. function set_target_ar(t:tar):boolean;
  414. function set_target_res(t:tres):boolean;
  415. function set_target_dbg(t:tdbg):boolean;
  416. function find_system_by_string(const s : string) : tsystem;
  417. function find_asm_by_string(const s : string) : tasm;
  418. function find_dbg_by_string(const s : string) : tdbg;
  419. procedure set_source_info(const ti : tsysteminfo);
  420. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  421. procedure RegisterTarget(const r:tsysteminfo);
  422. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  423. procedure RegisterAr(const r:tarinfo);
  424. { Register the external linker. This routine is called to setup the
  425. class to use for the linker. It returns the tsysteminfo structure
  426. updated with the correct linker class for external linking.
  427. }
  428. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  429. { Register the internal linker. This routine is called to setup the
  430. class to use for the linker. It returns the tsysteminfo structure
  431. updated with the correct linker class for internal linking.
  432. If internal linking is not supported, this class can be set
  433. to nil.
  434. }
  435. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  436. procedure InitSystems;
  437. {$ifdef FreeBSD}
  438. function GetOSRelDate:Longint;
  439. {$endif}
  440. implementation
  441. uses
  442. cutils{$ifdef FreeBSD},SysCtl,BaseUnix{$endif};
  443. {****************************************************************************
  444. OS runtime version detection utility routine
  445. ****************************************************************************}
  446. {$ifdef FreeBSD}
  447. function GetOSRelDate:Longint;
  448. var
  449. mib : array[0..1] of cint;
  450. rval : cint;
  451. len : size_t;
  452. i : longint;
  453. v : longint;
  454. oerrno : cint;
  455. S : AnsiString;
  456. Begin
  457. s:='ab';
  458. SetLength(S,50);
  459. mib[0] := CTL_KERN;
  460. mib[1] := KERN_OSRELDATE;
  461. len := 4;
  462. oerrno:= fpgeterrno;
  463. if (FPsysctl(pChar(@mib), 2, pchar(@v), @len, NIL, 0) = -1) Then
  464. Begin
  465. if (fpgeterrno = ESysENOMEM) Then
  466. fpseterrno(oerrno);
  467. GetOSRelDate:=0;
  468. End
  469. else
  470. GetOSRelDate:=v;
  471. End;
  472. {$endif}
  473. {****************************************************************************
  474. Target setting
  475. ****************************************************************************}
  476. function set_target(t:tsystem):boolean;
  477. begin
  478. set_target:=false;
  479. if assigned(targetinfos[t]) then
  480. begin
  481. target_info:=targetinfos[t]^;
  482. set_target_asm(target_info.assem);
  483. set_target_ar(target_info.ar);
  484. set_target_res(target_info.res);
  485. set_target_dbg(target_info.dbg);
  486. target_cpu:=target_info.cpu;
  487. target_os_string:=lower(target_info.shortname);
  488. target_cpu_string:=cpu2str[target_cpu];
  489. target_full_string:=target_cpu_string+'-'+target_os_string;
  490. set_target:=true;
  491. exit;
  492. end;
  493. end;
  494. function set_target_asm(t:tasm):boolean;
  495. begin
  496. set_target_asm:=false;
  497. if assigned(asminfos[t]) and
  498. ((target_info.system in asminfos[t]^.supported_targets) or
  499. (system_any in asminfos[t]^.supported_targets)) then
  500. begin
  501. target_asm:=asminfos[t]^;
  502. set_target_asm:=true;
  503. exit;
  504. end;
  505. end;
  506. function set_target_ar(t:tar):boolean;
  507. begin
  508. result:=false;
  509. if assigned(arinfos[t]) then
  510. begin
  511. target_ar:=arinfos[t]^;
  512. result:=true;
  513. exit;
  514. end;
  515. end;
  516. function set_target_res(t:tres):boolean;
  517. begin
  518. result:=false;
  519. if assigned(resinfos[t]) then
  520. begin
  521. target_res:=resinfos[t]^;
  522. result:=true;
  523. exit;
  524. end
  525. else
  526. FillByte(target_res,sizeof(target_res),0);
  527. end;
  528. function set_target_dbg(t:tdbg):boolean;
  529. begin
  530. result:=false;
  531. if assigned(dbginfos[t]) then
  532. begin
  533. target_dbg:=dbginfos[t]^;
  534. result:=true;
  535. exit;
  536. end;
  537. end;
  538. function find_system_by_string(const s : string) : tsystem;
  539. var
  540. hs : string;
  541. t : tsystem;
  542. begin
  543. result:=system_none;
  544. hs:=upper(s);
  545. for t:=low(tsystem) to high(tsystem) do
  546. if assigned(targetinfos[t]) and
  547. (upper(targetinfos[t]^.shortname)=hs) then
  548. begin
  549. result:=t;
  550. exit;
  551. end;
  552. end;
  553. function find_asm_by_string(const s : string) : tasm;
  554. var
  555. hs : string;
  556. t : tasm;
  557. begin
  558. result:=as_none;
  559. hs:=upper(s);
  560. for t:=low(tasm) to high(tasm) do
  561. if assigned(asminfos[t]) and
  562. (asminfos[t]^.idtxt=hs) then
  563. begin
  564. result:=t;
  565. exit;
  566. end;
  567. end;
  568. function find_dbg_by_string(const s : string) : tdbg;
  569. var
  570. hs : string;
  571. t : tdbg;
  572. begin
  573. result:=dbg_none;
  574. hs:=upper(s);
  575. for t:=low(tdbg) to high(tdbg) do
  576. if assigned(dbginfos[t]) and
  577. (dbginfos[t]^.idtxt=hs) then
  578. begin
  579. result:=t;
  580. exit;
  581. end;
  582. end;
  583. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  584. begin
  585. with d do
  586. begin
  587. { general update rules:
  588. minimum: if higher then update
  589. maximum: if lower then update or if undefined then update }
  590. if s.procalign>procalign then
  591. procalign:=s.procalign;
  592. if s.loopalign>loopalign then
  593. loopalign:=s.loopalign;
  594. if s.jumpalign>jumpalign then
  595. jumpalign:=s.jumpalign;
  596. if s.constalignmin>constalignmin then
  597. constalignmin:=s.constalignmin;
  598. if (constalignmax=0) or
  599. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  600. constalignmax:=s.constalignmax;
  601. if s.varalignmin>varalignmin then
  602. varalignmin:=s.varalignmin;
  603. if (varalignmax=0) or
  604. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  605. varalignmax:=s.varalignmax;
  606. if s.localalignmin>localalignmin then
  607. localalignmin:=s.localalignmin;
  608. if (localalignmax=0) or
  609. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  610. localalignmax:=s.localalignmax;
  611. if s.recordalignmin>recordalignmin then
  612. recordalignmin:=s.recordalignmin;
  613. if (recordalignmax=0) or
  614. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  615. recordalignmax:=s.recordalignmax;
  616. if (maxCrecordalign=0) or
  617. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  618. maxCrecordalign:=s.maxCrecordalign;
  619. end;
  620. end;
  621. {****************************************************************************
  622. Target registration
  623. ****************************************************************************}
  624. procedure RegisterTarget(const r:tsysteminfo);
  625. var
  626. t : tsystem;
  627. begin
  628. t:=r.system;
  629. if assigned(targetinfos[t]) then
  630. writeln('Warning: Target is already registered!')
  631. else
  632. Getmem(targetinfos[t],sizeof(tsysteminfo));
  633. targetinfos[t]^:=r;
  634. end;
  635. procedure RegisterRes(const r:tresinfo; rcf : TAbstractResourceFileClass);
  636. var
  637. t : tres;
  638. begin
  639. t:=r.id;
  640. if not assigned(resinfos[t]) then
  641. Getmem(resinfos[t],sizeof(tresinfo));
  642. resinfos[t]^:=r;
  643. resinfos[t]^.resourcefileclass:=rcf;
  644. end;
  645. procedure RegisterAr(const r:tarinfo);
  646. var
  647. t : tar;
  648. begin
  649. t:=r.id;
  650. if assigned(arinfos[t]) then
  651. writeln('Warning: ar is already registered!')
  652. else
  653. Getmem(arinfos[t],sizeof(tarinfo));
  654. arinfos[t]^:=r;
  655. end;
  656. procedure RegisterExternalLinker(var system_info: tsysteminfo; c:TAbstractLinkerClass);
  657. begin
  658. system_info.linkextern := c;
  659. end;
  660. procedure RegisterInternalLinker(var system_info : tsysteminfo; c:TAbstractLinkerClass);
  661. begin
  662. system_info.link := c;
  663. end;
  664. procedure DeregisterInfos;
  665. var
  666. assem : tasm;
  667. target : tsystem;
  668. ar : tar;
  669. res : tres;
  670. dbg : tdbg;
  671. begin
  672. for target:=low(tsystem) to high(tsystem) do
  673. if assigned(targetinfos[target]) then
  674. begin
  675. freemem(targetinfos[target],sizeof(tsysteminfo));
  676. targetinfos[target]:=nil;
  677. end;
  678. for assem:=low(tasm) to high(tasm) do
  679. if assigned(asminfos[assem]) then
  680. begin
  681. freemem(asminfos[assem],sizeof(tasminfo));
  682. asminfos[assem]:=nil;
  683. end;
  684. for ar:=low(tar) to high(tar) do
  685. if assigned(arinfos[ar]) then
  686. begin
  687. freemem(arinfos[ar],sizeof(tarinfo));
  688. arinfos[ar]:=nil;
  689. end;
  690. for res:=low(tres) to high(tres) do
  691. if assigned(resinfos[res]) then
  692. begin
  693. freemem(resinfos[res],sizeof(tresinfo));
  694. resinfos[res]:=nil;
  695. end;
  696. for dbg:=low(tdbg) to high(tdbg) do
  697. if assigned(dbginfos[dbg]) then
  698. begin
  699. freemem(dbginfos[dbg],sizeof(tdbginfo));
  700. dbginfos[dbg]:=nil;
  701. end;
  702. end;
  703. {****************************************************************************
  704. Initialization of default target
  705. ****************************************************************************}
  706. procedure default_target(t:tsystem);
  707. begin
  708. set_target(t);
  709. if source_info.name='' then
  710. source_info:=target_info;
  711. end;
  712. procedure set_source_info(const ti : tsysteminfo);
  713. begin
  714. { can't use message() here (PFV) }
  715. if source_info.name<>'' then
  716. Writeln('Warning: Source OS Redefined!');
  717. source_info:=ti;
  718. end;
  719. procedure InitSystems;
  720. begin
  721. { Now default target, this is dependent on the target cpu define,
  722. when the define is the same as the source cpu then we use the source
  723. os, else we pick a default }
  724. {$ifdef i386}
  725. {$ifdef cpu86}
  726. default_target(source_info.system);
  727. {$define default_target_set}
  728. {$else cpu86}
  729. {$ifdef linux}
  730. default_target(system_i386_linux);
  731. {$define default_target_set}
  732. {$endif}
  733. {$ifdef freebsd}
  734. default_target(system_i386_freebsd);
  735. {$define default_target_set}
  736. {$endif}
  737. {$ifdef darwin}
  738. default_target(system_i386_darwin);
  739. {$define default_target_set}
  740. {$endif}
  741. {$endif cpu86}
  742. { default is linux }
  743. {$ifndef default_target_set}
  744. default_target(system_i386_linux);
  745. {$endif default_target_set}
  746. {$endif i386}
  747. {$ifdef x86_64}
  748. {$ifdef cpux86_64}
  749. default_target(source_info.system);
  750. {$define default_target_set}
  751. {$else cpux86_64}
  752. {$ifdef MSWindows}
  753. default_target(system_x86_64_win64);
  754. {$define default_target_set}
  755. {$endif}
  756. {$ifdef linux}
  757. default_target(system_x86_64_linux);
  758. {$define default_target_set}
  759. {$endif}
  760. {$ifdef freebsd}
  761. default_target(system_x86_64_freebsd);
  762. {$define default_target_set}
  763. {$endif}
  764. {$ifdef darwin}
  765. default_target(system_x86_64_darwin);
  766. {$define default_target_set}
  767. {$endif}
  768. {$endif cpux86_64}
  769. { default is linux }
  770. {$ifndef default_target_set}
  771. default_target(system_x86_64_linux);
  772. {$endif default_target_set}
  773. {$endif x86_64}
  774. {$ifdef m68k}
  775. {$ifdef cpu68}
  776. default_target(source_info.target);
  777. {$else cpu68}
  778. default_target(system_m68k_linux);
  779. {$endif cpu68}
  780. {$endif m68k}
  781. {$ifdef alpha}
  782. {$ifdef cpualpha}
  783. default_target(source_info.system);
  784. {$else cpualpha}
  785. default_target(system_alpha_linux);
  786. {$endif cpualpha}
  787. {$endif alpha}
  788. {$ifdef powerpc}
  789. {$ifdef cpupowerpc}
  790. default_target(source_info.system);
  791. {$define default_target_set}
  792. {$else cpupowerpc}
  793. {$ifdef linux}
  794. default_target(system_powerpc_linux);
  795. {$define default_target_set}
  796. {$endif}
  797. {$ifdef darwin}
  798. default_target(system_powerpc_darwin);
  799. {$define default_target_set}
  800. {$endif}
  801. {$endif cpupowerpc}
  802. {$ifndef default_target_set}
  803. default_target(system_powerpc_linux);
  804. {$endif default_target_set}
  805. {$endif powerpc}
  806. {$ifdef POWERPC64}
  807. {$ifdef cpupowerpc64}
  808. default_target(source_info.system);
  809. {$define default_target_set}
  810. {$else cpupowerpc64}
  811. {$ifdef darwin}
  812. default_target(system_powerpc64_darwin);
  813. {$define default_target_set}
  814. {$endif}
  815. {$ifdef linux}
  816. default_target(system_powerpc64_linux);
  817. {$define default_target_set}
  818. {$endif}
  819. {$endif cpupowerpc64}
  820. {$ifndef default_target_set}
  821. default_target(system_powerpc64_linux);
  822. {$define default_target_set}
  823. {$endif}
  824. {$endif POWERPC64}
  825. {$ifdef sparc}
  826. {$ifdef cpusparc}
  827. default_target(source_info.system);
  828. {$else cpusparc}
  829. default_target(system_sparc_linux);
  830. {$endif cpusparc}
  831. {$endif sparc}
  832. {$ifdef arm}
  833. {$ifdef cpuarm}
  834. default_target(source_info.system);
  835. {$else cpuarm}
  836. {$ifdef WINDOWS}
  837. {$define default_target_set}
  838. default_target(system_arm_wince);
  839. {$endif}
  840. {$ifdef linux}
  841. {$define default_target_set}
  842. default_target(system_arm_linux);
  843. {$endif}
  844. {$ifdef darwin}
  845. {$define default_target_set}
  846. default_target(system_arm_darwin);
  847. {$endif}
  848. {$ifndef default_target_set}
  849. default_target(system_arm_linux);
  850. {$define default_target_set}
  851. {$endif}
  852. {$endif cpuarm}
  853. {$endif arm}
  854. {$ifdef avr}
  855. default_target(system_avr_embedded);
  856. {$endif avr}
  857. end;
  858. initialization
  859. source_info.name:='';
  860. finalization
  861. DeregisterInfos;
  862. end.