Accessing the hardware

Hi,
I'm new in programming and I'm intersted in accessing the hardware of my computer like the parallel port, usb, com port.
Can anyone help me on how to access these ports? What are the header files do I need and to include?
An easy example could be of a help/

thanks so much
For accessing ports (serial or otherwise) you would use the asm opcodes inb and outb for input and output respectively. The problem is that you need to write a device driver to gain access to the hardware itself; or, at the very least, a program to interact with the device drivers.

You won't be able to access the hardware unless the operating system 'lets' you.

Besides; hardware access is extremely difficult to get right. You have to know how the specific piece of hardware interacts with 1. the OS and 2. the other hardware.

Edit: I have zipped the source code to 8 releases of the Linux kernel (0.1 - 2.6), minix 1, 2 and 3, and the most recent release of GNU Hurd. At some stage you can read through all that and see the different ways they have written device drivers and then learn from it.

Here: Edit: I can't upload the files right now...

Note: I would have added Free-, Net- and OpenBSD (you can see, the BSD folder is empty) but I remember last time I tried to find a download for their source code; it simply didn't work.
Last edited on
You can simply call the OS and make it do what you want with no need of low level stuff.
What is your OS?
I assumed he wanted to do it himself...
I don't think so, being in the beginner forum
Exactly. I thought he had misconceptions about the difficulty of doing such a thing. He says he wants to access a bunch of ports; which I took to mean he wants to do it himself...
Hey thanks for replying.

Bazzy, I'm using Linux Ubuntu.

I'm working on a project on how to interface my computer to a measuring machine and do some controls, simply a mini CNC. And accessing my ports is one of my challenges.

Using the OS calls sounds better thans writing a device drivers. So how can I make my OS do what I want?

Thanks
Helios!!! We need you here, please!
BTW, since you are using Linux OS then you should move this to the UNIX/Linux forum. I guarantee you will receive more assistance there.
Last edited on
As you're using a Linux based OS; you can always write a kernel module and have that loaded.

If you want to access ports; read up on serial ports (I think all hardware is virtualized as a serial port) http://tldp.org/HOWTO/Serial-HOWTO.html
All I know is that the keyboard has ports 0x60 and 0x64 and the (first) hard disk is port 0x80. I think fd0 and fd1 are 0x0 and 0x1 respectively and hd1 0x81. Otherwise I'm not sure so use the link above.

If you want to do some cpuid stuff; look in the Lounge section. I've been writing a cpuid program for about a week or so, parts of it are successful. If you load a kernel module you can use rdtsc to calculate the clock frequency fairly accurately. You could also use a BIOS function I think is privileged (requires you to be in ring 0 (kernel) mode) which detects RAM.
http://wiki.osdev.org/Detecting_Memory_%28x86%29#BIOS_Function:_INT_0x15.2C_EAX_.3D_0xE820
Edit: never mind. While you may find tht interesting to read; I think it's privileged and at any rate it returns a memory map; meaning you'll get a segfault in a user application.

Oh also, Linux stores alot of cpuid information in /proc/cpuid; which is a text file.
Last edited on
Thanks alot chris.
I hope I can impliment my project. :)
Thanks again
If you need any more help; just ask.
@ chrisname

can you give me book titles on hardware programming or books on writing device drivers?

Thanks again
@kbw:
That link is the coolest thing ever. Total WIN ! :D
Last edited on
Topic archived. No new replies allowed.