long outport help [FIXED]

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
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

long outport help [FIXED]

Post 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!
Last edited by GLneo on Wed Feb 07, 2007 6:43 pm, edited 1 time in total.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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.. :)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

that worked!, thx!, but what was i doing wrong?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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 ;)
Attachments
for-GLneo.tar
(10 KiB) Downloaded 115 times
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply