*BSD News Article 28992


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!ihnp4.ucsd.edu!swrinde!cs.utexas.edu!howland.reston.ans.net!pipex!sunic!EU.net!Germany.EU.net!lemis!grog
From: grog@lemis.uucp (Greg Lehey)
Newsgroups: comp.os.386bsd.development
Subject: Re: Gnu Inline Assembly question
Message-ID: <3105@adagio.lemis.uucp>
Date: 2 Apr 94 07:56:05 GMT
References: <2n76gvINNbjn@uwm.edu>
Organization: LEMIS, W-6324 Feldatal, Germany
Lines: 43

In article <2n76gvINNbjn@uwm.edu> knier@miller.cs.uwm.edu (Robert Knier ) writes:
>
> Sorry if this doesn't belong here - but since this is for
> developing a Future Domain, Seagate ST01/02 device driver here goes.
> Does any one have info on inline assembly with the gnu compiler?  More
> specifically, I am trying to write some assembly code to speed up data
> transfer to and from a future domain card.  I am wondering on the
> syntax of inline assembly code.

Read the gcc documentation. It is not as simple as it might appear: in
particular, you need to supply parameters and type information. I have
found it easier to do this by defining an inline function which
actually does the work, e.g.:

static INLINE void
outb (short port, char val)
{
  __asm__ volatile ("out%B0 %0,%1"::"a" (val), "d" (port));
}

static INLINE unsigned char
inb (short port)
{
  unsigned int ret;
  __asm__ volatile ("in%B0 %1,%0":"=a" (ret):"d" (port));
  return ret;
}

From memory, the __asm__ command is split into 3 parts, separated by
colons (logical, isn't it?). The first is the code itself, the second
is an input parameter list, the third is a return parameter list. The
parameters are referred to by position (%0, %1, etc.) in the code. The
"=a" and "d" in the example above are information on what kind of
parameter may be supplied - this is discussed in some depth in the gcc
manual, and I find I always have to go back to check up, so I won't go
into more detail here (and risk making mistakes :-).


-- 
---------------------------------------------
Greg Lehey              | Tel:  +49-6637-1488              
LEMIS, Schellnhausen 2, | Fax:  +49-6637-1489
36325 Feldatal, Germany | Mail: grog@lemis.de