*BSD News Article 24640


Return to BSD News archive

Newsgroups: comp.os.386bsd.questions
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!decwrl!netcomsv!netcom.com!hasty
From: hasty@netcom.com (Amancio Hasty Jr)
Subject: Re: [FreeBSD-1.0] How to access io-ports ?
Message-ID: <hastyCHDJJ1.C9I@netcom.com>
Organization: Netcom Online Communications Services (408-241-9760 login: guest)
References: <CHD7AB.Bwy@hermes.hrz.uni-bielefeld.de>
Date: Wed, 1 Dec 1993 20:57:01 GMT
Lines: 195

In article <CHD7AB.Bwy@hermes.hrz.uni-bielefeld.de> uphya001@odie.uni-bielefeld.de writes:
>---
>
>Hello!
>
>I want to access some AD-, DA-cards from FreeBSD. To implement this I must
>have access to the io-ports via in and out. 
>
>What is the best way to solve this problem. In the case I have to implement ioctls in the kernel, who is able to give me a small and simple example program?
>

This code fragment will give you access to the i/o ports;however,
it does have the unfortunate effect that will change your key
board input/output to X mode. This problem can be easily fix by
just hacking on pccons and creating a new ioctl that just gives
you access to the i/o ports so look around in pccons.c. You
can also telnet to your box and execute the code fragment if 
you don't want to hack on the kernel for the early stage
of your project to get out of X mode just close "fd" that 
should get you out of X mode.



 #define CONSOLE_DEV "/dev/vga"
 

     if ((fd = open(CONSOLE_DEV,O_RDWR | O_NDELAY,0)) < 0) 
       FatalError("Cannot open %s (errno=%d)\n",CONSOLE_DEV,errno);
     x386Info.consoleFd = fd;

    ioctl (x386Info.consoleFd, CONSOLE_X_MODE_ON, 0);

---------------------------------compiler.h----------------------------

the out/in instructions from the X distribution compiler.h :

/*
 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Thomas Roell not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Thomas Roell makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * $Header: /proj/X11/mit/server/ddx/x386/RCS/compiler.h,v 1.2 1991/06/27 00:01:11 root Exp $
 */


#ifndef _COMPILER_H
#define _COMPILER_H

#ifdef __GNUC__

#ifdef __386BSD__
static __inline__ void
outb(port, val)
     short port;
     char val;
{
  __asm__ volatile("out%B0 %%al, %1" : :"a" (val), "d" (port));
}

static __inline__ void
outw(port, val)
     short port;
     short val;
{
  __asm__ volatile("out%W0 %%ax, %1" : :"a" (val), "d" (port));
}

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

static __inline__ unsigned int
inw(port)
     short port;
{
  unsigned int ret;
  __asm__ volatile("in%W0 %1, %%al" :
		   "=a" (ret) :
		   "d" (port));
  return ret;
}

static __inline__ void
intr_disable()
{
  __asm__ volatile("cli");
}

static __inline__ void
intr_enable()
{
  __asm__ volatile("sti");
}
#else

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

static __inline__ void
outw(port, val)
     short port;
     short val;
{
  __asm__ volatile("out%W0 (%1)" : :"a" (val), "d" (port));
}

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

static __inline__ unsigned int
inw(port)
     short port;
{
  unsigned int ret;
  __asm__ volatile("in%W0 (%1)" :
		   "=a" (ret) :
		   "d" (port));
  return ret;
}

static __inline__ void
intr_disable()
{
  __asm__ volatile("cli");
}

static __inline__ void
intr_enable()
{
  __asm__ volatile("sti");
}
#endif

#else /* __GNUC__ */
# if defined(__STDC__) && (__STDC__ == 1)
#  define asm __asm
# endif
#include <sys/inline.h>
#define intr_disable() asm("cli")
#define intr_enable()  asm("sti")
#endif

#ifndef __STDC__
#define signed /**/
#define const /**/
#endif

#endif /* _COMPILER_H */




	Happy Hacking,
	Amancio
-- 
This message brought to you by the letters X and S and the number 3
Amancio Hasty           |  
Home: (415) 495-3046    |  ftp-site depository of all my work:
e-mail hasty@netcom.com	|  sunvis.rtpnc.epa.gov:/pub/386bsd/X