GRUB Error 7 Troubles

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
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

GRUB Error 7 Troubles

Post 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
Last edited by Marionumber1 on Thu Dec 29, 2011 9:10 am, edited 1 time in total.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: GRUB Error 7 Troubles

Post by xenos »

Since DJGPP is pretty outdated, you might consider using a GCC Cross-Compiler instead. It makes life much easier.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post by Marionumber1 »

I did build one in Cygwin, and it gets me Error 7, 13, or 28 when I tried to use it.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: GRUB Error 7 Troubles

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post 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.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: GRUB Error 7 Troubles

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GRUB Error 7 Troubles

Post 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?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post 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.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: GRUB Error 7 Troubles

Post by Combuster »

Have you tried the Bare Bones tutorial exactly as described
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post by Marionumber1 »

As I said, I was following Bran's tutorial.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: GRUB Error 7 Troubles

Post 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
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post 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?
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
User avatar
Marionumber1
Member
Member
Posts: 56
Joined: Sun May 08, 2011 9:03 am

Re: GRUB Error 7 Troubles

Post by Marionumber1 »

Never mind, I got it to build with my cross compiler.
Programmer and security enthusiast
DarkSide OS Kernel

Those who do not understand Windows NT are doomed to criticize it, poorly.
Post Reply