systems.pas 29 KB

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