X86EmulatorPkg icon indicating copy to clipboard operation
X86EmulatorPkg copied to clipboard

Should qemu run with interrupt disabled?

Open pttuan opened this issue 7 years ago • 0 comments

Hi, I think we should use TPL_HIGH_LEVEL to prevent qemu code be interrupted by higher priority TPL. Here is the patch. What do you think?

index 21f1eeb..f5f018b 100644
--- a/X86EmulatorPkg/main.c
+++ b/X86EmulatorPkg/main.c
@@ -332,7 +332,7 @@ uint64_t run_x86_func(void *func, uint64_t *args)
 
         asm volatile ("mov %0, sp" : "=r"(sp));
         printf_verbose("XXX Entering x86 at %lx (sp=%lx)\n", env->eip, sp);
-        env->exec_tpl = gBS->RaiseTPL (TPL_NOTIFY);
+        env->exec_tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
         in_critical = 1;
         trapnr = cpu_x86_exec(env);
         in_critical = 0;
@@ -426,7 +426,9 @@ uint64_t run_x86_func(void *func, uint64_t *args)
 
     /* Restore old context */
     r = env->regs[R_EAX];
-    cpu_single_env = env = envs[nesting_level];
+    if (nesting_level >= 0) {
+        cpu_single_env = env = envs[nesting_level];
+    }
 
     return r;
 }

pttuan avatar May 17 '17 18:05 pttuan