No multiboot header found
Posted: Sat Dec 10, 2016 7:54 am
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
kernel_main.c
linker.ld
Commands:
How I can solve this problem?
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:
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");
}
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)
}
}
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