Re: [Qemu-devel] Re: EFI console stopped working in Qemu 0.14.0

2011-03-06 Thread vagran

When I trying to specify 64-bit EFI BIOS nothing happens on VGA
nor serial console. It seems that CPU is continuously restarting.

Build and host system is Ubuntu 9.10:
Linux AST-mobile 2.6.31-22-generic-pae #73-Ubuntu SMP Fri Feb 11 
18:39:01 UTC 2011 i686 GNU/Linux


Qemu 0.14.0 was built with the following configuration options:
../src/configure --prefix=$PREFIX --target-list=x86_64-softmmu 
--source-path=../src --enable-kvm

--extra-cflags=-I$PREFIX/include --extra-ldflags=-L$PREFIX/lib

And launched:
qemu-system-x86_64 -L $PHOBOS_PREFIX/share/qemu/phobos64 -bios OVMF.fd 
-m 768 -cpu core2duo
-vga cirrus -monitor stdio -serial tcp::666,server -s -hdb 
$PHOBOS_PREFIX/share/qemu/phobos.disk -usb -enable-kvm


OVMF X64 is r11337.

log cpu_reset provides this information (continuously in a loop):
CPU Reset (CPU 0)
EAX=0100 EBX=fffee0e4 ECX=c080 EDX=
ESI=fffee2c4 EDI=5042 EBP=fffee000 ESP=
EIP=ff21 EFL=00010082 [--S] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0008   00c09300 DPL=0 DS   [-WA]
CS =0010   00c09b00 DPL=0 CS32 [-RA]
SS =0008   00c09300 DPL=0 DS   [-WA]
DS =0008   00c09300 DPL=0 DS   [-WA]
FS =0008   00c09300 DPL=0 DS   [-WA]
GS =0008   00c09300 DPL=0 DS   [-WA]
LDT=   8200 DPL=0 LDT
TR =   8b00 DPL=0 TSS32-busy
GDT= ff80 001f
IDT=  
CR0=4023 CR2= CR3=e000 CR4=0660
DR0= DR1= DR2= 
DR3=

DR6=0ff0 DR7=0400
CCS= CCD= CCO=DYNAMIC
EFER=
FCW=037f FSW= [ST=0] FTW=00 MXCSR=
FPR0=  FPR1= 
FPR2=  FPR3= 
FPR4=  FPR5= 
FPR6=  FPR7= 
XMM00= 
XMM01=
XMM02= 
XMM03=
XMM04= 
XMM05=
XMM06= 
XMM07=


Best regards,
Artyom.

Jordan Justen wrote:

On Thu, Mar 3, 2011 at 10:02, vagran vagran@gmail.com wrote:
  

I have taken EFI BIOS image from
http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=OVMF
32-bit version works perfectly. However 64-bit version for some reason
doesn't work on
qemu-system-x86_64.



Hi.  I was wondering if you could describe the OVMF issue you saw with
qemu-system-x86_64.

I tried 0.14.0 with OVMF X64 (r11337), and it was able to boot to the EFI shell.

I did see an issue while booting the 64-bit Ubuntu 10.10 live-cd, but
occurred on both the legacy (seabios) and uefi (ovmf) firmware.  With
kvm 0.14.0, in both cases the OS boots most of the way, but the
graphics do not start properly when X starts.

Thanks,

-Jordan
  


Re: [Qemu-devel] Qemu support on android

2011-03-06 Thread Dushyant Bansal

On Saturday 05 March 2011 04:30 PM, Mahesh Shivhare wrote:

Hi all,

Is there any way by which we can run qemu on android-x86 OS.does qemu needs any 
modification to run on android-x86
I'm trying to build QEMU with --static option but when m trying to run on 
android it's getting stuck with the message

VNC srver running on 127.0.0.1:'
   
It is working fine. You need a vnc viewer to connect to it. Try 
vncviewer 127.0.0.1:.


--
Dushyant



[Qemu-devel] Re: kvm crashes with spice while loading qxl

2011-03-06 Thread Alon Levy
On Sat, Mar 05, 2011 at 01:35:58PM -0300, Marcelo Tosatti wrote:
 On Sat, Feb 26, 2011 at 01:29:01PM +0100, Jan Kiszka wrote:
   at 
   /var/tmp/portage/app-emulation/qemu-kvm-0.14.0/work/qemu-kvm-0.14.0/qemu-kvm.c:1466
   #12 0x777bb944 in start_thread () from /lib/libpthread.so.0
   #13 0x75e491dd in clone () from /lib/libc.so.6
   (gdb)
  
  That's a spice bug. In fact, there are a lot of
  qemu_mutex_lock/unlock_iothread in that subsystem. I bet at least a few
  of them can cause even more subtle problems.
  
  Two general issues with dropping the global mutex like this:
   - The caller of mutex_unlock is responsible for maintaining
 cpu_single_env across the unlocked phase (that's related to the
 abort above).
   - Dropping the lock in the middle of a callback is risky. That may
 enable re-entrances of code sections that weren't designed for this
 (I'm skeptic about the side effects of
 qemu_spice_vm_change_state_handler - why dropping the lock here?).
  
  Spice requires a careful review regarding such issues. Or it should
  pioneer with introducing its own lock so that we can handle at least
  related I/O activities over the VCPUs without holding the global mutex
  (but I bet it's not the simplest candidate for such a new scheme).
  
  Jan
  
 
 Agree with the concern regarding spice.
 

What are the pros and cons of (re)introducing a spice specific lock?
 + simplicity. Only spice touches the spice lock.
 - ? what were the original reasons for Gerd dropping the spice lock?

I have no problem reintroducing this lock, I'm just concerned that it's
wasted effort because after I send that patch someone will jump and remind
me why it was removed in the first place.

 Regarding global mutex, TCG and KVM execution behaviour can become more
 similar wrt locking by dropping qemu_global_mutex during generation and
 execution of TBs.
 
 Of course for memory or PIO accesses from vcpu context qemu_global_mutex
 must be acquired.
 
 With that in place, it becomes easier to justify further improvements
 regarding parallelization, such as using a read-write lock for
 l1_phys_map / phys_page_find_alloc.
 
 
  21.62%   sh3d38920b3f  [.] 0x3d38920b3f  
 
   6.38%   sh  qemu-system-x86_64[.] phys_page_find_alloc  
 
   4.90%   sh  qemu-system-x86_64[.] tb_find_fast  
 
   4.34%   sh  qemu-system-x86_64[.] tlb_flush  
 
 --
 To unsubscribe from this list: send the line unsubscribe kvm in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Qemu-devel] Re: kvm crashes with spice while loading qxl

2011-03-06 Thread Avi Kivity

On 03/05/2011 06:35 PM, Marcelo Tosatti wrote:

Regarding global mutex, TCG and KVM execution behaviour can become more
similar wrt locking by dropping qemu_global_mutex during generation and
execution of TBs.


How can you do that?  During generation, a device can assert the reset 
line, changing cpu modes, or move the memory map.


During execution, tcg accesses memory a lot.  So we'll need to acquire 
qemu_global_mutex for every memory access, and separate protection for TB.


kvm achieves lockless protection by forcing vcpus off and dropping their 
page tables while executing natively, and using srcu while emulating.  
We can do something similar for tcg, but it won't be easy.



Of course for memory or PIO accesses from vcpu context qemu_global_mutex
must be acquired.


Yes, and not just mmio - all memory accesses.


With that in place, it becomes easier to justify further improvements
regarding parallelization, such as using a read-write lock for
l1_phys_map / phys_page_find_alloc.


  21.62%   sh3d38920b3f  [.] 0x3d38920b3f
   6.38%   sh  qemu-system-x86_64[.] phys_page_find_alloc


should be replaced by a memslot list probably


   4.90%   sh  qemu-system-x86_64[.] tb_find_fast
   4.34%   sh  qemu-system-x86_64[.] tlb_flush




--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] [PATCH v20 0/7] usb-ccid

2011-03-06 Thread Alon Levy
Ping.

On Wed, Feb 23, 2011 at 01:20:17PM +0200, Alon Levy wrote:
 This patchset adds three new devices, usb-ccid, ccid-card-passthru and
 ccid-card-emulated, providing a CCID bus, a simple passthru protocol
 implementing card requiring a client, and a standalone emulated card.
 
 It also introduces a new directory libcaccard with CAC card emulation,
 CAC is a type of ISO 7816 smart card.
 
 Tree for pull: git://anongit.freedesktop.org/~alon/qemu usb_ccid.v20
 
 v19-v20 changes:
  * checkpatch.pl. Here are the remaining errors with explanation:
   * ignored 5 macro errors of the type
ERROR: Macros with complex values should be enclosed in parenthesis
because fixing them breaks current code, if it really bothers someone
I can fix it.
* four of them are in libcacard/card_7816t.h:
/* give the subfields a unified look */
..
 #define a_cla a_header-ah_cla /* class */
 #define a_ins a_header-ah_ins /* instruction */
 #define a_p1 a_header-ah_p1   /* parameter 1 */
 #define a_p2 a_header-ah_p2   /* parameter 2 */
* and the fifth:
 #4946: FILE: libcacard/vcardt.h:31:
 +#define VCARD_ATR_PREFIX(size) 0x3b, 0x66+(size), 0x00, 0xff, \
 +   'V', 'C', 'A', 'R', 'D', '_'
   * Ignored this warning since I couldn't figure it out, and it's a test
file:
 WARNING: externs should be avoided in .c files
 #2343: FILE: libcacard/link_test.c:7:
 +VCardStatus cac_card_init(const char *flags, VCard *card,
 
 v18-v19 changes:
  * more merges, down to a single digit number of patches.
  * drop enumeration property, use string.
  * rebased (trivial)
 
 v17-v18 changes:
  * merge vscard_common.h patches.
  * actually provide a tree to pull.
 
 v16-v17 changes:
  * merged all the v15-v16 patches
  * merged some more wherever it was easy (all same file commits).
  * added signed off by to first four patches
  * ccid.h: added copyright, removed underscore in defines, and replaced
  non C89 comments
 
 v15-v16 changes:
  * split vscard_common introducing patch for ease of review
  * sum of commit logs for the v15-v16 commits: (whitespace fixes
 removed for space, see original commit messages in later patches)
   * usb-ccid:
* fix abort on client answer after card remove
* enable migration
* remove side affect code from asserts
* return consistent self-powered state
* mask out reserved bits in ccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
   * vscard_common.h protocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* define VSCARD_MAGIC
* added error code VSC_SUCCESS.
   * ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for 
 indices to buffer
* reset vscard_in indices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicate reader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* send VSC_SUCCESS on card insert/remove and reader add/remove
   * ccid-card-emulated
* fix error reporting in initfn
 
 v14-v15 changes:
  * add patch with --enable-smartcard and --disable-smartcard and only
   disable ccid-card-emulated if nss not found.
  * add patch with description strings
  * s/libcaccard/libcacard/ in docs/ccid.txt
 
 v13-v14 changes:
  - support device_del/device_add on ccid-card-* and usb-ccid
  * usb-ccid:
   * lose card reference when card device deleted
   * check slot number and deny adding a slot if one is already added.
  * ccid-card-*: use qdev_simple_unplug_cb in both emulated and passthru ccid 
 cards,
the exitfn already takes care of triggering card removal in the usb dev.
  * libcacard:
   * remove double include of config-host.mak
   * add replay of card events to libcacard to support second and more 
 emulation
   * don't initialize more then once (doesn't support it right now, so one
thread, NSS thread, is left when device_del is done)
   * add VCARD_EMUL_INIT_ALREADY_INITED
  * ccid-card-emulated:
   * take correct mutexes on signaling to fix deadlocks on device_del
   * allow card insertion/removal event without proper reader insertion event
 
 v12-v13 changes:
  * libcacard:
   * fix Makefile clean to remove vscclient
   * fix double include of config-host in Makefile
  * usb-ccid: remove attach/detach logic, usb is always attached. Guest
   doesn't care if there is a reader attached with no card anyway.
  * ccid-card-passthru: don't close chr_dev on removal, makes it possible
   to use device_del/device_add to create remove/insertion for debugging.
 
 v11-v12 changes:
  * fix out of tree build
 
 v10-v11 changes:
  * fix last patch that removed one of the doc files.
  * updated flow table in docs/ccid.txt
 
 v8-v10 changes:
  * 

Re: [Qemu-devel] Qemu support on android

2011-03-06 Thread Andreas Färber

Hi,

Am 05.03.2011 um 12:00 schrieb Mahesh Shivhare:

I'm trying to build QEMU with --static option but when m trying to  
run on android it's getting stuck with the message


VNC srver running on 127.0.0.1:'


Check configure output. Maybe the SDL headers were not available when  
configuring? It then falls back to VNC.


Regards,
Andreas



[Qemu-devel] [Bug 638955] Re: emulated netcards don't work with recent sunos kernel

2011-03-06 Thread Stefan Hajnoczi
Please test this patch:
http://repo.or.cz/w/qemu/stefanha.git/commitdiff/c405d1b66e045bce1c53a30f9ad840c6f19eca57

QEMU loads checksum offload flags from every tx data descriptor.  When a
multi-descriptor packet is sent, Solaris will only mark the first
descriptor with checksum offload flags.  Therefore QEMU fails to perform
checksum offload resulting in corrupted packets that will be discarded
by the receiver.

I'll try to come up with a proper fix that can be submitted to QEMU.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/638955

Title:
  emulated netcards don't work with recent sunos kernel

Status in QEMU:
  New

Bug description:
  hi there,

  i'm using qemu-kvm backend in version: # qemu-kvm -version
  QEMU PC emulator version 0.12.5 (qemu-kvm-0.12.5), Copyright (c) 2003-2008 
Fabrice Bellard

  and there are just *not working any of model=$type with combinations
  of recent sunos (solaris, openindiana, opensolaris, ..) ..

  you can download for testing purposes iso from here: http://dlc-
  origin.openindiana.org/isos/147/ or from here:
  http://genunix.org/distributions/indiana/  osol and oi are also
  bubuntu-like *live cds, so no need to bother with installing

  behaviour is as follows:
  e1000 - receiving doesn't work, transmitting works .. dladm (tool for handle 
ethers) shows that is all ok, correct mode is loaded up, it just seems like 
this driver works at 100% but ..

  rtl8169|pcnet - works in 10Mbit mode with several other issues like
  high cpu utilization and so .. dladm is unable to recognize options
  for this kind of -nic

  others - just don't work

  .. i experienced this issue several times in past .. woraround was,
  that rtl8169 worked so-so .. with recent sunos kernel it doesn't.

  it's easy to reproduce, this is why i'm not putting here more then
  launching script for my virtual machine:

  # cat openindiana.sh
  qemu-kvm -hda /home/kvm/openindiana/openindiana.img -m 2048 -localtime -cdrom 
/home/kvm/+images/oi-dev-147-x86.iso -boot d \
  -vga std -vnc :9 -k en-us -monitor 
unix:/home/kvm/openindiana/instance,server,nowait \
  -net nic,model=e1000,vlan=1 -net tap,ifname=oi0,script=no,vlan=1 

  sleep 2;
  ip l set oi0 up;
  ip a a 192.168.99.9/24 dev oi0;

  regards by daniel



[Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Herve Poussineau
From: Herv� Poussineau hpous...@reactos.org


Signed-off-by: Herv� Poussineau hpous...@reactos.org
---
 qemu-common.h |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/qemu-common.h b/qemu-common.h
index 40dad52..18e648f 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -33,6 +33,7 @@ typedef struct DeviceState DeviceState;
 #include unistd.h
 #include fcntl.h
 #include sys/stat.h
+#include sys/time.h
 #include assert.h
 
 #ifndef O_LARGEFILE
-- 
1.6.0.2.GIT




Re: [Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Blue Swirl
Thanks, applied.

On Sun, Mar 6, 2011 at 3:23 PM, Herve Poussineau hpous...@reactos.org wrote:
 From: Hervé Poussineau hpous...@reactos.org


 Signed-off-by: Hervé Poussineau hpous...@reactos.org
 ---
  qemu-common.h |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

 diff --git a/qemu-common.h b/qemu-common.h
 index 40dad52..18e648f 100644
 --- a/qemu-common.h
 +++ b/qemu-common.h
 @@ -33,6 +33,7 @@ typedef struct DeviceState DeviceState;
  #include unistd.h
  #include fcntl.h
  #include sys/stat.h
 +#include sys/time.h
  #include assert.h

  #ifndef O_LARGEFILE
 --
 1.6.0.2.GIT






Re: [Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Roy Tam
Hi,

2011/3/6 Herve Poussineau hpous...@reactos.org:

FYI:
[PATCH 1/3] w32: Add new directory hierarchy for MinGW extensions
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56858.html
[PATCH 2/3] w32: Add macro timersub to sys/time.h
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56859.html
[PATCH 3/3] osdep: Remove conditional compilation (fixes w32 compilation)
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56860.html

 From: Hervé Poussineau hpous...@reactos.org


 Signed-off-by: Hervé Poussineau hpous...@reactos.org
 ---
  qemu-common.h |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

 diff --git a/qemu-common.h b/qemu-common.h
 index 40dad52..18e648f 100644
 --- a/qemu-common.h
 +++ b/qemu-common.h
 @@ -33,6 +33,7 @@ typedef struct DeviceState DeviceState;
  #include unistd.h
  #include fcntl.h
  #include sys/stat.h
 +#include sys/time.h
  #include assert.h

  #ifndef O_LARGEFILE
 --
 1.6.0.2.GIT






[Qemu-devel] [PATCH v2] ioport: Improve error output

2011-03-06 Thread Andreas Färber
When failing due to conflicting I/O port registrations,
include the offending I/O port address in the message.

Cc: Aurelien Jarno aurel...@aurel32.net
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 v2:
 * Use for address 0x%x wording, as suggested by Aurelien.
 
 ioport.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/ioport.c b/ioport.c
index aa4188a..2e971fa 100644
--- a/ioport.c
+++ b/ioport.c
@@ -149,7 +149,8 @@ int register_ioport_read(pio_addr_t start, int length, int 
size,
 for(i = start; i  start + length; i += size) {
 ioport_read_table[bsize][i] = func;
 if (ioport_opaque[i] != NULL  ioport_opaque[i] != opaque)
-hw_error(register_ioport_read: invalid opaque);
+hw_error(register_ioport_read: invalid opaque for address 0x%x,
+ i);
 ioport_opaque[i] = opaque;
 }
 return 0;
@@ -168,7 +169,8 @@ int register_ioport_write(pio_addr_t start, int length, int 
size,
 for(i = start; i  start + length; i += size) {
 ioport_write_table[bsize][i] = func;
 if (ioport_opaque[i] != NULL  ioport_opaque[i] != opaque)
-hw_error(register_ioport_write: invalid opaque);
+hw_error(register_ioport_write: invalid opaque for address 0x%x,
+ i);
 ioport_opaque[i] = opaque;
 }
 return 0;
-- 
1.7.3.4




[Qemu-devel] [PATCH] i8254: Fix migration from older versions

2011-03-06 Thread Jan Kiszka
From: Jan Kiszka jan.kis...@siemens.com

qdev conversion broke migration as the previous version used vmstate
instance IDs derived from the iobase. Fix it by registering a legacy
alias.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 hw/i8254.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/i8254.c b/hw/i8254.c
index eaf5d3e..47c9d73 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -520,6 +520,8 @@ static int pit_initfn(ISADevice *dev)
 register_ioport_read(pit-iobase, 3, 1, pit_ioport_read, pit);
 isa_init_ioport(dev, pit-iobase);
 
+qdev_set_legacy_instance_id(dev-qdev, pit-iobase, 2);
+
 return 0;
 }
 
-- 
1.7.1



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Jan Kiszka
On 2011-02-13 22:10, Blue Swirl wrote:
 Convert to qdev. Don't expose PITState.
 

...

 diff --git a/hw/pc.h b/hw/pc.h
 index 60f8c42..feb8a7a 100644
 --- a/hw/pc.h
 +++ b/hw/pc.h
 @@ -82,14 +82,23 @@ void isa_irq_handler(void *opaque, int n, int level);
 
  #define PIT_FREQ 1193182
 
 -typedef struct PITState PITState;
 +static inline ISADevice *pit_init(int base, int irq)
 +{
 +ISADevice *dev;
 +
 +dev = isa_create(isa-pit);
 +qdev_prop_set_uint32(dev-qdev, iobase, base);
 +qdev_prop_set_uint32(dev-qdev, irq, irq);
 +qdev_init_nofail(dev-qdev);
 +
 +return dev;
 +}

This should be moved to i8254.c. We cannot compile the PIT out, and the
above contains no board information. So I see no reason for this inlining.

Jan




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] OVMF Google Summer of Code ideas

2011-03-06 Thread Michal Suchanek
Hello

On 6 March 2011 05:12, Jordan Justen jljus...@gmail.com wrote:
 I know you already have your own ideas to think of. :)
 http://wiki.qemu.org/Google_Summer_of_Code_2011

 But, I am wondering if any of you might have some UEFI or OVMF ideas for us:
 http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=GSOC2011


I would like to see the ability to run x86 on arm.

I think there were some attempts to implement this and an outdated?
support for arm on x86 exists but x86 cannot be emulated on arm so
far.

That said I don't really understand arm so I probably won't be writing
the support myself and can't help much anybody trying to implement it,
at least not anytime soon.

Is there any work going on adding this support?
Would it be suitable for GSoC?

Thanks

Michal



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 5:10 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-02-13 22:10, Blue Swirl wrote:
 Convert to qdev. Don't expose PITState.


 ...

 diff --git a/hw/pc.h b/hw/pc.h
 index 60f8c42..feb8a7a 100644
 --- a/hw/pc.h
 +++ b/hw/pc.h
 @@ -82,14 +82,23 @@ void isa_irq_handler(void *opaque, int n, int level);

  #define PIT_FREQ 1193182

 -typedef struct PITState PITState;
 +static inline ISADevice *pit_init(int base, int irq)
 +{
 +    ISADevice *dev;
 +
 +    dev = isa_create(isa-pit);
 +    qdev_prop_set_uint32(dev-qdev, iobase, base);
 +    qdev_prop_set_uint32(dev-qdev, irq, irq);
 +    qdev_init_nofail(dev-qdev);
 +
 +    return dev;
 +}

 This should be moved to i8254.c. We cannot compile the PIT out, and the
 above contains no board information. So I see no reason for this inlining.

I see no reason for moving this back. In fact, if this was only used
by PC, it could be moved to pc.c.



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Jan Kiszka
On 2011-03-06 16:35, Blue Swirl wrote:
 On Sun, Mar 6, 2011 at 5:10 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-02-13 22:10, Blue Swirl wrote:
 Convert to qdev. Don't expose PITState.


 ...

 diff --git a/hw/pc.h b/hw/pc.h
 index 60f8c42..feb8a7a 100644
 --- a/hw/pc.h
 +++ b/hw/pc.h
 @@ -82,14 +82,23 @@ void isa_irq_handler(void *opaque, int n, int level);

  #define PIT_FREQ 1193182

 -typedef struct PITState PITState;
 +static inline ISADevice *pit_init(int base, int irq)
 +{
 +ISADevice *dev;
 +
 +dev = isa_create(isa-pit);
 +qdev_prop_set_uint32(dev-qdev, iobase, base);
 +qdev_prop_set_uint32(dev-qdev, irq, irq);
 +qdev_init_nofail(dev-qdev);
 +
 +return dev;
 +}

 This should be moved to i8254.c. We cannot compile the PIT out, and the
 above contains no board information. So I see no reason for this inlining.
 
 I see no reason for moving this back. In fact, if this was only used
 by PC, it could be moved to pc.c.

To my understanding, it's a factory helper for the PIT, avoiding
boilerplate code at the creator site. And if we get 1 users, this
cleanup would definitely pay off.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 5:39 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-03-06 16:35, Blue Swirl wrote:
 On Sun, Mar 6, 2011 at 5:10 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-02-13 22:10, Blue Swirl wrote:
 Convert to qdev. Don't expose PITState.


 ...

 diff --git a/hw/pc.h b/hw/pc.h
 index 60f8c42..feb8a7a 100644
 --- a/hw/pc.h
 +++ b/hw/pc.h
 @@ -82,14 +82,23 @@ void isa_irq_handler(void *opaque, int n, int level);

  #define PIT_FREQ 1193182

 -typedef struct PITState PITState;
 +static inline ISADevice *pit_init(int base, int irq)
 +{
 +    ISADevice *dev;
 +
 +    dev = isa_create(isa-pit);
 +    qdev_prop_set_uint32(dev-qdev, iobase, base);
 +    qdev_prop_set_uint32(dev-qdev, irq, irq);
 +    qdev_init_nofail(dev-qdev);
 +
 +    return dev;
 +}

 This should be moved to i8254.c. We cannot compile the PIT out, and the
 above contains no board information. So I see no reason for this inlining.

 I see no reason for moving this back. In fact, if this was only used
 by PC, it could be moved to pc.c.

 To my understanding, it's a factory helper for the PIT, avoiding
 boilerplate code at the creator site. And if we get 1 users, this
 cleanup would definitely pay off.

It should be possible to leave PIT out, with small changes to pcspk
(which obviously has a hard dependency to PIT) and HPET. Then this
makes even more sense.



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Jan Kiszka
On 2011-03-06 17:06, Blue Swirl wrote:
 On Sun, Mar 6, 2011 at 5:39 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-03-06 16:35, Blue Swirl wrote:
 On Sun, Mar 6, 2011 at 5:10 PM, Jan Kiszka jan.kis...@web.de wrote:
 On 2011-02-13 22:10, Blue Swirl wrote:
 Convert to qdev. Don't expose PITState.


 ...

 diff --git a/hw/pc.h b/hw/pc.h
 index 60f8c42..feb8a7a 100644
 --- a/hw/pc.h
 +++ b/hw/pc.h
 @@ -82,14 +82,23 @@ void isa_irq_handler(void *opaque, int n, int level);

  #define PIT_FREQ 1193182

 -typedef struct PITState PITState;
 +static inline ISADevice *pit_init(int base, int irq)
 +{
 +ISADevice *dev;
 +
 +dev = isa_create(isa-pit);
 +qdev_prop_set_uint32(dev-qdev, iobase, base);
 +qdev_prop_set_uint32(dev-qdev, irq, irq);
 +qdev_init_nofail(dev-qdev);
 +
 +return dev;
 +}

 This should be moved to i8254.c. We cannot compile the PIT out, and the
 above contains no board information. So I see no reason for this inlining.

 I see no reason for moving this back. In fact, if this was only used
 by PC, it could be moved to pc.c.

 To my understanding, it's a factory helper for the PIT, avoiding
 boilerplate code at the creator site. And if we get 1 users, this
 cleanup would definitely pay off.
 
 It should be possible to leave PIT out, with small changes to pcspk
 (which obviously has a hard dependency to PIT) and HPET. Then this
 makes even more sense.

A PC without a PIT makes _no_ sense.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Anthony Liguori

On 02/13/2011 03:10 PM, Blue Swirl wrote:

Convert to qdev. Don't expose PITState.

Signed-off-by: Blue Swirlblauwir...@gmail.com
---
  hw/i8254.c |   61 +--
  hw/mips_fulong2e.c |4 +-
  hw/mips_jazz.c |4 +-
  hw/mips_malta.c|4 +-
  hw/mips_r4k.c  |4 +-
  hw/pc.c|5 +--
  hw/pc.h|   25 ++--
  hw/pcspk.c |4 +-
  hw/ppc_prep.c  |4 +-
  9 files changed, 75 insertions(+), 40 deletions(-)

diff --git a/hw/i8254.c b/hw/i8254.c
index 06b225c..680caab 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -53,9 +53,12 @@ typedef struct PITChannelState {
  qemu_irq irq;
  } PITChannelState;

-struct PITState {
+typedef struct PITState {
+ISADevice dev;
   


The PIT is not an ISA device.  Modelling it as such is worse than 
leaving it unmodelled.



-PITState *pit_init(int base, qemu_irq irq);
-void pit_set_gate(PITState *pit, int channel, int val);
-int pit_get_gate(PITState *pit, int channel);
-int pit_get_initial_count(PITState *pit, int channel);
-int pit_get_mode(PITState *pit, int channel);
-int pit_get_out(PITState *pit, int channel, int64_t current_time);
+void pit_set_gate(ISADevice *dev, int channel, int val);
+int pit_get_gate(ISADevice *dev, int channel);
+int pit_get_initial_count(ISADevice *dev, int channel);
+int pit_get_mode(ISADevice *dev, int channel);
+int pit_get_out(ISADevice *dev, int channel, int64_t current_time);
   


Making these functions take an ISADevice hurts type safety.  They should 
take a PITState.


Regards,

Anthony Liguori



Re: [Qemu-devel] [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 6:31 PM, Anthony Liguori anth...@codemonkey.ws wrote:
 On 02/13/2011 03:10 PM, Blue Swirl wrote:

 Convert to qdev. Don't expose PITState.

 Signed-off-by: Blue Swirlblauwir...@gmail.com
 ---
  hw/i8254.c         |   61
 +--
  hw/mips_fulong2e.c |    4 +-
  hw/mips_jazz.c     |    4 +-
  hw/mips_malta.c    |    4 +-
  hw/mips_r4k.c      |    4 +-
  hw/pc.c            |    5 +--
  hw/pc.h            |   25 ++--
  hw/pcspk.c         |    4 +-
  hw/ppc_prep.c      |    4 +-
  9 files changed, 75 insertions(+), 40 deletions(-)

 diff --git a/hw/i8254.c b/hw/i8254.c
 index 06b225c..680caab 100644
 --- a/hw/i8254.c
 +++ b/hw/i8254.c
 @@ -53,9 +53,12 @@ typedef struct PITChannelState {
      qemu_irq irq;
  } PITChannelState;

 -struct PITState {
 +typedef struct PITState {
 +    ISADevice dev;


 The PIT is not an ISA device.  Modelling it as such is worse than leaving it
 unmodelled.

No. These days, PIT is part of Super I/O chip, which is accessed via
LPC bus. LPC is from software point of view equal to ISA. Therefore,
in absence of LPC, ISA is correct.

 -PITState *pit_init(int base, qemu_irq irq);
 -void pit_set_gate(PITState *pit, int channel, int val);
 -int pit_get_gate(PITState *pit, int channel);
 -int pit_get_initial_count(PITState *pit, int channel);
 -int pit_get_mode(PITState *pit, int channel);
 -int pit_get_out(PITState *pit, int channel, int64_t current_time);
 +void pit_set_gate(ISADevice *dev, int channel, int val);
 +int pit_get_gate(ISADevice *dev, int channel);
 +int pit_get_initial_count(ISADevice *dev, int channel);
 +int pit_get_mode(ISADevice *dev, int channel);
 +int pit_get_out(ISADevice *dev, int channel, int64_t current_time);


 Making these functions take an ISADevice hurts type safety.  They should
 take a PITState.

These functions should be removed anyway. For example, pcspk probably
should be merged with i825, or a signal like interface could be used.



[Qemu-devel] [PATCH] e1000: Fix multi-descriptor packet checksum offload

2011-03-06 Thread Stefan Hajnoczi
The PCI/PCI-X Family of Gigabit Ethernet Controllers Software
Developer’s Manual states the following about the POPTS field:

  Provides a number of options which control the handling of this
  packet.  This field is ignored except on the first data descriptor of
  a packet.

The current implementation always loads the field and its checksum
offload flags.  This patch uses only the first descriptor's POPTS field
in order to comply with the specification.

When Solaris sends multi-descriptor packets it fills in POPTS for the
first descriptor only.  Therefore this patch is necessary in order to
perform checksum offload correctly for multi-descriptor packets.

Reported-by: Daniel Pecka dpe...@techniservit.cz
Reported-by: geppz no_carr...@plasmacore.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/e1000.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/e1000.c b/hw/e1000.c
index 0a4574c..2a4d5c7 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -446,7 +446,9 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
 return;
 } else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) {
 // data descriptor
-tp-sum_needed = le32_to_cpu(dp-upper.data)  8;
+if (tp-size == 0) {
+tp-sum_needed = le32_to_cpu(dp-upper.data)  8;
+}
 tp-cptse = ( txd_lower  E1000_TXD_CMD_TSE ) ? 1 : 0;
 } else {
 // legacy descriptor
-- 
1.7.2.3




Re: [Qemu-devel] [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 6:47 PM, Blue Swirl blauwir...@gmail.com wrote:
 On Sun, Mar 6, 2011 at 6:31 PM, Anthony Liguori anth...@codemonkey.ws wrote:
 On 02/13/2011 03:10 PM, Blue Swirl wrote:

 Convert to qdev. Don't expose PITState.

 Signed-off-by: Blue Swirlblauwir...@gmail.com
 ---
  hw/i8254.c         |   61
 +--
  hw/mips_fulong2e.c |    4 +-
  hw/mips_jazz.c     |    4 +-
  hw/mips_malta.c    |    4 +-
  hw/mips_r4k.c      |    4 +-
  hw/pc.c            |    5 +--
  hw/pc.h            |   25 ++--
  hw/pcspk.c         |    4 +-
  hw/ppc_prep.c      |    4 +-
  9 files changed, 75 insertions(+), 40 deletions(-)

 diff --git a/hw/i8254.c b/hw/i8254.c
 index 06b225c..680caab 100644
 --- a/hw/i8254.c
 +++ b/hw/i8254.c
 @@ -53,9 +53,12 @@ typedef struct PITChannelState {
      qemu_irq irq;
  } PITChannelState;

 -struct PITState {
 +typedef struct PITState {
 +    ISADevice dev;


 The PIT is not an ISA device.  Modelling it as such is worse than leaving it
 unmodelled.

 No. These days, PIT is part of Super I/O chip, which is accessed via
 LPC bus. LPC is from software point of view equal to ISA. Therefore,
 in absence of LPC, ISA is correct.

Actually, I could not find any pure Super I/O chips (without south
bridge functionality) which also contained PIT and other legacy
devices, instead most south bridges (with or without a Super I/O)
implement these. Then PIT could be a SysBusDevice, though SysBus does
not know anything about I/O ports. I think ISADevice is not totally
wrong.



Re: [Qemu-devel] [PATCH] lsi53c895a: Update dnad when skipping MSGOUT bytes

2011-03-06 Thread Aurelien Jarno
On Wed, Jan 26, 2011 at 12:31:00PM +, Stefan Hajnoczi wrote:
 Update not only dbc but also dnad when skipping bytes during the MSGOUT
 phase.  Previously only dbc was updated which is probably wrong and
 could lead to bogus message codes being read.
 
 Tested on Linux and Windows Server 2003.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  hw/lsi53c895a.c |   11 +--
  1 files changed, 9 insertions(+), 2 deletions(-)

Thanks, applied.

 diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
 index 9c761cd..84a4992 100644
 --- a/hw/lsi53c895a.c
 +++ b/hw/lsi53c895a.c
 @@ -842,6 +842,13 @@ static uint8_t lsi_get_msgbyte(LSIState *s)
  return data;
  }
  
 +/* Skip the next n bytes during a MSGOUT phase. */
 +static void lsi_skip_msgbytes(LSIState *s, unsigned int n)
 +{
 +s-dnad += n;
 +s-dbc  -= n;
 +}
 +
  static void lsi_do_msgout(LSIState *s)
  {
  uint8_t msg;
 @@ -869,11 +876,11 @@ static void lsi_do_msgout(LSIState *s)
  switch (msg) {
  case 1:
  DPRINTF(SDTR (ignored)\n);
 -s-dbc -= 2;
 +lsi_skip_msgbytes(s, 2);
  break;
  case 3:
  DPRINTF(WDTR (ignored)\n);
 -s-dbc -= 1;
 +lsi_skip_msgbytes(s, 1);
  break;
  default:
  goto bad;
 -- 
 1.7.2.3
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 6/8] kvm: consume internal signal with sigtimedwait

2011-03-06 Thread Andreas Färber

Hello,

Am 22.02.2010 um 22:26 schrieb Marcelo Tosatti:

Change the way the internal qemu signal, used for communication  
between

iothread and vcpus, is handled.

Block and consume it with sigtimedwait on the outer vcpu loop, which
allows more precise timing control.


Mac OS X v10.5 does not seem to support sigtimedwait():

  CCarm-softmmu/cpus.o
/Users/andreas/QEMU/qemu/cpus.c: In function ‘qemu_kvm_eat_signals’:
/Users/andreas/QEMU/qemu/cpus.c:379: warning: implicit declaration of  
function ‘sigtimedwait’
/Users/andreas/QEMU/qemu/cpus.c:379: warning: nested extern  
declaration of ‘sigtimedwait’
/Users/andreas/QEMU/qemu/cpus.c:388: warning: implicit declaration of  
function ‘sigbus_reraise’
/Users/andreas/QEMU/qemu/cpus.c:388: warning: nested extern  
declaration of ‘sigbus_reraise’


Could you please add some #ifdef? It used to be an optional POSIX  
extension.


Thanks,
Andreas


Change from standard signal (SIGUSR1) to real-time one, so multiple
signals are not collapsed.

Set the signal number on KVM's in-kernel allowed sigmask.

Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
Signed-off-by: Avi Kivity a...@redhat.com
---
kvm-all.c |   19 +
kvm.h |1 +
vl.c  |   89 +++ 
+

3 files changed, 97 insertions(+), 12 deletions(-)



diff --git a/vl.c b/vl.c
index af198c1..dc05da3 100644
--- a/vl.c
+++ b/vl.c



@@ -3432,11 +3439,36 @@ static void qemu_wait_io_event(CPUState *env)
qemu_wait_io_event_common(env);
}

+static void qemu_kvm_eat_signal(CPUState *env, int timeout)
+{
+struct timespec ts;
+int r, e;
+siginfo_t siginfo;
+sigset_t waitset;
+
+ts.tv_sec = timeout / 1000;
+ts.tv_nsec = (timeout % 1000) * 100;
+
+sigemptyset(waitset);
+sigaddset(waitset, SIG_IPI);
+
+qemu_mutex_unlock(qemu_global_mutex);
+r = sigtimedwait(waitset, siginfo, ts);
+e = errno;
+qemu_mutex_lock(qemu_global_mutex);
+
+if (r == -1  !(e == EAGAIN || e == EINTR)) {
+fprintf(stderr, sigtimedwait: %s\n, strerror(e));
+exit(1);
+}
+}





Re: [Qemu-devel] [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Anthony Liguori

On 03/06/2011 10:47 AM, Blue Swirl wrote:

The PIT is not an ISA device.  Modelling it as such is worse than leaving it
unmodelled.
 

No. These days, PIT is part of Super I/O chip, which is accessed via
LPC bus. LPC is from software point of view equal to ISA. Therefore,
in absence of LPC, ISA is correct.
   


In the system we model, the PIT is part of the PIIX3.  The right way to 
model it is as a DeviceState that's no_user=1 and created as part of the 
initialized of PIIX3 (for the PC at least).


LPC is still an expansion bus and it's primarily used for discrete 
components like a TPM.  For components that are all part of a Super I/O 
chip, there really just isn't a bus in the middle.



-PITState *pit_init(int base, qemu_irq irq);
-void pit_set_gate(PITState *pit, int channel, int val);
-int pit_get_gate(PITState *pit, int channel);
-int pit_get_initial_count(PITState *pit, int channel);
-int pit_get_mode(PITState *pit, int channel);
-int pit_get_out(PITState *pit, int channel, int64_t current_time);
+void pit_set_gate(ISADevice *dev, int channel, int val);
+int pit_get_gate(ISADevice *dev, int channel);
+int pit_get_initial_count(ISADevice *dev, int channel);
+int pit_get_mode(ISADevice *dev, int channel);
+int pit_get_out(ISADevice *dev, int channel, int64_t current_time);

   

Making these functions take an ISADevice hurts type safety.  They should
take a PITState.
 

These functions should be removed anyway. For example, pcspk probably
should be merged with i825, or a signal like interface could be used.
   


It's tough to do that without doing a real simulation.  The PC speaker 
uses one of the PIT channel outputs to drive its tone output.  But we 
don't want to do something like use a qemu_irq with a timer programmed 
to generate the right frequency wave to drive the tone.


So having the PC speaker hold a reference to the PIT and providing a 
high level method interface makes sense to me.


Regards,

Anthony Liguori





Re: [Qemu-devel] [PATCH] use correct initial region_offset

2011-03-06 Thread Aurelien Jarno
On Thu, Jan 27, 2011 at 01:01:01PM +0200, Alex Rozenman wrote:
 Hi,
 
 I found a bug in phys_page_find_alloc function causing initial region_offset
 field to be set to incorrect initial value.
 Usually, the pages are re-assigned afterwards, so the bug has very small
 effect on regular QEMU users.
 We use memory unassigned callback and this bug causes invalid addresses
 there.
 
 A small patch is attached. I have ssh membership on savannah. Please approve
 and/or push.
 This is my first time when I am suggesting patches to QEMU; I also would
 like to add some fixes for
 ppc440/ppc440x6 cores.
 
 -- 
 Best regards,
 Alex Rozenman (rozen...@gmail.com).

 From 8935358ddf9bf5b80c8b8ac7014b650a519a3ebf Mon Sep 17 00:00:00 2001
 From: Alex Rozenman rozen...@gmail.com
 Date: Thu, 27 Jan 2011 12:47:57 +0200
 Subject: [PATCH] phys_page_find_alloc: use correct initial region_offset
 
 ---
  exec.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)
 
 diff --git a/exec.c b/exec.c
 index db9ff55..00667d7 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -416,6 +416,7 @@ static PhysPageDesc 
 *phys_page_find_alloc(target_phys_addr_t index, int alloc)
  pd = *lp;
  if (pd == NULL) {
  int i;
 +int first_index = index  ~(L2_SIZE - 1);
  
  if (!alloc) {
  return NULL;
 @@ -425,7 +426,7 @@ static PhysPageDesc 
 *phys_page_find_alloc(target_phys_addr_t index, int alloc)
  
  for (i = 0; i  L2_SIZE; i++) {
  pd[i].phys_offset = IO_MEM_UNASSIGNED;
 -pd[i].region_offset = (index + i)  TARGET_PAGE_BITS;
 +pd[i].region_offset = (first_index + i)  TARGET_PAGE_BITS;
  }
  }

The patch looks correct, but it is missing a Signed-off-by: entry. Also
please provide a description in the patch itself.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 0/5] Fix MMC card detection for Realview boards

2011-03-06 Thread Aurelien Jarno
On Mon, Feb 21, 2011 at 08:57:48PM +, Peter Maydell wrote:
 This patchset fixes a number of problems which were preventing
 Linux on Realview boards (EB926, EB 11MPCore, PB-A8 and PBX)
 from recognising the presence of an MMC card. Basically the
 PL181 needs to export some output pins for card status,
 which we can then wire up to both a system register and a
 PL061 GPIO module. However we weren't actually instantiating
 the PL061 and in any case the ID registers weren't correct for
 Linux to detect it.
 
 Combined with the SD card model patch I posted earlier
 (http://patchwork.ozlabs.org/patch/83594/) these patches
 allow Linux on a PBX to detect and mount an SD card rootfs.
 
 (I'm doing this work not for the sake of the realview boards,
 but because it's also mostly necessary for the Versatile Express
 model patchset I'm cleaning up and hope to post shortly.)
 
 Peter Maydell (5):
   hw/pl181: Implement GPIO output pins for card status
   hw/arm_sysctl.c: Wire MCI register MMC card status bits to GPIO inputs
   hw/pl061.c: Implement ARM PL061 as well as Luminary one
   hw/irq: Add qemu_irq_split() so one GPIO output can feed two inputs
   hw/realview: Wire up the MMC card status
 
  hw/arm_sysctl.c |   47 ++-
  hw/irq.c|   15 +++
  hw/irq.h|3 +++
  hw/pl061.c  |   23 +++
  hw/pl181.c  |6 ++
  hw/primecell.h  |4 
  hw/realview.c   |   29 ++---
  hw/stellaris.c  |2 +-
  8 files changed, 120 insertions(+), 9 deletions(-)
 

Thanks all applied.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] simpletrace: Make simpletrace.py a Python module

2011-03-06 Thread Aurelien Jarno
On Tue, Feb 22, 2011 at 01:59:41PM +, Stefan Hajnoczi wrote:
 The simpletrace.py script pretty-prints a binary trace file.  Most of
 the code can be reused by trace file analysis scripts, so turn it into a
 module.
 
 Here is an example script that uses the new simpletrace module:
 
   #!/usr/bin/env python
   # Print virtqueue elements that were never returned to the guest.
 
   import simpletrace
 
   class VirtqueueRequestTracker(simpletrace.Analyzer):
   def __init__(self):
   self.elems = set()
 
   def virtqueue_pop(self, vq, elem, in_num, out_num):
   self.elems.add(elem)
 
   def virtqueue_fill(self, vq, elem, length, idx):
   self.elems.remove(elem)
 
   def end(self):
   for elem in self.elems:
   print hex(elem)
 
   simpletrace.run(VirtqueueRequestTracker())
 
 The simpletrace API is based around the Analyzer class.  Users implement
 an analyzer subclass and add methods for trace events they want to
 process.  A catchall() method is invoked for trace events which do not
 have dedicated methods.  Finally, there are also begin() and end()
 methods like in sed that can be used to perform setup or print
 statistics at the end.
 
 A binary trace file is processed either with:
 
   simpletrace.run(analyzer) # uses command-line args
 
 or with:
 
   simpletrace.process('path/to/trace-events',
   'path/to/trace-file',
   analyzer)
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  scripts/simpletrace.py |  123 
 +++-
  1 files changed, 90 insertions(+), 33 deletions(-)

Thanks, applied.


 diff --git a/scripts/simpletrace.py b/scripts/simpletrace.py
 index 553a727..9fe3dda 100755
 --- a/scripts/simpletrace.py
 +++ b/scripts/simpletrace.py
 @@ -9,9 +9,9 @@
  #
  # For help see docs/tracing.txt
  
 -import sys
  import struct
  import re
 +import inspect
  
  header_event_id = 0x
  header_magic= 0xf2b177cb0aa429b4
 @@ -21,12 +21,8 @@ trace_fmt = '='
  trace_len = struct.calcsize(trace_fmt)
  event_re  = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*')
  
 -def err(msg):
 -sys.stderr.write(msg + '\n')
 -sys.exit(1)
 -
  def parse_events(fobj):
 -Parse a trace-events file.
 +Parse a trace-events file into {event_num: (name, arg1, ...)}.
  
  def get_argnames(args):
  Extract argument names from a parameter list.
 @@ -45,20 +41,20 @@ def parse_events(fobj):
  return events
  
  def read_record(fobj):
 -Deserialize a trace record from a file.
 +Deserialize a trace record from a file into a tuple (event_num, 
 timestamp, arg1, ..., arg6).
  s = fobj.read(trace_len)
  if len(s) != trace_len:
  return None
  return struct.unpack(trace_fmt, s)
  
  def read_trace_file(fobj):
 -Deserialize trace records from a file.
 +Deserialize trace records from a file, yielding record tuples 
 (event_num, timestamp, arg1, ..., arg6).
  header = read_record(fobj)
  if header is None or \
 header[0] != header_event_id or \
 header[1] != header_magic or \
 header[2] != header_version:
 -err('not a trace file or incompatible version')
 +raise ValueError('not a trace file or incompatible version')
  
  while True:
  rec = read_record(fobj)
 @@ -67,27 +63,88 @@ def read_trace_file(fobj):
  
  yield rec
  
 -class Formatter(object):
 -def __init__(self, events):
 -self.events = events
 -self.last_timestamp = None
 -
 -def format_record(self, rec):
 -if self.last_timestamp is None:
 -self.last_timestamp = rec[1]
 -delta_ns = rec[1] - self.last_timestamp
 -self.last_timestamp = rec[1]
 -
 -event = self.events[rec[0]]
 -fields = [event[0], '%0.3f' % (delta_ns / 1000.0)]
 -for i in xrange(1, len(event)):
 -fields.append('%s=0x%x' % (event[i], rec[i + 1]))
 -return ' '.join(fields)
 -
 -if len(sys.argv) != 3:
 -err('usage: %s trace-events trace-file' % sys.argv[0])
 -
 -events = parse_events(open(sys.argv[1], 'r'))
 -formatter = Formatter(events)
 -for rec in read_trace_file(open(sys.argv[2], 'rb')):
 -print formatter.format_record(rec)
 +class Analyzer(object):
 +A trace file analyzer which processes trace records.
 +
 +An analyzer can be passed to run() or process().  The begin() method is
 +invoked, then each trace record is processed, and finally the end() 
 method
 +is invoked.
 +
 +If a method matching a trace event name exists, it is invoked to process
 +that trace record.  Otherwise the catchall() method is invoked.
 +
 +def begin(self):
 +Called at the start of the trace.
 +pass
 +
 +def catchall(self, event, rec):
 +Called if no specific method for processing a trace event has 
 been found.
 +pass
 +
 +def end(self):
 

[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Jan Kiszka
On 2011-03-06 18:47, Anthony Liguori wrote:
 On 03/06/2011 10:47 AM, Blue Swirl wrote:
 The PIT is not an ISA device.  Modelling it as such is worse than
 leaving it
 unmodelled.
  
 No. These days, PIT is part of Super I/O chip, which is accessed via
 LPC bus. LPC is from software point of view equal to ISA. Therefore,
 in absence of LPC, ISA is correct.

 
 In the system we model, the PIT is part of the PIIX3.  The right way to
 model it is as a DeviceState that's no_user=1 and created as part of the
 initialized of PIIX3 (for the PC at least).
 
 LPC is still an expansion bus and it's primarily used for discrete
 components like a TPM.  For components that are all part of a Super I/O
 chip, there really just isn't a bus in the middle.

There surely is some bus (or even multiple), just not external an one.

Most of the currently ISA-attached devices are chipset internal. They
belong to the PIIX3, so they need to be attached to some bus that is
owned by this device. If that is its ISA bus or a separate one for
internal devices - really, this looks like an academic discussion to me.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH] linux-user: Fix large seeks by 32 bit guest on 64 bit host

2011-03-06 Thread Aurelien Jarno
On Tue, Feb 22, 2011 at 01:02:26PM +, Peter Maydell wrote:
 When emulating a 32 bit Linux user-mode program on a 64 bit target
 we implement the llseek syscall in terms of lseek. Correct a bug
 which meant we were silently casting the result of host lseek()
 to a 32 bit integer as it passed through get_errno() and thus
 throwing away the top half.
 
 We also don't try to store the result back to userspace unless
 the seek succeeded; this matches the kernel behaviour.
 
 Thanks to Eoghan Sherry for identifying the problem and suggesting
 a solution.
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  linux-user/syscall.c |   16 ++--
  1 files changed, 10 insertions(+), 6 deletions(-)

Thanks, applied.

 diff --git a/linux-user/syscall.c b/linux-user/syscall.c
 index cf8a4c3..23d7a63 100644
 --- a/linux-user/syscall.c
 +++ b/linux-user/syscall.c
 @@ -6127,16 +6127,20 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
 arg1,
  #ifdef TARGET_NR__llseek /* Not on alpha */
  case TARGET_NR__llseek:
  {
 +int64_t res;
  #if !defined(__NR_llseek)
 -ret = get_errno(lseek(arg1, ((uint64_t )arg2  32) | arg3, 
 arg5));
 -if (put_user_s64(ret, arg4))
 -goto efault;
 +res = lseek(arg1, ((uint64_t)arg2  32) | arg3, arg5);
 +if (res == -1) {
 +ret = get_errno(res);
 +} else {
 +ret = 0;
 +}
  #else
 -int64_t res;
  ret = get_errno(_llseek(arg1, arg2, arg3, res, arg5));
 -if (put_user_s64(res, arg4))
 -goto efault;
  #endif
 +if ((ret == 0)  put_user_s64(res, arg4)) {
 +goto efault;
 +}
  }
  break;
  #endif
 -- 
 1.7.1
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] docs: Update stderr and simple backend, add systemtap backend

2011-03-06 Thread Aurelien Jarno
On Wed, Feb 23, 2011 at 02:00:21PM +, Stefan Hajnoczi wrote:
 The following additions to the tracing documentation are included:
 
 1. Move stderr backend documentation to top-level and out of simple
backend.  Include hints on when this backend is useful.
 
 2. Document the simple backend thread-safety limitation.
 
 3. Document the dtrace backend for SystemTap.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  docs/tracing.txt |   30 ++
  1 files changed, 26 insertions(+), 4 deletions(-)

Thanks, applied.

 diff --git a/docs/tracing.txt b/docs/tracing.txt
 index 21183f9..a6cc56f 100644
 --- a/docs/tracing.txt
 +++ b/docs/tracing.txt
 @@ -126,6 +126,14 @@ The nop backend generates empty trace event functions 
 so that the compiler
  can optimize out trace events completely.  This is the default and imposes no
  performance penalty.
  
 +=== Stderr ===
 +
 +The stderr backend sends trace events directly to standard error.  This
 +effectively turns trace events into debug printfs.
 +
 +This is the simplest backend and can be used together with existing code that
 +uses DPRINTF().
 +
  === Simpletrace ===
  
  The simple backend supports common use cases and comes as part of the QEMU
 @@ -133,10 +141,10 @@ source tree.  It may not be as powerful as 
 platform-specific or third-party
  trace backends but it is portable.  This is the recommended trace backend
  unless you have specific needs for more advanced backends.
  
 -=== Stderr ===
 -
 -The stderr backend sends trace events directly to standard error output
 -during emulation.
 +Warning: the simple backend is not thread-safe so only enable trace events
 +that are executed while the global mutex is held.  Much of QEMU meets this
 +requirement but some utility functions like qemu_malloc() or thread-related
 +code cannot be safely traced using the simple backend.
  
   Monitor commands 
  
 @@ -187,3 +195,17 @@ consistent.
  The ust backend uses the LTTng Userspace Tracer library.  There are no
  monitor commands built into QEMU, instead UST utilities should be used to 
 list,
  enable/disable, and dump traces.
 +
 +=== SystemTap ===
 +
 +The dtrace backend uses DTrace sdt probes but has only been tested with
 +SystemTap.  When SystemTap support is detected a .stp file with wrapper 
 probes
 +is generated to make use in scripts more convenient.  This step can also be
 +performed manually after a build in order to change the binary name in the 
 .stp
 +probes:
 +
 +scripts/tracetool --dtrace --stap \
 +  --binary path/to/qemu-binary \
 +  --target-type system \
 +  --target-arch x86_64 \
 +  trace-events qemu.stp
 -- 
 1.7.2.3
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 0/3] tcg: Support debugging leakage of temporaries

2011-03-06 Thread Aurelien Jarno
On Wed, Feb 23, 2011 at 03:19:33PM +, Peter Maydell wrote:
 This patchset removes the ad-hoc debug code in target-arm for
 identifying cases where we leaked TCG temporary variables, in
 favour of an implementation in tcg itself.
 
 Generally any temporaries created by a target while it is
 translating an instruction should be freed by the end of that
 instruction; otherwise carefully crafted guest code could cause
 TCG to run out of temporaries and assert.
 
 Putting the leak-debugging code into TCG proper (a) makes more
 sense as this isn't at all arm-specific (b) makes it more
 comprehensive, as it now covers temporaries created in all ways,
 not just via the new_tmp()/dead_tmp() wrapper functions
 (c) avoids annoying false positives where eg a TCG temp created
 with tcg_const_i32() was passed to dead_tmp().
 
 The tracking only happens if qemu was configured with
 --enable-debug-tcg. It should be easy to add to other targets if
 desired; it's just a matter of calling tcg_clear_temp_count()
 and tcg_check_temp_count() in the appropriate places.
 
 Peter Maydell (3):
   tcg: Add support for debugging leakage of temporaries
   target-arm: Remove ad-hoc leak checking code
   target-arm: Use TCG temporary leak debugging facilities
 
  target-arm/translate.c |  705 +++
  tcg/tcg.c  |   32 +++
  tcg/tcg.h  |   17 ++
  3 files changed, 394 insertions(+), 360 deletions(-)
 

I am basically fine with this patch series modulo the small comment you
made about patch 1. My only concern is that, given ARM code is quite
sensitive to this kind of issue (there is no real rule if the caller or
the callee should free the temp), that we forget to enable TCG debug to
validate a patch. On the other hand I fully agree that this kind of
check should not be done in production use.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 2/2 V1] Fixed EPROM for AMD driver compatibility under DOS with Netware driver

2011-03-06 Thread Andreas Färber

Am 05.03.2011 um 13:48 schrieb Gerhard Wiesinger:

For newbies for documentation how to submit a qemu patch made of  
several commits (updated for necessary signoff):


# Last commit before patch
git branch pcnet-amd-fix 1899e4afdc2d838be5625539df9c87cca49bdd70
git checkout pcnet-amd-fix


# Or in short:
git checkout -b pcnet-amd-fix 1899e4afdc2d838be5625539df9c87cca49bdd70


git merge --squash master
git commit -a -F - EOF
hw/pcnet.c: Fix EPROM contents to suit AMD netware drivers

bugfix under DOS for AMD netware driver:
AMD PCNTNW Ethernet MLID v3.10 (960115), network card not found

bugfix works well under DOS with:
1.) AMD NDIS driver v2.0.1
2.) AMD PCNTNW Ethernet MLID v3.10 (960115)
3.) Knoppix 6.2
EOF
# Signoff must be added
git format-patch -s master
git checkout master



For the record, another possible way is:

git rebase -i HEAD^^^ # rebase the last three commits:
# edit the last two lines to start with fixup (or squash)
# if you chose squash, you'll be able to edit the message immediately
git commit --amend -s # to add the SoB and edit the message if you  
didn't before

git format-patch HEAD^

Andreas



Re: [Qemu-devel] [PATCH] net: Use iov helper functions

2011-03-06 Thread Aurelien Jarno
On Wed, Feb 23, 2011 at 07:57:21PM -0500, Benjamin Poirier wrote:
 Signed-off-by: Benjamin Poirier benjamin.poir...@gmail.com
 ---
  net.c |   28 ++--
  1 files changed, 6 insertions(+), 22 deletions(-)

Thanks, applied.

 diff --git a/net.c b/net.c
 index ec4745d..15ed40b 100644
 --- a/net.c
 +++ b/net.c
 @@ -36,6 +36,7 @@
  #include qemu-common.h
  #include qemu_socket.h
  #include hw/qdev.h
 +#include iov.h
  
  static QTAILQ_HEAD(, VLANState) vlans;
  static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
 @@ -572,30 +573,13 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, 
 const struct iovec *iov,
 int iovcnt)
  {
  uint8_t buffer[4096];
 -size_t offset = 0;
 -int i;
 -
 -for (i = 0; i  iovcnt; i++) {
 -size_t len;
 +size_t offset;
  
 -len = MIN(sizeof(buffer) - offset, iov[i].iov_len);
 -memcpy(buffer + offset, iov[i].iov_base, len);
 -offset += len;
 -}
 +offset = iov_to_buf(iov, iovcnt, buffer, 0, sizeof(buffer));
  
  return vc-info-receive(vc, buffer, offset);
  }
  
 -static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
 -{
 -size_t offset = 0;
 -int i;
 -
 -for (i = 0; i  iovcnt; i++)
 -offset += iov[i].iov_len;
 -return offset;
 -}
 -
  static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
 unsigned flags,
 const struct iovec *iov,
 @@ -605,7 +589,7 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState 
 *sender,
  VLANClientState *vc = opaque;
  
  if (vc-link_down) {
 -return calc_iov_length(iov, iovcnt);
 +return iov_size(iov, iovcnt);
  }
  
  if (vc-info-receive_iov) {
 @@ -633,7 +617,7 @@ static ssize_t 
 qemu_vlan_deliver_packet_iov(VLANClientState *sender,
  }
  
  if (vc-link_down) {
 -ret = calc_iov_length(iov, iovcnt);
 +ret = iov_size(iov, iovcnt);
  continue;
  }
  
 @@ -658,7 +642,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *sender,
  NetQueue *queue;
  
  if (sender-link_down || (!sender-peer  !sender-vlan)) {
 -return calc_iov_length(iov, iovcnt);
 +return iov_size(iov, iovcnt);
  }
  
  if (sender-peer) {
 -- 
 1.7.2.3
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [PATCH] Implement qemu_kvm_eat_signals only for CONFIG_LINUX

2011-03-06 Thread Jan Kiszka
On 2011-03-06 18:46, Andreas Färber wrote:
 Hello,
 
 Am 22.02.2010 um 22:26 schrieb Marcelo Tosatti:
 
 Change the way the internal qemu signal, used for communication between
 iothread and vcpus, is handled.

 Block and consume it with sigtimedwait on the outer vcpu loop, which
 allows more precise timing control.
 
 Mac OS X v10.5 does not seem to support sigtimedwait():
 
   CCarm-softmmu/cpus.o
 /Users/andreas/QEMU/qemu/cpus.c: In function ‘qemu_kvm_eat_signals’:
 /Users/andreas/QEMU/qemu/cpus.c:379: warning: implicit declaration of
 function ‘sigtimedwait’
 /Users/andreas/QEMU/qemu/cpus.c:379: warning: nested extern declaration
 of ‘sigtimedwait’
 /Users/andreas/QEMU/qemu/cpus.c:388: warning: implicit declaration of
 function ‘sigbus_reraise’
 /Users/andreas/QEMU/qemu/cpus.c:388: warning: nested extern declaration
 of ‘sigbus_reraise’
 
 Could you please add some #ifdef? It used to be an optional POSIX
 extension.

This should fix it.

Jan

--8---

From: Jan Kiszka jan.kis...@siemens.com

qemu_kvm_eat_signals requires POSIX support with realtime extensions for
sigtimedwait. Not all our target platforms provide this.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---
 cpus.c |   94 
 1 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/cpus.c b/cpus.c
index 94af696..a10559d 100644
--- a/cpus.c
+++ b/cpus.c
@@ -235,11 +235,58 @@ static void qemu_init_sigbus(void)
 prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
 }
 
+static void qemu_kvm_eat_signals(CPUState *env)
+{
+struct timespec ts = { 0, 0 };
+siginfo_t siginfo;
+sigset_t waitset;
+sigset_t chkset;
+int r;
+
+sigemptyset(waitset);
+sigaddset(waitset, SIG_IPI);
+sigaddset(waitset, SIGBUS);
+
+do {
+r = sigtimedwait(waitset, siginfo, ts);
+if (r == -1  !(errno == EAGAIN || errno == EINTR)) {
+perror(sigtimedwait);
+exit(1);
+}
+
+switch (r) {
+case SIGBUS:
+if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
+sigbus_reraise();
+}
+break;
+default:
+break;
+}
+
+r = sigpending(chkset);
+if (r == -1) {
+perror(sigpending);
+exit(1);
+}
+} while (sigismember(chkset, SIG_IPI) || sigismember(chkset, SIGBUS));
+
+#ifndef CONFIG_IOTHREAD
+if (sigismember(chkset, SIGIO) || sigismember(chkset, SIGALRM)) {
+qemu_notify_event();
+}
+#endif
+}
+
 #else /* !CONFIG_LINUX */
 
 static void qemu_init_sigbus(void)
 {
 }
+
+static void qemu_kvm_eat_signals(CPUState *env)
+{
+}
 #endif /* !CONFIG_LINUX */
 
 #ifndef _WIN32
@@ -364,49 +411,6 @@ static int qemu_signalfd_init(sigset_t mask)
 return 0;
 }
 
-static void qemu_kvm_eat_signals(CPUState *env)
-{
-struct timespec ts = { 0, 0 };
-siginfo_t siginfo;
-sigset_t waitset;
-sigset_t chkset;
-int r;
-
-sigemptyset(waitset);
-sigaddset(waitset, SIG_IPI);
-sigaddset(waitset, SIGBUS);
-
-do {
-r = sigtimedwait(waitset, siginfo, ts);
-if (r == -1  !(errno == EAGAIN || errno == EINTR)) {
-perror(sigtimedwait);
-exit(1);
-}
-
-switch (r) {
-case SIGBUS:
-if (kvm_on_sigbus_vcpu(env, siginfo.si_code, siginfo.si_addr)) {
-sigbus_reraise();
-}
-break;
-default:
-break;
-}
-
-r = sigpending(chkset);
-if (r == -1) {
-perror(sigpending);
-exit(1);
-}
-} while (sigismember(chkset, SIG_IPI) || sigismember(chkset, SIGBUS));
-
-#ifndef CONFIG_IOTHREAD
-if (sigismember(chkset, SIGIO) || sigismember(chkset, SIGALRM)) {
-qemu_notify_event();
-}
-#endif
-}
-
 #else /* _WIN32 */
 
 HANDLE qemu_event_handle;
@@ -434,10 +438,6 @@ static void qemu_event_increment(void)
 exit (1);
 }
 }
