fixed the physical to virtual translation issues with DJGPP, watcom just
[dosdemo] / src / dos / cdpmi.h
index cdfd2f7..71138b6 100644 (file)
@@ -3,10 +3,22 @@
 
 #ifdef __DJGPP__
 #include <dpmi.h>
-#endif
+#include <sys/nearptr.h>
+
+#define virt_to_phys(v)        ((v) + __djgpp_base_address)
+#define phys_to_virt(p)        ((p) - __djgpp_base_address)
+
+#else  /* not djgpp (basically watcom) */
+
+#define virt_to_phys(v)        (v)
+#define phys_to_virt(p)        (p)
+
+#endif /* __DJGPP__ */
 
 #include "inttypes.h"
+#include "util.h"
 
+#pragma pack (push, 1)
 struct dpmi_regs {
        uint32_t edi, esi, ebp;
        uint32_t reserved;
@@ -14,7 +26,8 @@ struct dpmi_regs {
        uint16_t flags;
        uint16_t es, ds, fs, gs;
        uint16_t ip, cs, sp, ss;
-};
+} PACKED;
+#pragma pack (pop)
 
 uint16_t dpmi_alloc(unsigned int par, uint16_t *sel);
 void dpmi_free(uint16_t sel);
@@ -27,8 +40,12 @@ void dpmi_munmap(void *addr);
                "mov ax, 0x100" \
                "int 0x31" \
                "mov [edi], dx" \
+               "jnc alloc_skip_err" \
+               "xor ax, ax" \
+               "alloc_skip_err:" \
                value[ax] \
-               parm[ebx][edi];
+               parm[ebx][edi] \
+               modify[dx];
 
 #pragma aux dpmi_free = \
                "mov ax, 0x101" \
@@ -59,7 +76,7 @@ void dpmi_munmap(void *addr);
                "mov ax, cx" \
                value[eax] \
                parm[ebx][esi] \
-               modify[cx di];
+               modify[bx cx di esi];
 
 #pragma aux dpmi_munmap = \
                "mov ax, 0x801" \
@@ -67,7 +84,7 @@ void dpmi_munmap(void *addr);
                "shr ebx, 16" \
                "int 0x31" \
                parm[ebx] \
-               modify[ax];
+               modify[ax cx ebx];
 #endif /* __WATCOMC__ */
 
 #ifdef __DJGPP__