* VESA/VGA BIOS emulation
@ 2004-12-16 20:24 Chip Coldwell
2004-12-18 21:27 ` Chip Coldwell
0 siblings, 1 reply; 7+ messages in thread
From: Chip Coldwell @ 2004-12-16 20:24 UTC (permalink / raw)
I posted this question on comp.os.vms a few days ago, but nobody's
responded so I suspect they don't know the answer. Thus, I am trying
my luck here. If you feel this is way OT, I've got my asbestos
underpants on so let the flames begin.
The Alpha SRM console supports a PC BIOS emulation callback routine
(Alpha Architecture Reference Manual, 3rd Ed, part III sect 2.3.7.3).
I've been using this function from VMS to set VGA video modes on a
video card not currently supported by OpenVMS Alpha, and since I can
see the results on screen I know this part of my code works.
One of the arguments the BIOS_EMUL function takes is an array of
longwords that correspond to the emulated Intel x86 registers. Some
of the VESA extended BIOS functions (VBE 3.0) take parameters passed
by reference in the x86 registers, with the pointers in ES:DI using
the godawful Intel 20-bit real-mode segmented addressing scheme.[1]
My question is: how do I map from an OS virtual address to the
values in the emulated 8086 ES:DI registers?
For example, if I put the value 0x4F00 into the emulated AX register,
and a pointer to a 512 byte buffer in the ES:DI registers, then call
int 0x10, the VESA BIOS will fill in a bunch of very useful
information in the 512 byte buffer[2]. I can do all of this using the
SRM BIOS emulator callback, and I know it does something because the
AX register has the value 0x004F on return (byte-swap of the input AX
value), which the documents say indicates success.
I suspect there is a region of virtual address space set aside to
serve as memory for the x86 emulator, and that addresses I pass in the
ES:DI registers turn into offsets from the base of that region. If
that's true, then what I really need to know is what that base address
is.
The BIOS_EMUL console callback can be passed an "additional_data"
parameter in the r20 register, but putting the virtual address in there
didn't work. P0 space includes virtual addresses that fit in 20 bits, so
I tried stuffing one into the x86 segment/offset registers but that didn't
work either. I even tried doing both simultaneously.
I noticed that XFree86 solves this problem by having their own x86
emulator that runs in the OS (see the contents of "xc/extras/x86emu"
in their source distribution). This enables things like the XFree86
VESA driver to work on Alpha. I could do something similar; I could
even use the emulator that comes with XFree86 since it was there
before their license changed, but it seems a shameful duplication of
effort if the SRM console already does what I need.
I can post my code if anyone thinks that would be helpful.
Notes:
[1] The 8086 segment/offset scheme represents a 20-bit address by a 16-bit
segment register and a 16-bit offset register where the physical address
is calculated as (segment << 4) + offset. Yes, there are many
segment/offset combinations that yeild the same physical address.
[2] See http://www.vesa.org/vbe3.pdf for details.
Chip
--
Charles M. "Chip" Coldwell
System Administrator
Harvard Physics Department
617-495-3388
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-16 20:24 VESA/VGA BIOS emulation Chip Coldwell
@ 2004-12-18 21:27 ` Chip Coldwell
2004-12-18 21:50 ` Måns Rullgård
0 siblings, 1 reply; 7+ messages in thread
From: Chip Coldwell @ 2004-12-18 21:27 UTC (permalink / raw)
On Thu, 16 Dec 2004, Chip Coldwell wrote:
>
> The Alpha SRM console supports a PC BIOS emulation callback routine
> (Alpha Architecture Reference Manual, 3rd Ed, part III sect 2.3.7.3).
> I've been using this function from VMS to set VGA video modes on a
> video card not currently supported by OpenVMS Alpha, and since I can
> see the results on screen I know this part of my code works.
>
> One of the arguments the BIOS_EMUL function takes is an array of
> longwords that correspond to the emulated Intel x86 registers. Some
> of the VESA extended BIOS functions (VBE 3.0) take parameters passed
> by reference in the x86 registers, with the pointers in ES:DI using
> the godawful Intel 20-bit real-mode segmented addressing scheme.[1]
>
> My question is: how do I map from an OS virtual address to the
> values in the emulated 8086 ES:DI registers?
>
> For example, if I put the value 0x4F00 into the emulated AX register,
> and a pointer to a 512 byte buffer in the ES:DI registers, then call
> int 0x10, the VESA BIOS will fill in a bunch of very useful
> information in the 512 byte buffer[2]. I can do all of this using the
> SRM BIOS emulator callback, and I know it does something because the
> AX register has the value 0x004F on return (byte-swap of the input AX
> value), which the documents say indicates success.
>
> I suspect there is a region of virtual address space set aside to
> serve as memory for the x86 emulator, and that addresses I pass in the
> ES:DI registers turn into offsets from the base of that region. If
> that's true, then what I really need to know is what that base address
> is.
>
> The BIOS_EMUL console callback can be passed an "additional_data"
> parameter in the r20 register, but putting the virtual address in there
> didn't work. P0 space includes virtual addresses that fit in 20 bits, so
> I tried stuffing one into the x86 segment/offset registers but that didn't
> work either. I even tried doing both simultaneously.
>
> I noticed that XFree86 solves this problem by having their own x86
> emulator that runs in the OS (see the contents of "xc/extras/x86emu"
> in their source distribution). This enables things like the XFree86
> VESA driver to work on Alpha. I could do something similar; I could
> even use the emulator that comes with XFree86 since it was there
> before their license changed, but it seems a shameful duplication of
> effort if the SRM console already does what I need.
>
> I can post my code if anyone thinks that would be helpful.
>
> Notes:
>
> [1] The 8086 segment/offset scheme represents a 20-bit address by a 16-bit
> segment register and a 16-bit offset register where the physical address
> is calculated as (segment << 4) + offset. Yes, there are many
> segment/offset combinations that yeild the same physical address.
>
> [2] See http://www.vesa.org/vbe3.pdf for details.
>
> Chip
>
>
Here I am following up to my own post, and cross-posting to boot.
Netiquette goes out the window. But maybe getting this information into
the Google archive will help somebody else someday.
While reading the Book of Ruth (OpenVMS Alpha Internals and Data
Structures: Memory Management, by Ruth E. Goldenberg) I stumbled across
the following tantalizing quote on p. 78
"At boot time, the console determines the memory configuration and
passes its findings as well as its own memory use to OpenVMS through
a data structure called the hardware restart parameter block
(HWRPB). ... Chapter Boostrap Processing provides more details on
the HWRPB and associated structures."
I already knew about the HWRPB, of course, but the phrase "its [the
console's] *OWN* memory use" was interesting. The SRM console BIOS
emulator must stash the results of these BIOS calls somewhere in the range
of "its own memory use", so all I need to do is search through the range
of addresses set aside for the console for a block of memory that looks
like what I want.
Fortunately, the VESA standard specifies that the block returned by the
0x4f00 BIOS call starts with the ASCII-encoded string 'VESA' followed by
the version number 0x0300 (see p.25 of the vbe3.pdf document cited above).
That gave me something to look for.
Furthermore, the console routine block (CRB) pointed to by HWRPB contains
a virtual-physical map section. The AARM describes the format in detail,
but doesn't give any hint as to the purpose of these mappings. I took an
educated guess that the emulated x86 memory used by the BIOS_EMUL SRM
callback must be located in one of these mappings. The following program
searches through the CRB mappings for the occurrance of the string 'VESA'
and dumps some memory following it:
#include <hwrpbdef.h>
#include <starlet.h>
#include <stdio.h>
static char buf[256];
static const char *crb_search(const char *str)
{
extern HWRPB *exe$gpq_hwrpb;
HWRPB_CRB *crb;
VAPAMAP *map;
const char *ptr;
long long i, len;
for(len = 0; *str; str++, len++);
str -= len;
crb = (HWRPB_CRB *) ((long long)exe$gpq_hwrpb +
exe$gpq_hwrpb->hwrpb$iq_crb_offset);
map = (VAPAMAP *) &crb->hwrpb_crb$iq_vapa_map;
for(i=0; i<crb->hwrpb_crb$iq_map_count; i++) {
long long size = map[i].hwrpb_vapamap$iq_page_count *
exe$gpq_hwrpb->hwrpb$iq_pagesize;
for(ptr = (char *) map[i].hwrpb_vapamap$iq_va;
ptr < (char *) map[i].hwrpb_vapamap$iq_va + size - len + 1LL;
ptr++) {
const char *p, *s;
for(p = ptr, s = str; *s && *s == *p; p++, s++);
if(!*s)
goto found;
}
}
return 0;
found:
for(i=0;i<sizeof(buf);i++)
buf[i] = ptr[i];
return ptr;
}
int main()
{
int arglist[2], i, *ptr, adr;
arglist[0] = 1;
arglist[1] = (int) "VESA";
adr = sys$cmkrnl(crb_search, arglist);
if(adr) {
ptr = (int *) buf;
for(i=0; i<8; i++)
printf("%08x: %08x\n", adr+4*i, ptr[i]);
}
return 0;
}
and here's the output:
$ run crb_search
8b8622f5: 41534556
8b8622f9: 00000300
8b8622fd: 00010000
8b862301: 00000000
8b862305: 00000000
8b862309: 00000000
8b86230d: 00000000
8b862311: 00000000
0x41534556 is 'VESA' in ASCII on a little-endian machine. The version
code 0x0300 occupies the next two bytes. I'm pretty sure I've found it.
But there are still some strange things about it, such as the fact that
it's not longword-aligned.
The reverse-engineering continues ....
Chip
--
Charles M. "Chip" Coldwell
System Administrator
Harvard Physics Department
617-495-3388
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-18 21:27 ` Chip Coldwell
@ 2004-12-18 21:50 ` Måns Rullgård
2004-12-19 18:01 ` Chip Coldwell
0 siblings, 1 reply; 7+ messages in thread
From: Måns Rullgård @ 2004-12-18 21:50 UTC (permalink / raw)
Chip Coldwell <coldwell@physics.harvard.edu> writes:
[reverse engineering]
> 0x41534556 is 'VESA' in ASCII on a little-endian machine. The version
> code 0x0300 occupies the next two bytes. I'm pretty sure I've found
> it. But there are still some strange things about it, such as the fact
> that it's not longword-aligned.
That does sound somewhat odd. Does the following data seem to make
sense?
> The reverse-engineering continues ....
Please keep us updated. The information may be useful some day.
--
M�ns Rullg�rd
mru@inprovide.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-18 21:50 ` Måns Rullgård
@ 2004-12-19 18:01 ` Chip Coldwell
2004-12-21 17:21 ` FredK
0 siblings, 1 reply; 7+ messages in thread
From: Chip Coldwell @ 2004-12-19 18:01 UTC (permalink / raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2051 bytes --]
On Sat, 18 Dec 2004, [iso-8859-1] Måns Rullgård wrote:
> Chip Coldwell <coldwell@physics.harvard.edu> writes:
>
> [reverse engineering]
>
>> 0x41534556 is 'VESA' in ASCII on a little-endian machine. The version
>> code 0x0300 occupies the next two bytes. I'm pretty sure I've found
>> it. But there are still some strange things about it, such as the fact
>> that it's not longword-aligned.
>
> That does sound somewhat odd. Does the following data seem to make
> sense?
Yes and no. Here's what I get:
8b8622f5: 41534556 00000300 00010000 00000000 VESA............
8b862305: 00000000 00000000 00000000 00000000 ................
8b862315: 001b0000 00400007 a0000040 00000000 ......@.@.......
8b862325: 000f0000 00200007 b8000020 00000000 ...... . .......
8b862335: 614d0000 786f7274 61724720 63696870 ..Matrox Graphic
8b862345: 6e492073 4d002e63 6f727461 614d0078 s Inc..Matrox.Ma
8b862355: 786f7274 35344720 30300030 45425600 trox G450.00.VBE
8b862365: 41474d2f 00000101 00000000 01023f00 /MGA.........?..
8b862375: 1074143c 1d770b3c e432fcfb 2e93e0d1 <.t.<.w...2.....
8b862385: 553da7ff 0f03fb80 80080284 840f05fb ..=U............
8b862395: 01eb080a ffffb890 cb8b51cf 01ffe181 .........Q......
8b8623a5: 746af983 02f98106 81087501 81f600e3 ..jt.....u......
8b8623b5: 590102cb 565350c3 811f0e1e 8d01ffe3 ...Y.PSV........
8b8623c5: ad526136 0774d83b 75ffff3d 1fc00bf6 6aR.;.t.=..u....
8b8623d5: c3585b5e 571ed88b 0e525156 0000ba1f ^[X....WVQR.....
8b8623e5: 3d816626 32454256 01ba0375 80b95700 &f.=VBE2u....W..
(once again, note that the addresses on the left are not
longword-aligned). The OemString, OemVendorName and OemProductName are
pretty clearly in there. I haven't made any sense of the pointers yet.
I discovered that this data is already in memory before I call out to any
of the VGA BIOS functions. So it's left over from a BIOS call the SRM
console itself made.
Chip
--
Charles M. "Chip" Coldwell
System Administrator
Harvard Physics Department
617-495-3388
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-19 18:01 ` Chip Coldwell
@ 2004-12-21 17:21 ` FredK
2004-12-21 21:31 ` Chip Coldwell
0 siblings, 1 reply; 7+ messages in thread
From: FredK @ 2004-12-21 17:21 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2578 bytes --]
I'm not sure who I could direct your question to. Most of the guys who did
this work have long ago moved on to other companies. The callbacks were put
in, in part, due to a request I made. However, they didn't show up until
too late for me to use them (I had moved on to other things). It's quite
likely that they have never been fully tested. I'll poke around and see if
I have anything still around that spells out how to use parameters.
"Chip Coldwell" <coldwell@physics.harvard.edu> wrote in message
news:Pine.LNX.4.61.0412191258300.8500@frank.harvard.edu...
On Sat, 18 Dec 2004, [iso-8859-1] M�ns Rullg�rd wrote:
> Chip Coldwell <coldwell@physics.harvard.edu> writes:
>
> [reverse engineering]
>
>> 0x41534556 is 'VESA' in ASCII on a little-endian machine. The version
>> code 0x0300 occupies the next two bytes. I'm pretty sure I've found
>> it. But there are still some strange things about it, such as the fact
>> that it's not longword-aligned.
>
> That does sound somewhat odd. Does the following data seem to make
> sense?
Yes and no. Here's what I get:
8b8622f5: 41534556 00000300 00010000 00000000 VESA............
8b862305: 00000000 00000000 00000000 00000000 ................
8b862315: 001b0000 00400007 a0000040 00000000 ......@.@.......
8b862325: 000f0000 00200007 b8000020 00000000 ...... . .......
8b862335: 614d0000 786f7274 61724720 63696870 ..Matrox Graphic
8b862345: 6e492073 4d002e63 6f727461 614d0078 s Inc..Matrox.Ma
8b862355: 786f7274 35344720 30300030 45425600 trox G450.00.VBE
8b862365: 41474d2f 00000101 00000000 01023f00 /MGA.........?..
8b862375: 1074143c 1d770b3c e432fcfb 2e93e0d1 <.t.<.w...2.....
8b862385: 553da7ff 0f03fb80 80080284 840f05fb ..=U............
8b862395: 01eb080a ffffb890 cb8b51cf 01ffe181 .........Q......
8b8623a5: 746af983 02f98106 81087501 81f600e3 ..jt.....u......
8b8623b5: 590102cb 565350c3 811f0e1e 8d01ffe3 ...Y.PSV........
8b8623c5: ad526136 0774d83b 75ffff3d 1fc00bf6 6aR.;.t.=..u....
8b8623d5: c3585b5e 571ed88b 0e525156 0000ba1f ^[X....WVQR.....
8b8623e5: 3d816626 32454256 01ba0375 80b95700 &f.=VBE2u....W..
(once again, note that the addresses on the left are not
longword-aligned). The OemString, OemVendorName and OemProductName are
pretty clearly in there. I haven't made any sense of the pointers yet.
I discovered that this data is already in memory before I call out to any
of the VGA BIOS functions. So it's left over from a BIOS call the SRM
console itself made.
Chip
--
Charles M. "Chip" Coldwell
System Administrator
Harvard Physics Department
617-495-3388
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-21 17:21 ` FredK
@ 2004-12-21 21:31 ` Chip Coldwell
2004-12-24 4:15 ` FredK
0 siblings, 1 reply; 7+ messages in thread
From: Chip Coldwell @ 2004-12-21 21:31 UTC (permalink / raw)
On Tue, 21 Dec 2004, FredK wrote:
> I'm not sure who I could direct your question to. Most of the guys who did
> this work have long ago moved on to other companies. The callbacks were put
> in, in part, due to a request I made. However, they didn't show up until
> too late for me to use them (I had moved on to other things). It's quite
> likely that they have never been fully tested. I'll poke around and see if
> I have anything still around that spells out how to use parameters.
Thanks a lot, I really appreciate it.
Like I said, I have been using the BIOS_EMUL callback to set
VESA-standard video modes, including the extended modes defined in the
VBE 3.0 document, and that does work. I would guess that the SRM
itself must be using the BIOS emulation in order to set a text mode so
it can use the video device for the operator console. (Although in
principle it could set up the VGA registers without using the BIOS.)
Chip
--
Charles M. "Chip" Coldwell
System Administrator
Harvard Physics Department
617-495-3388
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: VESA/VGA BIOS emulation
2004-12-21 21:31 ` Chip Coldwell
@ 2004-12-24 4:15 ` FredK
0 siblings, 0 replies; 7+ messages in thread
From: FredK @ 2004-12-24 4:15 UTC (permalink / raw)
The BIOS emulation in the SRM console was done purely as a way to do generic
text console. I asked them for an Int 10 emulation at some point - because
I was so tired of trying to figure out how to reverse engineer a device
initialization. But I never ended up using it.
A lot of x86 BIOS code is really, really bad. Vendors took every liberty
they could find. So the BIOS emulation seemed to be a job of fixing things
as they went.
"Chip Coldwell" <coldwell@physics.harvard.edu> wrote in message
news:Pine.LNX.4.61.0412211623110.27727@localhost.localdomain...
> On Tue, 21 Dec 2004, FredK wrote:
>
> > I'm not sure who I could direct your question to. Most of the guys who
did
> > this work have long ago moved on to other companies. The callbacks were
put
> > in, in part, due to a request I made. However, they didn't show up
until
> > too late for me to use them (I had moved on to other things). It's
quite
> > likely that they have never been fully tested. I'll poke around and see
if
> > I have anything still around that spells out how to use parameters.
>
> Thanks a lot, I really appreciate it.
>
> Like I said, I have been using the BIOS_EMUL callback to set
> VESA-standard video modes, including the extended modes defined in the
> VBE 3.0 document, and that does work. I would guess that the SRM
> itself must be using the BIOS emulation in order to set a text mode so
> it can use the video device for the operator console. (Although in
> principle it could set up the VGA registers without using the BIOS.)
>
> Chip
>
> --
> Charles M. "Chip" Coldwell
> System Administrator
> Harvard Physics Department
> 617-495-3388
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-12-24 4:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-16 20:24 VESA/VGA BIOS emulation Chip Coldwell
2004-12-18 21:27 ` Chip Coldwell
2004-12-18 21:50 ` Måns Rullgård
2004-12-19 18:01 ` Chip Coldwell
2004-12-21 17:21 ` FredK
2004-12-21 21:31 ` Chip Coldwell
2004-12-24 4:15 ` FredK
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox