Linux->Nasm->Flush ports

Programming, for all ages and all languages.
Post Reply
yousafsajjad
Posts: 5
Joined: Thu Jul 08, 2010 6:03 pm

Linux->Nasm->Flush ports

Post by yousafsajjad »

Hi,

I am using the following code to flush port:

in al, 081h
out 081h, al

but it is giving me segmentation fault. Does anyone how I can do it.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Linux->Nasm->Flush ports

Post by gravaera »

Hi:

Please explain what you mean by "flushing" a port: in that code all you do is read from port I/O and then write the value back. Technically, this is just an unnecessary delay: devices usually have specific read/write sequences which trigger device responses, and interacting with port mapped I/O unnecessarily is just introducing unnecessary latency and probably causing the device to do undesired operation anyway.

Also, I/O reads and writes are usually implemented using some protocol between the processor and bus, and this has overhead, plus the fact that the firmware will then have to, in its own chipset specific manner redirect your I/O signal to the right device, etc etc: all you're doing is causing unnecessary hassle.

If a device requires a "flush", it will tell you so in its datasheet and it will tell you how to do so. But you don't go around "flushing" port mapped regs.

--All the best,
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Linux->Nasm->Flush ports

Post by Brynet-Inc »

I would be very surprised if Linux allowed direct I/O access like that, also, if that's the bulk of your program.. it will not execute.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
yousafsajjad
Posts: 5
Joined: Thu Jul 08, 2010 6:03 pm

Re: Linux->Nasm->Flush ports

Post by yousafsajjad »

yeah you are right .. i am calling an assembly function from C. So I need to get permission to that port using ioperm() first and than it works.
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Re: Linux->Nasm->Flush ports

Post by ucosty »

yousafsajjad wrote:yeah you are right .. i am calling an assembly function from C. So I need to get permission to that port using ioperm() first and than it works.
According to http://www.pcguide.com/ref/mbsys/res/ioSummary-c.html, port 81h is a DMA page register. I doubt very much that your code does what you think or even want.
The cake is a lie | rackbits.com
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Linux->Nasm->Flush ports

Post by pcmattman »

I believe the OP is looking for something like "iodelay()", often implemented like so:

Code: Select all

inline void iodelay(){
    outl(0x80, inl(0x80));
}
Port 0x80 is often used in this way as a delay+flush operation.
yousafsajjad
Posts: 5
Joined: Thu Jul 08, 2010 6:03 pm

Re: Linux->Nasm->Flush ports

Post by yousafsajjad »

Yeah you are right its DMA register and I have done what I intended to do. Thanks guys
Post Reply