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