Re: [Qemu-devel] [PATCH] arm: Ensure LSB of BLX is set

2015-09-01 Thread Meador Inge
On Tue, Sep 01, 2015 at 05:28:10PM +0100, Peter Maydell wrote:
> On 6 July 2015 at 19:09,  <mead...@codesourcery.com> wrote:
> > From: Meador Inge <mead...@codesourcery.com>
> >
> > This small patch adds a sanity check when disassembling
> > the BLX instruction.  The use case came to light when
> > doing toolchain development and a similar check was
> > upstreamed for Binutils:
> >
> >   * https://sourceware.org/ml/binutils/2011-01/msg00077.html
> >
> > Patch by Nathan Sidwell.
> >
> > Signed-off-by: Meador Inge <mead...@codesourcery.com>
> 
> Hi; are you planning to send a v2 of this patch?

I am.  Thank you for the reminder.  I will send a v2 some time tomorrow.

Thanks,

-- Meador



Re: [Qemu-devel] [PATCH 2/2] target-arm: Add anyvfp CPU

2015-07-13 Thread Meador Inge
On Mon, Jul 06, 2015 at 11:31:37PM +0100, Peter Maydell wrote:

 I'm not convinced. System mode gives you a bare metal
 system -- it's the bare metal app's job to enable
 VFP if it wants to use it. If your bare metal app
 doesn't do that then it is broken.

Fair enough.  I knew this patch would be a bit of a stretch :-)

Thanks.

-- Meador



Re: [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used

2015-07-13 Thread Meador Inge
On Mon, Jul 06, 2015 at 09:43:20PM +0200, Laurent Vivier wrote:

 Global comment: you should use EXIT_SUCCESS and EXIT_FAILURE from stdlib.h

On second thought, I was following an existing pattern in 'main.c'. Really
fixing this would require changing around 30 other locations too.  I think
if we are going to switch to the EXIT_* macros, then the whole file should
be changed in one patch and making that fix shouldn't hold this patch up.

-- Meador



Re: [Qemu-devel] [PATCH 2/2] target-arm: Add anyvfp CPU

2015-07-13 Thread Meador Inge
On Mon, Jul 06, 2015 at 03:00:20PM -0700, Peter Crosthwaite wrote:

 So a better way to do this is via QOM properties. You can propertyify
 VFP support on the QOM type ARMCPU then users can use -global to set
 in on the command line. You could do this for any number of ARM CPU
 features you care about to create the combos you want on the command
 line rather than having an in tree CPU def for special cases.
 
 Have a look at the way the has_el3 feature is handled as a CPU property.

I will look into that.  Thank you.

 Do you have originals in a git with the author SOBs that you can just
 amend with your own editor notes?

Unfortunately for this case, no.  This is a very hold patch that was
originally in an SVN mirror.

-- Meador



Re: [Qemu-devel] [PATCH 0/2] target-arm: any CPUs for system-mode

2015-07-13 Thread Meador Inge
On Mon, Jul 06, 2015 at 04:05:46PM -0700, Peter Crosthwaite wrote:

 On Mon, Jul 6, 2015 at 3:49 PM, Peter Maydell peter.mayd...@linaro.org 
 wrote:
  On 6 July 2015 at 23:42, Peter Crosthwaite peter.crosthwa...@xilinx.com 
  wrote:
  On Mon, Jul 6, 2015 at 3:29 PM, Peter Maydell peter.mayd...@linaro.org 
  wrote:
  On 6 July 2015 at 19:53,  mead...@codesourcery.com wrote:
  From: Meador Inge mead...@codesourcery.com
 
  This patch series opens up the any CPU for system-mode and
  adds a new any variant named anyvfp that initializes the
  FP coprocessors as well.
 
  We deliberately removed cpu any for system mode in
  commit f5f6d38b7458b8a back in 2013; I think the rationale
  for its removal still holds. If you're emulating a system
  you're emulating a specific system and you get a real
  CPU. A CPU with no impdef sysregs or initialized feature
  and ID registers is broken...
 
  You can still have a CPU+RAM only machine model, load elfs and get
  meaningful result on a debugger.
 
  Yeah, but what does any get you over just going ahead
  and specifying your CPU type? What interrupt controller
  should the any CPU type have? Generic timers? Etc.
 
 
 None and none. You are only interested in CPU internal state with no IO at 
 all.

Exactly.  We have a use-case where QEMU acts as basically an ISS and we
only care about architecture level support.  So, someone compiles their
application with various options (-march=armv7-a, -march=arv5te, etc...)
and runs those through GDB that connects to the QEMU GDB stub.  From
the QEMU side we can launch an instance with '-cpu any' and expect most
applications to run on it regardless of how it was built with GCC.

This is a reasonable use-case and it is a very small change to QEMU,
which introduces hardly any complexity or maintenance burden.

  There isn't zero utility there, but I don't really think
  there's enough to justify cluttering up QEMU with when
  -cpu cortex-a15 is not very much more to type, and
  has the advantage of being something that actually
  exists in reality.

As mentioned above, there is utility and saying that it is clutter is a
bit of an exaggeration (it is 5 deletions(-) that introduces *one* new
option).

 
 There is a clean definition of an ARM CPU without any IO however which
 has utility in compiler testing.

I agree.

-- Meador



Re: [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used

2015-07-08 Thread Meador Inge
On Mon, Jul 06, 2015 at 09:43:20PM +0200, Laurent Vivier wrote:

 Global comment: you should use EXIT_SUCCESS and EXIT_FAILURE from stdlib.h

Will fix.  Thanks.

-- Meador



Re: [Qemu-devel] [PATCH v2] MIPS: Translate breaks and traps into the appropriate signal

2013-02-04 Thread Meador Inge
Ping: http://patchwork.ozlabs.org/patch/211162/.

On 01/10/2013 04:50 PM, Meador Inge wrote:
 GCC and GAS are capable of generating traps or breaks to check for
 division by zero.  Additionally, GAS is capable of generating traps
 or breaks to check for overflow on certain division and multiplication
 operations.  The Linux kernel translates these traps and breaks into
 signals.  This patch implements the corresponding feature in QEMU.
 
 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
 Changes since v1:
 
   * Moved the BRK_* enumerations from target-mips/cpu.h to
 linux-user/main.c since they are only used in main.c
 
   * Fixed some style violations found by checkpatch.pl.
 
   * Removed a superfluous break.
 
  linux-user/main.c |   76 
 -
  1 file changed, 75 insertions(+), 1 deletion(-)
 
 diff --git a/linux-user/main.c b/linux-user/main.c
 index 9ade1bf..583940c 100644
 --- a/linux-user/main.c
 +++ b/linux-user/main.c
 @@ -2182,6 +2182,33 @@ static int do_store_exclusive(CPUMIPSState *env)
  return segv;
  }
  
 +/* Break codes */
 +enum {
 +BRK_OVERFLOW = 6,
 +BRK_DIVZERO = 7
 +};
 +
 +static int do_break(CPUMIPSState *env, target_siginfo_t *info,
 +unsigned int code)
 +{
 +int ret = -1;
 +
 +switch (code) {
 +case BRK_OVERFLOW:
 +case BRK_DIVZERO:
 +info-si_signo = TARGET_SIGFPE;
 +info-si_errno = 0;
 +info-si_code = (code == BRK_OVERFLOW) ? FPE_INTOVF : FPE_INTDIV;
 +queue_signal(env, info-si_signo, *info);
 +ret = 0;
 +break;
 +default:
 +break;
 +}
 +
 +return ret;
 +}
 +
  void cpu_loop(CPUMIPSState *env)
  {
  target_siginfo_t info;
 @@ -2297,8 +2324,55 @@ done_syscall:
  info.si_code = TARGET_ILL_ILLOPC;
  queue_signal(env, info.si_signo, info);
  break;
 +/* The code below was inspired by the MIPS Linux kernel trap
 + * handling code in arch/mips/kernel/traps.c.
 + */
 +case EXCP_BREAK:
 +{
 +abi_ulong trap_instr;
 +unsigned int code;
 +
 +ret = get_user_ual(trap_instr, env-active_tc.PC);
 +if (ret != 0) {
 +goto error;
 +}
 +
 +/* As described in the original Linux kernel code, the
 + * below checks on 'code' are to work around an old
 + * assembly bug.
 + */
 +code = ((trap_instr  6)  ((1  20) - 1));
 +if (code = (1  10)) {
 +code = 10;
 +}
 +
 +if (do_break(env, info, code) != 0) {
 +goto error;
 +}
 +}
 +break;
 +case EXCP_TRAP:
 +{
 +abi_ulong trap_instr;
 +unsigned int code = 0;
 +
 +ret = get_user_ual(trap_instr, env-active_tc.PC);
 +if (ret != 0) {
 +goto error;
 +}
 +
 +/* The immediate versions don't provide a code.  */
 +if (!(trap_instr  0xFC00)) {
 +code = ((trap_instr  6)  ((1  10) - 1));
 +}
 +
 +if (do_break(env, info, code) != 0) {
 +goto error;
 +}
 +}
 +break;
  default:
 -//error:
 +error:
  fprintf(stderr, qemu: unhandled CPU exception 0x%x - 
 aborting\n,
  trapnr);
  cpu_dump_state(env, stderr, fprintf, 0);
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded



[Qemu-devel] [PATCH] MIPS: Translate breaks and traps into the appropriate signal

2013-01-10 Thread Meador Inge
GCC and GAS are capable of generating traps or breaks to check for
division by zero.  Additionally, GAS is capable of generating traps
or breaks to check for overflow on certain division and multiplication
operations.  The Linux kernel translates these traps and breaks into
signals.  This patch implements the corresponding feature in QEMU.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/main.c |   64 -
 target-mips/cpu.h |6 +
 2 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9ade1bf..b9532e0 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2182,6 +2182,26 @@ static int do_store_exclusive(CPUMIPSState *env)
 return segv;
 }
 
+static int do_break(CPUMIPSState *env, target_siginfo_t *info,
+unsigned int code)
+{
+int ret = -1;
+
+switch (code) {
+case BRK_OVERFLOW:
+case BRK_DIVZERO:
+info-si_signo = TARGET_SIGFPE;
+info-si_errno = 0;
+info-si_code = (code == BRK_OVERFLOW) ? FPE_INTOVF : FPE_INTDIV;
+queue_signal(env, info-si_signo, *info);
+ret = 0;
+default:
+break;
+}
+
+return ret;
+}
+
 void cpu_loop(CPUMIPSState *env)
 {
 target_siginfo_t info;
@@ -2297,8 +2317,50 @@ done_syscall:
 info.si_code = TARGET_ILL_ILLOPC;
 queue_signal(env, info.si_signo, info);
 break;
+/* The code below was inspired by the MIPS Linux kernel trap
+ * handling code in arch/mips/kernel/traps.c.
+ */
+case EXCP_BREAK:
+{
+abi_ulong trap_instr;
+unsigned int code;
+
+ret = get_user_ual(trap_instr, env-active_tc.PC);
+if (ret != 0)
+goto error;
+
+/* As described in the original Linux kernel code, the
+ * below checks on 'code' are to work around an old
+ * assembly bug.
+ */
+code = ((trap_instr  6)  ((1  20) - 1));
+if (code = (1  10))
+code = 10;
+
+if (do_break(env, info, code) != 0)
+goto error;
+break;
+}
+case EXCP_TRAP:
+{
+abi_ulong trap_instr;
+unsigned int code = 0;
+
+ret = get_user_ual(trap_instr, env-active_tc.PC);
+if (ret != 0)
+goto error;
+
+/* The immediate versions don't provide a code.  */
+if (!(trap_instr  0xFC00))
+code = ((trap_instr  6)  ((1  10) - 1));
+
+if (do_break(env, info, code) != 0)
+goto error;
+break;
+}
+break;
 default:
-//error:
+error:
 fprintf(stderr, qemu: unhandled CPU exception 0x%x - aborting\n,
 trapnr);
 cpu_dump_state(env, stderr, fprintf, 0);
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 5963d62..c5fbe04 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -620,6 +620,12 @@ enum {
 /* Dummy exception for conditional stores.  */
 #define EXCP_SC 0x100
 
+/* Break codes */
+enum {
+BRK_OVERFLOW = 6,
+BRK_DIVZERO = 7
+};
+
 /*
  * This is an interrnally generated WAKE request line.
  * It is driven by the CPU itself. Raised when the MT
-- 
1.7.9.5




Re: [Qemu-devel] [PATCH] MIPS: Translate breaks and traps into the appropriate signal

2013-01-10 Thread Meador Inge
On 01/10/2013 03:57 PM, Stefan Weil wrote:

 please check your patch before submitting it to qemu-devel.
 See also http://wiki.qemu.org/Contribute/SubmitAPatch.

Ah, thanks for the pointer.  I have fixed the style violations.


-- 
Meador Inge
CodeSourcery / Mentor Embedded



Re: [Qemu-devel] [PATCH] MIPS: Translate breaks and traps into the appropriate signal

2013-01-10 Thread Meador Inge
On 01/10/2013 04:12 PM, Peter Maydell wrote:

 This is an OS/ABI specific define, right? I don't think it
 belongs in the target-mips header file. Since it only has one
 user, I think you could reasonably just put it in linux-user/main.c.

The enum will only be used in the MIPS CPU loop.  I originally put it in
target-mips/cpu.h because that is where the exception codes
are defined.   However, the one user argument makes sense to me.  I
moved the enum definition.

Thanks for the review.

-- 
Meador Inge
CodeSourcery / Mentor Embedded



[Qemu-devel] [PATCH v2] MIPS: Translate breaks and traps into the appropriate signal

2013-01-10 Thread Meador Inge
GCC and GAS are capable of generating traps or breaks to check for
division by zero.  Additionally, GAS is capable of generating traps
or breaks to check for overflow on certain division and multiplication
operations.  The Linux kernel translates these traps and breaks into
signals.  This patch implements the corresponding feature in QEMU.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
Changes since v1:

  * Moved the BRK_* enumerations from target-mips/cpu.h to
linux-user/main.c since they are only used in main.c

  * Fixed some style violations found by checkpatch.pl.

  * Removed a superfluous break.

 linux-user/main.c |   76 -
 1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9ade1bf..583940c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2182,6 +2182,33 @@ static int do_store_exclusive(CPUMIPSState *env)
 return segv;
 }
 
+/* Break codes */
+enum {
+BRK_OVERFLOW = 6,
+BRK_DIVZERO = 7
+};
+
+static int do_break(CPUMIPSState *env, target_siginfo_t *info,
+unsigned int code)
+{
+int ret = -1;
+
+switch (code) {
+case BRK_OVERFLOW:
+case BRK_DIVZERO:
+info-si_signo = TARGET_SIGFPE;
+info-si_errno = 0;
+info-si_code = (code == BRK_OVERFLOW) ? FPE_INTOVF : FPE_INTDIV;
+queue_signal(env, info-si_signo, *info);
+ret = 0;
+break;
+default:
+break;
+}
+
+return ret;
+}
+
 void cpu_loop(CPUMIPSState *env)
 {
 target_siginfo_t info;
@@ -2297,8 +2324,55 @@ done_syscall:
 info.si_code = TARGET_ILL_ILLOPC;
 queue_signal(env, info.si_signo, info);
 break;
+/* The code below was inspired by the MIPS Linux kernel trap
+ * handling code in arch/mips/kernel/traps.c.
+ */
+case EXCP_BREAK:
+{
+abi_ulong trap_instr;
+unsigned int code;
+
+ret = get_user_ual(trap_instr, env-active_tc.PC);
+if (ret != 0) {
+goto error;
+}
+
+/* As described in the original Linux kernel code, the
+ * below checks on 'code' are to work around an old
+ * assembly bug.
+ */
+code = ((trap_instr  6)  ((1  20) - 1));
+if (code = (1  10)) {
+code = 10;
+}
+
+if (do_break(env, info, code) != 0) {
+goto error;
+}
+}
+break;
+case EXCP_TRAP:
+{
+abi_ulong trap_instr;
+unsigned int code = 0;
+
+ret = get_user_ual(trap_instr, env-active_tc.PC);
+if (ret != 0) {
+goto error;
+}
+
+/* The immediate versions don't provide a code.  */
+if (!(trap_instr  0xFC00)) {
+code = ((trap_instr  6)  ((1  10) - 1));
+}
+
+if (do_break(env, info, code) != 0) {
+goto error;
+}
+}
+break;
 default:
-//error:
+error:
 fprintf(stderr, qemu: unhandled CPU exception 0x%x - aborting\n,
 trapnr);
 cpu_dump_state(env, stderr, fprintf, 0);
-- 
1.7.9.5




Re: [Qemu-devel] [PATCH v1 4/4] hw: Add support for a dummy ARMv7-M board

2012-08-28 Thread Meador Inge
On 08/28/2012 07:48 AM, Peter Maydell wrote:

 On 27 August 2012 21:37, Meador Inge mead...@codesourcery.com wrote:
 This patch adds support for a dummy ARMv7-M board so that
 QEMU can be used as an ISS for ARMv7-M processors.  For example,
 running an image compiled for the Cortex-M3 with -cpu cortex-m3
 should just work.
 
 So what programs would run on this 'dummy' board which would not
 execute correctly on the existing stellaris board models?

Similar programs will run on the Stellaris models, but the RAM on
those models is severely limited (8KB for LM3S811EVB and 64KB for LM3S6965EVB)
and it is hard wired.  Having some board that can handle ARMv7-M with more RAM
(and can be used with -m) is useful.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v1 0/4] Improve ARMv7-M architecture emulation

2012-08-27 Thread Meador Inge
Hi All,

This patch series is an attempt to improve the current ARMv7-M support
by making it easier to run applications that only require architecture
level support from the emulation (basically an ISS).  We are mostly there
already, but there are some cases that we don't handle well.  For example,
running an ARMv7-M application that uses SVC with only '-cpu cortex-m3'
currently will not work because the NVIC is not initialized (the Cortex-M3
gets wedged into the default Integrator/CP board, hence PATCH 3).

The first patch fixes support for using -kernel with ARMv7-M applications.
The second patch fixes the SYS_HEAPINFO semihosting call to work for ARMv7-M
applications.  The third patch allows for the default machine to be chosen
depending on what -cpu is specified.  The final patch adds support for a
dummy ARMv7-M board so that QEMU can be used as an ISS for ARMv7-M
applications.

Meador Inge (4):
  hw: Add support for loading ARMv7-M applications via -kernel
  target-arm: Make SYS_HEAPINFO work for ARMv7-M
  hw: Deduce the default machine from the specified CPU model
  hw: Add support for a dummy ARMv7-M board

 hw/alpha_dp264.c  |2 +-
 hw/arm/Makefile.objs  |1 +
 hw/armv7m.c   |   13 +
 hw/axis_dev88.c   |2 +-
 hw/boards.h   |4 ++--
 hw/dummy_armv7m.c |   40 
 hw/integratorcp.c |2 +-
 hw/lm32_boards.c  |3 +--
 hw/mcf5208.c  |2 +-
 hw/milkymist.c|1 -
 hw/mips_malta.c   |2 +-
 hw/openrisc_sim.c |2 +-
 hw/pc_piix.c  |2 +-
 hw/pc_sysfw.c |2 +-
 hw/petalogix_ml605_mmu.c  |1 -
 hw/petalogix_s3adsp1800_mmu.c |2 +-
 hw/ppc_newworld.c |2 +-
 hw/ppc_oldworld.c |2 +-
 hw/puv3.c |2 +-
 hw/s390-virtio.c  |2 +-
 hw/shix.c |2 +-
 hw/sun4m.c|2 +-
 hw/sun4u.c|2 +-
 hw/xtensa_sim.c   |2 +-
 qapi-schema.json  |4 ++--
 target-arm/arm-semi.c |8 +++-
 vl.c  |   38 +-
 27 files changed, 108 insertions(+), 39 deletions(-)
 create mode 100644 hw/dummy_armv7m.c

-- 
1.7.7.6




[Qemu-devel] [PATCH v1 2/4] target-arm: Make SYS_HEAPINFO work for ARMv7-M

2012-08-27 Thread Meador Inge
The current implementation of the ARM semi-hosting SYS_HEAPINFO
system call assumes that the base address of RAM for all ARM devices
is 0x0.  This isn't true for ARMv7-M devices, which uses a base of
0x2000 for SRAM.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-arm/arm-semi.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
index 73bde58..fd90794 100644
--- a/target-arm/arm-semi.c
+++ b/target-arm/arm-semi.c
@@ -486,7 +486,13 @@ uint32_t do_arm_semihosting(CPUARMState *env)
 ptr[3] = tswap32(0); /* Stack limit.  */
 unlock_user(ptr, ARG(0), 16);
 #else
-limit = ram_size;
+/* For ARMv7-M use the base address of SRAM as specified by the
+   architecture.  */
+if (arm_feature(env, ARM_FEATURE_M)) {
+limit = 0x2000 + ram_size;
+} else {
+limit = ram_size;
+}
 if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0)))
 /* FIXME - should this error code be -TARGET_EFAULT ? */
 return (uint32_t)-1;
