Re: [PATCH] meson: add tests option

2021-03-02 Thread Romain Naour
Hello,

Le 02/03/2021 à 12:08, Paolo Bonzini a écrit :
> On 02/03/21 11:22, Thomas Huth wrote:
>> On 26/02/2021 23.07, Romain Naour wrote:
>>> tests/fp/fp-bench.c use fenv.h that is not always provided
>>> by the libc (uClibc).
>>
>> For such  problem it might be better to check for the availability of the
>> header and then to only disable the single test that depends on it if the
>> header is not available.

You're right, I thought about adding a header check but I noticed that was no
option to disable all tests. Buildroot try to avoid as much as possible building
tests program.

>>
>> Anyway, a switch to disable the tests completely could still be handy in some
>> cases, so FWIW:

It can save some build time:

qemu build with tests disabled
real3m27,310s
user19m56,887s
sys 2m1,738s

qemu build with tests enabled
real4m0,638s
user23m34,963s
sys 2m32,944s


>>
>> Acked-by: Thomas Huth 
> 
> I disagree, without a use case the right thing to do is to check for fenv.h. 
> It's as easy as this:

Is it ok if I take your patch to disable fp tests when fenv.h is missing and
resend my patch with an updated commit log to disable all tests to save some
build time?

Best regards,
Romain

> 
> diff --git a/tests/meson.build b/tests/meson.build
> index 0c939f89f7..3b9b2f0483 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -281,7 +281,7 @@ test('decodetree', sh,
>   workdir: meson.current_source_dir() / 'decode',
>   suite: 'decodetree')
> 
> -if 'CONFIG_TCG' in config_all
> +if 'CONFIG_TCG' in config_all and cc.has_header('fenv.h')
>    subdir('fp')
>  endif
> 
> Thanks,
> 
> Paolo
> 




[PATCH] meson: add tests option

2021-02-26 Thread Romain Naour
tests/fp/fp-bench.c use fenv.h that is not always provided
by the libc (uClibc).

To workaround this issue, add an new meson option to
disable tests while building Qemu.

Fixes:
http://autobuild.buildroot.net/results/53f5d8baa994d599b9da013ee643b82353366ec3/build-end.log

Signed-off-by: Romain Naour 
---
 configure | 7 +++
 meson.build   | 6 +-
 meson_options.txt | 3 +++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index a79b3746d4..cd114f4b9e 100755
--- a/configure
+++ b/configure
@@ -464,6 +464,7 @@ gettext="auto"
 fuse="auto"
 fuse_lseek="auto"
 multiprocess="no"
+tests="auto"
 
 malloc_trim="auto"
 
@@ -1562,6 +1563,10 @@ for opt do
   ;;
   --disable-multiprocess) multiprocess="no"
   ;;
+  --disable-tests) tests="disabled"
+  ;;
+  --enable-tests) tests="enabled"
+  ;;
   *)
   echo "ERROR: unknown option $opt"
   echo "Try '$0 --help' for more information"
@@ -1915,6 +1920,7 @@ disabled with --disable-FEATURE, default is enabled if 
available
   fuseFUSE block device export
   fuse-lseek  SEEK_HOLE/SEEK_DATA support for FUSE exports
   multiprocessMultiprocess QEMU support
+  tests   build tests
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -6428,6 +6434,7 @@ NINJA=$ninja $meson setup \
 -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek 
-Dguest_agent_msi=$guest_agent_msi \
 $(if test "$default_features" = no; then echo 
"-Dauto_features=disabled"; fi) \
-Dtcg_interpreter=$tcg_interpreter \
+-Dtests=$tests \
 $cross_arg \
 "$PWD" "$source_path"
 
diff --git a/meson.build b/meson.build
index 05a67c20d9..2d7cbc0fbd 100644
--- a/meson.build
+++ b/meson.build
@@ -2341,7 +2341,11 @@ subdir('scripts')
 subdir('tools')
 subdir('pc-bios')
 subdir('docs')
-subdir('tests')
+
+if get_option('tests').enabled()
+  subdir('tests')
+endif
+
 if gtk.found()
   subdir('po')
 endif
