cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. {*****************************************************************************}
  2. { File : cpubase.pas }
  3. { Author : Mazen NEIFER }
  4. { Project : Free Pascal Compiler (FPC) }
  5. { Creation date : 2002\04\26 }
  6. { Last modification date : 2002\08\20 }
  7. { Licence : GPL }
  8. { Bug report : [email protected] }
  9. {*****************************************************************************}
  10. { $Id$
  11. Copyright (c) 1998-2000 by Florian Klaempfl and Peter Vreman
  12. Contains the base types for the i386
  13. * This code was inspired by the NASM sources
  14. The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  15. Julian Hall. All rights reserved.
  16. This program is free software; you can redistribute it and/or modify
  17. it under the terms of the GNU General Public License as published by
  18. the Free Software Foundation; either version 2 of the License, or
  19. (at your option) any later version.
  20. This program is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. GNU General Public License for more details.
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software
  26. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. ****************************************************************************}
  28. UNIT cpuBase;
  29. {$INCLUDE fpcdefs.inc}
  30. INTERFACE
  31. USES globals,cutils,cclasses,aasmbase,cpuinfo,cginfo;
  32. CONST
  33. {Size of the instruction table converted by nasmconv.pas}
  34. maxinfolen = 8;
  35. {Defines the default address size for a processor}
  36. OS_ADDR=OS_32;{$WARNING "OS_ADDR" was set to "OS_32" but not verified!}
  37. {the natural int size for a processor}
  38. OS_INT=OS_32;{$WARNING "OS_INT" was set to "OS_32" but not verified!}
  39. {the maximum float size for a processor}
  40. OS_FLOAT=OS_F80;{$WARNING "OS_FLOAT" was set to "OS_F80" but not verified!}
  41. {the size of a vector register for a processor}
  42. OS_VECTOR=OS_M64;{$WARNING "OS_VECTOR" was set to "OS_M64" but not verified!}
  43. {By default we want everything}
  44. {$DEFINE ATTOP}
  45. {$DEFINE ATTREG}
  46. {$DEFINE ATTSUF}
  47. {We Don't need the intel style opcodes as we are coding for SPARC architecture}
  48. {$DEFINE NORA386INT}
  49. {$DEFINE NOAG386NSM}
  50. {$DEFINE NOAG386INT}
  51. CONST
  52. {Operand types}
  53. OT_NONE = $00000000;
  54. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  55. OT_BITS16 = $00000002;
  56. OT_BITS32 = $00000004;
  57. OT_BITS64 = $00000008; { FPU only }
  58. OT_BITS80 = $00000010;
  59. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  60. OT_NEAR = $00000040;
  61. OT_SHORT = $00000080;
  62. OT_SIZE_MASK = $000000FF; { all the size attributes }
  63. OT_NON_SIZE = LongInt(not OT_SIZE_MASK);
  64. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  65. OT_TO = $00000200; { operand is followed by a colon }
  66. { reverse effect in FADD, FSUB &c }
  67. OT_COLON = $00000400;
  68. OT_REGISTER = $00001000;
  69. OT_IMMEDIATE = $00002000;
  70. OT_IMM8 = $00002001;
  71. OT_IMM16 = $00002002;
  72. OT_IMM32 = $00002004;
  73. OT_IMM64 = $00002008;
  74. OT_IMM80 = $00002010;
  75. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  76. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  77. OT_REG8 = $00201001;
  78. OT_REG16 = $00201002;
  79. OT_REG32 = $00201004;
  80. OT_MMXREG = $00201008; { MMX registers }
  81. OT_XMMREG = $00201010; { Katmai registers }
  82. OT_MEMORY = $00204000; { register number in 'basereg' }
  83. OT_MEM8 = $00204001;
  84. OT_MEM16 = $00204002;
  85. OT_MEM32 = $00204004;
  86. OT_MEM64 = $00204008;
  87. OT_MEM80 = $00204010;
  88. OT_FPUREG = $01000000; { floating point stack registers }
  89. OT_FPU0 = $01000800; { FPU stack register zero }
  90. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  91. { a mask for the following }
  92. OT_REG_ACCUM = $00211000; { accumulator: AL, AX or EAX }
  93. OT_REG_AL = $00211001; { REG_ACCUM | BITSxx }
  94. OT_REG_AX = $00211002; { ditto }
  95. OT_REG_EAX = $00211004; { and again }
  96. OT_REG_COUNT = $00221000; { counter: CL, CX or ECX }
  97. OT_REG_CL = $00221001; { REG_COUNT | BITSxx }
  98. OT_REG_CX = $00221002; { ditto }
  99. OT_REG_ECX = $00221004; { another one }
  100. OT_REG_DX = $00241002;
  101. OT_REG_SREG = $00081002; { any segment register }
  102. OT_REG_CS = $01081002; { CS }
  103. OT_REG_DESS = $02081002; { DS, ES, SS (non-CS 86 registers) }
  104. OT_REG_FSGS = $04081002; { FS, GS (386 extENDed registers) }
  105. OT_REG_CDT = $00101004; { CRn, DRn and TRn }
  106. OT_REG_CREG = $08101004; { CRn }
  107. OT_REG_CR4 = $08101404; { CR4 (Pentium only) }
  108. OT_REG_DREG = $10101004; { DRn }
  109. OT_REG_TREG = $20101004; { TRn }
  110. OT_MEM_OFFS = $00604000; { special type of EA }
  111. { simple [address] offset }
  112. OT_ONENESS = $00800000; { special type of immediate operand }
  113. { so UNITY == IMMEDIATE | ONENESS }
  114. OT_UNITY = $00802000; { for shift/rotate instructions }
  115. {Instruction flags }
  116. IF_NONE = $00000000;
  117. IF_SM = $00000001; { size match first two operands }
  118. IF_SM2 = $00000002;
  119. IF_SB = $00000004; { unsized operands can't be non-byte }
  120. IF_SW = $00000008; { unsized operands can't be non-word }
  121. IF_SD = $00000010; { unsized operands can't be nondword }
  122. IF_AR0 = $00000020; { SB, SW, SD applies to argument 0 }
  123. IF_AR1 = $00000040; { SB, SW, SD applies to argument 1 }
  124. IF_AR2 = $00000060; { SB, SW, SD applies to argument 2 }
  125. IF_ARMASK = $00000060; { mask for unsized argument spec }
  126. IF_PRIV = $00000100; { it's a privileged instruction }
  127. IF_SMM = $00000200; { it's only valid in SMM }
  128. IF_PROT = $00000400; { it's protected mode only }
  129. IF_UNDOC = $00001000; { it's an undocumented instruction }
  130. IF_FPU = $00002000; { it's an FPU instruction }
  131. IF_MMX = $00004000; { it's an MMX instruction }
  132. IF_3DNOW = $00008000; { it's a 3DNow! instruction }
  133. IF_SSE = $00010000; { it's a SSE (KNI, MMX2) instruction }
  134. IF_PMASK =
  135. LongInt($FF000000); { the mask for processor types }
  136. IF_PFMASK =
  137. LongInt($F001FF00); { the mask for disassembly "prefer" }
  138. IF_8086 = $00000000; { 8086 instruction }
  139. IF_186 = $01000000; { 186+ instruction }
  140. IF_286 = $02000000; { 286+ instruction }
  141. IF_386 = $03000000; { 386+ instruction }
  142. IF_486 = $04000000; { 486+ instruction }
  143. IF_PENT = $05000000; { Pentium instruction }
  144. IF_P6 = $06000000; { P6 instruction }
  145. IF_KATMAI = $07000000; { Katmai instructions }
  146. IF_CYRIX = $10000000; { Cyrix-specific instruction }
  147. IF_AMD = $20000000; { AMD-specific instruction }
  148. { added flags }
  149. IF_PRE = $40000000; { it's a prefix instruction }
  150. IF_PASS2 =LongInt($80000000);{if the instruction can change in a second pass}
  151. TYPE
  152. TAttSuffix=(
  153. AttSufNONE, {No suffix is needed}
  154. AttSufINT, {Integer operation suffix is needed}
  155. AttSufFPU, {}
  156. AttSufFPUint{}
  157. );
  158. {$WARNING CPU32 opcodes do not fully include the Ultra SPRAC instruction set.}
  159. TAsmOp=({$INCLUDE opcode.inc});
  160. op2strtable=ARRAY[TAsmOp]OF STRING[11];
  161. CONST
  162. FirstOp=Low(TAsmOp);
  163. LastOp=High(TAsmOp);
  164. {$IFDEF ATTSUF}
  165. att_needsuffix:ARRAY[tasmop]OF TAttSuffix=({$INCLUDE sparcatts.inc});
  166. {$ENDIF ATTSUF}
  167. std_op2str:op2strtable=({$INCLUDE attinstr.inc});
  168. {*****************************************************************************
  169. Operand Sizes
  170. *****************************************************************************}
  171. TYPE
  172. { S_NO = No Size of operand }
  173. { S_B = Byte size operand }
  174. { S_W = Word size operand }
  175. { S_L = DWord size operand }
  176. { USED FOR conversions in x86}
  177. { S_BW = Byte to word }
  178. { S_BL = Byte to long }
  179. { S_WL = Word to long }
  180. { Floating point types }
  181. { S_FS = single type (32 bit) }
  182. { S_FL = double/64bit integer }
  183. { S_FX = ExtENDed type }
  184. { S_IS = integer on 16 bits }
  185. { S_IL = integer on 32 bits }
  186. { S_IQ = integer on 64 bits }
  187. TOpSize=(S_NO,
  188. S_B,
  189. S_W,
  190. S_L,
  191. S_BW,
  192. S_BL,
  193. S_WL,
  194. S_IS,
  195. S_IL,
  196. S_IQ,
  197. S_FS,
  198. S_FL,
  199. S_FX,
  200. S_D,
  201. S_Q,
  202. S_FV,
  203. S_NEAR,
  204. S_FAR,
  205. S_SHORT);
  206. CONST
  207. { Intel style operands ! }
  208. opsize_2_type:ARRAY[0..2,topsize] of LongInt=(
  209. (OT_NONE,
  210. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS16,OT_BITS32,OT_BITS32,
  211. OT_BITS16,OT_BITS32,OT_BITS64,
  212. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,
  213. OT_NEAR,OT_FAR,OT_SHORT
  214. ),
  215. (OT_NONE,
  216. OT_BITS8,OT_BITS16,OT_BITS32,OT_BITS8,OT_BITS8,OT_BITS16,
  217. OT_BITS16,OT_BITS32,OT_BITS64,
  218. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,
  219. OT_NEAR,OT_FAR,OT_SHORT
  220. ),
  221. (OT_NONE,
  222. OT_BITS8,OT_BITS16,OT_BITS32,OT_NONE,OT_NONE,OT_NONE,
  223. OT_BITS16,OT_BITS32,OT_BITS64,
  224. OT_BITS32,OT_BITS64,OT_BITS80,OT_BITS64,OT_BITS64,OT_BITS64,
  225. OT_NEAR,OT_FAR,OT_SHORT
  226. )
  227. );
  228. {$IFDEF ATTOP}
  229. att_opsize2str : ARRAY[topsize] of string[2] = ('',
  230. 'b','w','l','bw','bl','wl',
  231. 's','l','q',
  232. 's','l','t','d','q','v',
  233. '','',''
  234. );
  235. {$ENDIF}
  236. {*****************************************************************************
  237. Conditions
  238. *****************************************************************************}
  239. TYPE
  240. TAsmCond=(C_None,
  241. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  242. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  243. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  244. );
  245. CONST
  246. cond2str:ARRAY[TAsmCond] of string[3]=('',
  247. 'a','ae','b','be','c','e','g','ge','l','le','na','nae',
  248. 'nb','nbe','nc','ne','ng','nge','nl','nle','no','np',
  249. 'ns','nz','o','p','pe','po','s','z'
  250. );
  251. inverse_cond:ARRAY[TAsmCond] of TAsmCond=(C_None,
  252. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  253. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  254. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  255. );
  256. CONST
  257. CondAsmOps=3;
  258. CondAsmOp:ARRAY[0..CondAsmOps-1] of TAsmOp=(A_FCMPd, A_JMPL, A_FCMPs);
  259. CondAsmOpStr:ARRAY[0..CondAsmOps-1] of string[4]=('FCMPd','JMPL','FCMPs');
  260. {*****************************************************************************
  261. Registers
  262. *****************************************************************************}
  263. TYPE
  264. { enumeration for registers, don't change the order }
  265. { it's used by the register size conversions }
  266. TRegister=({$INCLUDE registers.inc});
  267. TRegister64=PACKED RECORD
  268. {A type to store register locations for 64 Bit values.}
  269. RegLo,RegHi:TRegister;
  270. END;
  271. treg64=tregister64;{alias for compact code}
  272. TRegisterSet=SET OF TRegister;
  273. reg2strtable=ARRAY[tregister] OF STRING[6];
  274. CONST
  275. firstreg = low(tregister);
  276. lastreg = high(tregister);
  277. {$ifdef ATTREG}
  278. std_reg2str:reg2strtable=({$INCLUDE strregs.inc});
  279. {$ENDif ATTREG}
  280. {*****************************************************************************
  281. Flags
  282. *****************************************************************************}
  283. TYPE
  284. TResFlags=(
  285. F_E, {Equal}
  286. F_NE, {Not Equal}
  287. F_G, {Greater}
  288. F_L, {Less}
  289. F_GE, {Greater or Equal}
  290. F_LE, {Less or Equal}
  291. F_C, {Carry}
  292. F_NC, {Not Carry}
  293. F_A, {Above}
  294. F_AE, {Above or Equal}
  295. F_B, {Below}
  296. F_BE {Below or Equal}
  297. );
  298. {*****************************************************************************
  299. Reference
  300. *****************************************************************************}
  301. TYPE
  302. trefoptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  303. { immediate/reference record }
  304. poperreference = ^treference;
  305. treference = packed record
  306. segment,
  307. base,
  308. index : tregister;
  309. scalefactor : byte;
  310. offset : LongInt;
  311. symbol : tasmsymbol;
  312. offsetfixup : LongInt;
  313. options : trefoptions;
  314. {$ifdef newcg}
  315. alignment : byte;
  316. {$ENDif newcg}
  317. END;
  318. { reference record }
  319. PParaReference=^TParaReference;
  320. TParaReference=PACKED RECORD
  321. Index:TRegister;
  322. Offset:longint;
  323. END;
  324. {*****************************************************************************
  325. Operands
  326. *****************************************************************************}
  327. { Types of operand }
  328. toptype=(top_none,top_reg,top_ref,top_CONST,top_symbol);
  329. toper=record
  330. ot : LongInt;
  331. case typ : toptype of
  332. top_none : ();
  333. top_reg : (reg:tregister);
  334. top_ref : (ref:poperreference);
  335. top_CONST : (val:aword);
  336. top_symbol : (sym:tasmsymbol;symofs:LongInt);
  337. END;
  338. {*****************************************************************************
  339. Argument Classification
  340. *****************************************************************************}
  341. TYPE
  342. TArgClass = (
  343. { the following classes should be defined by all processor implemnations }
  344. AC_NOCLASS,
  345. AC_MEMORY,
  346. AC_INTEGER,
  347. AC_FPU,
  348. { the following argument classes are i386 specific }
  349. AC_FPUUP,
  350. AC_SSE,
  351. AC_SSEUP);
  352. {*****************************************************************************
  353. Generic Location
  354. *****************************************************************************}
  355. TYPE
  356. TLoc=( {information about the location of an operand}
  357. LOC_INVALID, { added for tracking problems}
  358. LOC_CONSTANT, { CONSTant value }
  359. LOC_JUMP, { boolean results only, jump to false or true label }
  360. LOC_FLAGS, { boolean results only, flags are set }
  361. LOC_CREFERENCE, { in memory CONSTant value }
  362. LOC_REFERENCE, { in memory value }
  363. LOC_REGISTER, { in a processor register }
  364. LOC_CREGISTER, { Constant register which shouldn't be modified }
  365. LOC_FPUREGISTER, { FPU stack }
  366. LOC_CFPUREGISTER, { if it is a FPU register variable on the fpu stack }
  367. LOC_MMXREGISTER, { MMX register }
  368. LOC_CMMXREGISTER, { MMX register variable }
  369. LOC_MMREGISTER,
  370. LOC_CMMREGISTER
  371. );
  372. {tparamlocation describes where a parameter for a procedure is stored.
  373. References are given from the caller's point of view. The usual TLocation isn't
  374. used, because contains a lot of unnessary fields.}
  375. TParaLocation=PACKED RECORD
  376. Size:TCGSize;
  377. Loc:TLoc;
  378. sp_fixup:LongInt;
  379. CASE TLoc OF
  380. LOC_REFERENCE:(reference:tparareference);
  381. { segment in reference at the same place as in loc_register }
  382. LOC_REGISTER,LOC_CREGISTER : (
  383. CASE LongInt OF
  384. 1 : (register,registerhigh : tregister);
  385. { overlay a registerlow }
  386. 2 : (registerlow : tregister);
  387. { overlay a 64 Bit register type }
  388. 3 : (reg64 : tregister64);
  389. 4 : (register64 : tregister64);
  390. );
  391. { it's only for better handling }
  392. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  393. END;
  394. TLocation=PACKED RECORD
  395. loc : TLoc;
  396. size : TCGSize;
  397. case TLoc of
  398. LOC_FLAGS : (resflags : tresflags);
  399. LOC_CONSTANT : (
  400. case longint of
  401. 1 : (value : AWord);
  402. 2 : (valuelow, valuehigh:AWord);
  403. { overlay a complete 64 Bit value }
  404. 3 : (valueqword : qword);
  405. );
  406. LOC_CREFERENCE,
  407. LOC_REFERENCE : (reference : treference);
  408. { segment in reference at the same place as in loc_register }
  409. LOC_REGISTER,LOC_CREGISTER : (
  410. case longint of
  411. 1 : (register,registerhigh,segment : tregister);
  412. { overlay a registerlow }
  413. 2 : (registerlow : tregister);
  414. { overlay a 64 Bit register type }
  415. 3 : (reg64 : tregister64);
  416. 4 : (register64 : tregister64);
  417. );
  418. { it's only for better handling }
  419. LOC_MMXREGISTER,LOC_CMMXREGISTER : (mmxreg : tregister);
  420. end;
  421. {*****************************************************************************
  422. Constants
  423. *****************************************************************************}
  424. CONST
  425. general_registers = [R_G0..R_I7];
  426. { legEND: }
  427. { xxxregs = set of all possibly used registers of that type in the code }
  428. { generator }
  429. { usableregsxxx = set of all 32bit components of registers that can be }
  430. { possible allocated to a regvar or using getregisterxxx (this }
  431. { excludes registers which can be only used for parameter }
  432. { passing on ABI's that define this) }
  433. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  434. intregs = [R_G0..R_I7];
  435. usableregsint = general_registers;
  436. c_countusableregsint = 4;
  437. fpuregs = [R_F0..R_F31];
  438. usableregsfpu = [];
  439. c_countusableregsfpu = 0;
  440. mmregs = [R_G0..R_G7];
  441. usableregsmm = [R_G0..R_G7];
  442. c_countusableregsmm = 8;
  443. firstsaveintreg = R_G0;
  444. lastsaveintreg = R_I7;
  445. firstsavefpureg = R_F0;
  446. lastsavefpureg = R_F31;
  447. firstsavemmreg = R_G0;
  448. lastsavemmreg = R_I7;
  449. lowsavereg = R_G0;
  450. highsavereg = R_I7;
  451. ALL_REGISTERS = [lowsavereg..highsavereg];
  452. lvaluelocations = [LOC_REFERENCE,LOC_CFPUREGISTER,
  453. LOC_CREGISTER,LOC_MMXREGISTER,LOC_CMMXREGISTER];
  454. {
  455. registers_saved_on_cdecl = [R_ESI,R_EDI,R_EBX];}
  456. { generic register names }
  457. stack_pointer_reg=R_O6;
  458. frame_pointer_reg=R_I6;
  459. self_pointer_reg=R_G5;
  460. accumulator = R_G0;
  461. accumulatorhigh = R_I7;
  462. { WARNING: don't change to R_ST0!! See comments above implementation of }
  463. { a_loadfpu* methods in rgcpu (JM) }
  464. fpu_result_reg=R_F0;
  465. mmresultreg=R_G0;
  466. {*****************************************************************************}
  467. { GCC /ABI linking information }
  468. {*****************************************************************************}
  469. {# Registers which must be saved when calling a routine declared as cppdecl,
  470. cdecl, stdcall, safecall, palmossyscall. The registers saved should be the ones
  471. as defined in the target ABI and / or GCC.
  472. This value can be deduced from the CALLED_USED_REGISTERS array in the GCC
  473. source.}
  474. std_saved_registers=[R_O6];
  475. {# Required parameter alignment when calling a routine declared as stdcall and
  476. cdecl. The alignment value should be the one defined by GCC or the target ABI.
  477. The value of this constant is equal to the constant
  478. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.}
  479. std_param_align=4;
  480. {# Registers which are defined as scratch and no need to save across routine
  481. calls or in assembler blocks.}
  482. ScratchRegsCount=3;
  483. scratch_regs:ARRAY[1..ScratchRegsCount]OF TRegister=(R_O4,R_O5,R_I7);
  484. {$WARNING FIXME : Scratch registers list has to be verified}
  485. { low and high of the available maximum width integer general purpose }
  486. { registers }
  487. LoGPReg = R_G0;
  488. HiGPReg = R_I7;
  489. { low and high of every possible width general purpose register (same as }
  490. { above on most architctures apart from the 80x86) }
  491. LoReg = R_G0;
  492. HiReg = R_I7;
  493. cpuflags = [];
  494. { sizes }
  495. pointersize = 4;
  496. extENDed_size = 8;{SPARC architecture uses IEEE floating point numbers}
  497. mmreg_size = 8;
  498. sizepostfix_pointer = S_L;
  499. {*****************************************************************************
  500. Instruction table
  501. *****************************************************************************}
  502. {$ifndef NOAG386BIN}
  503. TYPE
  504. tinsentry=packed record
  505. opcode : tasmop;
  506. ops : byte;
  507. optypes : ARRAY[0..2] of LongInt;
  508. code : ARRAY[0..maxinfolen] of char;
  509. flags : LongInt;
  510. END;
  511. pinsentry=^tinsentry;
  512. TInsTabCache=ARRAY[TasmOp] of LongInt;
  513. PInsTabCache=^TInsTabCache;
  514. VAR
  515. InsTabCache : PInsTabCache;
  516. {$ENDif NOAG386BIN}
  517. {*****************************************************************************
  518. Helpers
  519. *****************************************************************************}
  520. CONST
  521. maxvarregs=30;
  522. VarRegs:ARRAY[1..maxvarregs]OF TRegister=(
  523. R_G0,R_G1,R_G2,R_G3,R_G4,R_G5,R_G6,R_G7,
  524. R_O0,R_O1,R_O2,R_O3,R_O4,R_O5,{R_R14=R_SP}R_O7,
  525. R_L0,R_L1,R_L2,R_L3,R_L4,R_L5,R_L6,R_L7,
  526. R_I0,R_I1,R_I2,R_I3,R_I4,R_I5,{R_R30=R_FP}R_I7
  527. );
  528. maxfpuvarregs = 8;
  529. max_operands = 3;
  530. maxintregs = maxvarregs;
  531. maxfpuregs = maxfpuvarregs;
  532. FUNCTION reg2str(r:tregister):string;
  533. FUNCTION is_calljmp(o:tasmop):boolean;
  534. FUNCTION flags_to_cond(CONST f:TResFlags):TAsmCond;
  535. IMPLEMENTATION
  536. FUNCTION reg2str(r:tregister):string;
  537. TYPE
  538. TStrReg=ARRAY[TRegister]OF STRING[5];
  539. CONST
  540. StrReg:TStrReg=({$INCLUDE strregs.inc});
  541. BEGIN
  542. reg2str:=StrReg[r];
  543. END;
  544. FUNCTION is_calljmp(o:tasmop):boolean;
  545. BEGIN
  546. CASE o OF
  547. A_CALL,A_JMPL:
  548. is_calljmp:=true;
  549. ELSE
  550. is_calljmp:=false;
  551. END;
  552. END;
  553. FUNCTION flags_to_cond(CONST f:TResFlags):TAsmCond;
  554. CONST
  555. flags_2_cond:ARRAY[TResFlags]OF TAsmCond=(C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  556. BEGIN
  557. result:=flags_2_cond[f];
  558. END;
  559. END.