/* vim: set filetype=c:
 *
 * port.h86  -  Port I/O interface routines for C
 *
 * Copyright (C) 2004-2007 Gero Kuhlmann   <gero@gkminix.han.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: port.h86,v 1.5 2007/01/06 18:30:54 gkminix Exp $
 */


#ifndef I386_PORT_H86
#define I386_PORT_H86



/*
 **************************************************************************
 *
 * This file can not be included into assembler source
 */
#ifndef _ASSEMBLY_

#include <common.h86>



/*
 **************************************************************************
 *
 * Port input routines
 */

/* Read a byte from a port address */
__nb_inline__ __u8 in_byte(unsigned short portnum)
{
  register __u8 ret;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"inb %%dx,%%al"
	: "=a" (ret)
	: "d" (d0));
  return(ret);
}


/* Read a word from a port address */
__nb_inline__ __u16 in_word(unsigned short portnum)
{
  register __u16 ret;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"inw %%dx,%%ax"
	: "=a" (ret)
	: "d" (d0));
  return(ret);
}


/* Read a double word from a port address */
__nb_inline__ __u32 in_dword(unsigned short portnum)
{
  register __u32 ret;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"inl %%dx,%%eax"
	: "=a" (ret)
	: "d" (d0));
  return(ret);
}




/*
 **************************************************************************
 *
 * Port output routines
 */

/* Write a byte into a port address */
__nb_inline__ void out_byte(unsigned short portnum, __u8 val)
{
  register __u8 d1 = val;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"outb %%al,%%dx"
	: /* no output */
	: "d" (d0), "a" (d1));
}


/* Write a word into a port address */
__nb_inline__ void out_word(unsigned short portnum, __u16 val)
{
  register __u16 d1 = val;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"outw %%ax,%%dx"
	: /* no output */
	: "d" (d0), "a" (d1));
}


/* Write a double word into a port address */
__nb_inline__ void out_dword(unsigned short portnum, __u32 val)
{
  register __u32 d1 = val;
  register __u16 d0 = portnum;

  __asm__ __volatile__(
	"outl %%eax,%%dx"
	: /* no output */
	: "d" (d0), "a" (d1));
}


#endif /* _ASSEMBLY_ */

#endif

