This page looks best with JavaScript enabled

MercuryOS Interrupts

 ·  🎃 kr0m

Interrupts allow the CPU to pause the task it is currently performing to execute another task with higher priority and then return to the original task once the higher priority task has been attended to. Interrupts can be triggered by both software (int 0x10) and hardware (such as the arrival of a network packet). In this article, we will use int0x10 to print text on the screen.

Before we begin, it is recommended that you read this previous article:


Each interrupt is represented by a unique ID. This ID is used to query an interrupt vector table that was loaded by the BIOS at physical address 0x0. The table associates the ID with a pointer to a memory address where the Interrupt Service Routine (ISR) is located.

To print characters on the screen, we will use interrupt 0x10 , which is responsible for screen functions. Depending on the value of the ah register, it will perform a different function.

If we assign the value 0x0e to the ah register, it will print a character on the screen and move the cursor to the next character. The al register will be read to determine which character to print. Let’s proceed with our ASM program.

vi boot_sect_hello.asm
mov ah, 0x0e ; tty mode
mov al, 'H'
int 0x10
mov al, 'e'
int 0x10
mov al, 'l'
int 0x10
int 0x10
mov al, 'o'
int 0x10

jmp $ ; jump to current address = infinite loop

; padding and magic number
times 510 - ($-$$) db 0
dw 0xaa55 

We generate the image:

nasm -f bin boot_sect_hello.asm -o boot_sect_hello.bin

We start qemu with our image:

qemu-system-x86_64 boot_sect_hello.bin

SeaBIOS (version rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.org)  
iPXE (http://ipxe.org) 00:03.0 C980 PCI2.10 PnP PMM+07F91410+07EF1410 C980  
  
Booting from Hard Disk...  
Hello

Incredible, we have managed to print characters on the screen by calling the basic BIOS interrupts.

If you liked the article, you can treat me to a RedBull here