From 7d3505c55aae54c9610e8be1ff476ec8849c98e6 Mon Sep 17 00:00:00 2001 From: bellard Date: Wed, 12 May 2004 19:32:15 +0000 Subject: bsd port (Markus Niemisto) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@800 c046a42c-6fe2-441c-8c8c-71466251a162 --- Makefile | 10 +++++----- configure | 20 ++++++++++++++++++- dyngen-exec.h | 4 ++++ gdbstub.c | 2 +- target-i386/cpu.h | 2 +- target-i386/exec.h | 6 ++++++ target-i386/op.c | 19 ++++++++++++++++++ vl.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-------- vl.h | 8 ++++++++ 9 files changed, 111 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 7645c0857d..0f64aae5a3 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif all: dyngen$(EXESUF) $(TOOLS) qemu-doc.html qemu-tech.html qemu.1 for d in $(TARGET_DIRS); do \ - make -C $$d $@ || exit 1 ; \ + $(MAKE) -C $$d $@ || exit 1 ; \ done qemu-mkcow: qemu-mkcow.c @@ -29,9 +29,9 @@ clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS qemu.pod - make -C tests clean + $(MAKE) -C tests clean for d in $(TARGET_DIRS); do \ - make -C $$d $@ || exit 1 ; \ + $(MAKE) -C $$d $@ || exit 1 ; \ done distclean: clean @@ -55,12 +55,12 @@ ifndef CONFIG_WIN32 install qemu.1 qemu-mkcow.1 "$(mandir)/man1" endif for d in $(TARGET_DIRS); do \ - make -C $$d $@ || exit 1 ; \ + $(MAKE) -C $$d $@ || exit 1 ; \ done # various test targets test speed test2: all - make -C tests $@ + $(MAKE) -C tests $@ TAGS: etags *.[ch] tests/*.[ch] diff --git a/configure b/configure index 765b23428f..055f50ee93 100755 --- a/configure +++ b/configure @@ -79,9 +79,23 @@ case $targetos in MINGW32*) mingw32="yes" ;; +FreeBSD) +bsd="yes" +;; +NetBSD) +bsd="yes" +;; +OpenBSD) +bsd="yes" +;; *) ;; esac +if [ "$bsd" = "yes" ] ; then + make="gmake" + target_list="i386-softmmu" +fi + # find source path # XXX: we assume an absolute path is given when launching configure, # except in './configure' case. @@ -373,7 +387,7 @@ fi if test "$mingw32" = "yes" ; then echo "CONFIG_WIN32=yes" >> $config_mak echo "#define CONFIG_WIN32 1" >> $config_h -else +elif test -f "/usr/include/byteswap.h" ; then echo "#define HAVE_BYTESWAP_H 1" >> $config_h fi if test "$gdbstub" = "yes" ; then @@ -402,6 +416,10 @@ echo "\"" >> $config_h echo "SRC_PATH=$source_path" >> $config_mak echo "TARGET_DIRS=$target_list" >> $config_mak +if [ "$bsd" = "yes" ] ; then + echo "#define _BSD 1" >> $config_h +fi + for target in $target_list; do target_dir="$target" diff --git a/dyngen-exec.h b/dyngen-exec.h index ea20e395d6..2d5209bc89 100644 --- a/dyngen-exec.h +++ b/dyngen-exec.h @@ -59,7 +59,11 @@ extern int fprintf(FILE *, const char *, ...); extern int printf(const char *, ...); #undef NULL #define NULL 0 +#ifdef _BSD +#include +#else #include +#endif #ifdef __i386__ #define AREG0 "ebp" diff --git a/gdbstub.c b/gdbstub.c index 3560b269b9..19623102de 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -532,7 +532,7 @@ static void gdb_accept(void *opaque, const uint8_t *buf, int size) /* set short latency */ val = 1; - setsockopt(fd, SOL_TCP, TCP_NODELAY, &val, sizeof(val)); + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); s = qemu_mallocz(sizeof(GDBState)); if (!s) { diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 6939a2c6e6..19340d2579 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -259,7 +259,7 @@ enum { CC_OP_NB, }; -#if defined(__i386__) || defined(__x86_64__) +#if (defined(__i386__) || defined(__x86_64__)) && !defined(_BSD) #define USE_X86LDOUBLE #endif diff --git a/target-i386/exec.h b/target-i386/exec.h index fb9cc772f9..f5b03fbe58 100644 --- a/target-i386/exec.h +++ b/target-i386/exec.h @@ -17,6 +17,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" #include "dyngen-exec.h" /* at least 4 register variables are defines */ @@ -307,8 +308,13 @@ static inline void stfl(void *ptr, float v) #define rint rintl #endif +#if !defined(_BSD) extern int lrint(CPU86_LDouble x); extern int64_t llrint(CPU86_LDouble x); +#else +#define lrint(d) ((int)rint(d)) +#define llrint(d) ((int)rint(d)) +#endif extern CPU86_LDouble fabs(CPU86_LDouble x); extern CPU86_LDouble sin(CPU86_LDouble x); extern CPU86_LDouble cos(CPU86_LDouble x); diff --git a/target-i386/op.c b/target-i386/op.c index 37823319d6..fad8a730e7 100644 --- a/target-i386/op.c +++ b/target-i386/op.c @@ -1938,6 +1938,24 @@ void OPPROTO op_fldcw_A0(void) int rnd_type; env->fpuc = lduw((void *)A0); /* set rounding mode */ +#ifdef _BSD + switch(env->fpuc & RC_MASK) { + default: + case RC_NEAR: + rnd_type = FP_RN; + break; + case RC_DOWN: + rnd_type = FP_RM; + break; + case RC_UP: + rnd_type = FP_RP; + break; + case RC_CHOP: + rnd_type = FP_RZ; + break; + } + fpsetround(rnd_type); +#else switch(env->fpuc & RC_MASK) { default: case RC_NEAR: @@ -1954,6 +1972,7 @@ void OPPROTO op_fldcw_A0(void) break; } fesetround(rnd_type); +#endif } void OPPROTO op_fclex(void) diff --git a/vl.c b/vl.c index 05c6f0f1cf..4489056108 100644 --- a/vl.c +++ b/vl.c @@ -28,29 +28,35 @@ #include #include #include -#include #include #include #ifndef _WIN32 #include #include -#include #include #include #include #include #include +#ifdef _BSD +#include +#include +#else #include #include +#include +#include #include #endif +#endif #if defined(CONFIG_SLIRP) #include "libslirp.h" #endif #ifdef _WIN32 +#include #include #include #define getopt_long_only getopt_long @@ -58,15 +64,17 @@ #endif #ifdef CONFIG_SDL +#if defined(__linux__) /* SDL use the pthreads and they modify sigaction. We don't want that. */ -#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) +#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) extern void __libc_sigaction(); #define sigaction(sig, act, oact) __libc_sigaction(sig, act, oact) #else extern void __sigaction(); #define sigaction(sig, act, oact) __sigaction(sig, act, oact) #endif +#endif /* __linux__ */ #endif /* CONFIG_SDL */ #include "disas.h" @@ -637,11 +645,17 @@ int64_t qemu_get_clock(QEMUClock *clock) #ifdef _WIN32 return GetTickCount(); #else - /* XXX: portability among Linux hosts */ - if (timer_freq == 100) { - return times(NULL) * 10; - } else { - return ((int64_t)times(NULL) * 1000) / timer_freq; + { + struct tms tp; + + /* Note that using gettimeofday() is not a good solution + for timers because its value change when the date is + modified. */ + if (timer_freq == 100) { + return times(&tp) * 10; + } else { + return ((int64_t)times(&tp) * 1000) / timer_freq; + } } #endif default: @@ -964,7 +978,27 @@ static int net_slirp_init(NetDriverState *nd) #endif /* CONFIG_SLIRP */ #if !defined(_WIN32) +#ifdef _BSD +static int tun_open(char *ifname, int ifname_size) +{ + int fd; + char *dev; + struct stat s; + fd = open("/dev/tap", O_RDWR); + if (fd < 0) { + fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n"); + return -1; + } + + fstat(fd, &s); + dev = devname(s.st_rdev, S_IFCHR); + pstrcpy(ifname, ifname_size, dev); + + fcntl(fd, F_SETFL, O_NONBLOCK); + return fd; +} +#else static int tun_open(char *ifname, int ifname_size) { struct ifreq ifr; @@ -989,6 +1023,7 @@ static int tun_open(char *ifname, int ifname_size) fcntl(fd, F_SETFL, O_NONBLOCK); return fd; } +#endif static void tun_send_packet(NetDriverState *nd, const uint8_t *buf, int size) { @@ -2248,7 +2283,12 @@ int main(int argc, char **argv) phys_ram_size = ram_size + vga_ram_size; #ifdef CONFIG_SOFTMMU +#ifdef _BSD + /* mallocs are always aligned on BSD. */ + phys_ram_base = malloc(phys_ram_size); +#else phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size); +#endif if (!phys_ram_base) { fprintf(stderr, "Could not allocate physical memory\n"); exit(1); diff --git a/vl.h b/vl.h index 639b473cd5..b640ad4e72 100644 --- a/vl.h +++ b/vl.h @@ -35,6 +35,7 @@ #include #include #include +#include #ifndef O_LARGEFILE #define O_LARGEFILE 0 @@ -49,6 +50,13 @@ #include "cpu.h" +#ifdef _BSD +#define lseek64 lseek +#define ftruncate64 ftruncate +#define mkstemp64 mkstemp +#define MAP_ANONYMOUS MAP_ANON +#endif + #ifndef glue #define xglue(x, y) x ## y #define glue(x, y) xglue(x, y) -- cgit v1.2.3