knt@cbnews.ATT.COM (kirk.n.trost) (01/03/90)
Is there an easy way to access 386 ports using C under UNIX. For example: x = input (portno) output (portno, value) Thanks, Kirk ...
tneff@bfmny0.UU.NET (Tom Neff) (01/03/90)
In article <12720@cbnews.ATT.COM> knt@cbnews.ATT.COM (kirk.n.trost,59473,cb,1k238,614 860 4225) writes: >Is there an easy way to access 386 ports using C >under UNIX. > >For example: > > x = input (portno) > output (portno, value) [ This is not a C question, therefore I have crossposted this to comp.lang.i386 and directed followups there. Read the stuff in news.announce.newusers, folks. ] User written programs under UNIX 386 cannot typically access I/O ports in the way described above. That's a privilege granted only to the kernel. It takes a bit of getting used to the idea that when a real OS like UNIX is running, as opposed to a baby monitor like DOS, one cannot tweak the hardware at will from user programs. There are two workarounds: write a *device driver* for the hardware in question, which will be linked into the kernel and so have its priveleges, and which will then be available as a 'device' to user programs, or (if you have VP/ix aka Simul-Task) there is a special set of routines to map certain registers into your space. No specific example is given of what the user wants to do, so the best solution isn't clear. If it's just something like toggling 43/25 lines or making sound, check to see if there isn't already something in the library that will do what you want. If it's something truly nonstandard and site specific like operating an A/D converter card for a lab, then write a device driver. -- "DO NOT, repeat, DO NOT blow the hatch!" /)\ Tom Neff "Roger....hatch blown!" \(/ tneff@bfmny0.UU.NET
bill@twwells.com (T. William Wells) (01/03/90)
In article <12720@cbnews.ATT.COM> knt@cbnews.ATT.COM (kirk.n.trost,59473,cb,1k238,614 860 4225) writes:
: Is there an easy way to access 386 ports using C
: under UNIX.
:
: For example:
:
: x = input (portno)
: output (portno, value)
Yes.
You'll note that you know no more than you did before. That is
because you neglected to say *which* C and *which* Unix.
Also, best to ask the question on comp.unix.i386, to which
followups have been directed.
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com
scott@bbxsda.UUCP (Scott Amspoker) (01/04/90)
In article <12720@cbnews.ATT.COM> knt@cbnews.ATT.COM (kirk.n.trost,59473,cb,1k238,614 860 4225) writes: > >Is there an easy way to access 386 ports using C >under UNIX. > >For example: > > x = input (portno) > output (portno, value) I would be very surprised if UNIX system allowed a user process to access ports directly. If you are writing a driver or kernal routine in C, procedures like the ones in your example could be used. Turbo C, for example, will generate in-line code for inport() and outport() calls. However, there is no standard here. You may write your own in assembler or see if your C library already has them. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232 unmvax.cs.unm.edu!bbx!bbxsda!scott
friedl@mtndew.UUCP (Steve Friedl) (01/07/90)
Kirk Trost asks: >Is there an easy way to access 386 ports using C under UNIX. Scott Amspoker replies: > I would be very surprised if UNIX system allowed a user process > to access ports directly. Surprise! General-purpose access to I/O ports is not supported, but there is limited access to display-related ports. <sys/kd.h> contains a handful of what are referred to as "VP/ix reserved ioctls", and two are /* VP/ix reserved ioctls */ #define KDENABIO (KIOC|60) /* enable direct I/O to ports */ #define KDDISABIO (KIOC|61) /* disable direct I/O to ports */ The third arg to ioctl is not used. I am not sure exactly which I/O addresses are permitted, but I do know that the port input and output instructions work for some ports (the display, probably) while they don't work for others. Steve -- Stephen J. Friedl, KA8CMY / Consultant / Tustin, CA / 3B2-kind-of-guy 714 544 6561 voice / 714 544 6496 fax / uunet!mtndew!friedl / friedl@vsi.com "PostScript wizard in training." - me
scott@bbxsda.UUCP (Scott Amspoker) (01/09/90)
>Scott Amspoker replies: >> I would be very surprised if UNIX system allowed a user process >> to access ports directly. > >Surprise! > >General-purpose access to I/O ports is not supported, but there >is limited access to display-related ports. >[...] >a handful of what are referred to as "VP/ix reserved ioctls", and >two are... Well, the 386 CPU does provide an I/O port bit map which allows user-mode access to selected I/O ports. This is quite unusual and is inconsistent with the UNIX model. However, I consider VP/ix to be a DOS environment rather than a UNIX one even though it runs under Xenix. I would be curious to know what the original poster was trying to do. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232 unmvax.cs.unm.edu!bbx!bbxsda!scott