Basic support for PCI BIOS.
[seabios.git] / src / util.h
index b858e8cb43fb07b2455c6a6186a88e4b9e54274f..d553b3ad6ca79fcf751416c77eb108d6d499bc60 100644 (file)
@@ -37,8 +37,19 @@ static inline void nop(void)
     asm volatile("nop");
 }
 
-#define DEBUGF(fmt, args...) bprintf(0, fmt , ##args)
-#define BX_PANIC(fmt, args...) bprintf(0, fmt , ##args)
+static inline void hlt(void)
+{
+    asm volatile("hlt");
+}
+
+// XXX - move this to a c file and use PANIC PORT.
+#define BX_PANIC(fmt, args...) do { \
+        bprintf(0, fmt , ##args);   \
+        irq_disable();              \
+        for (;;)                    \
+            hlt();                  \
+    } while (0)
+
 #define BX_INFO(fmt, args...) bprintf(0, fmt , ##args)
 
 static inline void
@@ -48,6 +59,18 @@ memset(void *s, int c, size_t n)
         ((char *)s)[--n] = c;
 }
 
+static inline void *
+memcpy(void *d1, const void *s1, size_t len)
+{
+    u8 *d = d1;
+    const u8 *s = s1;
+
+    while (len--) {
+        *d++ = *s++;
+    }
+    return d1;
+}
+
 static inline void
 eoi_master_pic()
 {
@@ -61,22 +84,20 @@ eoi_both_pics()
     eoi_master_pic();
 }
 
+// Call a function with a specified register state.  Note that on
+// return, the interrupt enable/disable flag may be altered.
 static inline
 void call16(struct bregs *callregs)
 {
     asm volatile(
-        "pushl %%ebp\n" // Save state
-        "pushfl\n"
 #ifdef MODE16
         "calll __call16\n"
 #else
         "calll __call16_from32\n"
 #endif
-        "popfl\n"       // Restore state
-        "popl %%ebp\n"
         : "+a" (callregs), "+m" (*callregs)
         :
-        : "ebx", "ecx", "edx", "esi", "edi");
+        : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
 }
 
 static inline
@@ -102,30 +123,59 @@ void __call16_int(struct bregs *callregs, u16 offset)
 void bprintf(u16 action, const char *fmt, ...)
     __attribute__ ((format (printf, 2, 3)));
 void __debug_enter(const char *fname, struct bregs *regs);
-void __debug_exit(const char *fname, struct bregs *regs);
+void __debug_fail(const char *fname, struct bregs *regs);
 void __debug_stub(const char *fname, struct bregs *regs);
+void __debug_isr(const char *fname);
 #define debug_enter(regs) \
     __debug_enter(__func__, regs)
-#define debug_exit(regs) \
-    __debug_exit(__func__, regs)
 #define debug_stub(regs) \
     __debug_stub(__func__, regs)
+#define debug_isr(regs) \
+    __debug_isr(__func__)
 #define printf(fmt, args...)                     \
     bprintf(1, fmt , ##args )
 
+// Frequently used return codes
+#define RET_EUNSUPPORTED 0x86
+static inline void
+set_success(struct bregs *regs)
+{
+    set_cf(regs, 0);
+}
+
+static inline void
+set_code_success(struct bregs *regs)
+{
+    regs->ah = 0;
+    set_cf(regs, 0);
+}
+
+#define set_fail(regs) do {                     \
+        __debug_fail(__func__, (regs));         \
+        set_cf((regs), 1);                      \
+    } while (0)
+
+#define set_code_fail(regs, code) do {          \
+        set_fail(regs);                         \
+        (regs)->ah = (code);                    \
+    } while (0)
+
 // kbd.c
 void handle_15c2(struct bregs *regs);
 
 // clock.c
 void handle_1583(struct bregs *regs);
 
-// Frequent bios return helper
-#define RET_EUNSUPPORTED 0x86
-static inline void
-handle_ret(struct bregs *regs, u8 code)
-{
-    regs->ah = code;
-    set_cf(regs, code);
-}
+// apm.c
+void VISIBLE16 handle_1553(struct bregs *regs);
+
+// pcibios.c
+void handle_1ab1(struct bregs *regs);
+
+// util.c
+void usleep(u32 count);
+
+// rombios32.c
+void rombios32_init(void);
 
 #endif // util.h