Commit 7d3505c55aae54c9610e8be1ff476ec8849c98e6

Authored by bellard
1 parent fd872598

bsd port (Markus Niemisto)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@800 c046a42c-6fe2-441c-8c8c-71466251a162
Makefile
@@ -16,7 +16,7 @@ endif @@ -16,7 +16,7 @@ endif
16 16
17 all: dyngen$(EXESUF) $(TOOLS) qemu-doc.html qemu-tech.html qemu.1 17 all: dyngen$(EXESUF) $(TOOLS) qemu-doc.html qemu-tech.html qemu.1
18 for d in $(TARGET_DIRS); do \ 18 for d in $(TARGET_DIRS); do \
19 - make -C $$d $@ || exit 1 ; \ 19 + $(MAKE) -C $$d $@ || exit 1 ; \
20 done 20 done
21 21
22 qemu-mkcow: qemu-mkcow.c 22 qemu-mkcow: qemu-mkcow.c
@@ -29,9 +29,9 @@ clean: @@ -29,9 +29,9 @@ clean:
29 # avoid old build problems by removing potentially incorrect old files 29 # avoid old build problems by removing potentially incorrect old files
30 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 30 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
31 rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS qemu.pod 31 rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS qemu.pod
32 - make -C tests clean 32 + $(MAKE) -C tests clean
33 for d in $(TARGET_DIRS); do \ 33 for d in $(TARGET_DIRS); do \
34 - make -C $$d $@ || exit 1 ; \ 34 + $(MAKE) -C $$d $@ || exit 1 ; \
35 done 35 done
36 36
37 distclean: clean 37 distclean: clean
@@ -55,12 +55,12 @@ ifndef CONFIG_WIN32 @@ -55,12 +55,12 @@ ifndef CONFIG_WIN32
55 install qemu.1 qemu-mkcow.1 "$(mandir)/man1" 55 install qemu.1 qemu-mkcow.1 "$(mandir)/man1"
56 endif 56 endif
57 for d in $(TARGET_DIRS); do \ 57 for d in $(TARGET_DIRS); do \
58 - make -C $$d $@ || exit 1 ; \ 58 + $(MAKE) -C $$d $@ || exit 1 ; \
59 done 59 done
60 60
61 # various test targets 61 # various test targets
62 test speed test2: all 62 test speed test2: all
63 - make -C tests $@ 63 + $(MAKE) -C tests $@
64 64
65 TAGS: 65 TAGS:
66 etags *.[ch] tests/*.[ch] 66 etags *.[ch] tests/*.[ch]
configure
@@ -79,9 +79,23 @@ case $targetos in @@ -79,9 +79,23 @@ case $targetos in
79 MINGW32*) 79 MINGW32*)
80 mingw32="yes" 80 mingw32="yes"
81 ;; 81 ;;
  82 +FreeBSD)
  83 +bsd="yes"
  84 +;;
  85 +NetBSD)
  86 +bsd="yes"
  87 +;;
  88 +OpenBSD)
  89 +bsd="yes"
  90 +;;
82 *) ;; 91 *) ;;
83 esac 92 esac
84 93
  94 +if [ "$bsd" = "yes" ] ; then
  95 + make="gmake"
  96 + target_list="i386-softmmu"
  97 +fi
  98 +
85 # find source path 99 # find source path
86 # XXX: we assume an absolute path is given when launching configure, 100 # XXX: we assume an absolute path is given when launching configure,
87 # except in './configure' case. 101 # except in './configure' case.
@@ -373,7 +387,7 @@ fi @@ -373,7 +387,7 @@ fi
373 if test "$mingw32" = "yes" ; then 387 if test "$mingw32" = "yes" ; then
374 echo "CONFIG_WIN32=yes" >> $config_mak 388 echo "CONFIG_WIN32=yes" >> $config_mak
375 echo "#define CONFIG_WIN32 1" >> $config_h 389 echo "#define CONFIG_WIN32 1" >> $config_h
376 -else 390 +elif test -f "/usr/include/byteswap.h" ; then
377 echo "#define HAVE_BYTESWAP_H 1" >> $config_h 391 echo "#define HAVE_BYTESWAP_H 1" >> $config_h
378 fi 392 fi
379 if test "$gdbstub" = "yes" ; then 393 if test "$gdbstub" = "yes" ; then
@@ -402,6 +416,10 @@ echo "\"" >> $config_h @@ -402,6 +416,10 @@ echo "\"" >> $config_h
402 echo "SRC_PATH=$source_path" >> $config_mak 416 echo "SRC_PATH=$source_path" >> $config_mak
403 echo "TARGET_DIRS=$target_list" >> $config_mak 417 echo "TARGET_DIRS=$target_list" >> $config_mak
404 418
  419 +if [ "$bsd" = "yes" ] ; then
  420 + echo "#define _BSD 1" >> $config_h
  421 +fi
  422 +
405 for target in $target_list; do 423 for target in $target_list; do
406 424
407 target_dir="$target" 425 target_dir="$target"
dyngen-exec.h
@@ -59,7 +59,11 @@ extern int fprintf(FILE *, const char *, ...); @@ -59,7 +59,11 @@ extern int fprintf(FILE *, const char *, ...);
59 extern int printf(const char *, ...); 59 extern int printf(const char *, ...);
60 #undef NULL 60 #undef NULL
61 #define NULL 0 61 #define NULL 0
  62 +#ifdef _BSD
  63 +#include <ieeefp.h>
  64 +#else
62 #include <fenv.h> 65 #include <fenv.h>
  66 +#endif
63 67
64 #ifdef __i386__ 68 #ifdef __i386__
65 #define AREG0 "ebp" 69 #define AREG0 "ebp"
gdbstub.c
@@ -532,7 +532,7 @@ static void gdb_accept(void *opaque, const uint8_t *buf, int size) @@ -532,7 +532,7 @@ static void gdb_accept(void *opaque, const uint8_t *buf, int size)
532 532
533 /* set short latency */ 533 /* set short latency */
534 val = 1; 534 val = 1;
535 - setsockopt(fd, SOL_TCP, TCP_NODELAY, &val, sizeof(val)); 535 + setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
536 536
537 s = qemu_mallocz(sizeof(GDBState)); 537 s = qemu_mallocz(sizeof(GDBState));
538 if (!s) { 538 if (!s) {
target-i386/cpu.h
@@ -259,7 +259,7 @@ enum { @@ -259,7 +259,7 @@ enum {
259 CC_OP_NB, 259 CC_OP_NB,
260 }; 260 };
261 261
262 -#if defined(__i386__) || defined(__x86_64__) 262 +#if (defined(__i386__) || defined(__x86_64__)) && !defined(_BSD)
263 #define USE_X86LDOUBLE 263 #define USE_X86LDOUBLE
264 #endif 264 #endif
265 265
target-i386/exec.h
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 * License along with this library; if not, write to the Free Software 17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
  20 +#include "config.h"
20 #include "dyngen-exec.h" 21 #include "dyngen-exec.h"
21 22
22 /* at least 4 register variables are defines */ 23 /* at least 4 register variables are defines */
@@ -307,8 +308,13 @@ static inline void stfl(void *ptr, float v) @@ -307,8 +308,13 @@ static inline void stfl(void *ptr, float v)
307 #define rint rintl 308 #define rint rintl
308 #endif 309 #endif
309 310
  311 +#if !defined(_BSD)
310 extern int lrint(CPU86_LDouble x); 312 extern int lrint(CPU86_LDouble x);
311 extern int64_t llrint(CPU86_LDouble x); 313 extern int64_t llrint(CPU86_LDouble x);
  314 +#else
  315 +#define lrint(d) ((int)rint(d))
  316 +#define llrint(d) ((int)rint(d))
  317 +#endif
312 extern CPU86_LDouble fabs(CPU86_LDouble x); 318 extern CPU86_LDouble fabs(CPU86_LDouble x);
313 extern CPU86_LDouble sin(CPU86_LDouble x); 319 extern CPU86_LDouble sin(CPU86_LDouble x);
314 extern CPU86_LDouble cos(CPU86_LDouble x); 320 extern CPU86_LDouble cos(CPU86_LDouble x);
target-i386/op.c
@@ -1938,6 +1938,24 @@ void OPPROTO op_fldcw_A0(void) @@ -1938,6 +1938,24 @@ void OPPROTO op_fldcw_A0(void)
1938 int rnd_type; 1938 int rnd_type;
1939 env->fpuc = lduw((void *)A0); 1939 env->fpuc = lduw((void *)A0);
1940 /* set rounding mode */ 1940 /* set rounding mode */
  1941 +#ifdef _BSD
  1942 + switch(env->fpuc & RC_MASK) {
  1943 + default:
  1944 + case RC_NEAR:
  1945 + rnd_type = FP_RN;
  1946 + break;
  1947 + case RC_DOWN:
  1948 + rnd_type = FP_RM;
  1949 + break;
  1950 + case RC_UP:
  1951 + rnd_type = FP_RP;
  1952 + break;
  1953 + case RC_CHOP:
  1954 + rnd_type = FP_RZ;
  1955 + break;
  1956 + }
  1957 + fpsetround(rnd_type);
  1958 +#else
1941 switch(env->fpuc & RC_MASK) { 1959 switch(env->fpuc & RC_MASK) {
1942 default: 1960 default:
1943 case RC_NEAR: 1961 case RC_NEAR:
@@ -1954,6 +1972,7 @@ void OPPROTO op_fldcw_A0(void) @@ -1954,6 +1972,7 @@ void OPPROTO op_fldcw_A0(void)
1954 break; 1972 break;
1955 } 1973 }
1956 fesetround(rnd_type); 1974 fesetround(rnd_type);
  1975 +#endif
1957 } 1976 }
1958 1977
1959 void OPPROTO op_fclex(void) 1978 void OPPROTO op_fclex(void)
@@ -28,29 +28,35 @@ @@ -28,29 +28,35 @@
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <signal.h> 29 #include <signal.h>
30 #include <time.h> 30 #include <time.h>
31 -#include <malloc.h>  
32 #include <errno.h> 31 #include <errno.h>
33 #include <sys/time.h> 32 #include <sys/time.h>
34 33
35 #ifndef _WIN32 34 #ifndef _WIN32
36 #include <sys/times.h> 35 #include <sys/times.h>
37 #include <sys/wait.h> 36 #include <sys/wait.h>
38 -#include <pty.h>  
39 #include <termios.h> 37 #include <termios.h>
40 #include <sys/poll.h> 38 #include <sys/poll.h>
41 #include <sys/mman.h> 39 #include <sys/mman.h>
42 #include <sys/ioctl.h> 40 #include <sys/ioctl.h>
43 #include <sys/socket.h> 41 #include <sys/socket.h>
  42 +#ifdef _BSD
  43 +#include <sys/stat.h>
  44 +#include <libutil.h>
  45 +#else
