Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

At work we have some embedded devices controlled by DOS software. I have been tasked with the responsibility of assessing the use of Linux as a replacement OS for DOS on a next generation of hardware. I am not a linux expert at all and my research leads me to the conclusion that DOS is simply a totally different type of operating system that allows you to do potentially dangerous things if you want to. From my understanding if you wish to access hardware directly you would have to write a custom driver. What I need to know to satisfy the curiosity of my boss is the following: is it at all possible to access hardware directly from user space??

My guess is no, but I would like to request the opinion of those with knowledge far greater than mine.

share|improve this question
    
How are the devices accessed from the OS? E.g. are they PCI cards? –  daniel kullmann Jul 13 '12 at 18:16
    
I believe so yes. Most hardware is wired into the board directly (like serial ports and ethernet adaptor). There are devices attached also - I am a simple desktop application developer so my in depth knowledge of hardware is very limited. Hence my asking here. –  mathematician1975 Jul 13 '12 at 18:21
    
If you are not using specialized hardware and are only looking to get serial-ports and ethernet working, you probably don't need to access the hardware directly ... –  Bananguin Jul 13 '12 at 18:38
    
This was my thought to be honest. However, I think because the old code uses stuff like hardware interrupts to access incoming TCP and serial transmissions my boss wants the same functionality. It's probably a real-time issue. I personally cant see the problem with using things like poll() or select() to get data. –  mathematician1975 Jul 13 '12 at 18:43
add comment

2 Answers

up vote 1 down vote accepted

Your guess is correct. The kernel is the only software that can send hardware requests. That does not only hold true for Linux. Virtually no operating system newer than DOS lets you access hardware directly, because, as you also suspect, it's quite quite dangerous.

However, there is no problem in writing your own driver and plenty of documentation is available. For example, this tutorial at xatlantis seems a recent (that's important!) and good source.

share|improve this answer
add comment

Yes, but it is rarely useful. On 32-bit x86 systems, you can use the ioperm(2) system call to set up the current process to allow it to perform port I/O directly. I believe this does not work on 64-bit systems. You can also do lseek/read/write combinations against /dev/port and I think this likewise is not very portable. See http://tldp.org/HOWTO/IO-Port-Programming-2.html for some more details. Both of these approaches are much slower and less flexible than writing a device driver of course (/dev/port slowest of all). None of tese userspace mechanisms allow you to handle interrupts or anything like that, of course. If performance is an issue you're going to end up writing a device driver.

share|improve this answer
    
But work with interrupts and DMA is still impossible in userspace (AFAIK) So device access from userspace is limited to communicate via ports or device mapped memory. –  Netch Jul 15 '12 at 10:33
    
Yes, which is why I mentioned that in my answer. –  James Youngman Jul 15 '12 at 22:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.