Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / sam / src / SS_VirtualStrand.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: SS_VirtualStrand.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#ifndef __SS_VirtualStrand_h__
25#define __SS_VirtualStrand_h__
26
27#include "SS_Types.h"
28#include "SS_Strand.h"
29#include "SS_SamTracer.h"
30
31#define bool_t bool
32
33namespace Sam {
34#include "vcpu.h"
35#include "Memory.h"
36}
37
38class SS_SamTracer; // forward declaration
39
40class SS_VirtualStrand : public Sam::Vcpu
41{
42 public:
43 SS_VirtualStrand();
44
45
46 int stepi( int64_t n=1 )
47 {
48 uint64_t ret = 0;
49
50 if (config.delay >= n)
51 {
52 config.delay -= n; // skip n instructions
53 }
54 else // step n instruction
55 {
56 int ii = n - config.delay;
57
58 config.delay = 0;
59
60 // strand will not increments tick/stick after every step
61 if(sys_intf.vtrace) // tracer is enabled
62 {
63 strand->add_tracer(&tracer);
64 ret = strand->trc_step(ii);
65 strand->del_tracer(&tracer);
66 }
67 else if (strand->trc_hook || strand->sim_state.ras_enabled())
68 {
69 ret = strand->trc_step(ii);
70 }
71 else
72 {
73 ret = strand->run_step(ii);
74 }
75 }
76 return ret;
77 }
78
79 void update_stick(int64_t stickincr)
80 {
81 strand->run_tick(stickincr);
82 }
83
84 virtual void update_perfcntr (Sam::Vcpu::perfcntr which, int64_t incr)
85 {
86 strand->run_perf(strand, which, incr); // performance instrumentation counters
87 }
88
89 int interrupt( Sam::VCPU_InterruptRequest* );
90
91 RegError get_reg_index( const char* reg_name, RegIndex* index )
92 {
93 for (int i=SS_Registers::INDEX_BEGIN; i < SS_Registers::ALIAS_END; i++)
94 {
95 // First check all the alias names like pc for asr5, etc
96 // If reg_name is not an alias then check if it is say asr5
97
98 const char* name = get_reg_name(i);
99
100 if (!name)
101 continue;
102
103 if (strcmp(reg_name,name) == 0)
104 {
105 *index = RegIndex(i);
106 return REG_OK;
107 }
108 else if (strcmp(reg_name,SS_Registers::get_name(SS_Registers::Index(i))) == 0)
109 {
110 if (get_reg_name(i))
111 {
112 *index = RegIndex(i);
113 return REG_OK;
114 }
115 else
116 return REG_NOT_AVAILABLE;
117 }
118 }
119 return REG_NOT_AVAILABLE;
120 }
121
122 const char* get_reg_name( RegIndex index )
123 {
124 return (strand->get_state_name)(strand,SS_Registers::Index(index));
125 }
126
127 RegError get_reg( RegIndex index, uint64_t* data )
128 {
129 return RegError((strand->get_state)(strand,SS_Registers::Index(index),data));
130 }
131
132 RegError set_reg( RegIndex index, uint64_t data )
133 {
134 return RegError((strand->set_state)(strand,SS_Registers::Index(index),data));
135 }
136
137 int get_asi(uint8_t asi, uint64_t addr, uint64_t &data)
138 {
139 return (strand->asi_map.rd64( strand, asi, addr, &data )) != SS_AsiSpace::OK;
140 }
141 int set_asi(uint8_t asi, uint64_t addr, uint64_t data)
142 {
143 return (strand->asi_map.wr64( strand, asi, addr, data )) != SS_AsiSpace::OK;
144 }
145
146 TranslateError translate( TranslateMode mode, uint64_t addr, uint64_t context, uint64_t partitionid, uint64_t* phys_addr )
147 {
148 return (strand->cnv2pa)(strand,mode,addr,context,partitionid,phys_addr);
149 }
150
151 int get_tlb_entries(struct Sam::TLBInfo * &return_array);
152
153 int read_mem ( uint64_t addr, uint64_t *value, int size, int asi= 0x82, int is_physical=0 );
154 int write_mem ( uint64_t addr, uint64_t value, int size, int asi= 0x82, int is_physical=0 );
155
156
157 int set_breakpoint ( int *bp_id, Sam::VCPU_BpType type, uint64_t value,
158 Sam::VCPU_BpActionFn action, uint64_t mask= ~(uint64_t(0)));
159
160 int delete_breakpoint ( int bp_id = ~(0) );
161
162
163 // print breakpoint list
164 virtual int print_breakpoints ( FILE *fp );
165
166 // print all regs to file/consol
167 virtual int print_regs ( FILE *fp ) { return 1; }
168
169 // print tlbs to file/consol
170 virtual int print_tlbs ( FILE *fp );
171
172
173 SS_Strand* strand;
174
175 SS_SamTracer tracer;
176};
177
178#endif