Linking C and ASM

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
kernel

Linking C and ASM

Post by kernel »

I'm making a small Pmode kernel, and I can't seem to be able to link a compiled C file with a compiled ASM file!

What I am trying to do is have my ASM file be the 'start' of the kernel. inside the asm file, it calls a function from the C file.

I can't get them to link right. Here is my ASM code:

EXTERN _test

call _test
jmp $ ;hang

There is my C file:

void test() {
//Code Here
}

I am compiling the c file like this : gcc -O3 -c kernel_c.c
I am compiling the ASM like this: NASM -f obj kernel.asm

I am linking them with jloc like this: JLOC kernel.ld kernel.bin

The linker control file (kernel.ld) looks like this:
ALL:

kernel.obj
kernel_c.o
START: 0,0FF800000
,,code,,kernel.obj
CODE: 0
,,code
DATA: 0,#10
,,data
BSS: 0,#10
,,bss

(BTW, this is a Protected Mode Kernel loaded from the bootf02 bootstrap)

What am I doing wrong here? When I try to link it, it tells me that there are 'overlapping chunks' and 'unable to assign section for: ALL, kernel.obj, _NASMDEFSEG'

How do I link a C and an ASM file together and have the ASM file be the beginning of the kernel?
Willow

Re:Linking C and ASM

Post by Willow »

Me to i'm searching for that and no body want to anser me !!! :(
Tom

Re:Linking C and ASM

Post by Tom »

you do this, and you won't need a asm file

// C module
asm( "jmp test" );

test()
{
// code

while ( 1 )
;
}
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Linking C and ASM

Post by Pype.Clicker »

aouch! i dunno anything about JLOc, but you're trying to mix OBJ (16 bits format) with gcc output (32 bits format !!) thus nothing good can result of this %-?

i strongly recommend you select a 32 bits format like ELF, COFF with your asm file...
AIT

Re:Linking C and ASM

Post by AIT »

Try using the follwoing command line:

[pre]
>ld my_asm.o my_kernel_in_c.o -o kernel.bin -oformat binary -Ttext 0x100000[/pre]

Note that your start asm file should come first.
ydopostsdisapear?

Re:Linking C and ASM

Post by ydopostsdisapear? »

I want to say that obj can be 32 bit...

Ive been trying to use Borland C++ builder compiler and Watcom C++ as I realy dislike the DJGPP syntax and...

I like it to be ANSI. Ive tryed the 2 compilers with ELINK as I couldnt figgure out how to use JLOC. ELINK works fine for ONE obj... problem was that I never got to print a whole word on the screen.. it always printed 1 character(with proper colour and backcolour) when it didnt print 1 char it printed thi: "ooooooooo" and thats all

eventually I gave up cuz I had school... couldnt afford the time

now I got back to work but in a diff domain... Im working on a GUI... and Im writting it in boralnd C++(dos 16 bit) and I wrote a class to emulate a video driver using BGI(dont have time to write an actual video driver but I still need to keep the code modular so I can change the commpiler to 32 bit ansi and actual video driver)

Ill as well design a file system soon... on the lines of HPFS but with higher capacity... and wont be compatible with HPFS...

now I need some help I need to be able to compile my ANSI C++ code and link it and be able to load it..

Im asking for experience/help on a compiler like BC++B or Watcom C++ and how to use JLOC properly and efficiently

thanks.. let me know what you think
Post Reply