|
From: Greg P. <gp...@us...> - 2006-03-10 03:36:48
|
Syscalls on Mac OS X for Intel return success or failure in the carry bit. This means do_syscall_for_client() needs to store the real carry flag into the VEX state. I see VEX has a LibVEX_GuestX86_get_eflags() function to read the carry bit and other flags, but I don't see a way to write it. The actual representation of the eflags makes my head spin. -- Greg Parker gp...@us... |
|
From: Julian S. <js...@ac...> - 2006-03-18 19:11:05
|
> I see VEX has a LibVEX_GuestX86_get_eflags() function to read > the carry bit and other flags, but I don't see a way to write > it. The actual representation of the eflags makes my head spin. Unfortunately a head-spinning arrangement is needed to get reasonable simulation efficiency given the fact that the flags are set after practically all ALU integer instructions except plain loads and stores. Anyway: do you really need to write all of %eflags, or would a simple function to set/clear the carry flag, and leave the others unchanged, suffice? J |
|
From: Greg P. <gp...@us...> - 2006-03-18 21:06:35
|
Julian Seward writes: > > I see VEX has a LibVEX_GuestX86_get_eflags() function to read > > the carry bit and other flags, but I don't see a way to write > > it. The actual representation of the eflags makes my head spin. > > Unfortunately a head-spinning arrangement is needed to get reasonable > simulation efficiency given the fact that the flags are set after > practically all ALU integer instructions except plain loads and > stores. > > Anyway: do you really need to write all of %eflags, or would a > simple function to set/clear the carry flag, and leave the others > unchanged, suffice? For syscalls, I think all that's needed is to set/clear the carry flag. For Mach's thread_set_state(), I'd need to set all of %eflags, but that's a much lower priority feature. -- Greg Parker gp...@us... |
|
From: Julian S. <js...@ac...> - 2006-03-18 23:34:07
|
> For syscalls, I think all that's needed is to set/clear the carry flag.
Try the following and let me know if it works or not. I haven't
tested it but it looks pretty straightforward.
J
Index: priv/guest-x86/ghelpers.c
===================================================================
--- priv/guest-x86/ghelpers.c (revision 1598)
+++ priv/guest-x86/ghelpers.c (working copy)
@@ -743,7 +743,29 @@
return eflags;
}
+/* VISIBLE TO LIBVEX CLIENT */
+void
+LibVEX_GuestX86_put_eflag_c ( UInt new_carry_flag,
+ /*MOD*/VexGuestX86State* vex_state )
+{
+ UInt oszacp = x86g_calculate_eflags_all_WRK(
+ vex_state->guest_CC_OP,
+ vex_state->guest_CC_DEP1,
+ vex_state->guest_CC_DEP2,
+ vex_state->guest_CC_NDEP
+ );
+ if (new_carry_flag & 1) {
+ oszacp |= X86G_CC_MASK_C;
+ } else {
+ oszacp &= ~X86G_CC_MASK_C;
+ }
+ vex_state->guest_CC_OP = X86G_CC_OP_COPY;
+ vex_state->guest_CC_DEP1 = oszacp;
+ vex_state->guest_CC_DEP2 = 0;
+ vex_state->guest_CC_NDEP = 0;
+}
+
/*---------------------------------------------------------------*/
/*--- %eflags translation-time function specialisers. ---*/
/*--- These help iropt specialise calls the above run-time ---*/
Index: pub/libvex_guest_x86.h
===================================================================
--- pub/libvex_guest_x86.h (revision 1598)
+++ pub/libvex_guest_x86.h (working copy)
@@ -279,8 +279,13 @@
extern
UInt LibVEX_GuestX86_get_eflags ( /*IN*/VexGuestX86State* vex_state );
+/* Set the carry flag in the given state to 'new_carry_flag', which
+ should be zero or one. */
+extern
+void
+LibVEX_GuestX86_put_eflag_c ( UInt new_carry_flag,
+ /*MOD*/VexGuestX86State* vex_state );
-
#endif /* ndef __LIBVEX_PUB_GUEST_X86_H */
/*---------------------------------------------------------------*/
|