Subject: Re: asm constraints in machine/pio.h and gcc-2.7.2
To: None <chase@ece.utexas.edu>
From: David Mazieres <dm@amsterdam.lcs.mit.edu>
List: port-i386
Date: 12/07/1995 12:20:25
> From: "Craig M. Chase" <chase@pine.ece.utexas.edu>
> Date: Wed, 6 Dec 1995 17:03:51 -0600 (CST)
> Reply-To: "Craig M. Chase" <chase@ece.utexas.edu>
> Organization:  Department of Electrical and Computer Engineering 
> X-Address: The University of Texas at Austin, Austin, TX 78712
> X-Phone: (512) 471 7457
> X-Fax: (512) 471 5907
> X-Mailer: ELM [version 2.4 PL24 ME8b]
> MIME-Version: 1.0
> Content-Type: text/plain; charset=US-ASCII
> Content-Transfer-Encoding: 7bit
> Content-Length:       1303
> Sender: owner-port-i386@NetBSD.ORG
> Precedence: list
> X-Loop: port-i386@NetBSD.ORG
> 
> Greetings,
> 
> I tried compiling NetBSD-current (12/5/95) with gcc-2.7.2 and
> encountered a little trouble with machine/pio.h
> 
> The offending lines are:
> 
> __inbc(int port)
> {
> 	u_char	data;
> 	__asm __volatile("inb %1,%0" : "=a" (data) : "i" (port));
> 	return data;
> }

The builtin_constant_p hack does not work any more, because asm
statements can't seem to use the arguments of inline functions as
immediates (even when they really are).  However, a new constraint `N'
corresponds to small immediates, so there is no need for this
complicated scheme.  You can simply have one inb function which
handles both the dx register and the small port number case:

inb (int port)
{
  unsigned char data;
  asm volatile ("inb %w1,%b0" : "=a" (data) : "Nd" (port));
  return (data);
}

static inline unsigned short
inw (int port)
{
  unsigned short data;
  asm volatile ("inw %w1,%w0" : "=a" (data) : "Nd" (port));
  return (data);
}

static inline unsigned int
inl (int port)
{
  unsigned int data;
  asm volatile ("inl %w1,%0" : "=a" (data) : "Nd" (port));
  return (data);
}

David