annotate linux/vbelib.c @ 2555:66837325b929

config.h cleanup, few things added to steram/demuxer headers
author arpi
date Tue, 30 Oct 2001 17:03:11 +0000
parents bd734d41a407
children 65cb69a90a9f
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>
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
16 #include <ctype.h>
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
17
f4b588dba08a vbelib import
nick
parents:
diff changeset
18 static struct VesaProtModeInterface vbe_pm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
19
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
20 static inline int VERR(const void *p)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
21 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
22 register int retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
23 __asm __volatile(
622cd80caaba memory verification
nick
parents: 2460
diff changeset
24 "xorl %0, %0\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
25 "verr %1\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
26 "setnz %b0"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
27 :"=r"(retval)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
28 :"m"(*(unsigned char *)p)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
29 :"memory");
622cd80caaba memory verification
nick
parents: 2460
diff changeset
30 return retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
31 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
32
622cd80caaba memory verification
nick
parents: 2460
diff changeset
33 #if 0
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
34 static inline int VERW(const void *p)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
35 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
36 register int retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
37 __asm __volatile(
622cd80caaba memory verification
nick
parents: 2460
diff changeset
38 "xorl %0, %0\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
39 "verw %1\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
40 "setnz %b0"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
41 :"=r"(retval)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
42 :"m"(*(unsigned char *)p)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
43 :"memory");
622cd80caaba memory verification
nick
parents: 2460
diff changeset
44 return retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
45 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
46 #endif
622cd80caaba memory verification
nick
parents: 2460
diff changeset
47
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
48 #define HAVE_VERBOSE_VAR 1
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
49
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
50 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
51 extern int verbose;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
52
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
53 static void __dump_regs(struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
54 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
55 printf("vbelib: eax=%08lXh ebx=%08lXh ecx=%08lXh edx=%08lXh\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
56 "vbelib: edi=%08lXh esi=%08lXh ebp=%08lXh esp=%08lXh\n"
2445
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
57 "vbelib: ds=%04Xh es=%04Xh ss=%04Xh cs:ip=%04X:%04X\n"
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
58 "vbelib: fs=%04Xh gs=%04Xh ss:sp=%04X:%04X flags=%04X\n"
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
59 ,(unsigned long)r->eax,(unsigned long)r->ebx,(unsigned long)r->ecx,(unsigned long)r->edx
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
60 ,(unsigned long)r->edi,(unsigned long)r->esi,(unsigned long)r->ebp,(unsigned long)r->reserved
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
61 ,r->ds,r->es,r->ss,r->cs,r->ip
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
62 ,r->fs,r->gs,r->ss,r->sp,r->flags);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
63 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
64
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
65 static inline int VBE_LRMI_int(int int_no, struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
66 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
67 int retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
68 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
69 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
70 printf("vbelib: registers before int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
71 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
72 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
73 retval = LRMI_int(int_no,r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
74 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
75 {
2445
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
76 printf("vbelib: Interrupt handler returns: %X\n",retval);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
77 printf("vbelib: registers after int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
78 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
79 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
80 return retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
81 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
82 #else
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
83 #define VBE_LRMI_int(int_no,regs) (VBE_LRMI_int(int_no,regs))
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
84 #endif
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
85
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
86 static unsigned hh_int_10_seg;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
87 int vbeInit( void )
f4b588dba08a vbelib import
nick
parents:
diff changeset
88 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
89 unsigned short iopl_port;
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
90 size_t i;
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
91 int retval;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
92 if(!LRMI_init()) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
93 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
94 Allow read/write to ALL io ports
f4b588dba08a vbelib import
nick
parents:
diff changeset
95 */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
96 hh_int_10_seg = *(unsigned short *)PhysToVirtSO(0x0000,0x0042);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
97 /* Video BIOS should be at C000:0000 and above */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
98 hh_int_10_seg >>= 12;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
99 if(hh_int_10_seg < 0xC) return VBE_BROKEN_BIOS;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
100 ioperm(0, 1024, 1);
f4b588dba08a vbelib import
nick
parents:
diff changeset
101 iopl(3);
f4b588dba08a vbelib import
nick
parents:
diff changeset
102 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface));
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
103 retval = vbeGetProtModeInfo(&vbe_pm_info);
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
104 if(retval != VBE_OK) return retval;
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
105 i = 0;
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
106 while((iopl_port=vbe_pm_info.iopl_ports[i]) != 0xFFFF
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
107 && vbe_pm_info.iopl_ports[i++] > 1023) ioperm(iopl_port,1,1);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
108 iopl(3);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
109 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
110 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
111
f4b588dba08a vbelib import
nick
parents:
diff changeset
112 int vbeDestroy( void ) { return VBE_OK; }
f4b588dba08a vbelib import
nick
parents:
diff changeset
113
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
114 /* Fixme!!! This code is compatible only with mplayer's version of lrmi*/
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
115 static inline int is_addr_valid(const void *p)
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
116 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
117 return (p < (const void *)0x502) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
118 (p >= (const void *)0x10000 && p < (const void *)0x20000) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
119 (p >= (const void *)0xa0000 && p < (const void *)0x100000);
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
120 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
121
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
122 static int check_str(const unsigned char *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
123 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
124 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
125 int null_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
126 for(i = 0;i < 256;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
127 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
128 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
129 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
130 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
131 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
132 if(!str[i]) { null_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
133 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
134 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
135 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
136 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
137 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
138 return null_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
139 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
140
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
141 static int check_wrd(const unsigned short *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
142 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
143 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
144 int ffff_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
145 for(i = 0;i < 1024;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
146 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
147 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
148 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
149 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
150 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
151 if(str[i] == 0xffff) { ffff_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
152 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
153 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
154 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
155 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
156 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
157 return ffff_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
158 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
159
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
160 static void print_str(unsigned char *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
161 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
162 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
163 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
164 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
165 for(i = 0;i < 256;i++) { printf("%02X(%c) ",str[i],isprint(str[i])?str[i]:'.'); if(!str[i]) break; }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
166 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
167 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
168 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
169
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
170 static void print_wrd(unsigned short *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
171 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
172 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
173 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
174 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
175 for(i = 0;i < 256;i++) { printf("%04X ",str[i]); if(str[i] == 0xffff) break; }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
176 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
177 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
178 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
179
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
180 int vbeGetControllerInfo(struct VbeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
181 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
182 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
183 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
184 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
185 if(!(rm_space = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
186 memcpy(rm_space,data,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
187 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
188 r.eax = 0x4f00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
189 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
190 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
191 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
192 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
193 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
194 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
195 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
196 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
197 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
198 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
199 FarPtr fpdata;
f4b588dba08a vbelib import
nick
parents:
diff changeset
200 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
201 memcpy(data,rm_space,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
202 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
203 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
204 data->OemStringPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
205 if(!check_str(data->OemStringPtr)) data->OemStringPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
206 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
207 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
208 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
209 printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
210 if(data->OemStringPtr) print_str(data->OemStringPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
211 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
212 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
213 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
214 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
215 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
216 data->VideoModePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
217 if(!check_wrd(data->VideoModePtr))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
218 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
219 data->VideoModePtr = NULL;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
220 retval = VBE_BROKEN_BIOS;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
221 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
222 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
223 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
224 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
225 printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
226 if(data->VideoModePtr) print_wrd(data->VideoModePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
227 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
228 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
229 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
230 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
231 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
232 data->OemVendorNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
233 if(!check_str(data->OemVendorNamePtr)) data->OemVendorNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
234 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
235 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
236 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
237 printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
238 if(data->OemVendorNamePtr) print_str(data->OemVendorNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
239 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
240 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
241 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
242 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
243 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
244 data->OemProductNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
245 if(!check_str(data->OemProductNamePtr)) data->OemProductNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
246 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
247 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
248 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
249 printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
250 if(data->OemVendorNamePtr) print_str(data->OemProductNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
251 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
252 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
253 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
254 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
255 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
256 data->OemProductRevPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
257 if(!check_str(data->OemProductRevPtr)) data->OemProductRevPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
258 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
259 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
260 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
261 printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
262 if(data->OemProductRevPtr) print_str(data->OemProductRevPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
263 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
264 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
265 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
266 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
267 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
268 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
269
f4b588dba08a vbelib import
nick
parents:
diff changeset
270 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
271 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
272 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
273 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
274 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
275 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
276 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
277 r.eax = 0x4f01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
278 r.ecx = mode;
f4b588dba08a vbelib import
nick
parents:
diff changeset
279 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
280 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
281 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
282 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
283 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
284 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
285 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
286 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
287 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
288 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
289 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
290 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
291 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
292 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
293 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
294
f4b588dba08a vbelib import
nick
parents:
diff changeset
295 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
296 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
297 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
298 void *rm_space = NULL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
299 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
300 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
301 if(data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
302 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
303 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
304 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
305 r.edi = VirtToPhysOff(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
306 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
307 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
308 r.eax = 0x4f02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
309 r.ebx = mode;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
310 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
311 if(rm_space) LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
312 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
313 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
314 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
315 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
316 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
317
f4b588dba08a vbelib import
nick
parents:
diff changeset
318 int vbeGetMode(unsigned *mode)
f4b588dba08a vbelib import
nick
parents:
diff changeset
319 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
320 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
321 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
322 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
323 r.eax = 0x4f03;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
324 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
325 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
326 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
327 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
328 *mode = r.ebx;
f4b588dba08a vbelib import
nick
parents:
diff changeset
329 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
330 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
331 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
332 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
333
f4b588dba08a vbelib import
nick
parents:
diff changeset
334 int vbeSaveState(void **data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
335 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
336 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
337 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
338 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
339 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
340 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
341 r.edx = 0x00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
342 r.ecx = 0x0f;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
343 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
344 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
345 if(retval != 0x4f) return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
346 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
347 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
348 r.edx = 0x01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
349 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
350 r.es = VirtToPhysSeg(rm_space);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
351 r.ebx = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
352 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
353 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
354 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
355 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
356 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
357 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
358 if(retval != 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
359 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
360 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
361 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
362 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
363 *data = rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
364 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
365 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
366
f4b588dba08a vbelib import
nick
parents:
diff changeset
367 int vbeRestoreState(void *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
368 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
369 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
370 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
371 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
372 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
373 r.edx = 0x02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
374 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
375 r.es = VirtToPhysSeg(data);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
376 r.ebx = VirtToPhysOff(data);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
377 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
378 LRMI_free_real(data);
f4b588dba08a vbelib import
nick
parents:
diff changeset
379 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
380 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
381 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
382 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
383 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
384
f4b588dba08a vbelib import
nick
parents:
diff changeset
385 int vbeGetWindow(unsigned *win_num)
f4b588dba08a vbelib import
nick
parents:
diff changeset
386 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
387 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
388 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
389 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
390 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
391 r.ebx = (*win_num & 0x0f) | 0x0100;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
392 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
393 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
394 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
395 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
396 *win_num = r.edx & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
397 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
398 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
399 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
400 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
401
f4b588dba08a vbelib import
nick
parents:
diff changeset
402 int vbeSetWindow(unsigned win_num,unsigned win_gran)
f4b588dba08a vbelib import
nick
parents:
diff changeset
403 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
404 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
405 if(vbe_pm_info.SetWindowCall)
f4b588dba08a vbelib import
nick
parents:
diff changeset
406 {
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
407 /* Don't verbose this stuff from performance reasons */
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
408 /* 32-bit function call is much better of int 10h */
f4b588dba08a vbelib import
nick
parents:
diff changeset
409 __asm __volatile(
f4b588dba08a vbelib import
nick
parents:
diff changeset
410 "pushl %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
411 "movl %1, %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
412 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory");
f4b588dba08a vbelib import
nick
parents:
diff changeset
413 (*vbe_pm_info.SetWindowCall)();
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
414 __asm __volatile("popl %%ebx":::"memory");
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
415 retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
416 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
417 else
f4b588dba08a vbelib import
nick
parents:
diff changeset
418 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
419 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
420 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
421 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
422 r.ebx = win_num & 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
423 r.edx = win_gran;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
424 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
425 retval = r.eax & 0xffff;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
426 if(retval == 0x4f) retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
427 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
428 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
429 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
430
f4b588dba08a vbelib import
nick
parents:
diff changeset
431 struct realVesaProtModeInterface
f4b588dba08a vbelib import
nick
parents:
diff changeset
432 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
433 unsigned short SetWindowCall;
f4b588dba08a vbelib import
nick
parents:
diff changeset
434 unsigned short SetDisplayStart;
f4b588dba08a vbelib import
nick
parents:
diff changeset
435 unsigned short SetPaletteData;
f4b588dba08a vbelib import
nick
parents:
diff changeset
436 unsigned short iopl_ports;
f4b588dba08a vbelib import
nick
parents:
diff changeset
437 }__attribute__((packed));
f4b588dba08a vbelib import
nick
parents:
diff changeset
438
f4b588dba08a vbelib import
nick
parents:
diff changeset
439 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info)
f4b588dba08a vbelib import
nick
parents:
diff changeset
440 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
441 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
442 int retval;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
443 unsigned info_offset;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
444 struct realVesaProtModeInterface *rm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
445 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
446 r.eax = 0x4f0a;
f4b588dba08a vbelib import
nick
parents:
diff changeset
447 r.ebx = 0;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
448 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
449 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
450 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
451 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
452 retval = VBE_OK;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
453 info_offset = r.edi&0xffff;
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
454 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
455 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
456 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
457 if(!is_addr_valid(pm_info->SetWindowCall)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
458 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
459 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
460 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
461 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
462 if(!is_addr_valid(pm_info->SetDisplayStart)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
463 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
464 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
465 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
466 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
467 if(!is_addr_valid(pm_info->SetPaletteData)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
468 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
469 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
470 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
471 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
472 if(!check_wrd(pm_info->iopl_ports))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
473 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
474 pm_info->iopl_ports = NULL;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
475 retval = VBE_BROKEN_BIOS;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
476 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
477 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
478 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
479 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
480 printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
481 if(pm_info->iopl_ports) print_wrd(pm_info->iopl_ports);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
482 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
483 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
484 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
485 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
486 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
487 }
2410
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
488 /* --------- Standard VGA stuff -------------- */
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
489 int vbeWriteString(int x, int y, int attr, char *str)
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
490 {
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
491 struct LRMI_regs r;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
492 void *rm_space = NULL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
493 int retval;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
494 memset(&r,0,sizeof(struct LRMI_regs));
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
495 r.ecx = strlen(str);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
496 r.edx = ((y<<8)&0xff00)|(x&0xff);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
497 r.ebx = attr;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
498 if(!(rm_space = LRMI_alloc_real(r.ecx))) return VBE_OUT_OF_DOS_MEM;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
499 r.es = VirtToPhysSeg(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
500 r.ebp = VirtToPhysOff(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
501 memcpy(rm_space,str,r.ecx);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
502 r.eax = 0x1300;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
503 retval = VBE_LRMI_int(0x10,&r);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
504 if(rm_space) LRMI_free_real(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
505 if(!retval) return VBE_VM86_FAIL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
506 retval = r.eax & 0xffff;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
507 if(retval == 0x4f) retval = VBE_OK;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
508 return retval;
2460
7925f241765b Suppress trivial warnings
nick
parents: 2445
diff changeset
509 }