Page 1 of 1

Frustration over gcc/as combination

Posted: Sun Dec 02, 2007 1:57 pm
by elfenix
I'm attempting to remove all inline assembly from my C code so that I can port it to another compiler easily. The goal is to have a couple assembly files that perform all the compiler/hardware specific work there, so that I can port over to another arch easily.

In setting up my IDT, I'm trying to export a symbol from assembly, and use it in C. So, I define the IDT:

Code: Select all

.global idt
idt:
    .fill 512, 4, 0x0000
and then use it in C:

Code: Select all

     extern unsigned int* idt;

     ...

     idt[(vec * 2) + 0] = word1;
     idt[(vec * 2) + 1] = word2;
To my complete annoyance, this does not work. The assembly code generated is something to the affect of

Code: Select all

    mov idt, %edx
versus

Code: Select all

     mov $idt, %edx
Now, this cost me a whole afternoon of debugging time in bochs, trying to figure out why my interrupt table was not setup. The fix was to do this in C:

Code: Select all

    extern unsigned int idt;
    
    unsigned int* idt_ptr = &idt;
    
.... 
I've been trying to find some documentation on how to get around this. I guess I could define the idt in the C code, but I was rather hoping to keep it in the assembly for fine grained and compiler independent control.

Am I doing something wrong in the assembly section? I'm used to inline assembly in C, but not so much dealing with mixed C and .S files... Might be on the wiki, but I failed to get the right keyword magic to pull it up.

Posted: Sun Dec 02, 2007 2:00 pm
by cg123
This is because you declared it as an external pointer, Try declaring it as an external fixed-size array.

Posted: Sun Dec 02, 2007 2:16 pm
by elfenix
Thanks, that fixed it.

Shoulda figured this out earlier, guess I wasn't seeing the forest for the trees. It makes sense that an address to a pointer and an address to an array would be handled differently.

(That would be a loud D'Oh! from me)