diff --git a/README.adoc b/README.adoc index 86dbe24..a952b0c 100644 --- a/README.adoc +++ b/README.adoc @@ -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. diff --git a/baremetal_hello_world.S b/baremetal_hello_world.S deleted file mode 100644 index 1bce427..0000000 --- a/baremetal_hello_world.S +++ /dev/null @@ -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! <-- " - diff --git a/no_bios_hello_world.S b/no_bios_hello_world.S new file mode 100644 index 0000000..0849c21 --- /dev/null +++ b/no_bios_hello_world.S @@ -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"