On Wed, 17 Mar 1999, Dave wrote:
> How does one directly access an I/O address from C?
With GNU C, you can use the inline assembly macro capability. There are
versions of these macros included with Linux and I know the i386 port of
RTEMS includes some. Here is one example:
#define i386_inport_byte( _port, _value ) \
{ register unsigned short __port = _port; \
register unsigned char __value = 0; \
\
asm volatile ( "inb %1,%0" : "=a" (__value), "=d" (__port) \
: "0" (__value), "1" (__port) \
); \
_value = __value; \
}
> For example if I want to write a char to port 0x80 (or read a char from a
> port) what is the statement?
Assuming the above macro, you would do something like:
i386_outport_byte( 0x80, my_char );
i386_inport_byte( 0x80, my_char );
> How about memory mapped I/O? If one wants to directly access a specific
> memory address what are the statements?
Others have shown how to do this directly in portable ANSI C.
> Is direct I/O and direct memory access part of ANSI C?
i386 IO and any DMA is not.
> I have an embedded X86 project that has to directly access the hardware. I
> would prefer doing it in C rather than ASM.
Careful use of inline assembly macros can go a long way to eliminating
assembly language. The RTEMS and Linux sources have plenty of examples
of doing just this.
--joel
Joel Sherrill Director of Research & Development
[EMAIL PROTECTED] On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985