How do low level thigns without BIOS?

Programming, for all ages and all languages.
Post Reply
User avatar
growlnx
Posts: 15
Joined: Sun Jan 05, 2020 5:51 pm
Libera.chat IRC: growlnx
Location: 0.0.0.0
Contact:

How do low level thigns without BIOS?

Post 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!
Last edited by growlnx on Mon Feb 03, 2020 6:52 am, edited 1 time in total.
Regards,
Growlnx.
nullplan
Member
Member
Posts: 1770
Joined: Wed Aug 30, 2017 8:24 am

Re: How do low level thigns without BIOS?

Post 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.
Carpe diem!
User avatar
growlnx
Posts: 15
Joined: Sun Jan 05, 2020 5:51 pm
Libera.chat IRC: growlnx
Location: 0.0.0.0
Contact:

Re: How do low level thigns without BIOS?

Post 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?
Regards,
Growlnx.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: How do low level thigns without BIOS?

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: How do low level thigns without BIOS?

Post 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...
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: How do low level thigns without BIOS?

Post 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
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: How do low level thigns without BIOS?

Post 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.
Post Reply