annotate linux/vbelib.c @ 2369:10a6a6535670

misinformation corrected
author gabucino
date Mon, 22 Oct 2001 15:34:04 +0000
parents ee6ef0b10655
children 2e4c17f4a744
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
1 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
2 This file contains implementation of VESA library which is based on
f4b588dba08a vbelib import
nick
parents:
diff changeset
3 LRMI (Linux real-mode interface).
f4b588dba08a vbelib import
nick
parents:
diff changeset
4 So it's not an emulator - it calls real int 10h handler under Linux.
f4b588dba08a vbelib import
nick
parents:
diff changeset
5 Note: VESA is available only on x86 systems.
f4b588dba08a vbelib import
nick
parents:
diff changeset
6 You can redistribute this file under terms and conditions
f4b588dba08a vbelib import
nick
parents:
diff changeset
7 GNU General Public licence v2.
f4b588dba08a vbelib import
nick
parents:
diff changeset
8 Written by Nick Kurshev <nickols_k@mail.ru>
f4b588dba08a vbelib import
nick
parents:
diff changeset
9 */
f4b588dba08a vbelib import
nick
parents:
diff changeset
10 #include "vbelib.h"
f4b588dba08a vbelib import
nick
parents:
diff changeset
11 #include "lrmi.h"
f4b588dba08a vbelib import
nick
parents:
diff changeset
12 #include <stdlib.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
13 #include <string.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
14 #include <stdio.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
15 #include <sys/io.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
16
f4b588dba08a vbelib import
nick
parents:
diff changeset
17 static struct VesaProtModeInterface vbe_pm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
18
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
19 #define HAVE_VERBOSE_VAR 1
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
20
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
21 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
22 extern int verbose;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
23
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
24 static void __dump_regs(struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
25 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
26 printf("vbelib: eax=%08lXh ebx=%08lXh ecx=%08lXh edx=%08lXh\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
27 "vbelib: edi=%08lXh esi=%08lXh ebp=%08lXh esp=%08lXh\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
28 "vbelib: ds=%04lXh es=%04Xh ss=%04Xh cs:ip=%04X:%04X\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
29 "vbelib: fs=%04lXh gs=%04Xh ss:sp=%04X:%04X flags=%04X\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
30 ,r->eax,r->ebx,r->ecx,r->edx
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
31 ,r->edi,r->esi,r->ebp,r->reserved
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
32 ,r->ds,r->es,r->ss,r->cs,r->ip
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
33 ,r->fs,r->gs,r->ss,r->sp,r->flags);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
34 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
35
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
36 static inline int VBE_LRMI_int(int int_no, struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
37 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
38 int retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
39 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
40 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
41 printf("vbelib: registers before int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
42 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
43 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
44 retval = LRMI_int(int_no,r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
45 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
46 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
47 printf("vbelib: Interrupt handler returns: %08lXh\n",retval);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
48 printf("vbelib: registers after int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
49 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
50 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
51 return retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
52 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
53 #else
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
54 #define VBE_LRMI_int(int_no,regs) (VBE_LRMI_int(int_no,regs))
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
55 #endif
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
56
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
57 int vbeInit( void )
f4b588dba08a vbelib import
nick
parents:
diff changeset
58 {
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
59 unsigned short iopl_port,int_10_seg;
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
60 size_t i;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
61 if(!LRMI_init()) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
62 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
63 Allow read/write to ALL io ports
f4b588dba08a vbelib import
nick
parents:
diff changeset
64 */
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
65 int_10_seg = *(unsigned short *)PhysToVirtSO(0x0000,0x0042);
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
66 /* Video BIOS should be at C000:0000 and above */
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
67 if((int_10_seg >> 12) < 0xC) return VBE_BROKEN_BIOS;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
68 ioperm(0, 1024, 1);
f4b588dba08a vbelib import
nick
parents:
diff changeset
69 iopl(3);
f4b588dba08a vbelib import
nick
parents:
diff changeset
70 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface));
f4b588dba08a vbelib import
nick
parents:
diff changeset
71 vbeGetProtModeInfo(&vbe_pm_info);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
72 i = 0;
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
73 while((iopl_port=vbe_pm_info.iopl_ports[i++]) != 0xFFFF) ioperm(iopl_port,1,1);
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
74 iopl(3);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
75 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
76 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
77
f4b588dba08a vbelib import
nick
parents:
diff changeset
78 int vbeDestroy( void ) { return VBE_OK; }
f4b588dba08a vbelib import
nick
parents:
diff changeset
79
f4b588dba08a vbelib import
nick
parents:
diff changeset
80 int vbeGetControllerInfo(struct VbeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
81 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
82 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
83 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
84 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
85 if(!(rm_space = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
86 memcpy(rm_space,data,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
87 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
88 r.eax = 0x4f00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
89 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
90 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
91 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
92 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
93 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
94 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
95 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
96 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
97 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
98 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
99 FarPtr fpdata;
f4b588dba08a vbelib import
nick
parents:
diff changeset
100 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
101 memcpy(data,rm_space,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
102 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
103 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
104 data->OemStringPtr = PhysToVirt(fpdata);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
105 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
106 if(verbose > 1) printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
107 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
108 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
109 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
110 data->VideoModePtr = PhysToVirt(fpdata);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
111 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
112 if(verbose > 1) printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
113 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
114 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
115 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
116 data->OemVendorNamePtr = PhysToVirt(fpdata);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
117 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
118 if(verbose > 1) printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
119 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
120 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
121 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
122 data->OemProductNamePtr = PhysToVirt(fpdata);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
123 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
124 if(verbose > 1) printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
125 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
126 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
127 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
128 data->OemProductRevPtr = PhysToVirt(fpdata);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
129 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
130 if(verbose > 1) printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
131 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
132 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
133 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
134 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
135
f4b588dba08a vbelib import
nick
parents:
diff changeset
136 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
137 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
138 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
139 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
140 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
141 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
142 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
143 r.eax = 0x4f01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
144 r.ecx = mode;
f4b588dba08a vbelib import
nick
parents:
diff changeset
145 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
146 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
147 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
148 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
149 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
150 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
151 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
152 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
153 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
154 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
155 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
156 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
157 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
158 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
159 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
160
f4b588dba08a vbelib import
nick
parents:
diff changeset
161 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
162 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
163 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
164 void *rm_space = NULL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
165 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
166 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
167 if(data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
168 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
169 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
170 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
171 r.edi = VirtToPhysOff(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
172 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
173 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
174 r.eax = 0x4f02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
175 r.ebx = mode;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
176 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
177 if(rm_space) LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
178 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
179 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
180 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
181 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
182 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
183
f4b588dba08a vbelib import
nick
parents:
diff changeset
184 int vbeGetMode(unsigned *mode)
f4b588dba08a vbelib import
nick
parents:
diff changeset
185 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
186 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
187 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
188 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
189 r.eax = 0x4f03;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
190 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
191 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
192 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
193 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
194 *mode = r.ebx;
f4b588dba08a vbelib import
nick
parents:
diff changeset
195 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
196 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
197 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
198 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
199
f4b588dba08a vbelib import
nick
parents:
diff changeset
200 int vbeSaveState(void **data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
201 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
202 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
203 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
204 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
205 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
206 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
207 r.edx = 0x00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
208 r.ecx = 0x0f;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
209 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
210 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
211 if(retval != 0x4f) return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
212 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
213 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
214 r.edx = 0x01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
215 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
216 r.es = VirtToPhysSeg(rm_space);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
217 r.ebx = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
218 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
219 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
220 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
221 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
222 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
223 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
224 if(retval != 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
225 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
226 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
227 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
228 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
229 *data = rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
230 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
231 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
232
f4b588dba08a vbelib import
nick
parents:
diff changeset
233 int vbeRestoreState(void *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
234 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
235 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
236 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
237 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
238 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
239 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
240 r.edx = 0x02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
241 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
242 r.es = VirtToPhysSeg(data);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
243 r.ebx = VirtToPhysOff(data);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
244 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
245 LRMI_free_real(data);
f4b588dba08a vbelib import
nick
parents:
diff changeset
246 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
247 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
248 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
249 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
250 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
251
f4b588dba08a vbelib import
nick
parents:
diff changeset
252 int vbeGetWindow(unsigned *win_num)
f4b588dba08a vbelib import
nick
parents:
diff changeset
253 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
254 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
255 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
256 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
257 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
258 r.ebx = (*win_num & 0x0f) | 0x0100;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
259 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
260 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
261 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
262 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
263 *win_num = r.edx & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
264 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
265 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
266 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
267 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
268
f4b588dba08a vbelib import
nick
parents:
diff changeset
269 int vbeSetWindow(unsigned win_num,unsigned win_gran)
f4b588dba08a vbelib import
nick
parents:
diff changeset
270 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
271 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
272 if(vbe_pm_info.SetWindowCall)
f4b588dba08a vbelib import
nick
parents:
diff changeset
273 {
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
274 /* Don't verbose this stuff from performance reasons */
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
275 /* 32-bit function call is much better of int 10h */
f4b588dba08a vbelib import
nick
parents:
diff changeset
276 __asm __volatile(
f4b588dba08a vbelib import
nick
parents:
diff changeset
277 "pushl %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
278 "movl %1, %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
279 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory");
f4b588dba08a vbelib import
nick
parents:
diff changeset
280 (*vbe_pm_info.SetWindowCall)();
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
281 __asm __volatile("popl %%ebx":::"memory");
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
282 retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
283 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
284 else
f4b588dba08a vbelib import
nick
parents:
diff changeset
285 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
286 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
287 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
288 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
289 r.ebx = win_num & 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
290 r.edx = win_gran;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
291 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
292 retval = r.eax & 0xffff;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
293 if(retval == 0x4f) retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
294 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
295 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
296 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
297
f4b588dba08a vbelib import
nick
parents:
diff changeset
298 struct realVesaProtModeInterface
f4b588dba08a vbelib import
nick
parents:
diff changeset
299 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
300 unsigned short SetWindowCall;
f4b588dba08a vbelib import
nick
parents:
diff changeset
301 unsigned short SetDisplayStart;
f4b588dba08a vbelib import
nick
parents:
diff changeset
302 unsigned short SetPaletteData;
f4b588dba08a vbelib import
nick
parents:
diff changeset
303 unsigned short iopl_ports;
f4b588dba08a vbelib import
nick
parents:
diff changeset
304 }__attribute__((packed));
f4b588dba08a vbelib import
nick
parents:
diff changeset
305
f4b588dba08a vbelib import
nick
parents:
diff changeset
306 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info)
f4b588dba08a vbelib import
nick
parents:
diff changeset
307 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
308 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
309 int retval;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
310 unsigned info_offset;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
311 struct realVesaProtModeInterface *rm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
312 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
313 r.eax = 0x4f0a;
f4b588dba08a vbelib import
nick
parents:
diff changeset
314 r.ebx = 0;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
315 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
316 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
317 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
318 {
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
319 info_offset = r.edi&0xffff;
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
320 rm_info = PhysToVirtSO(r.es,info_offset);
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
321 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
322 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
323 if(verbose > 1) printf("vbelib: SetWindowCall=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetWindowCall,pm_info->SetWindowCall);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
324 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
325 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
326 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
327 if(verbose > 1) printf("vbelib: SetDisplayStart=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetDisplayStart,pm_info->SetDisplayStart);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
328 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
329 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
330 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
331 if(verbose > 1) printf("vbelib: SetPaletteData=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetPaletteData,pm_info->SetPaletteData);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
332 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
333 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
334 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
335 if(verbose > 1) printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
336 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
337 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
338 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
339 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
340 }