> > If you think adding another --enable-parallel-inpout isn't the best 
> > solution I could try to modify giveio code in such a way that if loading of 
> > giveio driver fails (always on 64-bit Windows and when giveio.sys isn't 
> > installed) then as a fallback inpout32 is loaded.
> > What do you think about this?
> I would prefer this - otherwise, it would be impossible to distribute a 
> binary with full functionality.

And here it is - second patch that try to use inpout32 when giveio fails.
Choose which one you like best.

Regards,
Jarek
diff --git a/configure.ac b/configure.ac
index ec51bd7..6c67587 100644
--- a/configure.ac
+++ b/configure.ac
@@ -377,7 +377,7 @@ AC_ARG_ENABLE(parport_ppdev,
 
 AC_ARG_ENABLE(parport_giveio,
     AS_HELP_STRING([--enable-parport-giveio],
-      [Enable use of giveio for parport (for CygWin only)]),
+      [Enable use of giveio or inpout32 for parport (for CygWin only)]),
     [parport_use_giveio=$enableval], [parport_use_giveio=])
 
 AC_ARG_ENABLE(ft2232_libftdi,
@@ -657,9 +657,9 @@ else
 fi
 
 if test x$parport_use_giveio = xyes; then
-  AC_DEFINE(PARPORT_USE_GIVEIO, 1, [1 if you want parport to use giveio.])
+  AC_DEFINE(PARPORT_USE_GIVEIO, 1, [1 if you want parport to use giveio or 
inpout32.])
 else
-  AC_DEFINE(PARPORT_USE_GIVEIO, 0, [0 if you don't want parport to use 
giveio.])
+  AC_DEFINE(PARPORT_USE_GIVEIO, 0, [0 if you don't want parport to use giveio 
and inpout32.])
 fi
 
 if test $build_bitbang = yes; then
diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c
index ad07791..62be08b 100644
--- a/src/jtag/drivers/parport.c
+++ b/src/jtag/drivers/parport.c
@@ -116,6 +116,17 @@ static int device_handle;
 #else
 static unsigned long dataport;
 static unsigned long statusport;
+static bool inpout32_lib = 0;
+#endif
+
+#if PARPORT_USE_GIVEIO == 1
+typedef void   (__stdcall *func_out32)(short, short);
+typedef short  (__stdcall *func_inp32)(short);
+typedef BOOL   (__stdcall *func_is_driver_open)(void);
+
+func_out32 out32;
+func_inp32 inp32;
+func_is_driver_open is_driver_open;
 #endif
 
 static int parport_read(void)
@@ -125,7 +136,7 @@ static int parport_read(void)
 #if PARPORT_USE_PPDEV == 1
        ioctl(device_handle, PPRSTATUS, & data);
 #else
-       data = inb(statusport);
+       data = (inpout32_lib == 0) ? inb(statusport) : inp32(statusport);
 #endif
 
        if ((data ^ cable->INPUT_INVERT) & cable->TDO_MASK)
@@ -145,7 +156,7 @@ static __inline__ void parport_write_data(void)
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
        outb(dataport, output);
 #else
-       outb(output, dataport);
+       (inpout32_lib == 0) ? outb(output, dataport) : out32(dataport, output);
 #endif
 #endif
 }
@@ -251,6 +262,44 @@ static int parport_get_giveio_access(void)
 
        return 0;
 }
+
+static int parport_get_inpout_access(void)
+{
+       HINSTANCE dll;
+
+       if (sizeof(void*) == 8) { //64-bit windows
+               dll = LoadLibrary("InpOutx64.dll");
+       }
+       else { //32-bit windows
+               dll = LoadLibrary("InpOut32.dll") ;
+       }
+
+       if ( dll != NULL ) {
+               out32 = (func_out32)GetProcAddress(dll, "Out32");
+               inp32 = (func_inp32)GetProcAddress(dll, "Inp32");
+               is_driver_open = (func_is_driver_open)GetProcAddress(dll, 
"IsInpOutDriverOpen");
+
+               if (out32 == NULL || inp32 == NULL || is_driver_open == NULL) {
+                       LOG_ERROR("InpOut library seems to be in wrong version. 
"
+                                         "Check 
http://www.highrez.co.uk/Downloads/InpOut32/";);
+                       return -1;
+               }
+
+               if (is_driver_open() == FALSE) {
+                       LOG_ERROR("InpOut driver is not installed. "
+                                         "Check 
http://www.highrez.co.uk/Downloads/InpOut32/";);
+                       return -1;
+               }
+       }
+       else {
+               LOG_ERROR("Could not load InpOut32.dll (32-bit OpenOCD) or 
InpOutx64.dll (64-bit OpenOCD). "
+                                 "Check 
http://www.highrez.co.uk/Downloads/InpOut32/";);
+               return -1;
+       }
+
+       inpout32_lib = 1;
+       return 0;
+}
 #endif
 
 static struct bitbang_interface parport_bitbang = {
@@ -360,6 +409,7 @@ static int parport_init(void)
        LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport);
 #if PARPORT_USE_GIVEIO == 1
        if (parport_get_giveio_access() != 0)
+               if (parport_get_inpout_access() != 0) //as a giveio fallback 
try inpout32 library
 #else /* PARPORT_USE_GIVEIO */
        if (ioperm(dataport, 3, 1) != 0)
 #endif /* PARPORT_USE_GIVEIO */
@@ -373,7 +423,7 @@ static int parport_init(void)
        #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
                outb(parport_port + 2, 0x0);
        #else
-               outb(0x0, parport_port + 2);
+               (inpout32_lib == 0) ? outb(0x0, parport_port + 2) : 
out32(parport_port + 2, 0x0);
        #endif
 
 #endif /* PARPORT_USE_PPDEV */
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to