Use the faster span read/write template for 16bpp
[mesa.git] / src / mesa / drivers / dos / dpmi.c
index 26400ac3af3e1c31596f72f0f1babdff463847be..b2cef04ac8fee7a4474bc6e66448978912ae39ef 100644 (file)
-/*\r
- * Mesa 3-D graphics library\r
- * Version:  4.0\r
- * \r
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v0.3 for Mesa 4.0\r
- *\r
- *  Copyright (C) 2002 - Borca Daniel\r
- *  Email : dborca@yahoo.com\r
- *  Web   : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <dpmi.h>\r
-\r
-#include "dpmiint.h"\r
-\r
-\r
-\r
-/* _create_linear_mapping:\r
- *  Maps a physical address range into linear memory.\r
- */\r
-static int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)\r
-{\r
- __dpmi_meminfo meminfo;\r
-\r
- if (physaddr >= 0x100000) {\r
-    /* map into linear memory */\r
-    meminfo.address = physaddr;\r
-    meminfo.size = size;\r
-    if (__dpmi_physical_address_mapping(&meminfo) != 0)\r
-       return -1;\r
-\r
-    *linear = meminfo.address;\r
- } else {\r
-    /* exploit 1 -> 1 physical to linear mapping in low megabyte */\r
-    *linear = physaddr;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* _remove_linear_mapping:\r
- *  Frees the DPMI resources being used to map a linear address range.\r
- */\r
-static void _remove_linear_mapping (unsigned long *linear)\r
-{\r
- __dpmi_meminfo meminfo;\r
-\r
- if (*linear) {\r
-    if (*linear >= 0x100000) {\r
-       meminfo.address = *linear;\r
-       __dpmi_free_physical_address_mapping(&meminfo);\r
-    }\r
-\r
-    *linear = 0;\r
- }\r
-}\r
-\r
-\r
-\r
-/* _create_selector:\r
- *  Allocates a selector to access a region of linear memory.\r
- */\r
-int _create_selector (int *segment, unsigned long base, int size)\r
-{\r
- /* allocate an ldt descriptor */\r
- if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {\r
-    *segment = 0;\r
-    return -1;\r
- }\r
-\r
- /* create the linear mapping */\r
- if (_create_linear_mapping(&base, base, size)) {\r
-    __dpmi_free_ldt_descriptor(*segment);\r
-    *segment = 0;\r
-    return -1;\r
- }\r
-\r
- /* set the descriptor base and limit */\r
- __dpmi_set_segment_base_address(*segment, base);\r
- __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* _remove_selector:\r
- *  Frees a DPMI segment selector.\r
- */\r
-void _remove_selector (int *segment)\r
-{\r
- if (*segment) {\r
-    unsigned long base;\r
-    __dpmi_get_segment_base_address(*segment, &base);\r
-    _remove_linear_mapping(&base);\r
-    __dpmi_free_ldt_descriptor(*segment);\r
-    *segment = 0;\r
- }\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version:  4.0
+ * 
+ * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.5 for Mesa
+ *
+ *  Copyright (C) 2002 - Borca Daniel
+ *  Email : dborca@yahoo.com
+ *  Web   : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+
+#include "internal.h"
+
+
+#ifndef MAX
+#define MAX(x, y) (((x) < (y)) ? (y) : (x))
+#endif
+
+
+/* _create_linear_mapping:
+ *  Maps a physical address range into linear memory.
+ */
+int
+_create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
+{
+   __dpmi_meminfo meminfo;
+
+   if (physaddr >= 0x100000) {
+      /* map into linear memory */
+      meminfo.address = physaddr;
+      meminfo.size = size;
+      if (__dpmi_physical_address_mapping(&meminfo) != 0) {
+         return -1;
+      }
+
+      *linear = meminfo.address;
+   } else {
+      /* exploit 1 -> 1 physical to linear mapping in low megabyte */
+      *linear = physaddr;
+   }
+
+   return 0;
+}
+
+
+/* _remove_linear_mapping:
+ *  Frees the DPMI resources being used to map a linear address range.
+ */
+void
+_remove_linear_mapping (unsigned long *linear)
+{
+   __dpmi_meminfo meminfo;
+
+   if (*linear) {
+      if (*linear >= 0x100000) {
+         meminfo.address = *linear;
+         __dpmi_free_physical_address_mapping(&meminfo);
+      }
+
+      *linear = 0;
+   }
+}
+
+
+/* _create_selector:
+ *  Allocates a selector to access a region of linear memory.
+ */
+int
+_create_selector (int *segment, unsigned long base, int size)
+{
+   /* allocate an ldt descriptor */
+   if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {
+      *segment = 0;
+      return -1;
+   }
+
+   /* create the linear mapping */
+   if (_create_linear_mapping(&base, base, size)) {
+      __dpmi_free_ldt_descriptor(*segment);
+      *segment = 0;
+      return -1;
+   }
+
+   /* set the descriptor base and limit */
+   __dpmi_set_segment_base_address(*segment, base);
+   __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));
+
+   return 0;
+}
+
+
+/* _remove_selector:
+ *  Frees a DPMI segment selector.
+ */
+void
+_remove_selector (int *segment)
+{
+   if (*segment) {
+      unsigned long base;
+      __dpmi_get_segment_base_address(*segment, &base);
+      _remove_linear_mapping(&base);
+      __dpmi_free_ldt_descriptor(*segment);
+      *segment = 0;
+   }
+}
+
+
+/* Desc: retrieve CPU MMX capability
+ *
+ * In  : -
+ * Out : FALSE if CPU cannot do MMX
+ *
+ * Note: -
+ */
+int
+_can_mmx (void)
+{
+#ifdef USE_MMX_ASM
+   int x86_cpu_features = 0;
+   __asm("\n\
+               pushfl                  \n\
+               popl    %%eax           \n\
+               movl    %%eax, %%ecx    \n\
+               xorl    $0x200000, %%eax\n\
+               pushl   %%eax           \n\
+               popfl                   \n\
+               pushfl                  \n\
+               popl    %%eax           \n\
+               pushl   %%ecx           \n\
+               popfl                   \n\
+               xorl    %%ecx, %%eax    \n\
+               jz 0f                   \n\
+               movl    $1, %%eax       \n\
+               cpuid                   \n\
+               movl    %%edx, %0       \n\
+       0:                              \n\
+   ":"=g"(x86_cpu_features)::"%eax", "%ebx", "%ecx", "%edx");
+   return (x86_cpu_features & 0x00800000);
+#else
+   return 0;
+#endif
+}