[go: up one dir, main page]

Menu

[904618]: / src / mips.h  Maximize  Restore  History

Download this file

215 lines (183 with data), 5.9 kB

  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
// -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
// ----------------------------------------------------------------------------
// :oCCCCOCoc.
// .cCO8OOOOOOOOO8Oo:
// .oOO8OOOOOOOOOOOOOOOCc
// cO8888: .:oOOOOC. TM
// :888888: :CCCc .oOOOOC. ### ### #########
// C888888: .ooo: .C######## ##### ##### ###### ###### ##########
// O888888: .oO### ### ##### ##### ######## ######## #### ###
// C888888: :8O. .C########## ### #### ### ## ## ## ## #### ###
// :8@@@@8: :888c o### ### #### ### ######## ######## ##########
// :8@@@@C C@@@@ oo######## ### ## ### ###### ###### #########
// cO@@@@@@@@@@@@@@@@@Oc0
// :oO8@@@@@@@@@@Oo.
// .oCOOOOOCc. http://remood.org/
// ----------------------------------------------------------------------------
// Copyright (C) 2013-2013 GhostlyDeath <ghostlydeath@remood.org>
// <ghostlydeath@gmail.com>
// ----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// ----------------------------------------------------------------------------
// DESCRIPTION: MIPS Emulator/Simulator
#ifndef __MIPS_H__
#define __MIPS_H__
/*****************************************************************************/
/***************
*** INCLUDES ***
***************/
#include "doomtype.h"
/****************
*** CONSTANTS ***
****************/
/* MIPS_Regs_t -- MIPS Registers */
typedef enum MIPS_Regs_e
{
/* Numeric Registers */
MIPS_R0,
MIPS_R1,
MIPS_R2,
MIPS_R3,
MIPS_R4,
MIPS_R5,
MIPS_R6,
MIPS_R7,
MIPS_R8,
MIPS_R9,
MIPS_R10,
MIPS_R11,
MIPS_R12,
MIPS_R13,
MIPS_R14,
MIPS_R15,
MIPS_R16,
MIPS_R17,
MIPS_R18,
MIPS_R19,
MIPS_R20,
MIPS_R21,
MIPS_R22,
MIPS_R23,
MIPS_R24,
MIPS_R25,
MIPS_R26,
MIPS_R27,
MIPS_R28,
MIPS_R29,
MIPS_R30,
MIPS_R31,
/* Aliased */
MIPS_ZERO = MIPS_R0,
MIPS_AT,
MIPS_V0,
MIPS_V1,
MIPS_A0,
MIPS_A1,
MIPS_A2,
MIPS_A3,
MIPS_T0,
MIPS_T1,
MIPS_T2,
MIPS_T3,
MIPS_T4,
MIPS_T5,
MIPS_T6,
MIPS_T7,
MIPS_S0,
MIPS_S1,
MIPS_S2,
MIPS_S3,
MIPS_S4,
MIPS_S5,
MIPS_S6,
MIPS_S7,
MIPS_T8,
MIPS_T9,
MIPS_K0,
MIPS_K1,
MIPS_GP,
MIPS_SP,
MIPS_FP,
MIPS_RA,
/* Other aliases */
MIPS_S8 = MIPS_FP,
} MIPS_Regs_t;
/* MIPS_MemFlag_t -- Flags for Memory */
typedef enum MIPS_MemFlag_e
{
MIPS_MFR = UINT16_C(0x0001),
MIPS_MFW = UINT16_C(0x0002),
MIPS_MFX = UINT16_C(0x0004),
} MIPS_MemFlag_t;
/*****************
*** STRUCTURES ***
*****************/
/* MIPS_CPU_t -- MIPS CPU Status */
typedef struct MIPS_CPU_s
{
uint32_t r[32]; // MIPS Registers
uint32_t pc; // PC register
uint32_t hi; // HI register
uint32_t lo; // LO register
uint32_t jds; // Delay Slot (Jump)
uint32_t jdsactive; // Delay Slot Active (Jump)
int32_t ldsat; // Load Delay Slot At
uint32_t lds[2]; // Load Delay Slot
uint32_t ldsval[2]; // Load Delay Slot value
uint32_t ldsactive[2]; // Load Delay slot active
} MIPS_CPU_t;
typedef struct MIPS_VM_s MIPS_VM_t;
typedef struct MIPS_Map_s MIPS_Map_t;
// NOTE THAT THE MAP FUNCTION RETURNS NATIVE ENDIAN
typedef uint32_t (*MIPS_VMMapReadFunc_t)(MIPS_VM_t* const a_VM, MIPS_Map_t* const a_Map, const uint_fast32_t a_BaseAddr);
typedef void (*MIPS_VMMapWriteFunc_t)(MIPS_VM_t* const a_VM, MIPS_Map_t* const a_Map, const uint_fast32_t a_BaseAddr, const uint32_t a_Val);
// SYSTEM CALL FUNCTION
typedef bool_t (*MIPS_VMSysCallFunc_t)(MIPS_VM_t* const a_VM, void* const a_Data);
/* MIPS_Map_t -- MIPS Memory Mapping */
struct MIPS_Map_s
{
uint_fast32_t Len; // Length of mapping
uint_fast32_t VMOff; // VM Offset
uint_fast32_t Flags; // Flags
MIPS_VMMapReadFunc_t ReadFunc; // Function to call
MIPS_VMMapWriteFunc_t WriteFunc; // Write Function
void* RealMem; // Real Memory
};
/* MIPS_VM_t -- MIPS Virtual Machine */
struct MIPS_VM_s
{
MIPS_CPU_t CPU; // CPU Status
// Real buffer memory maps
MIPS_Map_t* Maps; // Memory maps
int_fast32_t NumMaps; // Number of memory maps
// System Call Handler
MIPS_VMSysCallFunc_t SysCall; // System calls handler
void* DataP; // Data Pointer
};
/****************
*** FUNCTIONS ***
****************/
bool_t MIPS_VMAddMap(MIPS_VM_t* const a_VM, void* const a_Real, const uint_fast32_t a_Fake, const uint_fast32_t a_Len, const uint_fast32_t a_Flags);
bool_t MIPS_VMAddMapFunc(MIPS_VM_t* const a_VM, MIPS_VMMapReadFunc_t a_ReadFunc, MIPS_VMMapWriteFunc_t a_WriteFunc, const uint_fast32_t a_Fake, const uint_fast32_t a_Len, const uint_fast32_t a_Flags);
uint32_t MIPS_ReadMemX(MIPS_VM_t* const a_VM, const uint_fast32_t a_Addr, const uint_fast32_t a_Width);
void MIPS_WriteMemX(MIPS_VM_t* const a_VM, const uint_fast32_t a_Addr, const uint_fast32_t a_Width, const uint32_t a_Val);
bool_t MIPS_VMRunX(MIPS_VM_t* const a_VM, const uint_fast32_t a_Count
#if defined(_DEBUG)
, const bool_t a_PrintOp
#endif
);
#if defined(_DEBUG)
#define MIPS_VMRun(v,c,d) MIPS_VMRunX(v,c,d)
#else
#define MIPS_VMRun(v,c,d) MIPS_VMRunX(v,c)
#endif
/*****************************************************************************/
#endif /* __MIPS_H__ */