I have written a lot of C code to load and run software on an old LSIC30 ISA DSP card. The original code was developed using the excellent DJGPP2 port of the gcc compiler under DOS, and latterly under Windows 98. Neither DOS nor Windows 98 places any restriction on access to PC hardware ports by the user code.
As Windows 98 is now officially obsolete, and therefore no longer supported by Microsoft for security updates, I decided to upgrade to Windows 2000, which does prevent direct I/O port access by user code. To work around this, I have used the SST DLPortIO universal driver, which allows port access via an API that uses a kernel driver. Many thanks to SST for an outstanding (free!) product that we have used on several occasions, and is also used by many companies to do the same job.
For simplicity in porting code that already worked with a gcc compiler, I chose the MinGW32 port of gcc.
Dlportio comes with examples and a DLL library to use the driver with Microsoft and Borland C/C++ compilers. No direct mention is made of the MinGW32 compiler. There are two ways to link in a Microsoft-created DLL such as DLPORTIO.dll:
or:
- Treat the standard Microsoft library dlportio.lib like an object file on the gcc command line (I don't understand how this works),
fakeio.c contains a mapping of inportw/b() and outportw/b() C calls using DlPortIO API calls.
Before you follow either of the following recipes, it is of course assumed
that you have installed the DLPortIO driver.
Type the following at the msys command prompt to create an executable:
gcc -c try.c(note that there is no '-l' to identify DLPORTIO.lib as a library.)
gcc -c fakeio.c
gcc -o try.exe try.o fakeio.o DLPORTIO.lib
DLPORTIO.lib referred to above is the standard (MSVC) import library from the DLPortIO package.
I suppose that the above "easy" way of doing things might not work for some DLLs, hence my decision to include the following.
Please note that this same procedure may be applied to make a MinGW32 import library for any DLL that comes with an associated MS inport library.
(1) Using the msys shell, use pexports to create a first draft of the definition file:
pexports DLPORTIO.dll | sed '/_//' > DLPORTIO.def
This produces the following DLPORTIO.def:
LIBRARY DlPortIO.dll
EXPORTS
DlPortReadPortBufferUchar
DlPortReadPortBufferUlong
DlPortReadPortBufferUshort
DlPortReadPortUchar
DlPortReadPortUlong
DlPortReadPortUshort
DlPortWritePortBufferUchar
DlPortWritePortBufferUlong
DlPortWritePortBufferUshort
DlPortWritePortUchar
DlPortWritePortUlong
DlPortWritePortUshort
(2) It is necessary to manually add information
about the size of data passed on the stack by each API call, by performing
the following mods (deduced by examining a "strings" dump of the
MS dlportio.lib import library):
LIBRARY DlPortIO.dll(3) This may then be turned into a MINGW32 import library as follows:
EXPORTS
DlPortReadPortBufferUchar@12
DlPortReadPortBufferUlong@12
DlPortReadPortBufferUshort@12
DlPortReadPortUchar@4
DlPortReadPortUlong@4
DlPortReadPortUshort@4
DlPortWritePortBufferUchar@12
DlPortWritePortBufferUlong@12
DlPortWritePortBufferUshort@12
DlPortWritePortUchar@8
DlPortWritePortUlong@8
DlPortWritePortUshort@8
dlltool --input-def DLPORTIO.def --dllname DLPORTIO.dll --output-lib libDLPORTIO.a -kFinally, to use the DLL, e.g.:
cp libDLPORTIO.a /mingw/lib
ranlib /mingw/lib/libDLPORTIO.a
gcc -c try.cHere, -lDLPORTIO refers to the newly-created libDLPORTIO.a import library in MinGW32 format.
gcc -c fakeio.c
gcc -o try.exe try.o fakeio.o -lDLPORTIO