Page 1 of 1

long outport help [FIXED]

Posted: Wed Feb 07, 2007 5:13 pm
by GLneo
hi all,

In the OSWIKI thing , says:
the functions sysOutLong and sysInLong are assembly language functions that make use of the OUTL and INPL Pentium assembly language instructions.
but i can't figure out how to write them, i've tried:

Code: Select all

inline unsigned int inportl(unsigned int port)
{
    unsigned int result;
    asm volatile("inl %1, %0" : "=a" (result) : "dN" (port));
    return result;
}

inline void outportl(unsigned int port, unsigned int data)
{
    asm volatile("outl %1, %0" : : "dN" (port), "a" (data));
}
but it says:
Error: suffix of operand invaled for "out"
thx!

Posted: Wed Feb 07, 2007 6:22 pm
by Brynet-Inc

Code: Select all

inline unsigned long inportl(unsigned short port)
{
	unsigned long result;
	__asm__ __volatile__("inl %%dx, %%eax" : "=a" (result) : "dN" (port));
	return result;
}

inline void outportl(unsigned short port, unsigned long data)
{
	__asm__ __volatile__("outl %%eax, %%dx" : : "d" (port), "a" (data));
}
This should be adequate.. :)

Posted: Wed Feb 07, 2007 6:42 pm
by GLneo
that worked!, thx!, but what was i doing wrong?

Posted: Wed Feb 07, 2007 6:48 pm
by Brynet-Inc
GLneo wrote:that worked!, thx!, but what was i doing wrong?
I attached a unified patch... It should outline the changes I made ;)

Posted: Thu Feb 08, 2007 1:54 am
by Combuster
As if a diff would explain the difference between correct and broken code...

What you did was suggesting gcc to fill in the most optimizer-effective registers it could spare (using %1, %0). However, inports and outports work only with one pair of registers: DX and AL/AX/EAX. Since you didnt tell it, it'd try to fill in some random register which would obviously fail the assembly stage.