diff --git a/meson_options.txt b/meson_options.txt
index 675a9c500a..be30ad5450 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -114,6 +114,9 @@ option('virtfs', type: 'feature', value: 'auto',
 option('virtiofsd', type: 'feature', value: 'auto',
description: 'build virtiofs daemon (virtiofsd)')
 
+option('tests', type : 'feature', value : 'auto',
+   description: 'Tests build support')
+
 option('capstone', type: 'combo', value: 'auto',
choices: ['disabled', 'enabled', 'auto', 'system', 'internal'],
description: 'Whether and how to find the capstone library')
-- 
2.29.2




Re: [Qemu-devel] [V6, 2/7] nios2: Add architecture emulation support

2016-11-07 Thread Romain Naour
Hi, Guenter,

Le 07/11/2016 à 20:54, Guenter Roeck a écrit :
> Hi Marek,
> 
> On 11/07/2016 10:14 AM, Marek Vasut wrote:
>> On 11/07/2016 04:58 AM, Guenter Roeck wrote:
>>> On Tue, Oct 25, 2016 at 09:57:43PM +0200, Marek Vasut wrote:
 From: Chris Wulff 

 Add support for emulating Altera NiosII R1 architecture into qemu.
 This patch is based on previous work by Chris Wulff from 2012 and
 updated to latest mainline QEMU.

 Signed-off-by: Marek Vasut 
 Cc: Chris Wulff 
 Cc: Jeff Da Silva 
 Cc: Ley Foon Tan 
 Cc: Sandra Loosemore 
 Cc: Yves Vandervennet 
 ---
 V3: Thorough cleanup, deal with the review comments all over the place
 V4: - Use extract32()
 - Fix gen_goto_tb() , suppress tcg_gen_goto_tb()
 - Clean up gen_check_supervisor() helper
 - Use TCGMemOp type for flags
 - Drop jump labels from wrctl/rdctl
 - More TCG cleanup
 V5: - Simplify load/store handling
 - Handle loads into R_ZERO from protected page, add comment
 V6: - Fix division opcode handling
 - Add missing disas handling
 - V5 review comments cleanup
 ---
>>> [ ... ]
>>>
 diff --git a/target-nios2/cpu.h b/target-nios2/cpu.h
 new file mode 100644
 index 000..17c9a0f
>>> [ ... ]
>>>
 +static inline void cpu_get_tb_cpu_state(CPUNios2State *env, target_ulong 
 *pc,
 +target_ulong *cs_base, uint32_t
 *flags)
 +{
 +*pc = env->regs[R_PC];
 +*cs_base = 0;
 +*flags = (env->regs[CR_STATUS] & (CR_STATUS_EH | CR_STATUS_U));
 +}
 +
 +#endif /* CPU_NIOS2_H */
 +
>>>
>>> The empty line at the end results in a whitespace message from git.
>>
>> Dropped, thanks. Is there anything else or is this patchset starting to
>> become acceptable ?
>>
> 
> Hard for me to say. I tried to build and run the series with the latest linux
> kernel (v4.9-rc4), but it is stuck in early boot. I tried with 10m50_defconfig
> and 10m50_devboard.dtb. gcc is 6.1.0 built with buildroot, though I also tried
> with toolchains from CodeSourcery. Obviously I have no idea if there is a
> kernel bug or a qemu bug or a problem with the command line I used.
> 
> Here is my command line:
> 
> qemu-system-nios2 -M 10m50-ghrd -kernel vmlinux -dtb 10m50_devboard.dtb \
> -append "earlycon=uart8250,mmio32,0x18001600,115200n8 console=ttyS0"

I'm also using Buildroot to build the Linux initrd system and it works fine :)
I'm using the CodeSourcery toolchain and I also tried with the Buildroot
internal toolchain too, I guess it's a problem with your Qemu command line.

Here is my Buildroot config:

BR2_nios2=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_DEFCONFIG="10m50"
BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/qemu/nios2-10m50/linux-4.8.fragment"
BR2_TARGET_ROOTFS_INITRAMFS=y

The board/qemu/nios2-10m50/linux-4.8.fragment file contain the following lines
to extend the 10m50 kernel defconfig:
CONFIG_NIOS2_DTB_SOURCE_BOOL=y
CONFIG_NIOS2_DTB_SOURCE="arch/nios2/boot/dts/10m50_devboard.dts"

With that, you should be able to boot Qemu with the following command line:

qemu-system-nios2 -kernel output/images/vmlinux -nographic

[...]

Welcome to Buildroot
buildroot login: root
# cat /proc/cpuinfo
CPU:Nios II/fast
MMU:present
FPU:none
Clocking:   75.00 MHz
BogoMips:   150.00
Calibration:7500 loops
HW:
 MUL:   yes
 MULX:  no
 DIV:   yes
Icache: 32kB, line length: 32
Dcache: random: fast init done
32kB, line length: 32
TLB:16 ways, 256 entries, 8 PID bits

But I haven't tested the upcoming v4.9 kernel yet.

I'll add this Buildroot Qemu defconfig to Buildroot as soon as the nios2 has
been merged in Qemu :)

