Ver Fonte

UserspaceEmulator: Make SBB actually respect the SoftCPU carry flag

We were forgetting to set the host CPU's carry flag before executing
the SBB instruction. This made the result a bit unpredictable. :^)
Andreas Kling há 5 anos atrás
pai
commit
6230c60296
1 ficheiros alterados com 15 adições e 2 exclusões
  1. 15 2
      DevTools/UserspaceEmulator/SoftCPU.cpp

+ 15 - 2
DevTools/UserspaceEmulator/SoftCPU.cpp

@@ -343,12 +343,17 @@ static T op_sub(SoftCPU& cpu, const T& dest, const T& src)
     return result;
 }
 
-template<typename T>
-static T op_sbb(SoftCPU& cpu, const T& dest, const T& src)
+template<typename T, bool cf>
+static T op_sbb_impl(SoftCPU& cpu, const T& dest, const T& src)
 {
     T result = 0;
     u32 new_flags = 0;
 
+    if constexpr (cf)
+        asm volatile("stc");
+    else
+        asm volatile("clc");
+
     if constexpr (sizeof(T) == 4) {
         asm volatile("sbbl %%ecx, %%eax\n"
                      : "=a"(result)
@@ -374,6 +379,14 @@ static T op_sbb(SoftCPU& cpu, const T& dest, const T& src)
     return result;
 }
 
+template<typename T>
+static T op_sbb(SoftCPU& cpu, T& dest, const T& src)
+{
+    if (cpu.cf())
+        return op_sbb_impl<T, true>(cpu, dest, src);
+    return op_sbb_impl<T, false>(cpu, dest, src);
+}
+
 template<typename T>
 static T op_add(SoftCPU& cpu, T& dest, const T& src)
 {