inportb

In system-level programming, hardware I/O is provided by the functions inportb, inportw, inportl, outportb, outportw, and outportl, all of which are defined in the pc.h header. The inportX functions are used to read from ports and the outportX functions are used to write to ports. The X is b for an 8-bit byte-sized operand, w for a 16-bit word-sized operand, and l for a 32-bit long-sized operand.
[adapted from the DJGPP documentation]

Implementation

The inb and outb assembly mnemonics are the basis of the inportb and outportb C functions. The following implementation is compatible with GCC:

inline unsigned char inportb(unsigned int port) {
	// read a byte from a port
	unsigned char ret;
	asm volatile ("inb %%dx,%%al":"=a"(ret):"d"(port));
	return ret;
}
inline void outportb(unsigned int port,unsigned char value) {
	// write a byte to a port
	asm volatile ("outb %%al,%%dx": :"d"(port),"a"(value));
}

The code optimizes to single inline assembly statements.

The Website

This website receives a significant amount of traffic from people seeking systems development advice. If you came here expecting to learn about the finer details of the inportb function, I’m sorry to disappoint you: this is a selfish blog.

I had an active interest in OS development many years ago; when I looked for an identifier that would represent my interests, inportb was a natural choice. Before my experience with systems development, I had very little computer programming knowledge. This was a stepping stone that lead me to application development and eventually to web development. Many people progress in the opposite direction, but I feel that my bottom-up track provided a unique perspective.

I do not design operating systems now, but the experience had such a significant impact on me that I find the old name inportb to still be relevant today. To you who have embarked on the wild journey of systems design, I wish the greatest of luck and many rewards.

2 Comments

  1. rahul says:

    can you tell me if a non blocking function for input()
    for writing kbhit()

  2. Chastity says:

    Instant Estimates Tip: Honest contractors earn most
    of them plans to withdraw in 2014. Copies of any fraudulent company and contractor was
    charged with communicating national defence documents
    and receive the OFCCP’s scheduling letter is only prudent then to pay $7.
    If you contractor are a customer a total of $6250 even if it would be
    done on a single point of view.

Leave a Reply