44 #include <linux/if.h> 46 #include <linux/if.h>
45 #include <linux/if_tun.h> 47 #include <linux/if_tun.h>
  48 +#include <pty.h>
  49 +#include <malloc.h>
46 #include <linux/rtc.h> 50 #include <linux/rtc.h>
47 #endif 51 #endif
  52 +#endif
48 53
49 #if defined(CONFIG_SLIRP) 54 #if defined(CONFIG_SLIRP)
50 #include "libslirp.h" 55 #include "libslirp.h"
51 #endif 56 #endif
52 57
53 #ifdef _WIN32 58 #ifdef _WIN32
  59 +#include <malloc.h>
54 #include <sys/timeb.h> 60 #include <sys/timeb.h>
55 #include <windows.h> 61 #include <windows.h>
56 #define getopt_long_only getopt_long 62 #define getopt_long_only getopt_long
@@ -58,15 +64,17 @@ @@ -58,15 +64,17 @@
58 #endif 64 #endif
59 65
60 #ifdef CONFIG_SDL 66 #ifdef CONFIG_SDL
  67 +#if defined(__linux__)
61 /* SDL use the pthreads and they modify sigaction. We don't 68 /* SDL use the pthreads and they modify sigaction. We don't
62 want that. */ 69 want that. */
63 -#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) 70 +#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
64 extern void __libc_sigaction(); 71 extern void __libc_sigaction();
65 #define sigaction(sig, act, oact) __libc_sigaction(sig, act, oact) 72 #define sigaction(sig, act, oact) __libc_sigaction(sig, act, oact)
66 #else 73 #else
67 extern void __sigaction(); 74 extern void __sigaction();
68 #define sigaction(sig, act, oact) __sigaction(sig, act, oact) 75 #define sigaction(sig, act, oact) __sigaction(sig, act, oact)
69 #endif 76 #endif
  77 +#endif /* __linux__ */
