summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dos/dpmi.c
diff options
context:
space:
mode:
authorDaniel Borca <[email protected]>2004-11-12 14:58:26 +0000
committerDaniel Borca <[email protected]>2004-11-12 14:58:26 +0000
commit0676fc357a12879531e6509354ecc7447c99d148 (patch)
treed4885d993c066614546beab3aad6168b92d97119 /src/mesa/drivers/dos/dpmi.c
parent885f10706a096037eea815803dbf4b4d28c3bd27 (diff)
added a few sanity checks
made coding style a bit more consistent
Diffstat (limited to 'src/mesa/drivers/dos/dpmi.c')
-rw-r--r--src/mesa/drivers/dos/dpmi.c148
1 files changed, 83 insertions, 65 deletions
diff --git a/src/mesa/drivers/dos/dpmi.c b/src/mesa/drivers/dos/dpmi.c
index f9943ea60bf..81af6ac5d0b 100644
--- a/src/mesa/drivers/dos/dpmi.c
+++ b/src/mesa/drivers/dos/dpmi.c
@@ -23,7 +23,7 @@
*/
/*
- * DOS/DJGPP device driver v1.4 for Mesa
+ * DOS/DJGPP device driver v1.5 for Mesa
*
* Copyright (C) 2002 - Borca Daniel
@@ -36,100 +36,99 @@
#include "internal.h"
-
#ifndef MAX
-#define MAX(x, y) (((x)<(y))?(y):(x))
+#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)
+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;
+ __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)
+void
+_remove_linear_mapping (unsigned long *linear)
{
- __dpmi_meminfo meminfo;
+ __dpmi_meminfo meminfo;
- if (*linear) {
- if (*linear >= 0x100000) {
- meminfo.address = *linear;
- __dpmi_free_physical_address_mapping(&meminfo);
- }
+ if (*linear) {
+ if (*linear >= 0x100000) {
+ meminfo.address = *linear;
+ __dpmi_free_physical_address_mapping(&meminfo);
+ }
- *linear = 0;
- }
+ *linear = 0;
+ }
}
-
/* _create_selector:
* Allocates a selector to access a region of linear memory.
*/
-int _create_selector (int *segment, unsigned long base, int size)
+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;
+ /* 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)
+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;
- }
+ 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 : -
@@ -137,12 +136,31 @@ void _remove_selector (int *segment)
*
* Note: -
*/
-int _can_mmx (void)
+int
+_can_mmx (void)
{
#ifdef USE_MMX_ASM
- extern int _mesa_x86_cpu_features;
- return (_mesa_x86_cpu_features & 0x00800000);
+ static 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;
+ return 0;
#endif
}