Page 1 of 1

BIOS-VGA

Posted: Fri Apr 30, 2021 9:55 am
by Fantasy94
My question is the following, could I modify an Award BIOS, so that the character output was different, for example the characters of another color?

Explain, I'm an OpenBSD user, I'm a bit frustrated that wscons only supports ANSI colors.

I have been reading good articles on this website, such as writing directly to the VGA memory address (0xb8000) with a few simple instructions and being in ring0, I could check the effectiveness.

Well, my bios boot when it executes all the character outputs does it send them to the VGA address?

I think I can understand. I have a Binary my bios Award, I was able to change simple things such as the logo.

Could you disassemble the binary and modify the character outputs? Yes, it works that way.

Where can I start?

Thanks.

Re: BIOS-VGA

Posted: Mon May 03, 2021 10:14 pm
by nullplan
Character colors are defined by the graphics card. The BIOS merely writes them into the memory area reserved for VGA, but it is the graphics card that interprets the bytes there and sends the signals to the monitor. If you wanted those bytes to be interpreted differently, you would have to change the way the graphics card works. Either by creating a new video BIOS or by just changing its settings. But that will require you to study your graphics card's documentation. Good luck!

These days, most people would just switch the graphics card to graphics mode and draw glyphs into the frame buffer. And then you can have any color you want. I also don't know what OpenBSD and BIOS have to do with any of this. BIOS is only needed to write characters in real mode, and OpenBSD is not using it for that if the developers have any sense.

Re: BIOS-VGA

Posted: Tue May 04, 2021 6:26 am
by bzt
You could simply modify the VGA DAC registers to use a different palette, simple as that. Palette works with text mode just as well as with 16 / 256 color graphics modes.

Otherwise yes, you can modify the VGA BIOS ROM and replace the default colors (vgatables.h line 532). The bochs source has the bios source too, you can modify that and recompile the vgabios.rom image...
nullplan wrote:These days, most people would just switch the graphics card to graphics mode and draw glyphs into the frame buffer.
...but yes, this would be my suggestion too. With UEFI there's no text mode, only graphics mode, meaning on modern machines this is the only option.

Cheers,
bzt

Re: BIOS-VGA

Posted: Wed May 05, 2021 5:16 pm
by foliagecanine
You most likely could figure out a way to decompile (or at least jump out to some custom code and then jump back into) the AwardBIOS and modify it in order to change the VGA color palette. It would probably take a while, but it's most likely possible.
However, it has a much higher chance at bricking your computer (unless you've got something like dual-BIOS).
Also, when you're writing code for a BIOS, you've got to be SUPER careful about vendor-specific stuff, which things have been initialized yet, and so on.

In any case, it is probably easier to either
A) Modify the OpenBSD kernel that you are using to change the color palette on boot-up or
B) Create an intermediate loader that runs prior to either BIOSBOOT (the OpenBSD bootloader) or OpenBSD, changes the color palette, then loads BIOSBOOT/OpenBSD

Re: BIOS-VGA

Posted: Mon May 10, 2021 1:24 pm
by Fantasy94
nullplan wrote:Character colors are defined by the graphics card. The BIOS merely writes them into the memory area reserved for VGA, but it is the graphics card that interprets the bytes there and sends the signals to the monitor. If you wanted those bytes to be interpreted differently, you would have to change the way the graphics card works. Either by creating a new video BIOS or by just changing its settings. But that will require you to study your graphics card's documentation. Good luck!

These days, most people would just switch the graphics card to graphics mode and draw glyphs into the frame buffer. And then you can have any color you want. I also don't know what OpenBSD and BIOS have to do with any of this. BIOS is only needed to write characters in real mode, and OpenBSD is not using it for that if the developers have any sense.
I only referenced OpenBSD because the wscons driver only supports ANSI colors. These are the colors that it supports, and it is shocking to me that it can write in ring0 directly to the VGA memory with more colors.

https://man.openbsd.org/wscons.4
https://github.com/openbsd/src/blob/mas ... splayvar.h

Code: Select all

/* fg / bg values. Made identical to ANSI terminal color codes. */
#define WSCOL_BLACK	0
#define WSCOL_RED	1
#define WSCOL_GREEN	2
#define WSCOL_BROWN	3
#define WSCOL_BLUE	4
#define WSCOL_MAGENTA	5
#define WSCOL_CYAN	6
#define WSCOL_WHITE	7
The only thing that I would like to try now, is simply that my BIOS write the characters on the screen of a different color, I thought that the BIOS itself would have a function of this type, and if there is to be able to modify the color parameter.
bzt wrote:You could simply modify the VGA DAC registers to use a different palette, simple as that. Palette works with text mode just as well as with 16 / 256 color graphics modes.

Otherwise yes, you can modify the VGA BIOS ROM and replace the default colors (vgatables.h line 532). The bochs source has the bios source too, you can modify that and recompile the vgabios.rom image...
nullplan wrote:These days, most people would just switch the graphics card to graphics mode and draw glyphs into the frame buffer.
...but yes, this would be my suggestion too. With UEFI there's no text mode, only graphics mode, meaning on modern machines this is the only option.

