All of lore.kernel.org
 help / color / mirror / Atom feed
* Wired linker problem...
@ 2005-08-14 10:36 Jan Schiefer
  0 siblings, 0 replies; only message in thread
From: Jan Schiefer @ 2005-08-14 10:36 UTC (permalink / raw)
  To: linux-kernel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is not linux kernel related, but at least it's kernel releated.
So I think u're the experts, that can help me. :)



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: ld -T link.ld -o kernel.bin entry.o
main.o display.o memory.o string.o io.o gdt.o gdt_helper.o

The linker script link.ld:

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 = .;
}

My start code in entry.asm:

[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


I think the problem lies in the liker script, but I'm unable to find it
myself... *sniff* :(

Greetings,
Jan Schiefer!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC/x66zC00UKXFdVcRAhvNAJ9uQ5UOT4wvKk5kKWAdfHE4ZXc8fwCfc4cB
drqR27xFcBEhXNReznruMJo=
=DCVJ
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-14 10:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-14 10:36 Wired linker problem Jan Schiefer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.