2 * Mesa 3-D graphics library
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * DOS/DJGPP device driver for Mesa
28 * Author: Daniel Borca
29 * Email : dborca@yahoo.com
30 * Web : http://www.geocities.com/dborca
40 #define MAX(x, y) (((x) < (y)) ? (y) : (x))
44 /* _create_linear_mapping:
45 * Maps a physical address range into linear memory.
48 _create_linear_mapping (unsigned long *linear
, unsigned long physaddr
, int size
)
50 __dpmi_meminfo meminfo
;
52 if (physaddr
>= 0x100000) {
53 /* map into linear memory */
54 meminfo
.address
= physaddr
;
56 if (__dpmi_physical_address_mapping(&meminfo
) != 0) {
60 *linear
= meminfo
.address
;
62 /* exploit 1 -> 1 physical to linear mapping in low megabyte */
70 /* _remove_linear_mapping:
71 * Frees the DPMI resources being used to map a linear address range.
74 _remove_linear_mapping (unsigned long *linear
)
76 __dpmi_meminfo meminfo
;
79 if (*linear
>= 0x100000) {
80 meminfo
.address
= *linear
;
81 __dpmi_free_physical_address_mapping(&meminfo
);
90 * Allocates a selector to access a region of linear memory.
93 _create_selector (int *segment
, unsigned long base
, int size
)
95 /* allocate an ldt descriptor */
96 if ((*segment
=__dpmi_allocate_ldt_descriptors(1)) < 0) {
101 /* create the linear mapping */
102 if (_create_linear_mapping(&base
, base
, size
)) {
103 __dpmi_free_ldt_descriptor(*segment
);
108 /* set the descriptor base and limit */
109 __dpmi_set_segment_base_address(*segment
, base
);
110 __dpmi_set_segment_limit(*segment
, MAX(size
-1, 0xFFFF));
117 * Frees a DPMI segment selector.
120 _remove_selector (int *segment
)
124 __dpmi_get_segment_base_address(*segment
, &base
);
125 _remove_linear_mapping(&base
);
126 __dpmi_free_ldt_descriptor(*segment
);
132 /* Desc: retrieve CPU MMX capability
135 * Out : FALSE if CPU cannot do MMX
143 int x86_cpu_features
= 0;
147 movl %%eax, %%ecx \n\
148 xorl $0x200000, %%eax\n\
155 xorl %%ecx, %%eax \n\
161 ":"=g"(x86_cpu_features
)::"%eax", "%ebx", "%ecx", "%edx");
162 return (x86_cpu_features
& 0x00800000);