cpubase.pas 22 KB

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