foo
[eightysix] / kern / src / asmutil.h
diff --git a/kern/src/asmutil.h b/kern/src/asmutil.h
new file mode 100644 (file)
index 0000000..751def6
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef ASMUTIL_H_
+#define ASMUTIL_H_
+
+#include <inttypes.h>
+
+struct wordregs {
+       uint16_t ax, bx, cx, dx;
+       uint16_t si, di, cflag;
+} __attribute__((packed));
+
+struct byteregs {
+       uint8_t al, ah;
+       uint8_t bl, bh;
+       uint8_t cl, ch;
+       uint8_t dl, dh;
+} __attribute__((packed));
+
+union regs {
+       struct wordregs w;
+       struct byteregs h;
+};
+
+void int86(int n, union regs *inregs, union regs *outregs);
+
+#define FP_SEG(x)      ((uint16_t)((uint32_t)(x) >> 16))
+#define FP_OFFS(x)     ((uint16_t)(x))
+#define MK_FP(s, o)    (((uint32_t)(s) << 16) | (uint32_t)(o))
+
+#define enable() asm("sti")
+#define disable() asm("cli")
+
+#define outp(p, v)     \
+       asm volatile( \
+               "outb %1, %0" \
+               :: "d"(p), "a"((unsigned char)v))
+
+#define outpw(p, v)    \
+       asm volatile( \
+               "outw %1, %0" \
+               :: "d"(p), "a"((unsigned short)v))
+
+static inline unsigned char inp(int p)
+{
+       unsigned char res;
+       asm volatile(
+               "inb %1, %0" \
+               : "=a"(res) : "d"(p));
+       return res;
+}
+
+static inline unsigned short inpw(int p)
+{
+       unsigned short res;
+       asm volatile(
+               "inw %1, %0" \
+               : "=a"(res) : "d"(p));
+       return res;
+}
+
+
+#endif /* ASMUTIL_H_ */