JustKernel

Ray Of Hope

Accessing parallel port – So simple and yet so complicated

small module of accessing parallel port turns to a horrific story.. The task was just to replicate a user layer app in Linux which accesses parallel port , to Windows OS.

Sounds simple, yes it did same to me.. The design was – use IOCTL to get exclusive access to parallel port and then Dispatch routine to read and write to parallel port..

So started my task by searching over the net the possible IOCTLs that I can use and found <a href=”http://msdn.microsoft.com/en-us/library/windows/hardware/ff543945.aspx” rel=”nofollow” target=”_blank”>http://msdn.microsoft.com/en-us/library/windows/hardware/ff543945.aspx</a>. This sites list the necessary IOCTLs to “Create parallel Port”, “Get Exclusive Access To Parallel Port”, “Read And Write to Parallel Port” .

But them as MS is famous for, things got complicated.. “These are INTERNAL IOCTLS and can’t be called from USER-MODE” . And to my surprise on discussing this in one of the mailing list I found that Linux allows simplistic approach to access parallel port (via IOCTL ) because its not secure, Windows is secure thus usermode acces to parallel port is blocked..

Please note ————

When I talk about accessing parallel port , I mean accessing control register, status register and data register for reading and writing.. This was a part of virtualization project where the requirement was to expose complete raw port to the guest.

Prior to Win2K direct access to hardware ports was allowed i.e from usermode you can do write(0x378, &lt;data&gt;) or data = read (0x378), but it was discontinued later on 🙂

——————–

Ok.. So, it was decided that kernel mode module will be fine to access the parallel port.. But then again constraint, no IOCTL is provided to control individual bits for control and status register.. As per the discusison on mailing list, I was told that there is no need to access independent bits, these are abstracted and should not be accessed.. And if I have to access, then there is no answer.

So , even with a kernel module my task was not complete. So at the end I wrote a user mode/kenrel mode module that used to switch between these modes for perfroming different operation. — To read and write to data/status and control register – R0/Kernel mode, To open the port, get address of parallel port – R3 /User Mode.. Such a complicated approach for a simple task….

Originally posted on: 2012-04-06 15:08:14

Anshul Makkar

anshul_makkar@justkernel.com

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.