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