Best regards,
Romain

> 
> This may be wrong, but the boot is stuck in an endless loop in mark_bootmem(),
> which seems early and odd. I tried with both vmlinux and 
> arch/nios2/boot/vmImage,
> with the same results.
> 
> Can you provide a working command line and kernel version, and/or directions 
> how
> to create a working image if I need to run the image, for example, from 
> u-boot ?
> Sorry if that is posted somewhere and I missed it.
> 
>> I'll wait a bit before you finish discussing the whitespace errors in
>> 1/7 with Sandra.
>>
> 
> I can't really comment on the whitespace issues; the qemu maintainers will 
> have
> to decide if they can accept this patch as-is. I am sure they will appreciate
> a heads-up, though.
> 
> Thanks,
> Guenter
> 
> 




Re: [Qemu-devel] [V2,1/7] nios2: Add disas entries

2016-10-31 Thread Romain Naour
Hi Marek, all,

Le 18/10/2016 à 06:17, Marek Vasut a écrit :
> On 10/15/2016 03:15 PM, Romain Naour wrote:
>> Hi Marek,
> 
> Hi!
> 
>> Le 28/09/2016 à 01:30, Marek Vasut a écrit :
>>> Add nios2 disassembler support. This patch is composed from binutils files
>>> from commit "Opcodes and assembler support for Nios II R2". The files from
>>> binutils used in this patch are:
>>>
>>> include/opcode/nios2.h
>>> include/opcode/nios2r1.h
>>> include/opcode/nios2r2.h
>>> opcodes/nios2-opc.c
>>> opcodes/nios2-dis.c
>>
>> With Waldemar Brodkorb and I, we tested this series using 10m50 kernel 
>> defconfig
>> with Buildroot generated system. In order to ease the test, we added the 
>> device
>> tree and a initramfs to the kernel image.
>>
>> Here is the result:
>>
>> Welcome to Buildroot
>> # cat /proc/cpuinfo
>> CPU: Nios II/fast
>> MMU: present
>> FPU: none
>> Clocking:75.00 MHz
>> BogoMips:150.00
>> Calibration: 7500 loops
>> HW:
>>  MUL:yes
>>  MULX:   no
>>  DIV:yes
>> Icache:  32kB, line length: 32
>> Dcache:  32kB, line length: 32
>> TLB: 16 ways, 256 entries, 8 PID bits
>> # uname -a
>> Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux
>>
>> When this series will be accepted in Qemu, I'll add a demo defconfig in
>> Buildroot in order to ease runtime testing.
>>
>> Tested-by: Romain Naour <romain.na...@gmail.com>
> 
> Great, thanks ! I'm glad to see it really becomes usable for other
> people too :)
> 
> I handled the feedback and pushed updated patches to:
> http://git.bfuser.eu/?p=marex/qemu.git;a=shortlog;h=refs/heads/nios2/master
> 

Thanks, I tried your latest nios2 Qemu (v3 series) + patch 2/3 v6 with a 4.8.5
Linux kernel. It still boot :)

Best regards,
Romain




Re: [Qemu-devel] [V2,1/7] nios2: Add disas entries

2016-10-15 Thread Romain Naour
Hi Marek,

Le 28/09/2016 à 01:30, Marek Vasut a écrit :
> Add nios2 disassembler support. This patch is composed from binutils files
> from commit "Opcodes and assembler support for Nios II R2". The files from
> binutils used in this patch are:
> 
> include/opcode/nios2.h
> include/opcode/nios2r1.h
> include/opcode/nios2r2.h
> opcodes/nios2-opc.c
> opcodes/nios2-dis.c

With Waldemar Brodkorb and I, we tested this series using 10m50 kernel defconfig
with Buildroot generated system. In order to ease the test, we added the device
tree and a initramfs to the kernel image.

Here is the result:

Welcome to Buildroot
# cat /proc/cpuinfo
CPU:Nios II/fast
MMU:present
FPU:none
Clocking:   75.00 MHz
BogoMips:   150.00
Calibration:7500 loops
HW:
 MUL:   yes
 MULX:  no
 DIV:   yes
