View Full Version : inport() function
Aljaber
Asslamo 3laykom
is there is an alternative for inport() function
in the ansi c++ library functions
peace be upon you
Aljaber
Asslamo 3laykom
ok , in other words what is the function in the starndrd C++ library that reads a word form a hardware port
peace be upon you
alaa
what does the inport() dunction do exaclty??
as I understand the ISO standards for C and C++ try to avoid any hardware specific functions, it gives a generic interface to files, stream and memory that can be used to address any device, how devices are addressed is left to the OS.
in POSIX systems and other Unix lookalikes hardware devices of all kinds are files, you access them using the normal stream files and classes.
does this answer your question??
cheers,
Alaa
Aljaber
Asslamo 3laykom
Originally posted by alaa
what does the inport() dunction do exaclty??
====================================
inport, inportb, outport, outportb <DOS.H>
====================================
* inport reads a word from a hardware port
* inportb reads a byte from a hardware port
* outport outputs a word to a hardware port
* outportb outputs a byte to a hardware port
Declaration:
* unsigned inport (unsigned portid);
* unsigned char inportb (unsigned portid);
* void outport (unsigned portid, unsigned value);
* void outportb(unsigned portid, unsigned char value);
Remarks:
* inport works just like the 80x86 instruction IN. It reads the low
byte of a word from portid, the high byte from portid + 2.
* inportb is a macro that reads a byte
* outport works just like the 80x86 instruction OUT. It writes the
low byte of value to portid, the high byte to portid + 1.
* outportb is a macro that writes value
Argument| What It Is
--------+------------------------------
portid ***** Inport port that inport and inportb read from;
outport port that outport and outportb write to
value ***** Word that outport writes to portid;
byte that outportb writes to portid.
If you call inportb or outportb when DOS.H
has been included, they are treated as macros
that expand to inline code.
If you don't include DOS.H, or if you do
include DOS.H and #undef the macro(s), you
get the function(s) of the same name.
Return Value:
* inport and inportb return the value read
* outport and outportb do not return
Portability:
DOS -> yes
UNIX -> no
Windows -> yes
ANSI C -> no
C++ Only -> no
+-----+------+---------+--------+----------+
Originally posted by alaa
as I understand the ISO standards for C and C++ try to avoid any hardware specific functions, it gives a generic interface to files, stream and memory that can be used to address any device, how devices are addressed is left to the OS.
in POSIX systems and other Unix lookalikes hardware devices of all kinds are files, you access them using the normal stream files and classes.
does this answer your question??
cheers,
Alaa
more than that , thanks
peace be upon you
alaa
and what is a hardware port exactly, is it a generic way to adress all hardware devices or does it refer to a certain class of hardware devices??
I don't know assembly and back in DOS days I used to do Pascal so I have no idea what you're talking about.
anyway if you tell me what you're trying to do I might be able to help you more.
cheers,
Alaa
MaherG
Open your kernel headers
/usr/include/linux/ioport.h
Also check chapter 2 from the book Linux Device Drivers 2nd Edition.
Maher
alaa
thanks MaherG now I can give Aljaber the correct answer.
OK Aljaber the Linux equivalent to inport() is probably inb().
try man inb
the man page says
"The port and value arguments are in the opposite order to most DOS implementations."
however you are completley discourage from using these, they are Hardware specific and Linux specific (might even change from one version of Linux to another) since they are strictly designed for internal usage in the kernel.
if you want to write code that will work on Other POSIX systems, hardware and future Linux versions then stick to normal device access through file streams.
for an example of how to do portable low level IO check the perfect Serial Programming Guide for POSIX operating systems @ http://www.easysw.com/~mike/serial/
if you only care about Linux compatibility then check the Advanced Linux Prgoramming and Linux Device Drivers @ http://tldp.org
cheers,
Alaa
alaa
BTW Aljaber it only took one command to find the correct function
apropos port
shame on you :-)
Aljaber
Asslamo 3laykom
Originally posted by MaherG
Open your kernel headers
/usr/include/linux/ioport.h
Also check chapter 2 from the book Linux Device Drivers 2nd Edition.
Maher
thanks for this addition ;)
peace be upon you
alaa
oh but please note none of this is IOS C++
you want ISO C++ use fstream or stdio :-)
cheers,
Alaa
Aljaber
Asslamo 3laykom
Originally posted by alaa
thanks MaherG now I can give Aljaber the correct answer.
OK Aljaber the Linux equivalent to inport() is probably inb().
try man inb
the man page says
"The port and value arguments are in the opposite order to most DOS implementations."
however you are completley discourage from using these, they are Hardware specific and Linux specific (might even change from one version of Linux to another) since they are strictly designed for internal usage in the kernel.
if you want to write code that will work on Other POSIX systems, hardware and future Linux versions then stick to normal device access through file streams.
for an example of how to do portable low level IO check the perfect Serial Programming Guide for POSIX operating systems @ http://www.easysw.com/~mike/serial/
if you only care about Linux compatibility then check the Advanced Linux Prgoramming and Linux Device Drivers @ http://tldp.org
cheers,
Alaa
it seems that you never give up ;)
thanks for this worth reply :)
peace be upon you
Aljaber
Asslamo 3laykom
Originally posted by alaa
BTW Aljaber it only took one command to find the correct function
apropos port
shame on you :-)
what a far way :D
peace be upon you
vBulletin v3.0.1, Copyright ©2000-2004, Jelsoft Enterprises Ltd.