No multiboot header found

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Adrox
Posts: 9
Joined: Wed Dec 07, 2016 10:39 am

No multiboot header found

Post by Adrox »

Hi,

I have a problem. Grub says it didn't found a multiboot header though I did exactly the same like bare bones tutorial http://wiki.osdev.org/Bare_Bones

boot.asm

Code: Select all

MBALIGN  equ  1<<0
MEMINFO  equ  1<<1
FLAGS    equ  MBALIGN | MEMINFO
MAGIC    equ  0x1badb002
CHECKSUM equ -(MAGIC + FLAGS)

section .multiboot
align 4
	dd MAGIC
	dd FLAGS
	dd CHECKSUM

section .bss
align 4
	stack_bottom:
	resb 16384
	stack_top:

section .text
	global _start:function (_start.end - _start)
	extern kernel_main

_start:
		mov esp, stack_top
		call kernel_main

		cli
.hang:	hlt
		jmp .hang
.end:

kernel_main.c

Code: Select all

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

enum VGAColor {
	VGA_BLACK 	 = 0,
	VGA_BLUE 	 = 1,
	VGA_GREEN 	 = 2,
	VGA_CYAN 	 = 3,
	VGA_RED 	 = 4,
	VGA_MAGENTA  = 5,
	VGA_BROWN 	 = 6,
	VGA_LGREY 	 = 7,
	VGA_DGREY 	 = 8,
	VGA_LBLUE 	 = 9,
	VGA_LGREEN 	 = 10,
	VGA_LCYAN 	 = 11,
	VGA_LRED 	 = 12,
	VGA_LMAGENTA = 13,
	VGA_LBROWN 	 = 14,
	VGA_WHITE 	 = 15,
};

static inline uint8_t vga_entry_color(enum VGAColor fg, enum VGAColor bg) {
	return fg | bg << 4;
}

static inline uint16_t vga_entry(unsigned char uc, uint8_t color) {
	return (uint16_t) uc | (uint16_t) color << 8;
}

size_t strlen(const char *str) {
	size_t len = 0;
	while(str[len]) {
		++len;
	}

	return len;
}

static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;

size_t terminal_row;
size_t terminal_column;
uint8_t terminal_color;
uint16_t* terminal_buffer;

void terminal_init() {
	terminal_row = 0;
	terminal_column = 0;
	terminal_color = vga_entry_color(VGA_LGREY, VGA_BLACK);
	terminal_buffer = (uint16_t*) 0xb8000;

	for(int i = 0; i < VGA_HEIGHT; ++i) {
		for(int j = 0; j < VGA_WIDTH; ++j) {
			const size_t index = i * VGA_WIDTH + j;
			terminal_buffer[index] = vga_entry(' ', terminal_color);
		}
	}
}

void terminal_set_color(uint8_t color) {
	terminal_color = color;
}

void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
	const size_t index = y * VGA_WIDTH + x;
	terminal_buffer[index] = vga_entry(c, color);
}
void terminal_putchar(char c) {
	terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
	if (++terminal_column == VGA_WIDTH) {
		terminal_column = 0;
		if (++terminal_row == VGA_HEIGHT)
			terminal_row = 0;
	}
}

void terminal_write(const char* data, size_t size) {
	for (size_t i = 0; i < size; i++) {
		terminal_putchar(data[i]);
	}
}

void terminal_writestring(const char* data) {
	terminal_write(data, strlen(data));
}

void kernel_main(void) {
	terminal_init();
	terminal_writestring("Hello, kernel World!\n");
}

linker.ld

Code: Select all

ENTRY(_start)

SECTIONS
{
	. = 1M;

	.text BLOCK(4K) : ALIGN(4K)
	{
		*(.multiboot)
		*(.text)
	}

	.rodata BLOCK(4K) : ALIGN(4K)
	{
		*(.rodata)
	}

	.data BLOCK(4K) : ALIGN(4K)
	{
		*(.data)
	}

	.bss BLOCK(4K) : ALIGN(4K)
	{
		*(COMMON)
		*(.bss)
	}
}

Commands:

Code: Select all

nasm -felf32 boot.asm

gcc -m32 -c kernel_main.c -ffreestanding -O2 -std=gnu99 -Wall -Wextra

gcc -m32 -T linker.ld -o test.bin -ffreestanding -O2 -nostdlib boot.o kernel_main.o -lgcc
How I can solve this problem?
"The world is in greater peril from those who tolerate or encourage evil than from those who actually commit it." - Albert Einstein
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: No multiboot header found

Post by Octocontrabass »

Adrox wrote:I did exactly the same like bare bones tutorial
No you didn't. You need to use a cross-compiler.
Adrox
Posts: 9
Joined: Wed Dec 07, 2016 10:39 am

Re: No multiboot header found

Post by Adrox »

I built a cross-compiler now and it works but I can't link libgcc how can I build it it doesn't work
"The world is in greater peril from those who tolerate or encourage evil than from those who actually commit it." - Albert Einstein
Adrox
Posts: 9
Joined: Wed Dec 07, 2016 10:39 am

Re: No multiboot header found

Post by Adrox »

I just saw make all-target-libgcc doesn't work
../../gcc/libgcc.mvars is missing.
How can I solve this problem?
"The world is in greater peril from those who tolerate or encourage evil than from those who actually commit it." - Albert Einstein
Adrox
Posts: 9
Joined: Wed Dec 07, 2016 10:39 am

Re: No multiboot header found

Post by Adrox »

I have just solved the problem. I had to make it from a seperate directory
"The world is in greater peril from those who tolerate or encourage evil than from those who actually commit it." - Albert Einstein
Post Reply