OpenCores
URL https://opencores.org/ocsvn/aor3000/aor3000/trunk

Subversion Repositories aor3000

[/] [aor3000/] [trunk/] [sim/] [vmips/] [vmips_emulator.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * This file is subject to the terms and conditions of the GPL License. See
3
 * the file "LICENSE" in the main directory of this archive for more details.
4
 *
5
 * Copyright (C) 2014 Aleksander Osman
6
 */
7
 
8
#ifndef __VMIPS_EMULATOR_H
9
 
10
#define __VMIPS_EMULATOR_H
11
 
12
//------------------------------------------------------------------------------
13
 
14
uint32 ao_interrupts        ();
15
uint8  ao_fetch_byte        (uint32 addr, bool cacheable, bool isolated);
16
uint16 ao_fetch_halfword    (uint32 addr, bool cacheable, bool isolated);
17
uint32 ao_fetch_word        (uint32 addr, int32 mode, bool cacheable, bool isolated);
18
void   ao_store_byte        (uint32 addr, uint8 data, bool cacheable, bool isolated);
19
void   ao_store_halfword    (uint32 addr, uint16 data, bool cacheable, bool isolated);
20
void   ao_store_word        (uint32 addr, uint32 data, bool cacheable, bool isolated, uint32 byteenable = 0xF);
21
 
22
void fatal_error(const char *error, ...);
23
 
24
//------------------------------------------------------------------------------
25
 
26
//------------------------------------------------------------------------------ Code from vmips-1.4.1 project under the GPL license
27
//------------------------------------------------------------------------------
28
//------------------------------------------------------------------------------
29
 
30
/* MIPS R3000 CPU emulation.
31
   Copyright 2001, 2002, 2003, 2004 Brian R. Gaeke.
32
 
33
This file is part of VMIPS.
34
 
35
VMIPS is free software; you can redistribute it and/or modify it
36
under the terms of the GNU General Public License as published by the
37
Free Software Foundation; either version 2 of the License, or (at your
38
option) any later version.
39
 
40
VMIPS is distributed in the hope that it will be useful, but
41
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
42
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43
for more details.
44
 
45
You should have received a copy of the GNU General Public License along
46
with VMIPS; if not, write to the Free Software Foundation, Inc.,
47
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
48
 
49
//------------------------------------------------------------------------------ excnames.h
50
 
51
/* Exceptions - Cause register ExcCode field */
52
#define Int 0       /* Interrupt */
53
#define Mod 1       /* TLB modification exception */
54
#define TLBL 2      /* TLB exception (load or instruction fetch) */
55
#define TLBS 3      /* TLB exception (store) */
56
#define AdEL 4      /* Address error exception (load or instruction fetch) */
57
#define AdES 5      /* Address error exception (store) */
58
#define IBE 6       /* Instruction bus error */
59
#define DBE 7       /* Data (load or store) bus error */
60
#define Sys 8       /* SYSCALL exception */
61
#define Bp 9        /* Breakpoint exception (BREAK instruction) */
62
#define RI 10       /* Reserved instruction exception */
63
#define CpU 11      /* Coprocessor Unusable */
64
#define Ov 12       /* Arithmetic Overflow */
65
#define Tr 13       /* Trap (R4k/R6k only) */
66
#define NCD 14      /* LDCz or SDCz to uncached address (R6k) */
67
#define VCEI 14     /* Virtual Coherency Exception (instruction) (R4k) */
68
#define MV 15       /* Machine check exception (R6k) */
69
#define FPE 15      /* Floating-point exception (R4k) */
70
/* 16-22 - reserved */
71
#define WATCH 23    /* Reference to WatchHi/WatchLo address detected (R4k) */
72
/* 24-30 - reserved */
73
#define VCED 31     /* Virtual Coherency Exception (data) (R4k) */
74
 
75
//------------------------------------------------------------------------------ accesstypes.h
76
 
77
/* Three kinds of memory accesses are possible.
78
 * There are two kinds of load and one kind of store:
79
 * INSTFETCH is a memory access due to an instruction fetch.
80
 * DATALOAD is a memory access due to a load instruction,
81
 * e.g., lw, lh, lb.
82
 * DATASTORE is a memory access due to a store instruction,
83
 * e.g., sw, sh, sb.
84
 *
85
 * ANY is a catch-all used in exception prioritizing which
86
 * implies that none of the kinds of memory accesses applies,
87
 * or that the type of memory access otherwise doesn't matter.
88
 */
89
#define INSTFETCH 0
90
#define DATALOAD 1
91
#define DATASTORE 2
92
#define ANY 3
93
 
94
/* add_core_mapping and friends maintain a set of protection
95
 * bits which define allowable access to memory. These do
96
 * not have anything to do with the virtual memory privilege
97
 * bits that a kernel would maintain; they are used to
98
 * distinguish between, for example, ROM and RAM, and between
99
 * readable and unreadable words of a memory-mapped device.
100
 */
101
#define MEM_READ       0x01
102
#define MEM_WRITE      0x02
103
#define MEM_READ_WRITE 0x03
104
 
105
//------------------------------------------------------------------------------ cpzeroreg.h
106
 
107
/* Constants for virtual address translation.
108
 *
109
 * Some of these are used as masks and some are used as constant
110
 * translations (i.e., the address of something is the address of
111
 * something else plus or minus a translation). The desired effect is
112
 * to reduce the number of random "magic numbers" floating around...
113
 */
114
 
115
#define KSEG_SELECT_MASK 0xe0000000 /* bits of address which determine seg. */
116
#define KUSEG 0            /* not really a mask, but user space begins here */
117
#define KERNEL_SPACE_MASK 0x80000000           /* beginning of kernel space */
118
#define KSEG0 0x80000000     /* beginning of unmapped cached kernel segment */
119
#define KSEG0_CONST_TRANSLATION 0x80000000 /* kseg0 v->p address difference */
120
#define KSEG1 0xa0000000   /* beginning of unmapped uncached kernel segment */
121
#define KSEG1_CONST_TRANSLATION 0xa0000000 /* kseg1 v->p address difference */
122
#define KSEG2 0xc0000000       /* beginning of mapped cached kernel segment */
123
#define KSEG2_top 0xe0000000    /* 2nd half of mapped cached kernel segment */
124
 
125
/* CP0 register names and masks
126
 *
127
 * A table of names for CP0's registers follows. After that follow a
128
 * series of masks by which fields of these registers can be isolated.
129
 * The masks are convenient for Boolean flags but are slightly less so
130
 * for numbers being extracted from the middle of a word because they
131
 * still need to be shifted. At least, it makes clear which field is
132
 * being accessed, and the bit numbers are clearly indicated in every mask
133
 * below.  The naming convention is as follows: Mumble is the name of some
134
 * CP0 register, Mumble_MASK is the bit mask which controls reading and
135
 * writing of the register (0 -> bit is always zero and ignores writes,
136
 * 1 -> normal read/write) and Mumble_Field_MASK is the mask used to
137
 * access the "Field" portion of register Mumble. For more information
138
 * on these fields consult "MIPS RISC Architecture", chapters 4 and 6.
139
 */
140
 
141
#define Index 0     /* selects TLB entry for r/w ops & shows probe success */ 
142
#define Random 1    /* continuously decrementing number (range 8..63) */
143
#define EntryLo 2   /* low word of a TLB entry */
144
#define EntryLo0 2  /* R4k uses this for even-numbered virtual pages */
145
#define EntryLo1 3  /* R4k uses this for odd-numbered virtual pages */
146
#define Context 4   /* TLB refill handler's kernel PTE entry pointer */
147
#define PageMask 5  /* R4k page number bit mask (impl. variable page sizes) */
148
#define Wired 6     /* R4k lower bnd for Random (controls randomness of TLB) */
149
#define Error 7     /* R6k status/control register for parity checking */
150
#define BadVAddr 8  /* "bad" virt. addr (VA of last failed v->p translation) */
151
#define Count 9     /* R4k r/w reg - continuously incrementing counter */
152
#define EntryHi 10  /* High word of a TLB entry */
153
#define ASID 10     /* R6k uses this to store the ASID (only) */
154
#define Compare 11  /* R4k traps when this register equals Count */
155
#define Status 12   /* Kernel/User mode, interrupt enb., & diagnostic states */
156
#define Cause 13    /* Cause of last exception */
157
#define EPC 14      /* Address to return to after processing this exception */
158
#define PRId 15     /* Processor revision identifier */
159
#define Config 16   /* R4k config options for caches, etc. */
160
#define LLAdr 17    /* R4k last instruction read by a Load Linked */
161
#define LLAddr 17   /* Inconsistencies in naming... sigh. */
162
#define WatchLo 18  /* R4k hardware watchpoint data */
163
#define WatchHi 19  /* R4k hardware watchpoint data */
164
/* 20-25 - reserved */
165
#define ECC 26      /* R4k cache Error Correction Code */
166
#define CacheErr 27 /* R4k read-only cache error codes */
167
#define TagLo 28    /* R4k primary or secondary cache tag and parity */
168
#define TagHi 29    /* R4k primary or secondary cache tag and parity */
169
#define ErrorEPC 30 /* R4k cache error EPC */
170
/* 31 - reserved */
171
 
172
/* (0) Index fields */
173
#define Index_P_MASK 0x80000000         /* Last TLB Probe instr failed (31) */
174
#define Index_Index_MASK 0x00003f00  /* TLB entry to read/write next (13-8) */
175
#define Index_MASK 0x80003f00
176
 
177
/* (1) Random fields */
178
#define Random_Random_MASK 0x00003f00   /* TLB entry to replace next (13-8) */
179
#define Random_MASK 0x00003f00
180
/* Random register upper and lower bounds (R3000) */
181
#define Random_UPPER_BOUND 63
182
#define Random_LOWER_BOUND 8
183
 
184
/* (2) EntryLo fields */
185
#define EntryLo_PFN_MASK 0xfffff000            /* Page frame number (31-12) */
186
#define EntryLo_N_MASK 0x00000800                      /* Noncacheable (11) */
187
#define EntryLo_D_MASK 0x00000400                             /* Dirty (10) */
188
#define EntryLo_V_MASK 0x00000200                              /* Valid (9) */
189
#define EntryLo_G_MASK 0x00000100                             /* Global (8) */
190
#define EntryLo_MASK 0xffffff00
191
 
192
/* (4) Context fields */
193
#define Context_PTEBase_MASK 0xffe00000          /* Page Table Base (31-21) */
194
#define Context_BadVPN_MASK 0x001ffffc      /* Bad Virtual Page num. (20-2) */
195
#define Context_MASK 0xfffffffc
196
 
197
/* (5) PageMask is only on the R4k */
198
#define PageMask_MASK 0x00000000
199
 
200
/* (6) Wired is only on the R4k */
201
#define Wired_MASK 0x00000000
202
 
203
/* (7) Error is only on the R6k */
204
#define Error_MASK 0x00000000
205
 
206
/* (8) BadVAddr has only one field */
207
#define BadVAddr_MASK 0xffffffff
208
 
209
/* (9) Count is only on the R4k */
210
#define Count_MASK 0x00000000
211
 
212
/* (10) EntryHi fields */
213
#define EntryHi_VPN_MASK 0xfffff000             /* Virtual page no. (31-12) */
214
#define EntryHi_ASID_MASK 0x00000fc0                 /* Current ASID (11-6) */
215
#define EntryHi_MASK 0xffffffc0
216
 
217
/* (11) Compare is only on the R4k */
218
#define Compare_MASK 0x00000000
219
 
220
/* (12) Status fields */
221
#define Status_CU_MASK 0xf0000000      /* Coprocessor (3..0) Usable (31-28) */
222
#define Status_CU3_MASK 0x80000000             /* Coprocessor 3 Usable (31) */
223
#define Status_CU2_MASK 0x40000000             /* Coprocessor 2 Usable (30) */
224
#define Status_CU1_MASK 0x20000000             /* Coprocessor 1 Usable (29) */
225
#define Status_CU0_MASK 0x10000000             /* Coprocessor 0 Usable (28) */
226
#define Status_RE_MASK 0x02000000     /* Reverse Endian (R3000A/R6000) (25) */
227
#define Status_DS_MASK 0x01ff0000              /* Diagnostic Status (24-16) */
228
#define Status_DS_BEV_MASK 0x00400000    /* Bootstrap Exception Vector (22) */
229
#define Status_DS_TS_MASK 0x00200000                   /* TLB Shutdown (21) */
230
#define Status_DS_PE_MASK 0x00100000             /* Cache Parity Error (20) */
231
#define Status_DS_CM_MASK 0x00080000                     /* Cache miss (19) */
232
#define Status_DS_PZ_MASK 0x00040000    /* Cache parity forced to zero (18) */
233
#define Status_DS_SwC_MASK 0x00020000      /* Data/Inst cache switched (17) */
234
#define Status_DS_IsC_MASK 0x00010000                /* Cache isolated (16) */
235
#define Status_IM_MASK 0x0000ff00                  /* Interrupt Mask (15-8) */
236
#define Status_IM_Ext_MASK 0x0000fc00 /* Extrn. (HW) Interrupt Mask (15-10) */
237
#define Status_IM_SW_MASK 0x00000300       /* Software Interrupt Mask (9-8) */
238
#define Status_KU_IE_MASK 0x0000003f /* Kernel/User & Int Enable bits (5-0) */
239
#define Status_KUo_MASK 0x00000020            /* Old Kernel/User status (5) */
240
#define Status_IEo_MASK 0x00000010       /* Old Interrupt Enable status (4) */
241
#define Status_KUp_MASK 0x00000008       /* Previous Kernel/User status (3) */
242
#define Status_IEp_MASK 0x00000004  /* Previous Interrupt Enable status (2) */
243
#define Status_KUc_MASK 0x00000002        /* Current Kernel/User status (1) */
244
#define Status_IEc_MASK 0x00000001   /* Current Interrupt Enable status (0) */
245
#define Status_MASK 0xf27fff3f
246
 
247
/* (13) Cause fields */
248
#define Cause_BD_MASK 0x80000000                       /* Branch Delay (31) */
249
#define Cause_CE_MASK 0x30000000               /* Coprocessor Error (29-28) */
250
#define Cause_IP_MASK 0x0000ff00                /* Interrupt Pending (15-8) */
251
#define Cause_IP_Ext_MASK 0x0000fc00  /* External (HW) ints IP(7-2) (15-10) */
252
#define Cause_IP_SW_MASK 0x00000300          /* Software ints IP(1-0) (9-8) */
253
#define Cause_ExcCode_MASK 0x0000007c               /* Exception Code (6-2) */
254
#define Cause_MASK 0xb000ff7c
255
 
256
/* (14) EPC has only one field */
257
#define EPC_MASK 0xffffffff
258
 
259
/* (15) PRId fields */
260
#define PRId_Imp_MASK 0x0000ff00                   /* Implementation (15-8) */
261
#define PRId_Rev_MASK 0x000000ff                          /* Revision (7-0) */
262
#define PRId_MASK 0x0000ffff
263
 
264
/* (16) Config is only on the R4k */
265
#define Config_MASK 0x00000000
266
 
267
/* (17) LLAddr is only on the R4k */
268
#define LLAddr_MASK 0x00000000
269
 
270
/* (18) WatchLo is only on the R4k */
271
#define WatchLo_MASK 0x00000000
272
 
273
/* (19) WatchHi is only on the R4k */
274
#define WatchHi_MASK 0x00000000
275
 
276
/* (20-25) reserved */
277
 
278
/* (26) ECC is only on the R4k */
279
#define ECC_MASK 0x00000000
280
 
281
/* (27) CacheErr is only on the R4k */
282
#define CacheErr_MASK 0x00000000
283
 
284
/* (28) TagLo is only on the R4k */
285
#define TagLo_MASK 0x00000000
286
 
287
/* (29) TagHi is only on the R4k */
288
#define TagHi_MASK 0x00000000
289
 
290
/* (30) ErrorEPC is only on the R4k */
291
#define ErrorEPC_MASK 0x00000000
292
 
293
/* (31) reserved */
294
 
295
//------------------------------------------------------------------------------ tlbentry.h
296
 
297
class TLBEntry {
298
public:
299
    uint32 entryHi;
300
    uint32 entryLo;
301
    TLBEntry () {
302
    }
303
    uint32 vpn() const { return (entryHi & EntryHi_VPN_MASK); }
304
    uint16 asid() const { return (entryHi & EntryHi_ASID_MASK); }
305
    uint32 pfn() const { return (entryLo & EntryLo_PFN_MASK); }
306
    bool noncacheable() const { return (entryLo & EntryLo_N_MASK); }
307
    bool dirty() const { return (entryLo & EntryLo_D_MASK); }
308
    bool valid() const { return (entryLo & EntryLo_V_MASK); }
309
    bool global() const { return (entryLo & EntryLo_G_MASK); }
310
};
311
 
312
//------------------------------------------------------------------------------ cpzero.h
313
 
314
class CPU;
315
 
316
#define TLB_ENTRIES 64
317
 
318
class CPZero
319
{
320
    TLBEntry tlb[TLB_ENTRIES];
321
    uint32 reg[32];
322
    CPU *cpu;
323
 
324
    // Return TRUE if interrupts are enabled, FALSE otherwise.
325
    bool interrupts_enabled(void) const;
326
 
327
    // Return TRUE if the cpu is running in kernel mode, FALSE otherwise.
328
    bool kernel_mode(void) const;
329
 
330
    // Return the currently pending interrupts.
331
    uint32 getIP(void);
332
 
333
    void mfc0_emulate(uint32 instr, uint32 pc);
334
    void mtc0_emulate(uint32 instr, uint32 pc);
335
    void bc0x_emulate(uint32 instr, uint32 pc);
336
    void tlbr_emulate(uint32 instr, uint32 pc);
337
    void tlbwi_emulate(uint32 instr, uint32 pc);
338
    void tlbwr_emulate(uint32 instr, uint32 pc);
339
    void tlbp_emulate(uint32 instr, uint32 pc);
340
    void rfe_emulate(uint32 instr, uint32 pc);
341
    void load_addr_trans_excp_info(uint32 va, uint32 vpn, TLBEntry *match);
342
    int find_matching_tlb_entry(uint32 vpn, uint32 asid);
343
    uint32 tlb_translate(uint32 seg, uint32 vaddr, int mode, bool *cacheable);
344
 
345
public:
346
    bool tlb_miss_user;
347
 
348
    // Write TLB entry number INDEX with the contents of the EntryHi
349
    // and EntryLo registers.
350
    void tlb_write(unsigned index);
351
 
352
    // Return the contents of the readable bits of register REG.
353
    uint32 read_reg(const uint16 regno);
354
 
355
    // Change the contents of the writable bits of register REG to NEW_DATA.
356
    void write_reg(const uint16 regno, const uint32 new_data);
357
 
358
    /* Convention says that CP0's condition is TRUE if the memory
359
       write-back buffer is empty. Because memory writes are fast as far
360
       as the emulation is concerned, the write buffer is always empty
361
       for CP0. */
362
    bool cpCond() const { return true; }
363
 
364
    CPZero(CPU *m);
365
    void reset(void);
366
 
367
    //initialize from shared memory
368
    void initialize();
369
    //report to shared memory
370
    void report();
371
 
372
    /* Request to translate virtual address VADDR, while the processor is
373
       in mode MODE to a physical address. CLIENT is the entity that will
374
       recieve any interrupts generated by the attempted translation. On
375
       return CACHEABLE will be set to TRUE if the returned address is
376
       cacheable, it will be set to FALSE otherwise. Returns the physical
377
       address corresponding to VADDR if such a translation is possible,
378
       otherwise an interrupt is raised with CLIENT and the return value
379
       is undefined. */
380
    uint32 address_trans(uint32 vaddr, int mode, bool *cacheable, bool *cache_isolated);
381
 
382
    void enter_exception(uint32 pc, uint32 excCode, uint32 ce, bool dly);
383
    bool use_boot_excp_address(void);
384
    bool caches_isolated(void);
385
 
386
    /* Return TRUE if the instruction and data caches are swapped,
387
       FALSE otherwise. */
388
    bool caches_swapped(void);
389
 
390
    bool cop_usable (int coprocno);
391
    void cpzero_emulate(uint32 instr, uint32 pc);
392
 
393
    /* Change the CP0 random register after an instruction step. */
394
    void adjust_random(void);
395
 
396
    /* Return TRUE if there is an interrupt which should be handled
397
       at the next available opportunity, FALSE otherwise. */
398
    bool interrupt_pending(void);
399
};
400
 
401
//------------------------------------------------------------------------------ cpu.h
402
 
403
/* states of the delay-slot state machine -- see CPU::step() */
404
static const int NORMAL = 0, DELAYING = 1, DELAYSLOT = 2;
405
 
406
/* Exception priority information -- see exception_priority(). */
407
struct excPriority {
408
    int priority;
409
    int excCode;
410
    int mode;
411
};
412
 
413
class CPU {
414
 
415
    // Important registers:
416
    uint32 pc;      // Program counter
417
    uint32 reg[32]; // General-purpose registers
418
    uint32 instr;   // The current instruction
419
    uint32 hi, lo;  // Division and multiplication results
420
 
421
    // Exception bookkeeping data.
422
    uint32 last_epc;
423
    int last_prio;
424
    uint32 next_epc;
425
 
426
    // Other components of the VMIPS machine.
427
    CPZero *cpzero;
428
 
429
    // Delay slot handling.
430
    int delay_state;
431
    uint32 delay_pc;
432
 
433
    // Miscellaneous shared code. 
434
    void control_transfer(uint32 new_pc);
435
    void jump(uint32 instr, uint32 pc);
436
    uint32 calc_jump_target(uint32 instr, uint32 pc);
437
    uint32 calc_branch_target(uint32 instr, uint32 pc);
438
    void mult64(uint32 *hi, uint32 *lo, uint32 n, uint32 m);
439
    void mult64s(uint32 *hi, uint32 *lo, int32 n, int32 m);
440
    void cop_unimpl (int coprocno, uint32 instr, uint32 pc);
441
 
442
    // Unaligned load/store support.
443
    uint32 lwr(uint32 regval, uint32 memval, uint8 offset);
444
    uint32 lwl(uint32 regval, uint32 memval, uint8 offset);
445
    uint32 swl(uint32 regval, uint32 memval, uint8 offset);
446
    uint32 swr(uint32 regval, uint32 memval, uint8 offset);
447
 
448
    // Emulation of specific instructions.
449
    void funct_emulate(uint32 instr, uint32 pc);
450
    void regimm_emulate(uint32 instr, uint32 pc);
451
    void j_emulate(uint32 instr, uint32 pc);
452
    void jal_emulate(uint32 instr, uint32 pc);
453
    void beq_emulate(uint32 instr, uint32 pc);
454
    void bne_emulate(uint32 instr, uint32 pc);
455
    void blez_emulate(uint32 instr, uint32 pc);
456
    void bgtz_emulate(uint32 instr, uint32 pc);
457
    void addi_emulate(uint32 instr, uint32 pc);
458
    void addiu_emulate(uint32 instr, uint32 pc);
459
    void slti_emulate(uint32 instr, uint32 pc);
460
    void sltiu_emulate(uint32 instr, uint32 pc);
461
    void andi_emulate(uint32 instr, uint32 pc);
462
    void ori_emulate(uint32 instr, uint32 pc);
463
    void xori_emulate(uint32 instr, uint32 pc);
464
    void lui_emulate(uint32 instr, uint32 pc);
465
    void cpzero_emulate(uint32 instr, uint32 pc);
466
    void cpone_emulate(uint32 instr, uint32 pc);
467
    void cptwo_emulate(uint32 instr, uint32 pc);
468
    void cpthree_emulate(uint32 instr, uint32 pc);
469
    void lb_emulate(uint32 instr, uint32 pc);
470
    void lh_emulate(uint32 instr, uint32 pc);
471
    void lwl_emulate(uint32 instr, uint32 pc);
472
    void lw_emulate(uint32 instr, uint32 pc);
473
    void lbu_emulate(uint32 instr, uint32 pc);
474
    void lhu_emulate(uint32 instr, uint32 pc);
475
    void lwr_emulate(uint32 instr, uint32 pc);
476
    void sb_emulate(uint32 instr, uint32 pc);
477
    void sh_emulate(uint32 instr, uint32 pc);
478
    void swl_emulate(uint32 instr, uint32 pc);
479
    void sw_emulate(uint32 instr, uint32 pc);
480
    void swr_emulate(uint32 instr, uint32 pc);
481
    void lwc1_emulate(uint32 instr, uint32 pc);
482
    void lwc2_emulate(uint32 instr, uint32 pc);
483
    void lwc3_emulate(uint32 instr, uint32 pc);
484
    void swc1_emulate(uint32 instr, uint32 pc);
485
    void swc2_emulate(uint32 instr, uint32 pc);
486
    void swc3_emulate(uint32 instr, uint32 pc);
487
    void sll_emulate(uint32 instr, uint32 pc);
488
    void srl_emulate(uint32 instr, uint32 pc);
489
    void sra_emulate(uint32 instr, uint32 pc);
490
    void sllv_emulate(uint32 instr, uint32 pc);
491
    void srlv_emulate(uint32 instr, uint32 pc);
492
    void srav_emulate(uint32 instr, uint32 pc);
493
    void jr_emulate(uint32 instr, uint32 pc);
494
    void jalr_emulate(uint32 instr, uint32 pc);
495
    void syscall_emulate(uint32 instr, uint32 pc);
496
    void break_emulate(uint32 instr, uint32 pc);
497
    void mfhi_emulate(uint32 instr, uint32 pc);
498
    void mthi_emulate(uint32 instr, uint32 pc);
499
    void mflo_emulate(uint32 instr, uint32 pc);
500
    void mtlo_emulate(uint32 instr, uint32 pc);
501
    void mult_emulate(uint32 instr, uint32 pc);
502
    void multu_emulate(uint32 instr, uint32 pc);
503
    void div_emulate(uint32 instr, uint32 pc);
504
    void divu_emulate(uint32 instr, uint32 pc);
505
    void add_emulate(uint32 instr, uint32 pc);
506
    void addu_emulate(uint32 instr, uint32 pc);
507
    void sub_emulate(uint32 instr, uint32 pc);
508
    void subu_emulate(uint32 instr, uint32 pc);
509
    void and_emulate(uint32 instr, uint32 pc);
510
    void or_emulate(uint32 instr, uint32 pc);
511
    void xor_emulate(uint32 instr, uint32 pc);
512
    void nor_emulate(uint32 instr, uint32 pc);
513
    void slt_emulate(uint32 instr, uint32 pc);
514
    void sltu_emulate(uint32 instr, uint32 pc);
515
    void bltz_emulate(uint32 instr, uint32 pc);
516
    void bgez_emulate(uint32 instr, uint32 pc);
517
    void bltzal_emulate(uint32 instr, uint32 pc);
518
    void bgezal_emulate(uint32 instr, uint32 pc);
519
    void RI_emulate(uint32 instr, uint32 pc);
520
 
521
    // Exception prioritization.
522
    int exception_priority(uint16 excCode, int mode) const;
523
 
524
    //
525
    bool exception_pending;
526
 
527
public:
528
    // Instruction decoding.
529
    static uint16 opcode(const uint32 i) { return (i >> 26) & 0x03f; }
530
    static uint16 rs(const uint32 i) { return (i >> 21) & 0x01f; }
531
    static uint16 rt(const uint32 i) { return (i >> 16) & 0x01f; }
532
    static uint16 rd(const uint32 i) { return (i >> 11) & 0x01f; }
533
    static uint16 immed(const uint32 i) { return i & 0x0ffff; }
534
    static short s_immed(const uint32 i) { return i & 0x0ffff; }
535
    static uint16 shamt(const uint32 i) { return (i >> 6) & 0x01f; }
536
    static uint16 funct(const uint32 i) { return i & 0x03f; }
537
    static uint32 jumptarg(const uint32 i) { return i & 0x03ffffff; }
538
 
539
    // Constructor & destructor.
540
    CPU ();
541
    virtual ~CPU ();
542
 
543
    // Register file accessors.
544
    uint32 get_reg (const unsigned regno) { return reg[regno]; }
545
    void put_reg (const unsigned regno, const uint32 new_data) {
546
        reg[regno] = new_data;
547
    }
548
    //initialize from shared memory
549
    void initialize();
550
    //report to shared memory
551
    void report();
552
    //
553
    uint32 get_delay_state() { return delay_state; }
554
 
555
    bool was_delayed_transfer;
556
    uint32 was_delayed_pc;
557
 
558
    // Control-flow methods.
559
    int step (bool debug=false);
560
    void reset ();
561
 
562
    // Methods which are only for use by the CPU and its coprocessors.
563
    void branch (uint32 instr, uint32 pc);
564
    void exception (uint16 excCode, int mode = ANY, int coprocno = -1);
565
};
566
 
567
#endif //__VMIPS_EMULATOR_H

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.