Mercurial > mplayer.hg
annotate linux/vbelib.c @ 2794:411be2ac50ae
vfw_raw fix
author | alex |
---|---|
date | Sat, 10 Nov 2001 14:52:05 +0000 |
parents | 1a8e5e017b1d |
children | 74731185c5c9 |
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 | |
2632 | 7 of GNU General Public licence v2. |
2243 | 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> | |
2610 | 16 #include <sys/mman.h> |
17 #include <sys/types.h> | |
18 #include <sys/stat.h> | |
2407 | 19 #include <ctype.h> |
2610 | 20 #include <unistd.h> |
21 #include <fcntl.h> | |
2243 | 22 |
23 static struct VesaProtModeInterface vbe_pm_info; | |
2632 | 24 static struct VesaModeInfoBlock curr_mode_info; |
2243 | 25 |
2536 | 26 static inline int VERR(const void *p) |
2515 | 27 { |
28 register int retval; | |
29 __asm __volatile( | |
30 "xorl %0, %0\n\t" | |
31 "verr %1\n\t" | |
32 "setnz %b0" | |
33 :"=r"(retval) | |
34 :"m"(*(unsigned char *)p) | |
35 :"memory"); | |
36 return retval; | |
37 } | |
38 | |
39 #if 0 | |
2536 | 40 static inline int VERW(const void *p) |
2515 | 41 { |
42 register int retval; | |
43 __asm __volatile( | |
44 "xorl %0, %0\n\t" | |
45 "verw %1\n\t" | |
46 "setnz %b0" | |
47 :"=r"(retval) | |
48 :"m"(*(unsigned char *)p) | |
49 :"memory"); | |
50 return retval; | |
51 } | |
52 #endif | |
53 | |
2294 | 54 #define HAVE_VERBOSE_VAR 1 |
55 | |
56 #ifdef HAVE_VERBOSE_VAR | |
57 extern int verbose; | |
58 | |
59 static void __dump_regs(struct LRMI_regs *r) | |
60 { | |
61 printf("vbelib: eax=%08lXh ebx=%08lXh ecx=%08lXh edx=%08lXh\n" | |
62 "vbelib: edi=%08lXh esi=%08lXh ebp=%08lXh esp=%08lXh\n" | |
2445 | 63 "vbelib: ds=%04Xh es=%04Xh ss=%04Xh cs:ip=%04X:%04X\n" |
64 "vbelib: fs=%04Xh gs=%04Xh ss:sp=%04X:%04X flags=%04X\n" | |
65 ,(unsigned long)r->eax,(unsigned long)r->ebx,(unsigned long)r->ecx,(unsigned long)r->edx | |
66 ,(unsigned long)r->edi,(unsigned long)r->esi,(unsigned long)r->ebp,(unsigned long)r->reserved | |
2294 | 67 ,r->ds,r->es,r->ss,r->cs,r->ip |
68 ,r->fs,r->gs,r->ss,r->sp,r->flags); | |
69 } | |
70 | |
71 static inline int VBE_LRMI_int(int int_no, struct LRMI_regs *r) | |
72 { | |
73 int retval; | |
74 if(verbose > 1) | |
75 { | |
76 printf("vbelib: registers before int %02X\n",int_no); | |
77 __dump_regs(r); | |
78 } | |
79 retval = LRMI_int(int_no,r); | |
80 if(verbose > 1) | |
81 { | |
2445 | 82 printf("vbelib: Interrupt handler returns: %X\n",retval); |
2294 | 83 printf("vbelib: registers after int %02X\n",int_no); |
84 __dump_regs(r); | |
85 } | |
86 return retval; | |
87 } | |
88 #else | |
89 #define VBE_LRMI_int(int_no,regs) (VBE_LRMI_int(int_no,regs)) | |
90 #endif | |
91 | |
2407 | 92 static unsigned hh_int_10_seg; |
2610 | 93 static int fd_mem; |
2243 | 94 int vbeInit( void ) |
95 { | |
2407 | 96 unsigned short iopl_port; |
2359 | 97 size_t i; |
2552 | 98 int retval; |
2243 | 99 if(!LRMI_init()) return VBE_VM86_FAIL; |
100 /* | |
101 Allow read/write to ALL io ports | |
102 */ | |
2407 | 103 hh_int_10_seg = *(unsigned short *)PhysToVirtSO(0x0000,0x0042); |
2359 | 104 /* Video BIOS should be at C000:0000 and above */ |
2407 | 105 hh_int_10_seg >>= 12; |
106 if(hh_int_10_seg < 0xC) return VBE_BROKEN_BIOS; | |
2243 | 107 ioperm(0, 1024, 1); |
108 iopl(3); | |
109 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface)); | |
2552 | 110 retval = vbeGetProtModeInfo(&vbe_pm_info); |
111 if(retval != VBE_OK) return retval; | |
2359 | 112 i = 0; |
2552 | 113 while((iopl_port=vbe_pm_info.iopl_ports[i]) != 0xFFFF |
114 && vbe_pm_info.iopl_ports[i++] > 1023) ioperm(iopl_port,1,1); | |
2359 | 115 iopl(3); |
2610 | 116 fd_mem = open("/dev/mem",O_RDWR); |
2243 | 117 return VBE_OK; |
118 } | |
119 | |
2610 | 120 int vbeDestroy( void ) |
121 { | |
122 close(fd_mem); | |
123 return VBE_OK; | |
124 } | |
2243 | 125 |
2536 | 126 /* Fixme!!! This code is compatible only with mplayer's version of lrmi*/ |
127 static inline int is_addr_valid(const void *p) | |
128 { | |
129 return (p < (const void *)0x502) || | |
130 (p >= (const void *)0x10000 && p < (const void *)0x20000) || | |
131 (p >= (const void *)0xa0000 && p < (const void *)0x100000); | |
132 } | |
133 | |
134 static int check_str(const unsigned char *str) | |
2515 | 135 { |
136 size_t i; | |
137 int null_found = 0; | |
138 for(i = 0;i < 256;i++) | |
139 { | |
2536 | 140 if(is_addr_valid(&str[i])) |
2515 | 141 { |
2536 | 142 if(VERR(&str[i])) |
143 { | |
144 if(!str[i]) { null_found = 1; break; } | |
145 } | |
146 else break; | |
2515 | 147 } |
148 else break; | |
149 } | |
150 return null_found; | |
151 } | |
152 | |
2536 | 153 static int check_wrd(const unsigned short *str) |
2515 | 154 { |
155 size_t i; | |
156 int ffff_found = 0; | |
157 for(i = 0;i < 1024;i++) | |
158 { | |
2536 | 159 if(is_addr_valid(&str[i])) |
2515 | 160 { |
2536 | 161 if(VERR(&str[i])) |
162 { | |
163 if(str[i] == 0xffff) { ffff_found = 1; break; } | |
164 } | |
165 else break; | |
2515 | 166 } |
167 else break; | |
168 } | |
169 return ffff_found; | |
170 } | |
171 | |
2407 | 172 static void print_str(unsigned char *str) |
173 { | |
174 size_t i; | |
175 fflush(stdout); | |
176 printf("vbelib: "); | |
177 for(i = 0;i < 256;i++) { printf("%02X(%c) ",str[i],isprint(str[i])?str[i]:'.'); if(!str[i]) break; } | |
178 printf("\n"); | |
179 fflush(stdout); | |
180 } | |
181 | |
182 static void print_wrd(unsigned short *str) | |
183 { | |
184 size_t i; | |
185 fflush(stdout); | |
186 printf("vbelib: "); | |
187 for(i = 0;i < 256;i++) { printf("%04X ",str[i]); if(str[i] == 0xffff) break; } | |
188 printf("\n"); | |
189 fflush(stdout); | |
190 } | |
191 | |
2243 | 192 int vbeGetControllerInfo(struct VbeInfoBlock *data) |
193 { | |
194 struct LRMI_regs r; | |
195 void *rm_space; | |
196 int retval; | |
197 if(!(rm_space = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
198 memcpy(rm_space,data,sizeof(struct VbeInfoBlock)); | |
199 memset(&r,0,sizeof(struct LRMI_regs)); | |
200 r.eax = 0x4f00; | |
201 r.es = VirtToPhysSeg(rm_space); | |
202 r.edi = VirtToPhysOff(rm_space); | |
2294 | 203 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 204 { |
205 LRMI_free_real(rm_space); | |
206 return VBE_VM86_FAIL; | |
207 } | |
208 retval = r.eax & 0xffff; | |
209 if(retval == 0x4f) | |
210 { | |
211 FarPtr fpdata; | |
212 retval = VBE_OK; | |
213 memcpy(data,rm_space,sizeof(struct VbeInfoBlock)); | |
214 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16; | |
215 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff; | |
216 data->OemStringPtr = PhysToVirt(fpdata); | |
2515 | 217 if(!check_str(data->OemStringPtr)) data->OemStringPtr = NULL; |
2294 | 218 #ifdef HAVE_VERBOSE_VAR |
2407 | 219 if(verbose > 1) |
220 { | |
221 printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr); | |
2515 | 222 if(data->OemStringPtr) print_str(data->OemStringPtr); |
2518 | 223 fflush(stdout); |
2407 | 224 } |
2294 | 225 #endif |
2243 | 226 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16; |
227 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff; | |
228 data->VideoModePtr = PhysToVirt(fpdata); | |
2515 | 229 if(!check_wrd(data->VideoModePtr)) |
230 { | |
231 data->VideoModePtr = NULL; | |
232 retval = VBE_BROKEN_BIOS; | |
233 } | |
2294 | 234 #ifdef HAVE_VERBOSE_VAR |
2407 | 235 if(verbose > 1) |
236 { | |
237 printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr); | |
2515 | 238 if(data->VideoModePtr) print_wrd(data->VideoModePtr); |
2518 | 239 fflush(stdout); |
2407 | 240 } |
2294 | 241 #endif |
2243 | 242 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16; |
243 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff; | |
244 data->OemVendorNamePtr = PhysToVirt(fpdata); | |
2515 | 245 if(!check_str(data->OemVendorNamePtr)) data->OemVendorNamePtr = NULL; |
2294 | 246 #ifdef HAVE_VERBOSE_VAR |
2407 | 247 if(verbose > 1) |
248 { | |
249 printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr); | |
2515 | 250 if(data->OemVendorNamePtr) print_str(data->OemVendorNamePtr); |
2518 | 251 fflush(stdout); |
2407 | 252 } |
2294 | 253 #endif |
2243 | 254 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16; |
255 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff; | |
256 data->OemProductNamePtr = PhysToVirt(fpdata); | |
2515 | 257 if(!check_str(data->OemProductNamePtr)) data->OemProductNamePtr = NULL; |
2294 | 258 #ifdef HAVE_VERBOSE_VAR |
2407 | 259 if(verbose > 1) |
260 { | |
261 printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr); | |
2515 | 262 if(data->OemVendorNamePtr) print_str(data->OemProductNamePtr); |
2518 | 263 fflush(stdout); |
2407 | 264 } |
2294 | 265 #endif |
2243 | 266 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16; |
267 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff; | |
268 data->OemProductRevPtr = PhysToVirt(fpdata); | |
2515 | 269 if(!check_str(data->OemProductRevPtr)) data->OemProductRevPtr = NULL; |
2294 | 270 #ifdef HAVE_VERBOSE_VAR |
2407 | 271 if(verbose > 1) |
272 { | |
273 printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr); | |
2515 | 274 if(data->OemProductRevPtr) print_str(data->OemProductRevPtr); |
2518 | 275 fflush(stdout); |
2407 | 276 } |
2294 | 277 #endif |
2243 | 278 } |
279 return retval; | |
280 } | |
281 | |
282 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data) | |
283 { | |
284 struct LRMI_regs r; | |
285 void *rm_space; | |
286 int retval; | |
287 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
288 memset(&r,0,sizeof(struct LRMI_regs)); | |
289 r.eax = 0x4f01; | |
290 r.ecx = mode; | |
291 r.es = VirtToPhysSeg(rm_space); | |
292 r.edi = VirtToPhysOff(rm_space); | |
2294 | 293 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 294 { |
295 LRMI_free_real(rm_space); | |
296 return VBE_VM86_FAIL; | |
297 } | |
298 retval = r.eax & 0xffff; | |
299 if(retval == 0x4f) | |
300 { | |
301 retval = VBE_OK; | |
302 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock)); | |
303 } | |
304 return retval; | |
305 } | |
306 | |
307 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data) | |
308 { | |
309 struct LRMI_regs r; | |
310 void *rm_space = NULL; | |
311 int retval; | |
312 memset(&r,0,sizeof(struct LRMI_regs)); | |
313 if(data) | |
314 { | |
315 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
316 r.es = VirtToPhysSeg(rm_space); | |
317 r.edi = VirtToPhysOff(rm_space); | |
318 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock)); | |
319 } | |
320 r.eax = 0x4f02; | |
321 r.ebx = mode; | |
2294 | 322 retval = VBE_LRMI_int(0x10,&r); |
2243 | 323 if(rm_space) LRMI_free_real(rm_space); |
324 if(!retval) return VBE_VM86_FAIL; | |
325 retval = r.eax & 0xffff; | |
2632 | 326 if(retval == 0x4f) |
327 { | |
328 /* Just info for internal use (currently in SetDiplayStart func). */ | |
329 vbeGetModeInfo(mode&0x1f,&curr_mode_info); | |
330 retval = VBE_OK; | |
331 } | |
2243 | 332 return retval; |
333 } | |
334 | |
335 int vbeGetMode(unsigned *mode) | |
336 { | |
337 struct LRMI_regs r; | |
338 int retval; | |
339 memset(&r,0,sizeof(struct LRMI_regs)); | |
340 r.eax = 0x4f03; | |
2294 | 341 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 342 retval = r.eax & 0xffff; |
343 if(retval == 0x4f) | |
344 { | |
345 *mode = r.ebx; | |
346 retval = VBE_OK; | |
347 } | |
348 return retval; | |
349 } | |
350 | |
351 int vbeSaveState(void **data) | |
352 { | |
353 struct LRMI_regs r; | |
354 int retval; | |
355 void *rm_space; | |
356 memset(&r,0,sizeof(struct LRMI_regs)); | |
357 r.eax = 0x4f04; | |
358 r.edx = 0x00; | |
359 r.ecx = 0x0f; | |
2294 | 360 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 361 retval = r.eax & 0xffff; |
362 if(retval != 0x4f) return retval; | |
363 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM; | |
364 r.eax = 0x4f04; | |
365 r.edx = 0x01; | |
366 r.ecx = 0x0f; | |
367 r.es = VirtToPhysSeg(rm_space); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
368 r.ebx = VirtToPhysOff(rm_space); |
2294 | 369 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 370 { |
371 LRMI_free_real(rm_space); | |
372 return VBE_VM86_FAIL; | |
373 } | |
374 retval = r.eax & 0xffff; | |
375 if(retval != 0x4f) | |
376 { | |
377 LRMI_free_real(rm_space); | |
378 return retval; | |
379 } | |
380 *data = rm_space; | |
381 return VBE_OK; | |
382 } | |
383 | |
384 int vbeRestoreState(void *data) | |
385 { | |
386 struct LRMI_regs r; | |
387 int retval; | |
388 memset(&r,0,sizeof(struct LRMI_regs)); | |
389 r.eax = 0x4f04; | |
390 r.edx = 0x02; | |
391 r.ecx = 0x0f; | |
392 r.es = VirtToPhysSeg(data); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
393 r.ebx = VirtToPhysOff(data); |
2294 | 394 retval = VBE_LRMI_int(0x10,&r); |
2243 | 395 LRMI_free_real(data); |
396 if(!retval) return VBE_VM86_FAIL; | |
397 retval = r.eax & 0xffff; | |
398 if(retval == 0x4f) retval = VBE_OK; | |
399 return retval; | |
400 } | |
401 | |
402 int vbeGetWindow(unsigned *win_num) | |
403 { | |
404 struct LRMI_regs r; | |
405 int retval; | |
406 memset(&r,0,sizeof(struct LRMI_regs)); | |
407 r.eax = 0x4f05; | |
408 r.ebx = (*win_num & 0x0f) | 0x0100; | |
2294 | 409 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 410 retval = r.eax & 0xffff; |
411 if(retval == 0x4f) | |
412 { | |
413 *win_num = r.edx & 0xffff; | |
414 retval = VBE_OK; | |
415 } | |
416 return retval; | |
417 } | |
418 | |
419 int vbeSetWindow(unsigned win_num,unsigned win_gran) | |
420 { | |
421 int retval; | |
422 if(vbe_pm_info.SetWindowCall) | |
423 { | |
2294 | 424 /* Don't verbose this stuff from performance reasons */ |
2243 | 425 /* 32-bit function call is much better of int 10h */ |
426 __asm __volatile( | |
427 "pushl %%ebx\n" | |
428 "movl %1, %%ebx\n" | |
429 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory"); | |
430 (*vbe_pm_info.SetWindowCall)(); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
431 __asm __volatile("popl %%ebx":::"memory"); |
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
432 retval = VBE_OK; |
2243 | 433 } |
434 else | |
435 { | |
436 struct LRMI_regs r; | |
437 memset(&r,0,sizeof(struct LRMI_regs)); | |
438 r.eax = 0x4f05; | |
439 r.ebx = win_num & 0x0f; | |
440 r.edx = win_gran; | |
2294 | 441 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 442 retval = r.eax & 0xffff; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
443 if(retval == 0x4f) retval = VBE_OK; |
2243 | 444 } |
445 return retval; | |
446 } | |
447 | |
2632 | 448 int vbeGetScanLineLength(unsigned *num_pixels,unsigned *num_bytes) |
449 { | |
450 struct LRMI_regs r; | |
451 int retval; | |
452 memset(&r,0,sizeof(struct LRMI_regs)); | |
453 r.eax = 0x4f06; | |
454 r.ebx = 1; | |
455 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
456 retval = r.eax & 0xffff; | |
457 if(retval == 0x4f) | |
458 { | |
459 if(num_bytes) *num_bytes = r.ebx & 0xffff; | |
460 if(num_pixels) *num_pixels= r.ecx & 0xffff; | |
461 retval = VBE_OK; | |
462 } | |
463 return retval; | |
464 } | |
465 | |
466 int vbeGetMaxScanLines(unsigned *num_pixels,unsigned *num_bytes, unsigned *num_lines) | |
467 { | |
468 struct LRMI_regs r; | |
469 int retval; | |
470 memset(&r,0,sizeof(struct LRMI_regs)); | |
471 r.eax = 0x4f06; | |
472 r.ebx = 3; | |
473 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
474 retval = r.eax & 0xffff; | |
475 if(retval == 0x4f) | |
476 { | |
477 if(num_bytes) *num_bytes = r.ebx & 0xffff; | |
478 if(num_pixels) *num_pixels= r.ecx & 0xffff; | |
479 if(num_lines) *num_lines = r.edx & 0xffff; | |
480 retval = VBE_OK; | |
481 } | |
482 return retval; | |
483 } | |
484 | |
485 int vbeSetScanLineLength(unsigned num_pixels) | |
486 { | |
487 int retval; | |
488 struct LRMI_regs r; | |
489 memset(&r,0,sizeof(struct LRMI_regs)); | |
490 r.eax = 0x4f06; | |
491 r.ebx = 0; | |
492 r.ecx = num_pixels; | |
493 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
494 retval = r.eax & 0xffff; | |
495 if(retval == 0x4f) retval = VBE_OK; | |
496 return retval; | |
497 } | |
498 | |
499 int vbeSetScanLineLengthB(unsigned num_bytes) | |
500 { | |
501 int retval; | |
502 struct LRMI_regs r; | |
503 memset(&r,0,sizeof(struct LRMI_regs)); | |
504 r.eax = 0x4f06; | |
505 r.ebx = 2; | |
506 r.ecx = num_bytes; | |
507 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
508 retval = r.eax & 0xffff; | |
509 if(retval == 0x4f) retval = VBE_OK; | |
510 return retval; | |
511 } | |
512 | |
513 int vbeGetDisplayStart(unsigned *pixel_num,unsigned *scan_line) | |
514 { | |
515 struct LRMI_regs r; | |
516 int retval; | |
517 memset(&r,0,sizeof(struct LRMI_regs)); | |
518 r.eax = 0x4f07; | |
519 r.ebx = 1; | |
520 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
521 retval = r.eax & 0xffff; | |
522 if(retval == 0x4f) | |
523 { | |
524 if(pixel_num) *pixel_num = r.ecx & 0xffff; | |
525 if(scan_line) *scan_line = r.edx & 0xffff; | |
526 retval = VBE_OK; | |
527 } | |
528 return retval; | |
529 } | |
530 | |
531 int vbeSetDisplayStart(unsigned long offset, int vsync) | |
532 { | |
533 int retval; | |
534 if(vbe_pm_info.SetDisplayStart) | |
535 { | |
536 /* Don't verbose this stuff from performance reasons */ | |
537 /* 32-bit function call is much better of int 10h */ | |
538 __asm __volatile( | |
539 "pushl %%ebx\n" | |
540 "movl %1, %%ebx\n" | |
541 ::"a"(0x4f07),"S"(vsync ? 0x80 : 0), | |
2686 | 542 "c"((offset>>2) & 0xffff),"d"((offset>>18)&0xffff):"memory"); |
2632 | 543 (*vbe_pm_info.SetDisplayStart)(); |
544 __asm __volatile("popl %%ebx":::"memory"); | |
545 retval = VBE_OK; | |
546 } | |
547 else | |
548 { | |
2686 | 549 #if 0 |
550 /* Something wrong here */ | |
2632 | 551 struct LRMI_regs r; |
552 unsigned long pixel_num; | |
553 memset(&r,0,sizeof(struct LRMI_regs)); | |
2686 | 554 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine; |
555 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++; | |
2632 | 556 r.eax = 0x4f07; |
2693 | 557 r.ebx = vsync ? 0x82 : 2; |
2632 | 558 r.ecx = pixel_num; |
559 r.edx = offset/(unsigned long)curr_mode_info.BytesPerScanLine; | |
560 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
561 retval = r.eax & 0xffff; | |
562 if(retval == 0x4f) retval = VBE_OK; | |
2686 | 563 #endif |
564 retval = VBE_BROKEN_BIOS; | |
2632 | 565 } |
566 return retval; | |
567 } | |
568 | |
2693 | 569 int vbeSetScheduledDisplayStart(unsigned long offset, int vsync) |
570 { | |
571 int retval; | |
572 struct LRMI_regs r; | |
573 unsigned long pixel_num; | |
574 memset(&r,0,sizeof(struct LRMI_regs)); | |
575 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine; | |
576 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++; | |
577 r.eax = 0x4f07; | |
578 r.ebx = vsync ? 0x82 : 2; | |
579 r.ecx = offset; | |
580 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
581 retval = r.eax & 0xffff; | |
582 if(retval == 0x4f) retval = VBE_OK; | |
583 return retval; | |
584 } | |
585 | |
2243 | 586 struct realVesaProtModeInterface |
587 { | |
588 unsigned short SetWindowCall; | |
589 unsigned short SetDisplayStart; | |
590 unsigned short SetPaletteData; | |
591 unsigned short iopl_ports; | |
592 }__attribute__((packed)); | |
593 | |
594 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info) | |
595 { | |
596 struct LRMI_regs r; | |
597 int retval; | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
598 unsigned info_offset; |
2243 | 599 struct realVesaProtModeInterface *rm_info; |
600 memset(&r,0,sizeof(struct LRMI_regs)); | |
601 r.eax = 0x4f0a; | |
602 r.ebx = 0; | |
2294 | 603 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 604 retval = r.eax & 0xffff; |
605 if(retval == 0x4f) | |
606 { | |
2407 | 607 retval = VBE_OK; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
608 info_offset = r.edi&0xffff; |
2407 | 609 if((r.es >> 12) != hh_int_10_seg) retval = VBE_BROKEN_BIOS; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
610 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
|
611 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall); |
2552 | 612 if(!is_addr_valid(pm_info->SetWindowCall)) retval = VBE_BROKEN_BIOS; |
2294 | 613 #ifdef HAVE_VERBOSE_VAR |
614 if(verbose > 1) printf("vbelib: SetWindowCall=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetWindowCall,pm_info->SetWindowCall); | |
615 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
616 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart); |
2552 | 617 if(!is_addr_valid(pm_info->SetDisplayStart)) retval = VBE_BROKEN_BIOS; |
2294 | 618 #ifdef HAVE_VERBOSE_VAR |
619 if(verbose > 1) printf("vbelib: SetDisplayStart=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetDisplayStart,pm_info->SetDisplayStart); | |
620 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
621 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData); |
2552 | 622 if(!is_addr_valid(pm_info->SetPaletteData)) retval = VBE_BROKEN_BIOS; |
2294 | 623 #ifdef HAVE_VERBOSE_VAR |
624 if(verbose > 1) printf("vbelib: SetPaletteData=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetPaletteData,pm_info->SetPaletteData); | |
625 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
626 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports); |
2515 | 627 if(!check_wrd(pm_info->iopl_ports)) |
628 { | |
629 pm_info->iopl_ports = NULL; | |
630 retval = VBE_BROKEN_BIOS; | |
631 } | |
2294 | 632 #ifdef HAVE_VERBOSE_VAR |
2407 | 633 if(verbose > 1) |
634 { | |
635 printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports); | |
2515 | 636 if(pm_info->iopl_ports) print_wrd(pm_info->iopl_ports); |
2518 | 637 fflush(stdout); |
2407 | 638 } |
2294 | 639 #endif |
2243 | 640 } |
641 return retval; | |
642 } | |
2410 | 643 /* --------- Standard VGA stuff -------------- */ |
644 int vbeWriteString(int x, int y, int attr, char *str) | |
645 { | |
646 struct LRMI_regs r; | |
647 void *rm_space = NULL; | |
648 int retval; | |
649 memset(&r,0,sizeof(struct LRMI_regs)); | |
650 r.ecx = strlen(str); | |
651 r.edx = ((y<<8)&0xff00)|(x&0xff); | |
652 r.ebx = attr; | |
653 if(!(rm_space = LRMI_alloc_real(r.ecx))) return VBE_OUT_OF_DOS_MEM; | |
654 r.es = VirtToPhysSeg(rm_space); | |
655 r.ebp = VirtToPhysOff(rm_space); | |
656 memcpy(rm_space,str,r.ecx); | |
657 r.eax = 0x1300; | |
658 retval = VBE_LRMI_int(0x10,&r); | |
659 if(rm_space) LRMI_free_real(rm_space); | |
660 if(!retval) return VBE_VM86_FAIL; | |
661 retval = r.eax & 0xffff; | |
662 if(retval == 0x4f) retval = VBE_OK; | |
663 return retval; | |
2460 | 664 } |
2610 | 665 |
666 void * vbeMapVideoBuffer(unsigned long phys_addr,unsigned long size) | |
667 { | |
668 void *lfb; | |
669 if(fd_mem == -1) return NULL; | |
670 if(verbose > 1) printf("vbelib: vbeMapVideoBuffer(%08lX,%08lX)\n",phys_addr,size); | |
671 /* Here we don't need with MAP_FIXED and prefered address (first argument) */ | |
672 lfb = mmap((void *)0,size,PROT_READ | PROT_WRITE,MAP_SHARED,fd_mem,phys_addr); | |
673 return lfb == (void *)-1 ? 0 : lfb; | |
674 } | |
675 | |
676 void vbeUnmapVideoBuffer(unsigned long linear_addr,unsigned long size) | |
677 { | |
678 if(verbose > 1) printf("vbelib: vbeUnmapVideoBuffer(%08lX,%08lX)\n",linear_addr,size); | |
679 munmap((void *)linear_addr,size); | |
680 } |