Inline Assembly Problems

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
chris

Inline Assembly Problems

Post by chris »

Code: Select all

[Aurora:~/aurora/dev] chris% gcc -c -I ./include misc.c
misc.c: In function `outb':
misc.c:12: error: inconsistent operand constraints in an `asm'
[Aurora:~/aurora/dev] chris% 
Misc.c

Code: Select all

inline void outb(unsigned int port,unsigned char value)  // Output a byte to a port
{
    asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
};

inline void outw(unsigned int port,unsigned int value)  // Output a word to a port
{
    asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
};

inline unsigned char inb(unsigned short port)
{
   unsigned char ret_val;

   asm volatile("inb %w1,%b0"
      : "=a"(ret_val)
      : "d"(port));
   return ret_val;
};

Code: Select all

[Aurora:~/aurora/dev] chris% gcc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
Not sure what's wrong here.
lea

Re:Inline Assembly Problems

Post by lea »

Not really sure how inline assembly works in gcc, but I would guess the error is because dx is a 16 bit register and port is a 32 bit int.
chris

Re:Inline Assembly Problems

Post by chris »

Hmm.. works fine on FreeBSD.. err Apples version of gcc = PPC Assembly?
lea

Re:Inline Assembly Problems

Post by lea »

If it works on FreeBSD then I don't think there is anything wrong with your code. You probably need to rebuild gcc with x86 support if it doesn't already include it and tell it that you want it to produce x86 code. I am pretty sure Apples version of gcc doesn't produce x86 code by default ;)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Inline Assembly Problems

Post by df »

inline assembly is notorious for break in every .point release of gcc.. :(
-- Stu --
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Inline Assembly Problems

Post by Perica »

..
Last edited by Perica on Tue Dec 05, 2006 9:24 pm, edited 1 time in total.
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:Inline Assembly Problems

Post by Pype.Clicker »

from the "--version" info shown, i'm pretty sure your GCC is for PPC only and thus it is unable to generate opcodes from intel assembly.

Try to get the sources of GCC and recompile a cross-compiler or try to search MacOSx packages for a x-86 cross-compiler.
Post Reply