aboutsummaryrefslogtreecommitdiff
path: root/sim/sparc/sparc-sim.h
blob: 1bbf3dffa71cca04cd8b507d2d182adaa8cf4b0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* collection of junk waiting time to sort out
   Copyright (C) 1999 Cygnus Solutions.  */

#ifndef SPARC_SIM_H
#define SPARC_SIM_H

/* GDB register numbers, will eventually live in more public place.  */
#define SPARC32_PC_REGNUM 68
#define SPARC32_NPC_REGNUM 69
#define SPARC64_PC_REGNUM ?
#define SPARC64_NPC_REGNUM ?

/* Commonly used registers.  */
#define REG_O0 8
#define REG_O1 9
#define REG_O2 10
#define REG_O3 11
#define REG_O4 12
#define REG_O5 13
#define REG_SP 14
#define REG_FP 30

#define CURRENT_GREGS(cpu) (& (cpu)->current_regs[0])
#define CURRENT_OREGS(cpu) (& (cpu)->current_regs[8])
#define CURRENT_LREGS(cpu) (& (cpu)->current_regs[16])
#define CURRENT_IREGS(cpu) (& (cpu)->current_regs[24])

/* The register windows are recorded in a seemingly backwards manner.
   %i0-7 live at lower addresses in memory than %o0-7 (even though they
   have higher register numbers).  This is because on v9 the stack grows
   upwards in the sense that CWP increases during a "push" (save) operation.
   On v8 CWP decreases during a "push" (save) operation.  */

#define REAL_GREGS(cpu) \
  (& (cpu)->global_regs[0])
#define REAL_IREGS(cpu, win) \
  (& (cpu)->win_regs[win][0])
#define REAL_LREGS(cpu, win) \
  (& (cpu)->win_regs[win][8])
#ifdef WANT_CPU_SPARC32
#define REAL_OREGS(cpu, win) \
  (& (cpu)->win_regs[ROUND_WIN ((win) - 1)][0])
#endif
#ifdef WANT_CPU_SPARC64
#define REAL_OREGS(cpu, win) \
  (& (cpu)->win_regs[ROUND_WIN ((win) + 1)][0])
#endif

/* Window state.  */

/* Various ways to handle register windows:
   - don't, do all index calculations at runtime
   - table of lookup tables, one entry for each window
   - working copy of registers that is swapped in/out on each
     register window change
   - table of 32 pointers, one for each regs
   - table of 4 pointers, one for each of g,o,l,i regs
   - ???
*/

/* FIXME: Hardcodes number of windows.  */
#define GET_NWINDOWS() NWINDOWS

/* We take advantage of the fact that NWINDOWS is always a power of two.  */
#define ROUND_WIN(x) ((x) & (NWINDOWS - 1))

/* Return the next and previous windows of WIN.
   Note that the next window for sparc32 is win-1 whereas the next window
   for sparc64 is win+1.  */
#ifdef WANT_CPU_SPARC32
#define NEXT_WIN(win) ROUND_WIN ((win) - 1)
#define PREV_WIN(win) ROUND_WIN ((win) + 1)
#endif
#ifdef WANT_CPU_SPARC64
#define NEXT_WIN(win) ROUND_WIN ((win) + 1)
#define PREV_WIN(win) ROUND_WIN ((win) - 1)
#endif

#if 0 /* FIXME: Use GET_H_FOO */
/* These are v9 specific.  */
#define GET_CANSAVE(cpu_)    (cpu_->cgen_cpu.cpu.h_cansave)
#define GET_CANRESTORE(cpu_) (cpu_->cgen_cpu.cpu.h_canrestore)
#define GET_CLEANWIN(cpu_)   (cpu_->cgen_cpu.cpu.h_cleanwin)
#define GET_OTHERWIN(cpu_)   (cpu_->cgen_cpu.cpu.h_otherwin)
#define GET_WSTATE(cpu_)     (cpu_->cgen_cpu.cpu.h_wstate)

/* These are v9 specific.  */
#define SET_CANSAVE(cpu_, x)    (cpu_->cgen_cpu.cpu.h_cansave = (x))
#define SET_CANRESTORE(cpu_, x) (cpu_->cgen_cpu.cpu.h_canrestore = (x))
#define SET_CLEANWIN(cpu_, x)   (cpu_->cgen_cpu.cpu.h_cleanwin = (x))
#define SET_OTHERWIN(cpu_, x)   (cpu_->cgen_cpu.cpu.h_otherwin = (x))
#define SET_WSTATE(cpu_, x)     (cpu_->cgen_cpu.cpu.h_wstate = (x))
#endif

#define CPU32_CGEN(cpu) (& (cpu)->sparc_cpu.sparc32.cpu_cgen)

#ifdef WANT_CPU_SPARC32
/*#define ARGBUF SPARC32_ARGBUF*/
#define CPU_PROFILE_STATE(cpu) (& CPU32 (cpu)->cpu_profile)
/* Macro to access heart of cpu: the registers, etc.  */
#define CPU_CGEN(cpu) CPU32_CGEN (cpu)
#endif

#define CPU64_CGEN(cpu) (& (cpu)->sparc_cpu.sparc64.cpu_cgen)

#ifdef WANT_CPU_SPARC64
/*#define ARGBUF SPARC64_ARGBUF*/
#define CPU_PROFILE_STATE(cpu) (& CPU64 (cpu)->cpu_profile)
/* Macro to access heart of cpu: the registers, etc.  */
#define CPU_CGEN(cpu) CPU64_CGEN (cpu)
#endif

/* ASI accesses.  */

