From 128ab2ff50a85969d08d2dec0fd88accdd153bcb Mon Sep 17 00:00:00 2001 From: blueswir1 Date: Fri, 15 Aug 2008 18:33:42 +0000 Subject: [PATCH] Preliminary OpenBSD host support (based on OpenBSD patches by Todd T. Fries) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5012 c046a42c-6fe2-441c-8c8c-71466251a162 --- block-raw-posix.c | 27 +++++++++++++++++++++++++++ configure | 6 ++++++ curses.c | 4 ++++ dyngen-exec.h | 4 ++++ fpu/softfloat-native.h | 12 +++++++++++- osdep.c | 17 +++++++++++++++-- osdep.h | 4 ++++ vl.c | 5 ++++- 8 files changed, 75 insertions(+), 4 deletions(-) diff --git a/block-raw-posix.c b/block-raw-posix.c index 5c3b0ac2e7..b1fc92181d 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -58,6 +58,12 @@ #include #endif +#ifdef __OpenBSD__ +#include +#include +#include +#endif + //#define DEBUG_FLOPPY //#define DEBUG_BLOCK @@ -745,6 +751,26 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset) return 0; } +#ifdef __OpenBSD__ +static int64_t raw_getlength(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + int fd = s->fd; + struct stat st; + + if (fstat(fd, &st)) + return -1; + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { + struct disklabel dl; + + if (ioctl(fd, DIOCGDINFO, &dl)) + return -1; + return (uint64_t)dl.d_secsize * + dl.d_partitions[DISKPART(st.st_rdev)].p_size; + } else + return st.st_size; +} +#else /* !__OpenBSD__ */ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -791,6 +817,7 @@ static int64_t raw_getlength(BlockDriverState *bs) } return size; } +#endif static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) diff --git a/configure b/configure index 5fdc227623..74ce443ff9 100755 --- a/configure +++ b/configure @@ -150,6 +150,7 @@ audio_possible_drivers="oss sdl esd" ;; OpenBSD) bsd="yes" +openbsd="yes" audio_drv_list="oss" audio_possible_drivers="oss sdl esd" ;; @@ -1086,6 +1087,11 @@ EOF echo "#define HAVE_BYTESWAP_H 1" >> $config_h fi fi + +if [ "$openbsd" = "yes" ] ; then + echo "#define ENOTSUP 4096" >> $config_h +fi + if test "$darwin" = "yes" ; then echo "CONFIG_DARWIN=yes" >> $config_mak echo "#define CONFIG_DARWIN 1" >> $config_h diff --git a/curses.c b/curses.c index 87aa9b36b6..d09eff256b 100644 --- a/curses.c +++ b/curses.c @@ -34,6 +34,10 @@ #include #endif +#ifdef __OpenBSD__ +#define resize_term resizeterm +#endif + #define FONT_HEIGHT 16 #define FONT_WIDTH 8 diff --git a/dyngen-exec.h b/dyngen-exec.h index 4caf9ffb57..9260b6f442 100644 --- a/dyngen-exec.h +++ b/dyngen-exec.h @@ -32,6 +32,9 @@ host headers do not allow that. */ #include +#ifdef __OpenBSD__ +#include +#else typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; @@ -61,6 +64,7 @@ typedef signed long int64_t; typedef signed long long int64_t; #endif #endif +#endif /* XXX: This may be wrong for 64-bit ILP32 hosts. */ typedef void * host_reg_t; diff --git a/fpu/softfloat-native.h b/fpu/softfloat-native.h index 53bf68192f..5994cd4737 100644 --- a/fpu/softfloat-native.h +++ b/fpu/softfloat-native.h @@ -15,7 +15,9 @@ * Solaris 10 with GCC4 does not need these macros as they * are defined in with a compiler directive */ -#if defined(HOST_SOLARIS) && (( HOST_SOLARIS <= 9 ) || ((HOST_SOLARIS >= 10) && (__GNUC__ <= 4))) +#if defined(HOST_SOLARIS) && (( HOST_SOLARIS <= 9 ) || ((HOST_SOLARIS >= 10) \ + && (__GNUC__ <= 4))) \ + || defined(__OpenBSD__) /* * C99 7.12.3 classification macros * and @@ -24,6 +26,9 @@ * ... do not work on Solaris 10 using GNU CC 3.4.x. * Try to workaround the missing / broken C99 math macros. */ +#if defined(__OpenBSD__) +#define unordered(x, y) (isnan(x) || isnan(y)) +#endif #define isnormal(x) (fpclass(x) >= FP_NZERO) #define isgreater(x, y) ((!unordered(x, y)) && ((x) > (y))) @@ -84,6 +89,11 @@ typedef union { | Software IEC/IEEE floating-point rounding mode. *----------------------------------------------------------------------------*/ #if (defined(_BSD) && !defined(__APPLE__)) || defined(HOST_SOLARIS) +#if defined(__OpenBSD__) +#define FE_RM FP_RM +#define FE_RP FP_RP +#define FE_RZ FP_RZ +#endif enum { float_round_nearest_even = FP_RN, float_round_down = FP_RM, diff --git a/osdep.c b/osdep.c index 46434af605..a49efba01b 100644 --- a/osdep.c +++ b/osdep.c @@ -68,7 +68,14 @@ void qemu_vfree(void *ptr) #if defined(USE_KQEMU) +#ifdef __OpenBSD__ +#include +#include +#include +#else #include +#endif + #include #include @@ -76,9 +83,14 @@ static void *kqemu_vmalloc(size_t size) { static int phys_ram_fd = -1; static int phys_ram_size = 0; + void *ptr; + +#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */ + int map_anon = MAP_ANON; +#else + int map_anon = 0; const char *tmpdir; char phys_ram_file[1024]; - void *ptr; #ifdef HOST_SOLARIS struct statvfs stfs; #else @@ -140,9 +152,10 @@ static void *kqemu_vmalloc(size_t size) } size = (size + 4095) & ~4095; ftruncate(phys_ram_fd, phys_ram_size + size); +#endif /* !__OpenBSD__ */ ptr = mmap(NULL, size, - PROT_WRITE | PROT_READ, MAP_SHARED, + PROT_WRITE | PROT_READ, map_anon | MAP_SHARED, phys_ram_fd, phys_ram_size); if (ptr == MAP_FAILED) { fprintf(stderr, "Could not map physical memory\n"); diff --git a/osdep.h b/osdep.h index a32242e07a..6312e7a2e4 100644 --- a/osdep.h +++ b/osdep.h @@ -2,6 +2,10 @@ #define QEMU_OSDEP_H #include +#ifdef __OpenBSD__ +#include +#include +#endif #ifndef glue #define xglue(x, y) x ## y diff --git a/vl.c b/vl.c index 6ade2ad165..0d6343f1b4 100644 --- a/vl.c +++ b/vl.c @@ -61,9 +61,12 @@ #include #ifdef _BSD #include -#ifndef __APPLE__ +#if !defined(__APPLE__) && !defined(__OpenBSD__) #include #endif +#ifdef __OpenBSD__ +#include +#endif #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__) #include #else