-
-static void qemu_kvm_eat_signals(CPUState *env)
-{
-}
 #endif /* _WIN32 */
 
 #ifndef CONFIG_IOTHREAD



Re: [Qemu-devel] [PATCH] net: remove parse_host_src_port() function

2011-03-06 Thread Aurelien Jarno
On Thu, Feb 24, 2011 at 12:22:10PM +0100, Juan Quintela wrote:
 It was deprecated, and it has no users.
 
 Signed-off-by: Juan Quintela quint...@redhat.com
 ---
  net.c |   41 -
  qemu_socket.h |3 ---
  2 files changed, 0 insertions(+), 44 deletions(-)

Thanks, applied.

 diff --git a/net.c b/net.c
 index ec4745d..4c3e083 100644
 --- a/net.c
 +++ b/net.c
 @@ -93,47 +93,6 @@ static int get_str_sep(char *buf, int buf_size, const char 
 **pp, int sep)
  return 0;
  }
 
 -int parse_host_src_port(struct sockaddr_in *haddr,
 -struct sockaddr_in *saddr,
 -const char *input_str)
 -{
 -char *str = qemu_strdup(input_str);
 -char *host_str = str;
 -char *src_str;
 -const char *src_str2;
 -char *ptr;
 -
 -/*
 - * Chop off any extra arguments at the end of the string which
 - * would start with a comma, then fill in the src port information
 - * if it was provided else use the any address and any port.
 - */
 -if ((ptr = strchr(str,',')))
 -*ptr = '\0';
 -
 -if ((src_str = strchr(input_str,'@'))) {
 -*src_str = '\0';
 -src_str++;
 -}
 -
 -if (parse_host_port(haddr, host_str)  0)
 -goto fail;
 -
 -src_str2 = src_str;
 -if (!src_str || *src_str == '\0')
 -src_str2 = :0;
 -
 -if (parse_host_port(saddr, src_str2)  0)
 -goto fail;
 -
 -free(str);
 -return(0);
 -
 -fail:
 -free(str);
 -return -1;
 -}
 -
  int parse_host_port(struct sockaddr_in *saddr, const char *str)
  {
  char buf[512];
 diff --git a/qemu_socket.h b/qemu_socket.h
 index 897a8ae..180e4db 100644
 --- a/qemu_socket.h
 +++ b/qemu_socket.h
 @@ -54,9 +54,6 @@ int unix_connect(const char *path);
 
  /* Old, ipv4 only bits.  Don't use for new code. */
  int parse_host_port(struct sockaddr_in *saddr, const char *str);
 -int parse_host_src_port(struct sockaddr_in *haddr,
 -struct sockaddr_in *saddr,
 -const char *str);
  int socket_init(void);
 
  #endif /* QEMU_SOCKET_H */
 -- 
 1.7.4
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 0/3] Remove wrong savevm sections

2011-03-06 Thread Aurelien Jarno
On Thu, Feb 24, 2011 at 03:17:13PM +0100, Juan Quintela wrote:
 Hi
 
 This devices savevm support is Not Even Wrong.  Just remove it.
 It has never work for sure.
 
 Anthony, please apply.
 
 Later, Juan.
 
 Juan Quintela (3):
   vmstate: remove grackle_pci savevm code
   vmstate: remove uninorth savevm code
   gt64xxx: remove savevm support
 
  hw/grackle_pci.c |   19 ---
  hw/gt64xxx.c |   21 -
  hw/unin_pci.c|   21 -
  3 files changed, 0 insertions(+), 61 deletions(-)
 

Thanks, all applied.


-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] net: Add the missing option declaration of vhostforce

2011-03-06 Thread Aurelien Jarno
On Fri, Feb 25, 2011 at 04:11:27PM +0800, Jason Wang wrote:
 Signed-off-by: Jason Wang jasow...@redhat.com
 ---
  net.c |6 +-
  1 files changed, 5 insertions(+), 1 deletions(-)
 
 diff --git a/net.c b/net.c
 index 9ba5be2..21d4443 100644
 --- a/net.c
 +++ b/net.c
 @@ -1025,7 +1025,11 @@ static const struct {
  .name = vhostfd,
  .type = QEMU_OPT_STRING,
  .help = file descriptor of an already opened vhost net 
 device,
 -},
 +}, {
 +.name = vhostforce,
 +.type = QEMU_OPT_BOOL,
 +.help = force vhost on for non-MSIX virtio guests,
 +},
  #endif /* _WIN32 */
  { /* end of list */ }
  },
 

Thanks, applied to HEAD and stable-0.14

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] target-arm: Don't decode old cp15 WFI instructions on v7 cores

2011-03-06 Thread Aurelien Jarno
On Fri, Feb 25, 2011 at 03:04:12PM +, Peter Maydell wrote:
 In v7 of the ARM architecture, WFI (wait for interrupt) is a first-class
 instruction, but in previous versions this functionality was provided
 via a cp15 coprocessor register. Add correct feature checks to the
 decoding of the cp15 WFI instructions so that they behave correctly
 for newer cores. In particular, the old 0,c7,c8,2 encoding used on
 ARM940 has been reused for VA-to-PA translation in v6 and v7.
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
 This patch stands alone as a fix to target-arm; it's a prerequisite
 for Adam's VA-PA translation patch, because otherwise attempting a
 user-read translation will get you a WFI instead...
 
  target-arm/translate.c |   35 ++-
  1 files changed, 30 insertions(+), 5 deletions(-)

Thanks, applied.

 diff --git a/target-arm/translate.c b/target-arm/translate.c
 index dbd958b..baa1256 100644
 --- a/target-arm/translate.c
 +++ b/target-arm/translate.c
 @@ -2538,13 +2538,38 @@ static int disas_cp15_insn(CPUState *env, 
 DisasContext *s, uint32_t insn)
  if (IS_USER(s)  !cp15_user_ok(insn)) {
  return 1;
  }
 -if ((insn  0x0fff0fff) == 0x0e070f90
 -|| (insn  0x0fff0fff) == 0x0e070f58) {
 -/* Wait for interrupt.  */
 -gen_set_pc_im(s-pc);
 -s-is_jmp = DISAS_WFI;
 +
 +/* Pre-v7 versions of the architecture implemented WFI via coprocessor
 + * instructions rather than a separate instruction.
 + */
 +if ((insn  0x0fff0fff) == 0x0e070f90) {
 +/* 0,c7,c0,4: Standard v6 WFI (also used in some pre-v6 cores).
 + * In v7, this must NOP.
 + */
 +if (!arm_feature(env, ARM_FEATURE_V7)) {
 +/* Wait for interrupt.  */
 +gen_set_pc_im(s-pc);
 +s-is_jmp = DISAS_WFI;
 +}
  return 0;
  }
 +
 +if ((insn  0x0fff0fff) == 0x0e070f58) {
 +/* 0,c7,c8,2: Not all pre-v6 cores implemented this WFI,
 + * so this is slightly over-broad.
 + */
 +if (!arm_feature(env, ARM_FEATURE_V6)) {
 +/* Wait for interrupt.  */
 +gen_set_pc_im(s-pc);
 +s-is_jmp = DISAS_WFI;
 +return 0;
 +}
 +/* Otherwise fall through to handle via helper function.
 + * In particular, on v7 and some v6 cores this is one of
 + * the VA-PA registers.
 + */
 +}
 +
  rd = (insn  12)  0xf;
  
  if (cp15_tls_load_store(env, s, insn, rd))
 -- 
 1.7.1
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] w32: Add support for curses

2011-03-06 Thread Aurelien Jarno
On Sun, Feb 27, 2011 at 08:23:30PM +0100, Stefan Weil wrote:
 MinGW optionally includes pdcurses, so add support for it.
 
 Signed-off-by: Stefan Weil w...@mail.berlios.de
 ---
  configure |6 +-
  1 files changed, 5 insertions(+), 1 deletions(-)

Thanks, applied.

 diff --git a/configure b/configure
 index 47779b6..ca15632 100755
 --- a/configure
 +++ b/configure
 @@ -1562,7 +1562,11 @@ fi
  
  ##
  # curses probe
 -curses_list=-lncurses -lcurses
 +if test $mingw32 = yes ; then
 +curses_list=-lpdcurses
 +else
 +curses_list=-lncurses -lcurses
 +fi
  
  if test $curses != no ; then
curses_found=no
 -- 
 1.7.2.3
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Stefan Weil

Am 06.03.2011 15:24, schrieb Roy Tam:

Hi,

2011/3/6 Herve Poussineauhpous...@reactos.org:

FYI:
[PATCH 1/3] w32: Add new directory hierarchy for MinGW extensions
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56858.html
[PATCH 2/3] w32: Add macro timersub to sys/time.h
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56859.html
[PATCH 3/3] osdep: Remove conditional compilation (fixes w32 compilation)
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56860.html


Yes, this patch series also addresses the same problem (and one more)
in a better way: it did not add code, but removed a conditional compilation.
(my first try was identical to Herve's patch).

Stefan


From: Hervé Poussineauhpous...@reactos.org


Signed-off-by: Hervé Poussineauhpous...@reactos.org
---
  qemu-common.h |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/qemu-common.h b/qemu-common.h
index 40dad52..18e648f 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -33,6 +33,7 @@ typedef struct DeviceState DeviceState;
  #includeunistd.h
  #includefcntl.h
  #includesys/stat.h
+#includesys/time.h
  #includeassert.h

  #ifndef O_LARGEFILE
--
1.6.0.2.GIT








Re: [Qemu-devel] [PATCH v5] PING: Fix ATA SMART and CHECK POWER MODE

2011-03-06 Thread Aurelien Jarno
You should Cc: the IDE maintainer (Kevin Wolf) so that this patch can 
get acked. Done with this mail.

On Tue, Mar 01, 2011 at 08:30:23AM -0500, Brian Wheeler wrote:
 This patch fixes two things:
  
  1) CHECK POWER MODE
  
 The error return value wasn't always zero, so it would show up as
 offline.  Error is now explicitly set to zero.
  
  2) SMART
  
 The smart values that were returned were invalid and tools like skdump
 would not recognize that the smart data was actually valid and would
 dump weird output.  The data has been fixed up and raw value support
 was added.  Tools like skdump and palimpsest work as expected.
 
 v5 changes:  rebase
 v4 changes:  incorporate changes from Ryan Harper
 v3 changes:  don't reformat code I didn't change
 v2 changes:  use single structure instead of one for thresholds and one
 for data.
 
 Signed-off-by: bdwhe...@indiana.edu
 
 diff --git a/hw/ide/core.c b/hw/ide/core.c
 index 9c91a49..1ffca56 100644
 --- a/hw/ide/core.c
 +++ b/hw/ide/core.c
 @@ -34,13 +34,26 @@
  
  #include hw/ide/internal.h
  
 -static const int smart_attributes[][5] = {
 -/* id,  flags, val, wrst, thrsh */
 -{ 0x01, 0x03, 0x64, 0x64, 0x06}, /* raw read */
 -{ 0x03, 0x03, 0x64, 0x64, 0x46}, /* spin up */
 -{ 0x04, 0x02, 0x64, 0x64, 0x14}, /* start stop count */
 -{ 0x05, 0x03, 0x64, 0x64, 0x36}, /* remapped sectors */
 -{ 0x00, 0x00, 0x00, 0x00, 0x00}
 +/* These values were based on a Seagate ST3500418AS but have been modified
 +   to make more sense in QEMU */
 +static const int smart_attributes[][12] = {
 +/* id,  flags, hflags, val, wrst, raw (6 bytes), threshold */
 +/* raw read error rate*/
 +{ 0x01, 0x03, 0x00, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x06},
 +/* spin up */
 +{ 0x03, 0x03, 0x00, 0x64, 0x64, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x00},
 +/* start stop count */
 +{ 0x04, 0x02, 0x00, 0x64, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x14},
 +/* remapped sectors */
 +{ 0x05, 0x03, 0x00, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x24},
 +/* power on hours */
 +{ 0x09, 0x03, 0x00, 0x64, 0x64, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x00},
 +/* power cycle count */
 +{ 0x0c, 0x03, 0x00, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
 0x00},
 +/* airflow-temperature-celsius */
 +{ 190,  0x03, 0x00, 0x45, 0x45, 0x1f, 0x00, 0x1f, 0x1f, 0x00, 0x00, 
 0x32},
 +/* end of list */
 +{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  };
  
  /* XXX: DVDs that could fit on a CD will be reported as a CD */
 @@ -1843,6 +1856,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
  break;
  case WIN_CHECKPOWERMODE1:
  case WIN_CHECKPOWERMODE2:
 +s-error = 0;
  s-nsector = 0xff; /* device active or idle */
  s-status = READY_STAT | SEEK_STAT;
  ide_set_irq(s-bus);
 @@ -2097,7 +2111,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
   if (smart_attributes[n][0] == 0)
   break;
   s-io_buffer[2+0+(n*12)] = smart_attributes[n][0];
 - s-io_buffer[2+1+(n*12)] = smart_attributes[n][4];
 + s-io_buffer[2+1+(n*12)] = smart_attributes[n][11];
   }
   for (n=0; n511; n++) /* checksum */
   s-io_buffer[511] += s-io_buffer[n];
 @@ -2110,12 +2124,13 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
   memset(s-io_buffer, 0, 0x200);
   s-io_buffer[0] = 0x01; /* smart struct version */
   for (n=0; n30; n++) {
 - if (smart_attributes[n][0] == 0)
 + if (smart_attributes[n][0] == 0) {
   break;
 - s-io_buffer[2+0+(n*12)] = smart_attributes[n][0];
 - s-io_buffer[2+1+(n*12)] = smart_attributes[n][1];
 - s-io_buffer[2+3+(n*12)] = smart_attributes[n][2];
 - s-io_buffer[2+4+(n*12)] = smart_attributes[n][3];
 + }
 + int i;
 + for(i = 0; i  11; i++) {
 + s-io_buffer[2+i+(n*12)] = smart_attributes[n][i];
 + }
   }
   s-io_buffer[362] = 0x02 | (s-smart_autosave?0x80:0x00);
   if (s-smart_selftest_count == 0) {
 
 
 
 
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] Re: EFI console stopped working in Qemu 0.14.0

2011-03-06 Thread vagran


Hey, can you tell me about $PHOBOS_PREFIX/share/qemu/phobos64?  Does
it have an alternative vgabios-cirrus.bin?  Is the contents of this
directory available publicly?

I have followed the instructions How to run OVMF. This directory has
the contents of OVMF package - OVMF.fd and vgabios-cirrus.bin which
is renamed CirrusLogic5446.rom. Also it has pxe-e1000.bin copied from
$PHOBOS_PREFIX/share/qemu.

Can you try disabling KVM?
  

Yes, it helped. Problem exists only when using KVM. Thanks.

Best regards,
Artyom.

Jordan Justen wrote:

On Sun, Mar 6, 2011 at 02:10, vagran vagran@gmail.com wrote:
  

And launched:
qemu-system-x86_64 -L $PHOBOS_PREFIX/share/qemu/phobos64 -bios OVMF.fd -m
768 -cpu core2duo
-vga cirrus -monitor stdio -serial tcp::666,server -s -hdb
$PHOBOS_PREFIX/share/qemu/phobos.disk -usb -enable-kvm



Hey, can you tell me about $PHOBOS_PREFIX/share/qemu/phobos64?  Does
it have an alternative vgabios-cirrus.bin?  Is the contents of this
directory available publicly?

Does it work if you follow these steps?
https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=How_to_run_OVMF

Can you try disabling KVM?

If you try the -d in_asm option (while KVM is disabled), do you see
the reset loop happen in the /tmp/qemu.log file?

Thanks for your time,

-Jordan
  


[Qemu-devel] [PATCH] moving eeprom initialization

2011-03-06 Thread William Dauchy
The initialization should not be only on reset but also when initializing
the device.
It resolves a bug when hot plugging a pci network device: the mac address
was always null.

Signed-off-by: William Dauchy wdau...@gmail.com
Signed-off-by: Wen Congyang we...@cn.fujitsu.com
---
 hw/pcnet.c   |   59 +
 hw/rtl8139.c |   23 ++---
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/hw/pcnet.c b/hw/pcnet.c
index 6dfdcc4..d3d5661 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1557,35 +1557,6 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap)
 void pcnet_h_reset(void *opaque)
 {
 PCNetState *s = opaque;
-int i;
-uint16_t checksum;
-
-/* Initialize the PROM */
-
-/*
-  Datasheet: http://pdfdata.datasheetsite.com/web/24528/AM79C970A.pdf
-  page 95
-*/
-memcpy(s-prom, s-conf.macaddr.a, 6);
-/* Reserved Location: must be 00h */
-s-prom[6] = s-prom[7] = 0x00;
-/* Reserved Location: must be 00h */
-s-prom[8] = 0x00;
-/* Hardware ID: must be 11h if compatibility to AMD drivers is desired */
-s-prom[9] = 0x11;
-/* User programmable space, init with 0 */
-s-prom[10] = s-prom[11] = 0x00;
-/* LSByte of two-byte checksum, which is the sum of bytes 00h-0Bh
-   and bytes 0Eh and 0Fh, must therefore be initialized with 0! */
-s-prom[12] = s-prom[13] = 0x00;
-/* Must be ASCII W (57h) if compatibility to AMD
-   driver software is desired */
-s-prom[14] = s-prom[15] = 0x57;
-
-for (i = 0,checksum = 0; i  16; i++)
-checksum += s-prom[i];
-*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
-
 
 s-bcr[BCR_MSRDA] = 0x0005;
 s-bcr[BCR_MSWRA] = 0x0005;
@@ -1752,6 +1723,9 @@ void pcnet_common_cleanup(PCNetState *d)
 
 int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 {
+int i;
+uint16_t checksum;
+
 s-poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
 qemu_macaddr_default_if_unset(s-conf.macaddr);
@@ -1760,5 +1734,32 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, 
NetClientInfo *info)
 
 add_boot_device_path(s-conf.bootindex, dev, /ethernet-phy@0);
 
+/* Initialize the PROM */
+
+/*
+  Datasheet: http://pdfdata.datasheetsite.com/web/24528/AM79C970A.pdf
+  page 95
+*/
+memcpy(s-prom, s-conf.macaddr.a, 6);
+/* Reserved Location: must be 00h */
+s-prom[6] = s-prom[7] = 0x00;
+/* Reserved Location: must be 00h */
+s-prom[8] = 0x00;
+/* Hardware ID: must be 11h if compatibility to AMD drivers is desired */
+s-prom[9] = 0x11;
+/* User programmable space, init with 0 */
+s-prom[10] = s-prom[11] = 0x00;
+/* LSByte of two-byte checksum, which is the sum of bytes 00h-0Bh
+   and bytes 0Eh and 0Fh, must therefore be initialized with 0! */
+s-prom[12] = s-prom[13] = 0x00;
+/* Must be ASCII W (57h) if compatibility to AMD
+   driver software is desired */
+s-prom[14] = s-prom[15] = 0x57;
+
+for (i = 0, checksum = 0; i  16; i++) {
+checksum += s-prom[i];
+}
+*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
+
 return 0;
 }
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index a22530c..7a87522 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -1189,18 +1189,6 @@ static void rtl8139_reset(DeviceState *d)
 
 rtl8139_update_irq(s);
 
