[SeaBIOS] SeaBIOS not fully working when compiled on FreeBSD

Kevin O'Connor kevin at koconnor.net
Thu Apr 16 17:52:57 CEST 2015


On Thu, Apr 16, 2015 at 05:23:20PM +0200, Roger Pau Monné wrote:
> Hello,
> 
> El 16/04/15 a les 15.56, Kevin O'Connor ha escrit:
> > On Thu, Apr 16, 2015 at 01:46:41PM +0200, Roger Pau Monné wrote:
> >> I've tried this, the function is handle_15c0. This happens quite late 
> >> in the boot process, the FreeBSD code that triggers this issue is at:
> >>
> >> http://fxr.watson.org/fxr/source/dev/atkbdc/atkbd.c#L1163
> > 
> > Is it possible you are running into:
> > 
> > http://lists.nongnu.org/archive/html/qemu-devel/2013-03/msg01311.html
> 
> Might be... I'm not familiar with this code at all, but I will try to 
> see if I can figure out what's going on.
> 
> > If freebsd is using x86emu to interpret the bios, then I'm not
> > surprised it is having problems.  In a previous mail, you indicated a
> > freebsd compiled seabios caused crashes under Linux - can you confirm
> > it crashes on non-freebsd guests (ie, linux, windows, dos, etc)?
> 
> I've tried booting Ubuntu using the _broken_ SeaBIOS, and it seems to 
> work fine, I can see calls to handle_15c0 succeeding:
> 
> (d10) enter handle_15c0:
> (d10)    a=0000c000  b=00000000  c=00000000  d=00000000 ds=1000 es=1000 ss=df80
> (d10)   si=00000000 di=00000000 bp=00000000 sp=0000f9f6 cs=1000 ip=02fd  f=0003
> 
> So it seems like the problem is only triggered when booting FreeBSD 
> guests with this specific SeaBIOS build.

Seems like the same problem.  You wont be able to set a gdb breakpoint
for the freebsd call because freebsd isn't calling the bios - it's
attempting to interpret the bios code.

Does the seabios patch below fix the problem for you?

-Kevin


--- a/src/system.c
+++ b/src/system.c
@@ -334,6 +334,7 @@ handle_15XX(struct bregs *regs)
 void VISIBLE16
 handle_15(struct bregs *regs)
 {
+    trap_x86emu();
     debug_enter(regs, DEBUG_HDL_15);
     switch (regs->ah) {
     case 0x24: handle_1524(regs); break;
diff --git a/src/x86.h b/src/x86.h
index 14ebb7d..865dcbe 100644
--- a/src/x86.h
+++ b/src/x86.h
@@ -75,6 +75,18 @@ static inline void __cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
         : "0" (index));
 }
 
+static inline void trap_x86emu(void) {
+    // Force a fault if running on x86emu (enterl insn not working properly)
+    asm volatile (
+        "movl %%esp, %%ecx\n"
+        "enterl $0, $0\n"
+        "popl %%ebp\n"
+        "cmpl %%ecx, %%esp\n"
+        "je 1f\n"
+        "hlt\n"
+        "1:" : : : "ecx", "cc");
+}
+
 static inline u32 getcr0(void) {
     u32 cr0;
     asm("movl %%cr0, %0" : "=r"(cr0));



More information about the SeaBIOS mailing list