Icache: 32kB, line length: 32
Dcache: 32kB, line length: 32
TLB:16 ways, 256 entries, 8 PID bits
# uname -a
Linux buildroot 4.8.1 #2 Fri Oct 14 19:10:18 CEST 2016 nios2 GNU/Linux

When this series will be accepted in Qemu, I'll add a demo defconfig in
Buildroot in order to ease runtime testing.

Tested-by: Romain Naour <romain.na...@gmail.com>

Best regards,
Romain

> Signed-off-by: Marek Vasut <ma...@denx.de>
> Cc: Chris Wulff <crwu...@gmail.com>
> Cc: Jeff Da Silva <jdasi...@altera.com>
> Cc: Ley Foon Tan <lf...@altera.com>
> Cc: Sandra Loosemore <san...@codesourcery.com>
> Cc: Yves Vandervennet <yvand...@altera.com>
> ---
> V2: Replace the nios2.c with GPL2 licensed version
> ---





Re: [Qemu-devel] [PATCH v2 1/1] genius: add genius serial mouse emulation

2014-01-18 Thread Romain Naour

Hi,

[snip]

+int dx;
+int dy;
+int button;
+struct QEMUTimer *transmit_timer; /* QEMU timer */
+uint64_t transmit_time;   /* time to transmit a char in ticks */
+unsigned char data[5];
+int index;
+} gnmouse_save;

How does all this state get migrated at VM migration? I know
how this works for device models, but does anybody know
the answer for char backends?

I never used the VM migration, I don't know.

[snip]

