going from asm file to c/c++ file

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mostermand
Posts: 4
Joined: Sun Mar 22, 2009 1:31 pm

going from asm file to c/c++ file

Post by mostermand »

Hi I am just starting in OSDeving.
I am trying to make a flat binary file by linking an asm file and a cpp file with my cross compiler using a custom link script from "Bran's Kernel Development Tutorial".

I have a kernel_start.asm that jumps to extern _main which is defined in kernel.cpp.

I am getting the following error when trying to link it.

kernel_start.asm:(.text+0x1): undefined reference to `_main'

If anyone could help me in this matter I would be most grapefull(and grape tastes good)
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: going from asm file to c/c++ file

Post by gzaloprgm »

Try removing the underscore (_) from extern _main and call _main.
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
mostermand
Posts: 4
Joined: Sun Mar 22, 2009 1:31 pm

Re: going from asm file to c/c++ file

Post by mostermand »

funny before I read your reply I came to the same conclusion by disassemblying my object files but it still didn't work then I found out I was passing my arguments wrong to the linker now the problem is that even though the linker script specifies "binary" format I get an elf file
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: going from asm file to c/c++ file

Post by AJ »

Hi,

Have you taken account of C++ name mangling? IIRC a standards-compiant main function name does not normally get mangled, but if it's not compilant the name could get mangled anyway. Try defining main as 'extern "C" ' rather than just 'extern'.

As for the linker producing elf output instead of a flat binary, can we see your compiler and linker commands, along with the linker script?

Cheers,
Adam
mostermand
Posts: 4
Joined: Sun Mar 22, 2009 1:31 pm

Re: going from asm file to c/c++ file

Post by mostermand »

The name mangling is no longer a problem I figured it out as for the the linker commands and script here it is:

i586-elf-ld -t link.ld -o kernel.bin Kernel.o kernel_start.o

linker-script:

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: going from asm file to c/c++ file

Post by Creature »

I'm not sure, but, shouldn't rodata be in the data section? Doesn't the 'text' section define executable and read-only code whilst the 'data' section defines 'read/write, but non-executable code'?
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
mostermand
Posts: 4
Joined: Sun Mar 22, 2009 1:31 pm

Re: going from asm file to c/c++ file

Post by mostermand »

I'll check it out
Post Reply