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

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

Revision 1.1.1.1 (vendor branch), Wed May 27 12:11:51 2009 UTC (15 years, 1 month ago) by yason
Branch: yason
CVS Tags: import
Changes since 1.1: +0 -0 lines

import

$OpenBSD$
--- src/jtag/parport.c.orig	Fri Jan 16 10:02:25 2009
+++ src/jtag/parport.c	Wed May 27 11:43:45 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,29 +45,32 @@
 #include "errno.h"
 #endif /* _WIN32 */
 
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __OpenBSD__ */
 
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 
 #if PARPORT_USE_PPDEV == 1
+#ifdef __OpenBSD__
+#error "OpenBSD doesn't have ppdev. Please compile with direct i/o instead."
+#endif /* __OpenBSD__ */
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <dev/ppbus/ppi.h>
 #include <dev/ppbus/ppbconf.h>
 #define PPRSTATUS	PPIGSTATUS
 #define PPWDATA		PPISDATA
-#else
+#else /* not __FreeBSD__ */
 #include <linux/parport.h>
 #include <linux/ppdev.h>
 #endif
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #else /* not PARPORT_USE_PPDEV */
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__OpenBSD__)
 #include <sys/io.h>
+#endif /* ! _WIN32 && !__OpenBSD__ */
 #endif
-#endif
 
 #if PARPORT_USE_GIVEIO == 1
 #if IS_CYGWIN == 1
@@ -76,6 +79,10 @@
 #endif
 #endif
 
+#ifdef __OpenBSD__
+#include <i386/pio.h>  /* inb/outb macross */
+#endif /* __OpenBSD__ */
+
 #include "log.h"
 
 /* parallel port cable description
@@ -200,12 +207,12 @@ static __inline__ void parport_write_data(void)
 #if PARPORT_USE_PPDEV == 1
 	ioctl(device_handle, PPWDATA, &output);
 #else
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 	outb(dataport, output);
 #else
 	outb(output, dataport);
 #endif
-#endif
+#endif  /* not PARPORT_USE_PPDEV */
 }
 
 void parport_write(int tck, int tms, int tdi)
@@ -310,6 +317,12 @@ int parport_init(void)
 	char buffer[256];
 	int i = 0;
 #endif
+#ifdef __OpenBSD__
+	u_long  iopermtable[32] = {};
+
+	/* get current i/o permission table */
+	i386_get_ioperm(iopermtable);
+#endif /* __OpenBSD__ */
 	
 	cur_cable = cables;
 	
@@ -403,7 +416,16 @@ int parport_init(void)
 #if PARPORT_USE_GIVEIO == 1
 	if (parport_get_giveio_access() != 0)
 #else /* PARPORT_USE_GIVEIO */
+#ifdef __FreeBSD__
 	if (ioperm(dataport, 3, 1) != 0)
+#endif /* __FreeBSD__ */
+#ifdef __OpenBSD__
+	/* request access to desired i/o port */
+	iopermtable[parport_port / 32] &= ~(1 << parport_port % 32);
+	iopermtable[parport_port / 32] &= ~(1 << parport_port % 32 + 1);
+	iopermtable[parport_port / 32] &= ~(1 << parport_port % 32 + 2);
+	if (i386_set_ioperm(iopermtable) != 0)
+#endif /* __OpenBSD__ */
 #endif /* PARPORT_USE_GIVEIO */
 	{
 		LOG_ERROR("missing privileges for direct i/o");
@@ -412,7 +434,7 @@ int parport_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(parport_port + 2, 0x0);
 	#else
 		outb(0x0, parport_port + 2);
@@ -469,7 +491,7 @@ int parport_handle_parport_cable_command(struct comman
 	if (parport_cable == 0)
 	{
 		parport_cable = malloc(strlen(args[0]) + sizeof(char));
-		strcpy(parport_cable, args[0]);
+		strlcpy(parport_cable, args[0], strlen(args[0]) + sizeof(char));
 	}
 
 	return ERROR_OK;