Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / include / vtracer.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: vtracer.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////////////////////////////////////////////////////////////
24//
25// File: vtracer.h
26//
27// Copyright (C) 2005 Sun Microsystems, Inc.
28// All rights reserved.
29//
30
31
32#ifndef _sam_vtracer_h_a73ef783_
33#define _sam_vtracer_h_a73ef783_
34
35/* vtracer.h describes the interface between SAM and the tracer */
36
37
38///////////////////////////////////////////////////////
39//
40// Instruction information
41//
42// Provide infomation about the instruction been executed.
43// Fields in this structure are arranged according to the
44// order in which they are used during instruction lifetime.
45//
46const int VCPU_MAX_DEST_REG_NUM = 32;
47const int VCPU_MAX_MEM_ACCESS_NUM = 32;
48
49// bit encoding for instruction information
50const uint32_t VCPU_UNKNOWN_ITYPE = 0;
51const uint32_t VCPU_LOAD_ITYPE = 1;
52const uint32_t VCPU_STORE_ITYPE = 1<<1;
53const uint32_t VCPU_IO_LOAD_ITYPE = 1<<2;
54const uint32_t VCPU_IO_STORE_ITYPE = 1<<3;
55const uint32_t VCPU_ASI_LOAD_ITYPE = 1<<4;
56const uint32_t VCPU_ASI_STORE_ITYPE = 1<<5;
57const uint32_t VCPU_BRANCH_ITYPE = 1<<6;
58const uint32_t VCPU_ALU_ITYPE = 1<<7;
59const uint32_t VCPU_FP_ITYPE = 1<<8;
60
61// register type encoding
62const uint16_t VCPU_PR_RTYPE = 1;
63const uint16_t VCPU_ASR_RTYPE = 2;
64const uint16_t VCPU_INT_RTYPE = 3;
65const uint16_t VCPU_FP_SINGLE_RTYPE = 4;
66const uint16_t VCPU_FP_DOUBLE_RTYPE = 5;
67const uint16_t VCPU_HPR_RTYPE = 6;
68
69// address type encoding
70enum VCPU_AddrType
71{
72 VCPU_PADDR = 0,
73 VCPU_RADDR = 1,
74 VCPU_VADDR = 2
75};
76
77struct VcpuRegType
78{
79 uint16_t type;
80 uint16_t id;
81};
82
83typedef union
84{
85 VcpuRegType r;
86 uint32_t regtid;
87}
88VCPU_RegType;
89
90
91typedef struct InstrInfo
92{
93 int16_t cpuid;
94
95 uint32_t pid; // partition id
96
97 // we care about priv, global, 32/64-bit arch mask
98 uint32_t pstate;
99
100 // only for newer processors. we care about hpriv
101 uint32_t hpstate;
102
103 uint32_t pc_type; // virtual, physical or real
104 uint8_t immu_asi;
105 uint16_t icontext;
106 uint64_t pc_va;
107 uint64_t npc_va;
108
109 bool ifetch_trap; // if true, expect trap record
110
111 uint64_t pc_pa;
112
113 uint32_t opcode; // instruction opcode
114 uint32_t itype; // instruction type
115
116 // insts that update registers (incl CTI, memop)
117 // the most common case is 1 or 2 registers are updated (eg i-reg and ccr)
118 int nregs; // total number of destination regs written
119 VCPU_RegType dreg[VCPU_MAX_DEST_REG_NUM]; // destination register type and index
120 uint64_t dval [VCPU_MAX_DEST_REG_NUM]; // destination reg value
121
122
123 // if branch
124 bool taken;
125 bool annul; // annul delay-slot inst if true
126
127 // if memop
128 uint32_t ea_type; // virtual, physical or real
129 uint8_t dmmu_asi;
130 uint16_t dcontext;
131
132 uint64_t ea_va;
133 uint64_t ea_pa;
134
135 bool dmmu_trap; // if true, trap record follows
136
137
138 uint64_t ld_mem_value[VCPU_MAX_MEM_ACCESS_NUM];
139 uint64_t st_mem_value[VCPU_MAX_MEM_ACCESS_NUM];
140 uint64_t st_bitmask; // store value bitmask
141 uint64_t ld_bitmask; // load value bitmask
142 uint32_t ld_num; // number of loads
143 uint32_t st_num; // number of stores
144
145 // if any instr
146 bool exception; // if true, trap record follows
147
148
149}
150VCPU_Instruction;
151
152typedef struct TrapInfo
153{
154
155 int16_t cpuid;
156 int tno; // trap number
157 int is_async; // asynchronous trap
158
159 int syscallno; // for tt 0x108
160 int intrsid; // for tt 0x060, val from IRSR (intr source id)
161 int intrino; // for tt 0x060, val from IRDR0 (solaris ino of device)
162
163 uint32_t pc_type; // virtual, physical or real
164 uint64_t pc_va;
165 uint64_t npc_va;
166
167 int nregs; // total number of destination regs written
168 VCPU_RegType dreg[VCPU_MAX_DEST_REG_NUM]; // destination register type and index
169 uint64_t dval [VCPU_MAX_DEST_REG_NUM]; // destination reg value
170
171}
172VCPU_Trap;
173
174
175typedef struct TLBInfo
176{
177 int16_t cpuid;
178
179 uint8_t demap ; // 0 = add/replace entry ; 1=invalidate
180 uint8_t tlb_type ; // 0:INSTR, 1:DATA 2:UNIFIED
181
182 // Each TLB implementor can number the lines in the TLB arbitrarily
183 // For direct-mapped TLBs, the line index is obvious
184 // For a K-way TLB, we recommend having idx={0,1,..,K-1}=first set
185 uint16_t tlb_index; // TLB line index, specific to each TLB impl
186
187 uint8_t tlb_no ; // which I or D TLB ? (eg. Ch+ has 3 DTLBS)
188
189 uint8_t format; // 0=>sun4u, 1=>sun4v
190
191 // for sun4u, tte_tag is {pa[63:13], ctxt[12:0]}
192 // for sun4v, tte_tag is pa[63:0]
193 uint64_t tte_tag; // tag for a TTE
194
195 // for sun4u (ch/ch+), tte_data is as described in rstf_tte_dataT
196 // v:63, size:62-61, nfo:60, ie:59, pa:42-13, l:6, cp:5, cv:4, e:3, p:2, w:1, g:0
197
198 // for sun4v, tte_data is as described in rstf_sun4v_tte_dataT
199 // v:63 nfo:62 taddr: 55-13 ie:12 e:11 cp:10 cv:9 p:8 ep:7 w:6 sz:3-0
200
201 uint64_t tte_data; // equal to taddr for sun4v; has flags besides paddr for sun4u
202
203 uint8_t is_real; // sun4v only
204 uint8_t partid; // sun4v only
205
206 uint8_t tte_page_size; // 0=8Kb, 1=64Kb, ...
207 uint16_t tte_context; // The context for virt TTE
208
209 uint64_t pagemask() const {
210 register uint64_t pgsz = 1ull << (13 + 3*tte_page_size);
211 return ~(pgsz - 1);
212 }
213
214 // PA is data[42:13] in sun4u, data[55:13] in sun4v
215 static const uint64_t sun4u_pa_mask = (0x3fffffffull << 13);
216 static const uint64_t sun4v_pa_mask = (0x7ffffffffffull << 13);
217
218 uint64_t va() const {
219 return tte_tag & pagemask();
220 }
221
222 uint64_t pa() const {
223 register uint64_t rv = tte_data & pagemask();
224 if (format == 0) {
225 rv &= sun4u_pa_mask;
226 } else {
227 rv &= sun4v_pa_mask;
228 }
229
230 return rv;
231 }
232
233 // flags
234 int v() { return (tte_data >> 63)&1; }
235 int nfo() { return (tte_data >> (format?62:60)) & 1; }
236 int ie() { return (tte_data >> (format?12:59)) & 1; }
237 int e() { return (tte_data >> (format?11:3)) & 1; }
238 int cp() {return (tte_data >> (format?10:5)) & 1; }
239 int cv() { return (tte_data >> (format?9:4)) & 1; }
240 int p() { return (tte_data >> (format?8:2)) & 1; }
241 int ep() { return (format? ((tte_data >> 7)&1) : (tlb_type==0)); }
242 int w() { return (tte_data >> (format?6:1)) & 1; }
243 int l() { return format? 0: ((tte_data >> 6) & 1); }
244 int g() { return format? 0: ((tte_data >> 0) & 1); }
245
246}
247VCPU_TLB;
248
249
250typedef struct HwOpInfo
251{
252 int16_t cpuid;
253
254 uint32_t op_type ; // 0 = INSTR, 1 = DATA
255
256 uint64_t addr;
257 uint64_t data[2];
258
259}
260VCPU_HwOp;
261
262// the async trace structures (dma, string) use a union type
263typedef union vtracer_async_data_u {
264 enum { rtype_DMA=13, rtype_STRING=14 };
265
266 struct {
267 uint8_t rtype; // == rtype_DMA
268 uint8_t iswrite;
269 uint16_t reserved1; // always zero
270 uint32_t devid;
271 int64_t nbytes;
272 uint64_t pa;
273 } dma;
274
275 struct {
276 uint8_t rtype; // == rtype_STRING
277 char s[23]; // must be null-terminated
278 } strdata;
279
280} VCPU_AsyncData;
281
282
283typedef struct vtracer_syncinfo {
284
285 // uses same value as rstracer timesync subtypes
286 enum {synctype_NIL=0, synctype_LOCAL=1, synctype_GLOBAL=2 };
287
288 int cpuid;
289 int synctype; // uses synctype enumerated values
290 int data; // not used for local or global barrier sync. usable for mem sync
291 int64_t syncid; // monotonically increasing id shared by all processors.
292 // syncid is not guaranteed to be preserved across dump/restore
293} VCPU_Sync;
294
295class VTracer_SAM_intf {
296 void dump_state();
297};
298
299// Virtual Tracer interface
300
301/* A tracer module must NOT define a static vtracer object. The
302 * vtracer object must be created by the vtracer_init() function
303 * provided by the module code and called by the simulator. Also, the
304 * module must provide a function called vtracer_fini() which should
305 * clean up before the module is unloaded (eg unregister ui cmds, free
306 * memory etc.)
307 */
308
309class VTracer
310{
311public:
312
313 virtual ~VTracer() {}
314
315 // virtual void ui_cmd(const char * tmp_cmd, int argc, const char ** tmp_argv) = 0;
316
317 virtual int attach(VTracer_SAM_intf * /* intf */) = 0;
318
319 virtual int instr ( VCPU_Instruction * ) = 0;
320 virtual int trap ( VCPU_Trap * ) = 0;
321 virtual int tlb ( VCPU_TLB * ) = 0;
322 virtual int hwop ( VCPU_HwOp * ) { return 0; }
323
324 virtual int async (VCPU_AsyncData *) = 0;
325
326 virtual int sync (VCPU_Sync *) = 0;
327
328
329 // for execution-driven mode
330 virtual int cycle() { return 0; }
331
332#if 0
333 // these methods are called from teh simulator into the tracer
334 // with information about simulated instructions and other events
335 virtual void SysConf(struct vtr_SysConf * sc);
336
337 virtual void MachState(struct vtr_MachState * ms);
338
339 virtual void Instr(VCPU_Instruction * ii);
340
341 virtual void Trap(struct vtr_trapinfo * ti);
342
343 virtual void TlbUpdate(struct vtr_tlbupdate * tu);
344
345 virtual void Dma(struct vtr_dma * dm);
346
347#endif
348}; // class VTracer
349
350
351extern "C" void * vtracer_init(const char * tmp_modname); // return value is class VTracer *
352extern "C" void vtracer_fini();
353#endif // _sam_vtracer_h_a73ef783_
354