Page 1 of 1

Inline Assembly Problems

Posted: Thu Jan 01, 2004 6:04 pm
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.

Re:Inline Assembly Problems

Posted: Thu Jan 01, 2004 6:21 pm
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.

Re:Inline Assembly Problems

Posted: Thu Jan 01, 2004 6:31 pm
by chris
Hmm.. works fine on FreeBSD.. err Apples version of gcc = PPC Assembly?

Re:Inline Assembly Problems

Posted: Thu Jan 01, 2004 6:56 pm
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 ;)

Re:Inline Assembly Problems

Posted: Fri Jan 02, 2004 7:43 am
by df
inline assembly is notorious for break in every .point release of gcc.. :(

Re:Inline Assembly Problems

Posted: Fri Jan 02, 2004 7:52 am
by Perica
..

Re:Inline Assembly Problems

Posted: Sat Jan 03, 2004 4:58 am
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.