Page 1 of 1
How do low level thigns without BIOS?
Posted: Sat Feb 01, 2020 2:13 pm
by growlnx
Hello people! I'm new here.
I don't know if this question was answered before.
How can I directly access the hardware without any help from the BIOS and be able to do the things it does (print a character, read keyboard entries, restart the computer ...).
like this:
https://raw.githubusercontent.com/ciros ... lo_world.S
I never developed a driver, but I believe it is more or that way (
correct me if I'm wrong).
Do you know any method? Any material, reference will be welcome!
Re: How do low level thigns without BIOS?
Posted: Sun Feb 02, 2020 12:20 am
by nullplan
growlnx wrote:I don't know if this question was answered before.
You would know if you used the search function.
growlnx wrote:How can I directly access the hardware without any help from the BIOS and be able to do the things it does (print a character, read keyboard entries, restart the computer ...).
Each of those requires knowledge of their respective subsystems.
Printing a character: If you are working in VGA text mode, then there will be a buffer of 80x25 characters starting at linear address 0xb8000. Each character consists of two bytes: A data byte (containing the character) and an attribute byte (containing the text color). You print characters by writing them there. You have to keep track of the cursor yourself, and if you come across control characters, you have to act on them yourself. You will also have to scroll the screen yourself.
These days I would caution against just assuming VGA text mode. Easier to let GRUB handle it. It will then tell you the base address.
Read keyboard entries: Depends. PS/2 or USB? For PS/2, all you have to do is await a keyboard interrupt and then read the keyboard port. Provided the BIOS set everything up for you. We have a wiki article about initializing the keyboard controller, I'd ask that you refer to it. USB? Well, that is going to be complicated. Because for that you will first need a PCI driver, then a host controller driver for the host controller that you have, then a USB hub driver, and then you can deal with a USB keyboard driver.
Restarting the computer: In most cases, the easiest is to just tripple-fault the computer. Unfortunately, that is not guaranteed to reset everything. For more comprehensive restart support, you will have to look into APM or ACPI.
Re: How do low level thigns without BIOS?
Posted: Mon Feb 03, 2020 10:49 am
by growlnx
nullplan wrote:
Printing a character: If you are working in VGA text mode, then there will be a buffer of 80x25 characters starting at linear address 0xb8000. Each character consists of two bytes: A data byte (containing the character) and an attribute byte (containing the text color). You print characters by writing them there. You have to keep track of the cursor yourself, and if you come across control characters, you have to act on them yourself. You will also have to scroll the screen yourself.
Is there anything watching that memory range and sending it to VGA output?
nullplan wrote:
These days I would caution against just assuming VGA text mode. Easier to let GRUB handle it. It will then tell you the base address.
Can the VGA text mode buffer change the base address?
Re: How do low level thigns without BIOS?
Posted: Mon Feb 03, 2020 4:42 pm
by bzt
growlnx wrote:Is there anything watching that memory range and sending it to VGA output?
Yes, that's the VGA hardware, the video card.
growlnx wrote:Can the VGA text mode buffer change the base address?
Of course. You can change it too (within a range), see
VGA registers. Furthermore, you can also change the actual VGA memory mapped at those addresses, search for "SVGA bank switching" (but that's manufacturer specific, banking was never standardized). A little bit more info
here.
TBH, you won't find any VGA on modern machines. Modern video cards MAY provide backward compatibility in some cases, but that compatibility layer is fading pretty quickly. Most higher resolution modes does not support VGA registers about 20 years now. Virtual machines are likely to support it for its simplicity (and keeping backward compatibility), but on real hardware it is already obsoleted. UEFI machines without CSM won't emulate VGA text mode at all.
Cheers,
bzt
Re: How do low level thigns without BIOS?
Posted: Tue Feb 04, 2020 4:14 am
by Candy
> Furthermore, you can also change the actual VGA memory mapped at those addresses, search for "SVGA bank switching" (but that's manufacturer specific, banking was never standardized).
It was standardized - int 0x10, ah=0x4f02 - in the VESA display extensions. That worked pretty universally until about 2005...
Re: How do low level thigns without BIOS?
Posted: Tue Feb 04, 2020 6:08 am
by bzt
Candy wrote:It was standardized - int 0x10, ah=0x4f02 - in the VESA display extensions. That worked pretty universally until about 2005...
The
VGA registers were never standardized (unlike the VGA CRTC registers for example). The OP asked about "without BIOS", and just for the records nobody used that bank switching VBE routine either because many cards' ROM haven't implemented it, and if it was implemented then it was terribly slow anyway. Software from that era used direct port writes, first-hand experience. For the Cirrus cards for example the VGA registers were
port 0x9 - port 0xB. For other manufacturer's port assignments, see
XFree86's source, directory xc/programs/Xserver/hw/xfree86/vga*/drivers/.
Cheers,
bzt
Re: How do low level thigns without BIOS?
Posted: Thu Feb 06, 2020 1:34 pm
by PeterX
Candy wrote:
It was standardized - int 0x10, ah=0x4f02 - in the VESA display extensions. That worked pretty universally until about 2005...
Minor correction: ax, not ah.