0

I am writing a simple 32-bit kernel. I'm booting with GRUB. Here is the code:

#include <stdio.h>
#include <sys/kernel.h>
#include <sys/tty.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <keys.h>
#include <sys/sata.h>
#include <string.h>
#include <sys/iob.h>

void *free_space;

void *kmalloc(size_t s) {
    void *block = free_space;
    free_space += s;
    return block;
}
void meminit() {
    /* Initialize the heap. It starts at 0xC0200000. */
    free_space = (void *)0xC0200000;
}
char *buffer;

void read() {
  buffer = malloc(512);
  read_sata(0, 1, buffer);
}
void check() {
  //outb(0x1F0, 0x00);
  //printf("%d\n", inw(0x1F0));
}
void kernel_init(void) {
  keys_init();
  meminit();
}
void kernel_main(void) {
  /* Initialize terminal interface */
  terminal_initialize();

  check();
  abort();
}

linker script:

ENTRY(_start)
OUTPUT_FORMAT(elf32-i386)

SECTIONS {
   /* The kernel will live at 3GB + 1MB in the virtual
      address space, which will be mapped to 1MB in the
      physical address space. */
   . = 0xC0100000;

   .text : AT(ADDR(.text) - 0xC0000000) {
       *(.text)
       *(.rodata*)
   }

   .data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
       *(.data)
   }

   .bss : AT(ADDR(.bss) - 0xC0000000) {
   _sbss = .;
       *(COMMON)
       *(.bss)
       _ebss = .;
   }
}

When i check if the multiboot header is valid, grub-file --is-x86-multiboot kernel.bin, it returns 1 (error). But when I comment the read() function, it's bootable. What is wrong here? Is it too large? The kernel is around 20KB.

SpilledMango
  • 575
  • 7
  • 25

0 Answers0