systems.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit contains information about the target systems supported
  5. (these are not processor specific)
  6. This program is free software; you can redistribute it and/or modify
  7. iu under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge- MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit systems;
  20. {$i defines.inc}
  21. interface
  22. type
  23. tendian = (endian_little,endian_big);
  24. {
  25. IMPORTANT NOTE:
  26. The value of this enumeration is stored in PPU files.
  27. Therefore adding new CPU targets should not change the
  28. values of the pre-existing targets. (CEC)
  29. FURTHERMORE : Make sure that this branch values, are
  30. consistant with the main branch version always.
  31. }
  32. ttargetcpu=
  33. (
  34. no_cpu, { 0 }
  35. i386, { 1 }
  36. m68k, { 2 }
  37. alpha, { 3 }
  38. powerpc, { 4 }
  39. sparc, { 5 }
  40. vm { 6 }
  41. );
  42. tprocessors = (no_processor
  43. ,Class386,ClassP5,ClassP6
  44. ,MC68000,MC68100,MC68020
  45. );
  46. tsection=(sec_none,
  47. sec_code,sec_data,sec_bss,
  48. sec_idata2,sec_idata4,sec_idata5,sec_idata6,sec_idata7,sec_edata,
  49. sec_stab,sec_stabstr
  50. );
  51. tasmmode= (asmmode_none
  52. ,asmmode_i386_direct,asmmode_i386_att,asmmode_i386_intel
  53. ,asmmode_m68k_mot
  54. ,asmmode_alpha_direct
  55. ,asmmode_powerpc_direct
  56. );
  57. { IMPORTANT NOTE:
  58. the integer value of this enum is stored in PPU
  59. files to recognize the target, so if you add new targets
  60. allways add them at end PM
  61. FURTHERMORE : Make sure that this branch values, are
  62. consistant with the main branch version always. (CEC)
  63. }
  64. type
  65. ttarget =
  66. (
  67. target_none, { 0 }
  68. obsolete_target_i386_GO32V1,{ 1 }
  69. target_i386_GO32V2, { 2 }
  70. target_i386_linux, { 3 }
  71. target_i386_OS2, { 4 }
  72. target_i386_Win32, { 5 }
  73. target_i386_freebsd, { 6 }
  74. target_m68k_Amiga, { 7 }
  75. target_m68k_Atari, { 8 }
  76. target_m68k_Mac, { 9 }
  77. target_m68k_linux, { 10 }
  78. target_m68k_PalmOS, { 11 }
  79. target_alpha_linux, { 12 }
  80. target_powerpc_linux, { 13 }
  81. target_powerpc_macos, { 14 }
  82. target_i386_sunos, { 15 }
  83. target_i386_beos, { 16 }
  84. target_i386_netbsd, { 17 }
  85. target_m68k_netbsd, { 18 }
  86. target_i386_Netware, { 19 }
  87. target_i386_qnx, { 20 }
  88. target_i386_wdosx, { 21 }
  89. target_sparc_sunos, { 22 }
  90. target_sparc_linux { 23 }
  91. );
  92. tasm = (as_none
  93. ,as_i386_as,as_i386_as_aout,as_i386_asw,as_i386_aswdosx,
  94. as_i386_nasmcoff,as_i386_nasmwin32,as_i386_nasmwdosx,
  95. as_i386_nasmelf,as_i386_nasmobj,
  96. as_i386_tasm,as_i386_masm,
  97. as_i386_dbg,as_i386_coff,as_i386_pecoff,as_i386_elf32,as_i386_pecoffwdosx
  98. ,as_m68k_as,as_m68k_gas,as_m68k_mit,as_m68k_mot,
  99. as_m68k_mpw,as_m68k_palm
  100. ,as_alpha_as
  101. ,as_powerpc_as,as_powerpc_mpw
  102. );
  103. tld = (ld_none,
  104. ld_i386_GO32V1,ld_i386_GO32V2,ld_i386_linux,
  105. ld_i386_OS2,ld_i386_Win32,ld_i386_freebsd,
  106. ld_i386_Netware,ld_i386_sunos,ld_i386_beos,
  107. ld_m68k_Amiga,ld_m68k_Atari,ld_m68k_Mac,
  108. ld_m68k_linux,ld_m68k_PalmOS,ld_m68k_freebsd,
  109. ld_alpha_linux,
  110. ld_powerpc_linux,ld_powerpc_macos,ld_i386_Wdosx
  111. );
  112. tar = (ar_none
  113. ,ar_gnu_ar,ar_gnu_arw
  114. );
  115. tres = (res_none
  116. ,res_gnu_windres,res_emxbind
  117. );
  118. tscripttype = (script_none
  119. ,script_dos,script_unix,script_amiga
  120. );
  121. {*****************************************************************************
  122. Structures
  123. *****************************************************************************}
  124. type
  125. palignmentinfo = ^talignmentinfo;
  126. talignmentinfo = packed record
  127. procalign,
  128. loopalign,
  129. jumpalign,
  130. constalignmin,
  131. constalignmax,
  132. varalignmin,
  133. varalignmax,
  134. localalignmin,
  135. localalignmax,
  136. paraalign,
  137. recordalignmin,
  138. recordalignmax,
  139. maxCrecordalign : longint;
  140. end;
  141. pasminfo = ^tasminfo;
  142. tasminfo = packed record
  143. id : tasm;
  144. idtxt : string[9];
  145. asmbin : string[8];
  146. asmcmd : string[50];
  147. supported_target : ttarget;
  148. outputbinary,
  149. allowdirect,
  150. externals,
  151. needar,
  152. labelprefix_only_inside_procedure : boolean;
  153. labelprefix : string[3];
  154. comment : string[2];
  155. secnames : array[tsection] of string[20];
  156. end;
  157. parinfo = ^tarinfo;
  158. tarinfo = packed record
  159. id : tar;
  160. arcmd : string[50];
  161. end;
  162. presinfo = ^tresinfo;
  163. tresinfo = packed record
  164. id : tres;
  165. resbin : string[8];
  166. rescmd : string[50];
  167. end;
  168. ttargetflags = (tf_none,
  169. tf_under_development,tf_supports_stack_checking,
  170. tf_need_export,tf_needs_isconsole
  171. {$ifdef m68k}
  172. ,tf_code_small,tf_static_a5_based
  173. {$endif m68k}
  174. );
  175. ptargetinfo = ^ttargetinfo;
  176. ttargetinfo = packed record
  177. target : ttarget;
  178. name : string[30];
  179. shortname : string[9];
  180. flags : set of ttargetflags;
  181. cpu : ttargetcpu;
  182. unit_env : string[12];
  183. extradefines : string[40];
  184. sourceext,
  185. pasext,
  186. exeext,
  187. defext,
  188. scriptext,
  189. smartext,
  190. unitext,
  191. unitlibext,
  192. asmext,
  193. objext,
  194. resext,
  195. resobjext : string[4];
  196. sharedlibext : string[10];
  197. staticlibext,
  198. staticlibprefix : string[4];
  199. sharedlibprefix : string[4];
  200. sharedClibext : string[10];
  201. staticClibext,
  202. staticClibprefix : string[4];
  203. sharedClibprefix : string[4];
  204. Cprefix : string[2];
  205. newline : string[2];
  206. dirsep : char;
  207. files_case_relevent : boolean;
  208. assem : tasm;
  209. assemextern : tasm; { external assembler, used by -a }
  210. link : tld;
  211. linkextern : tld; { external linker, used by -s }
  212. ar : tar;
  213. res : tres;
  214. script : tscripttype;
  215. endian : tendian;
  216. alignment : talignmentinfo;
  217. size_of_longint : byte;
  218. heapsize,
  219. maxheapsize,
  220. stacksize : longint;
  221. DllScanSupported : boolean;
  222. use_bound_instruction : boolean;
  223. use_function_relative_addresses : boolean;
  224. end;
  225. pasmmodeinfo = ^tasmmodeinfo;
  226. tasmmodeinfo = packed record
  227. id : tasmmode;
  228. idtxt : string[8];
  229. end;
  230. const
  231. { alias for supported_target field in tasminfo }
  232. target_any = target_none;
  233. var
  234. targetinfos : array[ttarget] of ptargetinfo;
  235. asminfos : array[tasm] of pasminfo;
  236. arinfos : array[tar] of parinfo;
  237. resinfos : array[tres] of presinfo;
  238. asmmodeinfos : array[tasmmode] of pasmmodeinfo;
  239. source_info : ttargetinfo;
  240. target_cpu : ttargetcpu;
  241. target_info : ttargetinfo;
  242. target_asm : tasminfo;
  243. target_ar : tarinfo;
  244. target_res : tresinfo;
  245. target_path : string[12]; { for rtl/<X>/,fcl/<X>/, etc. }
  246. function set_target(t:ttarget):boolean;
  247. function set_target_asm(t:tasm):boolean;
  248. function set_target_ar(t:tar):boolean;
  249. function set_target_res(t:tres):boolean;
  250. function set_target_by_string(const s : string) : boolean;
  251. function set_target_asm_by_string(const s : string) : boolean;
  252. function set_asmmode_by_string(const s:string;var t:tasmmode):boolean;
  253. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  254. procedure RegisterTarget(const r:ttargetinfo);
  255. procedure RegisterAsmMode(const r:tasmmodeinfo);
  256. procedure RegisterRes(const r:tresinfo);
  257. procedure RegisterAr(const r:tarinfo);
  258. procedure InitSystems;
  259. implementation
  260. uses
  261. cutils;
  262. {****************************************************************************
  263. Target setting
  264. ****************************************************************************}
  265. function set_target(t:ttarget):boolean;
  266. begin
  267. set_target:=false;
  268. if assigned(targetinfos[t]) then
  269. begin
  270. target_info:=targetinfos[t]^;
  271. set_target_asm(target_info.assem);
  272. set_target_ar(target_info.ar);
  273. set_target_res(target_info.res);
  274. target_path:=lower(target_info.shortname);
  275. target_cpu:=target_info.cpu;
  276. set_target:=true;
  277. exit;
  278. end;
  279. end;
  280. function set_target_asm(t:tasm):boolean;
  281. begin
  282. set_target_asm:=false;
  283. if assigned(asminfos[t]) then
  284. begin
  285. target_asm:=asminfos[t]^;
  286. set_target_asm:=true;
  287. exit;
  288. end;
  289. end;
  290. function set_target_ar(t:tar):boolean;
  291. begin
  292. set_target_ar:=false;
  293. if assigned(arinfos[t]) then
  294. begin
  295. target_ar:=arinfos[t]^;
  296. set_target_ar:=true;
  297. exit;
  298. end;
  299. end;
  300. function set_target_res(t:tres):boolean;
  301. begin
  302. set_target_res:=false;
  303. if assigned(resinfos[t]) then
  304. begin
  305. target_res:=resinfos[t]^;
  306. set_target_res:=true;
  307. exit;
  308. end;
  309. end;
  310. function set_target_by_string(const s : string) : boolean;
  311. var
  312. hs : string;
  313. t : ttarget;
  314. begin
  315. set_target_by_string:=false;
  316. { this should be case insensitive !! PM }
  317. hs:=upper(s);
  318. for t:=low(ttarget) to high(ttarget) do
  319. if assigned(targetinfos[t]) and
  320. (upper(targetinfos[t]^.shortname)=hs) then
  321. begin
  322. set_target_by_string:=set_target(t);
  323. exit;
  324. end;
  325. end;
  326. function set_target_asm_by_string(const s : string) : boolean;
  327. var
  328. hs : string;
  329. t : tasm;
  330. begin
  331. set_target_asm_by_string:=false;
  332. { this should be case insensitive !! PM }
  333. hs:=upper(s);
  334. for t:=low(tasm) to high(tasm) do
  335. if assigned(asminfos[t]) and
  336. (asminfos[t]^.idtxt=hs) then
  337. begin
  338. set_target_asm_by_string:=set_target_asm(t);
  339. exit;
  340. end;
  341. end;
  342. function set_asmmode_by_string(const s:string;var t:tasmmode):boolean;
  343. var
  344. hs : string;
  345. ht : tasmmode;
  346. begin
  347. set_asmmode_by_string:=false;
  348. { this should be case insensitive !! PM }
  349. hs:=upper(s);
  350. for ht:=low(tasmmode) to high(tasmmode) do
  351. if assigned(asmmodeinfos[ht]) and
  352. (asmmodeinfos[ht]^.idtxt=hs) then
  353. begin
  354. t:=asmmodeinfos[ht]^.id;
  355. set_asmmode_by_string:=true;
  356. end;
  357. end;
  358. procedure UpdateAlignment(var d:talignmentinfo;const s:talignmentinfo);
  359. begin
  360. with d do
  361. begin
  362. { general update rules:
  363. minimum: if higher then update
  364. maximum: if lower then update or if undefined then update }
  365. if s.procalign>procalign then
  366. procalign:=s.procalign;
  367. if s.loopalign>loopalign then
  368. loopalign:=s.loopalign;
  369. if s.jumpalign>jumpalign then
  370. jumpalign:=s.jumpalign;
  371. if s.constalignmin>constalignmin then
  372. constalignmin:=s.constalignmin;
  373. if (constalignmax=0) or
  374. ((s.constalignmax>0) and (s.constalignmax<constalignmax)) then
  375. constalignmax:=s.constalignmax;
  376. if s.varalignmin>varalignmin then
  377. varalignmin:=s.varalignmin;
  378. if (varalignmax=0) or
  379. ((s.varalignmax>0) and (s.varalignmax<varalignmax)) then
  380. varalignmax:=s.varalignmax;
  381. if s.localalignmin>localalignmin then
  382. localalignmin:=s.localalignmin;
  383. if (localalignmax=0) or
  384. ((s.localalignmax>0) and (s.localalignmax<localalignmax)) then
  385. localalignmax:=s.localalignmax;
  386. if s.paraalign>paraalign then
  387. paraalign:=s.paraalign;
  388. if s.recordalignmin>recordalignmin then
  389. recordalignmin:=s.recordalignmin;
  390. if (recordalignmax=0) or
  391. ((s.recordalignmax>0) and (s.recordalignmax<recordalignmax)) then
  392. recordalignmax:=s.recordalignmax;
  393. if (maxCrecordalign=0) or
  394. ((s.maxCrecordalign>0) and (s.maxCrecordalign<maxCrecordalign)) then
  395. maxCrecordalign:=s.maxCrecordalign;
  396. end;
  397. end;
  398. {****************************************************************************
  399. Target registration
  400. ****************************************************************************}
  401. procedure RegisterTarget(const r:ttargetinfo);
  402. var
  403. t : ttarget;
  404. begin
  405. t:=r.target;
  406. if assigned(targetinfos[t]) then
  407. writeln('Warning: Target is already registered!')
  408. else
  409. Getmem(targetinfos[t],sizeof(ttargetinfo));
  410. targetinfos[t]^:=r;
  411. end;
  412. procedure RegisterAsmmode(const r:tasmmodeinfo);
  413. var
  414. t : tasmmode;
  415. begin
  416. t:=r.id;
  417. if assigned(asmmodeinfos[t]) then
  418. writeln('Warning: Asmmode is already registered!')
  419. else
  420. Getmem(asmmodeinfos[t],sizeof(tasmmodeinfo));
  421. asmmodeinfos[t]^:=r;
  422. end;
  423. procedure RegisterRes(const r:tresinfo);
  424. var
  425. t : tres;
  426. begin
  427. t:=r.id;
  428. if assigned(resinfos[t]) then
  429. writeln('Warning: resourcecompiler is already registered!')
  430. else
  431. Getmem(resinfos[t],sizeof(tresinfo));
  432. resinfos[t]^:=r;
  433. end;
  434. procedure RegisterAr(const r:tarinfo);
  435. var
  436. t : tar;
  437. begin
  438. t:=r.id;
  439. if assigned(arinfos[t]) then
  440. writeln('Warning: ar is already registered!')
  441. else
  442. Getmem(arinfos[t],sizeof(tarinfo));
  443. arinfos[t]^:=r;
  444. end;
  445. procedure DeregisterInfos;
  446. var
  447. assem : tasm;
  448. target : ttarget;
  449. ar : tar;
  450. asmmode : tasmmode;
  451. res : tres;
  452. begin
  453. for target:=low(ttarget) to high(ttarget) do
  454. if assigned(targetinfos[target]) then
  455. begin
  456. freemem(targetinfos[target],sizeof(ttargetinfo));
  457. targetinfos[target]:=nil;
  458. end;
  459. for assem:=low(tasm) to high(tasm) do
  460. if assigned(asminfos[assem]) then
  461. begin
  462. freemem(asminfos[assem],sizeof(tasminfo));
  463. asminfos[assem]:=nil;
  464. end;
  465. for ar:=low(tar) to high(tar) do
  466. if assigned(arinfos[ar]) then
  467. begin
  468. freemem(arinfos[ar],sizeof(tarinfo));
  469. arinfos[ar]:=nil;
  470. end;
  471. for res:=low(tres) to high(tres) do
  472. if assigned(resinfos[res]) then
  473. begin
  474. freemem(resinfos[res],sizeof(tresinfo));
  475. resinfos[res]:=nil;
  476. end;
  477. for asmmode:=low(tasmmode) to high(tasmmode) do
  478. if assigned(asmmodeinfos[asmmode]) then
  479. begin
  480. freemem(asmmodeinfos[asmmode],sizeof(tasmmodeinfo));
  481. asmmodeinfos[asmmode]:=nil;
  482. end;
  483. end;
  484. {****************************************************************************
  485. Initialization of default target
  486. ****************************************************************************}
  487. procedure default_target(t:ttarget);
  488. begin
  489. set_target(t);
  490. if source_info.name='' then
  491. source_info:=target_info;
  492. end;
  493. procedure set_source(t:ttarget);
  494. begin
  495. { can't use message() here (PFV) }
  496. if source_info.name<>'' then
  497. Writeln('Warning: Source OS Redefined!');
  498. if assigned(targetinfos[t]) then
  499. source_info:=targetinfos[t]^
  500. else
  501. Writeln('Warning: Source OS Not Supported!');
  502. end;
  503. procedure InitSystems;
  504. begin
  505. { first get source OS }
  506. source_info.name:='';
  507. { please note then we use cpu86 and cpu68 here on purpose !! }
  508. {$ifdef cpu86}
  509. {$ifdef GO32V2}
  510. set_source(target_i386_GO32V2);
  511. {$else}
  512. {$ifdef OS2}
  513. set_source(target_i386_OS2);
  514. if (OS_Mode = osDOS) or (OS_Mode = osDPMI) then
  515. source_info.scriptext := '.bat';
  516. { OS/2 via EMX can be run under DOS as well }
  517. {$else}
  518. {$ifdef WIN32}
  519. {$ifdef WDOSX}
  520. set_source(target_i386_wdosx);
  521. {$else}
  522. set_source(target_i386_WIN32);
  523. {$endif}
  524. {$else}
  525. {$ifdef FreeBSD}
  526. set_source(target_i386_FreeBSD);
  527. {$else}
  528. {$ifdef netbsd}
  529. set_source(target_i386_NetBSD);
  530. {$else}
  531. {$ifdef sunos}
  532. set_source(target_i386_sunos);
  533. {$else}
  534. {$ifdef beos}
  535. set_source(target_i386_beos);
  536. {$else}
  537. { Must be the last as some freebsd also
  538. defined linux }
  539. {$ifdef linux}
  540. set_source(target_i386_linux);
  541. {$else}
  542. {$error Error setting source OS}
  543. {$endif linux}
  544. {$endif beos}
  545. {$endif sunos}
  546. {$endif netbsd}
  547. {$endif freebsd}
  548. {$endif win32}
  549. {$endif os2}
  550. {$endif go32v2}
  551. {$endif cpu86}
  552. {$ifdef cpu68}
  553. {$ifdef AMIGA}
  554. set_source(target_m68k_Amiga);
  555. {$else}
  556. {$ifdef ATARI}
  557. set_source(target_m68k_Atari);
  558. {$else}
  559. {$ifdef MACOS}
  560. set_source(target_m68k_MAC);
  561. {$else}
  562. {$ifdef linux}
  563. set_source(target_m68k_linux);
  564. {$endif linux}
  565. {$endif macos}
  566. {$endif atari}
  567. {$endif amiga}
  568. {$endif cpu68}
  569. { Now default target, this is dependent on the i386 or m68k define,
  570. when the define is the same as the current cpu then we use the source
  571. os, else we pick a default }
  572. {$ifdef i386}
  573. {$ifdef cpu86}
  574. default_target(source_info.target);
  575. {$else cpu86}
  576. default_target(target_i386_linux);
  577. {$endif cpu86}
  578. {$endif i386}
  579. {$ifdef m68k}
  580. {$ifdef cpu68}
  581. default_target(source_info.target);
  582. {$else cpu68}
  583. default_target(target_m68k_linux);
  584. {$endif cpu68}
  585. {$endif m68k}
  586. {$ifdef alpha}
  587. {$ifdef cpualpha}
  588. default_target(source_info.target);
  589. {$else cpualpha}
  590. default_target(target_alpha_linux);
  591. {$endif cpualpha}
  592. {$endif alpha}
  593. {$ifdef powerpc}
  594. {$ifdef cpuppc}
  595. default_target(source_info.target);
  596. {$else cpuppc}
  597. default_target(target_powerpc_linux);
  598. {$endif cpuppc}
  599. {$endif powerpc}
  600. end;
  601. initialization
  602. finalization
  603. DeregisterInfos;
  604. end.
  605. {
  606. $Log$
  607. Revision 1.39 2002-04-15 19:08:22 carl
  608. + target_info.size_of_pointer -> pointer_size
  609. + some cleanup of unused types/variables
  610. Revision 1.38 2002/04/14 16:56:30 carl
  611. - remove duplicate comment
  612. Revision 1.37 2002/04/07 10:20:15 carl
  613. + added SPARC targets
  614. + added VM target
  615. Revision 1.36 2002/04/04 19:18:06 carl
  616. - removed cmnts
  617. }