X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=kern%2Fsrc%2Fasmutil.h;fp=kern%2Fsrc%2Fasmutil.h;h=751def6f7411c698c1ca96cc53b4e4dae298f664;hb=88e57cf7f2581900eb31cb835a18ad414e37786c;hp=0000000000000000000000000000000000000000;hpb=5145ed1e2adefc9c66e20681532a3a7cd6c2de01;p=eightysix diff --git a/kern/src/asmutil.h b/kern/src/asmutil.h new file mode 100644 index 0000000..751def6 --- /dev/null +++ b/kern/src/asmutil.h @@ -0,0 +1,61 @@ +#ifndef ASMUTIL_H_ +#define ASMUTIL_H_ + +#include + +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_ */