systems.pas 28 KB

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