I was transforming my kernel from 32bit to 64 but when I modified my ld script and the assembly entry of the kernel appeared this problem: the linker puts 1MB of zeros between the elf header and the multiboot header and the entry and also between the entry and the kernel (that for the moment I simplified to an empty c++ function) making the binary 2,2MB large and making grub not detecting the multiboot header. To find the problem I left only the multiboot header and a loop in my assembly entry file and only the boot section in the ld script but the problem persists.
my simplified entry is this
Code: Select all
[BITS 32]
extern _loadStart
extern _loadEnd
extern _bssEnd
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; MULTIBOOT HEADER
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
section .multibootheader
ALIGN 8
Mb1Hdr:
;MULTIBOOT 1
magic dd 0x1badb002
flags dd 0x2
checksum dd -0x1badb002-0x2
Mb1HdrEnd:
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; CODICE
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
section .boot
global loader
loader:
xchg bx,bx
hang:
hlt
jmp hang
and the ld script is this
Code: Select all
ENTRY (loader)
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT(kernel.bin)
SECTIONS
{
. = 0x100000;
.boot :
{
*(.multibootheader )
_loadStart = . ;
*(.boot)
}
_loadEnd = .;
_bssEnd = .;
}
Code: Select all
readelf -S kernel.bin
There are 5 section headers, starting at offset 0x100038:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .boot PROGBITS 0000000000100000 00100000
0000000000000012 0000000000000000 A 0 0 8
[ 2] .shstrtab STRTAB 0000000000000000 00100012
0000000000000021 0000000000000000 0 0 1
[ 3] .symtab SYMTAB 0000000000000000 00100178
0000000000000150 0000000000000018 4 10 8
[ 4] .strtab STRTAB 0000000000000000 001002c8
0000000000000062 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
thank you in advance if you know what I'm doing wrong or what's causing this.