pulled in and adapted the dos code from eradicate
[retrobench] / src / dos / cdpmi.h
1 #ifndef DPMI_H_
2 #define DPMI_H_
3
4 #ifdef __DJGPP__
5 #include <dpmi.h>
6 #include <sys/nearptr.h>
7
8 #define virt_to_phys(v) ((v) + __djgpp_base_address)
9 #define phys_to_virt(p) ((p) - __djgpp_base_address)
10
11 #else   /* not djgpp (basically watcom) */
12
13 #define virt_to_phys(v) (v)
14 #define phys_to_virt(p) (p)
15
16 #endif  /* __DJGPP__ */
17
18 #include "util.h"
19
20 #pragma pack (push, 1)
21 struct dpmi_regs {
22         uint32_t edi, esi, ebp;
23         uint32_t reserved;
24         uint32_t ebx, edx, ecx, eax;
25         uint16_t flags;
26         uint16_t es, ds, fs, gs;
27         uint16_t ip, cs, sp, ss;
28 } PACKED;
29 #pragma pack (pop)
30
31 uint16_t dpmi_alloc(unsigned int par, uint16_t *sel);
32 void dpmi_free(uint16_t sel);
33 void dpmi_int(int inum, struct dpmi_regs *regs);
34 void *dpmi_mmap(uint32_t phys_addr, unsigned int size);
35 void dpmi_munmap(void *addr);
36
37 #ifdef __WATCOMC__
38 #pragma aux dpmi_alloc = \
39                 "mov ax, 0x100" \
40                 "int 0x31" \
41                 "mov [edi], dx" \
42                 "jnc alloc_skip_err" \
43                 "xor ax, ax" \
44                 "alloc_skip_err:" \
45                 value[ax] \
46                 parm[ebx][edi] \
47                 modify[dx];
48
49 #pragma aux dpmi_free = \
50                 "mov ax, 0x101" \
51                 "int 0x31" \
52                 parm[dx] \
53                 modify[ax];
54
55 #pragma aux dpmi_int = \
56                 "mov ax, 0x300" \
57                 "xor ecx, ecx" \
58                 "int 0x31" \
59                 parm[ebx][edi] \
60                 modify[ax ecx];
61
62 #pragma aux dpmi_mmap = \
63                 "mov ax, 0x800" \
64                 "mov cx, bx" \
65                 "shr ebx, 16" \
66                 "mov di, si" \
67                 "shr esi, 16" \
68                 "int 0x31" \
69                 "jnc mmap_skip_err" \
70                 "xor bx, bx" \
71                 "xor cx, cx" \
72         "mmap_skip_err:" \
73                 "mov ax, bx" \
74                 "shl eax, 16" \
75                 "mov ax, cx" \
76                 value[eax] \
77                 parm[ebx][esi] \
78                 modify[bx cx di esi];
79
80 #pragma aux dpmi_munmap = \
81                 "mov ax, 0x801" \
82                 "mov cx, bx" \
83                 "shr ebx, 16" \
84                 "int 0x31" \
85                 parm[ebx] \
86                 modify[ax cx ebx];
87 #endif  /* __WATCOMC__ */
88
89 #ifdef __DJGPP__
90 #define dpmi_int(inum, regs) __dpmi_int((inum), (__dpmi_regs*)(regs))
91 #endif
92
93 #endif  /* DPMI_H_ */