-- 
1.7.7.6




[Qemu-devel] [PATCH v1 3/4] hw: Deduce the default machine from the specified CPU model

2012-08-27 Thread Meador Inge
This changes the driver behavior to choose the default machine
model based on the CPU being used.  Defaulting the machine this
way makes it easier to use QEMU as an ISS by just specifying
the -cpu option since a default machine that is suitable for
emulating the full ISA can be chosen.

For example, currently on ARM the ARM Integrator/CP board is
chosen as the default machine when specifying just a CPU.
However, this doesn't work well when passing -cpu cortex-m3
since on ARMv7-M processors the NVIC is a part of the architecture
and is needed to support instructions like SVC.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 hw/alpha_dp264.c  |2 +-
 hw/axis_dev88.c   |2 +-
 hw/boards.h   |4 ++--
 hw/integratorcp.c |2 +-
 hw/lm32_boards.c  |3 +--
 hw/mcf5208.c  |2 +-
 hw/milkymist.c|1 -
 hw/mips_malta.c   |2 +-
 hw/openrisc_sim.c |2 +-
 hw/pc_piix.c  |2 +-
 hw/pc_sysfw.c |2 +-
 hw/petalogix_ml605_mmu.c  |1 -
 hw/petalogix_s3adsp1800_mmu.c |2 +-
 hw/ppc_newworld.c |2 +-
 hw/ppc_oldworld.c |2 +-
 hw/puv3.c |2 +-
 hw/s390-virtio.c  |2 +-
 hw/shix.c |2 +-
 hw/sun4m.c|2 +-
 hw/sun4u.c|2 +-
 hw/xtensa_sim.c   |2 +-
 qapi-schema.json  |4 ++--
 vl.c  |   38 +-
 23 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/hw/alpha_dp264.c b/hw/alpha_dp264.c
index 9eb939f..d6717aa 100644
--- a/hw/alpha_dp264.c
+++ b/hw/alpha_dp264.c
@@ -169,7 +169,7 @@ static QEMUMachine clipper_machine = {
 .desc = Alpha DP264/CLIPPER,
 .init = clipper_init,
 .max_cpus = 4,
-.is_default = 1,
+.default_for_cpu_model = any,
 };
 
 static void clipper_machine_init(void)
diff --git a/hw/axis_dev88.c b/hw/axis_dev88.c
index eab6327..41078e6 100644
--- a/hw/axis_dev88.c
+++ b/hw/axis_dev88.c
@@ -353,7 +353,7 @@ static QEMUMachine axisdev88_machine = {
 .name = axis-dev88,
 .desc = AXIS devboard 88,
 .init = axisdev88_init,
-.is_default = 1,
+.default_for_cpu_model = any,
 };
 
 static void axisdev88_machine_init(void)
diff --git a/hw/boards.h b/hw/boards.h
index a2e0a54..6f52561 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -28,7 +28,7 @@ typedef struct QEMUMachine {
 no_floppy:1,
 no_cdrom:1,
 no_sdcard:1;
-int is_default;
+const char* default_for_cpu_model;
 const char *default_machine_opts;
 GlobalProperty *compat_props;
 struct QEMUMachine *next;
@@ -36,7 +36,7 @@ typedef struct QEMUMachine {
 } QEMUMachine;
 
 int qemu_register_machine(QEMUMachine *m);
-QEMUMachine *find_default_machine(void);
+QEMUMachine *find_default_machine(const char *cpu_model);
 
 extern QEMUMachine *current_machine;
 
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index d0e2e90..4df0774 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -509,7 +509,7 @@ static QEMUMachine integratorcp_machine = {
 .name = integratorcp,
 .desc = ARM Integrator/CP (ARM926EJ-S),
 .init = integratorcp_init,
-.is_default = 1,
+.default_for_cpu_model = any,
 };
 
 static void integratorcp_machine_init(void)
diff --git a/hw/lm32_boards.c b/hw/lm32_boards.c
index b76d800..2e5348b 100644
--- a/hw/lm32_boards.c
+++ b/hw/lm32_boards.c
@@ -290,14 +290,13 @@ static QEMUMachine lm32_evr_machine = {
 .name = lm32-evr,
 .desc = LatticeMico32 EVR32 eval system,
 .init = lm32_evr_init,
-.is_default = 1
+.default_for_cpu_model = any,
 };
 
 static QEMUMachine lm32_uclinux_machine = {
 .name = lm32-uclinux,
 .desc = lm32 platform for uClinux and u-boot by Theobroma Systems,
 .init = lm32_uclinux_init,
-.is_default = 0
 };
 
 static void lm32_machine_init(void)
diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index ee25b1b..0e28ffd9 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -291,7 +291,7 @@ static QEMUMachine mcf5208evb_machine = {
 .name = mcf5208evb,
 .desc = MCF5206EVB,
 .init = mcf5208evb_init,
-.is_default = 1,
+.default_for_cpu_model = any,
 };
 
 static void mcf5208evb_machine_init(void)
diff --git a/hw/milkymist.c b/hw/milkymist.c
index 2e7235b..a8606ea 100644
--- a/hw/milkymist.c
+++ b/hw/milkymist.c
@@ -207,7 +207,6 @@ static QEMUMachine milkymist_machine = {
 .name = milkymist,
 .desc = Milkymist One,
 .init = milkymist_init,
-.is_default = 0
 };
 
 static void milkymist_machine_init(void)
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index ad23f26..ac955e9 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -1020,7 +1020,7 @@ static QEMUMachine mips_malta_machine = {
 .desc = MIPS Malta Core LV,
 .init = mips_malta_init,
 .max_cpus = 16

[Qemu-devel] [PATCH v1 1/4] hw: Add support for loading ARMv7-M applications via -kernel

2012-08-27 Thread Meador Inge
The minimal amount of arm_boot_info has been setup to allow
for machines based off of ARMv7-M processors to be loaded via the
-kernel option.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 hw/armv7m.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/armv7m.c b/hw/armv7m.c
index 9f7..d11be09 100644
--- a/hw/armv7m.c
+++ b/hw/armv7m.c
@@ -150,10 +150,16 @@ static void armv7m_bitband_init(void)
 static void armv7m_reset(void *opaque)
 {
 ARMCPU *cpu = opaque;
+CPUARMState *env = cpu-env;
+const struct arm_boot_info *info = env-boot_info;
 
 cpu_reset(CPU(cpu));
+env-regs[15] = info-entry  0xfffe;
+env-thumb = info-entry  1;
 }
 
+static struct arm_boot_info armv7m_binfo;
+
 /* Init CPU and memory for a v7-M based board.
flash_size and sram_size are in kb.
Returns the NVIC array.  */
@@ -232,10 +238,16 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
 exit(1);
 }
 
+armv7m_binfo.ram_size = sram_size;
+armv7m_binfo.kernel_filename = kernel_filename;
+armv7m_binfo.kernel_cmdline = ;
+env-boot_info = armv7m_binfo;
+
 image_size = load_elf(kernel_filename, NULL, NULL, entry, lowaddr,
   NULL, big_endian, ELF_MACHINE, 1);
 if (image_size  0) {
 image_size = load_image_targphys(kernel_filename, 0, flash_size);
+entry = 0;
lowaddr = 0;
 }
 if (image_size  0) {
@@ -243,6 +255,7 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
 kernel_filename);
 exit(1);
 }
+armv7m_binfo.entry = entry;
 
 /* Hack to map an additional page of ram at the top of the address
space.  This stops qemu complaining about executing code outside RAM
-- 
1.7.7.6




[Qemu-devel] [PATCH v1 4/4] hw: Add support for a dummy ARMv7-M board

2012-08-27 Thread Meador Inge
This patch adds support for a dummy ARMv7-M board so that
QEMU can be used as an ISS for ARMv7-M processors.  For example,
running an image compiled for the Cortex-M3 with -cpu cortex-m3
should just work.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 hw/arm/Makefile.objs |1 +
 hw/dummy_armv7m.c|   40 
 2 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 hw/dummy_armv7m.c

diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 2b39fb3..ba3811f 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -9,6 +9,7 @@ obj-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o
 obj-y += exynos4210_rtc.o exynos4210_i2c.o
 obj-y += arm_mptimer.o a15mpcore.o
 obj-y += armv7m.o armv7m_nvic.o stellaris.o stellaris_enet.o
+obj-y += dummy_armv7m.o
 obj-y += highbank.o
 obj-y += pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o
 obj-y += pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
diff --git a/hw/dummy_armv7m.c b/hw/dummy_armv7m.c
new file mode 100644
index 000..0a6c922
--- /dev/null
+++ b/hw/dummy_armv7m.c
@@ -0,0 +1,40 @@
+/*
+ * Dummy board with just RAM and CPU for use as an ISS.
+ *
+ * Copyright (c) 2012 Mentor Graphics.
+ * Written by Meador Inge
+ *
+ * This code is licensed under the GPL.
+ */
+
+#include arm-misc.h
+#include boards.h
+#include exec-memory.h
+
+static void dummy_armv7m_init(ram_addr_t ram_size,
+  const char *boot_device,
+  const char *kernel_filename,
+  const char *kernel_cmdline,
+  const char *initrd_filename,
+  const char *cpu_model)
+{
+
+MemoryRegion *address_space_mem = get_system_memory();
+
+(void) armv7m_init(address_space_mem,
+   64, ram_size / 1024, kernel_filename, cpu_model);
+}
+
+static QEMUMachine dummy_armv7m_machine = {
+.name = dummy_armv7m,
+.desc = Dummy ARMv7-M,
+.init = dummy_armv7m_init,
+.default_for_cpu_model = cortex-m3,
+};
+
+static void dummy_armv7m_machine_init(void)
+{
+qemu_register_machine(dummy_armv7m_machine);
+}
+
+machine_init(dummy_armv7m_machine_init);
-- 
1.7.7.6




[Qemu-devel] [PATCH] hw/armv7m_nvic: Correctly register GIC region when setting up NVIC

2012-08-27 Thread Meador Inge
When setting up the NVIC memory regions the memory range
0x100..0xcff is aliased to an IO memory region that belongs
to the ARM GIC.  This aliased region should be added to the
NVIC memory container, but the actual GIC IO memory region
was being added instead.  This mixup was causing the wrong
IO memory access functions to be called when accessing parts
of the NVIC memory.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 hw/armv7m_nvic.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/armv7m_nvic.c b/hw/armv7m_nvic.c
index 6a0832e..5c09116 100644
--- a/hw/armv7m_nvic.c
+++ b/hw/armv7m_nvic.c
@@ -489,7 +489,8 @@ static int armv7m_nvic_init(SysBusDevice *dev)
  */
 memory_region_init_alias(s-gic_iomem_alias, nvic-gic, s-gic.iomem,
  0x100, 0xc00);
-memory_region_add_subregion_overlap(s-container, 0x100, s-gic.iomem, 
1);
+memory_region_add_subregion_overlap(s-container, 0x100,
+s-gic_iomem_alias, 1);
 /* Map the whole thing into system memory at the location required
  * by the v7M architecture.
  */
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH] target-mips: Enable access to required RDHWR hardware registers

2012-08-21 Thread Meador Inge
On 08/21/2012 05:14 AM, Andreas Färber wrote:

 Am 21.08.2012 01:41, schrieb Meador Inge:
 While running in the usermode emulator all of the MIPS32r2 *required*
 RDHWR hardware registers should be accessible (the Linux kernel enables
 access to these same registers).

 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  target-mips/translate.c |7 +--
  1 files changed, 5 insertions(+), 2 deletions(-)

 diff --git a/target-mips/translate.c b/target-mips/translate.c
 index 47daf85..849e75d 100644
 --- a/target-mips/translate.c
 +++ b/target-mips/translate.c
 @@ -12768,8 +12768,11 @@ void cpu_state_reset(CPUMIPSState *env)
  
  #if defined(CONFIG_USER_ONLY)
  env-hflags = MIPS_HFLAG_UM;
 -/* Enable access to the SYNCI_Step register.  */
 -env-CP0_HWREna |= (1  1);
 +if (env-insn_flags  ISA_MIPS32R2) {
 +/* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
 +   hardware registers.  */
 +env-CP0_HWREna |= 0x000F;
 +}
 
 So what about the non-MIPS32r2 case? IIUC then the SYNCI_Step register
 would no longer be accessible, which your commit message does not
 mention. Intentional?

Yes, that is intentional.  In Section 9.13 of [1] it is stated that these
registers are only required starting at release 2 of the architecture.  The
Linux kernel follows the same approach.

I guess I should just split this into two minor patches: (1) for enabling all
the registers and (2) for making them conditional on R2.

[1] MIPS® Architecture For Programmers,
Volume III: The MIPS32 (R) and microMIPS32TM Privileged Resource
Architecture
Revision 3.12

 If this is a bugfix for v1.2.0 don't forget to mark for-1.2.

Will do.

Thanks for the review.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH] target-mips: Enable access to required RDHWR hardware registers

2012-08-21 Thread Meador Inge
On 08/21/2012 10:52 AM, Aurelien Jarno wrote:

 Le 21/08/2012 17:41, Meador Inge a écrit :
 On 08/21/2012 05:14 AM, Andreas Färber wrote:
 So what about the non-MIPS32r2 case? IIUC then the SYNCI_Step register
 would no longer be accessible, which your commit message does not
 mention. Intentional?

 Yes, that is intentional.  In Section 9.13 of [1] it is stated that these
 registers are only required starting at release 2 of the architecture.  The
 Linux kernel follows the same approach.
 
 Remember this is linux user mode, as such you should not look at the
 MIPS architecture, but rather at the behavour of MIPS architecture +
 Linux kernel. SYNCI_Step is emulated by the Linux kernel for non R2
 CPUs, as such it should be  available even for non R2 CPUs *in user mode
 only*. At a first glance, it seems to be the same for CPUNum, CC and
 CCRes, but someone has to check that more in details.

Ah, thanks Aurelien.  I see that in the kernel sources now.  Specifically,
it seems that 'simulate_rdhwr' handles the emulation [1] and that it includes
support for CPUNum, SYNCI_Step, CC, CCRes, and ULR (User Local register).  So,
I will remove the conditional.

I am not quite sure how to handle ULR at the moment.

[1]
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=arch/mips/kernel/traps.c;h=9be3df1fa8a461dc4e1e5563582f483e4ed7c103;hb=HEAD

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH for-1.2 v2] target-mips: Enable access to required RDHWR hardware registers

2012-08-21 Thread Meador Inge
While running in the usermode emulator all of the required*
MIPS32r2 RDHWR hardware registers should be accessible (the
Linux kernel enables access to these same registers).  Note
that these registers are still enabled when the MIPS ISA is
not release 2.  This is OK since the Linux kernel emulates
access to them when they are not available in hardware.

* There is also the ULR register which is only recommended
  for full release 2 compliance.  Incidentally, accessing
  this register in the current implementation works fine
  without flipping its access bit.

Signed-off-by: Meador Inge mead...@codesourcery.com
---

v1 - v2:

 * Removed (env-insn_flags  ISA_MIPS32R2) condition per
   feedback from Andreas and Aurelien.

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

diff --git a/target-mips/translate.c b/target-mips/translate.c
index 47daf85..d643676 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -12768,8 +12768,9 @@ void cpu_state_reset(CPUMIPSState *env)
 
 #if defined(CONFIG_USER_ONLY)
 env-hflags = MIPS_HFLAG_UM;
-/* Enable access to the SYNCI_Step register.  */
-env-CP0_HWREna |= (1  1);
+/* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
+   hardware registers.  */
+env-CP0_HWREna |= 0x000F;
 if (env-CP0_Config1  (1  CP0C1_FP)) {
 env-hflags |= MIPS_HFLAG_FPU;
 }
-- 
1.7.7.6




[Qemu-devel] [PATCH] target-mips: Enable access to required RDHWR hardware registers

2012-08-20 Thread Meador Inge
While running in the usermode emulator all of the MIPS32r2 *required*
RDHWR hardware registers should be accessible (the Linux kernel enables
access to these same registers).

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-mips/translate.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/target-mips/translate.c b/target-mips/translate.c
index 47daf85..849e75d 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -12768,8 +12768,11 @@ void cpu_state_reset(CPUMIPSState *env)
 
 #if defined(CONFIG_USER_ONLY)
 env-hflags = MIPS_HFLAG_UM;
-/* Enable access to the SYNCI_Step register.  */
-env-CP0_HWREna |= (1  1);
+if (env-insn_flags  ISA_MIPS32R2) {
+/* Enable access to the CPUNum, SYNCI_Step, CC, and CCRes RDHWR
+   hardware registers.  */
+env-CP0_HWREna |= 0x000F;
+}
 if (env-CP0_Config1  (1  CP0C1_FP)) {
 env-hflags |= MIPS_HFLAG_FPU;
 }
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v2 2/2] linux-user: Use init_guest_space when -R and -B are specified

2012-08-13 Thread Meador Inge
On 08/13/2012 09:52 AM, Peter Maydell wrote:

 I'm currently putting together a linux-user pullreq (with Riku's
 agreement since he's currently a bit busy), so I'll just fix this
 as I put this patch in, though.

Thank you!

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH 01/10] hw/armv7m_nvic: Fix incorrect default for num-irqs property

2012-08-13 Thread Meador Inge
On 08/13/2012 10:31 AM, Peter Maydell wrote:

 Fix an incorrect default value for the num-irqs property (we were
 attempting to override it from the default set by the parent class
 but not succeeding, which meant that the lm3s6965evb model would
 assert on startup attempting to wire up nonexistent irq lines).
 Instead of trying to override the parent's Property array, we
 define an instance_init function which runs after default setup
 but before user property setting and can just fix up the default
 value in the gic_state struct.
 
 Reported-by: Peter Crosthwaite peter.crosthwa...@petalogix.com
 Tested-by: Peter Crosthwaite peter.crosthwa...@petalogix.com
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org

I noticed this assertion recently as well while hacking on some Cortex-M3 stuff:

