Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6502

BIOS interrupt 0x10 causes booting from ROM loop in QEMU

$
0
0

Problem

I am programming a basic kernel in C with a little bit of assembly. I want to change the video mode to 0x13, but when I call int 0x10, QEMU gets stuck in a booting from ROM loop where it appears to repeatedly execute the kernel.


Files

kernel.asm

bits 32
global start
extern _kmain

section .text

        align 4
        dd 0x1BADB002
        dd 0x00
        dd -(0x1BADB002 + 0x00)

start:
        mov ah, 0x00
        mov al, 0x13
        int 0x10
        call _kmain
        hlt

kernel.c

void print(int x, int y, int colour, char* text) {
    char* video = (char*)0xb8000;
    unsigned int a = 0;
    unsigned int b = 0;

    a = ((y - 1) * 160) + ((x - 1) * 2);

    while (text[b] != '\0') {
        video[a] = text[b];
        video[a + 1] = colour;
        ++b;
        a = a + 2;
    }

    return;
}

void clear(int colour) {
    char* video = (char*)0xb8000;
    for (int a = 0; a < 4000; a = a + 2) {
        video[a] = '';
        video[a + 1] = colour;
    }

    return;
}

void kmain() {
    clear(0xff);
    print(1, 1, 0xf0, "Some text...");

    return;
}

link.ld

OUTPUT_FORMAT(pei-i386)
ENTRY(start)

SECTIONS
 {
   . = 0x100000;
   .text : { *(.text) }
   .data : { *(.data) }
   .bss  : { *(.bss)  }
 }

I compile and run the kernel using the following commands:

nasm -f elf32 kernel.asm -o ka.o
gcc -m32 -c kernel.c -o kc.o -ffreestanding -nostdlib -nostdinc
ld -T link.ld -o kernel ka.o kc.o
objcopy -O elf32-i386 kernel kernel.elf

qemu-system-i386 -kernel kernel.elf

Screenshot

QEMU booting from ROM loop


Viewing all articles
Browse latest Browse all 6502

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>