Author Topic: entry point in elf format  (Read 16390 times)

edwin

  • Guest
entry point in elf format
« on: July 26, 2009, 01:22:10 AM »
IS there a way to set the entry point in an ELF file while directly assembling from NASM? Will I have to use a linker, or manually to do this?

ed

nobody

  • Guest
Re: entry point in elf format
« Reply #1 on: July 26, 2009, 02:55:57 AM »
Sure, you can do it "directly" ("main" in this example). I would suggest you *do* use a linker (ld), unless you have some reason not to (ld knows "_start", unless told otherwise with "-e").

Best,
Frank


[map all]
;===========================================================================
bits 32
    ORIGIN equ 8048000h
org ORIGIN
section .text
    code_offset equ 0
    code_addr:
;--------------------------- ELF header -----------------------------------
        dd $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
        dd 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
        dd 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096
main:
;--------- your code goes here ------------------------------------------



;------------ constant data ---------------------------------
; (note that we're in .text, not .rdata)
        align 4



;---------------------------------------------------------------------------
        align 4
        code_memsz equ $ - $$
        code_filez equ code_memsz
        data_addr equ (ORIGIN+code_memsz+4095)/4096*4096 + (code_filez % 4096)
        data_offset equ code_filez
section .data vstart=data_addr
;------------ initialized data ------------------------------



;---------------------------------------------------------------------------
    idat_memsz equ $ - $$
    bss_addr equ data_addr + ($ - $$)
section .bss  vstart=bss_addr
;--------------------------- uninitialized data ----------------------------



;---------------------------------------------------------------------------
    udat_memsz equ $ - $$
    data_memsz equ  idat_memsz + udat_memsz
    data_filez equ  idat_memsz
;===========================================================================

edwin

  • Guest
Re: entry point in elf format
« Reply #2 on: July 26, 2009, 03:57:34 AM »
I a using NASM 2.07 and unless i am doing something wring, it will not assemble an org directive when going to an elf file. I cannot compile your code.
I am booting a kernel with grub, it gives the error 'cannot load below 1meg'.  I have put in the kludge fix to set the loading address, then I get 'unsupported executable format '. Really not sure what I am missing here.

ed

edwin

  • Guest
Re: entry point in elf format
« Reply #3 on: July 26, 2009, 04:00:11 AM »
sorry, current code just tryin to get it to boot.:

[bits 32]

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
CHECKSUM               equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)


Start:
_start:
   jmp   MultiBoot_Entry


; The Multiboot header (in NASM syntax)
align 4
MultibootHeader:
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd CHECKSUM


HeaderAddress   dd   0x0cffffff - 512
LoadAddr   dd   0x0c000000
LoadEndAddr   dd   0;ProgEnd
BssEndAddr   dd   0;ProgEnd
EntryAddr   dd   0x0c000000 + Start
;
;ModeType   dd   0
;Width      dd   0
;Height      dd   0
;Depth      dd   0
;=== Multiboot header end

MultiBoot_Entry:
jmp   $