From: Chip Coldwell <coldwell@physics.harvard.edu>
Subject: Re: VESA/VGA BIOS emulation
Date: Sat, 18 Dec 2004 16:27:20 -0500 [thread overview]
Message-ID: <Pine.LNX.4.61.0412181547060.23971@frank.harvard.edu> (raw)
In-Reply-To: <Pine.LNX.4.61.0412161458560.25782@localhost.localdomain>
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
next prev parent reply other threads:[~2004-12-18 21:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-16 20:24 VESA/VGA BIOS emulation Chip Coldwell
2004-12-18 21:27 ` Chip Coldwell [this message]
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
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox