shithub: choc

Download patch

ref: 73cc6b5a6017a15b02ce3480e0e58d19520b31ba
parent: 073e710f685a10c2084f6c04fbc4fe7c87530d93
author: Simon Howard <[email protected]>
date: Sun Oct 4 00:21:40 EDT 2009

Make OpenBSD native OPL backend work on x86_64 as well as i386.

Subversion-branch: /branches/opl-branch
Subversion-revision: 1707

--- a/configure.in
+++ b/configure.in
@@ -73,8 +73,10 @@
     AC_CHECK_FUNCS(mmap sched_setaffinity ioperm)
 
     # OpenBSD I/O i386 library for I/O port access.
+    # (64 bit has the same thing with a different name!)
 
     AC_CHECK_LIB(i386, i386_iopl)
+    AC_CHECK_LIB(amd64, amd64_iopl)
 ])
 
 AC_CHECK_TOOL(WINDRES, windres, )
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -42,7 +42,7 @@
 #ifdef HAVE_IOPERM
 extern opl_driver_t opl_linux_driver;
 #endif
-#ifdef HAVE_LIBI386
+#if defined(HAVE_LIBI386) || defined(HAVE_LIBAMD64)
 extern opl_driver_t opl_openbsd_driver;
 #endif
 #ifdef _WIN32
@@ -55,7 +55,7 @@
 #ifdef HAVE_IOPERM
     &opl_linux_driver,
 #endif
-#ifdef HAVE_LIBI386
+#if defined(HAVE_LIBI386) || defined(HAVE_LIBAMD64)
     &opl_openbsd_driver,
 #endif
 #ifdef _WIN32
--- a/opl/opl_obsd.c
+++ b/opl/opl_obsd.c
@@ -25,17 +25,37 @@
 
 #include "config.h"
 
-#ifdef HAVE_LIBI386
+// OpenBSD has a i386_iopl on i386 and amd64_iopl on x86_64,
+// even though they do the same thing.  Take care of this
+// here, and map set_iopl to point to the appropriate name.
 
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
+#if defined(HAVE_LIBI386)
 
 #include <sys/types.h>
 #include <machine/sysarch.h>
 #include <i386/pio.h>
+#define set_iopl i386_iopl
 
+#elif defined(HAVE_LIBAMD64)
+
+#include <sys/types.h>
+#include <machine/sysarch.h>
+#include <amd64/pio.h>
+#define set_iopl amd64_iopl
+
+#else
+#define NO_OBSD_DRIVER
+#endif
+
+// If the above succeeded, proceed with the rest.
+
+#ifndef NO_OBSD_DRIVER
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
 #include "opl.h"
 #include "opl_internal.h"
 #include "opl_timer.h"
@@ -46,7 +66,7 @@
 {
     // Try to get permissions:
 
-    if (i386_iopl(3) < 0)
+    if (set_iopl(3) < 0)
     {
         fprintf(stderr, "Failed to get raise I/O privilege level: "
                         "check that you are running as root.\n");
@@ -59,7 +79,7 @@
 
     if (!OPL_Timer_StartThread())
     {
-        i386_iopl(0);
+        set_iopl(0);
         return 0;
     }
 
@@ -74,7 +94,7 @@
 
     // Release I/O port permissions:
 
-    i386_iopl(0);
+    set_iopl(0);
 }
 
 static unsigned int OPL_OpenBSD_PortRead(opl_port_t port)
@@ -101,5 +121,5 @@
     OPL_Timer_SetPaused
 };
 
-#endif /* #ifdef HAVE_LIBI386 */
+#endif /* #ifndef NO_OBSD_DRIVER */