NetBSD and Dragonfly support
PATCH 1/1 NetBSD and Dragonfly support
Hello!
Please, consider merging following differences against QEMU 0.10.6 to support NetBSD and Dragonfly.
Collective work of pkgsrc project.
$NetBSD: patch-av,v 1.3 2007/10/07 21:21:00 heinz Exp $
Provide trunc() implementation for NetBSD 3 and Dragonfly
softfloat-native.c renamed from softfloat-native.c.orig +14 -0
@@ -3,6 +3,20 @@#include "softfloat.h" #include <math.h> +#if defined(__DragonFly__) || defined(__NetBSD__) +# include <sys/param.h> +#endif + +#if (defined(__DragonFly__) && __DragonFly_version <195000 ) || (defined(__NetBSD__) && __NetBSD_Version__ <=399001700 ) +static double trunc (double val ) +{ +if (val >0 ) +return floor (val); +else +return ceil (val); +} +#endif + void set_float_rounding_mode(int val STATUS_PARAM) {STATUS (float_rounding_mode) = val;
$NetBSD: patch-da,v 1.1 2009/08/31 10:18:49 hasso Exp $
sdlaudio.c renamed from sdlaudio.c.orig +1 -1
@@ -29,7 +29,7 @@#ifndef _WIN32#ifdef __sun__#define _POSIX_PTHREAD_SEMANTICS 1 -#elif defined(__OpenBSD__) || defined(__FreeBSD__) +#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)#include <pthread.h> #endif #include <signal.h>
$NetBSD: patch-db,v 1.1 2009/08/31 10:18:49 hasso Exp $
block-raw-posix.c renamed from block-raw-posix.c.orig +14 -0
@@ -63,6 +63,11 @@#include <sys/dkio.h> #endif +#ifdef __DragonFly__ +#include <sys/ioctl.h> +#include <sys/diskslice.h> +#endif +//#define DEBUG_FLOPPY //#define DEBUG_BLOCK
@@ -766,6 +771,15 @@ static int64_t raw_getlength(BlockDriveif (!fstat (fd, &sb) && (S_IFCHR & sb.st_mode)) {#ifdef DIOCGMEDIASIZE if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) +#elif defined(DIOCGPART ) + { +struct partinfo pi; +if (ioctl (fd,DIOCGPART , &pi) ==0 ) + size = pi.media_size; +else + size =0 ; + } + if (size == 0)#endif #ifdef CONFIG_COCOA size =LONG_LONG_MAX ;
$NetBSD: patch-dc,v 1.1 2009/08/31 10:18:49 hasso Exp $
block.c renamed from block.c.orig +2 -0
@@ -35,8 +35,10 @@#include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> +#ifndef __DragonFly__#include <sys/disk.h> #endif +#endif #define SECTOR_BITS 9#define SECTOR_SIZE (1 << SECTOR_BITS)
$NetBSD: patch-dd,v 1.1 2009/08/31 10:18:49 hasso Exp $
configure renamed from configure.orig +9 -0
@@ -228,6 +228,15 @@ if [ "$cpu" = "i386" -o "$cpu" = "x86_64 kqemu="yes" fi ;; +DragonFly) +bsd="yes" +audio_drv_list="oss" +audio_possible_drivers="oss sdl esd pa" +if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then + kqemu="yes" +fi +aio="no" +;; NetBSD) bsd="yes" audio_drv_list="oss"
$NetBSD: patch-de,v 1.2 2009/08/31 14:30:50 tnn Exp $
exec.c renamed from exec.c.orig +1 -1
@@ -454,7 +454,7 @@ static void code_gen_alloc(unsigned long exit(1); } } -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) {int flags;void *addr =NULL ;
$NetBSD: patch-df,v 1.1 2009/08/31 10:18:49 hasso Exp $
net.c renamed from net.c.orig +1 -1
@@ -59,7 +59,7 @@#include <sys/select.h> #ifdef _BSD#include <sys/stat.h> -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)#include <libutil.h> #else #include <util.h>
$NetBSD: patch-dg,v 1.2 2009/08/31 14:34:07 tnn Exp $
osdep.c renamed from osdep.c.orig +2 -2
@@ -90,7 +90,7 @@ static void *kqemu_vmalloc(size_t size)void *ptr;/* no need (?) for a dummy file on OpenBSD/FreeBSD */ -#if defined(__OpenBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__)int map_anon =MAP_ANON ;#else int map_anon =0 ;
@@ -157,7 +157,7 @@ static void *kqemu_vmalloc(size_t size) } size = (size +4095 ) & ~4095 ;ftruncate (phys_ram_fd, phys_ram_size + size); -#endif /* !(__OpenBSD__ || __FreeBSD__) */ +#endif /* !(__OpenBSD__ || __FreeBSD__ || __DragonFly__ || __NetBSD__) */ ptr = mmap(NULL, size, PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
$NetBSD: patch-dh,v 1.1 2009/08/31 10:18:49 hasso Exp $
qemu-char.c renamed from qemu-char.c.orig +9 -5
@@ -66,6 +66,10 @@#include <libutil.h> #include <dev/ppbus/ppi.h> #include <dev/ppbus/ppbconf.h> +#elif defined(__DragonFly__) +#include <libutil.h> +#include <dev/misc/ppi/ppi.h> +#include <bus/ppbus/ppbconf.h> #else #include <util.h> #endif
@@ -798,7 +802,7 @@ void cfmakeraw (struct termios *termios_#endif #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ - || defined(__NetBSD__) || defined(__OpenBSD__) + || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) typedef struct { int fd;
@@ -928,7 +932,7 @@ static CharDriverState *qemu_chr_open_ptPtyCharDriver *s;struct termios tty;int slave_fd, len; -#if defined(__OpenBSD__) +#if defined(__OpenBSD__) || defined(__DragonFly__)char pty_name[PATH_MAX ];#define q_ptsname (x) pty_name#else
@@ -1274,7 +1278,7 @@ static CharDriverState *qemu_chr_open_pp }#endif /* __linux__ */ -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__DragonFly__)static int pp_ioctl (CharDriverState *chr,int cmd,void *arg) {int fd = (int )chr->opaque;
@@ -2162,13 +2166,13 @@ CharDriverState *qemu_chr_open(const chaif (strstart (filename,"/dev/parport" ,NULL )) { chr =qemu_chr_open_pp (filename); } else -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined(__DragonFly__)if (strstart (filename,"/dev/ppi" ,NULL )) { chr =qemu_chr_open_pp (filename); } else#endif #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ - || defined(__NetBSD__) || defined(__OpenBSD__) + || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)if (strstart (filename,"/dev/" ,NULL )) { chr =qemu_chr_open_tty (filename); }else
$NetBSD: patch-di,v 1.1 2009/08/31 10:18:49 hasso Exp $
savevm.c renamed from savevm.c.orig +1 -1
@@ -63,7 +63,7 @@#include <sys/select.h> #ifdef _BSD#include <sys/stat.h> -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)#include <libutil.h> #else #include <util.h>
$NetBSD: patch-dj,v 1.1 2009/08/31 10:18:49 hasso Exp $
usb-bsd.c renamed from usb-bsd.c.orig +7 -3
@@ -34,7 +34,11 @@#undef USB_SPEED_LOW#include <sys/ioctl.h> +#ifndef __DragonFly__#include <dev/usb/usb.h> +#else +#include <bus/usb/usb.h> +#endif #include <signal.h> /* This value has maximum potential at 16.
@@ -68,7 +72,7 @@ static int ensure_ep_open(USBHostDevice ep =UE_GET_ADDR (ep);if (dev->ep_fd[ep] <0 ) { -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)snprintf (buf,sizeof (buf) -1 ,"%s.%d" , dev->devpath, ep);#else snprintf (buf,sizeof (buf) -1 ,"%s.%02d" , dev->devpath, ep);
@@ -321,7 +325,7 @@ USBDevice *usb_host_device_open(const chreturn NULL ; } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)snprintf (ctlpath,PATH_MAX ,"/dev/%s" , bus_info.udi_devnames[0 ]);#else snprintf (ctlpath,PATH_MAX ,"/dev/%s.00" , bus_info.udi_devnames[0 ]);
@@ -411,7 +415,7 @@ static int usb_host_scan(void *opaque, Uif (strncmp (bus_info.udi_devnames[0 ],"ugen" ,4 ) !=0 )continue ; -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)snprintf (devbuf,sizeof (devbuf) -1 ,"/dev/%s" , bus_info.udi_devnames[0 ]);#else snprintf (devbuf,sizeof (devbuf) -1 ,"/dev/%s.00" , bus_info.udi_devnames[0 ]);
$NetBSD: patch-dk,v 1.3 2009/08/31 14:49:21 tnn Exp $
vl.c renamed from vl.c.orig +5 -3
@@ -74,7 +74,7 @@#include <sys/select.h> #ifdef _BSD#include <sys/stat.h> -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__)#include <libutil.h> #else #include <util.h>
@@ -755,7 +755,8 @@ static int use_rt_clock;static void init_get_clock (void ) { use_rt_clock =0 ; -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >=500000 ) +#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >=500000 ) \ + || defined(__DragonFly__) || defined(__NetBSD__) {struct timespec ts;if (clock_gettime (CLOCK_MONOTONIC , &ts) ==0 ) {
@@ -767,7 +768,8 @@ static void init_get_clock(void)static int64_t get_clock (void ) { -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >=500000 ) +#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >=500000 ) \ + || defined(__DragonFly__) || defined(__NetBSD__)if (use_rt_clock) {struct timespec ts;clock_gettime (CLOCK_MONOTONIC , &ts);
$NetBSD: patch-dl,v 1.2 2009/08/31 13:07:04 asau Exp $
cpu-exec.c renamed from cpu-exec.c.orig +16 -0
@@ -1156,6 +1156,18 @@# define EIP_sig (context) (*((unsigned long*)&(context)->uc_mcontext->ss.eip))# define TRAP_sig (context) ((context)->uc_mcontext->es.trapno)# define ERROR_sig (context) ((context)->uc_mcontext->es.err) +#elif defined (__NetBSD__) +# include <ucontext.h> + +# define EIP_sig (context) ((context)->uc_mcontext.__gregs[_REG_EIP]) +# define TRAP_sig (context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO]) +# define ERROR_sig (context) ((context)->uc_mcontext.__gregs[_REG_ERR]) +#elif defined (__FreeBSD__) || defined(__DragonFly__) +# include <ucontext.h> + +# define EIP_sig (context) (*((unsigned long*)&(context)->uc_mcontext.mc_eip)) +# define TRAP_sig (context) ((context)->uc_mcontext.mc_trapno) +# define ERROR_sig (context) ((context)->uc_mcontext.mc_err)#else # define EIP_sig (context) ((context)->uc_mcontext.gregs[REG_EIP])# define TRAP_sig (context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
@@ -1166,7 +1178,11 @@ void *puc) {siginfo_t *info = pinfo; +#if defined(__NetBSD__) || defined (__FreeBSD__) || defined(__DragonFly__) +ucontext_t *uc = puc; +#else struct ucontext *uc = puc; +#endif unsigned long pc;int trapno;
$NetBSD: patch-dm,v 1.1 2009/08/31 10:18:49 hasso Exp $
exec-all.h renamed from exec-all.h.orig +1 -1
@@ -35,7 +35,7 @@typedef struct TranslationBlock TranslationBlock ;/* XXX: make safe guess about sizes */ -#define MAX_OP_PER_INSTR 64 +#define MAX_OP_PER_INSTR 128/* A Call op needs up to 6 + 2N parameters (N = number of arguments). */ #define MAX_OPC_PARAM 10#define OPC_BUF_SIZE 512
Signature · 1 line
CE3OH...
Quoted 6 lines · Aleksej Saushev
Hello!
Please, consider merging following differences against QEMU 0.10.6 to support NetBSD and Dragonfly.
Collective work of pkgsrc project.
I don't think one big patch for this is a good idea, one area per subject would be a lot easier maintainable as there are different people knowing the different areas better.
[Qemu-devel] raw_getlength, was [patch] NetBSD and Dragonfly support
In reply to Aleksej Saushevblock-raw-posix.c line 69
Quoted 10 lines · Aleksej Saushev
block-raw-posix.c renamed from block-raw-posix.c.orig +4
-0@@ -63,6 +63,11 @@#include <sys/dkio.h> #endif +#ifdef __DragonFly__ +#include <sys/ioctl.h> +#include <sys/diskslice.h> +#endif
This code already exists in current gemu git HEAD.
Quoted 5 lines
block-raw-posix.c renamed from block-raw-posix.c.orig +0
-0//#define DEBUG_BLOCK @@ -766,6 +771,15 @@ static int64_t raw_getlength(BlockDriveif (!fstat (fd, &sb) && (S_IFCHR & sb.st_mode)) {#ifdef DIOCGMEDIASIZE if (ioctl (fd,DIOCGMEDIASIZE , (off_t *)&size))
block-raw-posix.c static int64_t raw_getlength(BlockDrive · line 783
Quoted 10 lines
block-raw-posix.c renamed from block-raw-posix.c.orig +9
-0+#elif defined(DIOCGPART ) + { +struct partinfo pi; +if (ioctl (fd,DIOCGPART , &pi) ==0 ) + size = pi.media_size; +else + size =0 ; + } + if (size == 0)#endif
Same for this. But raw_getlength has been turned into an utter mess. Any chance you could see if the patch below works on the various BSD platforms?
block/raw-posix.c +70 -61
@@ -124,9 +124,6 @@ typedef struct BDRVRawState {static int fd_open (BlockDriverState *bs);static int64_t raw_getlength (BlockDriverState *bs); -#if defined(__FreeBSD__) -static int cdrom_reopen (BlockDriverState *bs); -#endif static int raw_open_common (BlockDriverState *bs,const char *filename,int bdrv_flags,int open_flags)
@@ -614,80 +611,74 @@ static int64_t raw_getlength(BlockDriver } elsereturn st.st_size; } -#else /* !__OpenBSD__ */ -static int64_t raw_getlength (BlockDriverState *bs) +#elif defined(CONFIG_BSD) +static int64_t raw_getlength (BlockDriverState *bs) {BDRVRawState *s = bs->opaque;int fd = s->fd; -int64_t size; -#ifdef CONFIG_BSD +int64_t size =0 ;struct stat sb; -#ifdef __FreeBSD__ -int reopened =0 ; -#endif -#endif -#ifdef __sun__ -struct dk_minfo minfo; -int rv; -#endif int ret; ret =fd_open (bs);if (ret <0 )return ret; -#ifdef CONFIG_BSD -#ifdef __FreeBSD__ -again: -#endif -if (!fstat (fd, &sb) && (S_IFCHR & sb.st_mode)) { +if (fstat (fd, &sb) !=0 || !(S_IFCHR & sb.st_mode)) { +return lseek (fd,0 ,SEEK_END ); +#ifdef DIOCGMEDIASIZE - if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) +if (!ioctl (fd,DIOCGMEDIASIZE , (off_t *)&size)) +return size;#elif defined(DIOCGPART ) - { -struct partinfo pi; -if (ioctl (fd,DIOCGPART , &pi) ==0 ) - size = pi.media_size; -else - size =0 ; - } - if (size == 0) + { +struct partinfo pi; +if (ioctl (fd,DIOCGPART , &pi) ==0 ) +return pi.media_size; + }#endif +#ifdef CONFIG_COCOA - size =LONG_LONG_MAX ; +return LONG_LONG_MAX ;#else - size =lseek (fd,0LL ,SEEK_END ); -#endif -#ifdef __FreeBSD__ -switch (s->type) { -case FTYPE_CD : -/* XXX FreeBSD acd returns UINT_MAX sectors for an empty drive */ -if (size ==2048LL * (unsigned )-1 ) - size =0 ; -/* XXX no disc? maybe we need to reopen... */ -if (size <=0 && !reopened &&cdrom_reopen (bs) >=0 ) { - reopened =1 ; - goto again; - } - } -#endif - } else +return lseek (fd,0LL ,SEEK_END );#endif -#ifdef __sun__ +} +#elif defined(__sun__) +static int64_t raw_getlength (BlockDriverState *bs) +{ +BDRVRawState *s = bs->opaque; +struct dk_minfo minfo; +int ret; + + ret =fd_open (bs); +if (ret <0 ) +return ret; +/* -* use the DKIOCGMEDIAINFO ioctl to read the size. +* Use the DKIOCGMEDIAINFO ioctl to read the size. */ - rv =ioctl ( fd,DKIOCGMEDIAINFO , &minfo ); -if ( rv !=-1 ) { - size = minfo.dki_lbsize * minfo.dki_capacity; - } else /* there are reports that lseek on some devices -fails, but irc discussion said that contingency -on contingency was overkill */ -#endif - { - size =lseek (fd,0 ,SEEK_END ); - } - return size; + ret =ioctl (s->fd,DKIOCGMEDIAINFO , &minfo); +if (ret !=-1 ) { +return minfo.dki_lbsize * minfo.dki_capacity; + +/* +* There are reports that lseek on some devices fails, but irc +* irc discussion said that contingency on contingency was overkill. +*/ +return lseek (s->fd,0 ,SEEK_END ); +} +#else +static int64_t raw_getlength (BlockDriverState *bs) +{ +BDRVRawState *s = bs->opaque; +int ret; + + ret =fd_open (bs); +if (ret <0 ) +return ret; + +return lseek (s->fd,0 ,SEEK_END ); }#endif
@@ -1240,9 +1231,27 @@ static int cdrom_reopen(BlockDriverStatereturn 0 ; } +static int64_t cdrom_getlength (BlockDriverState *bs) +{ +int64_t size; +int reopened =0 ; + +for (;;) { + size =raw_getlength (bs); + +/* XXX FreeBSD acd returns UINT_MAX sectors for an empty drive */ +if (size ==2048LL * (unsigned )-1 ) + size =0 ; +/* XXX no disc? maybe we need to reopen... */ +if (size >0 || reopened ||cdrom_reopen (bs) <0 ) +return size; + reopened =1 ; + } +} +static int cdrom_is_inserted (BlockDriverState *bs) { -return raw_getlength (bs) >0 ; +return cdrom_getlength (bs) >0 ; }static int cdrom_eject (BlockDriverState *bs,int eject_flag)
@@ -1298,7 +1307,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_read = raw_read, .bdrv_write = raw_write, - .bdrv_getlength = raw_getlength, + .bdrv_getlength = cdrom_getlength,/* removable device support */ .bdrv_is_inserted = cdrom_is_inserted,