no_bios_hello_world

This commit is contained in:
Ciro Santilli
2019-03-19 20:03:13 +00:00
parent 9440bdf396
commit 78246edcee
3 changed files with 61 additions and 38 deletions

View File

@@ -691,6 +691,34 @@ Open source x86 BIOS implementation.
Default BIOS for QEMU and KVM.
== No BIOS
Here we will collect some examples that do stuff without using the BIOS!
These tend to be less portable, not sure they will work on real hardware. But they were verified in QEMU.
=== No BIOS hello world
....
./run no_bios_hello_world
....
Source: link:no_bios_hello_world.S[]
Outcome:
....
hello world
....
with red foreground and blue background shows on the top left of the cleared screen.
This example uses the fact that BIOS maps video memory to address 0xB8000.
We can then move 0xB800 to a segment register and use segment:offset addressing to access this memory.
Then we can show characters by treating `0xB800:0000` as a `uint16_t` array, where low 8 bytes is the ASCII character, and the high 8 bytes is the color attribute of this character.
== Modes of operation
The x86 processor has a few modes, which have huge impact on how the processor works.

View File

@@ -1,38 +0,0 @@
#include "common.h"
BEGIN
mov $0xB800, %di
mov %di, %es
xor %di, %di
lea msg, %si
// clear screen from SeaBIOS messages
xor %ax, %ax
movw $2000, %cx
repz stosw
xor %di, %di
// write a string on the screen
.loop:
lodsb
test %al, %al
jz .halt
// write the character
movb %al, %es:(%di)
// write color attribute of this character
// 20d = 0x14 = 10100b = color attributes (red on blue)
// background color = 1b = blue
// foreground color = 100b = red
movb $20, %es:1(%di)
add $0x2, %di
jmp .loop
.halt:
hlt
msg:
.asciz " --> hello world! <-- "

33
no_bios_hello_world.S Normal file
View File

@@ -0,0 +1,33 @@
/* https://github.com/cirosantilli/x86-bare-metal-examples#no-bios-hello-world */
#include "common.h"
BEGIN
mov $0xB800, %di
mov %di, %es
xor %di, %di
lea msg, %si
/* clear screen from SeaBIOS messages */
xor %ax, %ax
movw $2000, %cx
repz stosw
xor %di, %di
/* write a string on the screen */
.loop:
lodsb
test %al, %al
jz .halt
/* write the character */
movb %al, %es:(%di)
/* write color attribute of this character
* 20d = 0x14 = 10100b = color attributes (red on blue)
* background color = 1b = blue
* foreground color = 100b = red
*/
movb $20, %es:1(%di)
add $0x2, %di
jmp .loop
.halt:
hlt
msg:
.asciz "hello world"