systems.pas 19 KB

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