removed clang-format and clang_complete files from the repo
[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 enum {
33         FLAGS_CF        = 0x000001,
34         FLAGS_PF        = 0x000004,
35         FLAGS_ZF        = 0x000040,
36         FLAGS_SF        = 0x000080,
37         FLAGS_IF        = 0x000020,
38         FLAGS_DF        = 0x000040,
39         FLAGS_VM        = 0x020000,
40         FLAGS_ID        = 0x200000,
41 };
42
43 uint16_t dpmi_alloc(unsigned int par, uint16_t *sel);
44 void dpmi_free(uint16_t sel);
45 void dpmi_int(int inum, struct dpmi_regs *regs);
46 void *dpmi_mmap(uint32_t phys_addr, unsigned int size);
47 void dpmi_munmap(void *addr);
48
49 #ifdef __WATCOMC__
50 #pragma aux dpmi_alloc = \
51                 "mov ax, 0x100" \
52                 "int 0x31" \
53                 "mov [edi], dx" \
54                 "jnc alloc_skip_err" \
55                 "xor ax, ax" \
56                 "alloc_skip_err:" \
57                 value[ax] \
58                 parm[ebx][edi] \
59                 modify[dx];
60
61 #pragma aux dpmi_free = \
62                 "mov ax, 0x101" \
63                 "int 0x31" \
64                 parm[dx] \
65                 modify[ax];
66
67 #pragma aux dpmi_int = \
68                 "mov ax, 0x300" \
69                 "xor ecx, ecx" \
70                 "int 0x31" \
71                 parm[ebx][edi] \
72                 modify[ax ecx];
73
74 #pragma aux dpmi_mmap = \
75                 "mov ax, 0x800" \
76                 "mov cx, bx" \
77                 "shr ebx, 16" \
78                 "mov di, si" \
79                 "shr esi, 16" \
80                 "int 0x31" \
81                 "jnc mmap_skip_err" \
82                 "xor bx, bx" \
83                 "xor cx, cx" \
84         "mmap_skip_err:" \
85                 "mov ax, bx" \
86                 "shl eax, 16" \
87                 "mov ax, cx" \
88                 value[eax] \
89                 parm[ebx][esi] \
90                 modify[bx cx di esi];
91
92 #pragma aux dpmi_munmap = \
93                 "mov ax, 0x801" \
94                 "mov cx, bx" \
95                 "shr ebx, 16" \
96                 "int 0x31" \
97                 parm[ebx] \
98                 modify[ax cx ebx];
99 #endif  /* __WATCOMC__ */
100
101 #ifdef __DJGPP__
102 #define dpmi_int(inum, regs) __dpmi_int((inum), (__dpmi_regs*)(regs))
103 #endif
104
105 #endif  /* DPMI_H_ */