Grub error #13

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
AdMiNeK
Posts: 8
Joined: Wed Jul 02, 2008 1:52 pm
Location: Brodnica, Poland
Contact:

Grub error #13

Post by AdMiNeK »

Hi,
Sorry for my English,
I've been rewriting my kernel and adding some features to my OS, and I've decided to rewrite my entry point to AT&t assembler. After that when I booting my kernel GRUB returns error #13 (Invalid or unsupported executable format)

There are sources:

start.S

Code: Select all

include <config.h>

#include <arch/x86/page.h>
#include <multiboot.h>

#define STACKSIZE 0x4000          // that is, 16k.

// setting up the Multiboot header - see GRUB docs for details
.section .mboot
.global start
start:
    jmp stage1

.align 4

mboot_header:
    .long MBOOT_MAGIC
    .long MBOOT_FLAGS
    .long MBOOT_CHECKSUM

.text

.extern pagedir
.extern pagetab

#ifdef __CONFIG_CPU_PAE
    .extern pagedir_ptr
#endif

.global stage1
stage1:

   mov   $(stack + STACKSIZE - KERNEL_BASE_ADDR), %esp
   push  %eax
   push  %ebx

    #ifdef __CONFIG_CPU_PAE
        movl $4, %ecx
        movl pagedir_ptr, %esi
        subl $KERNEL_BASE_ADDR, %esi
        .fill_ptr:
            movl $0, (%esi)
            addl $8, %esi
            loop .fill_ptr
    #endif

    movl $PGTAB_MAX, %ecx
    #ifdef __CONFIG_CPU_PAE
        // Map 4 MB!
        shll $1, %ecx
    #endif
    xorl %edx, %edx
    movl $KERNEL_TO_PSYH(pagetab), %esi
    .fill_pagetab:
        movl %edx, (%esi)
        orl $0x3, (%esi)
        addl $PAGE_SIZE, %edx
        addl $PAGE_ENTRY_SIZE, %esi
        loop .fill_pagetab

    movl $PGDIR_MAX, %ecx
    movl $KERNEL_TO_PSYH(pagedir), %esi
    .clear_pgdir:
        movl $0, (%esi)
        addl $PAGE_ENTRY_SIZE, %esi
        loop .clear_pgdir

    movl $KERNEL_TO_PSYH(pagedir), %esi
    movl $KERNEL_TO_PSYH(pagetab), %edi
    #ifdef __CONFIG_CPU_PAE
        movl %edi, (%esi)
        orl $0x3, (%esi)
    #else
        addl $(768 * 4), %esi
        movl %edx, (%esi)
        orl $0x3, (%esi)
    #endif

    #ifdef __CONFIG_CPU_PAE
        movl $KERNEL_TO_PSYH(pagedir_ptr), %esi
        movl $KERNEL_TO_PSYH(pagedir), %edi
        movl %edi, 32(%esi)
        movl %edi, (%esi)
        orl $0x01, 32(%esi)
        orl $0x01, (%esi)

        movl %cr4, %edx
        orl $0x20, %edx
        movl %edx, %cr4

        movl $KERNEL_TO_PSYH(pagedir_ptr), %edx
        movl %edx, %cr3
    #else
        movl $KERNEL_TO_PSYH(pagedir), %edx
        movl %edx, %cr3
    #endif

    movl %cr0, %edx
    orl $0x80000000, %edx
    movl %edx, %cr0

    lea (stage2), %ecx
    jmp *%ecx
stage2:
    addl $KERNEL_BASE_ADDR, %esp
    .extern main
    call main

.bss
// reserve initial kernel stack space
.comm stack, STACKSIZE, 32      // reserve 16k stack on a quadword boundary
kernel.ld:

Code: Select all

ENTRY(start)
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH("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) {
       arch/x86/start.o(.mboot)
       *(.text)
       *(.rodata*)
   }

   .data ALIGN (0x1000) : AT(ADDR(.data) - 0xC0000000) {
       tty_vga = .; . += 8 * 0x1000;
       *(.data)
   }

   .bss : AT(ADDR(.bss) - 0xC0000000) {
       _sbss = .;
       *(COMMON)
       *(.bss)
       _ebss = .;
   }
   end = . ; _end = . ;
}
mbchk tells that there is no multiboot header... how to fix it?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Grub error #13

Post by Kevin »

How are the MBOOT_* constants defined? Maybe you're trying to use a wrong checksum or something. Another common cause is that the multiboot header isn't contained in the first 8k of the binary, but given your kernel size this seems unlikely in your case.
Developer of tyndur - community OS of Lowlevel (German)
AdMiNeK
Posts: 8
Joined: Wed Jul 02, 2008 1:52 pm
Location: Brodnica, Poland
Contact:

Re: Grub error #13

Post by AdMiNeK »

Constants are defined:

Code: Select all

#define MBOOT_MAGIC 0x2BADB002
#define MBOOT_MODULEALIGN ( 1 << 0 ) 
#define MBOOT_MEMINFO     ( 1 << 1 ) 
#define MBOOT_FLAGS       MBOOT_MODULEALIGN | MBOOT_MEMINFO
#define MBOOT_CHECKSUM    -(MBOOT_MAGIC + MBOOT_FLAGS)
I have no idea what is wrong in my code. But it's not working...
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Grub error #13

Post by Kevin »

The magic is wrong, it should be 0x1badb002.
Developer of tyndur - community OS of Lowlevel (German)
AdMiNeK
Posts: 8
Joined: Wed Jul 02, 2008 1:52 pm
Location: Brodnica, Poland
Contact:

Re: Grub error #13

Post by AdMiNeK »

What a stupid mistake... thanks for help :) now it's work.
Post Reply