cpubase.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. {Operand types}
  33. OT_NONE = $00000000;
  34. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  35. OT_BITS16 = $00000002;
  36. OT_BITS32 = $00000004;
  37. OT_BITS64 = $00000008; { FPU only }
  38. OT_BITS80 = $00000010;
  39. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  40. OT_NEAR = $00000040;
  41. OT_SHORT = $00000080;
  42. OT_SIZE_MASK = $000000FF; { all the size attributes }
  43. OT_NON_SIZE = LongInt(not OT_SIZE_MASK);
  44. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  45. OT_TO = $00000200; { operand is followed by a colon }
  46. { reverse effect in FADD, FSUB &c }
  47. OT_COLON = $00000400;
  48. OT_REGISTER = $00001000;
  49. OT_IMMEDIATE = $00002000;
  50. OT_IMM8 = $00002001;
  51. OT_IMM16 = $00002002;
  52. OT_IMM32 = $00002004;
  53. OT_IMM64 = $00002008;
  54. OT_IMM80 = $00002010;
  55. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  56. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  57. OT_REG8 = $00201001;
  58. OT_REG16 = $00201002;
  59. OT_REG32 = $00201004;
  60. OT_MMXREG = $00201008; { MMX registers }
  61. OT_XMMREG = $00201010; { Katmai registers }
  62. OT_MEMORY = $00204000; { register number in 'basereg' }
  63. OT_MEM8 = $00204001;
  64. OT_MEM16 = $00204002;
  65. OT_MEM32 = $00204004;
  66. OT_MEM64 = $00204008;
  67. OT_MEM80 = $00204010;
  68. OT_FPUREG = $01000000; { floating point stack registers }
  69. OT_FPU0 = $01000800; { FPU stack register zero }
  70. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  71. { a mask for the following }
  72. OT_REG_ACCUM = $00211000; { accumulator: AL, AX or EAX }
  73. OT_REG_AL = $00211001; { REG_ACCUM | BITSxx }
  74. OT_REG_AX = $00211002; { ditto }
  75. OT_REG_EAX = $00211004; { and again }
  76. OT_REG_COUNT = $00221000; { counter: CL, CX or ECX }
  77. OT_REG_CL = $00221001; { REG_COUNT | BITSxx }
  78. OT_REG_CX = $00221002; { ditto }
  79. OT_REG_ECX = $00221004; { another one }
  80. OT_REG_DX = $00241002;
  81. OT_REG_SREG = $00081002; { any segment register }
  82. OT_REG_CS = $01081002; { CS }
  83. OT_REG_DESS = $02081002; { DS, ES, SS (non-CS 86 registers) }
  84. OT_REG_FSGS = $04081002; { FS, GS (386 extENDed registers) }
  85. OT_REG_CDT = $00101004; { CRn, DRn and TRn }
  86. OT_REG_CREG = $08101004; { CRn }
  87. OT_REG_CR4 = $08101404; { CR4 (Pentium only) }
  88. OT_REG_DREG = $10101004; { DRn }
  89. OT_REG_TREG = $20101004; { TRn }
  90. OT_MEM_OFFS = $00604000; { special type of EA }
  91. { simple [address] offset }
  92. OT_ONENESS = $00800000; { special type of immediate operand }
  93. { so UNITY == IMMEDIATE | ONENESS }
  94. OT_UNITY = $00802000; { for shift/rotate instructions }
  95. {Instruction flags }
  96. IF_NONE = $00000000;
  97. IF_SM = $00000001; { size match first two operands }
  98. IF_SM2 = $00000002;
  99. IF_SB = $00000004; { unsized operands can't be non-byte }
  100. IF_SW = $00000008; { unsized operands can't be non-word }
  101. IF_SD = $00000010; { unsized operands can't be nondword }
  102. IF_AR0 = $00000020; { SB, SW, SD applies to argument 0 }
  103. IF_AR1 = $00000040; { SB, SW, SD applies to argument 1 }
  104. IF_AR2 = $00000060; { SB, SW, SD applies to argument 2 }
  105. IF_ARMASK = $00000060; { mask for unsized argument spec }
  106. IF_PRIV = $00000100; { it's a privileged instruction }
  107. IF_SMM = $00000200; { it's only valid in SMM }
  108. IF_PROT = $00000400; { it's protected mode only }
  109. IF_UNDOC = $00001000; { it's an undocumented instruction }
  110. IF_FPU = $00002000; { it's an FPU instruction }
  111. IF_MMX = $00004000; { it's an MMX instruction }
  112. IF_3DNOW = $00008000; { it's a 3DNow! instruction }
  113. IF_SSE = $00010000; { it's a SSE (KNI, MMX2) instruction }
  114. IF_PMASK = LongInt($FF000000); { the mask for processor types }
  115. IF_PFMASK = LongInt($F001FF00); { the mask for disassembly "prefer" }
  116. IF_V7 = $00000000; { SPARC V7 instruction only (not supported)}
  117. IF_V8 = $01000000; { SPARC V8 instruction (the default)}
  118. IF_V9 = $02000000; { SPARC V9 instruction (not yet supported)}
  119. { added flags }
  120. IF_PRE = $40000000; { it's a prefix instruction }
  121. IF_PASS2 = LongInt($80000000);{instruction can change in a second pass?}
  122. TYPE
  123. {$WARNING CPU32 opcodes do not fully include the Ultra SPRAC instruction set.}
  124. { don't change the order of these opcodes! }
  125. TAsmOp=({$INCLUDE opcode.inc});
  126. op2strtable=ARRAY[TAsmOp]OF STRING[11];
  127. CONST
  128. FirstOp=Low(TAsmOp);
  129. LastOp=High(TAsmOp);
  130. std_op2str:op2strtable=({$INCLUDE strinst.inc});
  131. {*****************************************************************************
  132. Operand Sizes
  133. *****************************************************************************}
  134. TYPE
  135. TOpSize=(S_NO,
  136. S_B,{Byte}
  137. S_H,{Half word}
  138. S_W,{Word}
  139. S_L:=S_W,
  140. S_D,{Double Word}
  141. S_Q,{Quad word}
  142. S_IQ:=S_Q,
  143. S_SB,{Signed byte}
  144. S_SH,{Signed half word}
  145. S_SW,{Signed word}
  146. S_SD,{Signed double word}
  147. S_SQ,{Signed quad word}
  148. S_FS,{Float single word}
  149. S_FX:=S_FS,
  150. S_FD,{Float double word}
  151. S_FQ,{Float quad word}
  152. S_NEAR,
  153. S_FAR,
  154. S_SHORT);
  155. {*****************************************************************************}
  156. { Conditions }
  157. {*****************************************************************************}
  158. TYPE
  159. TAsmCond=(C_None,
  160. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  161. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  162. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  163. );
  164. CONST
  165. cond2str:ARRAY[TAsmCond] of string[3]=('',
  166. 'a','ae','b','be','c','e','g','ge','l','le','na','nae',
  167. 'nb','nbe','nc','ne','ng','nge','nl','nle','no','np',
  168. 'ns','nz','o','p','pe','po','s','z'
  169. );
  170. inverse_cond:ARRAY[TAsmCond] of TAsmCond=(C_None,
  171. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  172. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  173. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  174. );
  175. CONST
  176. CondAsmOps=3;
  177. CondAsmOp:ARRAY[0..CondAsmOps-1] of TAsmOp=(A_FCMPd, A_JMPL, A_FCMPs);
  178. CondAsmOpStr:ARRAY[0..CondAsmOps-1] of string[7]=('FCMPd','JMPL','FCMPs');
  179. {*****************************************************************************}
  180. { Registers }
  181. {*****************************************************************************}
  182. TYPE
  183. { enumeration for registers, don't change the order }
  184. { it's used by the register size conversions }
  185. TCpuRegister=({$INCLUDE cpuregs.inc});
  186. TOldRegister=TCpuRegister;
  187. Tnewregister=word;
  188. Tsuperregister=byte;
  189. Tsubregister=byte;
  190. Tregister=record
  191. enum:TCpuRegister;
  192. number:Tnewregister;
  193. end;
  194. TRegister64=PACKED RECORD
  195. {A type to store register locations for 64 Bit values.}
  196. RegLo,RegHi:TRegister;
  197. END;
  198. treg64=tregister64;{alias for compact code}
  199. TRegisterSet=SET OF TCpuRegister;
  200. Tsupregset=set of Tsuperregister;
  201. const
  202. R_NO=R_NONE;
  203. firstreg = Succ(R_NONE);
  204. lastreg = Pred(R_INTREGISTER);
  205. {General registers.}
  206. const
  207. NR_NONE=$0000;
  208. NR_NO=NR_NONE;
  209. NR_G0=$0001;
  210. NR_G1=$0002;
  211. NR_G2=$0003;
  212. NR_G3=$0004;
  213. NR_G4=$0005;
  214. NR_G5=$0006;
  215. NR_G6=$0007;
  216. NR_G7=$0008;
  217. NR_O0=$0100;
  218. NR_O1=$0200;
  219. NR_O2=$0300;
  220. NR_O3=$0400;
  221. NR_O4=$0500;
  222. NR_O5=$0600;
  223. NR_O6=$0700;
  224. NR_O7=$0800;
  225. NR_L0=$0900;
  226. NR_L1=$0A00;
  227. NR_L2=$0B00;
  228. NR_L3=$0C00;
  229. NR_L4=$0D00;
  230. NR_L5=$0E00;
  231. NR_L6=$0F00;
  232. NR_L7=$1000;
  233. NR_I0=$1100;
  234. NR_I1=$1200;
  235. NR_I2=$1300;
  236. NR_I3=$1400;
  237. NR_I4=$1500;
  238. NR_I5=$1600;
  239. NR_I6=$1700;
  240. NR_I7=$1800;
  241. {Floating point}
  242. NR_F0=$2000;
  243. NR_F1=$2000;
  244. NR_F2=$2000;
  245. NR_F3=$2000;
  246. NR_F4=$2000;
  247. NR_F5=$2000;
  248. NR_F6=$2000;
  249. NR_F7=$2000;
  250. NR_F8=$2000;
  251. NR_F9=$2000;
  252. NR_F10=$2000;
  253. NR_F11=$2000;
  254. NR_F12=$2000;
  255. NR_F13=$2000;
  256. NR_F14=$2000;
  257. NR_F15=$2000;
  258. NR_F16=$2000;
  259. NR_F17=$2000;
  260. NR_F18=$2000;
  261. NR_F19=$2000;
  262. NR_F20=$2000;
  263. NR_F21=$2000;
  264. NR_F22=$2000;
  265. NR_F23=$2000;
  266. NR_F24=$2000;
  267. NR_F25=$2000;
  268. NR_F26=$2000;
  269. NR_F27=$2000;
  270. NR_F28=$2000;
  271. NR_F29=$2000;
  272. NR_F30=$2000;
  273. NR_F31=$2000;
  274. {Coprocessor point}
  275. NR_C0=$3000;
  276. NR_C1=$3000;
  277. NR_C2=$3000;
  278. NR_C3=$3000;
  279. NR_C4=$3000;
  280. NR_C5=$3000;
  281. NR_C6=$3000;
  282. NR_C7=$3000;
  283. NR_C8=$3000;
  284. NR_C9=$3000;
  285. NR_C10=$3000;
  286. NR_C11=$3000;
  287. NR_C12=$3000;
  288. NR_C13=$3000;
  289. NR_C14=$3000;
  290. NR_C15=$3000;
  291. NR_C16=$3000;
  292. NR_C17=$3000;
  293. NR_C18=$3000;
  294. NR_C19=$3000;
  295. NR_C20=$3000;
  296. NR_C21=$3000;
  297. NR_C22=$3000;
  298. NR_C23=$3000;
  299. NR_C24=$3000;
  300. NR_C25=$3000;
  301. NR_C26=$3000;
  302. NR_C27=$3000;
  303. NR_C28=$3000;
  304. NR_C29=$3000;
  305. NR_C30=$3000;
  306. NR_C31=$3000;
  307. {ASR}
  308. NR_ASR0=$4000;
  309. NR_ASR1=$4000;
  310. NR_ASR2=$4000;
  311. NR_ASR3=$4000;
  312. NR_ASR4=$4000;
  313. NR_ASR5=$4000;
  314. NR_ASR6=$4000;
  315. NR_ASR7=$4000;
  316. NR_ASR8=$4000;
  317. NR_ASR9=$4000;
  318. NR_ASR10=$4000;
  319. NR_ASR11=$4000;
  320. NR_ASR12=$4000;
  321. NR_ASR13=$4000;
  322. NR_ASR14=$4000;
  323. NR_ASR15=$4000;
  324. NR_ASR16=$4000;
  325. NR_ASR17=$4000;
  326. NR_ASR18=$4000;
  327. NR_ASR19=$4000;
  328. NR_ASR20=$4000;
  329. NR_ASR21=$4000;
  330. NR_ASR22=$4000;
  331. NR_ASR23=$4000;
  332. NR_ASR24=$4000;
  333. NR_ASR25=$4000;
  334. NR_ASR26=$4000;
  335. NR_ASR27=$4000;
  336. NR_ASR28=$4000;
  337. NR_ASR29=$4000;
  338. NR_ASR30=$4000;
  339. NR_ASR31=$4000;
  340. {Floating point status/"front of queue" registers}
  341. NR_FSR=$5000;
  342. NR_FQ=$50001;
  343. NR_CSR=$5000;
  344. NR_CQ=$5000;
  345. NR_PSR=$5000;
  346. NR_TBR=$5000;
  347. NR_WIM=$5000;
  348. NR_Y=$5000;
  349. {Superregisters.}
  350. const
  351. RS_O0=$01;
  352. RS_O1=$02;
  353. RS_O2=$03;
  354. RS_O3=$04;
  355. RS_O4=$05;
  356. RS_O5=$06;
  357. RS_O6=$07;
  358. RS_O7=$08;
  359. RS_L0=$09;
  360. RS_L1=$0A;
  361. RS_L2=$0B;
  362. RS_L3=$0C;
  363. RS_L4=$0D;
  364. RS_L5=$0E;
  365. RS_L6=$0F;
  366. RS_L7=$10;
  367. RS_I0=$11;
  368. RS_I1=$12;
  369. RS_I2=$13;
  370. RS_I3=$14;
  371. RS_I4=$15;
  372. RS_I5=$16;
  373. RS_I6=$17;
  374. RS_I7=$18;
  375. first_supreg = $01;
  376. last_supreg = $18;
  377. first_imreg = $19;
  378. last_imreg = $ff;
  379. {Subregisters; nothing known about.}
  380. R_SUBWHOLE=$00;
  381. R_SUBL=$00;
  382. type
  383. reg2strtable=ARRAY[TCpuRegister] OF STRING[7];
  384. TCpuReg=array[TCpuRegister]of TRegister;
  385. const
  386. std_reg2str:reg2strtable=({$INCLUDE strregs.inc});
  387. CpuReg:TCpuReg=({$INCLUDE registers.inc});
  388. {*****************************************************************************
  389. Flags
  390. *****************************************************************************}
  391. TYPE
  392. TResFlags=(
  393. F_E, {Equal}
  394. F_NE, {Not Equal}
  395. F_G, {Greater}
  396. F_L, {Less}
  397. F_GE, {Greater or Equal}
  398. F_LE, {Less or Equal}
  399. F_C, {Carry}
  400. F_NC, {Not Carry}
  401. F_A, {Above}
  402. F_AE, {Above or Equal}
  403. F_B, {Below}
  404. F_BE {Below or Equal}
  405. );
  406. {*****************************************************************************
  407. Reference
  408. *****************************************************************************}
  409. TYPE
  410. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  411. { immediate/reference record }
  412. poperreference = ^treference;
  413. Preference=^Treference;
  414. treference = packed record
  415. segment,
  416. base,
  417. index : tregister;
  418. scalefactor : byte;
  419. offset : LongInt;
  420. symbol : tasmsymbol;
  421. offsetfixup : LongInt;
  422. options : trefoptions;
  423. alignment : byte;
  424. END;
  425. { reference record }
  426. PParaReference=^TParaReference;
  427. TParaReference=PACKED RECORD
  428. Index:TRegister;
  429. Offset:longint;
  430. END;
  431. {*****************************************************************************
  432. Operands
  433. *****************************************************************************}
  434. { Types of operand }
  435. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_raddr,top_caddr);
  436. toper=record
  437. ot:LongInt;
  438. case typ:toptype of
  439. top_none:();
  440. top_reg:(reg:tregister);
  441. top_ref:(ref:poperreference);
  442. top_const:(val:aword);
  443. top_symbol:(sym:tasmsymbol;symofs:LongInt);
  444. top_raddr:(reg1,reg2:TRegister);
  445. top_caddr:(regb:TRegister;const13:Integer);
  446. end;
  447. {*****************************************************************************
  448. Argument Classification
  449. *****************************************************************************}
  450. TYPE
  451. TArgClass = (
  452. { the following classes should be defined by all processor implemnations }
  453. AC_NOCLASS,
  454. AC_MEMORY,
  455. AC_INTEGER,
  456. AC_FPU,
  457. { the following argument classes are i386 specific }
  458. AC_FPUUP,
  459. AC_SSE,
  460. AC_SSEUP);
  461. {*****************************************************************************
  462. Generic Location
  463. *****************************************************************************}
  464. TYPE
  465. {tparamlocation describes where a parameter for a procedure is stored.
  466. References are given from the caller's point of view. The usual TLocation isn't
  467. used, because contains a lot of unnessary fields.}
  468. TParaLocation=PACKED RECORD
  469. Size:TCGSize;
  470. Loc:TCGLoc;
  471. sp_fixup:LongInt;
  472. CASE TCGLoc OF
  473. LOC_REFERENCE:(reference:tparareference);
  474. { segment in reference at the same place as in loc_register }
  475. LOC_REGISTER,LOC_CREGISTER : (
  476. CASE LongInt OF
  477. 1 : (register,registerhigh : tregister);
  478. { overlay a registerlow }
  479. 2 : (registerlow : tregister);
  480. { overlay a 64 Bit register type }
  481. 3 : (reg64 : tregister64);
  482. 4 : (register64 : tregister64);
  483. );
  484. { it's only for better handling }
  485. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  486. END;
  487. TLocation=PACKED RECORD
  488. loc : TCGLoc;
  489. size : TCGSize;
  490. case TCGLoc of
  491. LOC_FLAGS : (resflags : tresflags);
  492. LOC_CONSTANT : (
  493. case longint of
  494. 1 : (value : AWord);
  495. 2 : (valuelow, valuehigh:AWord);
  496. { overlay a complete 64 Bit value }
  497. 3 : (valueqword : qword);
  498. );
  499. LOC_CREFERENCE,
  500. LOC_REFERENCE : (reference : treference);
  501. { segment in reference at the same place as in loc_register }
  502. LOC_REGISTER,LOC_CREGISTER : (
  503. case longint of
  504. 1 : (register,registerhigh,segment : tregister);
  505. { overlay a registerlow }
  506. 2 : (registerlow : tregister);
  507. { overlay a 64 Bit register type }
  508. 3 : (reg64 : tregister64);
  509. 4 : (register64 : tregister64);
  510. );
  511. { it's only for better handling }
  512. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  513. end;
  514. {*****************************************************************************
  515. Constants
  516. *****************************************************************************}
  517. const
  518. general_registers = [R_G0..R_I7];
  519. general_superregisters = [RS_O0..RS_I7];
  520. { legend: }
  521. { xxxregs = set of all possibly used registers of that type in the code }
  522. { generator }
  523. { usableregsxxx = set of all 32bit components of registers that can be }
  524. { possible allocated to a regvar or using getregisterxxx (this }
  525. { excludes registers which can be only used for parameter }
  526. { passing on ABI's that define this) }
  527. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  528. IntRegs=[R_G0..R_I7];
  529. usableregsint=[RS_O0..RS_I7];
  530. c_countusableregsint = 24;
  531. fpuregs=[R_F0..R_F31];
  532. usableregsfpu=[R_F0..R_F31];
  533. c_countusableregsfpu=32;
  534. mmregs=[];
  535. usableregsmm=[];
  536. c_countusableregsmm=0;
  537. { no distinction on this platform }
  538. maxaddrregs = 0;
  539. addrregs = [];
  540. usableregsaddr = [];
  541. c_countusableregsaddr = 0;
  542. firstsaveintreg = RS_O0;
  543. lastsaveintreg = RS_I7;
  544. firstsavefpureg = R_F0;
  545. lastsavefpureg = R_F31;
  546. firstsavemmreg = R_NONE;
  547. lastsavemmreg = R_NONE;
  548. lowsavereg = R_G0;
  549. highsavereg = R_I7;
  550. ALL_REGISTERS = [lowsavereg..highsavereg];
  551. ALL_INTREGISTERS = [1..255];
  552. lvaluelocations = [LOC_REFERENCE,LOC_CFPUREGISTER,
  553. LOC_CREGISTER,LOC_MMXREGISTER,LOC_CMMXREGISTER];
  554. {*****************************************************************************
  555. GDB Information
  556. *****************************************************************************}
  557. {# Register indexes for stabs information, when some parameters or variables
  558. are stored in registers.
  559. Taken from rs6000.h (DBX_REGISTER_NUMBER) from GCC 3.x source code.}
  560. stab_regindex:ARRAY[TCpuRegister]OF ShortInt=({$INCLUDE stabregi.inc});
  561. {*************************** generic register names **************************}
  562. stack_pointer_reg = R_O6;
  563. NR_STACK_POINTER_REG = NR_O6;
  564. RS_STACK_POINTER_REG = RS_O6;
  565. frame_pointer_reg = R_I6;
  566. NR_FRAME_POINTER_REG = NR_I6;
  567. RS_FRAME_POINTER_REG = RS_I6;
  568. {the return_result_reg, is used inside the called function to store its return
  569. value when that is a scalar value otherwise a pointer to the address of the
  570. result is placed inside it}
  571. return_result_reg = R_I0;
  572. NR_RETURN_RESULT_REG = NR_I0;
  573. RS_RETURN_RESULT_REG = RS_I0;
  574. {the function_result_reg contains the function result after a call to a scalar
  575. function othewise it contains a pointer to the returned result}
  576. function_result_reg = R_O0;
  577. NR_FUNCTION_RESULT_REG = NR_O0;
  578. RS_FUNCTION_RESULT_REG = RS_O0;
  579. self_pointer_reg =R_G5;
  580. NR_SELF_POINTER_REG = NR_G5;
  581. { RS_SELF_POINTER_REG = RS_G5;}
  582. {There is no accumulator in the SPARC architecture. There are just families
  583. of registers. All registers belonging to the same family are identical except
  584. in the "global registers" family where GO is different from the others :
  585. G0 gives always 0 when it is red and thows away any value written to it.
  586. Nevertheless, scalar routine results are returned onto R_O0.}
  587. accumulator = R_O0;
  588. NR_ACCUMULATOR = NR_O0;
  589. RS_ACCUMULATOR = RS_O1;
  590. accumulatorhigh = R_O1;
  591. NR_ACCUMULATORHIGH = NR_O1;
  592. RS_ACCUMULATORHIGH = RS_O1;
  593. fpu_result_reg =R_F0;
  594. mmresultreg =R_G0;
  595. {*****************************************************************************}
  596. { GCC /ABI linking information }
  597. {*****************************************************************************}
  598. {# Registers which must be saved when calling a routine declared as cppdecl,
  599. cdecl, stdcall, safecall, palmossyscall. The registers saved should be the ones
  600. as defined in the target ABI and / or GCC.
  601. This value can be deduced from the CALLED_USED_REGISTERS array in the GCC
  602. source.}
  603. std_saved_registers=[RS_O6];
  604. {# Required parameter alignment when calling a routine declared as stdcall and
  605. cdecl. The alignment value should be the one defined by GCC or the target ABI.
  606. The value of this constant is equal to the constant
  607. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.}
  608. std_param_align=4;
  609. {# Registers which are defined as scratch and no need to save across routine
  610. calls or in assembler blocks.}
  611. ScratchRegsCount=8;
  612. scratch_regs:ARRAY[1..ScratchRegsCount] OF Tsuperregister=(RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7);
  613. { low and high of the available maximum width integer general purpose }
  614. { registers }
  615. LoGPReg = R_G0;
  616. HiGPReg = R_I7;
  617. { low and high of every possible width general purpose register (same as }
  618. { above on most architctures apart from the 80x86) }
  619. LoReg = R_G0;
  620. HiReg = R_I7;
  621. cpuflags = [];
  622. { sizes }
  623. pointersize = 4;
  624. extENDed_size = 8;{SPARC architecture uses IEEE floating point numbers}
  625. mmreg_size = 8;
  626. SizePostfix_pointer = S_SW;
  627. {*****************************************************************************
  628. Instruction table
  629. *****************************************************************************}
  630. {$ifndef NOAG386BIN}
  631. TYPE
  632. tinsentry=packed record
  633. opcode : tasmop;
  634. ops : byte;
  635. optypes : ARRAY[0..2] of LongInt;
  636. code : ARRAY[0..maxinfolen] of char;
  637. flags : LongInt;
  638. END;
  639. pinsentry=^tinsentry;
  640. TInsTabCache=ARRAY[TasmOp] of LongInt;
  641. PInsTabCache=^TInsTabCache;
  642. VAR
  643. InsTabCache : PInsTabCache;
  644. {$ENDif NOAG386BIN}
  645. {*****************************************************************************
  646. Helpers
  647. *****************************************************************************}
  648. const
  649. maxvarregs=30;
  650. VarRegs:ARRAY[1..maxvarregs]OF TCpuRegister=(
  651. R_G0,R_G1,R_G2,R_G3,R_G4,R_G5,R_G6,R_G7,
  652. R_O0,R_O1,R_O2,R_O3,R_O4,R_O5,{R_R14=R_SP}R_O7,
  653. R_L0,R_L1,R_L2,R_L3,R_L4,R_L5,R_L6,R_L7,
  654. R_I0,R_I1,R_I2,R_I3,R_I4,R_I5,{R_R30=R_FP}R_I7
  655. );
  656. maxfpuvarregs = 8;
  657. max_operands = 3;
  658. maxintregs = maxvarregs;
  659. maxfpuregs = maxfpuvarregs;
  660. max_scratch_regs=8;
  661. FUNCTION is_calljmp(o:tasmop):boolean;
  662. FUNCTION flags_to_cond(CONST f:TResFlags):TAsmCond;
  663. procedure convert_register_to_enum(var r:Tregister);
  664. function cgsize2subreg(s:Tcgsize):Tsubregister;
  665. IMPLEMENTATION
  666. uses verbose;
  667. const
  668. CallJmpOp=[A_JMPL..A_CBccc];
  669. function is_calljmp(o:tasmop):boolean;
  670. begin
  671. if o in CallJmpOp
  672. then
  673. is_calljmp:=true
  674. else
  675. is_calljmp:=false;
  676. end;
  677. function flags_to_cond(const f:TResFlags):TAsmCond;
  678. CONST
  679. flags_2_cond:ARRAY[TResFlags]OF TAsmCond=
  680. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  681. BEGIN
  682. result:=flags_2_cond[f];
  683. END;
  684. procedure convert_register_to_enum(var r:Tregister);
  685. begin
  686. if r.enum=R_INTREGISTER
  687. then
  688. case r.number of
  689. NR_NO: r.enum:= R_NO;
  690. NR_G0: r.enum:= R_G0;
  691. NR_G1: r.enum:= R_G1;
  692. NR_G2: r.enum:= R_G2;
  693. NR_G3: r.enum:= R_G3;
  694. NR_G4: r.enum:= R_G4;
  695. NR_G5: r.enum:= R_G5;
  696. NR_G6: r.enum:= R_G6;
  697. NR_G7: r.enum:= R_G7;
  698. NR_O0: r.enum:= R_O0;
  699. NR_O1: r.enum:= R_O1;
  700. NR_O2: r.enum:= R_O2;
  701. NR_O3: r.enum:= R_O3;
  702. NR_O4: r.enum:= R_O4;
  703. NR_O5: r.enum:= R_O5;
  704. NR_O6: r.enum:= R_O6;
  705. NR_O7: r.enum:= R_O7;
  706. NR_L0: r.enum:= R_L0;
  707. NR_L1: r.enum:= R_L1;
  708. NR_L2: r.enum:= R_L2;
  709. NR_L3: r.enum:= R_L3;
  710. NR_L4: r.enum:= R_L4;
  711. NR_L5: r.enum:= R_L5;
  712. NR_L6: r.enum:= R_L6;
  713. NR_L7: r.enum:= R_L7;
  714. NR_I0: r.enum:= R_I0;
  715. NR_I1: r.enum:= R_I1;
  716. NR_I2: r.enum:= R_I2;
  717. NR_I3: r.enum:= R_I3;
  718. NR_I4: r.enum:= R_I4;
  719. NR_I5: r.enum:= R_I5;
  720. NR_I6: r.enum:= R_I6;
  721. NR_I7: r.enum:= R_I7;
  722. else
  723. internalerror(200301082);
  724. end;
  725. end;
  726. function cgsize2subreg(s:Tcgsize):Tsubregister;
  727. begin
  728. cgsize2subreg:=R_SUBWHOLE;
  729. end;
  730. END.
  731. {
  732. $Log$
  733. Revision 1.29 2003-04-29 12:03:52 mazen
  734. * TOldRegister isnow just an alias for TCpuRegister
  735. * TCpuRegister is used to define cpu register set physically available
  736. + CpuRegs array to easially create correspondence between TCpuRegister and TRegister
  737. Revision 1.28 2003/04/28 09:46:30 mazen
  738. + max_scratch_regs variable added because requested by common compiler code
  739. Revision 1.27 2003/04/23 13:35:39 peter
  740. * fix sparc compile
  741. Revision 1.26 2003/04/23 12:35:35 florian
  742. * fixed several issues with powerpc
  743. + applied a patch from Jonas for nested function calls (PowerPC only)
  744. * ...
  745. }