-/* prepare eeprom */
-s-eeprom.contents[0] = 0x8129;
-#if 1
-// PCI vendor and device ID should be mirrored here
-s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
-s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
-#endif
-
-s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
-s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
-s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
-
 /* mark all status registers as owned by host */
 for (i = 0; i  4; ++i)
 {
@@ -3392,6 +3380,17 @@ static int pci_rtl8139_init(PCIDevice *dev)
 
 qemu_macaddr_default_if_unset(s-conf.macaddr);
 
+/* prepare eeprom */
+s-eeprom.contents[0] = 0x8129;
+#if 1
+/* PCI vendor and device ID should be mirrored here */
+s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
+s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
+#endif
+s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
+s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
+s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
+
 s-nic = qemu_new_nic(net_rtl8139_info, s-conf,
   dev-qdev.info-name, dev-qdev.id, s);
 qemu_format_nic_info_str(s-nic-nc, s-conf.macaddr.a);
-- 
1.7.2.3




Re: [Qemu-devel] [PATCH 0/3] tcg: Support debugging leakage of temporaries

2011-03-06 Thread Peter Maydell
On 6 March 2011 18:18, Aurelien Jarno aurel...@aurel32.net wrote:
 On Wed, Feb 23, 2011 at 03:19:33PM +, Peter Maydell wrote:
 This patchset removes the ad-hoc debug code in target-arm for
 identifying cases where we leaked TCG temporary variables, in
 favour of an implementation in tcg itself.

 I am basically fine with this patch series modulo the small comment you
 made about patch 1.

Thanks; I've sent a v2 which fixes that nit.

 My only concern is that, given ARM code is quite
 sensitive to this kind of issue (there is no real rule if the caller or
 the callee should free the temp), that we forget to enable TCG debug to
 validate a patch. On the other hand I fully agree that this kind of
 check should not be done in production use.

In the long term it would be good if we could make the ARM translate.c
less brittle like this. Can we at least define a rule for where we're
trying to get to so we can move in the right direction for new code?

My suggestion would be that we should say that for gen_* functions
the callee should always have to free temps passed in as arguments.
This matches the convention for tcg_gen_$OP() and gen_helper_$WHATEVER().

-- PMM



Re: [Qemu-devel] [PATCH 2/3] w32: Add macro timersub to sys/time.h

2011-03-06 Thread Stefan Weil

Am 05.03.2011 10:34, schrieb Blue Swirl:

On Sun, Feb 27, 2011 at 7:52 PM, Stefan Weil w...@mail.berlios.de wrote:

timersub is needed by the latest vnc code.

Signed-off-by: Stefan Weil w...@mail.berlios.de
---
 hosts/w32/include/sys/time.h |   24 
 1 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 hosts/w32/include/sys/time.h

diff --git a/hosts/w32/include/sys/time.h b/hosts/w32/include/sys/time.h
new file mode 100644
index 000..94056ff
--- /dev/null
+++ b/hosts/w32/include/sys/time.h


Nack. The QEMU way of handling host peculiarities is to add wrappers,
for example qemu_timersub in this case, and converting all callers.


That's one way how things can be handled.

I know at least one QEMU maintainer who does not like
those workarounds, especially if they are needed because
of w32/w64 operating systems, so I decided to choose
a different approach here. My approach also can be easily
removed as soon as MinGW is improved (I'm sure it will
be improved).

There is another QEMU way of handling host peculiarities:
conditional compilation. Most of this kind of handling
could be eliminated by my approach.




@@ -0,0 +1,24 @@
+/*
+ * Extensions of MinGW sys/time.h
+ *
+ * Copyright (C) 2011 Stefan Weil
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 
2.1 or later.

+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include_next sys/time.h


Isn't include_next an extension by GCC?


It is, but that's not critical given the fact that QEMU does not
work without gcc.

If needed, this dependency can be fixed easily by renaming
the intermediate include files (and including the renamed files).

I don't think that those intermediate files will be needed
forever, so a clean and cheap solution like the one which
I implemented seems to be more important to me.




+
+#ifndef timersub
+/* This is a copy from GNU C Library (GNU LGPL 2.1), sys/time.h. */
+# define timersub(a, b, result) 
  \
+  do {   
 \
+(result)-tv_sec = (a)-tv_sec - (b)-tv_sec;   
  \
+(result)-tv_usec = (a)-tv_usec - (b)-tv_usec; 
 \
+if ((result)-tv_usec  0) { 
 \
+  --(result)-tv_sec;   
  \
+  (result)-tv_usec += 100; 
  \
+}   
  \

+  } while (0)
+#endif
--
1.7.2.3


By the way: it's not possible to add timersub to existing files like
oslib-win32.c or os-win32.c (another way to handle the problem)
because of incompatible licenses.

Regards,
Stefan W.




[Qemu-devel] [PATCH v3 3/3] target-arm: Use TCG temporary leak debugging facilities

2011-03-06 Thread Peter Maydell
Use the new TCG temporary leak debugging facilities to
check that each ARM instruction does not leak temporaries.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 target-arm/translate.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index c8cbb9c..f9bb573 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -9150,6 +9150,8 @@ static inline void 
gen_intermediate_code_internal(CPUState *env,
 
 gen_icount_start();
 
+tcg_clear_temp_count();
+
 /* A note on handling of the condexec (IT) bits:
  *
  * We want to avoid the overhead of having to write the updated condexec
@@ -9259,6 +9261,11 @@ static inline void 
gen_intermediate_code_internal(CPUState *env,
 gen_set_label(dc-condlabel);
 dc-condjmp = 0;
 }
+
+if (tcg_check_temp_count()) {
+fprintf(stderr, TCG temporary leak before %08x\n, dc-pc);
+}
+
 /* Translation stops when a conditional branch is encountered.
  * Otherwise the subsequent code could get translated several times.
  * Also stop translation when a page boundary is reached.  This
-- 
1.7.1




[Qemu-devel] [PATCH v2 0/3] tcg: Support debugging leakage of temporaries

2011-03-06 Thread Peter Maydell
This patchset removes the ad-hoc debug code in target-arm for
identifying cases where we leaked TCG temporary variables, in
favour of an implementation in tcg itself.

Generally any temporaries created by a target while it is
translating an instruction should be freed by the end of that
instruction; otherwise carefully crafted guest code could cause
TCG to run out of temporaries and assert.

Putting the leak-debugging code into TCG proper (a) makes more
sense as this isn't at all arm-specific (b) makes it more
comprehensive, as it now covers temporaries created in all ways,
not just via the new_tmp()/dead_tmp() wrapper functions
(c) avoids annoying false positives where eg a TCG temp created
with tcg_const_i32() was passed to dead_tmp().

The tracking only happens if qemu was configured with
--enable-debug-tcg. It should be easy to add to other targets if
desired; it's just a matter of calling tcg_clear_temp_count()
and tcg_check_temp_count() in the appropriate places.

Changes since v1:
 use do { } while (0) for the non-debug version of the
 tcg_clear_temp_count() macro to avoid creating empty statements

Peter Maydell (3):
  tcg: Add support for debugging leakage of temporaries
  target-arm: Remove ad-hoc leak checking code
  target-arm: Use TCG temporary leak debugging facilities

 target-arm/translate.c |  705 +++
 tcg/tcg.c  |   32 +++
 tcg/tcg.h  |   17 ++
 3 files changed, 394 insertions(+), 360 deletions(-)




[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 10:45 PM, Anthony Liguori anth...@codemonkey.ws wrote:
 On 03/06/2011 12:06 PM, Jan Kiszka wrote:

 In the system we model, the PIT is part of the PIIX3.  The right way to
 model it is as a DeviceState that's no_user=1 and created as part of the
 initialized of PIIX3 (for the PC at least).

 LPC is still an expansion bus and it's primarily used for discrete
 components like a TPM.  For components that are all part of a Super I/O
 chip, there really just isn't a bus in the middle.


 There surely is some bus (or even multiple), just not external an one.


 It almost doesn't matter.  It would look like:

 I8254 is-a DeviceState

 SuperIO has-a I8254

 And the has-a relationship might be some custom bus mechanism (even if it's
 purely a VHDL or software concept).

 But in terms of modelling, we make I8254 a DeviceState because we don't care
 what bus it sits on.

Southbridge (+Super I/O) provides an ISA bus, partially internal and
external (LPC). i8254 is one of those devices, so calling it an
ISADevice is not completely wrong.

 Most of the currently ISA-attached devices are chipset internal.

 Yeah, and making them ISA devices was the wrong thing to do.  This is all
 going to have to be redone in the not too distant future.

I don't think the recent discussion about device models was very
conclusive. Maybe patches would clarify.

 An is-a relationship only makes sense when the device is naturally
 represented as the parent object.

  They
 belong to the PIIX3, so they need to be attached to some bus that is
 owned by this device. If that is its ISA bus or a separate one for
 internal devices - really, this looks like an academic discussion to me.


 It's far from academic as this is user-visible and visible via the command
 line.

Currently the device tree looks like this (extracted from 'info qtree' output):
bus: main-system-bus
  type System
  dev: i440FX-pcihost, id 
irq 0
bus: pci.0
  type PCI
  dev: PIIX3, id 
class ISA bridge, addr 00:01.0, pci id 8086:7000 (sub 1af4:1100)
bus: isa.0
  type ISA
  dev: isa-pit, id 
dev-prop: irq = 0
dev-prop: iobase = 0x40

I don't think this is completely wrong. 'isa-pit' device is in fact
part of PIIX3 and that is not visible. The tree should probably
reflect that somehow (for example, name the device PIIX3-isa-pit).



[Qemu-devel] Re: [PATCH v2] target-arm: Set carry flag correctly for Thumb2 ORNS

2011-03-06 Thread Aurelien Jarno
On Sun, Mar 06, 2011 at 08:32:09PM +, Peter Maydell wrote:
 The code for Thumb2 ORNS (or negated and set flags) was trashing
 a TCG input register which was needed later for use in calculating
 flags, with the effect that the carry flag was always set with
 the wrong sense. Fix this by using the TCG orc op instead of
 separate not and or ops.
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
 Change from v1: use orc as suggested by Aurelien
 
  target-arm/translate.c |3 +--
  1 files changed, 1 insertions(+), 2 deletions(-)

Thanks, applied.

 diff --git a/target-arm/translate.c b/target-arm/translate.c
 index dbd958b..dd56ac6 100644
 --- a/target-arm/translate.c
 +++ b/target-arm/translate.c
 @@ -7326,8 +7326,7 @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, 
 uint32_t shifter_out, TCG
  logic_cc = conds;
  break;
  case 3: /* orn */
 -tcg_gen_not_i32(t1, t1);
 -tcg_gen_or_i32(t0, t0, t1);
 +tcg_gen_orc_i32(t0, t0, t1);
  logic_cc = conds;
  break;
  case 4: /* eor */
 -- 
 1.7.1
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Stefan Weil

Am 06.03.2011 21:25, schrieb Blue Swirl:

On Sun, Mar 6, 2011 at 9:24 PM, Stefan Weilw...@mail.berlios.de  wrote:

Am 06.03.2011 15:24, schrieb Roy Tam:

Hi,

2011/3/6 Herve Poussineauhpous...@reactos.org:

FYI:
[PATCH 1/3] w32: Add new directory hierarchy for MinGW extensions
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56858.html
[PATCH 2/3] w32: Add macro timersub to sys/time.h
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56859.html
[PATCH 3/3] osdep: Remove conditional compilation (fixes w32 compilation)
http://www.mail-archive.com/qemu-devel@nongnu.org/msg56860.html

Yes, this patch series also addresses the same problem (and one more)
in a better way: it did not add code, but removed a conditional compilation.
(my first try was identical to Herve's patch).

As I replied to those, there are several problems with your approach.
Wrapping timersub() would solve the other problem nicely.

If we'd want to fake a POSIX-like programming environment, there are
other approaches like gnulib. But so far, the approach has been using
wrappers.


Obviously I missed your reply, but I just read it.

Patch 3/3 does not conflict with your intension.

It is still a better solution to include sys/time.h
and can be applied independent of the other
two patches.




Re: [Qemu-devel] [PATCH] target-arm: Handle VMOV between two core and VFP single regs

2011-03-06 Thread Aurelien Jarno
On Tue, Mar 01, 2011 at 05:35:19PM +, Peter Maydell wrote:
 Fix two bugs in the translation of the instructions VMOV sa,sb,rx,ry and
 VMOV rx,ry,sa,sb (which copy between a pair of ARM core registers and a
 pair of VFP single precision registers):
 
  * An incorrect condition meant these instruction patterns were being
treated as load/store multiple, which resulted in the generation
of bad code and a runtime segfault
  * The order of the core register pair was reversed so the values would
go to the wrong registers
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  target-arm/translate.c |   10 +-
  1 files changed, 5 insertions(+), 5 deletions(-)

Thanks, applied.

 diff --git a/target-arm/translate.c b/target-arm/translate.c
 index dbd958b..0111a61 100644
 --- a/target-arm/translate.c
 +++ b/target-arm/translate.c
 @@ -3232,7 +3232,7 @@ static int disas_vfp_insn(CPUState * env, DisasContext 
 *s, uint32_t insn)
  break;
  case 0xc:
  case 0xd:
 -if (dp  (insn  0x03e0) == 0x0040) {
 +if ((insn  0x03e0) == 0x0040) {
  /* two-register transfer */
  rn = (insn  16)  0xf;
  rd = (insn  12)  0xf;
 @@ -3254,10 +3254,10 @@ static int disas_vfp_insn(CPUState * env, 
 DisasContext *s, uint32_t insn)
  } else {
  gen_mov_F0_vreg(0, rm);
  tmp = gen_vfp_mrs();
 -store_reg(s, rn, tmp);
 +store_reg(s, rd, tmp);
  gen_mov_F0_vreg(0, rm + 1);
  tmp = gen_vfp_mrs();
 -store_reg(s, rd, tmp);
 +store_reg(s, rn, tmp);
  }
  } else {
  /* arm-vfp */
 @@ -3269,10 +3269,10 @@ static int disas_vfp_insn(CPUState * env, 
 DisasContext *s, uint32_t insn)
  gen_vfp_msr(tmp);
  gen_mov_vreg_F0(0, rm * 2 + 1);
  } else {
 -tmp = load_reg(s, rn);
 +tmp = load_reg(s, rd);
  gen_vfp_msr(tmp);
  gen_mov_vreg_F0(0, rm);
 -tmp = load_reg(s, rd);
 +tmp = load_reg(s, rn);
  gen_vfp_msr(tmp);
  gen_mov_vreg_F0(0, rm + 1);
  }
 -- 
 1.7.1
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 00/17 v3] LatticeMico32 target

2011-03-06 Thread Michael Walle
Am Dienstag 01 März 2011, 22:31:58 schrieb Edgar E. Iglesias:
 On Fri, Feb 25, 2011 at 12:03:37AM +0100, Michael Walle wrote:
  Am Donnerstag 17 Februar 2011, 23:45:01 schrieb Michael Walle:
   This patchset adds support for the LatticeMico32 softcore processor by
   Lattice Semiconductor.
   
   Changes since v2:
- lots of CODING_STYLE fixes
- reworked pic and juart model, CPUState is not passed anymore
- use qdev reset field instead of qemu_register_reset()
- add missing include guards
- merged lm32_pic_cpu.c into boards file
- removed buggy qemu_irq_lower() in reset functions
- converted hw_error to error_report()
   
   Changes since v1:
- removed variables which are no longer in use
- replaced some tcg ops with specialized ones
- kill VM in case of an unknown opcode
- fixed tracepoints format strings to match existing ones
  
  Any comments/reviews on this patchset?
  
  I've changed the opcode decoding to use a lookup table instead of the
  for- loop. If you don't mind, i would submit a patch after the above is
  merged. Or, alternatively, if there is another patchset version, i'll
  integrate it into that ;)
 
 Hi, lets do v3 first.
 
 Do you have a public tree to pull from?
My git repository is at:
http://git.serverraum.org/git/mw/qemu-lm32.git/

There i create a tag 'for-upstream-v3' which contains the patchset rebased on 
the latest official HEAD.

HTH, Michael



Re: [Qemu-devel] [PATCH] target-arm: Set carry flag correctly for Thumb2 ORNS

2011-03-06 Thread Aurelien Jarno
On Wed, Mar 02, 2011 at 05:34:08PM +, Peter Maydell wrote:
 The code for Thumb2 ORNS (or negated and set flags) was trashing
 a TCG input register which was needed later for use in calculating
 flags, with the effect that the carry flag was always set with
 the wrong sense. Fix this by using a TCG temporary instead.
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  target-arm/translate.c |   11 +--
  1 files changed, 9 insertions(+), 2 deletions(-)
 
 diff --git a/target-arm/translate.c b/target-arm/translate.c
 index dbd958b..8f4e16b 100644
 --- a/target-arm/translate.c
 +++ b/target-arm/translate.c
 @@ -7326,10 +7326,17 @@ gen_thumb2_data_op(DisasContext *s, int op, int 
 conds, uint32_t shifter_out, TCG
  logic_cc = conds;
  break;
  case 3: /* orn */
 -tcg_gen_not_i32(t1, t1);
 -tcg_gen_or_i32(t0, t0, t1);
 +{
 +/* We can't just invert t1 in place because we might need it
 + * to calculate the carry flag later.
 + */
 +TCGv tmp = tcg_temp_new_i32();
 +tcg_gen_not_i32(tmp, t1);
 +tcg_gen_or_i32(t0, t0, tmp);
 +tcg_temp_free_i32(tmp);

You may want to use tcg_gen_orc_i32() instead, which as a bonus might be
implemented directly on some hosts (currently ia64, powerpc and sparc).

  logic_cc = conds;
  break;
 +}
  case 4: /* eor */
  tcg_gen_xor_i32(t0, t0, t1);
  logic_cc = conds;
 -- 
 1.7.1
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH v3] tracetool: Add optional argument to specify dtrace probe names

2011-03-06 Thread Aurelien Jarno
On Thu, Feb 17, 2011 at 01:26:05PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Optional feature allowing a user to generate the probe list to match
 the name of the binary, in case they wish to install qemu under a
 different name than qemu-{system,user},arch
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  scripts/tracetool |   19 +--
  1 files changed, 13 insertions(+), 6 deletions(-)

Thanks, applied.

 diff --git a/scripts/tracetool b/scripts/tracetool
 index e046683..412f695 100755
 --- a/scripts/tracetool
 +++ b/scripts/tracetool
 @@ -30,9 +30,11 @@ Output formats:
--stap Generate .stp file (DTrace with SystemTAP only)
  
  Options:
 -  --binary  [path]  Full path to QEMU binary
 -  --target-arch [arch]  QEMU emulator target arch
 -  --target-type [type]  QEMU emulator target type ('system' or 'user')
 +  --binary   [path]Full path to QEMU binary
 +  --target-arch  [arch]QEMU emulator target arch
 +  --target-type  [type]QEMU emulator target type ('system' or 'user')
 +  --probe-prefix [prefix]  Prefix for dtrace probe names
 +   (default: qemu-\$targettype-\$targetarch)
  
  EOF
  exit 1
 @@ -472,7 +474,7 @@ linetostap_dtrace()
  
  # Define prototype for probe arguments
  cat EOF
 -probe qemu.$targettype.$targetarch.$name = process($binary).mark($name)
 +probe $probeprefix.$name = process($binary).mark($name)
  {
  EOF
  
 @@ -574,14 +576,17 @@ tracetostap()
 echo --binary is required for SystemTAP tapset generator
 exit 1
  fi
 -if [ -z $targettype ]; then
 +if [ -z $probeprefix -a -z $targettype ]; then
 echo --target-type is required for SystemTAP tapset generator
 exit 1
  fi
 -if [ -z $targetarch ]; then
 +if [ -z $probeprefix -a -z $targetarch ]; then
 echo --target-arch is required for SystemTAP tapset generator
 exit 1
  fi
 +if [ -z $probeprefix ]; then
 + probeprefix=qemu.$targettype.$targetarch;
 +fi
  echo /* This file is autogenerated by tracetool, do not edit. */
  convert stap
  }
 @@ -592,6 +597,7 @@ output=
  binary=
  targettype=
  targetarch=
 +probeprefix=
  
  
  until [ -z $1 ]
 @@ -602,6 +608,7 @@ do
  --binary) shift ; binary=$1 ;;
  --target-arch) shift ; targetarch=$1 ;;
  --target-type) shift ; targettype=$1 ;;
 +--probe-prefix) shift ; probeprefix=$1 ;;
  
  -h | -c | -d) output=${1#-} ;;
  --stap) output=${1#--} ;;
 -- 
 1.7.4
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [PATCH v2 1/3] tcg: Add support for debugging leakage of temporaries

2011-03-06 Thread Peter Maydell
Add support (if CONFIG_DEBUG_TCG is defined) for debugging leakage
of temporary variables. Generally any temporaries created by
a target while it is translating an instruction should be freed
by the end of that instruction; otherwise carefully crafted
guest code could cause TCG to run out of temporaries and assert.
By calling tcg_check_temp_count() after each instruction we can
check that we are not leaking temporaries in this way.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 tcg/tcg.c |   32 
 tcg/tcg.h |   17 +
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 5dd6a2c..8748c05 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -450,6 +450,10 @@ static inline int tcg_temp_new_internal(TCGType type, int 
temp_local)
 s-nb_temps++;
 }
 }
+
+#if defined(CONFIG_DEBUG_TCG)
+s-temps_in_use++;
+#endif
 return idx;
 }
 
@@ -475,6 +479,13 @@ static inline void tcg_temp_free_internal(int idx)
 TCGTemp *ts;
 int k;
 
+#if defined(CONFIG_DEBUG_TCG)
+s-temps_in_use--;
+if (s-temps_in_use  0) {
+fprintf(stderr, More temporaries freed than allocated!\n);
+}
+#endif
+
 assert(idx = s-nb_globals  idx  s-nb_temps);
 ts = s-temps[idx];
 assert(ts-temp_allocated != 0);
@@ -528,6 +539,27 @@ TCGv_i64 tcg_const_local_i64(int64_t val)
 return t0;
 }
 
+#if defined(CONFIG_DEBUG_TCG)
+void tcg_clear_temp_count(void)
+{
+TCGContext *s = tcg_ctx;
+s-temps_in_use = 0;
+}
+
+int tcg_check_temp_count(void)
+{
+TCGContext *s = tcg_ctx;
+if (s-temps_in_use) {
+/* Clear the count so that we don't give another
+ * warning immediately next time around.
+ */
+s-temps_in_use = 0;
+return 1;
+}
+return 0;
+}
+#endif
+
 void tcg_register_helper(void *func, const char *name)
 {
 TCGContext *s = tcg_ctx;
diff --git a/tcg/tcg.h b/tcg/tcg.h
index e1afde2..3fab8d6 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -323,6 +323,10 @@ struct TCGContext {
 int64_t restore_count;
 int64_t restore_time;
 #endif
+
+#ifdef CONFIG_DEBUG_TCG
+int temps_in_use;
+#endif
 };
 
 extern TCGContext tcg_ctx;
@@ -392,6 +396,19 @@ static inline TCGv_i64 tcg_temp_local_new_i64(void)
 void tcg_temp_free_i64(TCGv_i64 arg);
 char *tcg_get_arg_str_i64(TCGContext *s, char *buf, int buf_size, TCGv_i64 
arg);
 
+#if defined(CONFIG_DEBUG_TCG)
+/* If you call tcg_clear_temp_count() at the start of a section of
+ * code which is not supposed to leak any TCG temporaries, then
+ * calling tcg_check_temp_count() at the end of the section will
+ * return 1 if the section did in fact leak a temporary.
+ */
+void tcg_clear_temp_count(void);
+int tcg_check_temp_count(void);
+#else
+#define tcg_clear_temp_count() do { } while (0)
+#define tcg_check_temp_count() 0
+#endif
+
 void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf);
 
 #define TCG_CT_ALIAS  0x80
-- 
1.7.1




Re: [Qemu-devel] OVMF Google Summer of Code ideas

2011-03-06 Thread Jordan Justen
On Sun, Mar 6, 2011 at 07:29, Michal Suchanek hramr...@centrum.cz wrote:
 On 6 March 2011 05:12, Jordan Justen jljus...@gmail.com wrote:
 I know you already have your own ideas to think of. :)
 http://wiki.qemu.org/Google_Summer_of_Code_2011

 But, I am wondering if any of you might have some UEFI or OVMF ideas for us:
 http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=GSOC2011

 I would like to see the ability to run x86 on arm.

Hi.  Was this an idea for the qemu project and GSoC?

In this thread I was trying to get GSoC ideas related to a separate
(but qemu dependent) project:
https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=OVMF

Sorry for the confusion.  I think another thread previously discussed
qemu GSoC ideas.

-Jordan



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Anthony Liguori

On 03/06/2011 12:06 PM, Jan Kiszka wrote:

In the system we model, the PIT is part of the PIIX3.  The right way to
model it is as a DeviceState that's no_user=1 and created as part of the
initialized of PIIX3 (for the PC at least).

LPC is still an expansion bus and it's primarily used for discrete
components like a TPM.  For components that are all part of a Super I/O
chip, there really just isn't a bus in the middle.
 

There surely is some bus (or even multiple), just not external an one.
   


It almost doesn't matter.  It would look like:

I8254 is-a DeviceState

SuperIO has-a I8254

And the has-a relationship might be some custom bus mechanism (even if 
it's purely a VHDL or software concept).


But in terms of modelling, we make I8254 a DeviceState because we don't 
care what bus it sits on.



Most of the currently ISA-attached devices are chipset internal.


Yeah, and making them ISA devices was the wrong thing to do.  This is 
all going to have to be redone in the not too distant future.


An is-a relationship only makes sense when the device is naturally 
represented as the parent object.



  They
belong to the PIIX3, so they need to be attached to some bus that is
owned by this device. If that is its ISA bus or a separate one for
internal devices - really, this looks like an academic discussion to me.
   


It's far from academic as this is user-visible and visible via the 
command line.


Regards,

Anthony Liguori


Jan

   





[Qemu-devel] QAPI Merge Plans

2011-03-06 Thread Anthony Liguori

Hi,

I've gotten my QAPI branch now functionally complete so I'm ready to 
start working on merging.  I thought I'd send a note about my plans as 
both a heads up and to see if anyone had any suggestions.


My plan is to split everything up into three rounds.  The first round 
will just be core infrastructure--the code generator, the new QMP 
server, the signal infrastructure, etc.  This round will introduce a new 
command line option to expose the new QMP server (still chardev based).


Round two will consist of all of the 0.14 commands.  Some new commands 
are also needed because some of the 0.14 commands are untestable without 
new QMP commands :-/


Finally, round three will include some of the new and potentially 
controversial bits like the new non-chardev based QMP server, default 
session and discovery, qsh tool, etc.


After these three rounds are merged, I'll then work on adding all of the 
new QMP commands to support a full HMP session.


I've tried to put a ton of information on the wiki that hopefully will 
give a good amount of background along with current status.


I expect the first round of patches to be on list this week.

http://wiki.qemu.org/Features/QAPI

Regards,

Anthony Liguori



[Qemu-devel] [PATCH] moving eeprom initialization

2011-03-06 Thread William Dauchy
The initialization should not be only on reset but also when initializing
the device.
It resolves a bug when hot plugging a pci network device: the mac address
was always null.

Signed-off-by: William Dauchy wdau...@gmail.com
Signed-off-by: Wen Congyang we...@cn.fujitsu.com
---
 hw/pcnet.c   |   27 ++-
 hw/rtl8139.c |   24 
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/hw/pcnet.c b/hw/pcnet.c
index db52dc5..4e30e9c 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1557,19 +1557,6 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap)
 void pcnet_h_reset(void *opaque)
 {
 PCNetState *s = opaque;
-int i;
-uint16_t checksum;
-
-/* Initialize the PROM */
-
-memcpy(s-prom, s-conf.macaddr.a, 6);
-s-prom[12] = s-prom[13] = 0x00;
-s-prom[14] = s-prom[15] = 0x57;
-
-for (i = 0,checksum = 0; i  16; i++)
-checksum += s-prom[i];
-*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
-
 
 s-bcr[BCR_MSRDA] = 0x0005;
 s-bcr[BCR_MSWRA] = 0x0005;
@@ -1736,6 +1723,9 @@ void pcnet_common_cleanup(PCNetState *d)
 
 int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
 {
+int i;
+uint16_t checksum;
+
 s-poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
 qemu_macaddr_default_if_unset(s-conf.macaddr);
@@ -1744,5 +1734,16 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, 
NetClientInfo *info)
 
 add_boot_device_path(s-conf.bootindex, dev, /ethernet-phy@0);
 
+/* Initialize the PROM */
+
+memcpy(s-prom, s-conf.macaddr.a, 6);
+s-prom[12] = s-prom[13] = 0x00;
+s-prom[14] = s-prom[15] = 0x57;
+
+for (i = 0, checksum = 0; i  16; i++) {
+checksum += s-prom[i];
+}
+*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
+
 return 0;
 }
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index a22530c..8356d5a 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -1189,18 +1189,6 @@ static void rtl8139_reset(DeviceState *d)
 
 rtl8139_update_irq(s);
 
-/* prepare eeprom */
-s-eeprom.contents[0] = 0x8129;
-#if 1
-// PCI vendor and device ID should be mirrored here
-s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
-s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
-#endif
-
-s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
-s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
-s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
-
 /* mark all status registers as owned by host */
 for (i = 0; i  4; ++i)
 {
@@ -3392,6 +3380,18 @@ static int pci_rtl8139_init(PCIDevice *dev)
 
 qemu_macaddr_default_if_unset(s-conf.macaddr);
 
+/* prepare eeprom */
+s-eeprom.contents[0] = 0x8129;
+#if 1
+/* PCI vendor and device ID should be mirrored here */
+s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
+s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
+#endif
+
+s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
+s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
+s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
+
 s-nic = qemu_new_nic(net_rtl8139_info, s-conf,
   dev-qdev.info-name, dev-qdev.id, s);
 qemu_format_nic_info_str(s-nic-nc, s-conf.macaddr.a);
-- 
1.7.2.3




Re: [Qemu-devel] [PATCH] moving eeprom initialization

2011-03-06 Thread Gerhard Wiesinger

Hello,

AMD fix is now upstream. Please merge it.

Thnx.

Ciao,
Gerhard

--
http://www.wiesinger.com/


On Sun, 6 Mar 2011, William Dauchy wrote:


The initialization should not be only on reset but also when initializing
the device.
It resolves a bug when hot plugging a pci network device: the mac address
was always null.

Signed-off-by: William Dauchy wdau...@gmail.com
Signed-off-by: Wen Congyang we...@cn.fujitsu.com
---
hw/pcnet.c   |   27 ++-
hw/rtl8139.c |   24 
2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/hw/pcnet.c b/hw/pcnet.c
index db52dc5..4e30e9c 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1557,19 +1557,6 @@ uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap)
void pcnet_h_reset(void *opaque)
{
PCNetState *s = opaque;
-int i;
-uint16_t checksum;
-
-/* Initialize the PROM */
-
-memcpy(s-prom, s-conf.macaddr.a, 6);
-s-prom[12] = s-prom[13] = 0x00;
-s-prom[14] = s-prom[15] = 0x57;
-
-for (i = 0,checksum = 0; i  16; i++)
-checksum += s-prom[i];
-*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
-

s-bcr[BCR_MSRDA] = 0x0005;
s-bcr[BCR_MSWRA] = 0x0005;
@@ -1736,6 +1723,9 @@ void pcnet_common_cleanup(PCNetState *d)

int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
{
+int i;
+uint16_t checksum;
+
s-poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);

qemu_macaddr_default_if_unset(s-conf.macaddr);
@@ -1744,5 +1734,16 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, 
NetClientInfo *info)