qemu-system-arm: /home/meadori/Code/src/qemu/hw/qdev.c:310: qdev_get_gpio_in:
Assertion `n = 0  n  dev-num_gpio_in' failed.
Aborted (core dumped)

I just tried out your patch and it fixes the issue I was seeing.

Tested-by: Meador Inge mead...@codesoucery.com

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v2 0/2] Probe the guest memory space when using -R

2012-08-10 Thread Meador Inge
Ping ^ 2.

On 08/01/2012 01:47 PM, Meador Inge wrote:
 Ping.
 
 On 07/26/2012 09:50 PM, Meador Inge wrote:
 Hi,

 This patch series fixes an issue that was discussed here [1] where using -R
 can cause QEMU to fail to setup the guest address space because the guest 
 base
 validation fails.  I fixed this issue by (1) refactoring the guest space
 probing code into a single function for initializing the guest space and (2) 
 by 
 calling the guest space initialization code for both the case of reserving 
 the
 guest space upfront (-R) and the case where the initial memory space 
 base/size
 are gleaned from an ELF image.

 Tested by going through various combinations of -R size, -B base,
 -B base -R size, and neither -R or -B passed.  I also ran the libstdc++
 testsuite through the MIPS, ARM, and Power usermode emulators with -R set.
 No regressions.

 NOTE: This does not fix the problem that was raised concerning mapped the
 full 32-bit address space on a 64-bit system.  That will need to be another
 patch.

 - Changes since v1:

* Replaced '!host_start  !host_size' error check in 'init_guest_space'
  with an assert.

* Ensured that 'guest_validate_base' is passed the true guest base instead
  of the current host start address.

* s/init_guest_space(..., 0)/init_guest_space(..., false);/

* Fixed typo in 'init_guest_space' header comment.

 [1] http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg04508.html

 Signed-off-by: Meador Inge mead...@codesourcery.com

 Meador Inge (2):
   linux-user: Factor out guest space probing into a function
   linux-user: Use init_guest_space when -R and -B are specified

  linux-user/elfload.c |  161 
 ++
  linux-user/main.c|   35 ++-
  linux-user/qemu.h|   15 -
  3 files changed, 140 insertions(+), 71 deletions(-)

 
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH] MIPS: Correct FCR0 initialization

2012-08-10 Thread Meador Inge
On 08/10/2012 09:30 AM, Andreas Färber wrote:

 OK, so you didn't retract them but Meador did comment:
 
  I submitted a patch to fix this issue and the FCR0 issue a few months back 
  [1].
  Andreas reviewed it, but the patch never got committed.
  
  [1] http://patchwork.ozlabs.org/patch/144353/
 They're definitely different in scope and changes, whatever process and
 tools you guys use internally. And our policy is to give preference to
 the earlier patch to not invite people to redo other people's patches
 with different SoB (not saying you are, same company after all).

Please consider my patch retracted.  Maciej's work superseded mine.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v2 0/2] Probe the guest memory space when using -R

2012-08-01 Thread Meador Inge
Ping.

On 07/26/2012 09:50 PM, Meador Inge wrote:
 Hi,
 
 This patch series fixes an issue that was discussed here [1] where using -R
 can cause QEMU to fail to setup the guest address space because the guest base
 validation fails.  I fixed this issue by (1) refactoring the guest space
 probing code into a single function for initializing the guest space and (2) 
 by 
 calling the guest space initialization code for both the case of reserving the
 guest space upfront (-R) and the case where the initial memory space base/size
 are gleaned from an ELF image.
 
 Tested by going through various combinations of -R size, -B base,
 -B base -R size, and neither -R or -B passed.  I also ran the libstdc++
 testsuite through the MIPS, ARM, and Power usermode emulators with -R set.
 No regressions.
 
 NOTE: This does not fix the problem that was raised concerning mapped the
 full 32-bit address space on a 64-bit system.  That will need to be another
 patch.
 
 - Changes since v1:
 
* Replaced '!host_start  !host_size' error check in 'init_guest_space'
  with an assert.
 
* Ensured that 'guest_validate_base' is passed the true guest base instead
  of the current host start address.
 
* s/init_guest_space(..., 0)/init_guest_space(..., false);/
 
* Fixed typo in 'init_guest_space' header comment.
 
 [1] http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg04508.html
 
 Signed-off-by: Meador Inge mead...@codesourcery.com
 
 Meador Inge (2):
   linux-user: Factor out guest space probing into a function
   linux-user: Use init_guest_space when -R and -B are specified
 
  linux-user/elfload.c |  161 
 ++
  linux-user/main.c|   35 ++-
  linux-user/qemu.h|   15 -
  3 files changed, 140 insertions(+), 71 deletions(-)
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [Bug 1031920] [NEW] Linux user gdbserver does not respond to remote `Ctrl-C' interrupts

2012-08-01 Thread Meador Inge
Public bug reported:

The bug was reproduced in a recent mainline build for ARM Linux by
starting emulation with a gdbserver:

$ qemu-arm -g 1234 a.out

and then connecting from gdb:

(gdb) target remote :1234
Remote debugging using :1234
[New Remote target]
[Switching to Remote target]
0x8ba8 in _start ()
(gdb) b main
Breakpoint 1 at 0x8cb0: file hello.c, line 5.
(gdb) cont
Continuing.

Breakpoint 1, main (argc=1, argv=0xf6fff24c) at hello.c:5
5 int n = 0;
(gdb) l
1   #include stdio.h
2
3   int main (int argc, char **argv)
4   {
5 int n = 0;
6
7 for (;;) {
8printf (Hello, World!\n);
9sleep (5);
10}
(gdb) cont
Continuing.
^C^CInterrupted while waiting for the program.
Give up (and stop debugging it)? (y or n) y

Notice that the `Ctrl-C' interrupts are ignored.

** Affects: qemu
 Importance: Undecided
 Status: New

** Description changed:

- The bug was reproduce in a recent mainline build for ARM Linux by
+ The bug was reproduced in a recent mainline build for ARM Linux by
  starting emulation with a gdbserver:
  
  $ qemu-arm -g 1234 a.out
  
  and then connecting from gdb:
  
  (gdb) target remote :1234
  Remote debugging using :1234
  [New Remote target]
  [Switching to Remote target]
  0x8ba8 in _start ()
  (gdb) b main
  Breakpoint 1 at 0x8cb0: file hello.c, line 5.
  (gdb) cont
  Continuing.
  
  Breakpoint 1, main (argc=1, argv=0xf6fff24c) at hello.c:5
  5   int n = 0;
  (gdb) l
  1 #include stdio.h
- 2 
+ 2
  3 int main (int argc, char **argv)
  4 {
  5   int n = 0;
- 6 
+ 6
  7   for (;;) {
  8  printf (Hello, World!\n);
  9  sleep (5);
  10  }
  (gdb) cont
  Continuing.
  ^C^CInterrupted while waiting for the program.
  Give up (and stop debugging it)? (y or n) y
  
  Notice that the `Ctrl-C' interrupts are ignored.

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

Title:
  Linux user gdbserver does not respond to remote  `Ctrl-C' interrupts

Status in QEMU:
  New

Bug description:
  The bug was reproduced in a recent mainline build for ARM Linux by
  starting emulation with a gdbserver:

  $ qemu-arm -g 1234 a.out

  and then connecting from gdb:

  (gdb) target remote :1234
  Remote debugging using :1234
  [New Remote target]
  [Switching to Remote target]
  0x8ba8 in _start ()
  (gdb) b main
  Breakpoint 1 at 0x8cb0: file hello.c, line 5.
  (gdb) cont
  Continuing.

  Breakpoint 1, main (argc=1, argv=0xf6fff24c) at hello.c:5
  5   int n = 0;
  (gdb) l
  1 #include stdio.h
  2
  3 int main (int argc, char **argv)
  4 {
  5   int n = 0;
  6
  7   for (;;) {
  8  printf (Hello, World!\n);
  9  sleep (5);
  10  }
  (gdb) cont
  Continuing.
  ^C^CInterrupted while waiting for the program.
  Give up (and stop debugging it)? (y or n) y

  Notice that the `Ctrl-C' interrupts are ignored.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1031920/+subscriptions



[Qemu-devel] [PATCH v2 1/2] linux-user: Factor out guest space probing into a function

2012-07-26 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/elfload.c |  110 +++---
 linux-user/qemu.h|   13 ++
 2 files changed, 90 insertions(+), 33 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f3b1552..7d8d866 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1385,6 +1385,73 @@ bool guest_validate_base(unsigned long guest_base)
 }
 #endif
 
+unsigned long init_guest_space(unsigned long host_start,
+   unsigned long host_size,
+   unsigned long guest_start,
+   bool fixed)
+{
+unsigned long current_start, real_start;
+int flags;
+
+assert(host_start || host_size);
+
+/* If just a starting address is given, then just verify that
+ * address.  */
+if (host_start  !host_size) {
+if (guest_validate_base(host_start)) {
+return host_start;
+} else {
+return (unsigned long)-1;
+}
+}
+
+/* Setup the initial flags and start address.  */
+current_start = host_start  qemu_host_page_mask;
+flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
+if (fixed) {
+flags |= MAP_FIXED;
+}
+
+/* Otherwise, a non-zero size region of memory needs to be mapped
+ * and validated.  */
+while (1) {
+/* Do not use mmap_find_vma here because that is limited to the
+ * guest address space.  We are going to make the
+ * guest address space fit whatever we're given.
+ */
+real_start = (unsigned long)
+mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+return (unsigned long)-1;
+}
+
+if ((real_start == current_start)
+ guest_validate_base(real_start - guest_start)) {
+break;
+}
+
+/* That address didn't work.  Unmap and try a different one.
+ * The address the host picked because is typically right at
+ * the top of the host address space and leaves the guest with
+ * no usable address space.  Resort to a linear search.  We
+ * already compensated for mmap_min_addr, so this should not
+ * happen often.  Probably means we got unlucky and host
+ * address space randomization put a shared library somewhere
+ * inconvenient.
+ */
+munmap((void *)real_start, host_size);
+current_start += qemu_host_page_size;
+if (host_start == current_start) {
+/* Theoretically possible if host doesn't have any suitably
+ * aligned areas.  Normally the first mmap will fail.
+ */
+return (unsigned long)-1;
+}
+}
+
+return real_start;
+}
+
 static void probe_guest_base(const char *image_name,
  abi_ulong loaddr, abi_ulong hiaddr)
 {
@@ -1411,46 +1478,23 @@ static void probe_guest_base(const char *image_name,
 }
 }
 host_size = hiaddr - loaddr;
-while (1) {
-/* Do not use mmap_find_vma here because that is limited to the
-   guest address space.  We are going to make the
-   guest address space fit whatever we're given.  */
-real_start = (unsigned long)
-mmap((void *)host_start, host_size, PROT_NONE,
- MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
-if (real_start == (unsigned long)-1) {
-goto exit_perror;
-}
-guest_base = real_start - loaddr;
-if ((real_start == host_start) 
-guest_validate_base(guest_base)) {
-break;
-}
-/* That address didn't work.  Unmap and try a different one.
-   The address the host picked because is typically right at
-   the top of the host address space and leaves the guest with
-   no usable address space.  Resort to a linear search.  We
-   already compensated for mmap_min_addr, so this should not
-   happen often.  Probably means we got unlucky and host
-   address space randomization put a shared library somewhere
-   inconvenient.  */
-munmap((void *)real_start, host_size);
-host_start += qemu_host_page_size;
-if (host_start == loaddr) {
-/* Theoretically possible if host doesn't have any suitably
-   aligned areas.  Normally the first mmap will fail.  */
-errmsg = Unable to find space for application;
-goto exit_errmsg;
-}
+
+/* Setup the initial guest memory space with ranges gleaned from
+ * the ELF image that is being loaded.
+ */
+real_start = init_guest_space(host_start, host_size, loaddr, false

[Qemu-devel] [PATCH v2 2/2] linux-user: Use init_guest_space when -R and -B are specified

2012-07-26 Thread Meador Inge
Roll the code used to initialize the guest memory space when -R
or -B is used into 'init_guest_space' and then call 'init_guest_space'
from the driver.  This way the reserved guest memory space can
be probed for.  Calling 'mmap' just once as is currently done is not
guaranteed to succeed since the host address space validation might fail.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/elfload.c |   59 ++---
 linux-user/main.c|   35 +
 linux-user/qemu.h|6 -
 3 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7d8d866..977521a 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -332,9 +332,17 @@ enum
 ARM_HWCAP_ARM_VFPv3D16  = 1  13,
 };
 
-#define TARGET_HAS_GUEST_VALIDATE_BASE
-/* We want the opportunity to check the suggested base */
-bool guest_validate_base(unsigned long guest_base)
+#define TARGET_HAS_VALIDATE_GUEST_SPACE
+/* Return 1 if the proposed guest space is suitable for the guest.
+ * Return 0 if the proposed guest space isn't suitable, but another
+ * address space should be tried.
+ * Return -1 if there is no way the proposed guest space can be
+ * valid regardless of the base.
+ * The guest code may leave a page mapped and populate it if the
+ * address is suitable.
+ */
+static int validate_guest_space(unsigned long guest_base,
+unsigned long guest_size)
 {
 unsigned long real_start, test_page_addr;
 
@@ -342,6 +350,15 @@ bool guest_validate_base(unsigned long guest_base)
  * commpage at 0x0fxx
  */
 test_page_addr = guest_base + (0x0f00  qemu_host_page_mask);
+
+/* If the commpage lies within the already allocated guest space,
+ * then there is no way we can allocate it.
+ */
+if (test_page_addr = guest_base
+test_page_addr = (guest_base + guest_size)) {
+ return -1;
+}
+
 /* Note it needs to be writeable to let us initialise it */
 real_start = (unsigned long)
  mmap((void *)test_page_addr, qemu_host_page_size,
@@ -1377,9 +1394,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int 
argc, int envc,
 return sp;
 }
 
-#ifndef TARGET_HAS_GUEST_VALIDATE_BASE
+#ifndef TARGET_HAS_VALIDATE_GUEST_SPACE
 /* If the guest doesn't have a validation function just agree */
-bool guest_validate_base(unsigned long guest_base)
+static int validate_guest_space(unsigned long guest_base,
+unsigned long guest_size)
 {
 return 1;
 }
@@ -1398,7 +1416,7 @@ unsigned long init_guest_space(unsigned long host_start,
 /* If just a starting address is given, then just verify that
  * address.  */
 if (host_start  !host_size) {
-if (guest_validate_base(host_start)) {
+if (validate_guest_space(host_start, host_size) == 1) {
 return host_start;
 } else {
 return (unsigned long)-1;
@@ -1415,6 +1433,8 @@ unsigned long init_guest_space(unsigned long host_start,
 /* Otherwise, a non-zero size region of memory needs to be mapped
  * and validated.  */
 while (1) {
+unsigned long real_size = host_size;
+
 /* Do not use mmap_find_vma here because that is limited to the
  * guest address space.  We are going to make the
  * guest address space fit whatever we're given.
@@ -1425,9 +1445,28 @@ unsigned long init_guest_space(unsigned long host_start,
 return (unsigned long)-1;
 }
 
-if ((real_start == current_start)
- guest_validate_base(real_start - guest_start)) {
-break;
+/* Ensure the address is properly aligned.  */
+if (real_start  ~qemu_host_page_mask) {
+munmap((void *)real_start, host_size);
+real_size = host_size + qemu_host_page_size;
+real_start = (unsigned long)
+mmap((void *)real_start, real_size, PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+return (unsigned long)-1;
+}
+real_start = HOST_PAGE_ALIGN(real_start);
+}
+
+/* Check to see if the address is valid.  */
+if (!host_start || real_start == current_start) {
+int valid = validate_guest_space(real_start - guest_start,
+ real_size);
+if (valid == 1) {
+break;
+} else if (valid == -1) {
+return (unsigned long)-1;
+}
+/* valid == 0, so try again. */
 }
 
 /* That address didn't work.  Unmap and try a different one.
@@ -1449,6 +1488,8 @@ unsigned long init_guest_space(unsigned long host_start,
 }
 }
 
+qemu_log(Reserved 0x%lx bytes of guest address space\n, host_size);
+
 return real_start;
 }
 
diff --git a/linux-user/main.c b/linux-user

[Qemu-devel] [PATCH v2 0/2] Probe the guest memory space when using -R

2012-07-26 Thread Meador Inge
Hi,

This patch series fixes an issue that was discussed here [1] where using -R
can cause QEMU to fail to setup the guest address space because the guest base
validation fails.  I fixed this issue by (1) refactoring the guest space
probing code into a single function for initializing the guest space and (2) by 
calling the guest space initialization code for both the case of reserving the
guest space upfront (-R) and the case where the initial memory space base/size
are gleaned from an ELF image.

Tested by going through various combinations of -R size, -B base,
-B base -R size, and neither -R or -B passed.  I also ran the libstdc++
testsuite through the MIPS, ARM, and Power usermode emulators with -R set.
No regressions.

NOTE: This does not fix the problem that was raised concerning mapped the
full 32-bit address space on a 64-bit system.  That will need to be another
patch.

- Changes since v1:

   * Replaced '!host_start  !host_size' error check in 'init_guest_space'
 with an assert.

   * Ensured that 'guest_validate_base' is passed the true guest base instead
 of the current host start address.

   * s/init_guest_space(..., 0)/init_guest_space(..., false);/

   * Fixed typo in 'init_guest_space' header comment.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg04508.html

Signed-off-by: Meador Inge mead...@codesourcery.com

Meador Inge (2):
  linux-user: Factor out guest space probing into a function
  linux-user: Use init_guest_space when -R and -B are specified

 linux-user/elfload.c |  161 ++
 linux-user/main.c|   35 ++-
 linux-user/qemu.h|   15 -
 3 files changed, 140 insertions(+), 71 deletions(-)

-- 
1.7.7.6




Re: [Qemu-devel] [PATCH 1/2] linux-user: Factor out guest space probing into a function

2012-07-25 Thread Meador Inge
On 07/10/2012 11:12 AM, Peter Maydell wrote:

 On 10 July 2012 16:57, Meador Inge mead...@codesourcery.com wrote:
 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  linux-user/elfload.c |  111 
 +++---
  linux-user/qemu.h|   11 +
  2 files changed, 89 insertions(+), 33 deletions(-)

 diff --git a/linux-user/elfload.c b/linux-user/elfload.c
 index f3b1552..44b4bdb 100644
 --- a/linux-user/elfload.c
 +++ b/linux-user/elfload.c
 @@ -1385,6 +1385,74 @@ bool guest_validate_base(unsigned long guest_base)
  }
  #endif

 +unsigned long init_guest_space(unsigned long host_start,
 +   unsigned long host_size,
 +   bool fixed)
 +{
 +unsigned long current_start, real_start;
 +int flags;
 +
 +/* Nothing to do here, move along.  */
 +if (!host_start  !host_size) {
 +return 0;
 +}
 
 This is a check that wasn't in the pre-refactoring code. Is it actually
 a possible case, or should we be asserting() (perhaps checking for
 bad ELF files and printing a suitable error message earlier)?

Yeah, that shouldn't happen.  An assert should be sufficient.

 +
 +/* If just a starting address is given, then just verify that
 + * address.  */
 +if (host_start  !host_size) {
 +if (guest_validate_base(host_start)) {
 +return host_start;
 +} else {
 +return (unsigned long)-1;
 +}
 +}
 +
 +/* Setup the initial flags and start address.  */
 +current_start = host_start  qemu_host_page_mask;
 +flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
 +if (fixed) {
 +flags |= MAP_FIXED;
 +}
 +
 +/* Otherwise, a non-zero size region of memory needs to be mapped
 + * and validated.  */
 +while (1) {
 +/* Do not use mmap_find_vma here because that is limited to the
 + * guest address space.  We are going to make the
 + * guest address space fit whatever we're given.
 + */
 +real_start = (unsigned long)
 +mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0);
 +if (real_start == (unsigned long)-1) {
 +return (unsigned long)-1;
 +}
 +
 +if ((real_start == current_start)  
 guest_validate_base(real_start)) {
 
 This doesn't look like it's going to be calling guest_validate_base()
 on the same value as the pre-refactoring code: before this commit
 we called g_v_b() on real_start - loaddr.

Gah, fixed.  Thanks for finding that.

 +break;
 +}
 +
 +/* That address didn't work.  Unmap and try a different one.
 + * The address the host picked because is typically right at
 + * the top of the host address space and leaves the guest with
 + * no usable address space.  Resort to a linear search.  We
 + * already compensated for mmap_min_addr, so this should not
 + * happen often.  Probably means we got unlucky and host
 + * address space randomization put a shared library somewhere
 + * inconvenient.
 + */
 +munmap((void *)real_start, host_size);
 +current_start += qemu_host_page_size;
 +if (host_start == current_start) {
 +/* Theoretically possible if host doesn't have any suitably
 + * aligned areas.  Normally the first mmap will fail.
 + */
 +return (unsigned long)-1;
 +}
 +}
 +
 +return real_start;
 +}
 +
  static void probe_guest_base(const char *image_name,
   abi_ulong loaddr, abi_ulong hiaddr)
  {
 @@ -1411,46 +1479,23 @@ static void probe_guest_base(const char *image_name,
  }
  }
  host_size = hiaddr - loaddr;
 -while (1) {
 -/* Do not use mmap_find_vma here because that is limited to the
 -   guest address space.  We are going to make the
 -   guest address space fit whatever we're given.  */
 -real_start = (unsigned long)
 -mmap((void *)host_start, host_size, PROT_NONE,
 - MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
 -if (real_start == (unsigned long)-1) {
 -goto exit_perror;
 -}
 -guest_base = real_start - loaddr;
 -if ((real_start == host_start) 
 -guest_validate_base(guest_base)) {
 -break;
 -}
 -/* That address didn't work.  Unmap and try a different one.
 -   The address the host picked because is typically right at
 -   the top of the host address space and leaves the guest with
 -   no usable address space.  Resort to a linear search.  We
 -   already compensated for mmap_min_addr, so this should not
 -   happen often.  Probably means we got unlucky and host
 -   address space

[Qemu-devel] [PATCH 0/2] Probe the guest memory space when using -R

2012-07-10 Thread Meador Inge
Hi,

This patch series fixes an issue that was discussed here [1] where -R
can fail when the mapped address space fails validation.  I fixed this
issue by (1) refactoring the guest space probing code into a single
function for initialing the guest space and (2) by calling the guest space
initializing code for both the case of reserving the guest memory space
upfront (-R) and the case where the initial memory space base/size are gleaned
from an ELF image.

Tested by going through various combinations of -R size, -B base,
-B base -R size, and neither -R or -B passed.  I also ran the libstdc++
testsuite through the MIPS, ARM, and Power usermode emulators with -R set.
No regressions.

NOTE: This does not fix the problem that was raised concerning mapped the
full 32-bit address space on a 64-bit system.  That will need to be another
patch.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg04508.html

Signed-off-by: Meador Inge mead...@codesourcery.com

Meador Inge (2):
  linux-user: Factor out guest space probing into a function
  linux-user: Use init_guest_space when -R and -B are specified

 linux-user/elfload.c |  162 ++
 linux-user/main.c|   35 ++-
 linux-user/qemu.h|   13 +++-
 3 files changed, 139 insertions(+), 71 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH 1/2] linux-user: Factor out guest space probing into a function

2012-07-10 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/elfload.c |  111 +++---
 linux-user/qemu.h|   11 +
 2 files changed, 89 insertions(+), 33 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f3b1552..44b4bdb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1385,6 +1385,74 @@ bool guest_validate_base(unsigned long guest_base)
 }
 #endif
 
+unsigned long init_guest_space(unsigned long host_start,
+   unsigned long host_size,
+   bool fixed)
+{
+unsigned long current_start, real_start;
+int flags;
+
+/* Nothing to do here, move along.  */
+if (!host_start  !host_size) {
+return 0;
+}
+
+/* If just a starting address is given, then just verify that
+ * address.  */
+if (host_start  !host_size) {
+if (guest_validate_base(host_start)) {
+return host_start;
+} else {
+return (unsigned long)-1;
+}
+}
+
+/* Setup the initial flags and start address.  */
+current_start = host_start  qemu_host_page_mask;
+flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
+if (fixed) {
+flags |= MAP_FIXED;
+}
+
+/* Otherwise, a non-zero size region of memory needs to be mapped
+ * and validated.  */
+while (1) {
+/* Do not use mmap_find_vma here because that is limited to the
+ * guest address space.  We are going to make the
+ * guest address space fit whatever we're given.
+ */
+real_start = (unsigned long)
+mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+return (unsigned long)-1;
+}
+
+if ((real_start == current_start)  guest_validate_base(real_start)) {
+break;
+}
+
+/* That address didn't work.  Unmap and try a different one.
+ * The address the host picked because is typically right at
+ * the top of the host address space and leaves the guest with
+ * no usable address space.  Resort to a linear search.  We
+ * already compensated for mmap_min_addr, so this should not
+ * happen often.  Probably means we got unlucky and host
+ * address space randomization put a shared library somewhere
+ * inconvenient.
+ */
+munmap((void *)real_start, host_size);
+current_start += qemu_host_page_size;
+if (host_start == current_start) {
+/* Theoretically possible if host doesn't have any suitably
+ * aligned areas.  Normally the first mmap will fail.
+ */
+return (unsigned long)-1;
+}
+}
+
+return real_start;
+}
+
 static void probe_guest_base(const char *image_name,
  abi_ulong loaddr, abi_ulong hiaddr)
 {
@@ -1411,46 +1479,23 @@ static void probe_guest_base(const char *image_name,
 }
 }
 host_size = hiaddr - loaddr;
-while (1) {
-/* Do not use mmap_find_vma here because that is limited to the
-   guest address space.  We are going to make the
-   guest address space fit whatever we're given.  */
-real_start = (unsigned long)
-mmap((void *)host_start, host_size, PROT_NONE,
- MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
-if (real_start == (unsigned long)-1) {
-goto exit_perror;
-}
-guest_base = real_start - loaddr;
-if ((real_start == host_start) 
-guest_validate_base(guest_base)) {
-break;
-}
-/* That address didn't work.  Unmap and try a different one.
-   The address the host picked because is typically right at
-   the top of the host address space and leaves the guest with
-   no usable address space.  Resort to a linear search.  We
-   already compensated for mmap_min_addr, so this should not
-   happen often.  Probably means we got unlucky and host
-   address space randomization put a shared library somewhere
-   inconvenient.  */
-munmap((void *)real_start, host_size);
-host_start += qemu_host_page_size;
-if (host_start == loaddr) {
-/* Theoretically possible if host doesn't have any suitably
-   aligned areas.  Normally the first mmap will fail.  */
-errmsg = Unable to find space for application;
-goto exit_errmsg;
-}
+
+/* Setup the initial guest memory space with ranges gleaned from
+ * the ELF image that is being loaded.
+ */
+real_start = init_guest_space(host_start, host_size, 0);
+if (real_start

[Qemu-devel] [PATCH 2/2] linux-user: Use init_guest_space when -R and -B are specified

2012-07-10 Thread Meador Inge
Modify the driver to initialize the guest address space when -R or -B
is specified so that the reserved memory space can be probed.  Calling
'mmap' just once as is currently done is not guaranteed to succeed since
the host address space validation might fail.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/elfload.c |   57 +++---
 linux-user/main.c|   35 +-
 linux-user/qemu.h|6 -
 3 files changed, 55 insertions(+), 43 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 44b4bdb..8de96bc 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -332,9 +332,17 @@ enum
 ARM_HWCAP_ARM_VFPv3D16  = 1  13,
 };
 
-#define TARGET_HAS_GUEST_VALIDATE_BASE
-/* We want the opportunity to check the suggested base */
-bool guest_validate_base(unsigned long guest_base)
+#define TARGET_HAS_VALIDATE_GUEST_SPACE
+/* Return 1 if the proposed guest space is suitable for the guest.
+ * Return 0 if the proposed guest space isn't suitable, but another
+ * address space should be tried.
+ * Return -1 if there is no way the proposed guest space can be
+ * valid regardless of the base.
+ * The guest code may leave a page mapped and populate it if the
+ * address is suitable.
+ */
+static int validate_guest_space(unsigned long guest_base,
+unsigned long guest_size)
 {
 unsigned long real_start, test_page_addr;
 
@@ -342,6 +350,15 @@ bool guest_validate_base(unsigned long guest_base)
  * commpage at 0x0fxx
  */
 test_page_addr = guest_base + (0x0f00  qemu_host_page_mask);
+
+/* If the commpage lies within the already allocated guest space,
+ * then there is no way we can allocate it.
+ */
+if (test_page_addr = guest_base
+test_page_addr = (guest_base + guest_size)) {
+ return -1;
+}
+
 /* Note it needs to be writeable to let us initialise it */
 real_start = (unsigned long)
  mmap((void *)test_page_addr, qemu_host_page_size,
@@ -1377,9 +1394,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int 
argc, int envc,
 return sp;
 }
 
-#ifndef TARGET_HAS_GUEST_VALIDATE_BASE
+#ifndef TARGET_HAS_VALIDATE_GUEST_SPACE
 /* If the guest doesn't have a validation function just agree */
-bool guest_validate_base(unsigned long guest_base)
+static int validate_guest_space(unsigned long guest_base,
+unsigned long guest_size)
 {
 return 1;
 }
@@ -1400,7 +1418,7 @@ unsigned long init_guest_space(unsigned long host_start,
 /* If just a starting address is given, then just verify that
  * address.  */
 if (host_start  !host_size) {
-if (guest_validate_base(host_start)) {
+if (validate_guest_space(host_start, host_size) == 1) {
 return host_start;
 } else {
 return (unsigned long)-1;
@@ -1417,6 +1435,8 @@ unsigned long init_guest_space(unsigned long host_start,
 /* Otherwise, a non-zero size region of memory needs to be mapped
  * and validated.  */
 while (1) {
+unsigned long real_size = host_size;
+
 /* Do not use mmap_find_vma here because that is limited to the
  * guest address space.  We are going to make the
  * guest address space fit whatever we're given.
@@ -1427,8 +1447,27 @@ unsigned long init_guest_space(unsigned long host_start,
 return (unsigned long)-1;
 }
 
-if ((real_start == current_start)  guest_validate_base(real_start)) {
-break;
+/* Ensure the address is properly aligned.  */
+if (real_start  ~qemu_host_page_mask) {
+munmap((void *)real_start, host_size);
+real_size = host_size + qemu_host_page_size;
+real_start = (unsigned long)
+mmap((void *)real_start, real_size, PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+return (unsigned long)-1;
+}
+real_start = HOST_PAGE_ALIGN(real_start);
+}
+
+/* Check to see if the address is valid.  */
+if (!host_start || real_start == current_start) {
+int valid = validate_guest_space(real_start, real_size);
+if (valid == 1) {
+break;
+} else if (valid == -1) {
+return (unsigned long)-1;
+}
+/* valid == 0, so try again. */
 }
 
 /* That address didn't work.  Unmap and try a different one.
@@ -1450,6 +1489,8 @@ unsigned long init_guest_space(unsigned long host_start,
 }
 }
 
+qemu_log(Reserved 0x%lx bytes of guest address space\n, host_size);
+
 return real_start;
 }
 
diff --git a/linux-user/main.c b/linux-user/main.c
index d0e0e4f..ef56c09 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3425,39 +3425,16 @@ int main(int argc, char **argv, char **envp

Re: [Qemu-devel] [RFC PATCH 1/1] linux-user: Probe the guest base for shared objects when needed

2012-06-27 Thread Meador Inge
On 06/12/2012 09:08 AM, Richard Henderson wrote:

 I think this is one of those cases where the -B or -R options
 (or QEMU_GUEST_BASE and QEMU_RESERVED_VA env variables) are the best
 way forward for whatever cpu you're emulating.  That or a change to
 the target's default ld script, not to link real executables quite so 
 low in the address space.

Per Richard's recommendation I experimented with -R for my use cases.  It seems
to mostly work, but for ARM GNU/Linux there is an issue that makes it awkward
to work with.

In particular, this commit [1] added validation for the guest base as a way to
ensure that the kernel-provided user mode helper functions on ARM can be mapped.
The validation function is invoked by 'probe_guest_base', but also in
main.c:3456 whenever -R or -B is used:

if (reserved_va || have_guest_base) {
if (!guest_validate_base(guest_base)) {
fprintf(stderr, Guest base/Reserved VA rejected by guest code\n);
exit(1);
}
}

Thus we might be able to allocate the reserved VA region, but it might fail the
validation and exit.  I had this actually happen on many test cases when testing
'-R 128M' with portions of the GCC testsuite.

To solve this issue I experimented with performing a similar probing in 'main'
as in 'probe_guest_base' so that we can find a reserved VA region that also
passes validation.  If a region isn't found that can be validated, then QEMU
gives up.  Does this approach seem reasonable?


[1]
http://git.qemu.org/?p=qemu.git;a=commit;h=97cc75606aef406e90a243cdb25347039003e7f0

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [RFC PATCH 1/1] linux-user: Probe the guest base for shared objects when needed

2012-06-27 Thread Meador Inge
On 06/27/2012 12:32 PM, Richard Henderson wrote:

 On 06/27/2012 08:51 AM, Meador Inge wrote:
 To solve this issue I experimented with performing a similar probing in 
 'main'
 as in 'probe_guest_base' so that we can find a reserved VA region that also
 passes validation.  If a region isn't found that can be validated, then QEMU
 gives up.  Does this approach seem reasonable?
 
 I guess so, depending on how you adjust the hint each time.

What I am currently experimenting with is essentially the same as what is in
'probe_guest_base'.  So something like (not an actually patch submission, just
listing this here for discussion):

Index: linux-user/main.c
===
--- linux-user/main.c   (revision 376549)
+++ linux-user/main.c   (working copy)
@@ -3486,35 +3486,53 @@ int main(int argc, char **argv, char **e
 guest_base = HOST_PAGE_ALIGN(guest_base);

 if (reserved_va) {
-void *p;
+unsigned long host_start, real_start, first_start, host_size;
 int flags;

 flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
 if (have_guest_base) {
 flags |= MAP_FIXED;
 }
-p = mmap((void *)guest_base, reserved_va, PROT_NONE, flags, -1, 0);
-if (p == MAP_FAILED) {
-fprintf(stderr, Unable to reserve guest address space\n);
-exit(1);
-}
-guest_base = (unsigned long)p;
-/* Make sure the address is properly aligned.  */
-if (guest_base  ~qemu_host_page_mask) {
-munmap(p, reserved_va);
-p = mmap((void *)guest_base, reserved_va + qemu_host_page_size,
- PROT_NONE, flags, -1, 0);
-if (p == MAP_FAILED) {
+
+   first_start = host_start = HOST_PAGE_ALIGN(guest_base);
+   while (1) {
+host_size = reserved_va;
+real_start = (unsigned long) mmap((void *)host_start, host_size,
+  PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+fprintf(stderr, Unable to reserve guest address space\n);
+exit(1);
+}
+guest_base = host_start;
+/* Make sure the address is properly aligned.  */
+if (guest_base  ~qemu_host_page_mask) {
+munmap((void*)real_start, host_size);
+host_size += qemu_host_page_size;
+real_start = (unsigned long) mmap((void *)guest_base,
+  host_size,
+  PROT_NONE, flags, -1, 0);
+if (real_start == (unsigned long)-1) {
+fprintf(stderr, Unable to reserve guest address space\n);
+exit(1);
+}
+guest_base = HOST_PAGE_ALIGN(real_start);
+}
+
+if (guest_validate_base(guest_base))
+break;
+
+munmap((void *)real_start, host_size);
+host_start += qemu_host_page_size;
+if (host_start == first_start) {
 fprintf(stderr, Unable to reserve guest address space\n);
 exit(1);
 }
-guest_base = HOST_PAGE_ALIGN((unsigned long)p);
 }
 qemu_log(Reserved 0x%lx bytes of guest address space\n, reserved_va);
 mmap_next_start = reserved_va;
 }

-if (reserved_va || have_guest_base) {
+if (have_guest_base) {
 if (!guest_validate_base(guest_base)) {
 fprintf(stderr, Guest base/Reserved VA rejected by guest code\n);
 exit(1);

 I do wonder if it wouldn't be better to rearrange things such that
 for 64-bit hosts and 32-bit guests we *always* reserve 4G so that
 there's zero possibility of the guest stomping on host memory.  That
 would also solve your problem.

I am seeing problems with 32-on-32 where the ARM commpage check wraps around
(incidentally I also ran into problems with -B because for some values of
guest_base it is easy for guest_base = min_mmap_addr and guest_base +
kernel_helper_addr  min_mmap_addr to hold).

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [RFC PATCH 1/1] linux-user: Probe the guest base for shared objects when needed

2012-06-27 Thread Meador Inge
On 06/27/2012 07:47 PM, Paul Brook wrote:

 On 28.06.2012, at 02:06, Paul Brook wrote:
 openSUSE uses a version patched so that IIUC 3G are reserved.
 Just today this failed on a system where swap got disabled and the
 mmap() thus failed.

 Err... why?  We map with MAP_NORESERVE, so swap shouldn't matter...

 I can't say if it's the same cause, but we fail with ulimit -v 4046848.

 Incidentally, it seems a strange that we only reserve 0xf700 bytes,
 not the full 4G.

 Uh, I think that was because of the vdso shared page that is allocated on
 top of -R.
 
 That can't be right.  The whole point of -R is that it defines all the guest 
 accessible virtual address space.  The surrounding space is liable to be used 
 by something else, and we must not make any assumptions about it.
 
 Further inspection shows that guest_validate_base contains some extremely 
 bogus code.
 
 If the guest needs something at the top of its address space then we need to 
 offset address zero within the block, and ensure accesses wrap appropriately.

'guest_validate_base' is currently called for three reasons: (1) in main.c
when using -B, (2) in main.c when using -R after mapping the reserved va
region, and (3) and when probing for a guest base in probe_guest_base.

For case (1) I suppose things are pretty much the same -- we just need to map
the extra region when needed (e.g. for the ARM kernel helpers).

For case (2) maybe we can do a probing similar to what I mentioned here [1],
but taking into account what you stated above and ensuring that the probing
finds a single region for the request va region size and any needed extra stuff.

Case (3) is mostly the same as (2) but we are probing for a guest base with a
region size deduced from looking at the image we are loading.  I suppose it is
still OK to map two regions here.  The single region only applies to -R?

Thoughts?

[1] http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg04589.html

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [RFC PATCH 1/1] linux-user: Probe the guest base for shared objects when needed

2012-06-12 Thread Meador Inge
On 06/12/2012 09:08 AM, Richard Henderson wrote:

 On 2012-06-07 13:59, Meador Inge wrote:
  load_addr = loaddr;
  if (ehdr-e_type == ET_DYN) {
 +if (loaddr  mmap_min_addr)
 +probe_guest_base(image_name, loaddr, hiaddr);
 
 This doesn't make any sense.  loaddr is almost certainly 0, unless
 you've pre-linked the ld.so image.  But the next statement is letting
 the system pick the address at which the image will be loaded.

It usually is.  I just want guest_base to be computed to something that
will work for cases where a fixed address image is later loaded (at which
point it is too late to compute the guest_base).  Always probing is one way I
found to do that, but as I originally said I don't know this code very well so
maybe that is not a good method.

 I think this is one of those cases where the -B or -R options
 (or QEMU_GUEST_BASE and QEMU_RESERVED_VA env variables) are the best
 way forward for whatever cpu you're emulating.  That or a change to
 the target's default ld script, not to link real executables quite so 
 low in the address space.

Hmmm, OK.  I was really hoping to have something more automatic.  Perhaps
I will have to use the options.

Thanks for the review.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH] MIPS/user: Fix reset CPU state initialization

2012-06-08 Thread Meador Inge
;
 -}
 -} else if (env-insn_flags  ISA_MIPS32) {
 -if (env-hflags  MIPS_HFLAG_64) {
 -env-hflags |= MIPS_HFLAG_COP1X;
 -}
 -} else if (env-insn_flags  ISA_MIPS4) {
 -/* All supported MIPS IV CPUs use the XX (CU3) to enable
 -   and disable the MIPS IV extensions to the MIPS III ISA.
 -   Some other MIPS IV CPUs ignore the bit, so the check here
 -   would be too restrictive for them.  */
 -if (env-CP0_Status  (1  CP0St_CU3)) {
 -env-hflags |= MIPS_HFLAG_COP1X;
 -}
 -}
 -}
 -
  
 /*/
  /* Exceptions processing helpers */
  
 Index: qemu-git-trunk/target-mips/translate.c
 ===
 --- qemu-git-trunk.orig/target-mips/translate.c   2012-06-07 
 03:18:46.275645763 +0100
 +++ qemu-git-trunk/target-mips/translate.c2012-06-07 03:18:48.345427587 
 +0100
 @@ -12780,17 +12780,12 @@ void cpu_state_reset(CPUMIPSState *env)
  env-insn_flags = env-cpu_model-insn_flags;
  
  #if defined(CONFIG_USER_ONLY)
 -env-hflags = MIPS_HFLAG_UM;
 +env-CP0_Status = (MIPS_HFLAG_UM  CP0St_KSU);
  /* Enable access to the SYNCI_Step register.  */
  env-CP0_HWREna |= (1  1);
  if (env-CP0_Config1  (1  CP0C1_FP)) {
 -env-hflags |= MIPS_HFLAG_FPU;
 -}
 -#ifdef TARGET_MIPS64
 -if (env-active_fpu.fcr0  (1  FCR0_F64)) {
 -env-hflags |= MIPS_HFLAG_F64;
 +env-CP0_Status |= (1  CP0St_CU1);
  }
 -#endif
  #else
  if (env-hflags  MIPS_HFLAG_BMASK) {
  /* If the exception was raised from a delay slot,
 @@ -12820,7 +12815,6 @@ void cpu_state_reset(CPUMIPSState *env)
  }
  /* Count register increments in debug mode, EJTAG version 1 */
  env-CP0_Debug = (1  CP0DB_CNT) | (0x1  CP0DB_VER);
 -env-hflags = MIPS_HFLAG_CP0;
  
  if (env-CP0_Config3  (1  CP0C3_MT)) {
  int i;
 @@ -12848,11 +12842,7 @@ void cpu_state_reset(CPUMIPSState *env)
  }
  }
  #endif
 -#if defined(TARGET_MIPS64)
 -if (env-cpu_model-insn_flags  ISA_MIPS3) {
 -env-hflags |= MIPS_HFLAG_64;
 -}
 -#endif
 +compute_hflags(env);
  env-exception_index = EXCP_NONE;
  }
  
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup

2012-06-08 Thread Meador Inge
Ping ^ 3.

On 05/07/2012 09:44 AM, Meador Inge wrote:
 Ping ^ 2.
 
 On 04/04/2012 09:30 PM, Meador Inge wrote:
 Ping.  Any comments on this series?

 On 03/27/2012 05:44 PM, Meador Inge wrote:
 This series is focused at cleaning up a few issues in the
 GNU/Linux usermode driver's option parsing.  -h has been
 fixed to exit with 0, a -help option has been added, proper
 error messages have been added for unknown options and bad
 arguments, and --foo is now excepted in addition to -foo.

 Meador Inge (4):
   linux-user: Exit 0 when -h is used
   linux-user: Add -help
   linux-user: Add proper error messages for bad options
   linux-user: Treat --foo options the same as -foo

  linux-user/main.c |   30 --
  1 files changed, 20 insertions(+), 10 deletions(-)



 
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [RFC PATCH 1/1] linux-user: Probe the guest base for shared objects when needed

2012-06-07 Thread Meador Inge
In some cases when running a shared library directly from QEMU
(e.g. ld.so) the guest base should still be probed so that
any images loaded later at fixed addresses by the target code
can still be mapped.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/elfload.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f3b1552..c71c287 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1443,6 +1443,7 @@ static void probe_guest_base(const char *image_name,
 goto exit_errmsg;
 }
 }
+have_guest_base = 1;
 qemu_log(Relocating guest address space from 0x
  TARGET_ABI_FMT_lx  to 0x%lx\n,
  loaddr, real_start);
@@ -1528,6 +1529,8 @@ static void load_elf_image(const char *image_name, int 
image_fd,
 
 load_addr = loaddr;
 if (ehdr-e_type == ET_DYN) {
+if (loaddr  mmap_min_addr)
+probe_guest_base(image_name, loaddr, hiaddr);
 /* The image indicates that it can be loaded anywhere.  Find a
location that can hold the memory space required.  If the
image is pre-linked, LOADDR will be non-zero.  Since we do
-- 
1.7.7.6




[Qemu-devel] [RFC PATCH 0/1] linux-user: Issue running applications through ld.so

2012-06-07 Thread Meador Inge
Hi All,

I am running into an issue where QEMU fails to map a target executable
due to hitting the lower limit on /proc/sys/vm/mmap_min_addr.  This normally
just works because of all the nice guest base probing we have in place:

$ cat /proc/sys/vm/mmap_min_addr 
4096
$ qemu-arm ./hello.out
Hello, World!

In cases where the executable is run through the glibc loader we are not so
lucky:

$ qemu-arm /path/to/lib/ld-2.15.so --library-path /path/to/lib/ ./hello.out 
./hello.out: error while loading shared libraries: ./hello.out: failed to map
segment from shared object: Permission denied

The reason is that we successfully load the loader (since it can be put
anywhere), but later ld.so goes to map in hello.out at a fixed address
and fails because that fixed address is bellow mmap_min_addr and it is
too late to fixup the guest base.

I am able to fix the issue by probing for the guest base when needed for
shared objects.  This worked for all the test cases I threw at it
(including running the gcc and glibc test suites through QEMU).  However,
I am not all that familiar with the Linux usermode pieces and would like
some feedback.

Thoughts?
 
Meador Inge (1):
  linux-user: Probe the guest base for shared objects when needed

 linux-user/elfload.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

-- 
1.7.7.6




Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup

2012-05-07 Thread Meador Inge
Ping ^ 2.

On 04/04/2012 09:30 PM, Meador Inge wrote:
 Ping.  Any comments on this series?
 
 On 03/27/2012 05:44 PM, Meador Inge wrote:
 This series is focused at cleaning up a few issues in the
 GNU/Linux usermode driver's option parsing.  -h has been
 fixed to exit with 0, a -help option has been added, proper
 error messages have been added for unknown options and bad
 arguments, and --foo is now excepted in addition to -foo.

 Meador Inge (4):
   linux-user: Exit 0 when -h is used
   linux-user: Add -help
   linux-user: Add proper error messages for bad options
   linux-user: Treat --foo options the same as -foo

  linux-user/main.c |   30 --
  1 files changed, 20 insertions(+), 10 deletions(-)

 
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [Bug 916720] Re: select fails on windows because a non-socket fd is in the rfds set

2012-04-19 Thread Meador Inge
I am still seeing the symptoms that Arie pointed out:

Remote debugging using :1234
Ignoring packet error, continuing...
warning: unrecognized item timeout in qSupported response
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Ignoring packet error, continuing...
Malformed response to offset query, timeout

I started QEMU like:

arm-none-eabi-qemu-system.exe -gdb
tcp:127.0.0.1:1234,nowait,nodelay,server,ipv4 -S -semihosting -kernel
hello.out

This was with an ARM EABI system emulator that I built from today's
mainline.  From a brief look it seems like QEMU is going into 'g_poll'
and never coming out.

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

Title:
  select fails on windows because a non-socket fd is in the rfds set

Status in QEMU:
  Fix Committed

Bug description:
  The select call in file main_loop.c at line 460 fails on windows
  because a non-socket fd is in the rfds set. As a result, gdb remote
  connections will never be accepted by qemu. The select function
  returns with -1. WSAGetLastError returns code 10038 (WSAENOTSOCK).

  I start qemu as follows:
  qemu-system-arm -cpu cortex-m3 -M lm3s6965evb -nographic -monitor null 
-serial null -semihosting -kernel test1.elf -S -gdb tcp:127.0.0.1:2200

  qemu is configure with:
  CFLAGS=-O4 -march=i686
  configure --target-list=i386-softmmu arm-softmmu sparc-softmmu ppc-softmmu 
--prefix=/home/qemu/install --cc=mingw32-gcc --host-cc=mingw32-gcc 
--audio-drv-list=dsound sdl --audio-card-list=ac97 es1370 sb16 cs4231a adlib 
gus

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/916720/+subscriptions



Re: [Qemu-devel] [Qemu-ppc] [PATCH] target-ppc: Init dcache and icache size for e500 user mode

2012-04-13 Thread Meador Inge
On 04/13/2012 06:40 AM, Andreas Färber wrote:

 Am 12.04.2012 19:24, schrieb Scott Wood:
 On 04/12/2012 11:59 AM, Andreas Färber wrote:
 Am 10.04.2012 22:04, schrieb Meador Inge:
 commit f7aa558396dd0f6b7a2b22c05cb503c655854102 pulled the dcache and 
 icache
 line size initialization inside of a '#if !defined(CONFIG_USER_ONLY)' 
 block.
 This is not correct because instructions like 'dcbz' need the dcache size
 initialized even for user mode.

 Signed-off-by: Meador Inge mead...@codesourcery.com

 Looks okay and compiles,

 Reviewed-by: Andreas Färber afaer...@suse.de

 Scott, are you planning to review this e500 patch? Or should I go ahead
 and apply?

 I'm OK with it, though it may make more sense for USER_ONLY to just pick
 an arbitrary cache line size (probably 32) than to try to imitate a
 specific core.
 
 Meador, what was your specific problem: The value being zero or not
 matching real hardware?

My specific problem was the value being zero.  Therefore nothing actually got
cleared because the 'dcbz' implementation uses 'dcache_line_size' as an upper
bound on a loop.

On a side note, the way I actually ran into this was by running a application
linked against an optimized version of glibc for e500 that uses 'dcbz' in
'memset'.  ld.so wasn't correctly clearing .bss as a result.  That was fun to
debug :-)

 Scott's suggestion would avoid some #ifdef'ery so I'd prefer that if
 possible. I'm planning for a PULL later today, so let me know.

Sounds good to me.  I think the #ifdef stuff is gross, but I wasn't sure of way
around it.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH] target-ppc: Init dcache and icache size for e500 user mode

2012-04-10 Thread Meador Inge
commit f7aa558396dd0f6b7a2b22c05cb503c655854102 pulled the dcache and icache
line size initialization inside of a '#if !defined(CONFIG_USER_ONLY)' block.
This is not correct because instructions like 'dcbz' need the dcache size
initialized even for user mode.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-ppc/translate_init.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index b1f8785..ef8735a 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -4466,25 +4466,32 @@ static void init_proc_e500 (CPUPPCState *env, int 
version)
 env-nb_pids = 3;
 env-nb_ways = 2;
 env-id_tlbs = 0;
+#endif
 switch (version) {
 case fsl_e500v1:
 /* e500v1 */
+#if !defined(CONFIG_USER_ONLY)
 tlbncfg[0] = gen_tlbncfg(2, 1, 1, 0, 256);
 tlbncfg[1] = gen_tlbncfg(16, 1, 9, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16);
+#endif
 env-dcache_line_size = 32;
 env-icache_line_size = 32;
 break;
 case fsl_e500v2:
 /* e500v2 */
+#if !defined(CONFIG_USER_ONLY)
 tlbncfg[0] = gen_tlbncfg(4, 1, 1, 0, 512);
 tlbncfg[1] = gen_tlbncfg(16, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16);
+#endif
 env-dcache_line_size = 32;
 env-icache_line_size = 32;
 break;
 case fsl_e500mc:
 /* e500mc */
+#if !defined(CONFIG_USER_ONLY)
 tlbncfg[0] = gen_tlbncfg(4, 1, 1, 0, 512);
 tlbncfg[1] = gen_tlbncfg(64, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 64);
+#endif
 env-dcache_line_size = 64;
 env-icache_line_size = 64;
 l1cfg0 |= 0x100; /* 64 byte cache block size */
@@ -4492,7 +4499,6 @@ static void init_proc_e500 (CPUPPCState *env, int version)
 default:
 cpu_abort(env, Unknown CPU:  TARGET_FMT_lx \n, env-spr[SPR_PVR]);
 }
-#endif
 gen_spr_BookE206(env, 0x00DF, tlbncfg);
 /* XXX : not implemented */
 spr_register(env, SPR_HID0, HID0,
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup

2012-04-04 Thread Meador Inge
Ping.  Any comments on this series?

On 03/27/2012 05:44 PM, Meador Inge wrote:
 This series is focused at cleaning up a few issues in the
 GNU/Linux usermode driver's option parsing.  -h has been
 fixed to exit with 0, a -help option has been added, proper
 error messages have been added for unknown options and bad
 arguments, and --foo is now excepted in addition to -foo.
 
 Meador Inge (4):
   linux-user: Exit 0 when -h is used
   linux-user: Add -help
   linux-user: Add proper error messages for bad options
   linux-user: Treat --foo options the same as -foo
 
  linux-user/main.c |   30 --
  1 files changed, 20 insertions(+), 10 deletions(-)
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] m68k: Return semihosting errno values correctly

2012-03-27 Thread Meador Inge
Ping.

On 02/24/2012 04:53 PM, Andreas Färber wrote:
 Am 24.02.2012 23:18, schrieb Meador Inge:
 Fixing a simple typo, s/errno/err/, that caused
 the error status from GDB semihosted system calls
 to be returned incorrectly.

 Signed-off-by: Meador Inge mead...@codesourcery.com
 
 Nice catch!
 
 Reviewed-by: Andreas Färber afaer...@suse.de
 
 Andreas
 
 ---
  m68k-semi.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/m68k-semi.c b/m68k-semi.c
 index bab01ee..6d60ced 100644
 --- a/m68k-semi.c
 +++ b/m68k-semi.c
 @@ -150,7 +150,7 @@ static void m68k_semi_cb(CPUState *env, target_ulong 
 ret, target_ulong err)
  }
  /* FIXME - handle put_user() failure */
  put_user_u32(ret, args);
 -put_user_u32(errno, args + 4);
 +put_user_u32(err, args + 4);
  }
  
  #define ARG(n)  \
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] syscall: #ifdef newer RLIMIT_* codes

2012-03-27 Thread Meador Inge
Ping.

On 02/20/2012 01:38 PM, Andreas Färber wrote:
 Am 20.02.2012 19:26, schrieb Meador Inge:
 Commit e22b7015353be824620b1f0f5e32a8575b898a8c added the translation
 from target to host RLIMIT_* codes, but some of the added codes are
 only available on newer version of Linux (as documented in 'getrlimit(2)').

 Signed-off-by: Meador Inge mead...@codesourcery.com
 
 Reviewed-by: Andreas Färber afaer...@suse.de
 
 CC'ing the linux-user maintainer.
 
 Andreas
 
 ---
  linux-user/syscall.c |   12 
  1 files changed, 12 insertions(+), 0 deletions(-)

 diff --git a/linux-user/syscall.c b/linux-user/syscall.c
 index 8a11213..1986238 100644
 --- a/linux-user/syscall.c
 +++ b/linux-user/syscall.c
 @@ -996,20 +996,32 @@ static inline int target_to_host_resource(int code)
  return RLIMIT_LOCKS;
  case TARGET_RLIMIT_MEMLOCK:
  return RLIMIT_MEMLOCK;
 +/* = Linux 2.6.8 */
 +#ifdef RLIMIT_MSGQUEUE
  case TARGET_RLIMIT_MSGQUEUE:
  return RLIMIT_MSGQUEUE;
 +#endif
 +/* = Linux 2.6.12 */
 +#ifdef RLIMIT_NICE
  case TARGET_RLIMIT_NICE:
  return RLIMIT_NICE;
 +#endif
  case TARGET_RLIMIT_NOFILE:
  return RLIMIT_NOFILE;
  case TARGET_RLIMIT_NPROC:
  return RLIMIT_NPROC;
  case TARGET_RLIMIT_RSS:
  return RLIMIT_RSS;
 +/* = Linux 2.6.12 */
 +#ifdef RLIMIT_RTPRIO
  case TARGET_RLIMIT_RTPRIO:
  return RLIMIT_RTPRIO;
 +#endif
 +/* = Linux 2.6.8 */
 +#ifdef RLIMIT_SIGPENDING
  case TARGET_RLIMIT_SIGPENDING:
  return RLIMIT_SIGPENDING;
 +#endif
  case TARGET_RLIMIT_STACK:
  return RLIMIT_STACK;
  default:
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] syscall: #ifdef newer RLIMIT_* codes

2012-03-27 Thread Meador Inge
On 03/27/2012 12:15 PM, Riku Voipio wrote:

 Hi,
 
 Do we really need this? 2.6.12 came out in 2005, even oldest supported
 RHEL (5) is minimum 2.6.18 these days.

The development environment I am working with uses a RHEL 3 compatible sysroot
(RHEL 3 is currently marked with extended life cycle support).  So, I
definitely need it :-) (and yes I know that this sysroot is ancient).  I don't
know if others are using such old development sysroots.  The changes are
minimal and while it would be great to have this applied upstream I do
understand if you want to NACK.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup

2012-03-27 Thread Meador Inge
This series is focused at cleaning up a few issues in the
GNU/Linux usermode driver's option parsing.  -h has been
fixed to exit with 0, a -help option has been added, proper
error messages have been added for unknown options and bad
arguments, and --foo is now excepted in addition to -foo.

Meador Inge (4):
  linux-user: Exit 0 when -h is used
  linux-user: Add -help
  linux-user: Add proper error messages for bad options
  linux-user: Treat --foo options the same as -foo

 linux-user/main.c |   30 --
 1 files changed, 20 insertions(+), 10 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH 2/4] linux-user: Add -help

2012-03-27 Thread Meador Inge
This option is already available on the system mode
binaries.  It would be better if long options were
supported (i.e. --help), but this is okay for now.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/main.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index aabce83..570178a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3104,6 +3104,8 @@ struct qemu_argument {
 };
 
 struct qemu_argument arg_table[] = {
+{help,   , false, handle_arg_help,
+ ,   },
 {h,  , false, handle_arg_help,
  ,   print this help},
 {g,  QEMU_GDB, true,  handle_arg_gdb,
-- 
1.7.7.6




[Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo

2012-03-27 Thread Meador Inge
The system mode binaries provide a similiar alias
and it makes common options like --version and --help
work as expected.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/main.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9616d8e..8f6ca0d 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3240,6 +3240,10 @@ static int parse_args(int argc, char **argv)
 if (!strcmp(r, -)) {
 break;
 }
+/* Treat --foo the same as -foo.  */
+if (r[0] == '-') {
+r++;
+}
 
 for (arginfo = arg_table; arginfo-handle_opt != NULL; arginfo++) {
 if (!strcmp(r, arginfo-argv)) {
-- 
1.7.7.6




[Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used

2012-03-27 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/main.c |   20 ++--
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 962677e..aabce83 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -51,7 +51,7 @@ int have_guest_base;
 unsigned long reserved_va;
 #endif
 
-static void usage(void);
+static void usage(int exitcode);
 
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
 const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
@@ -2926,7 +2926,7 @@ void init_task_state(TaskState *ts)
 
 static void handle_arg_help(const char *arg)
 {
-usage();
+usage(0);
 }
 
 static void handle_arg_log(const char *arg)
@@ -2956,7 +2956,7 @@ static void handle_arg_set_env(const char *arg)
 r = p = strdup(arg);
 while ((token = strsep(p, ,)) != NULL) {
 if (envlist_setenv(envlist, token) != 0) {
-usage();
+usage(1);
 }
 }
 free(r);
@@ -2968,7 +2968,7 @@ static void handle_arg_unset_env(const char *arg)
 r = p = strdup(arg);
 while ((token = strsep(p, ,)) != NULL) {
 if (envlist_unsetenv(envlist, token) != 0) {
-usage();
+usage(1);
 }
 }
 free(r);
@@ -2984,7 +2984,7 @@ static void handle_arg_stack_size(const char *arg)
 char *p;
 guest_stack_size = strtoul(arg, p, 0);
 if (guest_stack_size == 0) {
-usage();
+usage(1);
 }
 
 if (*p == 'M') {
@@ -3143,7 +3143,7 @@ struct qemu_argument arg_table[] = {
 {NULL, NULL, false, NULL, NULL, NULL}
 };
 
-static void usage(void)
+static void usage(int exitcode)
 {
 struct qemu_argument *arginfo;
 int maxarglen;
@@ -3204,7 +3204,7 @@ static void usage(void)
Note that if you provide several changes to a single variable\n
the last change will stay in effect.\n);
 
-exit(1);
+exit(exitcode);
 }
 
 static int parse_args(int argc, char **argv)
@@ -3243,7 +3243,7 @@ static int parse_args(int argc, char **argv)
 if (!strcmp(r, arginfo-argv)) {
 if (arginfo-has_arg) {
 if (optind = argc) {
-usage();
+usage(1);
 }
 arginfo-handle_opt(argv[optind]);
 optind++;
@@ -3256,12 +3256,12 @@ static int parse_args(int argc, char **argv)
 
 /* no option matched the current argv */
 if (arginfo-handle_opt == NULL) {
-usage();
+usage(1);
 }
 }
 
 if (optind = argc) {
-usage();
+usage(1);
 }
 
 filename = argv[optind];
-- 
1.7.7.6




[Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options

2012-03-27 Thread Meador Inge
This patch adds better support for diagnosing option
parser errors.  The previous implementation just printed
the usage text and exited when a bad option or argument
was found.  This made it very difficult to determine why
the usage was being displayed and it was doubly confusing
for cases like '--help' (it wasn't clear that --help was
actually an error).

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/main.c |   10 +++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 570178a..9616d8e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3245,7 +3245,9 @@ static int parse_args(int argc, char **argv)
 if (!strcmp(r, arginfo-argv)) {
 if (arginfo-has_arg) {
 if (optind = argc) {
-usage(1);
+(void) fprintf(stderr,
+qemu: missing argument for option '%s'\n, r);
+exit(1);
 }
 arginfo-handle_opt(argv[optind]);
 optind++;
@@ -3258,12 +3260,14 @@ static int parse_args(int argc, char **argv)
 
 /* no option matched the current argv */
 if (arginfo-handle_opt == NULL) {
-usage(1);
+(void) fprintf(stderr, qemu: unknown option '%s'\n, r);
+exit(1);
 }
 }
 
 if (optind = argc) {
-usage(1);
+(void) fprintf(stderr, qemu: invalid option '%s'\n, r);
+exit(1);
 }
 
 filename = argv[optind];
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v1 1/1] ppc: Correctly define POWERPC_INSNS2_DEFAULT

2012-03-05 Thread Meador Inge
On 02/23/2012 07:44 AM, Meador Inge wrote:

 'POWERPC_INSNS2_DEFAULT' was defined incorrectly which was causing the
 opcode table creation code to erroneously register 'eieio' and 'mbar'
 for the default processor:
 
** ERROR: opcode 1a already assigned in opcode table 16
*** ERROR: unable to insert opcode [1f-16-1a]
*** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a
 
 Signed-off-by: Meador Inge mead...@codesourcery.com

Ping.

 ---
  target-ppc/translate_init.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
 index 6253076..6cb5fad 100644
 --- a/target-ppc/translate_init.c
 +++ b/target-ppc/translate_init.c
 @@ -6713,7 +6713,7 @@ static void init_proc_620 (CPUPPCState *env)
  #if defined (TARGET_PPC64)  0 // XXX: TODO
  #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC64
  #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC64
 -#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC64
 +#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC64
  #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC64
  #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC64
  #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC64
 @@ -6725,7 +6725,7 @@ static void init_proc_620 (CPUPPCState *env)
  #else
  #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC32
  #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC32
 -#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC32
 +#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC32
  #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC32
  #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC32
  #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC32


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] ppc: Correctly define POWERPC_INSNS2_DEFAULT

2012-03-05 Thread Meador Inge
On 03/05/2012 01:53 PM, Andreas Färber wrote:

 Am 05.03.2012 18:06, schrieb Meador Inge:
 On 02/23/2012 07:44 AM, Meador Inge wrote:

 'POWERPC_INSNS2_DEFAULT' was defined incorrectly which was causing the
 opcode table creation code to erroneously register 'eieio' and 'mbar'
 for the default processor:

** ERROR: opcode 1a already assigned in opcode table 16
*** ERROR: unable to insert opcode [1f-16-1a]
*** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a

 Signed-off-by: Meador Inge mead...@codesourcery.com

 Ping.
 
 Cc'ing qemu-ppc.
 
 What's the test case (command line) that breaks? Don't all machines use
 different default CPUs? I would rather drop these ..._DEFAULT defines in
 favor of using a real CPU model - but maybe I'm misunderstanding something?

I meant quite literally the default CPU:

$ ./install/bin/qemu-system-ppc -cpu default
*** ERROR: opcode 1a already assigned in opcode table 16
*** ERROR: unable to insert opcode [1f-16-1a]
*** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a
Segmentation fault (core dumped)

 

 ---
  target-ppc/translate_init.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

 diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
 index 6253076..6cb5fad 100644
 --- a/target-ppc/translate_init.c
 +++ b/target-ppc/translate_init.c
 @@ -6713,7 +6713,7 @@ static void init_proc_620 (CPUPPCState *env)
  #if defined (TARGET_PPC64)  0 // XXX: TODO
  #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC64
  #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC64
 -#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC64
 +#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC64
  #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC64
  #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC64
  #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC64
 @@ -6725,7 +6725,7 @@ static void init_proc_620 (CPUPPCState *env)
  #else
  #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC32
  #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC32
 -#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC32
 +#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC32
  #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC32
  #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC32
  #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC32
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] mips: properly compute hflags and fcr0 on cpu reset

2012-03-03 Thread Meador Inge
On 03/03/2012 10:45 AM, Andreas Färber wrote:

 Am 02.03.2012 22:03, schrieb Meador Inge:
 Currently 'cpu_reset' doesn't fully compute all of the needed
 HFLAGs and fails to setup fcr0 after clearing the CPU state.
 This can cause instruction exceptions.  For example, using
 'madd.d' on machines that should support it is kindly greeted
 with:

 qemu: uncaught target signal 4 (Illegal instruction) - core dumped
 Illegal instruction (core dumped)

 because fcr0 is bogus and MIPS_HFLAG_COP1X is not correcly set in hflags.

 This is fixed by modifying 'cpu_reset' to use 'compute_hflags' and
 initializing 'fcr0' from the current CPU model.
 
 fcr0 issue has also been
 
 Reported-by: Khansa Butt kha...@kics.edu.pk
 
 e.g., http://patchwork.ozlabs.org/patch/133974/

Ah, thanks.  The fcr0 fix had been sitting in our local tree for a while and I
just forgot to check upstream patch submissions.  I need to get in the habit of
looking at patchwork first.

 Your use of compute_hflags() looks more future-proof.
 

 Signed-off-by: Maciej W. Rozycki ma...@codesourcery.com
 Signed-off-by: Nathan Froyd froy...@codesourcery.com
 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  target-mips/cpu.h   |   49 
 +++
  target-mips/op_helper.c |   49 
 ---
  target-mips/translate.c |   17 +++
  3 files changed, 53 insertions(+), 62 deletions(-)

 diff --git a/target-mips/cpu.h b/target-mips/cpu.h
 index 71cb4e8..fc65348 100644
 --- a/target-mips/cpu.h
 +++ b/target-mips/cpu.h
 @@ -737,4 +737,53 @@ static inline void cpu_pc_from_tb(CPUState *env, 
 TranslationBlock *tb)
  env-hflags |= tb-flags  MIPS_HFLAG_BMASK;
  }
  
 +static inline void compute_hflags(CPUState *env)
 +{
 
 Moving helper functions like these to cpu.h has proven troublesome for
 QOM'ification (when they need access to MIPSCPU[Class] in addition to
 CPUMIPSState) but it'll do for now.

Okay, I will keep that in mind for the future.  Thanks for the review.

 Reviewed-by: Andreas Färber afaer...@suse.de
 
 Andreas
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v1 1/1] mips: properly compute hflags and fcr0 on cpu reset

2012-03-02 Thread Meador Inge
Currently 'cpu_reset' doesn't fully compute all of the needed
HFLAGs and fails to setup fcr0 after clearing the CPU state.
This can cause instruction exceptions.  For example, using
'madd.d' on machines that should support it is kindly greeted
with:

qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction (core dumped)

because fcr0 is bogus and MIPS_HFLAG_COP1X is not correcly set in hflags.

This is fixed by modifying 'cpu_reset' to use 'compute_hflags' and
initializing 'fcr0' from the current CPU model.

Signed-off-by: Maciej W. Rozycki ma...@codesourcery.com
Signed-off-by: Nathan Froyd froy...@codesourcery.com
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-mips/cpu.h   |   49 +++
 target-mips/op_helper.c |   49 ---
 target-mips/translate.c |   17 +++
 3 files changed, 53 insertions(+), 62 deletions(-)

diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 71cb4e8..fc65348 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -737,4 +737,53 @@ static inline void cpu_pc_from_tb(CPUState *env, 
TranslationBlock *tb)
 env-hflags |= tb-flags  MIPS_HFLAG_BMASK;
 }
 
+static inline void compute_hflags(CPUState *env)
+{
+env-hflags = ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
+ MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
+ MIPS_HFLAG_UX);
+if (!(env-CP0_Status  (1  CP0St_EXL)) 
+!(env-CP0_Status  (1  CP0St_ERL)) 
+!(env-hflags  MIPS_HFLAG_DM)) {
+env-hflags |= (env-CP0_Status  CP0St_KSU)  MIPS_HFLAG_KSU;
+}
+#if defined(TARGET_MIPS64)
+if (((env-hflags  MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) ||
+(env-CP0_Status  (1  CP0St_PX)) ||
+(env-CP0_Status  (1  CP0St_UX))) {
+env-hflags |= MIPS_HFLAG_64;
+}
+if (env-CP0_Status  (1  CP0St_UX)) {
+env-hflags |= MIPS_HFLAG_UX;
+}
+#endif
+if ((env-CP0_Status  (1  CP0St_CU0)) ||
+!(env-hflags  MIPS_HFLAG_KSU)) {
+env-hflags |= MIPS_HFLAG_CP0;
+}
+if (env-CP0_Status  (1  CP0St_CU1)) {
+env-hflags |= MIPS_HFLAG_FPU;
+}
+if (env-CP0_Status  (1  CP0St_FR)) {
+env-hflags |= MIPS_HFLAG_F64;
+}
+if (env-insn_flags  ISA_MIPS32R2) {
+if (env-active_fpu.fcr0  (1  FCR0_F64)) {
+env-hflags |= MIPS_HFLAG_COP1X;
+}
+} else if (env-insn_flags  ISA_MIPS32) {
+if (env-hflags  MIPS_HFLAG_64) {
+env-hflags |= MIPS_HFLAG_COP1X;
+}
+} else if (env-insn_flags  ISA_MIPS4) {
+/* All supported MIPS IV CPUs use the XX (CU3) to enable
+   and disable the MIPS IV extensions to the MIPS III ISA.
+   Some other MIPS IV CPUs ignore the bit, so the check here
+   would be too restrictive for them.  */
+if (env-CP0_Status  (1  CP0St_CU3)) {
+env-hflags |= MIPS_HFLAG_COP1X;
+}
+}
+}
+
 #endif /* !defined (__MIPS_CPU_H__) */
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index c51b9cb..1f1c736 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -32,55 +32,6 @@
 static inline void cpu_mips_tlb_flush (CPUState *env, int flush_global);
 #endif
 
-static inline void compute_hflags(CPUState *env)
-{
-env-hflags = ~(MIPS_HFLAG_COP1X | MIPS_HFLAG_64 | MIPS_HFLAG_CP0 |
- MIPS_HFLAG_F64 | MIPS_HFLAG_FPU | MIPS_HFLAG_KSU |
- MIPS_HFLAG_UX);
-if (!(env-CP0_Status  (1  CP0St_EXL)) 
-!(env-CP0_Status  (1  CP0St_ERL)) 
-!(env-hflags  MIPS_HFLAG_DM)) {
-env-hflags |= (env-CP0_Status  CP0St_KSU)  MIPS_HFLAG_KSU;
-}
-#if defined(TARGET_MIPS64)
-if (((env-hflags  MIPS_HFLAG_KSU) != MIPS_HFLAG_UM) ||
-(env-CP0_Status  (1  CP0St_PX)) ||
-(env-CP0_Status  (1  CP0St_UX))) {
-env-hflags |= MIPS_HFLAG_64;
-}
-if (env-CP0_Status  (1  CP0St_UX)) {
-env-hflags |= MIPS_HFLAG_UX;
-}
-#endif
-if ((env-CP0_Status  (1  CP0St_CU0)) ||
-!(env-hflags  MIPS_HFLAG_KSU)) {
-env-hflags |= MIPS_HFLAG_CP0;
-}
-if (env-CP0_Status  (1  CP0St_CU1)) {
-env-hflags |= MIPS_HFLAG_FPU;
-}
-if (env-CP0_Status  (1  CP0St_FR)) {
-env-hflags |= MIPS_HFLAG_F64;
-}
-if (env-insn_flags  ISA_MIPS32R2) {
-if (env-active_fpu.fcr0  (1  FCR0_F64)) {
-env-hflags |= MIPS_HFLAG_COP1X;
-}
-} else if (env-insn_flags  ISA_MIPS32) {
-if (env-hflags  MIPS_HFLAG_64) {
-env-hflags |= MIPS_HFLAG_COP1X;
-}
-} else if (env-insn_flags  ISA_MIPS4) {
-/* All supported MIPS IV CPUs use the XX (CU3) to enable
-   and disable the MIPS IV extensions to the MIPS III ISA.
-   Some other MIPS IV CPUs ignore the bit, so the check here
-   would be too restrictive for them.  */
-if (env-CP0_Status

[Qemu-devel] [PATCH v1 1/1] m68k: Return semihosting errno values correctly

2012-02-24 Thread Meador Inge
Fixing a simple typo, s/errno/err/, that caused
the error status from GDB semihosted system calls
to be returned incorrectly.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 m68k-semi.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/m68k-semi.c b/m68k-semi.c
index bab01ee..6d60ced 100644
--- a/m68k-semi.c
+++ b/m68k-semi.c
@@ -150,7 +150,7 @@ static void m68k_semi_cb(CPUState *env, target_ulong ret, 
target_ulong err)
 }
 /* FIXME - handle put_user() failure */
 put_user_u32(ret, args);
-put_user_u32(errno, args + 4);
+put_user_u32(err, args + 4);
 }
 
 #define ARG(n) \
-- 
1.7.7.6




[Qemu-devel] [PATCH v1 1/1] ppc: Correctly define POWERPC_INSNS2_DEFAULT

2012-02-23 Thread Meador Inge
'POWERPC_INSNS2_DEFAULT' was defined incorrectly which was causing the
opcode table creation code to erroneously register 'eieio' and 'mbar'
for the default processor:

   ** ERROR: opcode 1a already assigned in opcode table 16
   *** ERROR: unable to insert opcode [1f-16-1a]
   *** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-ppc/translate_init.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 6253076..6cb5fad 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -6713,7 +6713,7 @@ static void init_proc_620 (CPUPPCState *env)
 #if defined (TARGET_PPC64)  0 // XXX: TODO
 #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC64
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC64
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC64
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC64
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC64
 #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC64
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC64
@@ -6725,7 +6725,7 @@ static void init_proc_620 (CPUPPCState *env)
 #else
 #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC32
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC32
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC32
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC32
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC32
 #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC32
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC32
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v2 1/1] exec: Fix watchpoint implementation

2012-02-20 Thread Meador Inge
On 02/18/2012 10:33 AM, Andreas Färber wrote:

 Am 17.02.2012 18:06, schrieb Andreas Färber:
 Am 17.02.2012 18:03, schrieb Meador Inge:
 Fix a bug introduced by commit 1ec9b909ff207a44d5ef2609cb4a2e3d449d485f
 where 'watch_mem_write' was modified to fall-through to 'abort' on
 every input.

 Signed-off-by: Meador Inge mead...@codesourcery.com

 Reviewed-by: Andreas Färber afaer...@suse.de
 
 Actually I already reviewed such a fix by Max on Jan 29 (with breaks
 from the start), and it's in his PULL request now. So this is again a
 duplicate and shouldn't be applied.
 
 If you want to remind maintainers of a patch that's been on the list but
 has not yet been applied, the correct procedure is to add a Reviewed-by
 or Acked-by tag if you haven't already, or to reply with a Ping?
 otherwise.

Ah, I missed that.  I will add a review tag to the other.  Thanks for the heads
up.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH 07/12] exec: add missing breaks to the watch_mem_write

2012-02-20 Thread Meador Inge
On 02/18/2012 11:11 AM, Max Filippov wrote:
 Signed-off-by: Max Filippov jcmvb...@gmail.com

Reviewed-by: Meador Inge mead...@codesourcery.com

 ---
  exec.c |   12 +---
  1 files changed, 9 insertions(+), 3 deletions(-)
 
 diff --git a/exec.c b/exec.c
 index b81677a..f105b43 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -3289,9 +3289,15 @@ static void watch_mem_write(void *opaque, 
 target_phys_addr_t addr,
  {
  check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_WRITE);
  switch (size) {
 -case 1: stb_phys(addr, val);
 -case 2: stw_phys(addr, val);
 -case 4: stl_phys(addr, val);
 +case 1:
 +stb_phys(addr, val);
 +break;
 +case 2:
 +stw_phys(addr, val);
 +break;
 +case 4:
 +stl_phys(addr, val);
 +break;
  default: abort();
  }
  }


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v1 1/1] syscall: #ifdef newer RLIMIT_* codes

2012-02-20 Thread Meador Inge
Commit e22b7015353be824620b1f0f5e32a8575b898a8c added the translation
from target to host RLIMIT_* codes, but some of the added codes are
only available on newer version of Linux (as documented in 'getrlimit(2)').

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 linux-user/syscall.c |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8a11213..1986238 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -996,20 +996,32 @@ static inline int target_to_host_resource(int code)
 return RLIMIT_LOCKS;
 case TARGET_RLIMIT_MEMLOCK:
 return RLIMIT_MEMLOCK;
+/* = Linux 2.6.8 */
+#ifdef RLIMIT_MSGQUEUE
 case TARGET_RLIMIT_MSGQUEUE:
 return RLIMIT_MSGQUEUE;
+#endif
+/* = Linux 2.6.12 */
+#ifdef RLIMIT_NICE
 case TARGET_RLIMIT_NICE:
 return RLIMIT_NICE;
+#endif
 case TARGET_RLIMIT_NOFILE:
 return RLIMIT_NOFILE;
 case TARGET_RLIMIT_NPROC:
 return RLIMIT_NPROC;
 case TARGET_RLIMIT_RSS:
 return RLIMIT_RSS;
+/* = Linux 2.6.12 */
+#ifdef RLIMIT_RTPRIO
 case TARGET_RLIMIT_RTPRIO:
 return RLIMIT_RTPRIO;
+#endif
+/* = Linux 2.6.8 */
+#ifdef RLIMIT_SIGPENDING
 case TARGET_RLIMIT_SIGPENDING:
 return RLIMIT_SIGPENDING;
+#endif
 case TARGET_RLIMIT_STACK:
 return RLIMIT_STACK;
 default:
-- 
1.7.7.6




[Qemu-devel] [PATCH v2 1/1] gdbserver: Don't send a GDB syscall until the system CPU is stopped

2012-02-17 Thread Meador Inge
Fix an issue where the GDB server implementation was sending GDB syscall
requests while the system CPU was still running.  Syscall requests must
be sent while the CPU is stopped otherwise replies from the GDB client
might get dropped and the GDB server might be incorrectly transitioned
into a 'RUN_STATE_PAUSED' state.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 gdbstub.c |   44 
 1 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 7d470b6..a08532f 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -283,8 +283,7 @@ enum RSState {
 RS_IDLE,
 RS_GETLINE,
 RS_CHKSUM1,
-RS_CHKSUM2,
-RS_SYSCALL,
+RS_CHKSUM2
 };
 typedef struct GDBState {
 CPUState *c_cpu; /* current CPU for step/continue ops */
@@ -304,6 +303,8 @@ typedef struct GDBState {
 CharDriverState *chr;
 CharDriverState *mon_chr;
 #endif
+char syscall_buf[256];
+gdb_syscall_complete_cb current_syscall_cb;
 } GDBState;
 
 /* By default use no IRQs and no timers while single stepping so as to
@@ -346,8 +347,6 @@ static int get_char(GDBState *s)
 }
 #endif
 
-static gdb_syscall_complete_cb gdb_current_syscall_cb;
-
 static enum {
 GDB_SYS_UNKNOWN,
 GDB_SYS_ENABLED,
@@ -2095,8 +2094,10 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 if (*p == ',')
 p++;
 type = *p;
-if (gdb_current_syscall_cb)
-gdb_current_syscall_cb(s-c_cpu, ret, err);
+if (s-current_syscall_cb) {
+s-current_syscall_cb(s-c_cpu, ret, err);
+s-current_syscall_cb = NULL;
+}
 if (type == 'C') {
 put_packet(s, T02);
 } else {
@@ -2396,7 +2397,12 @@ static void gdb_vm_state_change(void *opaque, int 
running, RunState state)
 const char *type;
 int ret;
 
-if (running || s-state == RS_INACTIVE || s-state == RS_SYSCALL) {
+if (running || s-state == RS_INACTIVE) {
+return;
+}
+/* Is there a GDB syscall waiting to be sent?  */
+if (s-current_syscall_cb) {
+put_packet(s, s-syscall_buf);
 return;
 }
 switch (state) {
@@ -2466,8 +2472,8 @@ send_packet:
 void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
 {
 va_list va;
-char buf[256];
 char *p;
+char *p_end;
 target_ulong addr;
 uint64_t i64;
 GDBState *s;
@@ -2475,14 +2481,13 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const 
char *fmt, ...)
 s = gdbserver_state;
 if (!s)
 return;
-gdb_current_syscall_cb = cb;
-s-state = RS_SYSCALL;
+s-current_syscall_cb = cb;
 #ifndef CONFIG_USER_ONLY
 vm_stop(RUN_STATE_DEBUG);
 #endif
-s-state = RS_IDLE;
 va_start(va, fmt);
-p = buf;
+p = s-syscall_buf;
+p_end = s-syscall_buf[sizeof(s-syscall_buf)];
 *(p++) = 'F';
 while (*fmt) {
 if (*fmt == '%') {
@@ -2490,17 +2495,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const 
char *fmt, ...)
 switch (*fmt++) {
 case 'x':
 addr = va_arg(va, target_ulong);
-p += snprintf(p, buf[sizeof(buf)] - p, TARGET_FMT_lx, addr);
+p += snprintf(p, p_end - p, TARGET_FMT_lx, addr);
 break;
 case 'l':
 if (*(fmt++) != 'x')
 goto bad_format;
 i64 = va_arg(va, uint64_t);
-p += snprintf(p, buf[sizeof(buf)] - p, % PRIx64, i64);
+p += snprintf(p, p_end - p, % PRIx64, i64);
 break;
 case 's':
 addr = va_arg(va, target_ulong);
-p += snprintf(p, buf[sizeof(buf)] - p, TARGET_FMT_lx /%x,
+p += snprintf(p, p_end - p, TARGET_FMT_lx /%x,
   addr, va_arg(va, int));
 break;
 default:
@@ -2515,10 +2520,16 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const 
char *fmt, ...)
 }
 *p = 0;
 va_end(va);
-put_packet(s, buf);
 #ifdef CONFIG_USER_ONLY
+put_packet(s, s-syscall_buf);
 gdb_handlesig(s-c_cpu, 0);
 #else
+/* In this case wait to send the syscall packet until notification that
+   the CPU has stopped.  This must be done because if the packet is sent
+   now the reply from the syscall request could be received while the CPU
+   is still in the running state, which can cause packets to be dropped
+   and state transition 'T' packets to be sent while the syscall is still
+   being processed.  */
 cpu_exit(s-c_cpu);
 #endif
 }
@@ -2917,6 +2928,7 @@ int gdbserver_start(const char *device)
 s-chr = chr;
 s-state = chr ? RS_IDLE : RS_INACTIVE;
 s-mon_chr = mon_chr;
+s-current_syscall_cb = NULL;
 
 return 0;
 }
-- 
1.7.7.6




[Qemu-devel] [PATCH v2 0/1] Fix GDB semihosting

2012-02-17 Thread Meador Inge
Hi All,

GDB semihosting support is broken in the current trunk.  When debugging a
basic Hello, World application via the QEMU GDB stub:

   $ qemu-system-arm -s -S -M integratorcp -cpu any --semihosting
 --monitor null --serial null -kernel hello

GDB (7.2.50) receives an interrupt before anything is printed:

   Program received signal SIGINT, Interrupt.

The fundamental issue is that the GDB server implementation sends syscall
requests while the system CPU is still running and isn't prepared to handle
the replies.  This patch fixes the problem by delaying syscall request until
the system CPU has stopped.

* Changes from v1
 - At the suggestion of Peter Maydell I changed the implementation to delay
   sending syscall requests until the CPU has stopped instead of incorrectly
   attempting to just suppress the sending of 'T' status replies.

Meador Inge (1):
  gdbserver: Don't send a GDB syscall until the system CPU is stopped

 gdbstub.c |   44 
 1 files changed, 28 insertions(+), 16 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH v1 1/1] exec: Fix watchpoint implementation

2012-02-17 Thread Meador Inge
Fix a bug introduced by commit 1ec9b909ff207a44d5ef2609cb4a2e3d449d485f
where 'watch_mem_write' was modified to fall-through to 'abort' on
every input.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 exec.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index b81677a..fe8b2d1 100644
--- a/exec.c
+++ b/exec.c
@@ -3289,9 +3289,9 @@ static void watch_mem_write(void *opaque, 
target_phys_addr_t addr,
 {
 check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_WRITE);
 switch (size) {
-case 1: stb_phys(addr, val);
-case 2: stw_phys(addr, val);
-case 4: stl_phys(addr, val);
+case 1: return stb_phys(addr, val);
+case 2: return stw_phys(addr, val);
+case 4: return stl_phys(addr, val);
 default: abort();
 }
 }
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v1 1/1] exec: Fix watchpoint implementation

2012-02-17 Thread Meador Inge
On 02/17/2012 10:28 AM, Jan Kiszka wrote:

 On 2012-02-17 17:23, Meador Inge wrote:
 Fix a bug introduced by commit 1ec9b909ff207a44d5ef2609cb4a2e3d449d485f
 where 'watch_mem_write' was modified to fall-through to 'abort' on
 every input.

 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  exec.c |6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

 diff --git a/exec.c b/exec.c
 index b81677a..fe8b2d1 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -3289,9 +3289,9 @@ static void watch_mem_write(void *opaque, 
 target_phys_addr_t addr,
  {
  check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_WRITE);
  switch (size) {
 -case 1: stb_phys(addr, val);
 -case 2: stw_phys(addr, val);
 -case 4: stl_phys(addr, val);
 +case 1: return stb_phys(addr, val);
 +case 2: return stw_phys(addr, val);
 +case 4: return stl_phys(addr, val);
  default: abort();
  }
  }
 
 You likely wanted to introduce breaks here, no...?

I see both styles in 'exec.c'.  An example similar to the above is:

static void subpage_ram_write(void *opaque, target_phys_addr_t addr,
  uint64_t value, unsigned size)
{
ram_addr_t raddr = addr;
void *ptr = qemu_get_ram_ptr(raddr);
switch (size) {
case 1: return stb_p(ptr, value);
case 2: return stw_p(ptr, value);
case 4: return stl_p(ptr, value);
default: abort();
}
}

I will switch to the 'break' style if that is more consistent with the general
coding convention.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v2 1/1] exec: Fix watchpoint implementation

2012-02-17 Thread Meador Inge
Fix a bug introduced by commit 1ec9b909ff207a44d5ef2609cb4a2e3d449d485f
where 'watch_mem_write' was modified to fall-through to 'abort' on
every input.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
* Changes since v1:
  - 'break' out of switch statement instead of 'return'.
 exec.c |   12 +---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index b81677a..f105b43 100644
--- a/exec.c
+++ b/exec.c
@@ -3289,9 +3289,15 @@ static void watch_mem_write(void *opaque, 
target_phys_addr_t addr,
 {
 check_watchpoint(addr  ~TARGET_PAGE_MASK, ~(size - 1), BP_MEM_WRITE);
 switch (size) {
-case 1: stb_phys(addr, val);
-case 2: stw_phys(addr, val);
-case 4: stl_phys(addr, val);
+case 1:
+stb_phys(addr, val);
+break;
+case 2:
+stw_phys(addr, val);
+break;
+case 4:
+stl_phys(addr, val);
+break;
 default: abort();
 }
 }
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v1 0/1] Fix GDB semihosting

2012-02-16 Thread Meador Inge
;
 va_end(va);
-put_packet(s, buf);
 #ifdef CONFIG_USER_ONLY
+s-state = RS_IDLE;
+put_packet(s, gdb_syscall_buf);
 gdb_handlesig(s-c_cpu, 0);
 #else
+/* In this case wait to send the syscall packet until notification that
+   the CPU has stopped.  This must be done because if the packet is sent
+   now the reply from the syscall request could be received while the CPU
+   is still in the running state, which can cause packets to be dropped
+   and state transition 'T' packets to be sent while the syscall is still
+   being processed.  */
 cpu_exit(s-c_cpu);
 #endif
 }

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 0/1] Fix GDB semihosting

2012-02-16 Thread Meador Inge
On 02/16/2012 01:08 PM, Peter Maydell wrote:

 On 16 February 2012 18:39, Meador Inge mead...@codesourcery.com wrote:
 On 02/15/2012 02:14 PM, Peter Maydell wrote:
 I think the right way to deal with both the problem you were seeing
 and this related issue is simply not to try to send the syscall
 request until we have really stopped the CPU. That is, when not
 in CONFIG_USER_ONLY we should send the syscall request from
 gdb_vm_state_change().

 I agree.  I am doing some more testing and will send an official v2 patch
 later, but just to make sure I am on the right track something like (this
 worked in the basic testing I have done so far and avoids the pitfall pointed
 out above):
 
 That looks roughly OK, but:
  * shouldn't gdb_syscall_buf[] be in GDBState ?
  * I don't think the are we stopping to do a syscall? flag should be
implemented as an RSState enum -- that enum is for the
 parsing-incoming-packet
state machine

I cleaned up these bits.  v2 patch coming up soon.

 Bonus extra semihosting bug: if you start with -gdb none rather than -s 
 then
 we segfault, because gdbserver_start() creates a GDBState with a NULL s-chr
 but use_gdb_syscalls() only looks at whether gdbserver_state is non-NULL, not
 whether s-state is RS_INACTIVE, so the first gdb_do_syscall() ends up
 dereferencing that NULL pointer. (Watch out when fixing this that you don't
 break semihosting in linux-user mode, because at the moment linux-user mode
 doesn't set up s-state at all so it's always RS_INACTIVE... We may also
 want to declare that mixing all of gdb, semihosting and fork() in a linux-user
 guest is not supported ;-))

I will take a look at that one as a separate patch :-)

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v1] ./configure: use -lole32 when building with mingw32

2012-02-15 Thread Meador Inge
glib calls 'CoTaskMemFree' which is defined by ole32.dll.
Therefore when building with mingw32 -lole32 should be in
'LIBS'.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 configure |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 88521d2..40caf81 100755
--- a/configure
+++ b/configure
@@ -502,7 +502,7 @@ if test $mingw32 = yes ; then
   QEMU_CFLAGS=-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS=-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS
-  LIBS=-lwinmm -lws2_32 -liberty -liphlpapi $LIBS
+  LIBS=-lole32 -lwinmm -lws2_32 -liberty -liphlpapi $LIBS
   prefix=c:/Program Files/Qemu
   mandir=\${prefix}
   datadir=\${prefix}
-- 
1.7.7.6




[Qemu-devel] [PATCH v1 0/1] Fix GDB semihosting

2012-02-15 Thread Meador Inge
Hi All,

GDB semihosting support is broken in the current trunk.  When debugging a
basic Hello, World application via the QEMU GDB stub:

   $ qemu-system-arm -s -S -M integratorcp -cpu any --semihosting
 --monitor null --serial null -kernel hello

GDB (7.2.50) receives an interrupt before anything is printed:

   Program received signal SIGINT, Interrupt.

As an example, consider this processing of the 'isatty' syscall.
'gdb_do_syscall' gets executed while 'current_run_state == RUN_STATE_RUNNING'.
It then changes the VM and GDB server state with:

s-state = RS_SYSCALL;
vm_stop(RUN_STATE_DEBUG);
s-state = RS_IDLE;

which leaves the GDB server state in 'RS_IDLE', but since the syscall
happens while in the TCG thread the 'RUN_STATE_DEBUG' stop does not
happen immediately.  This leads to the following course of events:

1. 'gdb_do_syscall' finishes up by sending a 'Fisatty,0001' packet to the
   GDB client.
2. 'RUN_STATE_DEBUG' get pulled from the event queue.
3. 'gdb_vm_state_change' is invoked thus causing a 'T05thread:01;' reply
   to be sent back to the GDB client.
4. A payload of '+$F1#77+' comes in containing the syscall reply and the
   'T05' ACK.
5. '+$F1#77' is processed and 'gdb_handle_packet' transitions the
   state back 'RUN_STATE_RUNNING'.
6. 'gdb_read_byte' starts processing the remaining payload of '+',
   but the current state is 'RUN_STATE_RUNNING' so 'gdb_read_byte' issues
   a 'vm_stop(RUN_STATE_PAUSED)' which takes effect immediately.
7. 'gdb_vm_state_change' is invoked thus causing a 'T02thread:01;' reply
   to be sent back to the GDB client.
8. The GDB client interrupts and breaks the semihosting flow.

This patch fixes the problem be staying in the 'RS_SYSCALL' state until next
packet read comes in.  Therefore keeping any 'T' statuses from being sent
back to the GDB client while the syscall is still being processed.

Meador Inge (1):
  gdbserver: Keep VM state status replies from happening during a
syscall

 gdbstub.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH v1 1/1] gdbserver: Keep VM state status replies from happening during a syscall

2012-02-15 Thread Meador Inge
Fix an issue where the GDB server implementation was allowing 'RUN_STATE_DEBUG'
transitions to send a signal trap status back to the GDB client while a syscall
is being processed.  This eventually resulted in sending a SIGINT to the GDB
client.

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 gdbstub.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 7d470b6..34d2717 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2480,7 +2480,6 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const 
char *fmt, ...)
 #ifndef CONFIG_USER_ONLY
 vm_stop(RUN_STATE_DEBUG);
 #endif
-s-state = RS_IDLE;
 va_start(va, fmt);
 p = buf;
 *(p++) = 'F';
@@ -2557,6 +2556,8 @@ static void gdb_read_byte(GDBState *s, int ch)
 #endif
 {
 switch(s-state) {
+case RS_SYSCALL:
+s-state = RS_IDLE;
 case RS_IDLE:
 if (ch == '$') {
 s-line_buf_index = 0;
-- 
1.7.7.6




Re: [Qemu-devel] [PATCH v1 1/1] gdbserver: Keep VM state status replies from happening during a syscall

2012-02-15 Thread Meador Inge
On 02/15/2012 11:54 AM, Blue Swirl wrote:

 On Wed, Feb 15, 2012 at 16:55, Meador Inge mead...@codesourcery.com wrote:
 Fix an issue where the GDB server implementation was allowing 
 'RUN_STATE_DEBUG'
 transitions to send a signal trap status back to the GDB client while a 
 syscall
 is being processed.  This eventually resulted in sending a SIGINT to the GDB
 client.

 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  gdbstub.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

 diff --git a/gdbstub.c b/gdbstub.c
 index 7d470b6..34d2717 100644
 --- a/gdbstub.c
 +++ b/gdbstub.c
 @@ -2480,7 +2480,6 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const 
 char *fmt, ...)
  #ifndef CONFIG_USER_ONLY
 vm_stop(RUN_STATE_DEBUG);
  #endif
 -s-state = RS_IDLE;
 va_start(va, fmt);
 p = buf;
 *(p++) = 'F';
 @@ -2557,6 +2556,8 @@ static void gdb_read_byte(GDBState *s, int ch)
  #endif
 {
 switch(s-state) {
 +case RS_SYSCALL:
 +s-state = RS_IDLE;
 
 Missing break statement or a comment about fallthrough.

The fallthrough is intentional.  I will add a comment.


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v3 0/1] Allow the building of VirtFS to be disabled

2012-02-15 Thread Meador Inge
Ping... Any comments on the v3 patch?

http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg01236.html

On Thu, Feb 9, 2012 at 8:31 PM, Meador Inge mead...@codesourcery.com wrote:
 There have been reports [1, 2] where folks have had issues building
 VirtFS and the virtio backend on older systems.  I personally saw
 problems due to the use of features (struct statfs f_frsize field,
 fdopendir, O_NOATIME) in this code that are not available on much older
 Linux systems.  Given, the system I ran into this on is ancient (RH8 sysroot),
 but I still need to build QEMU on it nonetheless.

 This patch adds a new configure option for disabling the building of
 VirtFS all together.  Tested by building with and without --disable-virtfs
 on older (RH8 sysroot) and newer systems (x64 Fedora 16).

 [1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html
 [2] http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00404.html

 * Changes from v2
  - Use 'test $foo = yes  test $bar = yes' instead of
    '$foo = yes -a $bar = yes'.
 * Changes from v1
  - Simplify the configure logic and support the standard behavior
    of defaulting virtfs=.  Changes suggested by Peter Maydell.

 Meador Inge (1):
  ./configure: add option for disabling VirtFS

  Makefile  |    2 ++
  configure |   25 +++--
  2 files changed, 21 insertions(+), 6 deletions(-)

 --
 1.7.7.6





-- 
# Meador



Re: [Qemu-devel] [PATCH v1] ./configure: use -lole32 when building with mingw32

2012-02-15 Thread Meador Inge
On 02/15/2012 10:49 AM, Peter Maydell wrote:

 On 15 February 2012 16:41, Meador Inge mead...@codesourcery.com wrote:
 glib calls 'CoTaskMemFree' which is defined by ole32.dll.
 Therefore when building with mingw32 -lole32 should be in
 'LIBS'.
 
 Not that I'm objecting to the patch, but isn't this technically
 a bug in the pkg-config for glib with mingw32 that we're working
 around?

Yup, the issue is fixed in recent versions of glib:

http://git.gnome.org/browse/glib/commit/?id=b79eae5c197aeec8d57f39c0f7bf5d5114068bea

http://git.gnome.org/browse/glib/commit/?id=5377c0de0108d292ea3e23fa6d90410f9ac9fa00

I am OK with backporting the glib fix for mingw32 builds.  Sorry for the noise.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [MASCOT CONTEST] Clare Liguori #1

2012-02-15 Thread Meador Inge
On Wed, Feb 15, 2012 at 8:46 AM, Anthony Liguori anth...@codemonkey.ws wrote:
 Please respond to this note with an '+1', or an Ack, to vote for this icon.

+1



Re: [Qemu-devel] [MASCOT CONTEST] Alex Bradbury #1

2012-02-15 Thread Meador Inge
On Wed, Feb 15, 2012 at 8:31 AM, Anthony Liguori anth...@codemonkey.ws wrote:
 Please respond to this note with an '+1', or an Ack, to vote for this icon.

+1

-- Meador



Re: [Qemu-devel] [PATCH v1 0/1] Allow the building of VirtFS to be disabled

2012-02-09 Thread Meador Inge
On 02/08/2012 02:15 AM, Aneesh Kumar K.V wrote:

 On Tue, 7 Feb 2012 14:44:05 -0600, Meador Inge mead...@codesourcery.com 
 wrote:
 There have been reports [1, 2] where folks have had issues building
 VirtFS and the virtio backend on older systems.  I personally saw
 problems due to the use of features (struct statfs f_frsize field,
 fdopendir, O_NOATIME) in this code that are not available on much older
 Linux systems.  Given, the system I ran into this on is ancient (RH8 
 sysroot),
 but I still need to build QEMU on it nonetheless.

 This patch adds a new configure option for disabling the building of
 VirtFS all together.  Tested by building with and without --disable-virtfs
 on older (RH8 sysroot) and newer systems (x64 Fedora 16).

 [1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html
 [2] http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00404.html

 Meador Inge (1):
   ./configure: add option for disabling VirtFS

  Makefile  |4 
  configure |   16 +---
  2 files changed, 17 insertions(+), 3 deletions(-)
 
 I like the patch because it help to get qemu build on platforms where
 the build failures are only due to virtfs. VirtFS do depend on some of
 the recent linux APIs, so sometime we do break build on old Linux
 distros.

Great.  Thanks for the review.  Can someone commit this for me?

 Anthony any objection here ?
 
 -aneesh
 


-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



Re: [Qemu-devel] [PATCH v1 1/1] ./configure: add option for disabling VirtFS

2012-02-09 Thread Meador Inge
On 02/09/2012 04:39 PM, Peter Maydell wrote:

 On 7 February 2012 20:44, Meador Inge mead...@codesourcery.com wrote:
 Signed-off-by: Meador Inge mead...@codesourcery.com
 ---
  Makefile  |4 
  configure |   16 +---
  2 files changed, 17 insertions(+), 3 deletions(-)

 diff --git a/Makefile b/Makefile
 index 47acf3d..030619c 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -40,7 +40,9 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)

  ifdef BUILD_DOCS
  DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 
 QMP/qmp-commands.txt
 +ifdef CONFIG_VIRTFS
  DOCS+=fsdev/virtfs-proxy-helper.1
 +endif
  else
  DOCS=
  endif
 @@ -162,8 +164,10 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) 
 $(block-obj-y)

  qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o

 +ifdef CONFIG_VIRTFS
  fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o 
 fsdev/virtio-9p-marshal.o oslib-posix.o $(trace-obj-y)
  fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 +endif
 
 We don't need to make this conditional, we will just not put
 the proxy-helper into TOOLS if we don't want to build it and
 this dependency will be ignored.

Fixed.

  qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h  $  $@,  
 GEN   $@)
 diff --git a/configure b/configure
 index 763db24..081d720 100755
 --- a/configure
 +++ b/configure
 @@ -121,6 +121,7 @@ docs=
  fdt=
  nptl=
  sdl=
 +virtfs=yes
  vnc=yes
  sparse=no
  uuid=
 @@ -586,6 +587,10 @@ for opt do
   ;;
   --enable-sdl) sdl=yes
   ;;
 +  --disable-virtfs) virtfs=no
 +  ;;
 +  --enable-virtfs) virtfs=yes
 +  ;;
   --disable-vnc) vnc=no
   ;;
   --enable-vnc) vnc=yes
 
 This should be handled the same way as a number of other optional
 components : default is  meaning 'probe and use if possible'.
 So you end up with a test like:
 
 if test $virtfs != no; then
if test $cap = yes  test $linux = yes  test $attr = yes; then
virtfs=yes
tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
else
if test $virtfs = yes; then
feature_not_found virtfs
fi
fi
 fi
 
 and then later just
 if test $virtfs = yes ; then
echo CONFIG_VIRTFS=y  $config_host_mak
 fi

That's much cleaner.  Thanks for the review.

v2 patch coming up soon.

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software



[Qemu-devel] [PATCH v2 0/1] Allow the building of VirtFS to be disabled

2012-02-09 Thread Meador Inge
There have been reports [1, 2] where folks have had issues building
VirtFS and the virtio backend on older systems.  I personally saw
problems due to the use of features (struct statfs f_frsize field,
fdopendir, O_NOATIME) in this code that are not available on much older
Linux systems.  Given, the system I ran into this on is ancient (RH8 sysroot),
but I still need to build QEMU on it nonetheless.

This patch adds a new configure option for disabling the building of
VirtFS all together.  Tested by building with and without --disable-virtfs
on older (RH8 sysroot) and newer systems (x64 Fedora 16).

[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html
[2] http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00404.html

* Changes from v1
  - Simplify the configure logic and support the standard behavior
of defaulting virtfs=.  Changes suggested by Peter Maydell.

Meador Inge (1):
  ./configure: add option for disabling VirtFS

 Makefile  |2 ++
 configure |   25 +++--
 2 files changed, 21 insertions(+), 6 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH v2 1/1] ./configure: add option for disabling VirtFS

