Re: Printing text with a C kernel doesn't work properly
Posted: Sun Feb 03, 2019 12:04 pm
It works fine with qemu but the problem with printing is still there. Am I setting up the stack incorrectly?MichaelPetch wrote:I'd clean it up and do it this way:This should compile each individual file, link them to an executable called kernel.elf and that executable is converted into a binary file call kernel.bin. I also simplify creating a disk image (I chose a nominal floppy disk size of 1.44MiB). Bootloader in first sector and kernel starting in second sector.Code: Select all
#!/bin/bash nasm -f bin boot.asm -o boot.bin gcc -m32 -c -ffreestanding main.c -o main.o gcc -m32 -c -ffreestanding video.c -o video.o # Link files to kernel.elf using GCC rather than LD gcc -m32 -Tlink.ld -fno-PIE -nostartfiles main.o video.o -o kernel.elf objcopy -R .note -R .comment -S -O binary kernel.elf kernel.bin # Make disk image size of 1.44MiB floppy dd if=/dev/zero of=disk.img bs=1024 count=1440 dd if=boot.bin of=disk.img conv=notrunc dd if=kernel.bin of=disk.img seek=1 conv=notrunc
Code: Select all
[BITS 16]
[ORG 0x7c00] ;First instruction adress
global loader
mov ax, 1003h
mov bx, 0
int 0x10
mov ax, 0x0003 ; 80x25 16color mode
int 0x10 ; video interrupt
xor ax, ax ; <---------------------------------------------------------------- ax = 0
mov ss, ax ; <--------------------------------------------------------------- ss = ax = 0
mov sp, 0x7c00 ; <--------------------------------------------------------- stack pointer = 0x7c00
reset_drive:
mov ah, 0
int 0x13
or ah, ah
jnz reset_drive
; load from disk
xor ax, ax
mov es, ax
mov ch, ah
mov dh, ah
mov bx, 0x7e00
mov cl, 0x02
mov ah, 0x02
mov al, 0x0A ; 10 (it works with numbers above 5 now)
int 0x13
or ah, ah
jnz reset_drive
more code below but it's irrelevant since this is the only part I changed