add_boot_device_path(s-conf.bootindex, dev, /ethernet-phy@0);

+/* Initialize the PROM */
+
+memcpy(s-prom, s-conf.macaddr.a, 6);
+s-prom[12] = s-prom[13] = 0x00;
+s-prom[14] = s-prom[15] = 0x57;
+
+for (i = 0, checksum = 0; i  16; i++) {
+checksum += s-prom[i];
+}
+*(uint16_t *)s-prom[12] = cpu_to_le16(checksum);
+
return 0;
}
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index a22530c..8356d5a 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -1189,18 +1189,6 @@ static void rtl8139_reset(DeviceState *d)

rtl8139_update_irq(s);

-/* prepare eeprom */
-s-eeprom.contents[0] = 0x8129;
-#if 1
-// PCI vendor and device ID should be mirrored here
-s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
-s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
-#endif
-
-s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
-s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
-s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
-
/* mark all status registers as owned by host */
for (i = 0; i  4; ++i)
{
@@ -3392,6 +3380,18 @@ static int pci_rtl8139_init(PCIDevice *dev)

qemu_macaddr_default_if_unset(s-conf.macaddr);

+/* prepare eeprom */
+s-eeprom.contents[0] = 0x8129;
+#if 1
+/* PCI vendor and device ID should be mirrored here */
+s-eeprom.contents[1] = PCI_VENDOR_ID_REALTEK;
+s-eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
+#endif
+
+s-eeprom.contents[7] = s-conf.macaddr.a[0] | s-conf.macaddr.a[1]  8;
+s-eeprom.contents[8] = s-conf.macaddr.a[2] | s-conf.macaddr.a[3]  8;
+s-eeprom.contents[9] = s-conf.macaddr.a[4] | s-conf.macaddr.a[5]  8;
+
s-nic = qemu_new_nic(net_rtl8139_info, s-conf,
  dev-qdev.info-name, dev-qdev.id, s);
qemu_format_nic_info_str(s-nic-nc, s-conf.macaddr.a);
--
1.7.2.3







Re: [Qemu-devel] [PATCH] moving eeprom initialization

2011-03-06 Thread William Dauchy
On Sun, Mar 6, 2011 at 9:38 PM, Gerhard Wiesinger li...@wiesinger.com wrote:
 AMD fix is now upstream. Please merge it.

oh sorry. did not see; will do.

-- 
William



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Jan Kiszka
On 2011-03-06 21:45, Anthony Liguori wrote:
 On 03/06/2011 12:06 PM, Jan Kiszka wrote:
 In the system we model, the PIT is part of the PIIX3.  The right way to
 model it is as a DeviceState that's no_user=1 and created as part of the
 initialized of PIIX3 (for the PC at least).

 LPC is still an expansion bus and it's primarily used for discrete
 components like a TPM.  For components that are all part of a Super I/O
 chip, there really just isn't a bus in the middle.
  
 There surely is some bus (or even multiple), just not external an one.

 
 It almost doesn't matter.  It would look like:
 
 I8254 is-a DeviceState
 
 SuperIO has-a I8254
 
 And the has-a relationship might be some custom bus mechanism (even if
 it's purely a VHDL or software concept).
 
 But in terms of modelling, we make I8254 a DeviceState because we don't
 care what bus it sits on.
 
 Most of the currently ISA-attached devices are chipset internal.
 
 Yeah, and making them ISA devices was the wrong thing to do.  This is
 all going to have to be redone in the not too distant future.
 
 An is-a relationship only makes sense when the device is naturally
 represented as the parent object.
 
   They
 belong to the PIIX3, so they need to be attached to some bus that is
 owned by this device. If that is its ISA bus or a separate one for
 internal devices - really, this looks like an academic discussion to me.

 
 It's far from academic as this is user-visible and visible via the
 command line.

I thought it was stated before that there is no guarantee on the
internal structure of our device tree as the user may explore it (as
long as it's stable for the guest). Regarding command line: What are
your worries here? The user can't mess with built-in devices.

I still think we have more important things to improve than these
cosmetic issues.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v2] target-arm: Set carry flag correctly for Thumb2 ORNS

2011-03-06 Thread Peter Maydell
The code for Thumb2 ORNS (or negated and set flags) was trashing
a TCG input register which was needed later for use in calculating
flags, with the effect that the carry flag was always set with
the wrong sense. Fix this by using the TCG orc op instead of
separate not and or ops.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
Change from v1: use orc as suggested by Aurelien

 target-arm/translate.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index dbd958b..dd56ac6 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -7326,8 +7326,7 @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, 
uint32_t shifter_out, TCG
 logic_cc = conds;
 break;
 case 3: /* orn */
-tcg_gen_not_i32(t1, t1);
-tcg_gen_or_i32(t0, t0, t1);
+tcg_gen_orc_i32(t0, t0, t1);
 logic_cc = conds;
 break;
 case 4: /* eor */
-- 
1.7.1




Re: [Qemu-devel] [PATCH] WIN32: Add missing include for 'struct timeval', used in vnc.h

2011-03-06 Thread Blue Swirl
On Sun, Mar 6, 2011 at 9:24 PM, Stefan Weil w...@mail.berlios.de wrote:
 Am 06.03.2011 15:24, schrieb Roy Tam:

 Hi,

 2011/3/6 Herve Poussineauhpous...@reactos.org:

 FYI:
 [PATCH 1/3] w32: Add new directory hierarchy for MinGW extensions
 http://www.mail-archive.com/qemu-devel@nongnu.org/msg56858.html
 [PATCH 2/3] w32: Add macro timersub to sys/time.h
 http://www.mail-archive.com/qemu-devel@nongnu.org/msg56859.html
 [PATCH 3/3] osdep: Remove conditional compilation (fixes w32 compilation)
 http://www.mail-archive.com/qemu-devel@nongnu.org/msg56860.html

 Yes, this patch series also addresses the same problem (and one more)
 in a better way: it did not add code, but removed a conditional compilation.
 (my first try was identical to Herve's patch).

As I replied to those, there are several problems with your approach.
Wrapping timersub() would solve the other problem nicely.

If we'd want to fake a POSIX-like programming environment, there are
other approaches like gnulib. But so far, the approach has been using
wrappers.



Re: [Qemu-devel] [PATCH v2] ioport: Improve error output

2011-03-06 Thread Aurelien Jarno
On Sun, Mar 06, 2011 at 03:48:13PM +0100, Andreas Färber wrote:
 When failing due to conflicting I/O port registrations,
 include the offending I/O port address in the message.
 
 Cc: Aurelien Jarno aurel...@aurel32.net
 Signed-off-by: Andreas Färber andreas.faer...@web.de
 ---
  v2:
  * Use for address 0x%x wording, as suggested by Aurelien.
  
  ioport.c |6 --
  1 files changed, 4 insertions(+), 2 deletions(-)

Thanks, applied.

 diff --git a/ioport.c b/ioport.c
 index aa4188a..2e971fa 100644
 --- a/ioport.c
 +++ b/ioport.c
 @@ -149,7 +149,8 @@ int register_ioport_read(pio_addr_t start, int length, 
 int size,
  for(i = start; i  start + length; i += size) {
  ioport_read_table[bsize][i] = func;
  if (ioport_opaque[i] != NULL  ioport_opaque[i] != opaque)
 -hw_error(register_ioport_read: invalid opaque);
 +hw_error(register_ioport_read: invalid opaque for address 0x%x,
 + i);
  ioport_opaque[i] = opaque;
  }
  return 0;
 @@ -168,7 +169,8 @@ int register_ioport_write(pio_addr_t start, int length, 
 int size,
  for(i = start; i  start + length; i += size) {
  ioport_write_table[bsize][i] = func;
  if (ioport_opaque[i] != NULL  ioport_opaque[i] != opaque)
 -hw_error(register_ioport_write: invalid opaque);
 +hw_error(register_ioport_write: invalid opaque for address 
 0x%x,
 + i);
  ioport_opaque[i] = opaque;
  }
  return 0;
 -- 
 1.7.3.4
 
 
 

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] Re: EFI console stopped working in Qemu 0.14.0

2011-03-06 Thread Jordan Justen
On Sun, Mar 6, 2011 at 13:26, vagran vagran@gmail.com wrote:
  Can you try disabling KVM?

 Yes, it helped. Problem exists only when using KVM. Thanks.

One thing I suspect is that the kernel side of kvm had an issue around
this time (Ubuntu 9.10) with a bios.bin larger than 256kb.

With qemu 0.14.0, you could investigate what value is being used for
identity_base in target-i386/kvm.c:kvm_arch_init.
(Notice it will be a lower value if KVM_CAP_SET_IDENTITY_MAP_ADDR is
defined, and this will allow for a larger bios.bin.)

I think I was able to use OVMF X64 with kvm on Ubuntu 10.04, but I
don't have a system set up right now to verify this.  I am able to use
OVMF X64 with kvm on Ubuntu 10.10.

-Jordan



[Qemu-devel] Re: [PATCH 4/4] i8254: convert to qdev

2011-03-06 Thread Anthony Liguori

On 03/06/2011 03:18 PM, Jan Kiszka wrote:

It's far from academic as this is user-visible and visible via the
command line.
 

I thought it was stated before that there is no guarantee on the
internal structure of our device tree as the user may explore it (as
long as it's stable for the guest).


We have a lot of unstable interfaces that folks yell about every time 
it changes (like the -help output).  Providing a bad external interface 
and justifying by saying its unstable is just asking for pain later.



  Regarding command line: What are
your worries here? The user can't mess with built-in devices.
   


-global still applies to no_user devices.


I still think we have more important things to improve than these
cosmetic issues.
   


What does converting this device to qdev actually add other than an 
interface that we're not going to be able to support long term?


Regards,

Anthony Liguori


Jan

   





[Qemu-devel] [PATCH v5 02/10] softfloat: Resolve type mismatches between declaration and implementation

2011-03-06 Thread Andreas Färber
The original SoftFloat 2.0b library avoided the use of custom integer types
in its public headers. This requires the definitions of int{8,16,32,64} to
match the assumptions in the declarations. This breaks on BeOS R5 and Haiku/x86,
where int32 is defined in {be,os}/support/SupportDefs.h in terms of a long
rather than an int. Spotted by Michael Lotz.

Since QEMU already breaks this distinction by defining those types just above,
do use them for consistency and to allow #ifndef'ing them out as done for
[u]int16 on AIX.

Note that the BeOS/Haiku types are exact-width types though.

v3:
* Split off as intermediate step.

v2:
* Rebased.

Cc: Michael Lotz m...@mlotz.ch
Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat.h |   68 +++---
 1 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/fpu/softfloat.h b/fpu/softfloat.h
index 9e10727..29492bc 100644
--- a/fpu/softfloat.h
+++ b/fpu/softfloat.h
@@ -255,25 +255,25 @@ void float_raise( int8 flags STATUS_PARAM);
 /*
 | Software IEC/IEEE integer-to-floating-point conversion routines.
 **/
-float32 int32_to_float32( int STATUS_PARAM );
-float64 int32_to_float64( int STATUS_PARAM );
+float32 int32_to_float32( int32 STATUS_PARAM );
+float64 int32_to_float64( int32 STATUS_PARAM );
 float32 uint32_to_float32( unsigned int STATUS_PARAM );
 float64 uint32_to_float64( unsigned int STATUS_PARAM );
 #ifdef FLOATX80
-floatx80 int32_to_floatx80( int STATUS_PARAM );
+floatx80 int32_to_floatx80( int32 STATUS_PARAM );
 #endif
 #ifdef FLOAT128
-float128 int32_to_float128( int STATUS_PARAM );
+float128 int32_to_float128( int32 STATUS_PARAM );
 #endif
-float32 int64_to_float32( int64_t STATUS_PARAM );
-float32 uint64_to_float32( uint64_t STATUS_PARAM );
-float64 int64_to_float64( int64_t STATUS_PARAM );
-float64 uint64_to_float64( uint64_t STATUS_PARAM );
+float32 int64_to_float32( int64 STATUS_PARAM );
+float32 uint64_to_float32( uint64 STATUS_PARAM );
+float64 int64_to_float64( int64 STATUS_PARAM );
+float64 uint64_to_float64( uint64 STATUS_PARAM );
 #ifdef FLOATX80
-floatx80 int64_to_floatx80( int64_t STATUS_PARAM );
+floatx80 int64_to_floatx80( int64 STATUS_PARAM );
 #endif
 #ifdef FLOAT128
-float128 int64_to_float128( int64_t STATUS_PARAM );
+float128 int64_to_float128( int64 STATUS_PARAM );
 #endif
 
 /*
@@ -303,14 +303,14 @@ float16 float16_maybe_silence_nan( float16 );
 /*
 | Software IEC/IEEE single-precision conversion routines.
 **/
-int float32_to_int16_round_to_zero( float32 STATUS_PARAM );
+int16 float32_to_int16_round_to_zero( float32 STATUS_PARAM );
 unsigned int float32_to_uint16_round_to_zero( float32 STATUS_PARAM );
-int float32_to_int32( float32 STATUS_PARAM );
-int float32_to_int32_round_to_zero( float32 STATUS_PARAM );
-unsigned int float32_to_uint32( float32 STATUS_PARAM );
-unsigned int float32_to_uint32_round_to_zero( float32 STATUS_PARAM );
-int64_t float32_to_int64( float32 STATUS_PARAM );
-int64_t float32_to_int64_round_to_zero( float32 STATUS_PARAM );
+int32 float32_to_int32( float32 STATUS_PARAM );
+int32 float32_to_int32_round_to_zero( float32 STATUS_PARAM );
+uint32 float32_to_uint32( float32 STATUS_PARAM );
+uint32 float32_to_uint32_round_to_zero( float32 STATUS_PARAM );
+int64 float32_to_int64( float32 STATUS_PARAM );
+int64 float32_to_int64_round_to_zero( float32 STATUS_PARAM );
 float64 float32_to_float64( float32 STATUS_PARAM );
 #ifdef FLOATX80
 floatx80 float32_to_floatx80( float32 STATUS_PARAM );
@@ -413,16 +413,16 @@ INLINE float32 float32_set_sign(float32 a, int sign)
 /*
 | Software IEC/IEEE double-precision conversion routines.
 **/
-int float64_to_int16_round_to_zero( float64 STATUS_PARAM );
+int16 float64_to_int16_round_to_zero( float64 STATUS_PARAM );
 unsigned int float64_to_uint16_round_to_zero( float64 STATUS_PARAM );
-int float64_to_int32( float64 STATUS_PARAM );
-int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
-unsigned int float64_to_uint32( float64 STATUS_PARAM );
-unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
-int64_t float64_to_int64( float64 STATUS_PARAM );
-int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
-uint64_t float64_to_uint64 (float64 a STATUS_PARAM);
-uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM);
+int32 float64_to_int32( float64 STATUS_PARAM );
+int32 float64_to_int32_round_to_zero( float64 STATUS_PARAM 

[Qemu-devel] Re: [PATCH 03/15] kvm: Install optimized interrupt handlers

2011-03-06 Thread Marcelo Tosatti
On Sat, Mar 05, 2011 at 07:11:53PM +0100, Jan Kiszka wrote:
 On 2011-03-05 16:37, Marcelo Tosatti wrote:
  On Fri, Mar 04, 2011 at 11:20:00AM +0100, Jan Kiszka wrote:
  KVM only requires to set the raised IRQ in CPUState and, if the user
  space irqchip is used, to kick the receiving vcpu if it is remote.
 
  Signed-off-by: Jan Kiszka jan.kis...@siemens.com
  ---
   kvm-all.c |   17 +
   1 files changed, 17 insertions(+), 0 deletions(-)
 
  diff --git a/kvm-all.c b/kvm-all.c
  index 226843c..c460d45 100644
  --- a/kvm-all.c
  +++ b/kvm-all.c
  @@ -650,6 +650,20 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client 
  = {
   .log_stop = kvm_log_stop,
   };
   
  +static void kvm_handle_interrupt(CPUState *env, int mask)
  +{
  +env-interrupt_request |= mask;
  +
  
  If the env-interrupt_request request is processed in userspace, such as
  MCE, the kick is still necessary for irqchip case. CPU_INTERRUPT_DEBUG
  is another example, no?
 
 [this probably targeted kvm_handle_interrupt_kernel_irqchip]
 
 In principle, you are right. But MCE must be injected synchronously over
 the target VCPU, see do_inject_x86_mce, and CPU_INTERRUPT_DEBUG is also
 synchronous and not even used in KVM mode.

CPU_INTERRUPT_NMI from monitor?

Don't see what gain you expect from avoiding the signal in this case.




[Qemu-devel] [PATCH v5 05/10] softfloat: Use [u]int_fast16_t consistently

2011-03-06 Thread Andreas Färber
Adapt float{32,64}_to_uint16_round_to_zero().

v5:
* Reworded.

v3:
* Split off. Use uint_fast16_t rather than uint16_t.

v2:
* Initial.

Cc: Peter Maydell peter.mayd...@linaro.org
Cc: Nathan Froyd froy...@codesourcery.com
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat.c |8 
 fpu/softfloat.h |4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index befd400..4e23511 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -5865,10 +5865,10 @@ unsigned int float32_to_uint32_round_to_zero( float32 a 
STATUS_PARAM )
 return res;
 }
 
-unsigned int float32_to_uint16_round_to_zero( float32 a STATUS_PARAM )
+uint_fast16_t float32_to_uint16_round_to_zero( float32 a STATUS_PARAM )
 {
 int64_t v;
-unsigned int res;
+uint_fast16_t res;
 
 v = float32_to_int64_round_to_zero(a STATUS_VAR);
 if (v  0) {
@@ -5919,10 +5919,10 @@ unsigned int float64_to_uint32_round_to_zero( float64 a 
STATUS_PARAM )
 return res;
 }
 
-unsigned int float64_to_uint16_round_to_zero( float64 a STATUS_PARAM )
+uint_fast16_t float64_to_uint16_round_to_zero( float64 a STATUS_PARAM )
 {
 int64_t v;
-unsigned int res;
+uint_fast16_t res;
 
 v = float64_to_int64_round_to_zero(a STATUS_VAR);
 if (v  0) {
diff --git a/fpu/softfloat.h b/fpu/softfloat.h
index f98e50c..795c2ea 100644
--- a/fpu/softfloat.h
+++ b/fpu/softfloat.h
@@ -285,7 +285,7 @@ float16 float16_maybe_silence_nan( float16 );
 | Software IEC/IEEE single-precision conversion routines.
 **/
 int_fast16_t float32_to_int16_round_to_zero( float32 STATUS_PARAM );
-unsigned int float32_to_uint16_round_to_zero( float32 STATUS_PARAM );
+uint_fast16_t float32_to_uint16_round_to_zero( float32 STATUS_PARAM );
 int32 float32_to_int32( float32 STATUS_PARAM );
 int32 float32_to_int32_round_to_zero( float32 STATUS_PARAM );
 uint32 float32_to_uint32( float32 STATUS_PARAM );
@@ -395,7 +395,7 @@ INLINE float32 float32_set_sign(float32 a, int sign)
 | Software IEC/IEEE double-precision conversion routines.
 **/
 int_fast16_t float64_to_int16_round_to_zero( float64 STATUS_PARAM );
-unsigned int float64_to_uint16_round_to_zero( float64 STATUS_PARAM );
+uint_fast16_t float64_to_uint16_round_to_zero( float64 STATUS_PARAM );
 int32 float64_to_int32( float64 STATUS_PARAM );
 int32 float64_to_int32_round_to_zero( float64 STATUS_PARAM );
 uint32 float64_to_uint32( float64 STATUS_PARAM );
-- 
1.7.3.4




[Qemu-devel] [PATCH v5 09/10] softfloat: Drop [u]int64 types in favor of [u]int_fast64_t

2011-03-06 Thread Andreas Färber
v5:
* Initial.

Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat.c |   48 
 fpu/softfloat.h |   34 --
 2 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index d1e3a42..6b2cbd7 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -159,11 +159,11 @@ static int_fast32_t roundAndPackInt32( flag zSign, 
uint64_t absZ STATUS_PARAM)
 | returned.
 **/
 
-static int64 roundAndPackInt64( flag zSign, uint64_t absZ0, uint64_t absZ1 
STATUS_PARAM)
+static int_fast64_t roundAndPackInt64( flag zSign, uint64_t absZ0, uint64_t 
absZ1 STATUS_PARAM)
 {
 int_fast8_t roundingMode;
 flag roundNearestEven, increment;
-int64 z;
+int_fast64_t z;
 
 roundingMode = STATUS(float_rounding_mode);
 roundNearestEven = ( roundingMode == float_round_nearest_even );
@@ -660,7 +660,7 @@ static floatx80
 {
 int_fast8_t roundingMode;
 flag roundNearestEven, increment, isTiny;
-int64 roundIncrement, roundMask, roundBits;
+int_fast64_t roundIncrement, roundMask, roundBits;
 
 roundingMode = STATUS(float_rounding_mode);
 roundNearestEven = ( roundingMode == float_round_nearest_even );
@@ -1206,10 +1206,10 @@ float128 int32_to_float128( int_fast32_t a STATUS_PARAM 
)
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
 **/
 
-float32 int64_to_float32( int64 a STATUS_PARAM )
+float32 int64_to_float32( int_fast64_t a STATUS_PARAM )
 {
 flag zSign;
-uint64 absA;
+uint_fast64_t absA;
 int_fast8_t shiftCount;
 
 if ( a == 0 ) return float32_zero;
@@ -1232,7 +1232,7 @@ float32 int64_to_float32( int64 a STATUS_PARAM )
 
 }
 
-float32 uint64_to_float32( uint64 a STATUS_PARAM )
+float32 uint64_to_float32( uint_fast64_t a STATUS_PARAM )
 {
 int_fast8_t shiftCount;
 
@@ -1259,7 +1259,7 @@ float32 uint64_to_float32( uint64 a STATUS_PARAM )
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
 **/
 
-float64 int64_to_float64( int64 a STATUS_PARAM )
+float64 int64_to_float64( int_fast64_t a STATUS_PARAM )
 {
 flag zSign;
 
@@ -1272,7 +1272,7 @@ float64 int64_to_float64( int64 a STATUS_PARAM )
 
 }
 
-float64 uint64_to_float64( uint64 a STATUS_PARAM )
+float64 uint64_to_float64( uint_fast64_t a STATUS_PARAM )
 {
 if ( a == 0 ) return float64_zero;
 return normalizeRoundAndPackFloat64( 0, 0x43C, a STATUS_VAR );
@@ -1288,10 +1288,10 @@ float64 uint64_to_float64( uint64 a STATUS_PARAM )
 | Arithmetic.
 **/
 
-floatx80 int64_to_floatx80( int64 a STATUS_PARAM )
+floatx80 int64_to_floatx80( int_fast64_t a STATUS_PARAM )
 {
 flag zSign;
-uint64 absA;
+uint_fast64_t absA;
 int_fast8_t shiftCount;
 
 if ( a == 0 ) return packFloatx80( 0, 0, 0 );
@@ -1312,10 +1312,10 @@ floatx80 int64_to_floatx80( int64 a STATUS_PARAM )
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
 **/
 
-float128 int64_to_float128( int64 a STATUS_PARAM )
+float128 int64_to_float128( int_fast64_t a STATUS_PARAM )
 {
 flag zSign;
-uint64 absA;
+uint_fast64_t absA;
 int_fast8_t shiftCount;
 int_fast32_t zExp;
 uint64_t zSig0, zSig1;
@@ -1474,7 +1474,7 @@ int_fast16_t float32_to_int16_round_to_zero( float32 a 
STATUS_PARAM )
 | largest integer with the same sign as `a' is returned.
 **/
 
-int64 float32_to_int64( float32 a STATUS_PARAM )
+int_fast64_t float32_to_int64( float32 a STATUS_PARAM )
 {
 flag aSign;
 int_fast16_t aExp, shiftCount;
@@ -1511,13 +1511,13 @@ int64 float32_to_int64( float32 a STATUS_PARAM )
 | returned.
 **/
 
-int64 float32_to_int64_round_to_zero( float32 a STATUS_PARAM )
+int_fast64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM )
 {
 flag aSign;
 int_fast16_t aExp, shiftCount;
 uint32_t aSig;
 uint64_t aSig64;
-int64 z;
+int_fast64_t z;
 a = float32_squash_input_denormal(a STATUS_VAR);
 
 aSig = extractFloat32Frac( a );
@@ -2616,7 +2616,7 @@ int_fast16_t float64_to_int16_round_to_zero( float64 a 
STATUS_PARAM )
 | largest integer with the same sign as `a' is returned.
 **/
 
-int64 float64_to_int64( float64 a STATUS_PARAM )
+int_fast64_t float64_to_int64( float64 a STATUS_PARAM )
 {
 flag aSign;
 int_fast16_t aExp, shiftCount;
@@ 

[Qemu-devel] [PATCH v5 01/10] [RESEND] softfloat: Prepend QEMU-style header with derivation notice

2011-03-06 Thread Andreas Färber
The SoftFloat license requires prominent notice that the work
is derivative. Having added features like improved 16-bit support
for arm already, add such a notice to the sources.

softfloat-native.[ch] are not under the SoftFloat license
and thus are not changed.

v4:
Initial.

Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat-macros.h |5 +
 fpu/softfloat-specialize.h |5 +
 fpu/softfloat.c|5 +
 fpu/softfloat.h|6 ++
 4 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index 7838228..54c0bad 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -1,3 +1,8 @@
+/*
+ * QEMU float support macros
+ *
+ * Derived from SoftFloat.
+ */
 
 /*
 
diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index adc5ada..4add93c 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -1,3 +1,8 @@
+/*
+ * QEMU float support
+ *
+ * Derived from SoftFloat.
+ */
 
 /*
 
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 30b07e9..e800daa 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -1,3 +1,8 @@
+/*
+ * QEMU float support
+ *
+ * Derived from SoftFloat.
+ */
 
 /*
 
diff --git a/fpu/softfloat.h b/fpu/softfloat.h
index fd61dc4..9e10727 100644
--- a/fpu/softfloat.h
+++ b/fpu/softfloat.h
@@ -1,3 +1,9 @@
+/*
+ * QEMU float support
+ *
+ * Derived from SoftFloat.
+ */
+
 /*
 
 This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
-- 
1.7.3.4




[Qemu-devel] [PATCH v5 07/10] softfloat: Drop [u]int32 types in favor of [u]int_fast32_t

2011-03-06 Thread Andreas Färber
v5:
* Initial.

Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat.c |  132 +++---
 fpu/softfloat.h |   34 +++
 2 files changed, 82 insertions(+), 84 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index e6ecf6c..7f0f603 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -109,12 +109,12 @@ INLINE flag extractFloat16Sign(float16 a)
 | positive or negative integer is returned.
 **/
 
-static int32 roundAndPackInt32( flag zSign, uint64_t absZ STATUS_PARAM)
+static int_fast32_t roundAndPackInt32( flag zSign, uint64_t absZ STATUS_PARAM)
 {
 int_fast8_t roundingMode;
 flag roundNearestEven;
 int_fast8_t roundIncrement, roundBits;
-int32 z;
+int_fast32_t z;
 
 roundingMode = STATUS(float_rounding_mode);
 roundNearestEven = ( roundingMode == float_round_nearest_even );
@@ -577,7 +577,7 @@ INLINE uint64_t extractFloatx80Frac( floatx80 a )
 | value `a'.
 **/
 
-INLINE int32 extractFloatx80Exp( floatx80 a )
+INLINE int_fast32_t extractFloatx80Exp( floatx80 a )
 {
 
 return a.high  0x7FFF;
@@ -604,7 +604,7 @@ INLINE flag extractFloatx80Sign( floatx80 a )
 **/
 
 static void
- normalizeFloatx80Subnormal( uint64_t aSig, int32 *zExpPtr, uint64_t *zSigPtr )
+ normalizeFloatx80Subnormal( uint64_t aSig, int_fast32_t *zExpPtr, uint64_t 
*zSigPtr )
 {
 int_fast8_t shiftCount;
 
@@ -619,7 +619,7 @@ static void
 | extended double-precision floating-point value, returning the result.
 **/
 
-INLINE floatx80 packFloatx80( flag zSign, int32 zExp, uint64_t zSig )
+INLINE floatx80 packFloatx80( flag zSign, int_fast32_t zExp, uint64_t zSig )
 {
 floatx80 z;
 
@@ -655,7 +655,7 @@ INLINE floatx80 packFloatx80( flag zSign, int32 zExp, 
uint64_t zSig )
 
 static floatx80
  roundAndPackFloatx80(
- int_fast8_t roundingPrecision, flag zSign, int32 zExp, uint64_t zSig0, 
uint64_t zSig1
+ int_fast8_t roundingPrecision, flag zSign, int_fast32_t zExp, uint64_t 
zSig0, uint64_t zSig1
  STATUS_PARAM)
 {
 int_fast8_t roundingMode;
@@ -824,7 +824,7 @@ static floatx80
 
 static floatx80
  normalizeRoundAndPackFloatx80(
- int_fast8_t roundingPrecision, flag zSign, int32 zExp, uint64_t zSig0, 
uint64_t zSig1
+ int_fast8_t roundingPrecision, flag zSign, int_fast32_t zExp, uint64_t 
zSig0, uint64_t zSig1
  STATUS_PARAM)
 {
 int_fast8_t shiftCount;
@@ -875,7 +875,7 @@ INLINE uint64_t extractFloat128Frac0( float128 a )
 | `a'.
 **/
 
-INLINE int32 extractFloat128Exp( float128 a )
+INLINE int_fast32_t extractFloat128Exp( float128 a )
 {
 
 return ( a.high48 )  0x7FFF;
@@ -907,7 +907,7 @@ static void
  normalizeFloat128Subnormal(
  uint64_t aSig0,
  uint64_t aSig1,
- int32 *zExpPtr,
+ int_fast32_t *zExpPtr,
  uint64_t *zSig0Ptr,
  uint64_t *zSig1Ptr
  )
@@ -948,7 +948,7 @@ static void
 **/
 
 INLINE float128
- packFloat128( flag zSign, int32 zExp, uint64_t zSig0, uint64_t zSig1 )
+ packFloat128( flag zSign, int_fast32_t zExp, uint64_t zSig0, uint64_t zSig1 )
 {
 float128 z;
 
@@ -981,7 +981,7 @@ INLINE float128
 
 static float128
  roundAndPackFloat128(
- flag zSign, int32 zExp, uint64_t zSig0, uint64_t zSig1, uint64_t zSig2 
STATUS_PARAM)
+ flag zSign, int_fast32_t zExp, uint64_t zSig0, uint64_t zSig1, uint64_t 
zSig2 STATUS_PARAM)
 {
 int_fast8_t roundingMode;
 flag roundNearestEven, increment, isTiny;
@@ -1082,7 +1082,7 @@ static float128
 
 static float128
  normalizeRoundAndPackFloat128(
- flag zSign, int32 zExp, uint64_t zSig0, uint64_t zSig1 STATUS_PARAM)
+ flag zSign, int_fast32_t zExp, uint64_t zSig0, uint64_t zSig1 
STATUS_PARAM)
 {
 int_fast8_t shiftCount;
 uint64_t zSig2;
@@ -1114,7 +1114,7 @@ static float128
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
 **/
 
-float32 int32_to_float32( int32 a STATUS_PARAM )
+float32 int32_to_float32( int_fast32_t a STATUS_PARAM )
 {
 flag zSign;
 
@@ -1131,10 +1131,10 @@ float32 int32_to_float32( int32 a STATUS_PARAM )
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic.
 **/
 
-float64 int32_to_float64( int32 a STATUS_PARAM )
+float64 int32_to_float64( int_fast32_t a STATUS_PARAM )
 {
 flag zSign;
-uint32 absA;
+uint_fast32_t absA;
 int_fast8_t shiftCount;
 uint64_t zSig;
 

[Qemu-devel] [PATCH v5 06/10] softfloat: Drop [u]int8 types in favor of int_fast8_t

2011-03-06 Thread Andreas Färber
v5:
* Initial.

Cc: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat-macros.h |   26 +-
 fpu/softfloat-specialize.h |2 +-
 fpu/softfloat.c|   62 ++--
 fpu/softfloat.h|4 +--
 4 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index 7b350c0..28637d4 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -109,7 +109,7 @@ INLINE void
  uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
-int8 negCount = ( - count )  63;
+int_fast8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -146,7 +146,7 @@ INLINE void
  uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
-int8 negCount = ( - count )  63;
+int_fast8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -181,7 +181,7 @@ INLINE void
  uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
-int8 negCount = ( - count )  63;
+int_fast8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z1 = a1;
@@ -239,7 +239,7 @@ INLINE void
  )
 {
 uint64_t z0, z1, z2;
-int8 negCount = ( - count )  63;
+int_fast8_t negCount = ( - count )  63;
 
 if ( count == 0 ) {
 z2 = a2;
@@ -316,7 +316,7 @@ INLINE void
  )
 {
 uint64_t z0, z1, z2;
-int8 negCount;
+int_fast8_t negCount;
 
 z2 = a2count;
 z1 = a1count;
@@ -373,7 +373,7 @@ INLINE void
  )
 {
 uint64_t z0, z1, z2;
-int8 carry0, carry1;
+int_fast8_t carry0, carry1;
 
 z2 = a2 + b2;
 carry1 = ( z2  a2 );
@@ -429,7 +429,7 @@ INLINE void
  )
 {
 uint64_t z0, z1, z2;
-int8 borrow0, borrow1;
+int_fast8_t borrow0, borrow1;
 
 z2 = a2 - b2;
 borrow1 = ( a2  b2 );
@@ -590,7 +590,7 @@ static uint32_t estimateSqrt32( int_fast16_t aExp, uint32_t 
a )
 0x0A2D, 0x08AF, 0x075A, 0x0629, 0x051A, 0x0429, 0x0356, 0x029E,
 0x0200, 0x0179, 0x0109, 0x00AF, 0x0068, 0x0034, 0x0012, 0x0002
 };
-int8 index;
+int_fast8_t index;
 uint32_t z;
 
 index = ( a27 )  15;
@@ -614,9 +614,9 @@ static uint32_t estimateSqrt32( int_fast16_t aExp, uint32_t 
a )
 | `a'.  If `a' is zero, 32 is returned.
 **/
 
-static int8 countLeadingZeros32( uint32_t a )
+static int_fast8_t countLeadingZeros32( uint32_t a )
 {
-static const int8 countLeadingZerosHigh[] = {
+static const int_fast8_t countLeadingZerosHigh[] = {
 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@@ -634,7 +634,7 @@ static int8 countLeadingZeros32( uint32_t a )
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
-int8 shiftCount;
+int_fast8_t shiftCount;
 
 shiftCount = 0;
 if ( a  0x1 ) {
@@ -655,9 +655,9 @@ static int8 countLeadingZeros32( uint32_t a )
 | `a'.  If `a' is zero, 64 is returned.
 **/
 
-static int8 countLeadingZeros64( uint64_t a )
+static int_fast8_t countLeadingZeros64( uint64_t a )
 {
-int8 shiftCount;
+int_fast8_t shiftCount;
 
 shiftCount = 0;
 if ( a  ( (uint64_t) 1 )32 ) {
diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 4b65de6..e81ae96 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -42,7 +42,7 @@ these four paragraphs for those parts of this code that are 
retained.
 | should be simply `float_exception_flags |= flags;'.
 **/
 
-void float_raise( int8 flags STATUS_PARAM )
+void float_raise( int_fast8_t flags STATUS_PARAM )
 {
 STATUS(float_exception_flags) |= flags;
 }
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 4e23511..e6ecf6c 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -111,9 +111,9 @@ INLINE flag extractFloat16Sign(float16 a)
 
 static int32 roundAndPackInt32( flag zSign, uint64_t absZ STATUS_PARAM)
 {
-int8 roundingMode;
+int_fast8_t roundingMode;
 flag roundNearestEven;
-int8 roundIncrement, roundBits;
+int_fast8_t roundIncrement, roundBits;
 int32 z;
 
 roundingMode = STATUS(float_rounding_mode);
@@ -161,7 +161,7 @@ static int32 roundAndPackInt32( flag zSign, uint64_t absZ 
STATUS_PARAM)
 
 static int64 roundAndPackInt64( flag zSign, uint64_t absZ0, uint64_t absZ1 
STATUS_PARAM)
 {
-int8 roundingMode;
+int_fast8_t roundingMode;
 flag roundNearestEven, increment;
 int64 z;
 
@@ -258,7 +258,7 @@ 

[Qemu-devel] [PATCH v5 08/10] softfloat: Use [u]int_fast32_t consistently

2011-03-06 Thread Andreas Färber
v5:
* Initial.

Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat-native.c |   42 +-
 fpu/softfloat-native.h |   32 
 fpu/softfloat.c|   12 ++--
 fpu/softfloat.h|4 ++--
 4 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/fpu/softfloat-native.c b/fpu/softfloat-native.c
index 50355a4..2c08958 100644
--- a/fpu/softfloat-native.c
+++ b/fpu/softfloat-native.c
@@ -77,28 +77,28 @@ static double qemu_rint(double x)
 /*
 | Software IEC/IEEE integer-to-floating-point conversion routines.
 **/
-float32 int32_to_float32(int v STATUS_PARAM)
+float32 int32_to_float32(int_fast32_t v STATUS_PARAM)
 {
 return (float32)v;
 }
 
-float32 uint32_to_float32(unsigned int v STATUS_PARAM)
+float32 uint32_to_float32(uint_fast32_t v STATUS_PARAM)
 {
 return (float32)v;
 }
 
-float64 int32_to_float64(int v STATUS_PARAM)
+float64 int32_to_float64(int_fast32_t v STATUS_PARAM)
 {
 return (float64)v;
 }
 
-float64 uint32_to_float64(unsigned int v STATUS_PARAM)
+float64 uint32_to_float64(uint_fast32_t v STATUS_PARAM)
 {
 return (float64)v;
 }
 
 #ifdef FLOATX80
-floatx80 int32_to_floatx80(int v STATUS_PARAM)
+floatx80 int32_to_floatx80(int_fast32_t v STATUS_PARAM)
 {
 return (floatx80)v;
 }
@@ -144,13 +144,13 @@ static inline int long_to_int32(long a)
 /*
 | Software IEC/IEEE single-precision conversion routines.
 **/
-int float32_to_int32( float32 a STATUS_PARAM)
+int_fast32_t float32_to_int32( float32 a STATUS_PARAM)
 {
 return long_to_int32(lrintf(a));
 }
-int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
+int_fast32_t float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
 {
-return (int)a;
+return (int32_t)a;
 }
 int64_t float32_to_int64( float32 a STATUS_PARAM)
 {
@@ -173,10 +173,10 @@ floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
 }
 #endif
 
-unsigned int float32_to_uint32( float32 a STATUS_PARAM)
+uint_fast32_t float32_to_uint32( float32 a STATUS_PARAM)
 {
 int64_t v;
-unsigned int res;
+uint_fast32_t res;
 
 v = llrintf(a);
 if (v  0) {
@@ -188,10 +188,10 @@ unsigned int float32_to_uint32( float32 a STATUS_PARAM)
 }
 return res;
 }
-unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM)
+uint_fast32_t float32_to_uint32_round_to_zero( float32 a STATUS_PARAM)
 {
 int64_t v;
-unsigned int res;
+uint_fast32_t res;
 
 v = (int64_t)a;
 if (v  0) {
@@ -266,13 +266,13 @@ int float32_is_quiet_nan( float32 a1 )
 /*
 | Software IEC/IEEE double-precision conversion routines.
 **/
-int float64_to_int32( float64 a STATUS_PARAM)
+int_fast32_t float64_to_int32( float64 a STATUS_PARAM)
 {
 return long_to_int32(lrint(a));
 }
-int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
+int_fast32_t float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
 {
-return (int)a;
+return (int32_t)a;
 }
 int64_t float64_to_int64( float64 a STATUS_PARAM)
 {
@@ -299,10 +299,10 @@ float128 float64_to_float128( float64 a STATUS_PARAM)
 }
 #endif
 
-unsigned int float64_to_uint32( float64 a STATUS_PARAM)
+uint_fast32_t float64_to_uint32( float64 a STATUS_PARAM)
 {
 int64_t v;
-unsigned int res;
+uint_fast32_t res;
 
 v = llrint(a);
 if (v  0) {
@@ -314,10 +314,10 @@ unsigned int float64_to_uint32( float64 a STATUS_PARAM)
 }
 return res;
 }
-unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM)
+uint_fast32_t float64_to_uint32_round_to_zero( float64 a STATUS_PARAM)
 {
 int64_t v;
-unsigned int res;
+uint_fast32_t res;
 
 v = (int64_t)a;
 if (v  0) {
@@ -427,11 +427,11 @@ int float64_is_quiet_nan( float64 a1 )
 /*
 | Software IEC/IEEE extended double-precision conversion routines.
 **/
-int floatx80_to_int32( floatx80 a STATUS_PARAM)
+int_fast32_t floatx80_to_int32( floatx80 a STATUS_PARAM)
 {
 return long_to_int32(lrintl(a));
 }
-int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
+int_fast32_t floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
 {
 return (int)a;
 }
diff --git a/fpu/softfloat-native.h b/fpu/softfloat-native.h
index 80b5f28..6cf5dc3 100644
--- a/fpu/softfloat-native.h
+++ b/fpu/softfloat-native.h
@@ -150,15 +150,15 @@ void set_floatx80_rounding_precision(int val 
STATUS_PARAM);
 

[Qemu-devel] [PATCH v5 04/10] softfloat: Drop [u]int16 types in favor of [u]int_fast16_t

2011-03-06 Thread Andreas Färber
AIX already didn't use our definition, so let's start ripping out this one:
As pointed out by Peter Maydell, int16 is currently int on most
supported platforms, so let's replace it with int_fast16_t,
allowing the system to use a wider type if appropriate.

Note that Darwin uses [u]int16_t now, whereas Haiku uses [u]int32_t.

v5:
* Rebased. Convert new use of int16.

v3:
* Split off. Use [u]int_fast16_t rather than [u]int16_t.

v2:
* Rebased. Fix two new instances of int16.

Cc: Peter Maydell peter.mayd...@linaro.org
Cc: malc av1...@comtv.ru
Signed-off-by: Andreas Färber andreas.faer...@web.de
---
 fpu/softfloat-macros.h |   18 
 fpu/softfloat.c|  116 
 fpu/softfloat.h|8 +---
 3 files changed, 69 insertions(+), 73 deletions(-)

diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h
index 3128e60..7b350c0 100644
--- a/fpu/softfloat-macros.h
+++ b/fpu/softfloat-macros.h
@@ -44,7 +44,7 @@ these four paragraphs for those parts of this code that are 
retained.
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-INLINE void shift32RightJamming( uint32_t a, int16 count, uint32_t *zPtr )
+INLINE void shift32RightJamming( uint32_t a, int_fast16_t count, uint32_t 
*zPtr )
 {
 uint32_t z;
 
@@ -70,7 +70,7 @@ INLINE void shift32RightJamming( uint32_t a, int16 count, 
uint32_t *zPtr )
 | The result is stored in the location pointed to by `zPtr'.
 **/
 
-INLINE void shift64RightJamming( uint64_t a, int16 count, uint64_t *zPtr )
+INLINE void shift64RightJamming( uint64_t a, int_fast16_t count, uint64_t 
*zPtr )
 {
 uint64_t z;
 
@@ -106,7 +106,7 @@ INLINE void shift64RightJamming( uint64_t a, int16 count, 
uint64_t *zPtr )
 
 INLINE void
  shift64ExtraRightJamming(
- uint64_t a0, uint64_t a1, int16 count, uint64_t *z0Ptr, uint64_t *z1Ptr )
+ uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
 int8 negCount = ( - count )  63;
@@ -143,7 +143,7 @@ INLINE void
 
 INLINE void
  shift128Right(
- uint64_t a0, uint64_t a1, int16 count, uint64_t *z0Ptr, uint64_t *z1Ptr )
+ uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
 int8 negCount = ( - count )  63;
@@ -178,7 +178,7 @@ INLINE void
 
 INLINE void
  shift128RightJamming(
- uint64_t a0, uint64_t a1, int16 count, uint64_t *z0Ptr, uint64_t *z1Ptr )
+ uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 uint64_t z0, z1;
 int8 negCount = ( - count )  63;
@@ -232,7 +232,7 @@ INLINE void
  uint64_t a0,
  uint64_t a1,
  uint64_t a2,
- int16 count,
+ int_fast16_t count,
  uint64_t *z0Ptr,
  uint64_t *z1Ptr,
  uint64_t *z2Ptr
@@ -287,7 +287,7 @@ INLINE void
 
 INLINE void
  shortShift128Left(
- uint64_t a0, uint64_t a1, int16 count, uint64_t *z0Ptr, uint64_t *z1Ptr )
+ uint64_t a0, uint64_t a1, int_fast16_t count, uint64_t *z0Ptr, uint64_t 
*z1Ptr )
 {
 
 *z1Ptr = a1count;
@@ -309,7 +309,7 @@ INLINE void
  uint64_t a0,
  uint64_t a1,
  uint64_t a2,
- int16 count,
+ int_fast16_t count,
  uint64_t *z0Ptr,
  uint64_t *z1Ptr,
  uint64_t *z2Ptr
@@ -580,7 +580,7 @@ static uint64_t estimateDiv128To64( uint64_t a0, uint64_t 
a1, uint64_t b )
 | value.
 **/
 
-static uint32_t estimateSqrt32( int16 aExp, uint32_t a )
+static uint32_t estimateSqrt32( int_fast16_t aExp, uint32_t a )
 {
 static const uint16_t sqrtOddAdjustments[] = {
 0x0004, 0x0022, 0x005D, 0x00B1, 0x011D, 0x019F, 0x0236, 0x02E0,
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 08e4ae0..befd400 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -84,7 +84,7 @@ INLINE uint32_t extractFloat16Frac(float16 a)
 | Returns the exponent bits of the half-precision floating-point value `a'.
 **/
 
-INLINE int16 extractFloat16Exp(float16 a)
+INLINE int_fast16_t extractFloat16Exp(float16 a)
 {
 return (float16_val(a)  10)  0x1f;
 }
@@ -215,7 +215,7 @@ INLINE uint32_t extractFloat32Frac( float32 a )
 | Returns the exponent bits of the single-precision floating-point value `a'.
 **/
 
-INLINE int16 extractFloat32Exp( float32 a )
+INLINE int_fast16_t extractFloat32Exp( float32 a )
 {
 
 return ( float32_val(a)23 )  0xFF;
@@ -256,7 +256,7 @@ static float32 float32_squash_input_denormal(float32 a 
STATUS_PARAM)
 **/
 
 static void
- normalizeFloat32Subnormal( uint32_t aSig, int16 *zExpPtr, uint32_t *zSigPtr )
+ 

[Qemu-devel] [PATCH 03/22] qapi: add Error object

2011-03-06 Thread Anthony Liguori
The Error class is similar to QError (now deprecated) except that it supports
propagation.  This allows for higher quality error handling.  It's losely
modeled after glib style GErrors.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile.objs b/Makefile.objs
index 0ba02c7..da31530 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -15,6 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
 block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
+block-obj-y += error.o
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
diff --git a/error.c b/error.c
new file mode 100644
index 000..5d84106
--- /dev/null
+++ b/error.c
@@ -0,0 +1,122 @@
+/*
+ * QEMU Error Objects
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include error.h
+#include error_int.h
+#include qemu-objects.h
+#include qerror.h
+#include assert.h
+
+struct Error
+{
+QDict *obj;
+const char *fmt;
+char *msg;
+};
+
+void error_set(Error **errp, const char *fmt, ...)
+{
+Error *err;
+va_list ap;
+
+if (errp == NULL) {
+return;
+}
+
+err = qemu_mallocz(sizeof(*err));
+
+va_start(ap, fmt);
+err-obj = qobject_to_qdict(qobject_from_jsonv(fmt, ap));
+va_end(ap);
+err-fmt = fmt;
+
+*errp = err;
+}
+
+bool error_is_set(Error **errp)
+{
+return (errp  *errp);
+}
+
+const char *error_get_pretty(Error *err)
+{
+if (err-msg == NULL) {
+QString *str;
+str = qerror_format(err-fmt, err-obj);
+err-msg = qemu_strdup(qstring_get_str(str));
+}
+
+return err-msg;
+}
+
+const char *error_get_field(Error *err, const char *field)
+{
+if (strcmp(field, class) == 0) {
+return qdict_get_str(err-obj, field);
+} else {
+QDict *dict = qdict_get_qdict(err-obj, data);
+return qdict_get_str(dict, field);
+}
+}
+
+void error_free(Error *err)
+{
+QDECREF(err-obj);
+qemu_free(err-msg);
+qemu_free(err);
+}
+
+bool error_is_type(Error *err, const char *fmt)
+{
+char *ptr;
+char *end;
+char classname[1024];
+
+ptr = strstr(fmt, 'class': ');
+assert(ptr != NULL);
+ptr += strlen('class': ');
+
+end = strchr(ptr, '\'');
+assert(end != NULL);
+
+memcpy(classname, ptr, (end - ptr));
+classname[(end - ptr)] = 0;
+
+return strcmp(classname, error_get_field(err, class)) == 0;
+}
+
+void error_propagate(Error **dst_err, Error *local_err)
+{
+if (dst_err) {
+*dst_err = local_err;
+} else if (local_err) {
+error_free(local_err);
+}
+}
+
+QObject *error_get_qobject(Error *err)
+{
+QINCREF(err-obj);
+return QOBJECT(err-obj);
+}
+
+void error_set_qobject(Error **errp, QObject *obj)
+{
+Error *err;
+if (errp == NULL) {
+return;
+}
+err = qemu_mallocz(sizeof(*err));
+err-obj = qobject_to_qdict(obj);
+qobject_incref(obj);
+
+*errp = err;
+}
diff --git a/error.h b/error.h
new file mode 100644
index 000..317d487
--- /dev/null
+++ b/error.h
@@ -0,0 +1,65 @@
+/*
+ * QEMU Error Objects
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#ifndef ERROR_H
+#define ERROR_H
+
+#include stdbool.h
+
+/**
+ * A class representing internal errors within QEMU.  An error has a string
+ * typename and optionally a set of named string parameters.
+ */
+typedef struct Error Error;
+
+/**
+ * Set an indirect pointer to an error given a printf-style format parameter.
+ * Currently, qerror.h defines these error formats.  This function is not
+ * meant to be used outside of QEMU.
+ */
+void error_set(Error **err, const char *fmt, ...)
+__attribute__((format(printf, 2, 3)));
+
+/**
+ * Returns true if an indirect pointer to an error is pointing to a valid
+ * error object.
+ */
+bool error_is_set(Error **err);
+
+/**
+ * Get a human readable representation of an error object.
+ */
+const char *error_get_pretty(Error *err);
+
+/**
+ * Get an individual named error field.
+ */
+const char *error_get_field(Error *err, const char *field);
+
+/**
+ * Propagate an error to an indirect pointer to an error.  This function will
+ * always transfer ownership of the error reference and handles the case where
+ * dst_err is NULL correctly.
+ */
+void error_propagate(Error **dst_err, Error *local_err);
+
+/**
+ * Free an error object.
+ */
+void error_free(Error *err);
+
+/**
+ * Determine if an error is of a speific type (based on the qerror format).
+ * Non-QEMU users should get the `class' field to identify the error type.
+ */
+bool error_is_type(Error *err, 

[Qemu-devel] [PATCH 15/22] qapi: add new QMP server that uses CharDriverState

2011-03-06 Thread Anthony Liguori
This will replace the current QMP server once all the functions are implemented.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qmp-core.c b/qmp-core.c
index 3a6242c..3a4d240 100644
--- a/qmp-core.c
+++ b/qmp-core.c
@@ -44,6 +44,15 @@ struct QmpState
 QTAILQ_HEAD(, DefaultQmpConnection) default_connections;
 };
 
+typedef struct QmpSession
+{
+JSONMessageParser parser;
+QmpState state;
+CharDriverState *chr;
+int max_global_handle;
+QTAILQ_HEAD(, QmpConnection) connections;
+} QmpSession;
+
 static QTAILQ_HEAD(, QmpCommand) qmp_commands =
 QTAILQ_HEAD_INITIALIZER(qmp_commands);
 
@@ -67,6 +76,18 @@ void qmp_register_stateful_command(const char *name, 
QmpStatefulCommandFunc *fn)
 QTAILQ_INSERT_TAIL(qmp_commands, cmd, node);
 }
 
+static QmpCommand *qmp_find_command(const char *name)
+{
+QmpCommand *i;
+
+QTAILQ_FOREACH(i, qmp_commands, node) {
+if (strcmp(i-name, name) == 0) {
+return i;
+}
+}
+return NULL;
+}
+
 char *qobject_as_string(QObject *obj)
 {
 char buffer[1024];
@@ -178,3 +199,197 @@ void qmp_signal_disconnect(QmpSignal *obj, int handle)
 }
 }
 }
+
+static QObject *qmp_dispatch_err(QmpState *state, QList *tokens, Error **errp)
+{
+const char *command;
+QDict *args, *dict;
+QObject *request;
+QmpCommand *cmd;
+QObject *ret = NULL;
+Error *err = NULL;
+
+request = json_parser_parse_err(tokens, NULL, err);
+if (request == NULL) {
+if (err == NULL) {
+error_set(errp, QERR_JSON_PARSE_ERROR, no valid JSON object);
+} else {
+error_propagate(errp, err);
+}
+return NULL;
+}
+if (qobject_type(request) != QTYPE_QDICT) {
+error_set(errp, QERR_JSON_PARSE_ERROR, request is not a dictionary);
+return NULL;
+}
+
+dict = qobject_to_qdict(request);
+if (!qdict_haskey(dict, execute)) {
+error_set(errp, QERR_JSON_PARSE_ERROR, no execute key);
+return NULL;
+}
+
+command = qdict_get_str(dict, execute);
+cmd = qmp_find_command(command);
+if (cmd == NULL) {
+error_set(errp, QERR_COMMAND_NOT_FOUND, command);
+return NULL;
+}
+
+if (!qdict_haskey(dict, arguments)) {
+args = qdict_new();
+} else {
+args = qdict_get_qdict(dict, arguments);
+QINCREF(args);
+}
+
+if (cmd-stateful) {
+cmd-sfn(state, args, ret, errp);
+} else {
+cmd-fn(args, ret, errp);
+}
+
+QDECREF(args);
+qobject_decref(request);
+
+return ret;
+}
+
+static QObject *qmp_dispatch(QmpState *state, QList *tokens)
+{
+Error *err = NULL;
+QObject *ret;
+QDict *rsp;
+
+ret = qmp_dispatch_err(state, tokens, err);
+
+rsp = qdict_new();
+if (err) {
+qdict_put_obj(rsp, error, error_get_qobject(err));
+error_free(err);
+} else {
+if (ret) {
+qdict_put_obj(rsp, return, ret);
+} else {
+qdict_put(rsp, return, qdict_new());
+}
+}
+
+return QOBJECT(rsp);
+}
+
+static void qmp_chr_parse(JSONMessageParser *parser, QList *tokens)
+{
+QmpSession *s = container_of(parser, QmpSession, parser);
+QObject *rsp;
+QString *str;
+
+rsp = qmp_dispatch(s-state, tokens);
+
+str = qobject_to_json(rsp);
+qemu_chr_write(s-chr, (void *)str-string, str-length);
+qemu_chr_write(s-chr, (void *)\n, 1);
+
+QDECREF(str);
+qobject_decref(rsp);
+}
+
+static int qmp_chr_can_receive(void *opaque)
+{
+return 1024;
+}
+
+static void qmp_chr_receive(void *opaque, const uint8_t *buf, int size)
+{
+QmpSession *s = opaque;
+json_message_parser_feed(s-parser, (char *)buf, size);
+}
+
+static void qmp_chr_send_greeting(QmpSession *s)
+{
+VersionInfo *info;
+QObject *vers;
+QObject *greeting;
+QString *str;
+
+info = qmp_query_version(NULL);
+vers = qmp_marshal_type_VersionInfo(info);
+qmp_free_version_info(info);
+
+greeting = qobject_from_jsonf({'QMP': {'version': %p, 'capabilities': []} 
},
+  vers);
+str = qobject_to_json(greeting);
+qobject_decref(greeting);
+
+qemu_chr_write(s-chr, (void *)str-string, str-length);
+qemu_chr_write(s-chr, (void *)\n, 1);
+QDECREF(str);
+}
+
+static void qmp_chr_event(void *opaque, int event)
+{
+QmpSession *s = opaque;
+switch (event) {
+case CHR_EVENT_OPENED:
+// FIXME disconnect any connected signals including defaults
+json_message_parser_init(s-parser, qmp_chr_parse);
+qmp_chr_send_greeting(s);
+break;
+case CHR_EVENT_CLOSED:
+json_message_parser_flush(s-parser);
+break;
+}
+}
+
+static int qmp_chr_add_connection(QmpState *state,  QmpConnection *conn)
+{
+QmpSession *s = container_of(state, QmpSession, state);
+
+QTAILQ_INSERT_TAIL(s-connections, conn, node);
+return ++s-max_global_handle;
+}
+

[Qemu-devel] [PATCH 12/22] qapi: add QAPI module type

2011-03-06 Thread Anthony Liguori
This lets us register marshaling handlers using a module init function.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/module.h b/module.h
index 9263f1c..ef66730 100644
--- a/module.h
+++ b/module.h
@@ -24,12 +24,14 @@ typedef enum {
 MODULE_INIT_BLOCK,
 MODULE_INIT_DEVICE,
 MODULE_INIT_MACHINE,
+MODULE_INIT_QAPI,
 MODULE_INIT_MAX
 } module_init_type;
 
 #define block_init(function) module_init(function, MODULE_INIT_BLOCK)
 #define device_init(function) module_init(function, MODULE_INIT_DEVICE)
 #define machine_init(function) module_init(function, MODULE_INIT_MACHINE)
+#define qapi_init(function) module_init(function, MODULE_INIT_QAPI)
 
 void register_module_init(void (*fn)(void), module_init_type type);
 
diff --git a/vl.c b/vl.c
index b436952..68c6715 100644
--- a/vl.c
+++ b/vl.c
@@ -1966,6 +1966,8 @@ int main(int argc, char **argv, char **envp)
 cyls = heads = secs = 0;
 translation = BIOS_ATA_TRANSLATION_AUTO;
 
+module_call_init(MODULE_INIT_QAPI);
+
 for (i = 0; i  MAX_NODES; i++) {
 node_mem[i] = 0;
 node_cpumask[i] = 0;
-- 
1.7.0.4




[Qemu-devel] [PATCH 07/22] json: propagate error from parser

2011-03-06 Thread Anthony Liguori
Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/json-parser.c b/json-parser.c
index 6c06ef9..ac4063a 100644
--- a/json-parser.c
+++ b/json-parser.c
@@ -22,9 +22,11 @@
 #include qbool.h
 #include json-parser.h
 #include json-lexer.h
+#include qerror.h
 
 typedef struct JSONParserContext
 {
+Error *err;
 } JSONParserContext;
 
 #define BUG_ON(cond) assert(!(cond))
@@ -95,11 +97,15 @@ static void GCC_FMT_ATTR(3, 4) 
parse_error(JSONParserContext *ctxt,
QObject *token, const char *msg, 
...)
 {
 va_list ap;
+char message[1024];
 va_start(ap, msg);
-fprintf(stderr, parse error: );
-vfprintf(stderr, msg, ap);
-fprintf(stderr, \n);
+vsnprintf(message, sizeof(message), msg, ap);
 va_end(ap);
+if (ctxt-err) {
+error_free(ctxt-err);
+ctxt-err = NULL;
+}
+error_set(ctxt-err, QERR_JSON_PARSE_ERROR, message);
 }
 
 /**
@@ -565,6 +571,11 @@ static QObject *parse_value(JSONParserContext *ctxt, QList 
**tokens, va_list *ap
 
 QObject *json_parser_parse(QList *tokens, va_list *ap)
 {
+return json_parser_parse_err(tokens, ap, NULL);
+}
+
+QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp)
+{
 JSONParserContext ctxt = {};
 QList *working = qlist_copy(tokens);
 QObject *result;
@@ -573,5 +584,7 @@ QObject *json_parser_parse(QList *tokens, va_list *ap)
 
 QDECREF(working);
 
+error_propagate(errp, ctxt.err);
+
 return result;
 }
diff --git a/json-parser.h b/json-parser.h
index 97f43f6..8f2b5ec 100644
--- a/json-parser.h
+++ b/json-parser.h
@@ -16,7 +16,9 @@
 
 #include qemu-common.h
 #include qlist.h
+#include error.h
 
 QObject *json_parser_parse(QList *tokens, va_list *ap);
+QObject *json_parser_parse_err(QList *tokens, va_list *ap, Error **errp);
 
 #endif
-- 
1.7.0.4




[Qemu-devel] [PATCH 06/22] qapi: add JSON parsing error message

2011-03-06 Thread Anthony Liguori
Using a string like this is a cop-out.  I plan on changing this before 0.15.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qerror.c b/qerror.c
index 5a1e637..c12dd3d 100644
--- a/qerror.c
+++ b/qerror.c
@@ -145,6 +145,10 @@ static const QErrorStringTable qerror_table[] = {
 .desc  = Invalid JSON syntax,
 },
 {
+.error_fmt = QERR_JSON_PARSE_ERROR,
+.desc  = Error parsing JSON: %(message),
+},
+{
 .error_fmt = QERR_KVM_MISSING_CAP,
 .desc  = Using KVM without %(capability), %(feature) unavailable,
 },
diff --git a/qerror.h b/qerror.h
index 35e7253..a0fb98d 100644
--- a/qerror.h
+++ b/qerror.h
@@ -125,6 +125,9 @@ void qerror_set_desc(QError *qerr, const char *fmt);
 #define QERR_JSON_PARSING \
 { 'class': 'JSONParsing', 'data': {} }
 
+#define QERR_JSON_PARSE_ERROR \
+{ 'class': 'JSONParseError', 'data': { 'message': %s } }
+
 #define QERR_KVM_MISSING_CAP \
 { 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }
 
-- 
1.7.0.4




[Qemu-devel] [PATCH 14/22] qapi: add query-version QMP command

2011-03-06 Thread Anthony Liguori
This is used internally by QMP.  It's also a pretty good example of a typical
command conversion.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile.objs b/Makefile.objs
index 5dae800..e1a2756 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -103,7 +103,7 @@ common-obj-y += block-migration.o
 common-obj-y += pflib.o
 common-obj-y += bitmap.o bitops.o
 common-obj-y += qmp-marshal-types.o qmp-marshal-types-core.o
-common-obj-y += qmp-core.o qmp-marshal.o
+common-obj-y += qmp-core.o qmp-marshal.o qmp.o
 
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
diff --git a/qmp-schema.json b/qmp-schema.json
index e69de29..b343f5e 100644
--- a/qmp-schema.json
+++ b/qmp-schema.json
@@ -0,0 +1,38 @@
+# *-*- Mode: Python -*-*
+### 0.14.0 commands.  Do not modify. ###
+
+##
+# @VersionInfo:
+#
+# A description of QEMU's version.
+#
+# @qemu.major:  The major version of QEMU
+#
+# @qemu.minor:  The minor version of QEMU
+#
+# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
+#   version of 50 signifies a development branch.  A micro version
+#   greater than or equal to 90 signifies a release candidate for
+#   the next minor version.  A micro version of less than 50
+#   signifies a stable release.
+#
+# @package: QEMU will always set this field to an empty string.  Downstream
+#   versions of QEMU should set this to a non-empty string.  The
+#   exact format depends on the downstream however it highly
+#   recommended that a unique name is used.
+#
+# Since: 0.14.0
+##
+{ 'VersionInfo': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
+  'package': 'str'} }
+
+##
+# @query-version:
+#
+# Returns the current version of QEMU.
+#
+# Returns:  A @VersionInfo object describing the current version of QEMU.
+#
+# Since: 0.14.0
+##
+[ 'query-version', {}, {}, 'VersionInfo' ]
diff --git a/qmp.c b/qmp.c
new file mode 100644
index 000..7b626f5
--- /dev/null
+++ b/qmp.c
@@ -0,0 +1,31 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include qemu-common.h
+#include qmp-core.h
+#include qmp.h
+
+VersionInfo *qmp_query_version(Error **err)
+{
+VersionInfo *info = qmp_alloc_version_info();
+const char *version = QEMU_VERSION;
+char *tmp;
+
+info-qemu.major = strtol(version, tmp, 10);
+tmp++;
+info-qemu.minor = strtol(tmp, tmp, 10);
+tmp++;
+info-qemu.micro = strtol(tmp, tmp, 10);
+info-package = qemu_strdup(QEMU_PKGVERSION);
+
+return info;
+}
+
-- 
1.7.0.4




[Qemu-devel] [PATCH 11/22] qapi: add signal support to core QMP server

2011-03-06 Thread Anthony Liguori
Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qmp-core.c b/qmp-core.c
index 78aef3a..3a6242c 100644
--- a/qmp-core.c
+++ b/qmp-core.c
@@ -28,6 +28,22 @@ typedef struct QmpCommand
 QTAILQ_ENTRY(QmpCommand) node;
 } QmpCommand;
 
+typedef struct DefaultQmpConnection
+{
+QmpSignal *obj;
+int handle;
+QTAILQ_ENTRY(DefaultQmpConnection) node;
+} DefaultQmpConnection;
+
+struct QmpState
+{
+int (*add_connection)(QmpState *s, QmpConnection *conn);
+void (*del_connection)(QmpState *s, int global_handle, Error **errp);
+void (*event)(QmpState *s, QObject *data);
+
+QTAILQ_HEAD(, DefaultQmpConnection) default_connections;
+};
+
 static QTAILQ_HEAD(, QmpCommand) qmp_commands =
 QTAILQ_HEAD_INITIALIZER(qmp_commands);
 
@@ -75,3 +91,90 @@ char *qobject_as_string(QObject *obj)
 return NULL;
 }
 }
+
+void qmp_state_add_connection(QmpState *sess, const char *event_name, 
QmpSignal *obj, int handle, QmpConnection *conn)
+{
+conn-state = sess;
+conn-event_name = event_name;
+conn-signal = obj;
+conn-handle = handle;
+conn-global_handle = sess-add_connection(sess, conn);
+}
+
+void qmp_state_del_connection(QmpState *sess, int global_handle, Error **errp)
+{
+sess-del_connection(sess, global_handle, errp);
+}
+
+void qmp_state_event(QmpConnection *conn, QObject *data)
+{
+QDict *event = qdict_new();
+qemu_timeval tv;
+QObject *ts;
+
+qemu_gettimeofday(tv);
+
+ts = qobject_from_jsonf({ 'seconds': % PRId64 , 
+'microseconds': % PRId64  },
+(int64_t)tv.tv_sec, (int64_t)tv.tv_usec);
+qdict_put_obj(event, timestamp, ts);
+
+qdict_put(event, event, qstring_from_str(conn-event_name));
+if (data) {
+qobject_incref(data);
+qdict_put_obj(event, data, data);
+}
+
+qdict_put(event, tag, qint_from_int(conn-global_handle));
+
+conn-state-event(conn-state, QOBJECT(event));
+QDECREF(event);
+}
+
+QmpSignal *qmp_signal_init(void)
+{
+QmpSignal *obj = qemu_mallocz(sizeof(*obj));
+obj-max_handle = 0;
+obj-ref = 1;
+QTAILQ_INIT(obj-slots);
+return obj;
+}
+
+void qmp_signal_ref(QmpSignal *obj)
+{
+obj-ref++;
+}
+
+void qmp_signal_unref(QmpSignal *obj)
+{
+if (--obj-ref) {
+qemu_free(obj);
+}
+}
+
+int qmp_signal_connect(QmpSignal *obj, void *func, void *opaque)
+{
+int handle = ++obj-max_handle;
+QmpSlot *slot = qemu_mallocz(sizeof(*slot));
+
+slot-handle = handle;
+slot-func = func;
+slot-opaque = opaque;
+
+QTAILQ_INSERT_TAIL(obj-slots, slot, node);
+
+return handle;
+}
+
+void qmp_signal_disconnect(QmpSignal *obj, int handle)
+{
+QmpSlot *slot;
+
+QTAILQ_FOREACH(slot, obj-slots, node) {
+if (slot-handle == handle) {
+QTAILQ_REMOVE(obj-slots, slot, node);
+qemu_free(slot);
+break;
+}
+}
+}
diff --git a/qmp-core.h b/qmp-core.h
index e3235ec..5ce02f7 100644
--- a/qmp-core.h
+++ b/qmp-core.h
@@ -21,10 +21,65 @@ typedef struct QmpState QmpState;
 typedef void (QmpCommandFunc)(const QDict *, QObject **, Error **);
 typedef void (QmpStatefulCommandFunc)(QmpState *qmp__sess, const QDict *, 
QObject **, Error **);
 
+typedef struct QmpSlot
+{
+int handle;
+void *func;
+void *opaque;
+QTAILQ_ENTRY(QmpSlot) node;
+} QmpSlot;
+
+struct QmpSignal
+{
+int max_handle;
+int ref;
+QTAILQ_HEAD(, QmpSlot) slots;
+};
+
+typedef struct QmpConnection
+{
+QmpState *state;
+const char *event_name;
+QmpSignal *signal;
+int handle;
+int global_handle;
+QTAILQ_ENTRY(QmpConnection) node;
+} QmpConnection;
+
 void qmp_register_command(const char *name, QmpCommandFunc *fn);
 void qmp_register_stateful_command(const char *name, QmpStatefulCommandFunc 
*fn);
 void qmp_init_chardev(CharDriverState *chr);
 
 char *qobject_as_string(QObject *obj);
 
+QmpSignal *qmp_signal_init(void);
+void qmp_signal_ref(QmpSignal *obj);
+void qmp_signal_unref(QmpSignal *obj);
+int qmp_signal_connect(QmpSignal *obj, void *func, void *opaque);
+void qmp_signal_disconnect(QmpSignal *obj, int handle);
+
+void qmp_state_add_connection(QmpState *sess, const char *name, QmpSignal 
*obj, int handle, QmpConnection *conn);
+void qmp_state_del_connection(QmpState *sess, int global_handle, Error **errp);
+void qmp_state_event(QmpConnection *conn, QObject *data);
+
+#define signal_init(obj) do {  \
+(obj)-signal = qmp_signal_init(); \
+} while (0)
+
+#define signal_unref(obj) qmp_signal_unref((obj)-signal)
+
+#define signal_connect(obj, fn, opaque) \
+qmp_signal_connect((obj)-signal, (obj)-func = fn, opaque)
+
+#define signal_disconnect(obj, handle) \
+qmp_signal_disconnect((obj)-signal, handle)
+
+#define signal_notify(obj, ...) do { \
+QmpSlot *qmp__slot;  \
+QTAILQ_FOREACH(qmp__slot, (obj)-signal-slots, node) { \
+

[Qemu-devel] [PATCH 13/22] qapi: add code generators for QMP command marshaling

2011-03-06 Thread Anthony Liguori
This generates qmp.h which contains the declarations of all of QMP functions
to be dispatched, plus a function that registers marshallers for each of
the QMP functions.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 8f3a4d3..47a755d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
-GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h
+GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -159,8 +159,15 @@ qmp-marshal-types.c: $(SRC_PATH)/qmp-schema.json 
$(SRC_PATH)/qmp-gen.py
 qmp-marshal-types.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
$(call quiet-command,python $(SRC_PATH)/qmp-gen.py --marshal-header  
$  $@,   GEN   $@)
 
+qmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --header  $  $@, 
  GEN   $@)
+
+qmp-marshal.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --body  $  $@,   
GEN   $@)
+
 qmp-types.o: qmp-types.c qmp-types.h
 qmp-marshal-types.o: qmp-marshal-types.c qmp-marshal-types.h qmp-types.h
+qmp-marshal.o: qmp-marshal.c qmp.h qmp-types.h qmp-marshal-types.h
 
 version.o: $(SRC_PATH)/version.rc config-host.mak
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)
diff --git a/Makefile.objs b/Makefile.objs
index dbdce3c..5dae800 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -103,7 +103,7 @@ common-obj-y += block-migration.o
 common-obj-y += pflib.o
 common-obj-y += bitmap.o bitops.o
 common-obj-y += qmp-marshal-types.o qmp-marshal-types-core.o
-common-obj-y += qmp-core.o
+common-obj-y += qmp-core.o qmp-marshal.o
 
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
diff --git a/qmp-gen.py b/qmp-gen.py
index 8adcc2b..aac0f90 100644
--- a/qmp-gen.py
+++ b/qmp-gen.py
@@ -429,6 +429,227 @@ QObject *qmp_marshal_type_%s(%s value)
 }
 ''' % (name, name, name)
 
+def print_declaration(name, required, optional, retval):
+args = []
+if name in ['qmp_capabilities', 'put-event']:
+return
+for key in required:
+args.append('%s %s' % (qmp_type_to_c(required[key]), c_var(key)))
+
+for key in optional:
+if optional[key] == '**':
+args.append('KeyValues * %s' % c_var(key))
+else:
+args.append('bool has_%s' % c_var(key))
+args.append('%s %s' % (qmp_type_to_c(optional[key]), c_var(key)))
+
+args.append('Error **err')
+
+print '%s qmp_%s(%s);' % (qmp_type_to_c(retval, True), c_var(name), ', 
'.join(args))
+
+def print_definition(name, required, optional, retval):
+if qmp_type_is_event(retval):
+arglist = ['void *opaque']
+for member in event_types[retval]:
+argname = c_var(member)
+argtype = event_types[retval][member]
+if argname[0] == '*':
+argname = argname[1:]
+arglist.append('bool has_%s' % argname)
+arglist.append('%s %s' % (qmp_type_to_c(argtype), argname))
+print '''
+static void qmp_marshal_%s(%s)
+{
+QDict *qmp__args = qdict_new();
+QmpConnection *qmp__conn = opaque;
+''' % (qmp_event_to_c(retval), ', '.join(arglist))
+
+for member in event_types[retval]:
+argname = member
+argtype = event_types[retval][member]
+opt = False
+if argname[0] == '*':
+argname = argname[1:]
+opt = True
+if opt:
+print 'if (has_%s) {' % c_var(argname)
+print 'qdict_put_obj(qmp__args, %s, %s(%s));' % 
(argname, qmp_type_to_qobj_ctor(argtype), c_var(argname))
+print '}'
+else:
+print 'qdict_put_obj(qmp__args, %s, %s(%s));' % 
(argname, qmp_type_to_qobj_ctor(argtype), c_var(argname))
+
+print '''
+qmp_state_event(qmp__conn, QOBJECT(qmp__args));
+QDECREF(qmp__args);
+}'''
+print '''
+static void qmp_marshal_%s(QmpState *qmp__sess, const QDict *qdict, QObject 
**ret_data, Error **err)
+{
+int qmp__handle;
+QmpConnection *qmp__connection = qemu_mallocz(sizeof(QmpConnection));''' % 
c_var(name)
+elif name in ['qmp_capabilities', 'put-event']:
+print '''
+static void qmp_marshal_%s(QmpState *qmp__sess, const QDict *qdict, QObject 
**ret_data, Error **err)
+{''' % c_var(name)
+else:
+print '''
+static void qmp_marshal_%s(const QDict *qdict, QObject **ret_data, Error **err)
+{''' % c_var(name)
+print 'Error *qmp__err = NULL;'
+
+for key in required:
+print '%s %s = 0;' % (qmp_type_to_c(required[key], True), 

[Qemu-devel] [PATCH 17/22] qapi: add QMP quit command

2011-03-06 Thread Anthony Liguori
This is needed by the test suite.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qmp-schema.json b/qmp-schema.json
index b343f5e..0581e67 100644
--- a/qmp-schema.json
+++ b/qmp-schema.json
@@ -36,3 +36,15 @@
 # Since: 0.14.0
 ##
 [ 'query-version', {}, {}, 'VersionInfo' ]
+
+##
+# @quit:
+#
+# This command will cause the QEMU process to exit gracefully.  While every
+# attempt is made to send the QMP response before terminating, this is not
+# guaranteed.  When using this interface, a premature EOF would not be
+# unexpected.
+#
+# Since: 0.14.0
+##
+[ 'quit', {}, {}, 'none' ]
diff --git a/qmp.c b/qmp.c
index 7b626f5..837ac95 100644
--- a/qmp.c
+++ b/qmp.c
@@ -12,6 +12,7 @@
 #include qemu-common.h
 #include qmp-core.h
 #include qmp.h
+#include sysemu.h
 
 VersionInfo *qmp_query_version(Error **err)
 {
@@ -29,3 +30,8 @@ VersionInfo *qmp_query_version(Error **err)
 return info;
 }
 
+void qmp_quit(Error **err)
+{
+no_shutdown = 0;
+qemu_system_shutdown_request();
+}
-- 
1.7.0.4




[Qemu-devel] [PATCH 16/22] vl: add a new -qmp2 option to expose experimental QMP server

2011-03-06 Thread Anthony Liguori
This is temporary until we implement all QMP commands.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qemu-options.hx b/qemu-options.hx
index badb730..957d935 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1881,6 +1881,9 @@ serial port).
 The default device is @code{vc} in graphical mode and @code{stdio} in
 non graphical mode.
 ETEXI
+DEF(qmp2, HAS_ARG, QEMU_OPTION_qmp2, \
+-qmp2 chardev   experimental QMP server\n,
+QEMU_ARCH_ALL)
 DEF(qmp, HAS_ARG, QEMU_OPTION_qmp, \
 -qmp devlike -monitor but opens in 'control' mode\n,
 QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index 68c6715..d1d0197 100644
--- a/vl.c
+++ b/vl.c
@@ -162,6 +162,7 @@ int main(int argc, char **argv)
 #include qemu-queue.h
 #include cpus.h
 #include arch_init.h
+#include qmp-core.h
 
 #include ui/qemu-spice.h
 
@@ -1917,6 +1918,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
 return popt;
 }
 
+#define MAX_QMP_CHARDEVS 16
+
 int main(int argc, char **argv, char **envp)
 {
 const char *gdbstub_dev = NULL;
@@ -1941,6 +1944,8 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 int show_vnc_port = 0;
 int defconfig = 1;
+int nb_qmp_chardevs = 0;
+const char *qmp_chardevs[MAX_QMP_CHARDEVS];
 
 #ifdef CONFIG_SIMPLE_TRACE
 const char *trace_file = NULL;
@@ -2391,6 +2396,13 @@ int main(int argc, char **argv, char **envp)
 monitor_parse(optarg, control);
 default_monitor = 0;
 break;
+case QEMU_OPTION_qmp2:
+if (nb_qmp_chardevs == MAX_QMP_CHARDEVS) {
+fprintf(stderr, -qmp: too many QMP chardevs\n);
+exit(1);
+}
+qmp_chardevs[nb_qmp_chardevs++] = optarg;
+break;
 case QEMU_OPTION_mon:
 opts = qemu_opts_parse(qemu_find_opts(mon), optarg, 1);
 if (!opts) {
@@ -3092,6 +3104,15 @@ int main(int argc, char **argv, char **envp)
 }
 #endif
 
+for (i = 0; i  nb_qmp_chardevs; i++) {
+CharDriverState *chr = qemu_chr_find(qmp_chardevs[i]);
+if (chr == NULL) {
+fprintf(stderr, -qmp: unknown chardev `%s'\n, qmp_chardevs[i]);
+exit(1);
+}
+qmp_init_chardev(chr);
+}
+
 /* display setup */
 dpy_resize(ds);
 dcl = ds-listeners;
-- 
1.7.0.4




[Qemu-devel] [PATCH 19/22] qapi: add QMP put-event command

2011-03-06 Thread Anthony Liguori
This is needed for libqmp to support events.  put-event is used to disconnect
from signals.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qmp-schema.json b/qmp-schema.json
index 3f2dd4e..a13885f 100644
--- a/qmp-schema.json
+++ b/qmp-schema.json
@@ -58,3 +58,18 @@
 # Since: 0.14.0
 ##
 [ 'qmp_capabilities', {}, {}, 'none' ]
+
+##
+# @put_event:
+#
+# Disconnect a signal.  This command is used to disconnect from a signal based
+# on the handle returned by a signal accessor.
+#
+# @tag: the handle returned by a signal accessor.
+#
+# Returns: Nothing on success.
+#  If @tag is not a valid handle, InvalidParameterValue
+#
+# Since: 0.15.0
+##
+[ 'put-event', {'tag': 'int'}, {}, 'none' ]
-- 
1.7.0.4




[Qemu-devel] [PATCH 18/22] qapi: add QMP qmp_capabilities command

2011-03-06 Thread Anthony Liguori
For now, it's a nop.  In the near future, it will be used to register default
signals.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qmp-core.c b/qmp-core.c
index 3a4d240..72e4fea 100644
--- a/qmp-core.c
+++ b/qmp-core.c
@@ -393,3 +393,7 @@ void qmp_init_chardev(CharDriverState *chr)
 qemu_chr_add_handlers(chr, qmp_chr_can_receive, qmp_chr_receive,
   qmp_chr_event, s);
 }
+
+void qmp_qmp_capabilities(QmpState *state, Error **errp)
+{
+}
diff --git a/qmp-core.h b/qmp-core.h
index 808edf3..d15d349 100644
--- a/qmp-core.h
+++ b/qmp-core.h
@@ -82,4 +82,6 @@ void qmp_state_event(QmpConnection *conn, QObject *data);
 
 void qmp_init_chardev(CharDriverState *chr);
 
+void qmp_qmp_capabilities(QmpState *state, Error **errp);
+
 #endif
diff --git a/qmp-schema.json b/qmp-schema.json
index 0581e67..3f2dd4e 100644
--- a/qmp-schema.json
+++ b/qmp-schema.json
@@ -48,3 +48,13 @@
 # Since: 0.14.0
 ##
 [ 'quit', {}, {}, 'none' ]
+
+##
+# @qmp_capabilities:
+#
+# Currently a nop command.  To communicate with older servers, this should be
+# sent first before executing new commands.
+#
+# Since: 0.14.0
+##
+[ 'qmp_capabilities', {}, {}, 'none' ]
-- 
1.7.0.4




[Qemu-devel] [PATCH 04/22] qerror: split out the reporting bits of QError

2011-03-06 Thread Anthony Liguori
These make it very hard to compile QError outside of QEMU.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile.objs b/Makefile.objs
index da31530..69f0383 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -2,7 +2,7 @@
 # QObject
 qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
 qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
-qobject-obj-y += qerror.o
+qobject-obj-y += qerror.o qerror-report.o
 
 ###
 # oslib-obj-y is code depending on the OS (win32 vs posix)
diff --git a/qerror-report.c b/qerror-report.c
new file mode 100644
index 000..1ebb111
--- /dev/null
+++ b/qerror-report.c
@@ -0,0 +1,131 @@
+/*
+ * QError Module
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ *  Luiz Capitulino lcapitul...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+
+#include qemu-common.h
+#include qerror.h
+#include monitor.h
+#include qjson.h
+
+static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
+const char *fmt, ...)
+{
+va_list ap;
+
+fprintf(stderr, qerror: bad call in function '%s':\n, qerr-func);
+fprintf(stderr, qerror: - );
+
+va_start(ap, fmt);
+vfprintf(stderr, fmt, ap);
+va_end(ap);
+
+fprintf(stderr, \nqerror: call at %s:%d\n, qerr-file, qerr-linenr);
+abort();
+}
+
+static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
+   const char *fmt, va_list *va)
+{
+QObject *obj;
+
+obj = qobject_from_jsonv(fmt, va);
+if (!obj) {
+qerror_abort(qerr, invalid format '%s', fmt);
+}
+if (qobject_type(obj) != QTYPE_QDICT) {
+qerror_abort(qerr, error format is not a QDict '%s', fmt);
+}
+
+qerr-error = qobject_to_qdict(obj);
+
+obj = qdict_get(qerr-error, class);
+if (!obj) {
+qerror_abort(qerr, missing 'class' key in '%s', fmt);
+}
+if (qobject_type(obj) != QTYPE_QSTRING) {
+qerror_abort(qerr, 'class' key value should be a QString);
+}
+
+obj = qdict_get(qerr-error, data);
+if (!obj) {
+qerror_abort(qerr, missing 'data' key in '%s', fmt);
+}
+if (qobject_type(obj) != QTYPE_QDICT) {
+qerror_abort(qerr, 'data' key value should be a QDICT);
+}
+}
+
+/**
+ * qerror_from_info(): Create a new QError from error information
+ *
+ * The information consists of:
+ *
+ * - file   the file name of where the error occurred
+ * - linenr the line number of where the error occurred
+ * - func   the function name of where the error occurred
+ * - fmtJSON printf-like dictionary, there must exist keys 'class' and
+ *  'data'
+ * - va va_list of all arguments specified by fmt
+ *
+ * Return strong reference.
+ */
+QError *qerror_from_info(const char *file, int linenr, const char *func,
+ const char *fmt, va_list *va)
+{
+QError *qerr;
+
+qerr = qerror_new();
+loc_save(qerr-loc);
+qerr-linenr = linenr;
+qerr-file = file;
+qerr-func = func;
+
+if (!fmt) {
+qerror_abort(qerr, QDict not specified);
+}
+
+qerror_set_data(qerr, fmt, va);
+qerror_set_desc(qerr, fmt);
+
+return qerr;
+}
+
+/**
+ * qerror_print(): Print QError data
+ *
+ * This function will print the member 'desc' of the specified QError object,
+ * it uses error_report() for this, so that the output is routed to the right
+ * place (ie. stderr or Monitor's device).
+ */
+void qerror_print(QError *qerror)
+{
+QString *qstring = qerror_human(qerror);
+loc_push_restore(qerror-loc);
+error_report(%s, qstring_get_str(qstring));
+loc_pop(qerror-loc);
+QDECREF(qstring);
+}
+
+void qerror_report_internal(const char *file, int linenr, const char *func,
+const char *fmt, ...)
+{
+va_list va;
+QError *qerror;
+
+va_start(va, fmt);
+qerror = qerror_from_info(file, linenr, func, fmt, va);
+va_end(va);
+
+qerror_print(qerror);
+QDECREF(qerror);
+}
+
+
diff --git a/qerror.c b/qerror.c
index 13d53c9..78d3884 100644
--- a/qerror.c
+++ b/qerror.c
@@ -243,39 +243,7 @@ static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError 
*qerr,
 abort();
 }
 
-static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
-   const char *fmt, va_list *va)
-{
-QObject *obj;
-
-obj = qobject_from_jsonv(fmt, va);
-if (!obj) {
-qerror_abort(qerr, invalid format '%s', fmt);
-}
-if (qobject_type(obj) != QTYPE_QDICT) {
-qerror_abort(qerr, error format is not a QDict '%s', fmt);
-}
-
-qerr-error = qobject_to_qdict(obj);
-
-obj = qdict_get(qerr-error, class);
-if (!obj) {
-qerror_abort(qerr, missing 'class' key in '%s', fmt);
-}
-if 

[Qemu-devel] [PATCH 21/22] qapi: add test-libqmp

2011-03-06 Thread Anthony Liguori
This provides a glib-test based testing framework for QMP

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 5170675..1d363d7 100644
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,8 @@ defconfig:
 
 -include config-all-devices.mak
 
+TOOLS += test-libqmp
+
 build-all: $(DOCS) $(TOOLS) recurse-all
 
 config-host.h: config-host.h-timestamp
@@ -205,6 +207,15 @@ check-qlist: check-qlist.o qlist.o qint.o 
$(CHECK_PROG_DEPS)
 check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
 check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS)
 
+LIBQMP_OBJS := qmp-types.o libqmp.o error.o libqmp-core.o
+LIBQMP_OBJS += qmp-marshal-types-core.o qmp-marshal-types.o
+LIBQMP_OBJS += qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o
+LIBQMP_OBJS += qerror.o
+LIBQMP_OBJS += json-streamer.o json-lexer.o json-parser.o
+LIBQMP_OBJS += $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o
+
+test-libqmp: test-libqmp.o $(LIBQMP_OBJS) qemu-timer-common.o
+
 clean:
 # avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
diff --git a/test-libqmp.c b/test-libqmp.c
new file mode 100644
index 000..9b73987
--- /dev/null
+++ b/test-libqmp.c
@@ -0,0 +1,170 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include stdio.h
+#include sys/socket.h
+#include netinet/in.h
+#include netinet/tcp.h
+#include arpa/inet.h
+#include sys/un.h
+#include stdlib.h
+#include glib.h
+#include sys/wait.h
+#include config-host.h
+#include libqmp.h
+#include qerror.h
+
+#define g_assert_noerr(err) g_assert(err == NULL);
+#define g_assert_anyerr(err) g_assert(err != NULL);
+#define g_assert_cmperr(err, op, type) do {   \
+g_assert_anyerr(err);\
+g_assert_cmpstr(error_get_field(err, class), op, type); \
+} while (0)
+
+static pid_t last_qemu_pid = -1;
+
+static QmpSession *qemu(const char *fmt, ...)
+{
+char buffer0[4096];
+char buffer1[4096];
+const char *pid_filename = /tmp/test-libqmp-qemu.pid;
+const char *path = /tmp/test-libqmp-qemu.sock;
+struct sockaddr_un addr;
+va_list ap;
+int ret;
+int fd;
+
+va_start(ap, fmt);
+vsnprintf(buffer0, sizeof(buffer0), fmt, ap);
+va_end(ap);
+
+snprintf(buffer1, sizeof(buffer1),
+ i386-softmmu/qemu 
+ -enable-kvm 
+ -name test-libqmp 
+ -qmp2 qmp 
+ -chardev socket,id=qmp,path=%s,server=on,wait=off 
+ -vnc none 
+ -daemonize 
+ -pidfile %s 
+ %s, path, pid_filename, buffer0);
+g_test_message(Executing %s\n, buffer1);
+ret = system(buffer1);
+g_assert(ret != -1);
+
+{
+FILE *f;
+char buffer[1024];
+char *ptr;
+
+f = fopen(pid_filename, r);
+g_assert(f != NULL);
+
+ptr = fgets(buffer, sizeof(buffer), f);
+g_assert(ptr != NULL);
+
+fclose(f);
+
+last_qemu_pid = atoi(buffer);
+}
+
+fd = socket(PF_UNIX, SOCK_STREAM, 0);
+g_assert(fd != -1);
+
+addr.sun_family = AF_UNIX;
+snprintf(addr.sun_path, sizeof(addr.sun_path), %s, path);
+ret = connect(fd, (struct sockaddr *)addr, sizeof(addr));
+g_assert(ret != -1);
+
+return qmp_session_new(fd);
+}
+
+static void wait_for_pid_exit(pid_t pid)
+{
+FILE *f = NULL;
+
+/* This is ugly but I don't know of a better way */
+do {
+char buffer[1024];
+
+if (f) {
+fclose(f);
+usleep(1);
+}
+
+snprintf(buffer, sizeof(buffer), /proc/%d/stat, pid);
+f = fopen(buffer, r);
+} while (f);
+}
+
+static void qemu_destroy(QmpSession *sess)
+{
+wait_for_pid_exit(last_qemu_pid);
+last_qemu_pid = -1;
+qmp_session_destroy(sess);
+}
+
+static void test_version(void)
+{
+QmpSession *sess = NULL;
+VersionInfo *info;
+char version[1024];
+char *ptr, *end;
+int major, minor, micro;
+
+/* Even though we use the same string as the source input, we do parse it
+ * a little bit different for no other reason that to make sure we catch
+ * potential bugs.
+ */
+snprintf(version, sizeof(version), %s, QEMU_VERSION);
+ptr = version;
+
+end = strchr(ptr, '.');
+g_assert(end != NULL);
+*end = 0;
+major = atoi(ptr);
+ptr = end + 1;
+
+end = strchr(ptr, '.');
+g_assert(end != NULL);
+*end = 0;
+minor = atoi(ptr);
+ptr = end + 1;
+
+micro = atoi(ptr);
+while (g_ascii_isdigit(*ptr)) ptr++;
+
+sess = qemu(-S);
+
+info = libqmp_query_version(sess, NULL);
+
+   

[Qemu-devel] [PATCH 02/22] qerror: expose a function to format an error

2011-03-06 Thread Anthony Liguori
This will let Error share the QError human formatting.  This is only used for
HMP.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/qerror.c b/qerror.c
index 4855604..13d53c9 100644
--- a/qerror.c
+++ b/qerror.c
@@ -326,12 +326,18 @@ QError *qerror_from_info(const char *file, int linenr, 
const char *func,
 return qerr;
 }
 
-static void parse_error(const QError *qerror, int c)
+static void parse_error(const QErrorStringTable *entry, int c)
 {
-qerror_abort(qerror, expected '%c' in '%s', c, qerror-entry-desc);
+#if 0
+qerror_abort(qerror, expected '%c' in '%s', c, entry-desc);
+#else
+fprintf(stderr, expected '%c' in '%s', c, entry-desc);
+abort();
+#endif
 }
 
-static const char *append_field(QString *outstr, const QError *qerror,
+static const char *append_field(QDict *error, QString *outstr,
+const QErrorStringTable *entry,
 const char *start)
 {
 QObject *obj;
@@ -339,24 +345,31 @@ static const char *append_field(QString *outstr, const 
QError *qerror,
 QString *key_qs;
 const char *end, *key;
 
-if (*start != '%')
-parse_error(qerror, '%');
+if (*start != '%') {
+parse_error(entry, '%');
+}
 start++;
-if (*start != '(')
-parse_error(qerror, '(');
+if (*start != '(') {
+parse_error(entry, '(');
+}
 start++;
 
 end = strchr(start, ')');
-if (!end)
-parse_error(qerror, ')');
+if (!end) {
+parse_error(entry, ')');
+}
 
 key_qs = qstring_from_substr(start, 0, end - start - 1);
 key = qstring_get_str(key_qs);
 
-qdict = qobject_to_qdict(qdict_get(qerror-error, data));
+qdict = qobject_to_qdict(qdict_get(error, data));
 obj = qdict_get(qdict, key);
 if (!obj) {
+#if 0
 qerror_abort(qerror, key '%s' not found in QDict, key);
+#else
+abort();
+#endif
 }
 
 switch (qobject_type(obj)) {
@@ -367,41 +380,66 @@ static const char *append_field(QString *outstr, const 
QError *qerror,
 qstring_append_int(outstr, qdict_get_int(qdict, key));
 break;
 default:
+#if 0
 qerror_abort(qerror, invalid type '%c', qobject_type(obj));
+#else
+abort();
+#endif
 }
 
 QDECREF(key_qs);
 return ++end;
 }
 
-/**
- * qerror_human(): Format QError data into human-readable string.
- *
- * Formats according to member 'desc' of the specified QError object.
- */
-QString *qerror_human(const QError *qerror)
+static QString *qerror_format_desc(QDict *error,
+   const QErrorStringTable *entry)
 {
-const char *p;
 QString *qstring;
+const char *p;
 
-assert(qerror-entry != NULL);
+assert(entry != NULL);
 
 qstring = qstring_new();
 
-for (p = qerror-entry-desc; *p != '\0';) {
+for (p = entry-desc; *p != '\0';) {
 if (*p != '%') {
 qstring_append_chr(qstring, *p++);
 } else if (*(p + 1) == '%') {
 qstring_append_chr(qstring, '%');
 p += 2;
 } else {
-p = append_field(qstring, qerror, p);
+p = append_field(error, qstring, entry, p);
 }
 }
 
 return qstring;
 }
 
+QString *qerror_format(const char *fmt, QDict *error)
+{
+const QErrorStringTable *entry = NULL;
+int i;
+
+for (i = 0; qerror_table[i].error_fmt; i++) {
+if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
+entry = qerror_table[i];
+break;
+}
+}
+
+return qerror_format_desc(error, entry);
+}
+
+/**
+ * qerror_human(): Format QError data into human-readable string.
+ *
+ * Formats according to member 'desc' of the specified QError object.
+ */
+QString *qerror_human(const QError *qerror)
+{
+return qerror_format_desc(qerror-error, qerror-entry);
+}
+
 /**
  * qerror_print(): Print QError data
  *
diff --git a/qerror.h b/qerror.h
index f732d45..fd63ee9 100644
--- a/qerror.h
+++ b/qerror.h
@@ -42,6 +42,7 @@ void qerror_report_internal(const char *file, int linenr, 
const char *func,
 #define qerror_report(fmt, ...) \
 qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
 QError *qobject_to_qerror(const QObject *obj);
+QString *qerror_format(const char *fmt, QDict *error);
 
 /*
  * QError class list
-- 
1.7.0.4




[Qemu-devel] [PATCH 20/22] qapi: add code generator for libqmp

2011-03-06 Thread Anthony Liguori
Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 47a755d..5170675 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
-GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h
+GENERATED_HEADERS += qmp-types.h qmp-marshal-types.h qmp.h libqmp.h
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -165,9 +165,16 @@ qmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
 qmp-marshal.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
$(call quiet-command,python $(SRC_PATH)/qmp-gen.py --body  $  $@,   
GEN   $@)
 
+libqmp.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-header  $  
$@,   GEN   $@)
+
+libqmp.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --lib-body  $  
$@,   GEN   $@)
+
 qmp-types.o: qmp-types.c qmp-types.h
 qmp-marshal-types.o: qmp-marshal-types.c qmp-marshal-types.h qmp-types.h
 qmp-marshal.o: qmp-marshal.c qmp.h qmp-types.h qmp-marshal-types.h
+libqmp.o: libqmp.c libqmp.h qmp-types.h
 
 version.o: $(SRC_PATH)/version.rc config-host.mak
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)
diff --git a/libqmp-core.c b/libqmp-core.c
new file mode 100644
index 000..4613d4f
--- /dev/null
+++ b/libqmp-core.c
@@ -0,0 +1,361 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.  See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include libqmp.h
+#include libqmp-internal.h
+#include libqmp-core.h
+#include json-streamer.h
+#include json-parser.h
+#include dirent.h
+#include sys/socket.h
+#include sys/un.h
+#include assert.h
+
+#ifndef container_of
+#define offset_of(type, field) \
+((unsigned long)(((type *)0)-field))
+#define container_of(obj, type, field) \
+((type *)(((char *)obj) - offsetof(type, field)))
+#endif
+
+//#define DEBUG_LIBQMP 1
+
+typedef struct FdQmpSession
+{
+QmpSession session;
+JSONMessageParser parser;
+QObject *result;
+bool got_greeting;
+int fd;
+int event_count;
+} FdQmpSession;
+
+static EventTrampolineFunc *get_event_trampoline(QmpSession *sess, const char 
*name)
+{
+QmpEventTrampoline *t;
+
+QTAILQ_FOREACH(t, sess-events, node) {
+if (strcmp(t-name, name) == 0) {
+return t-dispatch;
+}
+}
+
+return NULL;
+}
+
+static void fd_qmp_session_process_event(FdQmpSession *fs, QDict *response)
+{
+EventTrampolineFunc *tramp;
+QmpSignal *signal;
+const char *event;
+int tag;
+
+event = qdict_get_str(response, event);
+tramp = get_event_trampoline(fs-session, event);
+
+fs-event_count++;
+
+if (tramp  qdict_haskey(response, tag)) {
+tag = qdict_get_int(response, tag);
+
+QTAILQ_FOREACH(signal, fs-session.signals, node) {
+if (signal-global_handle == tag) {
+QmpConnection *conn;
+QDict *args = NULL;
+Error *err = NULL;
+
+if (qdict_haskey(response, data)) {
+args = qobject_to_qdict(qdict_get(response, data));
+}
+
+QTAILQ_FOREACH(conn, signal-connections, node) {
+tramp(args, conn-fn, conn-opaque, err);
+if (err) {
+error_free(err);
+}
+}
+
+break;
+}
+}
+}
+}
+
+static void fd_qmp_session_parse(JSONMessageParser *parser, QList *tokens)
+{
+FdQmpSession *fs = container_of(parser, FdQmpSession, parser);
+QObject *result;
+
+result = json_parser_parse(tokens, NULL);
+if (!fs-got_greeting) {
+fs-got_greeting = true;
+qobject_decref(result);
+} else {
+QDict *response = qobject_to_qdict(result);
+if (qdict_haskey(response, event)) {
+fd_qmp_session_process_event(fs, response);
+qobject_decref(result);
+} else {
+qobject_decref(fs-result);
+fs-result = result;
+}
+}
+}
+
+static QDict *fd_qmp_session_read(FdQmpSession *fs)
+{
+QDict *response;
+
+assert(fs-result == NULL);
+fs-result = NULL;
+while (!fs-result) {
+char buffer[1024];
+ssize_t len;
+
+len = read(fs-fd, buffer, sizeof(buffer));
+if (len == -1  errno == EINTR) {
+continue;
+}
+if (len  1) {
+abort();
+}
+
+#if defined(DEBUG_LIBQMP)
+fwrite(buffer, len, 1, stdout);
+fflush(stdout);
+#endif
+json_message_parser_feed(fs-parser, buffer, len);
+}

[Qemu-devel] [PATCH 00/22] QAPI Round 1

2011-03-06 Thread Anthony Liguori
This is the first round of QAPI.  This lays all the basic ground work for QAPI
including a client library, new server, and new signal/slot mechanism.

The QAPI development branch contains conversions of every 0.14 QMP command and
also converts all possible HMP commands to use the QMP versions of these
commands.

The bulk of QAPI is generated by a JSON schema using a Python code generator.
The test suite is based on glib.

Reviewing the code generator is hard.  I'll reply to each note with the code
generator output to show what kind of code actually is generated.

This series adds an unconditional build dependency on Python and glib.

More information about QAPI can be found on the wiki:

http://wiki.qemu.org/Features/QAPI




[Qemu-devel] [PATCH] qapi: qmp-types.c and qmp-types.h

2011-03-06 Thread Anthony Liguori
These are generated type functions.  This file will not be committed but is
included to help review.

diff --git a/qmp-types.c b/qmp-types.c
new file mode 100644
index 000..3162265
--- /dev/null
+++ b/qmp-types.c
@@ -0,0 +1,22 @@
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT */
+
+#include qmp-types.h
+#include qemu-common.h
+
+
+void qmp_free_version_info(VersionInfo *obj)
+{
+if (!obj) {
+return;
+}
+qemu_free(obj-package);
+
+qmp_free_version_info(obj-next);
+qemu_free(obj);
+}
+
+VersionInfo *qmp_alloc_version_info(void)
+{
+BUILD_ASSERT(sizeof(VersionInfo)  512);
+return qemu_mallocz(512);
+}
diff --git a/qmp-types.h b/qmp-types.h
new file mode 100644
index 000..e6a4c8c
--- /dev/null
+++ b/qmp-types.h
@@ -0,0 +1,22 @@
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT */
+#ifndef QMP_TYPES_H
+#define QMP_TYPES_H
+
+#include qmp-types-core.h
+
+
+
+typedef struct VersionInfo VersionInfo;
+struct VersionInfo {
+struct {
+int64_t major;
+int64_t minor;
+int64_t micro;
+} qemu;
+char * package;
+VersionInfo *next;
+};
+
+VersionInfo *qmp_alloc_version_info(void);
+void qmp_free_version_info(VersionInfo *obj);
+#endif
-- 
1.7.0.4




[Qemu-devel] [PATCH 22/22] qapi: generate HTML report for test-libqmp

2011-03-06 Thread Anthony Liguori
Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 1d363d7..c5a4820 100644
--- a/Makefile
+++ b/Makefile
@@ -216,6 +216,15 @@ LIBQMP_OBJS += $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o
 
 test-libqmp: test-libqmp.o $(LIBQMP_OBJS) qemu-timer-common.o
 
+check: test-libqmp
+   $(call quiet-command, ./test-libqmp,   CHECK   $@)
+
+test-report.html: test-report.log
+   $(call quiet-command, gtester-report $  $@,   GEN   $@)
+
+test-report.log: test-libqmp
+   $(call quiet-command, gtester -k -o $@ ./test-libqmp 2/dev/null 
/dev/null || true,   TEST  $)
+
 clean:
 # avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
-- 
1.7.0.4




[Qemu-devel] [PATCH 08/22] qapi: add code generator for qmp-types

2011-03-06 Thread Anthony Liguori
Only generate qmp-types.[ch].  These files contain the type definitions for
QMP along with the alloc/free functions for these types.  Functions to convert
enum values to integers and vice versa are also included.

qmp-types is used both within QEMU and within libqmp

Special alloc/free functions are provided to ensure that all structures are
padded when allocated.  This makes sure that libqmp can provide a forward
compatible interface since all additions to a structure will have a boolean
enable flag.

The free function is convenient since individual structures may have pointers
that also require freeing.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index 6b1d716..6b9fd69 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
+GENERATED_HEADERS += qmp-types.h
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -146,6 +147,14 @@ trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
 
 simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
 
+qmp-types.c: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-body  $  
$@,   GEN   $@)
+
+qmp-types.h: $(SRC_PATH)/qmp-schema.json $(SRC_PATH)/qmp-gen.py
+   $(call quiet-command,python $(SRC_PATH)/qmp-gen.py --types-header  $ 
 $@,   GEN   $@)
+
+qmp-types.o: qmp-types.c qmp-types.h
+
 version.o: $(SRC_PATH)/version.rc config-host.mak
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)
 
diff --git a/Makefile.objs b/Makefile.objs
index 69f0383..710d99f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -15,7 +15,7 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
 block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
-block-obj-y += error.o
+block-obj-y += error.o qmp-types.o
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
diff --git a/ordereddict.py b/ordereddict.py
new file mode 100644
index 000..e17269f
--- /dev/null
+++ b/ordereddict.py
@@ -0,0 +1,128 @@
+# Copyright (c) 2009 Raymond Hettinger
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the Software), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+
+from UserDict import DictMixin
+
+class OrderedDict(dict, DictMixin):
+
+def __init__(self, *args, **kwds):
+if len(args)  1:
+raise TypeError('expected at most 1 arguments, got %d' % len(args))
+try:
+self.__end
+except AttributeError:
+self.clear()
+self.update(*args, **kwds)
+
+def clear(self):
+self.__end = end = []
+end += [None, end, end] # sentinel node for doubly linked list
+self.__map = {} # key -- [key, prev, next]
+dict.clear(self)
+
+def __setitem__(self, key, value):
+if key not in self:
+end = self.__end
+curr = end[1]
+curr[2] = end[1] = self.__map[key] = [key, curr, end]
+dict.__setitem__(self, key, value)
+
+def __delitem__(self, key):
+dict.__delitem__(self, key)
+key, prev, next = self.__map.pop(key)
+prev[2] = next
+next[1] = prev
+
+def __iter__(self):
+end = self.__end
+curr = end[2]
+while curr is not end:
+yield curr[0]
+curr = curr[2]
+
+def __reversed__(self):
+end = self.__end
+curr = end[1]
+while curr is not end:
+yield curr[0]
+curr = curr[1]
+
+def popitem(self, last=True):
+if not self:
+raise KeyError('dictionary is empty')
+if last:
+key = reversed(self).next()
+else:
+key = iter(self).next()
+

[Qemu-devel] [PATCH 01/22] Add hard build dependency on glib

2011-03-06 Thread Anthony Liguori
GLib is an extremely common library that has a portable thread implementation
along with tons of other goodies.

GLib and GObject have a fantastic amount of infrastructure we can leverage in
QEMU including an object oriented programming infrastructure.

Short term, it has a very nice thread pool implementation that we could leverage
in something like virtio-9p.  It also has a test harness implementation that
this series will use.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com

diff --git a/Makefile b/Makefile
index eca4c76..6b1d716 100644
--- a/Makefile
+++ b/Makefile
@@ -104,6 +104,8 @@ audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += 
$(FMOD_CFLAGS)
 
 QEMU_CFLAGS+=$(CURL_CFLAGS)
 
+QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
 ui/cocoa.o: ui/cocoa.m
 
 ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
diff --git a/Makefile.objs b/Makefile.objs
index 9e98a66..0ba02c7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -322,3 +322,5 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
+vl.o: QEMU_CFLAGS+=$(GLIB_CFLAGS)
+
diff --git a/Makefile.target b/Makefile.target
index 220589e..0bd42da 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -204,6 +204,7 @@ QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
+QEMU_CFLAGS += $(GLIB_CFLAGS)
 
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
diff --git a/configure b/configure
index ef51a58..e1305ae 100755
--- a/configure
+++ b/configure
@@ -1662,6 +1662,18 @@ EOF
 fi
 
 ##
+# glib support probe
+if $pkg_config --modversion gthread-2.0  /dev/null 21 ; then
+glib_cflags=`$pkg_config --cflags gthread-2.0 2/dev/null`
+glib_libs=`$pkg_config --libs gthread-2.0 2/dev/null`
+libs_softmmu=$glib_libs $libs_softmmu
+libs_tools=$glib_libs $libs_softmmu
+else
+echo glib-2.0 required to compile QEMU
+exit 1
+fi
+
+##
 # kvm probe
 if test $kvm != no ; then
 cat  $TMPC EOF
@@ -2757,6 +2769,7 @@ if test $bluez = yes ; then
   echo CONFIG_BLUEZ=y  $config_host_mak
   echo BLUEZ_CFLAGS=$bluez_cflags  $config_host_mak
 fi
+echo GLIB_CFLAGS=$glib_cflags  $config_host_mak
 if test $xen = yes ; then
   echo CONFIG_XEN=y  $config_host_mak
 fi
-- 
1.7.0.4




[Qemu-devel] limitations of DEF_HELPER

2011-03-06 Thread felix.matenaar@rwth-aachen
Hello *,

modifying target-i386/translate.c for calling helper functions when
specific arithmetic operations are executed.

Example:
static void gen_shift(DisasContext *s1, int op, int ot, int d, int s,
target_ulong pc_start)
{
if (s != OR_TMP1)
gen_op_mov_TN_reg(ot, 1, s);
if(optrace_enabled  userspace(pc_start))
gen_helper_opcode_event(); // custom helper function
switch(op) {
 ...
 ...
}

What I noticed is that Qemu segfaults after some calls to these helper
functions but as far as I figured out not in my analysis code. So my
question is if there are any limitations on how helper functions can be
used because I have already hooks in disas_insn which work without any
problems.

Regards,
Felix



[Qemu-devel] [PATCH] qapi: qmp-marshal-types.c and qmp-marshal-types.h

2011-03-06 Thread Anthony Liguori
This is not to be committed.

diff --git a/qmp-marshal-types.c b/qmp-marshal-types.c
new file mode 100644
index 000..c3ab141
--- /dev/null
+++ b/qmp-marshal-types.c
@@ -0,0 +1,77 @@
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT */
+
+#include qmp-marshal-types.h
+#include qerror.h
+
+
+QObject *qmp_marshal_type_VersionInfo(struct VersionInfo * src)
+{
+QObject *qmp__retval;
+{
+QDict *qmp__dict = qdict_new();
+QObject *qmp__member0;
+
+{
+QDict *qmp__dict = qdict_new();
+QObject *qmp__member1;
+
+qmp__member1 = qmp_marshal_type_int(src-qemu.major);
+qdict_put_obj(qmp__dict, major, qmp__member1);
+
+qmp__member1 = qmp_marshal_type_int(src-qemu.minor);
+qdict_put_obj(qmp__dict, minor, qmp__member1);
+
+qmp__member1 = qmp_marshal_type_int(src-qemu.micro);
+qdict_put_obj(qmp__dict, micro, qmp__member1);
+
+qmp__member0 = QOBJECT(qmp__dict);
+}
+qdict_put_obj(qmp__dict, qemu, qmp__member0);
+
+qmp__member0 = qmp_marshal_type_str(src-package);
+qdict_put_obj(qmp__dict, package, qmp__member0);
+
+qmp__retval = QOBJECT(qmp__dict);
+}
+return qmp__retval;
+}
+
+struct VersionInfo * qmp_unmarshal_type_VersionInfo(QObject *src, Error **errp)
+{
+Error *qmp__err = NULL;
+struct VersionInfo * qmp__retval = qmp_alloc_version_info();
+{
+QDict *qmp__dict = qobject_to_qdict(src);
+QObject *qmp__object0;
+qmp__object0 = qdict_get(qmp__dict, qemu);
+{
+QDict *qmp__dict = qobject_to_qdict(qmp__object0);
+QObject *qmp__object1;
+qmp__object1 = qdict_get(qmp__dict, major);
+qmp__retval-qemu.major = qmp_unmarshal_type_int(qmp__object1, 
qmp__err);
+if (qmp__err) {
+goto qmp__err_out;
+}
+qmp__object1 = qdict_get(qmp__dict, minor);
+qmp__retval-qemu.minor = qmp_unmarshal_type_int(qmp__object1, 
qmp__err);
+if (qmp__err) {
+goto qmp__err_out;
+}
+qmp__object1 = qdict_get(qmp__dict, micro);
+qmp__retval-qemu.micro = qmp_unmarshal_type_int(qmp__object1, 
qmp__err);
+if (qmp__err) {
+goto qmp__err_out;
+}
+}
+qmp__object0 = qdict_get(qmp__dict, package);
+qmp__retval-package = qmp_unmarshal_type_str(qmp__object0, qmp__err);
+if (qmp__err) {
+goto qmp__err_out;
+}
+}
+return qmp__retval;
+qmp__err_out:
+error_propagate(errp, qmp__err);
+qmp_free_version_info(qmp__retval);
+return NULL;
+}
diff --git a/qmp-marshal-types.h b/qmp-marshal-types.h
new file mode 100644
index 000..ce4f6ea
--- /dev/null
+++ b/qmp-marshal-types.h
@@ -0,0 +1,11 @@
+/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT */
+#ifndef QMP_MARSHAL_TYPES_H
+#define QMP_MARSHAL_TYPES_H
+
+#include qmp-marshal-types-core.h
+
+
+
+QObject *qmp_marshal_type_VersionInfo(struct VersionInfo * src);
+struct VersionInfo * qmp_unmarshal_type_VersionInfo(QObject *src, Error 
**errp);
+#endif
-- 
1.7.0.4




  1   2   >