2012-02-09 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 Makefile  |2 ++
 configure |   25 +++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index e66e885..3dd67e2 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,9 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
 ifdef BUILD_DOCS
 DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 
QMP/qmp-commands.txt
+ifdef CONFIG_VIRTFS
 DOCS+=fsdev/virtfs-proxy-helper.1
+endif
 else
 DOCS=
 endif
diff --git a/configure b/configure
index 763db24..f0892e7 100755
--- a/configure
+++ b/configure
@@ -121,6 +121,7 @@ docs=
 fdt=
 nptl=
 sdl=
+virtfs=
 vnc=yes
 sparse=no
 uuid=
@@ -586,6 +587,10 @@ for opt do
   ;;
   --enable-sdl) sdl=yes
   ;;
+  --disable-virtfs) virtfs=no
+  ;;
+  --enable-virtfs) virtfs=yes
+  ;;
   --disable-vnc) vnc=no
   ;;
   --enable-vnc) vnc=yes
@@ -993,6 +998,8 @@ echo   --disable-strip  disable stripping binaries
 echo   --disable-werror disable compilation abort on warning
 echo   --disable-sdldisable SDL
 echo   --enable-sdl enable SDL
+echo   --disable-virtfs disable VirtFS
+echo   --enable-virtfs  enable VirtFS
 echo   --disable-vncdisable VNC
 echo   --enable-vnc enable VNC
 echo   --enable-cocoa   enable COCOA (Mac OS X only)
