Page 1 of 2
link c/asm
Posted: Mon Oct 19, 2009 1:49 pm
by lama
hi ,
i have these two test files:
prepc.asm
Code: Select all
global _start
extern main
_start:
mov ax, 0x10
mov ds, ax
mov ax, 0x18
mov es, ax
mov esi, 0x600
mov edi, pre
mov ecx, 0x1c00
cld
rep movsb
mov ax, 0x18
mov ds, ax
call main
pre:
times 0x1c00 db 0
pstst.c
Code: Select all
void main(){
__asm__ ("cli");
__asm__ ("hlt");
}
so as you can see - i want to do some stuff and then jump to main().What i dont know is, how can i link these files together to create pure binary.(using ld).thanks a lot for showing me how to do that
Re: link c/asm
Posted: Mon Oct 19, 2009 2:35 pm
by scgtrp
Compile them both to a.out/ELF/COFF/anything else besides flat binary, then:
Code: Select all
ld -Ttext 0x100000 -m binary obj1.o obj2.o -o kernel.bin
Replace 0x100000 with the address where your kernel is loaded.
Re: link c/asm
Posted: Tue Oct 20, 2009 1:40 am
by lama
i tried that, -i compiled pstst.c using 'gcc -c pstst.c -std=c99' (loops)
and preps.asm with 'nasm preps.asm -f coff' .but executing the following link command 'ld -Ttext 0 -m binary preps.o pstst.o -o ps.bin
failes with : ld: unrecognised emulation mode: binary
Supported emulations: elf_i386 i386linux elf_x86_64
whats wrong now?
Re: link c/asm
Posted: Tue Oct 20, 2009 3:29 am
by Combuster
you don't want to set the default format, you want to set the output format: --oformat=binary
Oh and, before you report more problems.
GCC Cross-Compiler
Re: link c/asm
Posted: Tue Oct 20, 2009 4:18 am
by lama
used 'ld preps.o pstst.o -o ps.bin --oformat binary -Ttext 0'
preps.o: file not recognized: File format not recognized...
Re: link c/asm
Posted: Tue Oct 20, 2009 4:21 am
by Solar
lama wrote:preps.o: file not recognized: File format not recognized...
Well?
What's the format of preps.o, that it is not recognized? Did you try to find out? If not, why not? If yes, why didn't you provide the information to us (if it didn't already give you the critical hint as to what the problem was)?
Hint: 'file' is a very useful tool.
Re: link c/asm
Posted: Tue Oct 20, 2009 4:36 am
by lama
preps is compiled into coff.
Re: link c/asm
Posted: Tue Oct 20, 2009 5:01 am
by Solar
lama wrote:failes with : ld: unrecognised emulation mode: binary
Supported emulations: elf_i386 i386linux elf_x86_64
lama wrote:preps is compiled into coff.
Do you notice something?
Re: link c/asm
Posted: Tue Oct 20, 2009 5:37 am
by Combuster
Do you notice something?
I notice the OP is
not ready for OS development. He fails to see the solution even when stabbed twice with the Page Of Answers, besides breaking half the rules.
Re: link c/asm
Posted: Tue Oct 20, 2009 5:50 am
by lama
so i have to build brand new gcc compiler ..? ok
Re: link c/asm
Posted: Tue Oct 20, 2009 6:09 am
by lama
to Combuster:
i just wanted to know how to handle with gcc properly , when i want to mix asm codes with c codes, thats all.i have never programmed in c, so i never had to use gcc, i dont have to use c for my project at all - i can do it in asm , but again : a just wanted to try a different way how to do that.so , please dont blame me from my stupidity.
Re: link c/asm
Posted: Tue Oct 20, 2009 6:37 am
by Combuster
I rest my case.
Re: link c/asm
Posted: Tue Oct 20, 2009 7:19 am
by pguy
prepc.asm != preps.asm. Did you change the name?
Re: link c/asm
Posted: Tue Oct 20, 2009 7:33 am
by lama
nn names are correct, thats just spell check or whatewher.but that guy above said , that he's done with me , so great - i will built that gcc cc, or screw c and continue writing asm , or shoot myself .But probably i'm no use, so no mather what i do - it will be wrong.but that's not a part of a topic, sorry about that.
Re: link c/asm
Posted: Tue Oct 20, 2009 8:06 am
by Solar
Come on. You were given helpful hints, but it was apparent by your subsequent posts that you ignored them. This happens quite often on this forum, which results in rather little tolerance toward that behaviour.
Yes, this wasn't something that earned you fame, but that doesn't mean you're a failure. Only throwing the towel and stopping to learn new things would mean that.
If there is something you didn't understand, ask the proper question, and you will be answered. But you didn't tell us you don't know about C, for example, which might have softened the response you got.