Beginner Question: Error 13
Posted: Sat Mar 02, 2019 6:00 pm
Hello. I started with trying osdev, just for fun.
I've managed to boot the kernel and print stuff with the framebuffer, so I implemented a few printing functions and now it doesn't work anymore for no good reason.
When I add an additional empty method in my framebuffer.c, the error appears and when I remove that empty method, it works again.
So I researched, and it seems the multiboot header is probably not located at the beginning anymore, when the size of the kernel increases.
How can I guarantee that the multiboot header is at the beginning?
My loader.s:
My link.ld:
My Makefile:
I've managed to boot the kernel and print stuff with the framebuffer, so I implemented a few printing functions and now it doesn't work anymore for no good reason.
When I add an additional empty method in my framebuffer.c, the error appears and when I remove that empty method, it works again.
So I researched, and it seems the multiboot header is probably not located at the beginning anymore, when the size of the kernel increases.
How can I guarantee that the multiboot header is at the beginning?
My loader.s:
Code: Select all
global loader
extern kmain
MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
KERNEL_STACK_SIZE equ 4096
section .bss
align 4
kernel_stack:
resb KERNEL_STACK_SIZE
section .text:
align 4
dd MAGIC_NUMBER
dd FLAGS
dd CHECKSUM
loader:
mov esp, kernel_stack + KERNEL_STACK_SIZE
mov eax, 0xCAFEBABE
call kmain
.loop:
jmp .loop
Code: Select all
ENTRY(loader)
SECTIONS {
. = 0x00100000;Hel
.text ALIGN (0x1000) :
{
*(.text)
*(.rodata)
}
.rodata ALIGN (0x1000) :
{
*(.rodata*)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss ALIGN (0x1000) :
{
*(COMMON)
*(.bss)
}
}
Code: Select all
OBJECTS = loader.o kmain.o devices/framebuffer.o
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c
LDFLAGS = -T link.ld -melf_i386
AS = nasm
ASFLAGS = -f elf
all: kernel.elf
kernel.elf: $(OBJECTS)
ld $(LDFLAGS) $(OBJECTS) -o kernel.elf
os.iso: kernel.elf
cp kernel.elf iso/boot/kernel.elf
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -A os -input-charset utf8 -quiet -boot-info-table -o os.iso iso
run: os.iso
bochs -f bochsrc.txt -q
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
clean:
rm -rf *.o kernel.elf os.iso