@@ -2808,8 +2815,15 @@ confdir=$sysconfdir$confsuffix
 tools=
 if test $softmmu = yes ; then
   tools=qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools
-  if [ $cap = yes -a $linux = yes ] ; then
-  tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
+  if test $virtfs != no ; then
+  if [ $cap = yes -a $linux = yes -a $attr = yes ] ; then
+ virtfs=yes
+ tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
+  else
+ if test $virtfs = yes; then
+ feature_not_found virtfs
+ fi
+  fi
   fi
   if [ $linux = yes -o $bsd = yes -o $solaris = yes ] ; then
   tools=qemu-nbd\$(EXESUF) $tools
@@ -2874,6 +2888,7 @@ echo Audio drivers $audio_drv_list
 echo Extra audio cards $audio_card_list
 echo Block whitelist   $block_drv_whitelist
 echo Mixer emulation   $mixemu
+echo VirtFS support$virtfs
 echo VNC support   $vnc
 if test $vnc = yes ; then
 echo VNC TLS support   $vnc_tls
@@ -3163,10 +3178,8 @@ fi
 if test $libattr = yes ; then
   echo CONFIG_LIBATTR=y  $config_host_mak
 fi
-if test $linux = yes ; then
-  if test $attr = yes ; then
-echo CONFIG_VIRTFS=y  $config_host_mak
-  fi
+if test $virtfs = yes ; then
+  echo CONFIG_VIRTFS=y  $config_host_mak
 fi
 if test $blobs = yes ; then
   echo INSTALL_BLOBS=yes  $config_host_mak
