foo
[eightysix] / kern / src / asmutil.h
1 #ifndef ASMUTIL_H_
2 #define ASMUTIL_H_
3
4 #include <inttypes.h>
5
6 struct wordregs {
7         uint16_t ax, bx, cx, dx;
8         uint16_t si, di, cflag;
9 } __attribute__((packed));
10
11 struct byteregs {
12         uint8_t al, ah;
13         uint8_t bl, bh;
14         uint8_t cl, ch;
15         uint8_t dl, dh;
16 } __attribute__((packed));
17
18 union regs {
19         struct wordregs w;
20         struct byteregs h;
21 };
22
23 void int86(int n, union regs *inregs, union regs *outregs);
24
25 #define FP_SEG(x)       ((uint16_t)((uint32_t)(x) >> 16))
26 #define FP_OFFS(x)      ((uint16_t)(x))
27 #define MK_FP(s, o)     (((uint32_t)(s) << 16) | (uint32_t)(o))
28
29 #define enable() asm("sti")
30 #define disable() asm("cli")
31
32 #define outp(p, v)      \
33         asm volatile( \
34                 "outb %1, %0" \
35                 :: "d"(p), "a"((unsigned char)v))
36
37 #define outpw(p, v)     \
38         asm volatile( \
39                 "outw %1, %0" \
40                 :: "d"(p), "a"((unsigned short)v))
41
42 static inline unsigned char inp(int p)
43 {
44         unsigned char res;
45         asm volatile(
46                 "inb %1, %0" \
47                 : "=a"(res) : "d"(p));
48         return res;
49 }
50
51 static inline unsigned short inpw(int p)
52 {
53         unsigned short res;
54         asm volatile(
55                 "inw %1, %0" \
56                 : "=a"(res) : "d"(p));
57         return res;
58 }
59
60
61 #endif  /* ASMUTIL_H_ */