I'm coding a little kernel in C and ASM and I use only GCC + NASM for coding. GRUB loads my little kernel.
Everything goes well, but there is one really wired problem with ld, which I use for linking the stuff...
My kernel is about 8kb big and loads well with GRUB. But when I exceed a specific amount of code the size of my kernel goes up from 8kb to 1 MB and GRUB won't load it anymore.
It says, it won't recognize the file format anymore. So I think it doesn't finds the GRUB boot sigmature ( in entry.asm ) anymore.
I use following command for linking:The linker script link.ld:Code:ld -T link.ld -o kernel.bin entry.o main.o display.o memory.o string.o io.o gdt.o gdt_helper.oMy start code in entry.asm:Code:OUTPUT_FORMAT("binary") ENTRY(start) phys = 0x00100000; SECTIONS { .text phys : AT(phys) { code = .; *(.text) . = ALIGN(4096); } .data : AT(phys + (data - code)) { data = .; *(.data) . = ALIGN(4096); } .bss : AT(phys + (bss - code)) { bss = .; *(.bss) . = ALIGN(4096); } end = .; }I think the problem lies in the liker script, but I'm unable to find it myself...Code:[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_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 stublet: extern k_main call k_main jmp $ ; 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 8192 ; This reserves 8KBytes of memory here _sys_stack![]()
*sniff*



LinkBack URL
About LinkBacks



