Page 1 of 1

GRUB Error 7 Troubles

Posted: Sat May 14, 2011 7:22 pm
by Marionumber1
Hi, I'm new to this forum! :D

Anyway, I was developing an operating system under DJGPP (following Bran's Kernel Development Tutorial) and it worked until I had to switch to using FreeDOS (due to getting a new 64 bit computer). Whenever I try to run it, I always get GRUB Error 7.

My linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)

SECTIONS {
  .text 0x0100000 : {
    code = .;
    *(.text)
    . = ALIGN(4096);
  }

  .data : {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }

  .bss : {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }

  end = .;
}
And my assembler file:

Code: Select all

[BITS 32]
[extern code]
[extern bss]
[extern end]
[extern _main]
[global start]

; This part MUST be 4byte aligned, so we solve that issue using 'ALIGN 4'
ALIGN 4
mboot:
    ; Multiboot macros to make a few lines later more readable
    MULTIBOOT_PAGE_ALIGN        equ 1<<0
    MULTIBOOT_MEMORY_INFO       equ 1<<1
    MULTIBOOT_AOUT_KLUDGE       equ 1<<16
    MULTIBOOT_HEADER_MAGIC      equ 0x1BADB002
    MULTIBOOT_HEADER_FLAGS      equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_AOUT_KLUDGE
    MULTIBOOT_CHECKSUM  equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
    EXTERN code, bss, end

    ; This is the GRUB Multiboot header. A boot signature
    dd MULTIBOOT_HEADER_MAGIC
    dd MULTIBOOT_HEADER_FLAGS
    dd MULTIBOOT_CHECKSUM
    
    ; AOUT kludge - must be physical addresses. Make a note of these:
    ; The linker script fills in the data for these ones!
    dd mboot
    dd code
    dd bss
    dd end
    dd start

Re: GRUB Error 7 Troubles

Posted: Sun May 15, 2011 1:14 am
by xenos
Since DJGPP is pretty outdated, you might consider using a GCC Cross-Compiler instead. It makes life much easier.

Re: GRUB Error 7 Troubles

Posted: Sun May 15, 2011 6:16 am
by Marionumber1
I did build one in Cygwin, and it gets me Error 7, 13, or 28 when I tried to use it.

Re: GRUB Error 7 Troubles

Posted: Sun May 15, 2011 7:12 am
by xenos
That looks like a problem with the boot image. How do you create the boot image? Are you booting from a disk image or a real floppy / CD / HDD? Are you booting a real computer or a virtual one, such as Bochs, QEMU, VBox...? Which GRUB version are you using?

Just one quick remark about your multiboot header: In which section does it end up? Did you check that it is placed somewhere in the first 8k of the kernel binary? If not, GRUB will complain and give you an error 13.

Re: GRUB Error 7 Troubles

Posted: Sun May 15, 2011 7:16 am
by Marionumber1
I was creating an ELF with my cross compiler (i586-elf-xxx). I was using AS because LD wouldn't recognize the format of a NASM output file. And I took my ELF file, put it in /boot, and used GRUB legacy to load it on real hardware.

Re: GRUB Error 7 Troubles

Posted: Sun May 15, 2011 8:39 am
by xenos
In that case I recommend that you test your ELF kernel using a PC simulator before you try it on real hardware - that makes debugging much easier.

The best debugging support I found is that of Bochs, but you can also try QEMU, which has the nice feature that it can directly load multiboot kernels with the "-kernel" option.

Re: GRUB Error 7 Troubles

Posted: Mon May 16, 2011 4:12 am
by Combuster
Marionumber1 wrote:I was using AS because LD wouldn't recognize the format of a NASM output file.
Then you're not using your tools correctly. NASM has a host of formats it can output to, ELF included. It does not magically know however that you want an ELF-formatted file.


Have you tried the Bare Bones tutorial exactly as described, or are you trying to work out your own approach?

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 9:00 am
by Marionumber1
Sorry that I've been away for a while, but I've just been busy. Anyway, I was following Bran's Kernel Dev tutorial and when I used i586-elf-ld to link, it said that my ISR and IRQ routines couldn't be found. His tutorial says that you add leading underscores to every symbol name, but that didn't work. I also tried removing those underscores, which also failed.

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 12:05 pm
by Combuster
Have you tried the Bare Bones tutorial exactly as described

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 1:10 pm
by Marionumber1
As I said, I was following Bran's tutorial.

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 1:29 pm
by AJ
Hi,
Combuster wrote:
Marionumber1 wrote:I was using AS because LD wouldn't recognize the format of a NASM output file.
Then you're not using your tools correctly.

What does objdump tell you? Are you certain you're using your cross-ld? Could you post the output of ld -V and the objdump of your binary?

Cheers,
Adam

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 1:42 pm
by Marionumber1
If I build with my cross compiler in Cygwin, the build works.

Output of ld -V:

Code: Select all

GNU ld (GNU Binutils) 2.21
  Supported emulations:
   elf_i386
And what information should I dump in OBJDump?

Re: GRUB Error 7 Troubles

Posted: Thu Dec 29, 2011 6:44 pm
by Marionumber1
Never mind, I got it to build with my cross compiler.