Version 0.1.2
[seabios.git] / src / util.h
index d83820e4cf6fc860b9166b0e2fb01e3ebd568ac7..d33f2accb63881452a9aba06ca1f307bee28e905 100644 (file)
@@ -5,6 +5,7 @@
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
 #include "ioport.h" // outb
+#include "biosvar.h" // struct bregs
 
 static inline void irq_disable(void) {
         asm volatile("cli": : :"memory");
@@ -27,6 +28,11 @@ static inline void irq_restore(unsigned long flags)
     asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
 }
 
+static inline void nop(void)
+{
+    asm volatile("nop");
+}
+
 #define DEBUGF(fmt, args...)
 #define BX_PANIC(fmt, args...)
 #define BX_INFO(fmt, args...)
@@ -35,7 +41,7 @@ static inline void
 memset(void *s, int c, size_t n)
 {
     while (n)
-        ((char *)s)[n--] = c;
+        ((char *)s)[--n] = c;
 }
 
 static inline void
@@ -51,6 +57,37 @@ eoi_both_pics()
     eoi_master_pic();
 }
 
+static inline
+void call16(struct bregs *callregs)
+{
+    asm volatile(
+        "pushfl\n"   // Save flags
+        "pushal\n"   // Save registers
+        "calll __call16\n"
+        "popal\n"
+        "popfl\n"
+        : : "a" (callregs), "m" (*callregs));
+}
+
+// XXX - this is ugly.
+#ifdef MODE16
+#define call16_int(nr, callregs) do {           \
+        struct bregs *__br = (callregs);        \
+        extern void irq_trampoline_ ##nr ();    \
+        __br->cs = 0xf000;                      \
+        __br->ip = (u16)&irq_trampoline_ ##nr;  \
+        call16(__br);                           \
+    } while (0)
+#else
+#include "../out/rom16.offset.auto.h"
+#define call16_int(nr, callregs) do {           \
+        struct bregs *__br = (callregs);        \
+        __br->cs = 0xf000;                      \
+        __br->ip = OFFSET_irq_trampoline_ ##nr; \
+        call16(__br);                           \
+    } while (0)
+#endif
+
 // output.c
 void bprintf(u16 action, const char *fmt, ...)
     __attribute__ ((format (printf, 2, 3)));
@@ -62,7 +99,7 @@ void __debug_exit(const char *fname, struct bregs *regs);
 #define debug_exit(regs) \
     __debug_exit(__func__, regs)
 #define printf(fmt, args...)                     \
-    bprintf(0, fmt , ##args )
+    bprintf(1, fmt , ##args )
 
 // kbd.c
 void handle_15c2(struct bregs *regs);