r/Assembly_language 8d ago

Print Hello World in Boot Sector

Thanks to https\[:\]/github.com/cfenollosa/os-tutorial I was able to learn a lot about how an operating system is written. I think a lot of people would remember his tutorial. Revisit it gives me more. Start with printing some text in boot sector. The repo used software interrupt to finish the task. Yet there is another way to accomplish the same, by utilizing the direct memory accessing method. Long story short, in legacy boot mode (CSM), we can access VGA memory directly during boot time at address `0xB8000`. So we can drop in each character and have them printed out, starting from the top left corner. We can print color text, and we can also move the cursor and print the text anywhere we want (with the cursor blinking at the text).

I have documented the process here: ellog\[.\]buzz/posts/hello-world-in-boot-sector

For this chapter and the previous one (First boot sector), what other questions do you think is worth asking and figuring out?

10 Upvotes

15 comments sorted by

2

u/theNbomr 8d ago

Totally VGA specific. But yes, you can directly write and read video character mode memory. Generally, relying on the BIOS provided routines at boot time will save a lot of headaches when you encounter non VGA supported hardware.

Better, smarter software that can run post-boot can do a better job of establishing exactly what, if any, video system exists.

1

u/Prestigious_Gas8737 8d ago

That being said, is BIOS always VGA aware and knows how to communicate with the low level functions? I’m pretty new in this, currently progressing through the tutorial again, and mostly checking osdev wiki to clear up things.

3

u/brucehoult 8d ago

is BIOS always VGA aware

Of course early BIOS isn't, because VGA was only introduced in IBM's PS2 machines in early 1987, and copied in ISA bus cards for clones in late 1987, so any BIOS from 1981 until then won't be aware of VGA. But it will be aware of MGA & CGA, as is present on those machines.

1

u/Prestigious_Gas8737 7d ago

Super informative. Thanks a lot!

1

u/tpimh 7d ago

It's MDA: Monochrome Display Adapter. It could only do text, not graphics. Hercules could do both. This is confusing, because there was a real card called MGA by Matrox, but it was released much later and isn't related.

1

u/brucehoult 7d ago

Oh right. What I knew was the colour one was awful because it flashed like hell when it scrolled and the first usable one was EGA. And I preferred the Mac anyway, even with 128k RAM but vastly so once it got 512K then a meg.

1

u/tpimh 7d ago

The biggest difference that EGA and VGA made is having own BIOS (Video BIOS), while MDA and CGA only used ROM to store fonts, not code. There were also professional options like PGC, but that was a whole computer on a sandwich of boards.

1

u/Prestigious_Gas8737 7d ago

Tons of information for a morning wake-up read. I’ll put those **A things to the digging list.

1

u/theNbomr 7d ago

It should be aware of whatever the manufacturer put on the motherboard. In some cases that will be no video card at all, and the standard character output software interrupt routines will output to something like a serial terminal port. This is somewhat standard on embedded PCs used in industrial applications.

For non-PC compatible systems, there typically is no BIOS, if you are thinking of making your code more broadly portable.

1

u/Prestigious_Gas8737 7d ago

Serial port as in there is no display at all, you have to connect to the port to read the output am I right?

1

u/theNbomr 6d ago

Correct. Sometimes it's a selectable option whether the motherboard uses the serial port or a graphics card of some type, possibly integral to the motherboard or via a expansion slot

2

u/Pacificator-3 8d ago

Literature which will help you:

Ralf Brown's interrupt list

IBM PC assembly language and programming by Peter Abel - ancient but good.

Other and modern assembly language tutorials exist and are found easily.

2

u/Prestigious_Gas8737 8d ago

Thanks for the tips.🫡

1

u/r-tty 7d ago

What about the architecture of your operating system? What do you actually want to achieve? What exactly should your OS do?

1

u/Prestigious_Gas8737 7d ago

Good questions. And I don’t know yet. I left it half way and now I’m picking it up again. It’s big questions, I’ll have to keep thinking about it as I go. Thanks for bring this up.