+switch (save-index) {
+case CHAR_4:
+if (save-dx  save-dy) {

This looks wrong. If there's a saved delta-x then we
still want to send it to the guest, even if the save-dy is
correct, right?

Yes indeed, thanks.

[snip]

Also, it could use a comment. If I understand the logic correctly,
something like:
  /* Send as much of our accumulated delta as we can fit into
   * the packet format. Anything remaining will get sent in a
   * subsequent packet.
   */
These additional bytes are intended to send the movement made since the 
beginning of theframe transfer.


[snip]

+ /* reload timer */
This comment is stating the obvious. It would be more interesting
to know why we have a timer at all...
If I do like msmouse, the receive buffer is flooded by each GUI event 
and the last frame is not entirely received.

I hav'nt found a better solution than using a timer...
I added a comment for that in v3.

[snip]

+
+/* Buttons */
+BP |= (buttons_state  0x01 ? 0x00 : 0x04); /* BP1 = L */
+BP |= (buttons_state  0x02 ? 0x00 : 0x01); /* BP2 = R */
+BP |= (buttons_state  0x04 ? 0x00 : 0x02); /* BP4 = M */

Are these really 'bit set if button is up' ? If so that could use a comment,
because that's a bit of a weird protocol design.

Yes it's really bit set if button is up.


  @item -chardev msmouse ,id=@var{id}

-Forward QEMU's emulated msmouse events to the guest. @option{msmouse} does not
-take any options.
+Forward events from QEMU's emulated mouse to the guest using the
+Microsoft protocol. @option{msmouse} does not take any options.
+
+@item -chardev gnmouse ,id=@var{id}
+
+Forward events from QEMU's emulated mouse to the guest using the Genius
+(Mouse Systems) protocol. @option{gnmouse} does not take any options.

If we have more than one supported protocol, we should probably say in the
documentation which one we recommend for which purposes, rather than
leaving people to guess which one might be better supported/more efficient/etc.
My guess is that the answer is use msmouse unless your guest OS only
supports the Mouse Systems protocol, but your patch doesn't include any
rationale, so that is just a guess...

I'm agree with you, I added a comment in the documentation to says that.

Thank you for your time and review !

Best regards,
Romain Naour


[Qemu-devel] [PATCH v3 1/1] genius: add genius serial mouse emulation

2014-01-18 Thread Romain Naour
This patch adds the emulation for a serial Genius mouse using
Mouse Systems protocol (5bytes).
This protocol is compatible with most 3-button serial mice.

Signed-off-by: Romain Naour romain.na...@openwide.fr
---
Changes v2 - v3:
Following Peter Maydell's feedback:
 Fixes typos
 Duplicated code factored into a common utility function.
 Documentation: Prefer msmouse if available.
Fixes build warning when debug is set

Changes v1 - v2:
 Fixes documentation (Paolo Bonzini)
 Fixes typos

 backends/Makefile.objs |   2 +-
 backends/gnmouse.c | 313 +
 include/sysemu/char.h  |   3 +
 qapi-schema.json   |   1 +
 qemu-char.c|   4 +
 qemu-options.hx|  17 ++-
 6 files changed, 337 insertions(+), 3 deletions(-)
 create mode 100644 backends/gnmouse.c

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 42557d5..e4b072c 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -1,7 +1,7 @@
 common-obj-y += rng.o rng-egd.o
 common-obj-$(CONFIG_POSIX) += rng-random.o
 
-common-obj-y += msmouse.o
+common-obj-y += msmouse.o gnmouse.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
diff --git a/backends/gnmouse.c b/backends/gnmouse.c
new file mode 100644
index 000..e127b8b
--- /dev/null
+++ b/backends/gnmouse.c
@@ -0,0 +1,313 @@
+/*
+ * QEMU Genius GM-6 serial mouse emulation
+ *
+ * Adapted from msmouse
+ *
+ * Copyright (c) 2014 Romain Naour
+ *
+ * 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.
+ */
+#include stdlib.h
+#include string.h
+#include sys/time.h
+
+#include qemu-common.h
+#include sysemu/char.h
+#include ui/console.h
+#include qemu/timer.h
+
+/* #define DEBUG_GENIUS_MOUSE */
+
+#ifdef DEBUG_GENIUS_MOUSE
+#define DPRINTF(fmt, ...) \
+do { fprintf(stderr, gnmouse:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+do {} while (0)
+#endif
+
+/*
+ * struct GnMouseSave:
+ * This structure is used to save private info for Genius mouse.
+ *
+ * dx: deltas on x-axis saved since last frame send to emulated system.
+ * dy: deltas on y-axis saved since last frame send to emulated system.
+ * transmit_timer: QEMU's timer
+ * transmit_time: reload value for transmit_timer
+ * data: frame to be sent
+ * index: used to save current state of the state machine. see type states 
below
+ */
+typedef struct GnMouseSave {
+int dx;
+int dy;
+int button;
+struct QEMUTimer *transmit_timer; /* QEMU timer */
+uint64_t transmit_time;   /* time to transmit a char in ticks */
+unsigned char data[5];
+int index;
+} GnMouseSave;
+
+
+/* states */
+typedef enum {
+START,  /* 0 */
+CHAR_1, /* 1 : bp */
+CHAR_2, /* 2 : Dx */
+CHAR_3, /* 3 : Dy */
+CHAR_4, /* 4 : Dx */
+CHAR_5, /* 5 : Dy */
+STOP/* 6 */
+} States;
+
+/**
+ * gnmouse_chr_write: this function is used when QEMU
+ * try to write something to mouse port.
+ * Nothing is sent to the emulated mouse.
+ *
+ * Return: length of the buffer
+ *
+ * @s: address of the CharDriverState used by the mouse
+ * @buf: buffer to write
+ * @len: length of the buffer to write
+ */
+static int gnmouse_chr_write(struct CharDriverState *s, const uint8_t *buf,
+ int len)
+{
+/* Ignore writes to mouse port */
+return len;
+}
+
+/**
+ * gnmouse_chr_close: his function closes the mouse port.
+ * stops and frees the QEMU timer and frees the GnMouseSave struct.
+ *
+ * Return: void
+ *
+ * @chr: address of the CharDriverState used by the mouse
+ */
+static void gnmouse_chr_close(struct CharDriverState *chr)
+{
+GnMouseSave *save = (GnMouseSave *)chr-opaque;
+
+timer_del(save-transmit_timer);
+timer_free(save-transmit_timer);
+g_free(chr-opaque);
+g_free(chr);
+}
+
+/**
+ * gnmouse_return_accumulated_delta: this function checks and returns
+ * the accumulated value of delta that is passed as argument

Re: [Qemu-devel] [PATCH v2 1/1] genius: add genius serial mouse emulation

2014-01-16 Thread Romain Naour

Hi,

Le 14/01/2014 23:46, Peter Maydell a écrit :

It might be helpful to note why we should care, ie if there are
any particularly interesting guests which can only deal with this
and not the MS mouse protocol, or if there are mouse features
you can only get support for with this protocol.

I worked on this emulation for a quite old OS (Concurrent DOS) which use 
only Mouse System protocol.
So, I sent this patch to not leave this work unsubmitted in case someone 
wants to use it.


I will rework my patch following your feedback.

Thanks,
Romain Naour



Re: [Qemu-devel] [PATCH 1/1] genius: add genius serial mouse emulation

2014-01-14 Thread Romain Naour

Hi,

The standard is more like

# A union referencing different chardev backend configuration' info.
#
# @gnmouse: Send mouse data using the Genius protocol (since 2.0).
#
# Since: 1.4
##

but that format would require doucmenting all items. :(

You can leave this out of v2.

However, I'd be happy if you changed the documentation like this

@item -chardev msmouse,id=@var{id}
Forward events from QEMU's emulated mouse to the guest using the
Microsoft protocol. @option{msmouse} does not take any options.

@item -chardev gnmouse ,id=@var{id}

Forward events from QEMU's emulated mouse to the guest using the Genius
(Mouse Systems) protocol. @option{gnmouse} does not take any options.

Certainly, I changed the documentation accordingly.
The v2 in on the way.

Best regards,
Romain Naour



[Qemu-devel] [PATCH v2 1/1] genius: add genius serial mouse emulation

2014-01-14 Thread Romain Naour
This patch adds the emulation for a serial Genius mouse using
Mouse Systems protocol (5bytes).
This protocol is compatible with most 3-button serial mouse.

Signed-off-by: Romain Naour romain.na...@openwide.fr
---
Changes v1 - v2:
 Fixes documentation (Paolo Bonzini)
 Fixes typos

 backends/Makefile.objs |   2 +-
 backends/gnmouse.c | 339 +
 include/sysemu/char.h  |   3 +
 qapi-schema.json   |   1 +
 qemu-char.c|   4 +
 qemu-options.hx|  14 +-
 6 files changed, 360 insertions(+), 3 deletions(-)
 create mode 100644 backends/gnmouse.c

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 42557d5..e4b072c 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -1,7 +1,7 @@
 common-obj-y += rng.o rng-egd.o
 common-obj-$(CONFIG_POSIX) += rng-random.o
 
-common-obj-y += msmouse.o
+common-obj-y += msmouse.o gnmouse.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
diff --git a/backends/gnmouse.c b/backends/gnmouse.c
new file mode 100644
index 000..9581419
--- /dev/null
+++ b/backends/gnmouse.c
@@ -0,0 +1,339 @@
+/*
+ * QEMU Genius GM-6 serial mouse emulation
+ *
+ * Adapted from msmouse
+ *
+ * Copyright (c) 2014 Romain Naour
+ *
+ * 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.
+ */
+#include stdlib.h
+#include string.h
+#include sys/time.h
+
+#include qemu-common.h
+#include sysemu/char.h
+#include ui/console.h
+#include qemu/timer.h
+
+/* #define DEBUG_GENIUS_MOUSE */
+
+#ifdef DEBUG_GENIUS_MOUSE
+#define DPRINTF(fmt, ...) \
+do { fprintf(stderr, gnmouse:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+do {} while (0)
+#endif
+
+/*
+ * struct gnmouse_save:
+ * This structure is used to save private info for Genius mouse.
+ *
+ * dx: deltas on x-axis saved since last frame send to emulated system.
+ * dy: deltas on y-axis saved since last frame send to emulated system.
+ * transmit_timer: QEMU's timer
+ * transmit_time: reload value for transmit_timer
+ * data: frame to be sent
+ * index: used to save current state of the state machine. see type states 
below
+ */
+typedef struct gnmouse_save {
+int dx;
+int dy;
+int button;
+struct QEMUTimer *transmit_timer; /* QEMU timer */
+uint64_t transmit_time;   /* time to transmit a char in ticks */
+unsigned char data[5];
+int index;
+} gnmouse_save;
+
+
+/* states */
+typedef enum {
+START,  /* 0 */
+CHAR_1, /* 1 : BP */
+CHAR_2, /* 2 : Dx */
+CHAR_3, /* 3 : Dy */
+CHAR_4, /* 4 : Dx */
+CHAR_5, /* 5 : Dy */
+STOP/* 6 */
+}
+states;
+
+/**
+ * gnmouse_chr_write: this function is used when QEMU
+ * try to write something to mouse port.
+ * Nothing is send to the emulated mouse.
+ *
+ * Return: lengh of the buffer
+ *
+ * @s: address of the CharDriverState used by the mouse
+ * @buf: buffer to write
+ * @len: lengh of the buffer to write
+ */
+static int gnmouse_chr_write(struct CharDriverState *s, const uint8_t *buf,
+ int len)
+{
+/* Ignore writes to mouse port */
+return len;
+}
+
+/**
+ * gnmouse_chr_close: this function close the mouse port.
+ * It stop and free the QEMU's timer and free gnmouse_save struct.
+ *
+ * Return: void
+ *
+ * @chr: address of the CharDriverState used by the mouse
+ */
+static void gnmouse_chr_close(struct CharDriverState *chr)
+{
+/* stop and free the QEMU's timer */
+timer_del(((gnmouse_save *)chr-opaque)-transmit_timer);
+timer_free(((gnmouse_save *)chr-opaque)-transmit_timer);
+/* free gnmouse_save struct */
+g_free(chr-opaque);
+g_free(chr);
+}
+
+/**
+ * gnmouse_handler: send a byte on serial port to the guest system
+ * This handler is called on each timer timeout or directly by gnmouse_event()
+ * when no transmission is underway.
+ * It use a state machine in order to know which byte of the frame must be 
send

[Qemu-devel] [PATCH 0/1] Genius serial mouse emulation.

2014-01-13 Thread Romain Naour
This patch adds the emulation for a serial Genius mouse using
Mouse Systems protocol (5bytes) [1].
This protocol is compatible with most 3-buttons serial mouse.

This work was developed for qemu-1.1.0 and rebased on master.

To test this patch you need to start qemu with -serial gnmouse.
Then you need to start gpm (general purpose mouse) on Linux:

# gpm -m /dev/ttyS0 -T -t msc

I validated the emulation by comparing frames with a real mouse Genius (GM-6) 
with a USB-serial adapter (ttyUSB0).

I also tested with a CDOS operating system.

Best regards,
Romain Naour

[1] MSC protocol:
http://www.zimmers.net/anonftp/pub/cbm/documents/projects/interfaces/mouse/Mouse.html#serial

Romain Naour (1):
  genius: add genius serial mouse emulation

 backends/Makefile.objs |   2 +-
 backends/gnmouse.c | 339 +
 include/sysemu/char.h  |   3 +
 qapi-schema.json   |   1 +
 qemu-char.c|   4 +
 qemu-options.hx|  10 ++
 6 files changed, 358 insertions(+), 1 deletion(-)
 create mode 100644 backends/gnmouse.c

-- 
1.8.4.2




[Qemu-devel] [PATCH 1/1] genius: add genius serial mouse emulation

2014-01-13 Thread Romain Naour
This patch adds the emulation for a serial Genius mouse using
Mouse Systems protocol (5bytes).
This protocol is compatible with most 3-button serial mouse.

Signed-off-by: Romain Naour romain.na...@openwide.fr
---
 backends/Makefile.objs |   2 +-
 backends/gnmouse.c | 339 +
 include/sysemu/char.h  |   3 +
 qapi-schema.json   |   1 +
 qemu-char.c|   4 +
 qemu-options.hx|  10 ++
 6 files changed, 358 insertions(+), 1 deletion(-)
 create mode 100644 backends/gnmouse.c

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 42557d5..e4b072c 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -1,7 +1,7 @@
 common-obj-y += rng.o rng-egd.o
 common-obj-$(CONFIG_POSIX) += rng-random.o
 
-common-obj-y += msmouse.o
+common-obj-y += msmouse.o gnmouse.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
diff --git a/backends/gnmouse.c b/backends/gnmouse.c
new file mode 100644
index 000..e9bdc65
--- /dev/null
+++ b/backends/gnmouse.c
@@ -0,0 +1,339 @@
+/*
+ * QEMU Genius GM-6 serial mouse emulation
+ *
+ * Adapted from msmouse
+ *
+ * Copyright (c) 2012 Romain Naour
+ *
+ * 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.
+ */
+#include stdlib.h
+#include string.h
+#include sys/time.h
+
+#include qemu-common.h
+#include sysemu/char.h
+#include ui/console.h
+#include qemu/timer.h
+
+/* #define DEBUG_GENIUS_MOUSE */
+
+#ifdef DEBUG_GENIUS_MOUSE
+#define DPRINTF(fmt, ...) \
+do { fprintf(stderr, gnmouse:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) \
+do {} while (0)
+#endif
+
+/*
+ * struct gnmouse_save:
+ * This structure is used to save private info for Genius mouse.
+ *
+ * dx: deltas on x-axis saved since last frame send to emulated system.
+ * dy: deltas on y-axis saved since last frame send to emulated system.
+ * transmit_timer: QEMU's timer
+ * transmit_time: reload value for transmit_timer
+ * data: frame to be sent
+ * index: used to save current state of the state machine. see type states 
below
+ */
+typedef struct gnmouse_save {
+int dx;
+int dy;
+int button;
+struct QEMUTimer *transmit_timer; /* QEMU timer */
+uint64_t transmit_time;   /* time to transmit a char in ticks*/
+unsigned char data[5];
+int index;
+} gnmouse_save;
+
+
+/* states */
+typedef enum {
+START,  /* 0 */
+CHAR_1, /* 1 : BP */
+CHAR_2, /* 2 : Dx */
+CHAR_3, /* 3 : Dy */
+CHAR_4, /* 4 : Dx */
+CHAR_5, /* 5 : Dy */
+STOP/* 6 */
+}
+states;
+
+/**
+ * gnmouse_chr_write: this function is used when QEMU
+ * try to write something to mouse port.
+ * Nothing is send to the emulated mouse.
+ *
+ * Return: lengh of the buffer
+ *
+ * @s: address of the CharDriverState used by the mouse
+ * @buf: buffer to write
+ * @len: lengh of the buffer to write
+ */
+static int gnmouse_chr_write(struct CharDriverState *s, const uint8_t *buf,
+ int len)
+{
+/* Ignore writes to mouse port */
+return len;
+}
+
+/**
+ * gnmouse_chr_close: this function close the mouse port.
+ * It stop and free the QEMU's timer and free gnmouse_save struct.
+ *
+ * Return: void
+ *
+ * @chr: address of the CharDriverState used by the mouse
+ */
+static void gnmouse_chr_close(struct CharDriverState *chr)
+{
+/* stop and free the QEMU's timer */
+timer_del(((gnmouse_save *)chr-opaque)-transmit_timer);
+timer_free(((gnmouse_save *)chr-opaque)-transmit_timer);
+/* free gnmouse_save struct */
+g_free(chr-opaque);
+g_free(chr);
+}
+
+/**
+ * gnmouse_handler: send a byte on serial port to the guest system
+ * This handler is called on each timer timeout or directly by gnmouse_event()
+ * when no transmission is underway.
+ * It use a state machine in order to know which byte of the frame must be 
send.
+ *
+ * Returns void
+ *
+ * @opaque: address of the CharDriverState used

Re: [Qemu-devel] [PATCH 1/1] genius: add genius serial mouse emulation

2014-01-13 Thread Romain Naour

Hi,

Thanks for review.

Le 13/01/2014 23:45, Eric Blake a écrit :

On 01/13/2014 03:33 PM, Romain Naour wrote:

This patch adds the emulation for a serial Genius mouse using
Mouse Systems protocol (5bytes).
This protocol is compatible with most 3-button serial mouse.

Signed-off-by: Romain Naour romain.na...@openwide.fr
---
  backends/Makefile.objs |   2 +-
  backends/gnmouse.c | 339 +
  include/sysemu/char.h  |   3 +
  qapi-schema.json   |   1 +
  qemu-char.c|   4 +
  qemu-options.hx|  10 ++
  6 files changed, 358 insertions(+), 1 deletion(-)
  create mode 100644 backends/gnmouse.c
+++ b/backends/gnmouse.c
@@ -0,0 +1,339 @@
+/*
+ * QEMU Genius GM-6 serial mouse emulation
+ *
+ * Adapted from msmouse
+ *
+ * Copyright (c) 2012 Romain Naour

It is now 2014.

Fixed




+++ b/qapi-schema.json
@@ -3617,6 +3617,7 @@
 'null'   : 'ChardevDummy',
 'mux': 'ChardevMux',
 'msmouse': 'ChardevDummy',
+   'gnmouse': 'ChardevDummy',
 'braille': 'ChardevDummy',
 'stdio'  : 'ChardevStdio',
 'console': 'ChardevDummy',

Ideally, you should also document that this branch was not always
available in the union (I was expecting to see a doc line with '(since
2.0)' somewhere in the patch); but looking at the existing schema,
you're just copying bad practice of adding to an already
under-documented union.



You mean something like that ?
##
# @ChardevBackendKind:
#
# A union referencing different chardev backend configuration' info.
#
# Since: 1.4
#
# gnmouse backend since: 2.0
##
{ 'union': 'ChardevBackend', 'data': { 'file'   : 'ChardevFile',
[snip]

I will resend a v2 tomorrow.

Best regards,
Romain Naour