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