Cheers,
bzt
I think what you sent me is for an emulator called Bosch, I would like to apply it in a real BIOS, sorry if it is not like that and I misunderstood.
foliagecanine wrote:You most likely could figure out a way to decompile (or at least jump out to some custom code and then jump back into) the AwardBIOS and modify it in order to change the VGA color palette. It would probably take a while, but it's most likely possible.
However, it has a much higher chance at bricking your computer (unless you've got something like dual-BIOS).
Also, when you're writing code for a BIOS, you've got to be SUPER careful about vendor-specific stuff, which things have been initialized yet, and so on.

In any case, it is probably easier to either
A) Modify the OpenBSD kernel that you are using to change the color palette on boot-up or
B) Create an intermediate loader that runs prior to either BIOSBOOT (the OpenBSD bootloader) or OpenBSD, changes the color palette, then loads BIOSBOOT/OpenBSD
I would like to disassemble the BIOS and modify the color palette.

I found this site, it is very interesting there you can find the structure of an AWARD BIOS.

https://sites.google.com/site/pinczakko ... -structure

I have the binaries, even the VGA ROM one, but I don't think I need it as my current BIOS doesn't have VGA built in. In this case the BIOS system writes the characters to the VGA and that is what I want to find.

Referencing the link, the file:

Code: Select all

0. System BIOS       20000h(128.00K) 13C31h(79.05K)   865IDC19.BIN
In the BIOS system it must have some VGA writing function, am I wrong? This is where I want to go.

Forgive me if I'm saying something crazy, I'm getting started. I have the binaries and IDA to try to see the code in ASM, but there is where I am lost and I will not find that function if it exists.

Thanks guys.

Re: BIOS-VGA

Posted: Mon May 10, 2021 3:09 pm
by Octocontrabass
Why do you need to modify the BIOS instead of modifying OpenBSD? Here is the function to initialize VGA. Insert code to override the palette however you like.

Also, don't forget that you can use WSATTR_HILIT to access 16 different colors, not just 8 colors.

Re: BIOS-VGA

Posted: Tue May 11, 2021 1:05 am
by bzt
Fantasy94 wrote:I think what you sent me is for an emulator called Bosch, I would like to apply it in a real BIOS, sorry if it is not like that and I misunderstood.
Nope, what I've sent you is the source of a GPL licensed VGA ROM (used by many emulators, bochs and qemu as well, but it is a VGA ROM not an emulator). On a real machine you'll have a manufacturer specific ROM, and chances are good you can't change that at all. The best you can do is change the VGA ROM used by the emulator.

Why do you want to change the default palette by the way, when you could simply modify the effective palette any time? Or even better, by using a modern video hardware use true color pixels without palette in the first place?
Fantasy94 wrote:I only referenced OpenBSD because the wscons driver only supports ANSI colors.
This doesn't mean it's using text mode at all. It could be that it uses a framebuffer, and emulates ANSI colors. Same with the Linux consoles (Ctrl+Alt+F1 .. Ctrl+Alt+F6; do not confuse with GUI terminal emulators like xterm, gnome-terminal, konsole etc.) Under the hood those consoles are pixel based framebuffers, yet they only supports ANSI colors via CSI sequences. I haven't checked, but wscons could do the same. Actually if OpenBSD boots on an UEFI machine, there's no other way.
Fantasy94 wrote:I would like to disassemble the BIOS and modify the color palette.

I found this site, it is very interesting there you can find the structure of an AWARD BIOS.
You won't find the palette in that. That's stored in the VGA ROM, which is physically a chip on the video card not on the mother board. Let's assume you have a motherboard with AWARD BIOS. You plug in a Cirrus video card, then the default palette will be provided by the Cirrus VGA ROM. Then you replace the card with a Trident card, then the AWARD BIOS remains the same, but now you'll have an entirely different VGA ROM with different VGA functions, and in theory with a different default palette (the palette is standardized so it's unlikely to have a different one, but could be).
Fantasy94 wrote:In the BIOS system it must have some VGA writing function, am I wrong? This is where I want to go.
No, that's in the VGA ROM. It's just the interface is standardized, so that the BIOS could use the same IO ports for VGA. But not for SVGA and above, there the compatibility is limited to the INT 10h interface, and not to the IO ports. Furthermore, most modern video cards does not emulate legacy IO ports either.
Fantasy94 wrote:Forgive me if I'm saying something crazy, I'm getting started. I have the binaries and IDA to try to see the code in ASM, but there is where I am lost and I will not find that function if it exists.
No wonder, there's no such function in the system BIOS. Disassemble the VGA ROM, or take a look at the source I've linked. You'll find it there (vgabios.c, line 837 function load_dac_palette).

Cheers,
bzt

Re: BIOS-VGA

Posted: Tue May 11, 2021 12:52 pm
by Octocontrabass
bzt wrote:That's stored in the VGA ROM, which is physically a chip on the video card not on the mother board.
Only if the VGA card is separate from the motherboard. The option ROMs for integrated devices, including VGA, are part of the BIOS ROM.

But you still don't need to modify any ROMs.

Re: BIOS-VGA

Posted: Tue May 11, 2021 4:32 pm
by bzt
Octocontrabass wrote:Only if the VGA card is separate from the motherboard. The option ROMs for integrated devices, including VGA, are part of the BIOS ROM.
Even if the VGA card is integrated, they never write a specific combined BIOS+VGA software for it, they just put both the BIOS ROM image and the VGA ROM image on the motherboard next to each other. But that doesn't mean the manufacturer has implemented a completely new firmware from ground up with unseparateable BIOS and VGA functionality (I can assure you, they don't spend time and money on that, especially when adding both ROM images just works out-of-the-box).
Octocontrabass wrote:But you still don't need to modify any ROMs.
True.

Cheers,
bzt

Re: BIOS-VGA

Posted: Thu May 13, 2021 4:49 pm
by Fantasy94
Thank you for your answers, unfortunately I cannot take the time to understand the codes in depth, from here a few days I will comment on the possible doubts you may have.

Regards.