Hi Anirudh,

On 2026-10-03T20:07:54, Anirudh Srinivasan
<[email protected]> wrote:
> bios_emulator: extend VGA I/O ports to include ports 0x3B4-0x3DA
>
> The IS_VGA_PORT macro currently doesn't cover the 0x3B4, 0x3B5 and 0x3BA
> I/O ports. Reads/writes to this currently fall through to LOG_inpb/outb
> which are unimplemented on non x86 architectures (which don't support
> I/O ports).
>
> Add these ports to the IS_VGA_PORT macro, and implement reads/writes to
> these ports. 0x3B4 and 0x3B5 are mirrors of 0x3D4 and 0x3D5 that are
> used in monochrome mode (bit 0 of 0x3C2 is not set). Implement these
> with the same logic and env state as 0x3D4/0x3D5, but with the bit check
> condition for 0x3C2 flipped. 0x3BA is a mirror of 0x3DA, so the
> implementation for this falls back to the same logic as 0x3DA.
>
> The extended range also covers the non-VGA ports 0x3B6-0x3B9 and
> 0x3BB-0x3BF (LPT1 on legacy PCs): reads return 0xff and writes are
> dropped instead of reaching the real inb/outb path, which is harmless
> from the VBIOS's perspective.
>
> The write side handles 0x3B4/0x3B5 but not 0x3BA, consistent with the
> existing lack of a 0x3DA write handler.
>
> The Aspeed AST2600's VBIOS uses these I/O ports, and these changes are
> needed for it's VBIOS to run.

Please use 'its' rather than 'it's' here.

> [...]
>
> drivers/bios_emulator/besys.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)

> diff --git a/drivers/bios_emulator/besys.c b/drivers/bios_emulator/besys.c
> @@ -270,6 +270,18 @@ static u8 VGA_inpb (const int port)
> +     case 0x3B4:
> +             if (!(_BE_env.emu3C2 & 0x1))
> +                     return _BE_env.emu3D4;
> +             break;
> +     case 0x3B5:
> +             if (!(_BE_env.emu3C2 & 0x1) && (_BE_env.emu3D4 < CRT_C))
> +                     return _BE_env.emu3D5[_BE_env.emu3D4];
> +             break;

This repeats the 0x3D4/0x3D5 cases with the condition inverted, and
VGA_outpb() does the same again. You could add a small helper that
checks whether the CRTC port matches the current mode, for example:

    static bool vga_crtc_active(int port)
    {
            return (port >= 0x3d0) == !!(_BE_env.emu3C2 & 1);
    }

Then 0x3B4 can share a case with 0x3D4, and 0x3B5 with 0x3D5, in both
functions, removing the duplication. What do you think?

> diff --git a/drivers/bios_emulator/besys.c b/drivers/bios_emulator/besys.c
> @@ -321,6 +333,10 @@ static u8 VGA_inpb (const int port)
> +     /*
> +      * 3BA is a mirror of 3DA
> +      */
> +     case 0x3BA:
>       case 0x3DA:

Just to check: on real hardware 0x3BA only decodes in monochrome mode,
so a read in colour mode should not reset flipFlop3C0 or toggle
emu3DA. The existing 0x3DA case doesn't check the mode either, so this
may not matter for the AST2600 VBIOS, but it would be more accurate to
use the same mode check as 0x3B4/0x3B5. Also, a single-line comment is
enough here.

Regards,
Simon

Reply via email to