#define DECLARE_GETMEM(mode, size) \
extern mode XCONCAT3 (GETMEM,mode,ASI) (SIM_CPU *, IADDR, ADDR, INT);

DECLARE_GETMEM (QI, 1)
DECLARE_GETMEM (UQI, 1)
DECLARE_GETMEM (HI, 2)
DECLARE_GETMEM (UHI, 2)
DECLARE_GETMEM (SI, 4)
DECLARE_GETMEM (USI, 4)
DECLARE_GETMEM (DI, 8)
DECLARE_GETMEM (UDI, 8)

#undef DECLARE_GETMEM

#define DECLARE_SETMEM(mode, size) \
extern void XCONCAT3 (SETMEM,mode,ASI) (SIM_CPU *, IADDR, ADDR, INT, mode);

DECLARE_SETMEM (QI, 1)
DECLARE_SETMEM (UQI, 1)
DECLARE_SETMEM (HI, 2)
DECLARE_SETMEM (UHI, 2)
DECLARE_SETMEM (SI, 4)
DECLARE_SETMEM (USI, 4)
DECLARE_SETMEM (DI, 8)
DECLARE_SETMEM (UDI, 8)

#undef DECLARE_SETMEM

/* Misc. support routines.  */

void sparc32_cold_reset (SIM_CPU *, int userland_p_);

SI sparc32_do_restore (SIM_CPU *, IADDR pc_, SI rs1_, SI rs2_simm13_);
SI sparc32_do_save (SIM_CPU *, IADDR pc_, SI rs1_, SI rs2_simm13_);

void sparc32_do_ldstub (SIM_CPU *, IADDR pc_, INT rd_regno_,
			SI rs1_, SI rs2_simm13_, INT asi_);
void sparc32_do_swap (SIM_CPU *, IADDR pc_, INT rd_regno_,
		      SI rs1_, SI rs2_simm13_, INT asi_);

void sparc32_invalid_insn (SIM_CPU *, IADDR pc_);
void sparc32_core_signal (SIM_DESC, SIM_CPU *, sim_cia pc_,
			  unsigned int map_, int nr_bytes_, address_word addr_,
			  transfer_type transfer_, sim_core_signals sig_);

/* Profiling support.  */

void model_mark_get_h_gr (SIM_CPU *, void *);
void model_mark_set_h_gr (SIM_CPU *, void *);
void model_mark_busy_reg (SIM_CPU *, void *);
void model_mark_unbusy_reg (SIM_CPU *, void *);

/* Called by semantic code to annul the next insn.  */

#define SEM_ANNUL_INSN(cpu, pc, yes) \
do { CPU_CGEN_HW (cpu)->h_annul_p = (yes); } while (0)

#if 0 /* old experiment */

/* Macros used by the semantic code generator and cgen-run.c to control
   branches.  */

/* Value returned for the next PC when a branch has occured.  */
#define PC_BRANCH_INSN 3

/* Value of npc when there is no delay slot.  */
#define NPC_NO_DELAY_INSN 3

/* CURRENT_CPU isn't used, a variable of same name must exist for SET_H_NPC */
#define BRANCH_NEW_PC(current_cpu, var, addr) \
do { \
  SET_H_PC (var); \
  SET_H_NPC (addr); \
  var = PC_BRANCH_INSN; \
} while (0)

/* Mark the next instruction as being annulled if YES is non-zero.
   VAR is the local variable that contains the next PC value.
   CURRENT_CPU isn't used, a variable of same name must exist for SET_H_NPC */
#define ANNUL_NEXT_INSN(current_cpu, var, yes) \
do { \
  if (yes) \
    { \
      SET_H_ANNUL_P (yes); \
      var = PC_BRANCH_INSN; \
    } \
} while (0)

/* Update the PC.
   We also have to watch for delay slots and annulled insns.
   current_cpu isn't used, a variable of same name must exist for SET_H_PC */
#define UPDATE_PC(current_cpu, new_pc) \
do { \
  if ((new_pc) == PC_BRANCH_INSN) \
    { \
      int annul_p = GET_H_ANNUL_P (); \
      PCADDR npc = GET_H_NPC (); \
      SET_H_ANNUL_P (0); \
      if (npc != NPC_NO_DELAY_INSN) \
	{ \
	  if (annul_p) \
	    { \
	      /* FIXME: Could update cycle count.  */ \
	      SET_H_PC (npc); \
	      SET_H_NPC (NPC_NO_DELAY_INSN) ; \
	    } \
	  else \
	    goto GotoFirstInsn; \
	} \
      else \
	{ \
	  /* Untaken annulled branch.  */ \
	  /* FIXME: Could update cycle count.  */ \
	  ASSERT (annul_p); \
	  SET_H_PC (GET_H_PC () + 8); \
	} \
    } \
  else \
    SET_H_PC (new_pc); \
} while (0)

/* Return nonzero if in non-annulled delay slot.  */
#define EXECUTE_FIRST_INSN_P(current_cpu) \
(GET_H_NPC () != NPC_NO_DELAY_INSN)

/* Called when the first instruction is in non-annulled delay slot.  */

#define EXECUTE_FIRST_INSN(current_cpu, sc, fast_p) \
do { \
  PCADDR new_pc = execute (current_cpu, sc, fast_p); \
  if (new_pc == PC_BRANCH_INSN) \
    { \
      abort (); /* FIXME: dcti in delay slot not handled yet */ \
    } \
  else \
    { \
      SET_H_PC (GET_H_NPC ()); \
      SET_H_NPC (NPC_NO_DELAY_INSN); \
    } \
} while (0)

#endif /* old experiment */

#endif /* SPARC_SIM_H */