Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: SS_Opcode.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __SS_Opcode_h__ | |
24 | #define __SS_Opcode_h__ | |
25 | ||
26 | #include "SS_Types.h" | |
27 | ||
28 | class SS_Opcode | |
29 | { | |
30 | public: | |
31 | bool operator==( const SS_Opcode& o ) { return opc == o.opc; } | |
32 | bool operator!=( const SS_Opcode& o ) { return opc != o.opc; } | |
33 | ||
34 | SS_Opcode& operator=( uint32_t o ) { opc = o; return *this; } | |
35 | ||
36 | uint32_t operator()() { return opc; } | |
37 | ||
38 | void set ( uint32_t o ) { opc = o; } | |
39 | uint32_t get() { return opc; } | |
40 | ||
41 | uint_t get_op() { return (opc >> 30) & 3; } | |
42 | uint_t get_op2() { return (opc >> 22) & 0x7; } | |
43 | uint_t get_op2cc() { return (opc >> 20) & 0x1f; } | |
44 | uint_t get_op3() { return (opc >> 19) & 0x3f; } | |
45 | uint_t get_opf() { return (opc >> 5) & 0x1ff; } | |
46 | uint_t get_i() { return (opc >> 13) & 1; } | |
47 | uint_t get_a() { return (opc >> 29) & 1; } | |
48 | uint_t get_cond() { return (opc >> 25) & 0xf; } | |
49 | uint_t get_fcn() { return (opc >> 25) & 0x1f; } | |
50 | uint_t get_cc() { return (opc >> 20) & 3; } | |
51 | uint_t get_x() { return (opc >> 12) & 1; } | |
52 | uint_t get_ccr() { return (opc >> 11) & 3; } | |
53 | ||
54 | int_t get_rs1() { return (opc >> 14) & 0x1f; } | |
55 | int_t get_rs2() { return opc & 0x1f; } | |
56 | int_t get_rd() { return (opc >> 25) & 0x1f; } | |
57 | ||
58 | int_t get_rs1_irf() { return (opc >> 11) & 0xf8; } | |
59 | int_t get_rs2_irf() { return (opc << 3) & 0xf8; } | |
60 | int_t get_rd_irf() { return (opc >> 22) & 0xf8; } | |
61 | int_t get_p() { return (opc >> 19) & 1; } | |
62 | ||
63 | int_t get_rs1_frf() | |
64 | { | |
65 | #if defined (ARCH_X64) | |
66 | return ((opc >> 12) & 0x7c) ^ 0x4; | |
67 | #else | |
68 | return (opc >> 12) & 0x7c; | |
69 | #endif | |
70 | } | |
71 | int_t get_rs2_frf() | |
72 | { | |
73 | #if defined (ARCH_X64) | |
74 | return ((opc << 2) & 0x7c) ^ 0x4; | |
75 | #else | |
76 | return (opc << 2) & 0x7c; | |
77 | #endif | |
78 | } | |
79 | int_t get_rs3_frf() | |
80 | { | |
81 | #if defined (ARCH_X64) | |
82 | return ((opc >> 7) & 0x7c) ^ 0x4; | |
83 | #else | |
84 | return (opc >> 7) & 0x7c; | |
85 | #endif | |
86 | } | |
87 | int_t get_rd_frf() | |
88 | { | |
89 | #if defined (ARCH_X64) | |
90 | return ((opc >> 23) & 0x7c) ^ 0x4; | |
91 | #else | |
92 | return (opc >> 23) & 0x7c; | |
93 | #endif | |
94 | } | |
95 | ||
96 | int_t get_rs1_drf() { return (((opc) >> 7) & 0x80) | (((opc) >> 12) & 0x78); } | |
97 | int_t get_rs2_drf() { return (((opc) << 7) & 0x80) | (((opc) << 2) & 0x78); } | |
98 | int_t get_rs3_drf() { return (((opc) >> 2) & 0x80) | (((opc) >> 7) & 0x78); } | |
99 | int_t get_rd_drf() { return (((opc) >> 18) & 0x80) | (((opc) >> 23) & 0x78); } | |
100 | ||
101 | int64_t get_simm10() { return (int64_t(opc) << 54) >> 54; } | |
102 | int64_t get_simm11() { return (int64_t(opc) << 53) >> 53; } | |
103 | int64_t get_simm13() { return (int64_t(opc) << 51) >> 51; } | |
104 | ||
105 | uint64_t get_imm3() { return opc & 0x7; } | |
106 | uint64_t get_imm5() { return opc & 0x1f; } | |
107 | uint64_t get_imm6() { return opc & 0x3f; } | |
108 | uint64_t get_imm7() { return opc & 0x7f; } | |
109 | uint64_t get_imm8() { return opc & 0xff; } | |
110 | uint64_t get_imm16() { return ((opc >> 6) & 0xc000) | (opc & 0x3fff); } | |
111 | uint64_t get_imm22() { return opc << 10; } | |
112 | ||
113 | uint32_t get_imm_asi() { return (opc >> 5) & 0xff; } | |
114 | ||
115 | int64_t get_disp16() { return int64_t(((uint64_t(opc)>>20)<<62)|((uint64_t(opc)<<50)>>2)) >> 46; } | |
116 | int64_t get_disp19() { return (int64_t(opc) << 45) >> 43; } | |
117 | int64_t get_disp22() { return (int64_t(opc) << 42) >> 40; } | |
118 | int64_t get_disp30() { return (int64_t(opc) << 34) >> 32; } | |
119 | ||
120 | // is_zero_<to>_<from>() returns true when bits <from> to <to> (inclusive) are | |
121 | // zero. False is returned otherwise. The methods are used in decoding. | |
122 | ||
123 | bool is_zero_29_25() { return 0 == ((opc >> 25) & 0x1f); } | |
124 | bool is_zero_18_0() { return 0 == (opc & 0x7ffff); } | |
125 | bool is_zero_18_14() { return 0 == ((opc >> 14) & 0x1f); } | |
126 | bool is_zero_18_18() { return 0 == (opc & 0x40000); } | |
127 | bool is_zero_13_0() { return 0 == (opc & 0x3fff); } | |
128 | bool is_zero_12_8() { return 0 == ((opc >> 8) & 0x1f); } | |
129 | bool is_zero_12_7() { return 0 == ((opc >> 7) & 0x3f); } | |
130 | bool is_zero_12_5() { return 0 == ((opc >> 5) & 0xff); } | |
131 | bool is_zero_11_7() { return 0 == (opc & 0xf80); } | |
132 | bool is_zero_11_6() { return 0 == (opc & 0xfc0); } | |
133 | bool is_zero_11_5() { return 0 == (opc & 0xfe0); } | |
134 | bool is_zero_10_8() { return 0 == (opc & 0x700); } | |
135 | bool is_zero_10_5() { return 0 == (opc & 0x7e0); } | |
136 | bool is_zero_9_5() { return 0 == (opc & 0x3e0); } | |
137 | bool is_zero_4_0() { return 0 == (opc & 0x1f); } | |
138 | bool is_zero_4_3() { return 0 == (opc & 0x18); } | |
139 | ||
140 | void set_rs1( uint32_t v ) { opc = (opc & ~(0x1f << 14)) | ((v & 0x1f) << 14); } | |
141 | void set_rs2( uint32_t v ) { opc = (opc & ~ 0x1f ) | ( v & 0x1f ); } | |
142 | void set_rd ( uint32_t v ) { opc = (opc & ~(0x1f << 25)) | ((v & 0x1f) << 25); } | |
143 | void set_imm( uint32_t v ) { opc = (opc & ~0x3fff) | (v & 0x3fff); } | |
144 | ||
145 | protected: | |
146 | uint32_t opc; | |
147 | }; | |
148 | ||
149 | #endif | |
150 |