Can't print characters to screen on a real computer
Posted: Sun Jul 28, 2024 10:12 pm
I want to print a letter "A" in red color on a real computer by writing to video memory at address 0xb80000, but couldn't make it work.
What I observed:
My program works well with Qemu, and I can see a red "A" on the top of Qemu window. But on real computer, I can only see a blinking white underline symbol.
Steps to produce:
mbr.s
mbr.ld
What I observed:
My program works well with Qemu, and I can see a red "A" on the top of Qemu window. But on real computer, I can only see a blinking white underline symbol.
Steps to produce:
mbr.s
Code: Select all
// This program should be written to MBR
// BIOS will load it at read address mode
.section .text
.global mbr_start
.code16
mbr_start:
mov $0xb800, %ax
mov %ax, %ds
mov $0, %di
movw $0x0441, (%di) // red "A"
_halt:
jmp _halt
// add MBR boot sign
// https://stackoverflow.com/questions/47859273/calculating-padding-length-with-gas-att-directives-for-a-boot-sector
.org 510
.word 0xaa55
Code: Select all
ENTRY(mbr_start)
SECTIONS
{
.text 0x7c00:
{
*(.text)
}
}
Code: Select all
mbr.bin:
i686-elf-g++ -T mbr.ld -o mbr.elf -ffreestanding -Wall -Wextra -fno-exceptions -fno-rtti -nostdlib -g -save-temps mbr.S
i686-elf-objcopy -O binary mbr.elf mbr.bin
# generate a file of 200MB
dd if=/dev/zero of=./mbr.img bs=512 count=409600
# copy bin to disk img
dd if=./mbr.bin of=./mbr.img conv=notrunc
# it works with qemu
qemu-system-i386 mbr.img
# not work on real computer
# write disk image to a SATA disk
sudo dd if=mbr.img of=/dev/sdb bs=512 count=4
# boot that SATA disk on a laptop, ASUS x450vc