64-bit Higher half with grub2
Posted: Sun Apr 03, 2011 6:36 am
After many problems in getting the GRUB2 menu show up using an ISO, I'm still not able to boot my 64bit kernel in higher half. The linker script as suggested on the wiki is:
I'm using Netbeans on Windows, using a cygwin x86_64 cross compiler and Nasm. Compiling with
Actually the only object is this asm file:
But GRUB2, after finding the Multiboot2 Header (which I'm sure it finds, it was the previous error and I fixed it), says:
error: invalid offset in section header.
The output of objdump on my test kernel is:
Someone has an idea? Thanks
EDIT: There was an empty c++ file which added a lot of sections in the objdump output. I cleared them out and removed the file from the project
Code: Select all
ENTRY(_entry)
OUTPUT_FORMAT(elf64-x86-64)
KERNEL_VIRT_ADDR = 0xFFFFFFFF80100000;
KERNEL_PHYS_ADDR = 0x0000000000100000;
KERNEL_BASE_ADDR = (KERNEL_VIRT_ADDR - KERNEL_PHYS_ADDR);
SECTIONS
{
. = KERNEL_PHYS_ADDR;
bootstrap :
{
build/Debug/Cross-x64-Windows/Boot.o *(.header)
build/Debug/Cross-x64-Windows/Boot.o *(.text)
build/Debug/Cross-x64-Windows/Boot.o *(.data)
build/Debug/Cross-x64-Windows/Boot.o *(.bss)
}
. += KERNEL_BASE_ADDR;
_start = .;
.text : AT(ADDR(.text) - KERNEL_BASE_ADDR)
{
. = ALIGN(64);
_code = .;
*(EXCLUDE_FILE(*build/Debug/Cross-x64-Windows/Boot.o) .text)
*(.rodata*)
. = ALIGN(4096);
}
.data : AT(ADDR(.data) - KERNEL_BASE_ADDR)
{
_data = .;
*(EXCLUDE_FILE(*build/Debug/Cross-x64-Windows/Boot.o) .data)
. = ALIGN(4096);
}
.eh_frame : AT(ADDR(.eh_frame) - KERNEL_BASE_ADDR)
{
EhFrame = .;
*(.eh_frame)
QUAD(0)
. = ALIGN(4096);
}
.bss : AT(ADDR(.bss) - KERNEL_BASE_ADDR)
{
_bss = .;
*(EXCLUDE_FILE(*build/Debug/Cross-x64-Windows/Boot.o) .bss)
*(COMMON)
. = ALIGN(4096);
}
_end = .;
/DISCARD/ :
{
*(.comment)
}
}
Code: Select all
x86_64-elf-ld.exe -nostdlib -nodefaultlibs -Tlinker.ld -z max-page-size=0x1000 -o $(OUTPUT) $(OBJECTS) -L. libgcc.a libsupc++.a
Code: Select all
MB2_MAGIC EQU 0xE85250D6
MB2_ARCH EQU 0
MB2_HDRLEN EQU (Mb2HdrEnd - Mb2Hdr)
MB2_CHECKSUM EQU -(MB2_MAGIC + MB2_ARCH + MB2_HDRLEN)
[SECTION .header]
ALIGN 64
Mb2Hdr:
DD MB2_MAGIC
DD MB2_ARCH
DD MB2_HDRLEN
DD MB2_CHECKSUM
DW 0, 0
DD 8
Mb2HdrEnd:
[BITS 32]
[SECTION .text]
[GLOBAL _entry]
_entry:
CLI
HLT
error: invalid offset in section header.
The output of objdump on my test kernel is:
Code: Select all
test.sys: file format elf64-x86-64
test.sys
architecture: i386:x86-64, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x0000000000100020
Program Header:
LOAD off 0x00000000000000f0 vaddr 0x0000000000100000 paddr 0x0000000000100000 align 2**4
filesz 0x000000000000006a memsz 0x000000000000006a flags r-x
LOAD off 0x000000000000015a vaddr 0xffffffff8010006a paddr 0x000000000010006a align 2**0
filesz 0x0000000000000000 memsz 0x0000000000000f96 flags r-x
LOAD off 0x000000000000015a vaddr 0xffffffff80101000 paddr 0x0000000000101000 align 2**0
filesz 0x0000000000001000 memsz 0x0000000000001000 flags rw-
Sections:
Idx Name Size VMA LMA File off Algn
0 bootstrap 0000006a 0000000000100000 0000000000100000 000000f0 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .text 00000f96 ffffffff8010006a 000000000010006a 0000015a 2**0
ALLOC, READONLY, CODE
2 .eh_frame 00001000 ffffffff80101000 0000000000101000 0000015a 2**0
CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
0000000000100000 l d bootstrap 0000000000000000 bootstrap
ffffffff8010006a l d .text 0000000000000000 .text
ffffffff80101000 l d .eh_frame 0000000000000000 .eh_frame
0000000000000000 l df *ABS* 0000000000000000 Boot.asm
00000000e85250d6 l *ABS* 0000000000000000 MB2_MAGIC
0000000000000000 l *ABS* 0000000000000000 MB2_ARCH
0000000000000018 l *ABS* 0000000000000000 MB2_HDRLEN
ffffffff17adaf12 l *ABS* 0000000000000000 MB2_CHECKSUM
0000000000100000 l O bootstrap 0000000000000004 Mb2Hdr
0000000000100018 l bootstrap 0000000000000000 Mb2HdrEnd
ffffffff80100000 g *ABS* 0000000000000000 KERNEL_VIRT_ADDR
ffffffff80102000 g .eh_frame 0000000000000000 _bss
ffffffff8010006a g *ABS* 0000000000000000 _start
0000000000100020 g bootstrap 0000000000000000 _entry
ffffffff80101000 g .eh_frame 0000000000000000 EhFrame
ffffffff80000000 g *ABS* 0000000000000000 KERNEL_BASE_ADDR
ffffffff80101000 g .text 0000000000000000 _data
ffffffff80102000 g *ABS* 0000000000000000 _end
0000000000100000 g *ABS* 0000000000000000 KERNEL_PHYS_ADDR
ffffffff80100080 g .text 0000000000000000 _code
EDIT: There was an empty c++ file which added a lot of sections in the objdump output. I cleared them out and removed the file from the project