cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. {******************************************************************************
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl and Peter Vreman
  4. Contains the base types for the Scalable Processor ARChitecture (SPARC)
  5. This program is free software; you can redistribute it and/or modify
  6. it 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. unit cpuBase;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globals,cutils,cclasses,aasmbase,cpuinfo,cginfo;
  22. const
  23. {Size of the instruction table converted by nasmconv.pas}
  24. maxinfolen=8;
  25. {Defines the default address size for a processor}
  26. OS_ADDR=OS_32;
  27. {the natural int size for a processor}
  28. OS_INT=OS_32;
  29. {the maximum float size for a processor}
  30. OS_FLOAT=OS_F64;
  31. {the size of a vector register for a processor}
  32. OS_VECTOR=OS_M64;
  33. type
  34. {$WARNING CPU32 opcodes do not fully include the Ultra SPRAC instruction set.}
  35. { don't change the order of these opcodes! }
  36. TAsmOp=({$INCLUDE opcode.inc});
  37. op2strtable=array[TAsmOp]OF STRING[11];
  38. CONST
  39. FirstOp=Low(TAsmOp);
  40. LastOp=High(TAsmOp);
  41. std_op2str:op2strtable=({$INCLUDE strinst.inc});
  42. {*****************************************************************************
  43. Operand Sizes
  44. *****************************************************************************}
  45. type
  46. TOpSize=(S_NO,
  47. S_B,{Byte}
  48. S_H,{Half word}
  49. S_W,{Word}
  50. S_L:=S_W,
  51. S_D,{Double Word}
  52. S_Q,{Quad word}
  53. S_IQ:=S_Q,
  54. S_SB,{Signed byte}
  55. S_SH,{Signed half word}
  56. S_SW,{Signed word}
  57. S_SD,{Signed double word}
  58. S_SQ,{Signed quad word}
  59. S_FS,{Float single word}
  60. S_FX:=S_FS,
  61. S_FD,{Float double word}
  62. S_FQ,{Float quad word}
  63. S_NEAR,
  64. S_FAR,
  65. S_SHORT);
  66. {*****************************************************************************}
  67. { Conditions }
  68. {*****************************************************************************}
  69. type
  70. TAsmCond=(C_None,
  71. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  72. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  73. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  74. );
  75. CONST
  76. cond2str:array[TAsmCond] of string[3]=('',
  77. 'a','ae','b','be','c','e','g','ge','l','le','na','nae',
  78. 'nb','nbe','nc','ne','ng','nge','nl','nle','no','np',
  79. 'ns','nz','o','p','pe','po','s','z'
  80. );
  81. inverse_cond:array[TAsmCond] of TAsmCond=(C_None,
  82. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  83. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  84. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  85. );
  86. CONST
  87. CondAsmOps=3;
  88. CondAsmOp:array[0..CondAsmOps-1] of TAsmOp=(A_FCMPd, A_JMPL, A_FCMPs);
  89. CondAsmOpStr:array[0..CondAsmOps-1] of string[7]=('FCMPd','JMPL','FCMPs');
  90. {*****************************************************************************}
  91. { Registers }
  92. {*****************************************************************************}
  93. type
  94. { enumeration for registers, don't change the order }
  95. { it's used by the register size conversions }
  96. TCpuRegister=({$INCLUDE cpuregs.inc});
  97. TOldRegister=TCpuRegister;
  98. Tnewregister=word;
  99. Tsuperregister=byte;
  100. Tsubregister=byte;
  101. Tregister=record
  102. enum:TCpuRegister;
  103. number:Tnewregister;
  104. end;
  105. TRegister64=PACKED RECORD
  106. {A type to store register locations for 64 Bit values.}
  107. RegLo,RegHi:TRegister;
  108. end;
  109. treg64=tregister64;{alias for compact code}
  110. TRegisterSet=SET OF TCpuRegister;
  111. Tsupregset=set of Tsuperregister;
  112. const
  113. R_NO=R_NONE;
  114. firstreg = Succ(R_NONE);
  115. lastreg = Pred(R_INTREGISTER);
  116. {General registers.}
  117. const
  118. NR_NONE=$0000;
  119. NR_NO=NR_NONE;
  120. NR_G0=$0001;
  121. NR_G1=$0002;
  122. NR_G2=$0003;
  123. NR_G3=$0004;
  124. NR_G4=$0005;
  125. NR_G5=$0006;
  126. NR_G6=$0007;
  127. NR_G7=$0008;
  128. NR_O0=$0100;
  129. NR_O1=$0200;
  130. NR_O2=$0300;
  131. NR_O3=$0400;
  132. NR_O4=$0500;
  133. NR_O5=$0600;
  134. NR_O6=$0700;
  135. NR_O7=$0800;
  136. NR_L0=$0900;
  137. NR_L1=$0A00;
  138. NR_L2=$0B00;
  139. NR_L3=$0C00;
  140. NR_L4=$0D00;
  141. NR_L5=$0E00;
  142. NR_L6=$0F00;
  143. NR_L7=$1000;
  144. NR_I0=$1100;
  145. NR_I1=$1200;
  146. NR_I2=$1300;
  147. NR_I3=$1400;
  148. NR_I4=$1500;
  149. NR_I5=$1600;
  150. NR_I6=$1700;
  151. NR_I7=$1800;
  152. {Floating point}
  153. NR_F0=$2000;
  154. NR_F1=$2000;
  155. NR_F2=$2000;
  156. NR_F3=$2000;
  157. NR_F4=$2000;
  158. NR_F5=$2000;
  159. NR_F6=$2000;
  160. NR_F7=$2000;
  161. NR_F8=$2000;
  162. NR_F9=$2000;
  163. NR_F10=$2000;
  164. NR_F11=$2000;
  165. NR_F12=$2000;
  166. NR_F13=$2000;
  167. NR_F14=$2000;
  168. NR_F15=$2000;
  169. NR_F16=$2000;
  170. NR_F17=$2000;
  171. NR_F18=$2000;
  172. NR_F19=$2000;
  173. NR_F20=$2000;
  174. NR_F21=$2000;
  175. NR_F22=$2000;
  176. NR_F23=$2000;
  177. NR_F24=$2000;
  178. NR_F25=$2000;
  179. NR_F26=$2000;
  180. NR_F27=$2000;
  181. NR_F28=$2000;
  182. NR_F29=$2000;
  183. NR_F30=$2000;
  184. NR_F31=$2000;
  185. {Coprocessor point}
  186. NR_C0=$3000;
  187. NR_C1=$3000;
  188. NR_C2=$3000;
  189. NR_C3=$3000;
  190. NR_C4=$3000;
  191. NR_C5=$3000;
  192. NR_C6=$3000;
  193. NR_C7=$3000;
  194. NR_C8=$3000;
  195. NR_C9=$3000;
  196. NR_C10=$3000;
  197. NR_C11=$3000;
  198. NR_C12=$3000;
  199. NR_C13=$3000;
  200. NR_C14=$3000;
  201. NR_C15=$3000;
  202. NR_C16=$3000;
  203. NR_C17=$3000;
  204. NR_C18=$3000;
  205. NR_C19=$3000;
  206. NR_C20=$3000;
  207. NR_C21=$3000;
  208. NR_C22=$3000;
  209. NR_C23=$3000;
  210. NR_C24=$3000;
  211. NR_C25=$3000;
  212. NR_C26=$3000;
  213. NR_C27=$3000;
  214. NR_C28=$3000;
  215. NR_C29=$3000;
  216. NR_C30=$3000;
  217. NR_C31=$3000;
  218. {ASR}
  219. NR_ASR0=$4000;
  220. NR_ASR1=$4000;
  221. NR_ASR2=$4000;
  222. NR_ASR3=$4000;
  223. NR_ASR4=$4000;
  224. NR_ASR5=$4000;
  225. NR_ASR6=$4000;
  226. NR_ASR7=$4000;
  227. NR_ASR8=$4000;
  228. NR_ASR9=$4000;
  229. NR_ASR10=$4000;
  230. NR_ASR11=$4000;
  231. NR_ASR12=$4000;
  232. NR_ASR13=$4000;
  233. NR_ASR14=$4000;
  234. NR_ASR15=$4000;
  235. NR_ASR16=$4000;
  236. NR_ASR17=$4000;
  237. NR_ASR18=$4000;
  238. NR_ASR19=$4000;
  239. NR_ASR20=$4000;
  240. NR_ASR21=$4000;
  241. NR_ASR22=$4000;
  242. NR_ASR23=$4000;
  243. NR_ASR24=$4000;
  244. NR_ASR25=$4000;
  245. NR_ASR26=$4000;
  246. NR_ASR27=$4000;
  247. NR_ASR28=$4000;
  248. NR_ASR29=$4000;
  249. NR_ASR30=$4000;
  250. NR_ASR31=$4000;
  251. {Floating point status/"front of queue" registers}
  252. NR_FSR=$5000;
  253. NR_FQ=$5001; { was $50001, probably typo (FK) }
  254. NR_CSR=$5000;
  255. NR_CQ=$5000;
  256. NR_PSR=$5000;
  257. NR_TBR=$5000;
  258. NR_WIM=$5000;
  259. NR_Y=$5000;
  260. {Conversion between TCpuRegister and NewRegisters}
  261. RegEnum2Number:array[TCpuRegister]of cardinal=(
  262. NR_NO,
  263. NR_G0,
  264. NR_G1,
  265. NR_G2,
  266. NR_G3,
  267. NR_G4,
  268. NR_G5,
  269. NR_G6,
  270. NR_G7,
  271. NR_O0,
  272. NR_O1,
  273. NR_O2,
  274. NR_O3,
  275. NR_O4,
  276. NR_O5,
  277. NR_O6,
  278. NR_O7,
  279. NR_L0,
  280. NR_L1,
  281. NR_L2,
  282. NR_L3,
  283. NR_L4,
  284. NR_L5,
  285. NR_L6,
  286. NR_L7,
  287. NR_I0,
  288. NR_I1,
  289. NR_I2,
  290. NR_I3,
  291. NR_I4,
  292. NR_I5,
  293. NR_I6,
  294. NR_I7,
  295. NR_NO,
  296. NR_NO,
  297. NR_NO,
  298. NR_NO,
  299. NR_NO,
  300. NR_NO,
  301. NR_NO,
  302. NR_NO,
  303. NR_NO,
  304. NR_NO,
  305. NR_NO,
  306. NR_NO,
  307. NR_NO,
  308. NR_NO,
  309. NR_NO,
  310. NR_NO,
  311. NR_NO,
  312. NR_NO,
  313. NR_NO,
  314. NR_NO,
  315. NR_NO,
  316. NR_NO,
  317. NR_NO,
  318. NR_NO,
  319. NR_NO,
  320. NR_NO,
  321. NR_NO,
  322. NR_NO,
  323. NR_NO,
  324. NR_NO,
  325. NR_NO,
  326. NR_NO,
  327. NR_NO,
  328. NR_NO,
  329. NR_NO,
  330. NR_NO,
  331. NR_NO,
  332. NR_NO,
  333. NR_NO,
  334. NR_NO,
  335. NR_NO,
  336. NR_NO,
  337. NR_NO,
  338. NR_NO,
  339. NR_NO,
  340. NR_NO,
  341. NR_NO,
  342. NR_NO,
  343. NR_NO,
  344. NR_NO,
  345. NR_NO,
  346. NR_NO,
  347. NR_NO,
  348. NR_NO,
  349. NR_NO,
  350. NR_NO,
  351. NR_NO,
  352. NR_NO,
  353. NR_NO,
  354. NR_NO,
  355. NR_NO,
  356. NR_NO,
  357. NR_NO,
  358. NR_NO,
  359. NR_NO,
  360. NR_NO,
  361. NR_NO,
  362. NR_NO,
  363. NR_NO,
  364. NR_NO,
  365. NR_NO,
  366. NR_NO,
  367. NR_NO,
  368. NR_NO,
  369. NR_NO,
  370. NR_NO,
  371. NR_NO,
  372. NR_NO,
  373. NR_NO,
  374. NR_NO,
  375. NR_NO,
  376. NR_NO,
  377. NR_NO,
  378. NR_NO,
  379. NR_NO,
  380. NR_NO,
  381. NR_NO,
  382. NR_NO,
  383. NR_NO,
  384. NR_NO,
  385. NR_NO,
  386. NR_NO,
  387. NR_NO,
  388. NR_NO,
  389. NR_NO,
  390. NR_NO,
  391. NR_NO,
  392. NR_NO,
  393. NR_NO,
  394. NR_NO,
  395. NR_NO,
  396. NR_NO,
  397. NR_NO,
  398. NR_NO,
  399. NR_NO,
  400. NR_NO,
  401. NR_NO,
  402. NR_NO
  403. );
  404. {Superregisters.}
  405. const
  406. RS_O0=$01;
  407. RS_O1=$02;
  408. RS_O2=$03;
  409. RS_O3=$04;
  410. RS_O4=$05;
  411. RS_O5=$06;
  412. RS_O6=$07;
  413. RS_O7=$08;
  414. RS_L0=$09;
  415. RS_L1=$0A;
  416. RS_L2=$0B;
  417. RS_L3=$0C;
  418. RS_L4=$0D;
  419. RS_L5=$0E;
  420. RS_L6=$0F;
  421. RS_L7=$10;
  422. RS_I0=$11;
  423. RS_I1=$12;
  424. RS_I2=$13;
  425. RS_I3=$14;
  426. RS_I4=$15;
  427. RS_I5=$16;
  428. RS_I6=$17;
  429. RS_I7=$18;
  430. RS_G0=$19;
  431. RS_G1=$1A;
  432. RS_G2=$1B;
  433. RS_G3=$1C;
  434. RS_G4=$1D;
  435. RS_G5=$1E;
  436. RS_G6=$1F;
  437. RS_G7=$20;
  438. first_supreg = $01;
  439. last_supreg = $20;
  440. first_imreg = $21;
  441. last_imreg = $ff;
  442. {Subregisters; nothing known about.}
  443. R_SUBWHOLE=$00;
  444. R_SUBL=$00;
  445. type
  446. reg2strtable=array[TCpuRegister] OF STRING[7];
  447. TCpuReg=array[TCpuRegister]of TRegister;
  448. const
  449. std_reg2str:reg2strtable=({$INCLUDE strregs.inc});
  450. CpuReg:TCpuReg=({$INCLUDE registers.inc});
  451. {*****************************************************************************
  452. Flags
  453. *****************************************************************************}
  454. type
  455. TResFlags=(
  456. F_E, {Equal}
  457. F_NE, {Not Equal}
  458. F_G, {Greater}
  459. F_L, {Less}
  460. F_GE, {Greater or Equal}
  461. F_LE, {Less or Equal}
  462. F_C, {Carry}
  463. F_NC, {Not Carry}
  464. F_A, {Above}
  465. F_AE, {Above or Equal}
  466. F_B, {Below}
  467. F_BE {Below or Equal}
  468. );
  469. {*****************************************************************************
  470. Reference
  471. *****************************************************************************}
  472. type
  473. TRefOptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  474. { since we have no full 32 bit offsets, we need to be able to specify the high
  475. and low bits of the address of a symbol }
  476. trefsymaddr = (refs_full,refs_hi,refs_lo);
  477. { immediate/reference record }
  478. poperreference = ^treference;
  479. Preference=^Treference;
  480. treference = packed record
  481. base,
  482. index : tregister;
  483. offset : LongInt;
  484. symbol : tasmsymbol;
  485. symaddr : trefsymaddr;
  486. offsetfixup : LongInt;
  487. options : trefoptions;
  488. alignment : byte;
  489. end;
  490. { reference record }
  491. PParaReference=^TParaReference;
  492. TParaReference = packed record
  493. Index : TRegister;
  494. Offset : longint;
  495. end;
  496. {*****************************************************************************
  497. Operands
  498. *****************************************************************************}
  499. { Types of operand }
  500. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  501. toper=record
  502. ot:LongInt;
  503. case typ:toptype of
  504. top_none:();
  505. top_reg:(reg:tregister);
  506. top_ref:(ref:poperreference);
  507. top_const:(val:aword);
  508. top_symbol:(sym:tasmsymbol;symofs:LongInt);
  509. end;
  510. {*****************************************************************************
  511. Argument Classification
  512. *****************************************************************************}
  513. type
  514. TArgClass = (
  515. { the following classes should be defined by all processor implemnations }
  516. AC_NOCLASS,
  517. AC_MEMORY,
  518. AC_INTEGER,
  519. AC_FPU,
  520. { the following argument classes are i386 specific }
  521. AC_FPUUP,
  522. AC_SSE,
  523. AC_SSEUP);
  524. {*****************************************************************************
  525. Generic Location
  526. *****************************************************************************}
  527. type
  528. { tparamlocation describes where a parameter for a procedure is stored.
  529. References are given from the caller's point of view. The usual TLocation isn't
  530. used, because contains a lot of unnessary fields. }
  531. TParaLocation=packed record
  532. Size:TCGSize;
  533. Loc:TCGLoc;
  534. sp_fixup:LongInt;
  535. CASE TCGLoc OF
  536. LOC_REFERENCE:(reference:tparareference);
  537. { segment in reference at the same place as in loc_register }
  538. LOC_REGISTER,LOC_CREGISTER : (
  539. CASE LongInt OF
  540. 1 : (register,registerhigh : tregister);
  541. { overlay a registerlow }
  542. 2 : (registerlow : tregister);
  543. { overlay a 64 Bit register type }
  544. 3 : (reg64 : tregister64);
  545. 4 : (register64 : tregister64);
  546. );
  547. { it's only for better handling }
  548. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  549. end;
  550. TLocation=packed record
  551. loc : TCGLoc;
  552. size : TCGSize;
  553. case TCGLoc of
  554. LOC_FLAGS : (resflags : tresflags);
  555. LOC_CONSTANT : (
  556. case longint of
  557. 1 : (value : AWord);
  558. 2 : (valuelow, valuehigh:AWord);
  559. { overlay a complete 64 Bit value }
  560. 3 : (valueqword : qword);
  561. );
  562. LOC_CREFERENCE,
  563. LOC_REFERENCE : (reference : treference);
  564. { segment in reference at the same place as in loc_register }
  565. LOC_REGISTER,LOC_CREGISTER : (
  566. case longint of
  567. 1 : (register,registerhigh,segment : tregister);
  568. { overlay a registerlow }
  569. 2 : (registerlow : tregister);
  570. { overlay a 64 Bit register type }
  571. 3 : (reg64 : tregister64);
  572. 4 : (register64 : tregister64);
  573. );
  574. { it's only for better handling }
  575. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  576. end;
  577. {*****************************************************************************
  578. Constants
  579. *****************************************************************************}
  580. const
  581. general_registers = [R_G0..R_I7];
  582. general_superregisters = [RS_O0..RS_I7];
  583. { legend: }
  584. { xxxregs = set of all possibly used registers of that type in the code }
  585. { generator }
  586. { usableregsxxx = set of all 32bit components of registers that can be }
  587. { possible allocated to a regvar or using getregisterxxx (this }
  588. { excludes registers which can be only used for parameter }
  589. { passing on ABI's that define this) }
  590. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  591. IntRegs=[R_G0..R_I7];
  592. usableregsint=[RS_O0..RS_I7];
  593. c_countusableregsint = 24;
  594. fpuregs=[R_F0..R_F31];
  595. usableregsfpu=[R_F0..R_F31];
  596. c_countusableregsfpu=32;
  597. mmregs=[];
  598. usableregsmm=[];
  599. c_countusableregsmm=0;
  600. { no distinction on this platform }
  601. maxaddrregs = 0;
  602. addrregs = [];
  603. usableregsaddr = [];
  604. c_countusableregsaddr = 0;
  605. firstsaveintreg = RS_O0;
  606. lastsaveintreg = RS_I7;
  607. firstsavefpureg = R_F0;
  608. lastsavefpureg = R_F31;
  609. firstsavemmreg = R_NONE;
  610. lastsavemmreg = R_NONE;
  611. lowsavereg = R_G0;
  612. highsavereg = R_I7;
  613. ALL_REGISTERS = [lowsavereg..highsavereg];
  614. ALL_INTREGISTERS = [1..255];
  615. lvaluelocations = [LOC_REFERENCE,LOC_CFPUREGISTER,
  616. LOC_CREGISTER,LOC_MMXREGISTER,LOC_CMMXREGISTER];
  617. {*****************************************************************************
  618. GDB Information
  619. *****************************************************************************}
  620. {# Register indexes for stabs information, when some parameters or variables
  621. are stored in registers.
  622. Taken from rs6000.h (DBX_REGISTER_NUMBER) from GCC 3.x source code.}
  623. stab_regindex:array[TCpuRegister]OF ShortInt=({$INCLUDE stabregi.inc});
  624. {*************************** generic register names **************************}
  625. stack_pointer_reg = R_O6;
  626. NR_STACK_POINTER_REG = NR_O6;
  627. RS_STACK_POINTER_REG = RS_O6;
  628. frame_pointer_reg = R_I6;
  629. NR_FRAME_POINTER_REG = NR_I6;
  630. RS_FRAME_POINTER_REG = RS_I6;
  631. {the return_result_reg, is used inside the called function to store its return
  632. value when that is a scalar value otherwise a pointer to the address of the
  633. result is placed inside it}
  634. return_result_reg = R_I0;
  635. NR_RETURN_RESULT_REG = NR_I0;
  636. RS_RETURN_RESULT_REG = RS_I0;
  637. {the function_result_reg contains the function result after a call to a scalar
  638. function othewise it contains a pointer to the returned result}
  639. function_result_reg = R_O0;
  640. NR_FUNCTION_RESULT_REG = NR_O0;
  641. RS_FUNCTION_RESULT_REG = RS_O0;
  642. self_pointer_reg =R_G5;
  643. NR_SELF_POINTER_REG = NR_G5;
  644. { RS_SELF_POINTER_REG = RS_G5;}
  645. {There is no accumulator in the SPARC architecture. There are just families
  646. of registers. All registers belonging to the same family are identical except
  647. in the "global registers" family where GO is different from the others :
  648. G0 gives always 0 when it is red and thows away any value written to it.
  649. Nevertheless, scalar routine results are returned onto R_O0.}
  650. accumulator = R_O0;
  651. NR_ACCUMULATOR = NR_O0;
  652. RS_ACCUMULATOR = RS_O1;
  653. accumulatorhigh = R_O1;
  654. NR_ACCUMULATORHIGH = NR_O1;
  655. RS_ACCUMULATORHIGH = RS_O1;
  656. fpu_result_reg = R_F0;
  657. mmresultreg = R_G0;
  658. {*****************************************************************************}
  659. { GCC /ABI linking information }
  660. {*****************************************************************************}
  661. { Registers which must be saved when calling a routine declared as cppdecl,
  662. cdecl, stdcall, safecall, palmossyscall. The registers saved should be the ones
  663. as defined in the target ABI and / or GCC.
  664. This value can be deduced from the CALLED_USED_REGISTERS array in the GCC
  665. source.
  666. }
  667. std_saved_registers=[];
  668. { Required parameter alignment when calling a routine declared as stdcall and
  669. cdecl. The alignment value should be the one defined by GCC or the target ABI.
  670. The value of this constant is equal to the constant
  671. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source. }
  672. std_param_align=4;
  673. { Registers which are defined as scratch and no need to save across routine
  674. calls or in assembler blocks.}
  675. ScratchRegsCount=2;
  676. scratch_regs:array[1..ScratchRegsCount] OF Tsuperregister=(RS_O7,RS_G2);
  677. { low and high of the available maximum width integer general purpose
  678. registers }
  679. LoGPReg = R_G0;
  680. HiGPReg = R_I7;
  681. { low and high of every possible width general purpose register (same as
  682. above on most architctures apart from the 80x86) }
  683. LoReg = R_G0;
  684. HiReg = R_I7;
  685. cpuflags = [];
  686. { sizes }
  687. pointersize = 4;
  688. extended_size = 8; { SPARC architecture uses IEEE floating point numbers}
  689. mmreg_size = 8;
  690. SizePostfix_pointer = S_SW;
  691. {*****************************************************************************
  692. Instruction table
  693. *****************************************************************************}
  694. {$ifndef NOAG386BIN}
  695. type
  696. tinsentry=packed record
  697. opcode : tasmop;
  698. ops : byte;
  699. optypes : array[0..2] of LongInt;
  700. code : array[0..maxinfolen] of char;
  701. flags : LongInt;
  702. end;
  703. pinsentry=^tinsentry;
  704. TInsTabCache=array[TasmOp] of LongInt;
  705. PInsTabCache=^TInsTabCache;
  706. VAR
  707. InsTabCache : PInsTabCache;
  708. {$endif NOAG386BIN}
  709. {*****************************************************************************
  710. Helpers
  711. *****************************************************************************}
  712. const
  713. maxvarregs=8;
  714. VarRegs:array[1..maxvarregs] of tnewregister = (
  715. RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7
  716. );
  717. maxfpuvarregs = 8;
  718. max_operands = 3;
  719. maxintregs = maxvarregs;
  720. maxfpuregs = maxfpuvarregs;
  721. max_scratch_regs=8;
  722. function is_calljmp(o:tasmop):boolean;
  723. function flags_to_cond(CONST f:TResFlags):TAsmCond;
  724. procedure convert_register_to_enum(var Reg:Tregister);
  725. function cgsize2subreg(s:Tcgsize):Tsubregister;
  726. implementation
  727. uses
  728. verbose;
  729. const
  730. CallJmpOp=[A_JMPL..A_CBccc];
  731. function is_calljmp(o:tasmop):boolean;
  732. begin
  733. if o in CallJmpOp
  734. then
  735. is_calljmp:=true
  736. else
  737. is_calljmp:=false;
  738. end;
  739. function flags_to_cond(const f:TResFlags):TAsmCond;
  740. CONST
  741. flags_2_cond:array[TResFlags]OF TAsmCond=
  742. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  743. BEGIN
  744. result:=flags_2_cond[f];
  745. end;
  746. procedure convert_register_to_enum(var Reg:Tregister);
  747. begin
  748. with Reg do
  749. if(enum=R_INTREGISTER)
  750. then
  751. if(number<=RegEnum2Number[R_I7])
  752. then
  753. begin
  754. enum:=Low(enum);
  755. repeat
  756. Inc(enum);
  757. until(number=RegEnum2Number[enum])or(enum=High(enum));
  758. end
  759. else
  760. internalerror(200301082);
  761. end;
  762. function cgsize2subreg(s:Tcgsize):Tsubregister;
  763. begin
  764. cgsize2subreg:=R_SUBWHOLE;
  765. end;
  766. end.
  767. {
  768. $Log$
  769. Revision 1.34 2003-05-28 23:18:31 florian
  770. * started to fix and clean up the sparc port
  771. Revision 1.33 2003/05/26 22:08:42 mazen
  772. + RegEnum2Number to ease handling register pairs
  773. * changed convert_register_to_enum to use above
  774. array
  775. Revision 1.32 2003/05/23 21:10:50 florian
  776. * fixed sparc compiler compilation
  777. Revision 1.31 2003/05/22 16:11:22 florian
  778. * fixed sparc compilation partially
  779. Revision 1.30 2003/05/06 14:58:46 mazen
  780. - non used constants OT_* removed
  781. * some keywords moved lower case
  782. Revision 1.29 2003/04/29 12:03:52 mazen
  783. * TOldRegister isnow just an alias for TCpuRegister
  784. * TCpuRegister is used to define cpu register set physically available
  785. + CpuRegs array to easially create correspondence between TCpuRegister and TRegister
  786. Revision 1.28 2003/04/28 09:46:30 mazen
  787. + max_scratch_regs variable added because requested by common compiler code
  788. Revision 1.27 2003/04/23 13:35:39 peter
  789. * fix sparc compile
  790. Revision 1.26 2003/04/23 12:35:35 florian
  791. * fixed several issues with powerpc
  792. + applied a patch from Jonas for nested function calls (PowerPC only)
  793. * ...
  794. }