What is the correct form for the character structure in the early VESA / VGA kernel console?

I am currently working on a kernel for x86 (just for fun). I am trying to implement a fairly useful early console, report driver loading and let me play with memory at boot time if I need to with an 80x25 character VESA / VGA console located at 0xB8000. I would like to do this with a structure representing a character and its attribute byte. However, I am wondering how to properly format the Character structure. I currently have:

#define CONSOLE_SIZE_X  80  //The length of a line in the console
#define CONSOLE_SIZE_Y  25  //The number of lines in the console
#define CONSOLE_MEMLOC  0xB8000 //The position of the console in system memory

#define ATTR_DEFAULT    0x07 //DOS Default
#define ATTR_ERROR  0x1F //BSOD Colors
#define ATTR_PHOSPHOR   0x02 //"Phosphor" colors, green on black

typedef struct {
    char character = (char) 0x0000;
    char attribute = (char) 0x0000;
} Character; //A VESA VGA character

typedef struct {
    int pos_x = 0;
    int pos_y = 0;

    char defaultAttrib = ATTR_DEFAULT;

    Character buffer[CONSOLE_SIZE_Y][CONSOLE_SIZE_X];


} VESAConsole;

      

The structure VESAConsole

is for logical purposes only (i.e., it does not represent any important set of positions in RAM); it Character buffer[][]

will be copied to the actual location of the console using the function cFlushBuffer(Character* console, Character* buffer)

. This will allow me to implement multiple consoles in early mode for easier debugging on my part (ok screen

or tmux

).

So, I do have 2 questions, is my character structure correct and are there any issues I need to be aware of when working with an early VESA / VGA console?

+3


source to share


1 answer


First, yes, your structure is Character

correct if not populated.

And then, regarding gotchas, there are two situations:

  • Either you used some known code to set up the VGA hardware (for example, asked the BIOS to do this, asked GRUB to do it, took an example from another OS, ...),
  • Or you installed the hardware yourself .

In the first case, you're good to go. When the setup is done correctly, there are no really evil mistakes. Just write straight into memory and let the hardware handle it.



In the second case, there are (almost) endless ways in which things can go wrong. Graphics hardware is generally difficult to set up, and while VGA is nothing compared to what modern graphics cards use, it is still far from simple.

Possible side effects include, but are not limited to, blank screens, crashes, burning and / or exploding CRT monitors, etc.

If you are interested in reading further, you can take a look at various resources on the OSDev Wiki .

+2


source







All Articles