70 #endif /* CONFIG_SDL */ 78 #endif /* CONFIG_SDL */
71 79
72 #include "disas.h" 80 #include "disas.h"
@@ -637,11 +645,17 @@ int64_t qemu_get_clock(QEMUClock *clock) @@ -637,11 +645,17 @@ int64_t qemu_get_clock(QEMUClock *clock)
637 #ifdef _WIN32 645 #ifdef _WIN32
638 return GetTickCount(); 646 return GetTickCount();
639 #else 647 #else
640 - /* XXX: portability among Linux hosts */  
641 - if (timer_freq == 100) {  
642 - return times(NULL) * 10;  
643 - } else {  
644 - return ((int64_t)times(NULL) * 1000) / timer_freq; 648 + {
  649 + struct tms tp;
  650 +
  651 + /* Note that using gettimeofday() is not a good solution
  652 + for timers because its value change when the date is
  653 + modified. */
  654 + if (timer_freq == 100) {
  655 + return times(&tp) * 10;
  656 + } else {
  657 + return ((int64_t)times(&tp) * 1000) / timer_freq;
  658 + }
645 } 659 }
646 #endif 660 #endif
647 default: 661 default:
@@ -964,7 +978,27 @@ static int net_slirp_init(NetDriverState *nd) @@ -964,7 +978,27 @@ static int net_slirp_init(NetDriverState *nd)
964 #endif /* CONFIG_SLIRP */ 978 #endif /* CONFIG_SLIRP */
965 979
966 #if !defined(_WIN32) 980 #if !defined(_WIN32)
  981 +#ifdef _BSD
  982 +static int tun_open(char *ifname, int ifname_size)
  983 +{
  984 + int fd;
  985 + char *dev;
  986 + struct stat s;
967 987
  988 + fd = open("/dev/tap", O_RDWR);
  989 + if (fd < 0) {
  990 + fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
  991 + return -1;
  992 + }
  993 +
  994 + fstat(fd, &s);
  995 + dev = devname(s.st_rdev, S_IFCHR);
  996 + pstrcpy(ifname, ifname_size, dev);
  997 +
  998 + fcntl(fd, F_SETFL, O_NONBLOCK);
  999 + return fd;
  1000 +}
  1001 +#else
