I recently wrote a basic bootloader and a kernel that should change colors in the VGA palette.
The kernel doesnt make any problems runs perfectly but It does not change the colors as expectet.
Since I was not able to find a mistake I tried to run the bootloader+kernel from a bootstick on my machine. I got a blackscreen and a blinking cursor.
So I decided to use a gui tool for writing the bootstick ("usb-creator-gtk"), I used it to write my img file to the stick and then tested it using qemu as the program asked me to do.
The bootloader was not able to load the kernel. (qemu-system-x86_64 -hda /dev/sdc)
But if I use qemu-system-x86_64 -fda /dev/sdc the kernel gets loaded and works (except the VGA palette).
How I load the kernel code :
Code: Select all
load_kernel_dx_drive_sectors:
xor ax, ax;set zero
mov es, ax;ser es zero
mov bx, 0x9000 ;(es:bx)
push dx ;backup input data (dl=BOOT_DRIVE, dh=SECTORS)
mov ah, 0x02 ;13h : read from disk
mov al, dh ; read dh sectors
mov ch, 0x00 ; cylinder 0
mov dh, 0x00 ; head 0
mov cl, 0x02 ; start reading from the 2nd cylinder (skip boot sector)
int 13h ; EXECUTE
Code: Select all
jc .error; error (carryflag not set) --> red screen
pop dx
cmp dh, al ; al = sectors read --> if not as expected then : ERROR
jne .error2
push 0x0d;
push 320*200
call clearScreen_char_n
add esp, 4
ret
.error:
push 0x0d;
push 320*200
call clearScreen_char_n
add esp, 4
ret
.error2:
push 0x0f;
push 320*200
call clearScreen_char_n
add esp, 4
ret
Code: Select all
nasm boot.asm -f bin -o boot.bin
nasm -f elf32 kernel.asm -o kasm.o
gcc -w -g -m32 -c -ffreestanding -o kernel.o kernel.c -lgcc
ld -melf_i386 -Tlinker.ld -nostdlib --nmagic -o kernel.elf kernel.o kasm.o
objcopy -O binary kernel.elf kernel.bin
dd if=/dev/zero of=disk.img bs=512 count=2880
dd if=boot.bin of=disk.img bs=512 conv=notrunc
dd if=kernel.bin of=disk.img bs=512 seek=1 conv=notrunc
Code: Select all
OUTPUT_FORMAT(elf32-i386)
ENTRY(main)
SECTIONS
{
. = 0x9000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) *(COMMON) }
}
Code: Select all
void writeVGA_DAC_color(char index, char r, char g, char b){
write_port(0x3C6, 0b11111111);
write_port(0x3C8, index);
write_port(0x3C9, r);
write_port(0x3C9, g);
write_port(0x3C9, b);
}
Thanks in advance.