Skip to content

Commit 0c6f7c6

Browse files
committed
Implement mips floating point related registers
1 parent f2e80ff commit 0c6f7c6

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

include/unicorn/mips.h

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ typedef enum UC_MIPS_REG {
220220
UC_MIPS_REG_CP0_USERLOCAL,
221221
UC_MIPS_REG_CP0_STATUS,
222222

223+
// FCR(s) Ref: https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00083-2B-MIPS64INT-AFP-06.01.pdf
224+
UC_MIPS_REG_FIR,
225+
UC_MIPS_REG_FCSR,
226+
223227
UC_MIPS_REG_ENDING, // <-- mark the end of the list or registers
224228

225229
// alias registers

qemu/target/mips/unicorn.c

+94
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,49 @@ uc_err reg_read(void *_env, int mode, unsigned int regid, void *value,
103103
CHECK_REG_TYPE(mipsreg_t);
104104
*(mipsreg_t *)value = env->active_tc.CP0_UserLocal;
105105
break;
106+
case UC_MIPS_REG_F0:
107+
case UC_MIPS_REG_F1:
108+
case UC_MIPS_REG_F2:
109+
case UC_MIPS_REG_F3:
110+
case UC_MIPS_REG_F4:
111+
case UC_MIPS_REG_F5:
112+
case UC_MIPS_REG_F6:
113+
case UC_MIPS_REG_F7:
114+
case UC_MIPS_REG_F8:
115+
case UC_MIPS_REG_F9:
116+
case UC_MIPS_REG_F10:
117+
case UC_MIPS_REG_F11:
118+
case UC_MIPS_REG_F12:
119+
case UC_MIPS_REG_F13:
120+
case UC_MIPS_REG_F14:
121+
case UC_MIPS_REG_F15:
122+
case UC_MIPS_REG_F16:
123+
case UC_MIPS_REG_F17:
124+
case UC_MIPS_REG_F18:
125+
case UC_MIPS_REG_F19:
126+
case UC_MIPS_REG_F20:
127+
case UC_MIPS_REG_F21:
128+
case UC_MIPS_REG_F22:
129+
case UC_MIPS_REG_F23:
130+
case UC_MIPS_REG_F24:
131+
case UC_MIPS_REG_F25:
132+
case UC_MIPS_REG_F26:
133+
case UC_MIPS_REG_F27:
134+
case UC_MIPS_REG_F28:
135+
case UC_MIPS_REG_F29:
136+
case UC_MIPS_REG_F30:
137+
case UC_MIPS_REG_F31:
138+
CHECK_REG_TYPE(uint64_t);
139+
*(uint64_t *)value = env->active_fpu.fpr[regid - UC_MIPS_REG_F0].d;
140+
break;
141+
case UC_MIPS_REG_FIR:
142+
CHECK_REG_TYPE(uint32_t);
143+
*(uint32_t *)value = env->active_fpu.fcr0;
144+
break;
145+
case UC_MIPS_REG_FCSR:
146+
CHECK_REG_TYPE(uint32_t);
147+
*(uint32_t *)value = env->active_fpu.fcr31;
148+
break;
106149
}
107150
}
108151

@@ -158,6 +201,57 @@ uc_err reg_write(void *_env, int mode, unsigned int regid, const void *value,
158201
CHECK_REG_TYPE(mipsreg_t);
159202
env->active_tc.CP0_UserLocal = *(mipsreg_t *)value;
160203
break;
204+
case UC_MIPS_REG_F0:
205+
case UC_MIPS_REG_F1:
206+
case UC_MIPS_REG_F2:
207+
case UC_MIPS_REG_F3:
208+
case UC_MIPS_REG_F4:
209+
case UC_MIPS_REG_F5:
210+
case UC_MIPS_REG_F6:
211+
case UC_MIPS_REG_F7:
212+
case UC_MIPS_REG_F8:
213+
case UC_MIPS_REG_F9:
214+
case UC_MIPS_REG_F10:
215+
case UC_MIPS_REG_F11:
216+
case UC_MIPS_REG_F12:
217+
case UC_MIPS_REG_F13:
218+
case UC_MIPS_REG_F14:
219+
case UC_MIPS_REG_F15:
220+
case UC_MIPS_REG_F16:
221+
case UC_MIPS_REG_F17:
222+
case UC_MIPS_REG_F18:
223+
case UC_MIPS_REG_F19:
224+
case UC_MIPS_REG_F20:
225+
case UC_MIPS_REG_F21:
226+
case UC_MIPS_REG_F22:
227+
case UC_MIPS_REG_F23:
228+
case UC_MIPS_REG_F24:
229+
case UC_MIPS_REG_F25:
230+
case UC_MIPS_REG_F26:
231+
case UC_MIPS_REG_F27:
232+
case UC_MIPS_REG_F28:
233+
case UC_MIPS_REG_F29:
234+
case UC_MIPS_REG_F30:
235+
case UC_MIPS_REG_F31:
236+
CHECK_REG_TYPE(uint64_t);
237+
env->active_fpu.fpr[regid - UC_MIPS_REG_F0].d = *(uint64_t*)value;
238+
break;
239+
case UC_MIPS_REG_FCSR: {
240+
CHECK_REG_TYPE(uint32_t);
241+
uint32_t arg1 = *(uint32_t *)value;
242+
uint32_t original = env->active_fpu.fcr31;
243+
env->active_fpu.fcr31 = (arg1 & env->active_fpu.fcr31_rw_bitmask) |
244+
(env->active_fpu.fcr31 & ~(env->active_fpu.fcr31_rw_bitmask));
245+
if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) &
246+
GET_FP_CAUSE(env->active_fpu.fcr31)) {
247+
env->active_fpu.fcr31 = original;
248+
ret = UC_ERR_EXCEPTION;
249+
} else {
250+
restore_fp_status(env);
251+
set_float_exception_flags(0, &env->active_fpu.fp_status);
252+
}
253+
break;
254+
}
161255
}
162256
}
163257

0 commit comments

Comments
 (0)