First post, by RetroMaster137
As always, I hope it's posted in the right section, pardon me in case it's not.
Introduction
Hello. On my spare time I have worked on games and other misc software (i.e. PoCs) for old/"embedded" systems in MC68000's supervisor mode, both in C and Assembly (sadly not x86, I don't even know its non-extended instruction set just yet), and lately on my own custom engine. Mentally accostumed to big-endian, my work usually involved demoscene-like effects on very limited GPUs; by this point I wanted to work in VFX and maybe just try making some plugin for After Effects in the future or whatever, but the industry's fate is quite uncertain.
Instead, I made the leap to high-level or "modernity", worked some stuff in C# (including Unity-based games), a PHP game server with poor security, tinkering and modding bits of a leaked Unreal Engine 1 game's source code (C++ and UnrealScript for the most part), a bit of javascript...
This time I'd like to learn the low-level of a PC; I get most of my info from OSDev's wiki, but its forums don't seem to be too active anymore and I can't post either because my ISP's IP range is in some public blacklist (I'm under NAT, and I swear it's not my fault! 😜). I'm no hardware expert.
My PC's Specifications (once again, but just in case)
- Motherboard: ASUS A55BM-K
- Chipset: AMD A55 FCH (Hudson D2)
- BIOS: AMI BIOS (A55BM-K BIOS v2002)
- Microcode version: 6001119 (2012-07-13)
- APU: AMD A8-6600K (Quad @4.2Ghz)
- iGPU: Radeon HD 8570d
- dGPU: Aisurix RX 580 8GB 2048sp
- VBIOS: RX 580's original ATOMBIOS, v015.050.002.001.000000
- RAM: 2x8 (=16) GB @1833Mhz
PC design
Unlike a system with a defined setup and specific documentation, PC is so variable it's much more tedious and difficult in comparison.
Unlike the old systems I'm accostumed to, the CPU has multiple execution modes and in different bit extensions, each giving different privileges and address maps. A PC in general seems to have really powerful address mapping system(s), for the general address map and the RAM itself, correct?
Due to design and compatibility matters, the initial state is 16bit real mode (just like the original 8086), BIOS changes it for its own usage, but returns to real mode in the hand-off to boot device/OS, correct? Then any other mode is an extension (i.e. 64bit is called "long mode"), and you can either back to real mode (if got the privilege to do so) or enter virtual 8086 mode should it be needed (the latter causes many faults/interrupts during runtime, for a supervisor program to take care and decide how to deal with them). Do those advanced virtualization settings from BIOS work by enabling a full-fledged environment for v8086 mode, in turn allowing it to switch into a "virtual long mode" if the code asks for it?
Vectors (Interrupt ReQuest (IRQ) or Interrupt Vector Table (IVT))
Where is it? (EDIT: At the very beginning of the map) Is it possible to edit the pointers and/or remap the table's address to another?
Just took a quick read to this, and I wonder, is the BIOS ROM (or part of it) truly visible from the address map, or something else makes a copy of it into RAM? Does the CPU begin execution at a specific address (0xF0000 ?) not specified by IVT? And finally, how does PC deal with larger BIOS, such as the latest v2002 update for this mobo, which is 8192kb?
Microcode
Because processor designs change over time, "microcode" itself is an x86(+extensions) emulator, which translates all instructions with its registers into whatever set the chip "internally" uses, correct? In this case, how does the BIOS even manage to boot and load a microcode software/version to use at all? Is a default microcode incorported into the CPU itself?, or, do BIOS devs need to be aware of such "internal" instruction set so microcode contained within BIOS could be loaded before actually executing x86?
BIOS / UEFI
The first full-blown program that gets mapped (or loaded through RAM?) into address map, whose visible execution consists of integrity checks, a "general configuration menu", formerly included BASIC (lol), boot into a device chosen or preset by the user, and so on. It also manages the Option ROMs or OpROMs used by/for attached devices, for networking and such.
The BIOS itself could also subdivide itself into different, if "virtual" OpROMs as well, such as iGPU's VBIOS, chipset init and setup code, or others for misc. purposes, correct? However, weeks ago I read on something related to coreboot, that some retail BIOSes COULD keep their VBIOS display tables blank (i.e. VESA modes), only to fill them from "somewhere else" (in theory, I guess that means the tables are editable at runtime?).
I have a hard time conceptually understanding UEFI. Is it like, a standarized way of making a "general configuration menu" + API? as in, is UEFI a BIOS OpROM or submodule of some form, possibly compiled into some specific bytecode whose interpreter is located within the BIOS itself?
For this AMI & ASUS scenario, which part is which? Does AMI make the "basic" BIOS part & API, which in turn hands-off to a "UEFI" part & API made by ASUS?
AMD AGESA
What exactly is this? Chipset/overall initialization OpROM/submodule, AMD-specific?
AMD VBIOS
For all I know and understand, this is called ATOMBIOS here, and in order to use anything from the GPU, you either (A) use the old API, virtualized ports, and areas of the address map (i.e. VBE or such), or, (B) you use the VBIOS' API, correct? In order to actually make use of the ATOMBIOS functions, they must be ran through an interpreter for its own bytecode format. But then how does Windows Basic Display Driver, MS-DOS by itself, or VBE even work? Does the BIOS feature its own ATOMBIOS interpreter, used to virtualize the "A" way? If I'm not mistaken, there's no true text modes anymore, so the BIOS has to perform text-to-graphic conversion anyway; the program unknowingly writes to a backbuffer, while BIOS transforms and copies into the true graphical frontbuffer.
Planning a TSR
With all this information, as a learning exercise I'd like to try arranging or making a TSR, such that it runs under VBE 3.0 (or 2.0, if it happens to not be too different?) at some "fail-safe" setting such as 640x480px or 1024x768px in 16 or 32 bit color mode, modifies the display table and/or makes the system return a different table with more options, and traps/remaps whatever necessary in order to be able to produce a scaled or arranged output for the true display mode the TSR is set to run at, or fallback if settings are the same. The end goal is a software-based compatibility layer.
I have thought on getting the source code of a well-functioning TSR, such as SBEMU if it's not trouble (with all due credits of course), and give a try at writing this planned TSR on top of it.
Is this possible and doable?
Thanks for your time.