fixed the physical to virtual translation issues with DJGPP, watcom just
[dosdemo] / 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 "inttypes.h"
19 #include "util.h"
20
21 #pragma pack (push, 1)
22 struct dpmi_regs {
23         uint32_t edi, esi, ebp;
24         uint32_t reserved;
25         uint32_t ebx, edx, ecx, eax;
26         uint16_t flags;
27         uint16_t es, ds, fs, gs;
28         uint16_t ip, cs, sp, ss;
29 } PACKED;
30 #pragma pack (pop)
31
32 uint16_t dpmi_alloc(unsigned int par, uint16_t *sel);
33 void dpmi_free(uint16_t sel);
34 void dpmi_int(int inum, struct dpmi_regs *regs);
35 void *dpmi_mmap(uint32_t phys_addr, unsigned int size);
36 void dpmi_munmap(void *addr);
37
38 #ifdef __WATCOMC__
39 #pragma aux dpmi_alloc = \
40                 "mov ax, 0x100" \
41                 "int 0x31" \
42                 "mov [edi], dx" \
43                 "jnc alloc_skip_err" \
44                 "xor ax, ax" \
45                 "alloc_skip_err:" \
46                 value[ax] \
47                 parm[ebx][edi] \
48                 modify[dx];
49
50 #pragma aux dpmi_free = \
51                 "mov ax, 0x101" \
52                 "int 0x31" \
53                 parm[dx] \
54                 modify[ax];
55
56 #pragma aux dpmi_int = \
57                 "mov ax, 0x300" \
58                 "xor ecx, ecx" \
59                 "int 0x31" \
60                 parm[ebx][edi] \
61                 modify[ax ecx];
62
63 #pragma aux dpmi_mmap = \
64                 "mov ax, 0x800" \
65                 "mov cx, bx" \
66                 "shr ebx, 16" \
67                 "mov di, si" \
68                 "shr esi, 16" \
69                 "int 0x31" \
70                 "jnc mmap_skip_err" \
71                 "xor bx, bx" \
72                 "xor cx, cx" \
73         "mmap_skip_err:" \
74                 "mov ax, bx" \
75                 "shl eax, 16" \
76                 "mov ax, cx" \
77                 value[eax] \
78                 parm[ebx][esi] \
79                 modify[bx cx di esi];
80
81 #pragma aux dpmi_munmap = \
82                 "mov ax, 0x801" \
83                 "mov cx, bx" \
84                 "shr ebx, 16" \
85                 "int 0x31" \
86                 parm[ebx] \
87                 modify[ax cx ebx];
88 #endif  /* __WATCOMC__ */
89
90 #ifdef __DJGPP__
91 #define dpmi_int(inum, regs) __dpmi_int((inum), (__dpmi_regs*)(regs))
92 #endif
93
94 #endif  /* DPMI_H_ */