There is a working machine with Linux OS. It is required to get access to I / O ports from the console user application (ring3).

Under Windows, this problem is solved in the following ways:

  1. driver type userport or giveio -> directly in the program we do input-output through asm commands in / out
  2. a proprietary “virtual service” driver, which in ring0 does all the rough work and provides an interface using IOCTL to application programs. The user application calls the appropriate IOCTLs.

What are the options for Linux? I ask you to use short code examples.

PS: es-but root privileges have a place to be.

  • Plus: I, too, are interested, even though I practically did not work with Linux. - Alexey Sonkin
  • Sorry, could you write about <i href= hashcode.ru/questions/17707/… > about the IoCtrls, otherwise I need to deal with the Windows driver? =) - allcreater

1 answer 1

Well, the main way in Linux is to follow the same path: make a kernel module that works with I / O ports and provides some kind of interface for applications, for example, creates a tty or some other file device and possibly provides an IOCTL; and from the application you access this file device and work with the driver through it. I will give an example later if others do not. However, some examples can be easily found on the Internet. For example: Character Device Drivers . And in general, if you plan to follow the first path, it does not prevent you from browsing through this The Linux Kernel Module Programming Guide , which is a classic of the genre from the MUST READ category. Here is the same (or almost the same), in Russian: The Linux Kernel Module Programming Guide (RU) . Or another example: Implementing a Simple Char Device in Linux

Well, of course, when connecting, many devices are defined as a serial port or something like that, and then the corresponding kernel module creates this file device itself and then you just need to understand what to do with this file device.

The second way is to use the user space device driver API. Read, for example, here: User-space device drivers

  • one
    Well, well, we wait, with the comrades becoming more active ... - gecube
  • one
    Sorry, there is no time to write an example now :) I’m answering everything with a run. The second way is generally gaining popularity, so it does not interfere and try it. Added a couple of links to simple examples in the first part - cy6erGn0m