[BACK]Return to patch-src_jtag_gw16012_c CVS log [TXT][DIR] Up to [local] / ports / devel / openocd / patches

File: [local] / ports / devel / openocd / patches / Attic / patch-src_jtag_gw16012_c (download)

Revision 1.1, Wed May 27 12:11:51 2009 UTC (15 years, 1 month ago) by yason
Branch: MAIN

Initial revision

$OpenBSD$
--- src/jtag/gw16012.c.orig	Wed May 27 12:38:08 2009
+++ src/jtag/gw16012.c	Wed May 27 12:50:08 2009
@@ -31,7 +31,7 @@
 
 /* system includes */
 /*  -ino: 060521-1036 */
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 
 #include <sys/types.h>
 #include <machine/sysarch.h>
@@ -45,7 +45,7 @@
 #include "errno.h"
 #endif /* _WIN32 */
 
-#endif /* __FreeBSD__, __FreeBSD_kernel__ */
+#endif /* __FreeBSD__, __FreeBSD_kernel__, __OpenBSD__ */
 
 #include <string.h>
 #include <stdlib.h>
@@ -63,7 +63,7 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #else /* not PARPORT_USE_PPDEV */
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__OpenBSD__)
 #include <sys/io.h>
 #endif
 #endif
@@ -129,7 +129,7 @@ void gw16012_data(u8 value)
 	#if PARPORT_USE_PPDEV == 1
 		ioctl(device_handle, PPWDATA, &value);
 	#else
-		#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+		#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 			outb(gw16012_port, value);
 		#else
 			outb(value, gw16012_port);
@@ -150,7 +150,7 @@ void gw16012_control(u8 value)
 		#if PARPORT_USE_PPDEV == 1
 			ioctl(device_handle, PPWCONTROL, &gw16012_control_value);
 		#else
-			#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+			#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 				outb(gw16012_port + 2, gw16012_control_value);
 			#else
 				outb(gw16012_control_value, gw16012_port + 2);
@@ -469,6 +469,13 @@ int gw16012_init(void)
 #endif
 	u8 status_port;
 
+#ifdef __OpenBSD__
+	u_long  iopermtable[32] = {};
+
+	/* get current i/o permission table */
+	i386_get_ioperm(iopermtable);
+#endif /* __OpenBSD__ */
+
 #if PARPORT_USE_PPDEV == 1
 	if (device_handle>0)
 	{
@@ -530,7 +537,16 @@ int gw16012_init(void)
 #if PARPORT_USE_GIVEIO == 1
 	if (gw16012_get_giveio_access() != 0)
 #else /* PARPORT_USE_GIVEIO */
+#ifdef __FreeBSD__
 	if (ioperm(gw16012_port, 3, 1) != 0)
+#endif /* __FreeBSD__ */
+#ifdef __OpenBSD__
+	/* request access to desired i/o port */
+	iopermtable[gw16012_port / 32] &= ~(1 << gw16012_port % 32);
+	iopermtable[gw16012_port / 32] &= ~(1 << gw16012_port % 32 + 1);
+	iopermtable[gw16012_port / 32] &= ~(1 << gw16012_port % 32 + 2);
+	if (i386_set_ioperm(iopermtable) != 0)
+#endif /* __OpenBSD__ */
 #endif /* PARPORT_USE_GIVEIO */
 	{
 		LOG_ERROR("missing privileges for direct i/o");
@@ -539,7 +555,7 @@ int gw16012_init(void)
 	LOG_DEBUG("...privileges granted");
 
 	/* make sure parallel port is in right mode (clear tristate and interrupt */
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 	outb(gw16012_port + 2, 0x0);
 #else
 	outb(0x0, gw16012_port + 2);