968 static int tun_open(char *ifname, int ifname_size) 1002 static int tun_open(char *ifname, int ifname_size)
969 { 1003 {
970 struct ifreq ifr; 1004 struct ifreq ifr;
@@ -989,6 +1023,7 @@ static int tun_open(char *ifname, int ifname_size) @@ -989,6 +1023,7 @@ static int tun_open(char *ifname, int ifname_size)
989 fcntl(fd, F_SETFL, O_NONBLOCK); 1023 fcntl(fd, F_SETFL, O_NONBLOCK);
990 return fd; 1024 return fd;
991 } 1025 }
  1026 +#endif
992 1027
993 static void tun_send_packet(NetDriverState *nd, const uint8_t *buf, int size) 1028 static void tun_send_packet(NetDriverState *nd, const uint8_t *buf, int size)
994 { 1029 {
@@ -2248,7 +2283,12 @@ int main(int argc, char **argv) @@ -2248,7 +2283,12 @@ int main(int argc, char **argv)
2248 phys_ram_size = ram_size + vga_ram_size; 2283 phys_ram_size = ram_size + vga_ram_size;
2249 2284
2250 #ifdef CONFIG_SOFTMMU 2285 #ifdef CONFIG_SOFTMMU
  2286 +#ifdef _BSD
  2287 + /* mallocs are always aligned on BSD. */
  2288 + phys_ram_base = malloc(phys_ram_size);
  2289 +#else
2251 phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size); 2290 phys_ram_base = memalign(TARGET_PAGE_SIZE, phys_ram_size);
  2291 +#endif
2252 if (!phys_ram_base) { 2292 if (!phys_ram_base) {
2253 fprintf(stderr, "Could not allocate physical memory\n"); 2293 fprintf(stderr, "Could not allocate physical memory\n");
2254 exit(1); 2294 exit(1);
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 #include <errno.h> 35 #include <errno.h>
36 #include <unistd.h> 36 #include <unistd.h>
37 #include <fcntl.h> 37 #include <fcntl.h>
  38 +#include <sys/stat.h>
38 39
39 #ifndef O_LARGEFILE 40 #ifndef O_LARGEFILE
40 #define O_LARGEFILE 0 41 #define O_LARGEFILE 0
@@ -49,6 +50,13 @@ @@ -49,6 +50,13 @@
49 50
50 #include "cpu.h" 51 #include "cpu.h"
51 52
  53 +#ifdef _BSD
  54 +#define lseek64 lseek
  55 +#define ftruncate64 ftruncate
  56 +#define mkstemp64 mkstemp
  57 +#define MAP_ANONYMOUS MAP_ANON
  58 +#endif
  59 +
52 #ifndef glue 60 #ifndef glue
53 #define xglue(x, y) x ## y 61 #define xglue(x, y) x ## y
54 #define glue(x, y) xglue(x, y) 62 #define glue(x, y) xglue(x, y)