Subject: Re: compile kernel under gcc2.7.1
To: None <niklas@appli.se>
From: David Mazieres <dm@amsterdam.lcs.mit.edu>
List: current-users
Date: 11/23/1995 15:48:55
> Date: Wed, 22 Nov 1995 10:27:28 +0100
> From: Niklas Hallqvist <niklas@appli.se>
> CC: current-users@netbsd.org
> Sender: owner-current-users@netbsd.org
> Precedence: list
> X-Loop: current-users@NetBSD.ORG
> 
> If anything does *not* work with any part of NetBSD and GCC 2.7.1 I
> certainly want to know about that.  This is one of my main interests
> keeping NetBSD support in GCC up-to-date.
> 
> Niklas

Gcc 2.7.1 seems to do strange things when you use arguments of inline
functions with "i" constraints (and no other possibilities) in asm
statements (even if you have verified that the argument is constant
with __builtin_constant_p).

This is used on the i386 in machine/pio.h, with things like:

#ifdef __OPTIMIZE__
#define __use_immediate_port(port) \
        (__builtin_constant_p((port)) && (port) < 0x100)
#else

#define inb(port) \
        (__use_immediate_port(port) ? __inbc(port) : __inb(port))

static __inline u_char
__inbc(int port)
{
        u_char  data;
        __asm __volatile("inb %1,%0" : "=a" (data) : "i" (port));
        return data;
}

static __inline u_char
__inb(int port)
{
        u_char  data;
        __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
        return data;
}

However, the good news is that the GCC people have added a new
constraint "N" for immediate constants < 0x100, making all that
horribly complicated stuff unnecessary.  With gcc 2.7.1 all you need
is one inline function:

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

(Note that you need the w in `%w1' because otherwise gcc will use
`%edx' instead of `%dx' and the assembler doesn't like this with inb.)

David