summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2009-10-04 04:21:40 +0000
committerSimon Howard2009-10-04 04:21:40 +0000
commit73cc6b5a6017a15b02ce3480e0e58d19520b31ba (patch)
tree2cfb81d4c43594ff0a0e9d530df6c99147d24318
parent073e710f685a10c2084f6c04fbc4fe7c87530d93 (diff)
downloadchocolate-doom-73cc6b5a6017a15b02ce3480e0e58d19520b31ba.tar.gz
chocolate-doom-73cc6b5a6017a15b02ce3480e0e58d19520b31ba.tar.bz2
chocolate-doom-73cc6b5a6017a15b02ce3480e0e58d19520b31ba.zip
Make OpenBSD native OPL backend work on x86_64 as well as i386.
Subversion-branch: /branches/opl-branch Subversion-revision: 1707
-rw-r--r--configure.in2
-rw-r--r--opl/opl.c4
-rw-r--r--opl/opl_obsd.c38
3 files changed, 33 insertions, 11 deletions
diff --git a/configure.in b/configure.in
index d8bad56e..1d1b3f3e 100644
--- a/configure.in
+++ b/configure.in
@@ -73,8 +73,10 @@ AC_SDL_MAIN_WORKAROUND([
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, )
diff --git a/opl/opl.c b/opl/opl.c
index bf999d47..8e57647e 100644
--- 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 @@ static opl_driver_t *drivers[] =
#ifdef HAVE_IOPERM
&opl_linux_driver,
#endif
-#ifdef HAVE_LIBI386
+#if defined(HAVE_LIBI386) || defined(HAVE_LIBAMD64)
&opl_openbsd_driver,
#endif
#ifdef _WIN32
diff --git a/opl/opl_obsd.c b/opl/opl_obsd.c
index 05574333..b07a0421 100644
--- a/opl/opl_obsd.c
+++ b/opl/opl_obsd.c
@@ -25,16 +25,36 @@
#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"
@@ -46,7 +66,7 @@ static int OPL_OpenBSD_Init(unsigned int port_base)
{
// 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 @@ static int OPL_OpenBSD_Init(unsigned int port_base)
if (!OPL_Timer_StartThread())
{
- i386_iopl(0);
+ set_iopl(0);
return 0;
}
@@ -74,7 +94,7 @@ static void OPL_OpenBSD_Shutdown(void)
// 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_driver_t opl_openbsd_driver =
OPL_Timer_SetPaused
};
-#endif /* #ifdef HAVE_LIBI386 */
+#endif /* #ifndef NO_OBSD_DRIVER */