Booting with Grub problems.
Posted: Sat Sep 02, 2006 10:44 am
Hi everybody, I'm tring to boot a very simple kernel with grub but everytime I do it grub will complain that the kernel can't be loaded bellow 1mb of memory. I know that, that can happen under two situations when you actually load the kernel under the 1mb mark or when a very high memmory location is specified which "overlaps" and give the same error (#7).
Bellow is my asm file and the linker script:
asm:
linker_elf.ld:
the assembly file is taken from "Bran's Kernel Development Tutorial" from osdever.net and the linker script from
http://www.openbg.net/sto/os/xml/grub.html.
Btw, I'm working on a Linux machine and generating an ELF kernel, this is however working fine in Windows XP with DJGPP and a plaing bin image kernel. Any thoughts on what is the problem?
<pype:edit> "code" tag is preferred to "bold" for code snippets</pype>
Bellow is my asm file and the linker script:
asm:
Code: Select all
[BITS 32]
global start
start:
mov esp, _sys_stack ; This points the stack to our new stack area
jmp stublet
; 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_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
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
; This is an endless loop here. Make a note of this: Later on, we
; will insert an 'extern _main', followed by 'call _main', right
; before the 'jmp $'.
stublet:
extern main
call main
jmp $
;this loads our gdt here
global install_gdt
extern gdt
install_gdt:
lgdt [gdt]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:loadcs
loadcs:
ret
; Here is the definition of our BSS section. Right now, we'll use
; it just to store the stack. Remember that a stack actually grows
; downwards, so we declare the size of the data before declaring
; the identifier '_sys_stack'
SECTION .bss
resb 0x4000 ; This reserves 16KBs of memory here
_sys_stack:
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
virt = 0xC0000000; /* 3 gig */
phys = 0x100000; /* 1 meg */
SECTIONS
{ .text virt : AT(phys)
{ code = .;
*(.text)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{ data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{ bss = .;
*(.bss)
*(COMMON)
. = ALIGN(4096);
}
end = .;
}
http://www.openbg.net/sto/os/xml/grub.html.
Btw, I'm working on a Linux machine and generating an ELF kernel, this is however working fine in Windows XP with DJGPP and a plaing bin image kernel. Any thoughts on what is the problem?
<pype:edit> "code" tag is preferred to "bold" for code snippets</pype>