Mercurial > mplayer.hg
annotate linux/vbelib.c @ 2315:c3c73ba53f0e
streaming fixed
author | arpi |
---|---|
date | Sat, 20 Oct 2001 20:35:12 +0000 |
parents | 9475a75dde9c |
children | ee6ef0b10655 |
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 { | |
59 if(!LRMI_init()) return VBE_VM86_FAIL; | |
60 /* | |
61 Allow read/write to ALL io ports | |
62 */ | |
63 ioperm(0, 1024, 1); | |
64 iopl(3); | |
65 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface)); | |
66 vbeGetProtModeInfo(&vbe_pm_info); | |
67 return VBE_OK; | |
68 } | |
69 | |
70 int vbeDestroy( void ) { return VBE_OK; } | |
71 | |
72 int vbeGetControllerInfo(struct VbeInfoBlock *data) | |
73 { | |
74 struct LRMI_regs r; | |
75 void *rm_space; | |
76 int retval; | |
77 if(!(rm_space = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
78 memcpy(rm_space,data,sizeof(struct VbeInfoBlock)); | |
79 memset(&r,0,sizeof(struct LRMI_regs)); | |
80 r.eax = 0x4f00; | |
81 r.es = VirtToPhysSeg(rm_space); | |
82 r.edi = VirtToPhysOff(rm_space); | |
2294 | 83 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 84 { |
85 LRMI_free_real(rm_space); | |
86 return VBE_VM86_FAIL; | |
87 } | |
88 retval = r.eax & 0xffff; | |
89 if(retval == 0x4f) | |
90 { | |
91 FarPtr fpdata; | |
92 retval = VBE_OK; | |
93 memcpy(data,rm_space,sizeof(struct VbeInfoBlock)); | |
94 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16; | |
95 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff; | |
96 data->OemStringPtr = PhysToVirt(fpdata); | |
2294 | 97 #ifdef HAVE_VERBOSE_VAR |
98 if(verbose > 1) printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr); | |
99 #endif | |
2243 | 100 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16; |
101 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff; | |
102 data->VideoModePtr = PhysToVirt(fpdata); | |
2294 | 103 #ifdef HAVE_VERBOSE_VAR |
104 if(verbose > 1) printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr); | |
105 #endif | |
2243 | 106 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16; |
107 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff; | |
108 data->OemVendorNamePtr = PhysToVirt(fpdata); | |
2294 | 109 #ifdef HAVE_VERBOSE_VAR |
110 if(verbose > 1) printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr); | |
111 #endif | |
2243 | 112 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16; |
113 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff; | |
114 data->OemProductNamePtr = PhysToVirt(fpdata); | |
2294 | 115 #ifdef HAVE_VERBOSE_VAR |
116 if(verbose > 1) printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr); | |
117 #endif | |
2243 | 118 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16; |
119 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff; | |
120 data->OemProductRevPtr = PhysToVirt(fpdata); | |
2294 | 121 #ifdef HAVE_VERBOSE_VAR |
122 if(verbose > 1) printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr); | |
123 #endif | |
2243 | 124 } |
125 return retval; | |
126 } | |
127 | |
128 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data) | |
129 { | |
130 struct LRMI_regs r; | |
131 void *rm_space; | |
132 int retval; | |
133 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
134 memset(&r,0,sizeof(struct LRMI_regs)); | |
135 r.eax = 0x4f01; | |
136 r.ecx = mode; | |
137 r.es = VirtToPhysSeg(rm_space); | |
138 r.edi = VirtToPhysOff(rm_space); | |
2294 | 139 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 140 { |
141 LRMI_free_real(rm_space); | |
142 return VBE_VM86_FAIL; | |
143 } | |
144 retval = r.eax & 0xffff; | |
145 if(retval == 0x4f) | |
146 { | |
147 retval = VBE_OK; | |
148 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock)); | |
149 } | |
150 return retval; | |
151 } | |
152 | |
153 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data) | |
154 { | |
155 struct LRMI_regs r; | |
156 void *rm_space = NULL; | |
157 int retval; | |
158 memset(&r,0,sizeof(struct LRMI_regs)); | |
159 if(data) | |
160 { | |
161 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
162 r.es = VirtToPhysSeg(rm_space); | |
163 r.edi = VirtToPhysOff(rm_space); | |
164 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock)); | |
165 } | |
166 r.eax = 0x4f02; | |
167 r.ebx = mode; | |
2294 | 168 retval = VBE_LRMI_int(0x10,&r); |
2243 | 169 if(rm_space) LRMI_free_real(rm_space); |
170 if(!retval) return VBE_VM86_FAIL; | |
171 retval = r.eax & 0xffff; | |
172 if(retval == 0x4f) retval = VBE_OK; | |
173 return retval; | |
174 } | |
175 | |
176 int vbeGetMode(unsigned *mode) | |
177 { | |
178 struct LRMI_regs r; | |
179 int retval; | |
180 memset(&r,0,sizeof(struct LRMI_regs)); | |
181 r.eax = 0x4f03; | |
2294 | 182 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 183 retval = r.eax & 0xffff; |
184 if(retval == 0x4f) | |
185 { | |
186 *mode = r.ebx; | |
187 retval = VBE_OK; | |
188 } | |
189 return retval; | |
190 } | |
191 | |
192 int vbeSaveState(void **data) | |
193 { | |
194 struct LRMI_regs r; | |
195 int retval; | |
196 void *rm_space; | |
197 memset(&r,0,sizeof(struct LRMI_regs)); | |
198 r.eax = 0x4f04; | |
199 r.edx = 0x00; | |
200 r.ecx = 0x0f; | |
2294 | 201 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 202 retval = r.eax & 0xffff; |
203 if(retval != 0x4f) return retval; | |
204 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM; | |
205 r.eax = 0x4f04; | |
206 r.edx = 0x01; | |
207 r.ecx = 0x0f; | |
208 r.es = VirtToPhysSeg(rm_space); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
209 r.ebx = VirtToPhysOff(rm_space); |
2294 | 210 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 211 { |
212 LRMI_free_real(rm_space); | |
213 return VBE_VM86_FAIL; | |
214 } | |
215 retval = r.eax & 0xffff; | |
216 if(retval != 0x4f) | |
217 { | |
218 LRMI_free_real(rm_space); | |
219 return retval; | |
220 } | |
221 *data = rm_space; | |
222 return VBE_OK; | |
223 } | |
224 | |
225 int vbeRestoreState(void *data) | |
226 { | |
227 struct LRMI_regs r; | |
228 int retval; | |
229 void *rm_space; | |
230 memset(&r,0,sizeof(struct LRMI_regs)); | |
231 r.eax = 0x4f04; | |
232 r.edx = 0x02; | |
233 r.ecx = 0x0f; | |
234 r.es = VirtToPhysSeg(data); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
235 r.ebx = VirtToPhysOff(data); |
2294 | 236 retval = VBE_LRMI_int(0x10,&r); |
2243 | 237 LRMI_free_real(data); |
238 if(!retval) return VBE_VM86_FAIL; | |
239 retval = r.eax & 0xffff; | |
240 if(retval == 0x4f) retval = VBE_OK; | |
241 return retval; | |
242 } | |
243 | |
244 int vbeGetWindow(unsigned *win_num) | |
245 { | |
246 struct LRMI_regs r; | |
247 int retval; | |
248 memset(&r,0,sizeof(struct LRMI_regs)); | |
249 r.eax = 0x4f05; | |
250 r.ebx = (*win_num & 0x0f) | 0x0100; | |
2294 | 251 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 252 retval = r.eax & 0xffff; |
253 if(retval == 0x4f) | |
254 { | |
255 *win_num = r.edx & 0xffff; | |
256 retval = VBE_OK; | |
257 } | |
258 return retval; | |
259 } | |
260 | |
261 int vbeSetWindow(unsigned win_num,unsigned win_gran) | |
262 { | |
263 int retval; | |
264 if(vbe_pm_info.SetWindowCall) | |
265 { | |
2294 | 266 /* Don't verbose this stuff from performance reasons */ |
2243 | 267 /* 32-bit function call is much better of int 10h */ |
268 __asm __volatile( | |
269 "pushl %%ebx\n" | |
270 "movl %1, %%ebx\n" | |
271 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory"); | |
272 (*vbe_pm_info.SetWindowCall)(); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
273 __asm __volatile("popl %%ebx":::"memory"); |
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
274 retval = VBE_OK; |
2243 | 275 } |
276 else | |
277 { | |
278 struct LRMI_regs r; | |
279 memset(&r,0,sizeof(struct LRMI_regs)); | |
280 r.eax = 0x4f05; | |
281 r.ebx = win_num & 0x0f; | |
282 r.edx = win_gran; | |
2294 | 283 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 284 retval = r.eax & 0xffff; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
285 if(retval == 0x4f) retval = VBE_OK; |
2243 | 286 } |
287 return retval; | |
288 } | |
289 | |
290 struct realVesaProtModeInterface | |
291 { | |
292 unsigned short SetWindowCall; | |
293 unsigned short SetDisplayStart; | |
294 unsigned short SetPaletteData; | |
295 unsigned short iopl_ports; | |
296 }__attribute__((packed)); | |
297 | |
298 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info) | |
299 { | |
300 struct LRMI_regs r; | |
301 int retval; | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
302 unsigned info_offset; |
2243 | 303 struct realVesaProtModeInterface *rm_info; |
304 memset(&r,0,sizeof(struct LRMI_regs)); | |
305 r.eax = 0x4f0a; | |
306 r.ebx = 0; | |
2294 | 307 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 308 retval = r.eax & 0xffff; |
309 if(retval == 0x4f) | |
310 { | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
311 info_offset = r.edi&0xffff; |
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
312 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
|
313 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall); |
2294 | 314 #ifdef HAVE_VERBOSE_VAR |
315 if(verbose > 1) printf("vbelib: SetWindowCall=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetWindowCall,pm_info->SetWindowCall); | |
316 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
317 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart); |
2294 | 318 #ifdef HAVE_VERBOSE_VAR |
319 if(verbose > 1) printf("vbelib: SetDisplayStart=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetDisplayStart,pm_info->SetDisplayStart); | |
320 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
321 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData); |
2294 | 322 #ifdef HAVE_VERBOSE_VAR |
323 if(verbose > 1) printf("vbelib: SetPaletteData=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetPaletteData,pm_info->SetPaletteData); | |
324 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
325 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports); |
2294 | 326 #ifdef HAVE_VERBOSE_VAR |
327 if(verbose > 1) printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports); | |
328 #endif | |
2243 | 329 retval = VBE_OK; |
330 } | |
331 return retval; | |
332 } |