-- 
1.7.7.6




[Qemu-devel] [PATCH v3 0/1] Allow the building of VirtFS to be disabled

2012-02-09 Thread Meador Inge
There have been reports [1, 2] where folks have had issues building
VirtFS and the virtio backend on older systems.  I personally saw
problems due to the use of features (struct statfs f_frsize field,
fdopendir, O_NOATIME) in this code that are not available on much older
Linux systems.  Given, the system I ran into this on is ancient (RH8 sysroot),
but I still need to build QEMU on it nonetheless.

This patch adds a new configure option for disabling the building of
VirtFS all together.  Tested by building with and without --disable-virtfs
on older (RH8 sysroot) and newer systems (x64 Fedora 16).

[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html
[2] http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00404.html

* Changes from v2
  - Use 'test $foo = yes  test $bar = yes' instead of
'$foo = yes -a $bar = yes'.
* Changes from v1
  - Simplify the configure logic and support the standard behavior
of defaulting virtfs=.  Changes suggested by Peter Maydell.

Meador Inge (1):
  ./configure: add option for disabling VirtFS

 Makefile  |2 ++
 configure |   25 +++--
 2 files changed, 21 insertions(+), 6 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH v3 1/1] ./configure: add option for disabling VirtFS

2012-02-09 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 Makefile  |2 ++
 configure |   25 +++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index e66e885..3dd67e2 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,9 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
 ifdef BUILD_DOCS
 DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 
QMP/qmp-commands.txt
+ifdef CONFIG_VIRTFS
 DOCS+=fsdev/virtfs-proxy-helper.1
+endif
 else
 DOCS=
 endif
diff --git a/configure b/configure
index 763db24..88521d2 100755
--- a/configure
+++ b/configure
@@ -121,6 +121,7 @@ docs=
 fdt=
 nptl=
 sdl=
+virtfs=
 vnc=yes
 sparse=no
 uuid=
@@ -586,6 +587,10 @@ for opt do
   ;;
   --enable-sdl) sdl=yes
   ;;
+  --disable-virtfs) virtfs=no
+  ;;
+  --enable-virtfs) virtfs=yes
+  ;;
   --disable-vnc) vnc=no
   ;;
   --enable-vnc) vnc=yes
@@ -993,6 +998,8 @@ echo   --disable-strip  disable stripping binaries
 echo   --disable-werror disable compilation abort on warning
 echo   --disable-sdldisable SDL
 echo   --enable-sdl enable SDL
+echo   --disable-virtfs disable VirtFS
+echo   --enable-virtfs  enable VirtFS
 echo   --disable-vncdisable VNC
 echo   --enable-vnc enable VNC
 echo   --enable-cocoa   enable COCOA (Mac OS X only)
@@ -2808,8 +2815,15 @@ confdir=$sysconfdir$confsuffix
 tools=
 if test $softmmu = yes ; then
   tools=qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools
-  if [ $cap = yes -a $linux = yes ] ; then
-  tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
+  if test $virtfs != no ; then
+  if test $cap = yes  test $linux = yes  test $attr = yes ; then
+ virtfs=yes
+ tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
+  else
+ if test $virtfs = yes; then
+ feature_not_found virtfs
+ fi
+  fi
   fi
   if [ $linux = yes -o $bsd = yes -o $solaris = yes ] ; then
   tools=qemu-nbd\$(EXESUF) $tools
@@ -2874,6 +2888,7 @@ echo Audio drivers $audio_drv_list
 echo Extra audio cards $audio_card_list
 echo Block whitelist   $block_drv_whitelist
 echo Mixer emulation   $mixemu
+echo VirtFS support$virtfs
 echo VNC support   $vnc
 if test $vnc = yes ; then
 echo VNC TLS support   $vnc_tls
@@ -3163,10 +3178,8 @@ fi
 if test $libattr = yes ; then
   echo CONFIG_LIBATTR=y  $config_host_mak
 fi
-if test $linux = yes ; then
-  if test $attr = yes ; then
-echo CONFIG_VIRTFS=y  $config_host_mak
-  fi
+if test $virtfs = yes ; then
+  echo CONFIG_VIRTFS=y  $config_host_mak
 fi
 if test $blobs = yes ; then
   echo INSTALL_BLOBS=yes  $config_host_mak
-- 
1.7.7.6




[Qemu-devel] [PATCH v1 0/1] Allow the building of VirtFS to be disabled

2012-02-07 Thread Meador Inge
There have been reports [1, 2] where folks have had issues building
VirtFS and the virtio backend on older systems.  I personally saw
problems due to the use of features (struct statfs f_frsize field,
fdopendir, O_NOATIME) in this code that are not available on much older
Linux systems.  Given, the system I ran into this on is ancient (RH8 sysroot),
but I still need to build QEMU on it nonetheless.

This patch adds a new configure option for disabling the building of
VirtFS all together.  Tested by building with and without --disable-virtfs
on older (RH8 sysroot) and newer systems (x64 Fedora 16).

[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html
[2] http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00404.html

Meador Inge (1):
  ./configure: add option for disabling VirtFS

 Makefile  |4 
 configure |   16 +---
 2 files changed, 17 insertions(+), 3 deletions(-)

-- 
1.7.7.6




[Qemu-devel] [PATCH v1 1/1] ./configure: add option for disabling VirtFS

2012-02-07 Thread Meador Inge
Signed-off-by: Meador Inge mead...@codesourcery.com
---
 Makefile  |4 
 configure |   16 +---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 47acf3d..030619c 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,9 @@ HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
 ifdef BUILD_DOCS
 DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8 
QMP/qmp-commands.txt
+ifdef CONFIG_VIRTFS
 DOCS+=fsdev/virtfs-proxy-helper.1
+endif
 else
 DOCS=
 endif
@@ -162,8 +164,10 @@ qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) 
$(block-obj-y)
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
+ifdef CONFIG_VIRTFS
 fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o 
fsdev/virtio-9p-marshal.o oslib-posix.o $(trace-obj-y)
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
+endif
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h  $  $@,  GEN  
 $@)
diff --git a/configure b/configure
index 763db24..081d720 100755
--- a/configure
+++ b/configure
@@ -121,6 +121,7 @@ docs=
 fdt=
 nptl=
 sdl=
+virtfs=yes
 vnc=yes
 sparse=no
 uuid=
@@ -586,6 +587,10 @@ for opt do
   ;;
   --enable-sdl) sdl=yes
   ;;
+  --disable-virtfs) virtfs=no
+  ;;
+  --enable-virtfs) virtfs=yes
+  ;;
   --disable-vnc) vnc=no
   ;;
   --enable-vnc) vnc=yes
@@ -993,6 +998,8 @@ echo   --disable-strip  disable stripping binaries
 echo   --disable-werror disable compilation abort on warning
 echo   --disable-sdldisable SDL
 echo   --enable-sdl enable SDL
+echo   --disable-virtfs disable VirtFS
+echo   --enable-virtfs  enable VirtFS
 echo   --disable-vncdisable VNC
 echo   --enable-vnc enable VNC
 echo   --enable-cocoa   enable COCOA (Mac OS X only)
@@ -2808,7 +2815,7 @@ confdir=$sysconfdir$confsuffix
 tools=
 if test $softmmu = yes ; then
   tools=qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools
-  if [ $cap = yes -a $linux = yes ] ; then
+  if [ $cap = yes -a $linux = yes -a $virtfs = yes ] ; then
   tools=$tools fsdev/virtfs-proxy-helper\$(EXESUF)
   fi
   if [ $linux = yes -o $bsd = yes -o $solaris = yes ] ; then
@@ -2874,6 +2881,7 @@ echo Audio drivers $audio_drv_list
 echo Extra audio cards $audio_card_list
 echo Block whitelist   $block_drv_whitelist
 echo Mixer emulation   $mixemu
+echo VirtFS support$virtfs
 echo VNC support   $vnc
 if test $vnc = yes ; then
 echo VNC TLS support   $vnc_tls
@@ -3164,8 +3172,10 @@ if test $libattr = yes ; then
   echo CONFIG_LIBATTR=y  $config_host_mak
 fi
 if test $linux = yes ; then
-  if test $attr = yes ; then
-echo CONFIG_VIRTFS=y  $config_host_mak
+  if test $virtfs = yes ; then
+if test $attr = yes ; then
+  echo CONFIG_VIRTFS=y  $config_host_mak
+fi
   fi
 fi
 if test $blobs = yes ; then
-- 
1.7.7.6




[Qemu-devel] QEMU build errors with 'fdopendir'

2012-02-03 Thread Meador Inge
Did these [1] builds errors ever get fixed?  I am running into one of them.  I
am building QEMU in an environment where 'fdopendir' is not present.
'fdopendir' was introduced in POSIX 2008 (and The Open Group Technical
Standard, 2006, Extended API Set Part 2.), so it may not be available in some
environments where QEMU is built.

[1] http://lists.nongnu.org/archive/html/qemu-devel/2011-12/msg00171.html

-- 
Meador Inge
CodeSourcery / Mentor Embedded
http://www.mentor.com/embedded-software