Frustration over gcc/as combination

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
elfenix
Member
Member
Posts: 50
Joined: Sun Dec 02, 2007 1:24 pm
Libera.chat IRC: elfenix
Location: United States
Contact:

Frustration over gcc/as combination

Post 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.
cg123
Member
Member
Posts: 41
Joined: Wed Sep 27, 2006 2:34 pm

Post by cg123 »

This is because you declared it as an external pointer, Try declaring it as an external fixed-size array.
elfenix
Member
Member
Posts: 50
Joined: Sun Dec 02, 2007 1:24 pm
Libera.chat IRC: elfenix
Location: United States
Contact:

Post 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)
Post Reply