PinkEater has asked for the wisdom of the Perl Monks concerning the following question:

I found the PeekPoke module on CPAN made by an XS programmer but is there any other way? I need byte, word, and double word data and the documention of PeekPoke lacks details. It also lacks an inp & outp equivalent.

I mess with PCI space alot and the RTC (Real Time Clock (I/O)) space.

Perl hates me trying to use:

\$PCIWrite = 0xCF8;
No groaning. ;)

Replies are listed 'Best First'.
Re: Poke peek & inp outp equivalents
by Roger (Parson) on Jan 22, 2004 at 05:13 UTC
    -- InOut.xs --
    #include "EXTERN.h" #include "perl.h" #include "conio.h" #include "XSUB.h" MODULE = InOut PACKAGE = InOut IV inp(IV p) CODE: { RETVAL = inp( (unsigned short) p); } OUTPUT: RETVAL void outp(IV p, IV v) CODE: { outp((unsigned short) p, (unsigned char) v); } IV inpw(IV p) CODE: { RETVAL = inp( (unsigned short) p); } OUTPUT: RETVAL void outw(IV p, IV v) CODE: { outp((unsigned short) p, (unsigned short) v); } IV inpd(IV p) CODE: { RETVAL = inp( (unsigned short) p); } OUTPUT: RETVAL void outpd(IV p, IV v) CODE: { outp((unsigned short) p, (unsigned long) v); }

    -- InOut.pm --
    package InOut; require 5.005_92; use strict; use warnings; require Exporter; require DynaLoader; our @ISA = qw(Exporter DynaLoader); our @EXPORT_OK = qw(inp outp inpw outpw inpd outpd); our $VERSION = '1.00'; bootstrap InOut $VERSION; 1;

    Usage:
    use InOut; $b = inp($port); $w = inpw($port); $d = inpd($port); outp($port, $b); outpw($port, $w); outpd($port, $d);

      Thanks for your help. Here is an update:
      MakeMaker (ActiveState 5.8.0) hates spaces where perl.exe's path is concerned or I am to stupid to figure out a way to fix its problem with "C:\Program Files\perl".
      Uninstalled perl. Re-installed in "C:\perl" and got a little farther.

      While linking I got unresolved references.
      Tried coping msvcrt.lib & conio.h everywhere. No luck. I found 'libpth' in Config.pm and 'libpath' in Makefile but changes there didn't work. There is more with the libs but the answer was:
      In the XS code above I needed '_inp' not 'inp' (and the same for the rest). My fault for not mentioning I'm on a Windows 2000 machine. :(

      Now I just have to figure out the way around NT complaining with STAUS_PRIVILEGED_INSTRUCTION when I use outp. :| Ugh.

      Does anyone know how to get it to work in kernel mode instead of user? That should probably be a new question.

        While linking I got unresolved references.

        Opps, forgot to mention that you need to compile/link in release mode as inp and outp will not work in debug mode.

        Now I just have to figure out the way around NT complaining with STAUS_PRIVILEGED_INSTRUCTION when I use outp.

        You could use a Windows NT/2000/XP I/O Port device driver to do the port I/O on your behalf. Have a look at the following article which gives an insight to the problem and solution.

Re: Poke peek & inp outp equivalents
by Mr. Muskrat (Canon) on Jan 22, 2004 at 03:36 UTC
    PeekPoke does not include a method to access "far" memory. What does that mean? In most cases, you will not be able to use PeekPoke to access either of those memory spaces.