All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine
@ 2021-04-27 19:26 Philippe Mathieu-Daudé
  2021-04-27 19:26 ` [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-27 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Mark Cave-Ayland, Richard Henderson,
	Philippe Mathieu-Daudé,
	Fabien Chouteau, KONRAD Frederic, Artyom Tarasenko

This series fixes link failure when building either the leon3
machine or the sun4m ones.

The problem is we have hardware specific code in the architectural
translation code. Move this code to hw/sparc/.

The link failures can be reproduced doing:

  $ echo CONFIG_LEON3=y > default-configs/devices/sparc-softmmu.mak
  $ configure --without-default-devices
  $ ninja qemu-system-sparc
  $ ./qemu-system-sparc -M leon3 -S

or:

  $ echo CONFIG_SUN4M=y > default-configs/devices/sparc-softmmu.mak

Philippe Mathieu-Daudé (2):
  hw/sparc: Allow building the leon3 machine stand-alone
  hw/sparc: Allow building without the leon3 machine

 target/sparc/cpu.h          |  6 ----
 hw/sparc/irq.c              | 61 +++++++++++++++++++++++++++++++++++++
 hw/sparc/leon3.c            | 37 +++++++++++++++++++++-
 hw/sparc/sun4m.c            | 32 -------------------
 target/sparc/int32_helper.c | 37 ----------------------
 hw/sparc/meson.build        |  1 +
 hw/sparc/trace-events       |  2 ++
 target/sparc/trace-events   |  4 ---
 8 files changed, 100 insertions(+), 80 deletions(-)
 create mode 100644 hw/sparc/irq.c

-- 
2.26.3



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone
  2021-04-27 19:26 [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine Philippe Mathieu-Daudé
@ 2021-04-27 19:26 ` Philippe Mathieu-Daudé
  2021-04-28  0:11   ` Richard Henderson
  2021-04-27 19:26 ` [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-27 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Mark Cave-Ayland, Richard Henderson,
	Philippe Mathieu-Daudé,
	Fabien Chouteau, KONRAD Frederic, Artyom Tarasenko

When building only the leon3 machine, we get this link failure:

  /usr/bin/ld: target_sparc_win_helper.c.o: in function `cpu_put_psr':
  target/sparc/win_helper.c:91: undefined reference to `cpu_check_irqs'

This is because cpu_check_irqs() is defined in hw/sparc/sun4m.c,
which is only built if the base sun4m machines are built (with
the CONFIG_SUN4M selector).

Fix by moving cpu_check_irqs() out of hw/sparc/sun4m.c and build
it unconditionally.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/sparc/irq.c       | 61 ++++++++++++++++++++++++++++++++++++++++++++
 hw/sparc/sun4m.c     | 32 -----------------------
 hw/sparc/meson.build |  1 +
 3 files changed, 62 insertions(+), 32 deletions(-)
 create mode 100644 hw/sparc/irq.c

diff --git a/hw/sparc/irq.c b/hw/sparc/irq.c
new file mode 100644
index 00000000000..e34639f266e
--- /dev/null
+++ b/hw/sparc/irq.c
@@ -0,0 +1,61 @@
+/*
+ * QEMU Sun4m & Sun4d & Sun4c IRQ handling
+ *
+ * Copyright (c) 2003-2005 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/main-loop.h"
+#include "hw/irq.h"
+#include "cpu.h"
+#include "trace.h"
+
+void cpu_check_irqs(CPUSPARCState *env)
+{
+    CPUState *cs;
+
+    /* We should be holding the BQL before we mess with IRQs */
+    g_assert(qemu_mutex_iothread_locked());
+
+    if (env->pil_in && (env->interrupt_index == 0 ||
+                        (env->interrupt_index & ~15) == TT_EXTINT)) {
+        unsigned int i;
+
+        for (i = 15; i > 0; i--) {
+            if (env->pil_in & (1 << i)) {
+                int old_interrupt = env->interrupt_index;
+
+                env->interrupt_index = TT_EXTINT | i;
+                if (old_interrupt != env->interrupt_index) {
+                    cs = env_cpu(env);
+                    trace_sun4m_cpu_interrupt(i);
+                    cpu_interrupt(cs, CPU_INTERRUPT_HARD);
+                }
+                break;
+            }
+        }
+    } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
+        cs = env_cpu(env);
+        trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
+        env->interrupt_index = 0;
+        cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
+    }
+}
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 1a00816d9a8..2edf913d945 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -159,38 +159,6 @@ static void nvram_init(Nvram *nvram, uint8_t *macaddr,
     }
 }
 
-void cpu_check_irqs(CPUSPARCState *env)
-{
-    CPUState *cs;
-
-    /* We should be holding the BQL before we mess with IRQs */
-    g_assert(qemu_mutex_iothread_locked());
-
-    if (env->pil_in && (env->interrupt_index == 0 ||
-                        (env->interrupt_index & ~15) == TT_EXTINT)) {
-        unsigned int i;
-
-        for (i = 15; i > 0; i--) {
-            if (env->pil_in & (1 << i)) {
-                int old_interrupt = env->interrupt_index;
-
-                env->interrupt_index = TT_EXTINT | i;
-                if (old_interrupt != env->interrupt_index) {
-                    cs = env_cpu(env);
-                    trace_sun4m_cpu_interrupt(i);
-                    cpu_interrupt(cs, CPU_INTERRUPT_HARD);
-                }
-                break;
-            }
-        }
-    } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
-        cs = env_cpu(env);
-        trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
-        env->interrupt_index = 0;
-        cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
-    }
-}
-
 static void cpu_kick_irq(SPARCCPU *cpu)
 {
     CPUSPARCState *env = &cpu->env;
diff --git a/hw/sparc/meson.build b/hw/sparc/meson.build
index 19c442c90d9..470159ff659 100644
--- a/hw/sparc/meson.build
+++ b/hw/sparc/meson.build
@@ -1,4 +1,5 @@
 sparc_ss = ss.source_set()
+sparc_ss.add(files('irq.c'))
 sparc_ss.add(when: 'CONFIG_LEON3', if_true: files('leon3.c'))
 sparc_ss.add(when: 'CONFIG_SUN4M', if_true: files('sun4m.c'))
 sparc_ss.add(when: 'CONFIG_SUN4M', if_true: files('sun4m_iommu.c'))
-- 
2.26.3



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine
  2021-04-27 19:26 [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine Philippe Mathieu-Daudé
  2021-04-27 19:26 ` [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone Philippe Mathieu-Daudé
@ 2021-04-27 19:26 ` Philippe Mathieu-Daudé
  2021-04-28  0:07   ` Richard Henderson
  2021-04-28  9:21   ` Fred Konrad
  2021-04-28  8:40 ` [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without " Mark Cave-Ayland
  2021-04-28  9:05 ` Fred Konrad
  3 siblings, 2 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-04-27 19:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Mark Cave-Ayland, Richard Henderson,
	Philippe Mathieu-Daudé,
	Fabien Chouteau, KONRAD Frederic, Artyom Tarasenko

When building without the leon3 machine, we get this link failure:

  /usr/bin/ld: target_sparc_int32_helper.c.o: in function `leon3_irq_manager':
  target/sparc/int32_helper.c:172: undefined reference to `leon3_irq_ack'

This is because the leon3_irq_ack() is declared in hw/sparc/leon3.c,
which is only build when CONFIG_LEON3 is selected.

Fix by moving the leon3_cache_control_int() / leon3_irq_manager()
(which are specific to the leon3 machine) to hw/sparc/leon3.c.
Move the trace events along (but don't rename them).

leon3_irq_ack() is now locally used, declare it static to reduce
its scope.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
RFC: The problem is we have hardware specific code in the
architectural translation code. I wish there was a better
alternative rather than moving this code to hw/sparc/.
---
 target/sparc/cpu.h          |  6 ------
 hw/sparc/leon3.c            | 37 ++++++++++++++++++++++++++++++++++++-
 target/sparc/int32_helper.c | 37 -------------------------------------
 hw/sparc/trace-events       |  2 ++
 target/sparc/trace-events   |  4 ----
 5 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 4b2290650be..ff8ae73002a 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -615,15 +615,9 @@ int cpu_cwp_inc(CPUSPARCState *env1, int cwp);
 int cpu_cwp_dec(CPUSPARCState *env1, int cwp);
 void cpu_set_cwp(CPUSPARCState *env1, int new_cwp);
 
-/* int_helper.c */
-void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno);
-
 /* sun4m.c, sun4u.c */
 void cpu_check_irqs(CPUSPARCState *env);
 
-/* leon3.c */
-void leon3_irq_ack(void *irq_manager, int intno);
-
 #if defined (TARGET_SPARC64)
 
 static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 7e16eea9e67..98e3789cf84 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -137,7 +137,36 @@ static void main_cpu_reset(void *opaque)
     env->regbase[6] = s->sp;
 }
 
-void leon3_irq_ack(void *irq_manager, int intno)
+static void leon3_cache_control_int(CPUSPARCState *env)
+{
+    uint32_t state = 0;
+
+    if (env->cache_control & CACHE_CTRL_IF) {
+        /* Instruction cache state */
+        state = env->cache_control & CACHE_STATE_MASK;
+        if (state == CACHE_ENABLED) {
+            state = CACHE_FROZEN;
+            trace_int_helper_icache_freeze();
+        }
+
+        env->cache_control &= ~CACHE_STATE_MASK;
+        env->cache_control |= state;
+    }
+
+    if (env->cache_control & CACHE_CTRL_DF) {
+        /* Data cache state */
+        state = (env->cache_control >> 2) & CACHE_STATE_MASK;
+        if (state == CACHE_ENABLED) {
+            state = CACHE_FROZEN;
+            trace_int_helper_dcache_freeze();
+        }
+
+        env->cache_control &= ~(CACHE_STATE_MASK << 2);
+        env->cache_control |= (state << 2);
+    }
+}
+
+static void leon3_irq_ack(void *irq_manager, int intno)
 {
     grlib_irqmp_ack((DeviceState *)irq_manager, intno);
 }
@@ -181,6 +210,12 @@ static void leon3_set_pil_in(void *opaque, int n, int level)
     }
 }
 
+static void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
+{
+    leon3_irq_ack(irq_manager, intno);
+    leon3_cache_control_int(env);
+}
+
 static void leon3_generic_hw_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
diff --git a/target/sparc/int32_helper.c b/target/sparc/int32_helper.c
index 817a463a179..d008dbdb65c 100644
--- a/target/sparc/int32_helper.c
+++ b/target/sparc/int32_helper.c
@@ -136,40 +136,3 @@ void sparc_cpu_do_interrupt(CPUState *cs)
     }
 #endif
 }
-
-#if !defined(CONFIG_USER_ONLY)
-static void leon3_cache_control_int(CPUSPARCState *env)
-{
-    uint32_t state = 0;
-
-    if (env->cache_control & CACHE_CTRL_IF) {
-        /* Instruction cache state */
-        state = env->cache_control & CACHE_STATE_MASK;
-        if (state == CACHE_ENABLED) {
-            state = CACHE_FROZEN;
-            trace_int_helper_icache_freeze();
-        }
-
-        env->cache_control &= ~CACHE_STATE_MASK;
-        env->cache_control |= state;
-    }
-
-    if (env->cache_control & CACHE_CTRL_DF) {
-        /* Data cache state */
-        state = (env->cache_control >> 2) & CACHE_STATE_MASK;
-        if (state == CACHE_ENABLED) {
-            state = CACHE_FROZEN;
-            trace_int_helper_dcache_freeze();
-        }
-
-        env->cache_control &= ~(CACHE_STATE_MASK << 2);
-        env->cache_control |= (state << 2);
-    }
-}
-
-void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
-{
-    leon3_irq_ack(irq_manager, intno);
-    leon3_cache_control_int(env);
-}
-#endif
diff --git a/hw/sparc/trace-events b/hw/sparc/trace-events
index 355b07ae057..dfb53dc1a24 100644
--- a/hw/sparc/trace-events
+++ b/hw/sparc/trace-events
@@ -19,3 +19,5 @@ sun4m_iommu_bad_addr(uint64_t addr) "bad addr 0x%"PRIx64
 # leon3.c
 leon3_set_irq(int intno) "Set CPU IRQ %d"
 leon3_reset_irq(int intno) "Reset CPU IRQ %d"
+int_helper_icache_freeze(void) "Instruction cache: freeze"
+int_helper_dcache_freeze(void) "Data cache: freeze"
diff --git a/target/sparc/trace-events b/target/sparc/trace-events
index 6a064e23275..e925ddd1cc0 100644
--- a/target/sparc/trace-events
+++ b/target/sparc/trace-events
@@ -15,10 +15,6 @@ int_helper_set_softint(uint32_t softint) "new 0x%08x"
 int_helper_clear_softint(uint32_t softint) "new 0x%08x"
 int_helper_write_softint(uint32_t softint) "new 0x%08x"
 
-# int32_helper.c
-int_helper_icache_freeze(void) "Instruction cache: freeze"
-int_helper_dcache_freeze(void) "Data cache: freeze"
-
 # win_helper.c
 win_helper_gregset_error(uint32_t pstate) "ERROR in get_gregset: active pstate bits=0x%x"
 win_helper_switch_pstate(uint32_t pstate_regs, uint32_t new_pstate_regs) "change_pstate: switching regs old=0x%x new=0x%x"
-- 
2.26.3



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine
  2021-04-27 19:26 ` [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine Philippe Mathieu-Daudé
@ 2021-04-28  0:07   ` Richard Henderson
  2021-04-28  9:21   ` Fred Konrad
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2021-04-28  0:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Fabien Chouteau, Thomas Huth, Mark Cave-Ayland, KONRAD Frederic,
	Artyom Tarasenko

On 4/27/21 12:26 PM, Philippe Mathieu-Daudé wrote:
> When building without the leon3 machine, we get this link failure:
> 
>    /usr/bin/ld: target_sparc_int32_helper.c.o: in function `leon3_irq_manager':
>    target/sparc/int32_helper.c:172: undefined reference to `leon3_irq_ack'
> 
> This is because the leon3_irq_ack() is declared in hw/sparc/leon3.c,
> which is only build when CONFIG_LEON3 is selected.
> 
> Fix by moving the leon3_cache_control_int() / leon3_irq_manager()
> (which are specific to the leon3 machine) to hw/sparc/leon3.c.
> Move the trace events along (but don't rename them).
> 
> leon3_irq_ack() is now locally used, declare it static to reduce
> its scope.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
> RFC: The problem is we have hardware specific code in the
> architectural translation code. I wish there was a better
> alternative rather than moving this code to hw/sparc/.
> ---

This one seems dead obvious.  I think this code should have been in 
hw/sparc/leon3.c to begin with.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone
  2021-04-27 19:26 ` [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone Philippe Mathieu-Daudé
@ 2021-04-28  0:11   ` Richard Henderson
  2021-04-28  8:38     ` Mark Cave-Ayland
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Henderson @ 2021-04-28  0:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Fabien Chouteau, Thomas Huth, Mark Cave-Ayland, KONRAD Frederic,
	Artyom Tarasenko

On 4/27/21 12:26 PM, Philippe Mathieu-Daudé wrote:
> When building only the leon3 machine, we get this link failure:
> 
>    /usr/bin/ld: target_sparc_win_helper.c.o: in function `cpu_put_psr':
>    target/sparc/win_helper.c:91: undefined reference to `cpu_check_irqs'
> 
> This is because cpu_check_irqs() is defined in hw/sparc/sun4m.c,
> which is only built if the base sun4m machines are built (with
> the CONFIG_SUN4M selector).
> 
> Fix by moving cpu_check_irqs() out of hw/sparc/sun4m.c and build
> it unconditionally.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   hw/sparc/irq.c       | 61 ++++++++++++++++++++++++++++++++++++++++++++
>   hw/sparc/sun4m.c     | 32 -----------------------
>   hw/sparc/meson.build |  1 +
>   3 files changed, 62 insertions(+), 32 deletions(-)
>   create mode 100644 hw/sparc/irq.c

I think this code should be in target/sparc/.  There doesn't seem to be any 
reference to anything outside CPUSPARCState.


r~


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone
  2021-04-28  0:11   ` Richard Henderson
@ 2021-04-28  8:38     ` Mark Cave-Ayland
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Cave-Ayland @ 2021-04-28  8:38 UTC (permalink / raw)
  To: Richard Henderson, Philippe Mathieu-Daudé, qemu-devel
  Cc: Thomas Huth, KONRAD Frederic, Fabien Chouteau, Artyom Tarasenko

On 28/04/2021 01:11, Richard Henderson wrote:

> On 4/27/21 12:26 PM, Philippe Mathieu-Daudé wrote:
>> When building only the leon3 machine, we get this link failure:
>>
>>    /usr/bin/ld: target_sparc_win_helper.c.o: in function `cpu_put_psr':
>>    target/sparc/win_helper.c:91: undefined reference to `cpu_check_irqs'
>>
>> This is because cpu_check_irqs() is defined in hw/sparc/sun4m.c,
>> which is only built if the base sun4m machines are built (with
>> the CONFIG_SUN4M selector).
>>
>> Fix by moving cpu_check_irqs() out of hw/sparc/sun4m.c and build
>> it unconditionally.
>>
>> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
>> ---
>>   hw/sparc/irq.c       | 61 ++++++++++++++++++++++++++++++++++++++++++++
>>   hw/sparc/sun4m.c     | 32 -----------------------
>>   hw/sparc/meson.build |  1 +
>>   3 files changed, 62 insertions(+), 32 deletions(-)
>>   create mode 100644 hw/sparc/irq.c
> 
> I think this code should be in target/sparc/.  There doesn't seem to be any reference 
> to anything outside CPUSPARCState.

I suspect that this is based upon the existing precedent set by SPARC64 where the IRQ 
routines are stored in hw/sparc64/sparc64.c. I'd lean towards the current approach 
for now so that both 32-bit and 64-bit could be moved into target/sparc as a separate 
exercise for consistency.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine
  2021-04-27 19:26 [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine Philippe Mathieu-Daudé
  2021-04-27 19:26 ` [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone Philippe Mathieu-Daudé
  2021-04-27 19:26 ` [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine Philippe Mathieu-Daudé
@ 2021-04-28  8:40 ` Mark Cave-Ayland
  2021-04-28  9:05 ` Fred Konrad
  3 siblings, 0 replies; 9+ messages in thread
From: Mark Cave-Ayland @ 2021-04-28  8:40 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Thomas Huth, Richard Henderson, KONRAD Frederic, Fabien Chouteau,
	Artyom Tarasenko

On 27/04/2021 20:26, Philippe Mathieu-Daudé wrote:

> This series fixes link failure when building either the leon3
> machine or the sun4m ones.
> 
> The problem is we have hardware specific code in the architectural
> translation code. Move this code to hw/sparc/.
> 
> The link failures can be reproduced doing:
> 
>    $ echo CONFIG_LEON3=y > default-configs/devices/sparc-softmmu.mak
>    $ configure --without-default-devices
>    $ ninja qemu-system-sparc
>    $ ./qemu-system-sparc -M leon3 -S
> 
> or:
> 
>    $ echo CONFIG_SUN4M=y > default-configs/devices/sparc-softmmu.mak
> 
> Philippe Mathieu-Daudé (2):
>    hw/sparc: Allow building the leon3 machine stand-alone
>    hw/sparc: Allow building without the leon3 machine
> 
>   target/sparc/cpu.h          |  6 ----
>   hw/sparc/irq.c              | 61 +++++++++++++++++++++++++++++++++++++
>   hw/sparc/leon3.c            | 37 +++++++++++++++++++++-
>   hw/sparc/sun4m.c            | 32 -------------------
>   target/sparc/int32_helper.c | 37 ----------------------
>   hw/sparc/meson.build        |  1 +
>   hw/sparc/trace-events       |  2 ++
>   target/sparc/trace-events   |  4 ---
>   8 files changed, 100 insertions(+), 80 deletions(-)
>   create mode 100644 hw/sparc/irq.c

Just one comment from me but other than that seems fine: if Frederic and/or Fabien 
could give a R-B tag then I'm happy to queue it via qemu-sparc.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine
  2021-04-27 19:26 [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2021-04-28  8:40 ` [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without " Mark Cave-Ayland
@ 2021-04-28  9:05 ` Fred Konrad
  3 siblings, 0 replies; 9+ messages in thread
From: Fred Konrad @ 2021-04-28  9:05 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Thomas Huth, Mark Cave-Ayland, Richard Henderson,
	Fabien Chouteau, KONRAD Frederic, Artyom Tarasenko



Le 4/27/21 à 9:26 PM, Philippe Mathieu-Daudé a écrit :
> This series fixes link failure when building either the leon3
> machine or the sun4m ones.
> 
> The problem is we have hardware specific code in the architectural
> translation code. Move this code to hw/sparc/.
> 
> The link failures can be reproduced doing:
> 
>    $ echo CONFIG_LEON3=y > default-configs/devices/sparc-softmmu.mak
>    $ configure --without-default-devices
>    $ ninja qemu-system-sparc

Indeed:

libqemu-sparc-softmmu.fa.p/target_sparc_win_helper.c.o: \
In function `cpu_put_psr':
xxx/qemu/build/../target/sparc/win_helper.c:91: \
   undefined reference to `cpu_check_irqs'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

>    $ ./qemu-system-sparc -M leon3 -S
> 
> or:
> 
>    $ echo CONFIG_SUN4M=y > default-configs/devices/sparc-softmmu.mak
> 
> Philippe Mathieu-Daudé (2):
>    hw/sparc: Allow building the leon3 machine stand-alone
>    hw/sparc: Allow building without the leon3 machine
> 
>   target/sparc/cpu.h          |  6 ----
>   hw/sparc/irq.c              | 61 +++++++++++++++++++++++++++++++++++++
>   hw/sparc/leon3.c            | 37 +++++++++++++++++++++-
>   hw/sparc/sun4m.c            | 32 -------------------
>   target/sparc/int32_helper.c | 37 ----------------------
>   hw/sparc/meson.build        |  1 +
>   hw/sparc/trace-events       |  2 ++
>   target/sparc/trace-events   |  4 ---
>   8 files changed, 100 insertions(+), 80 deletions(-)
>   create mode 100644 hw/sparc/irq.c
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine
  2021-04-27 19:26 ` [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine Philippe Mathieu-Daudé
  2021-04-28  0:07   ` Richard Henderson
@ 2021-04-28  9:21   ` Fred Konrad
  1 sibling, 0 replies; 9+ messages in thread
From: Fred Konrad @ 2021-04-28  9:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Thomas Huth, Mark Cave-Ayland, Richard Henderson,
	Fabien Chouteau, KONRAD Frederic, Artyom Tarasenko

Hi Philippe,

Le 4/27/21 à 9:26 PM, Philippe Mathieu-Daudé a écrit :
> When building without the leon3 machine, we get this link failure:
> 
>    /usr/bin/ld: target_sparc_int32_helper.c.o: in function `leon3_irq_manager':
>    target/sparc/int32_helper.c:172: undefined reference to `leon3_irq_ack'
> 
> This is because the leon3_irq_ack() is declared in hw/sparc/leon3.c,
> which is only build when CONFIG_LEON3 is selected.
> 
> Fix by moving the leon3_cache_control_int() / leon3_irq_manager()
> (which are specific to the leon3 machine) to hw/sparc/leon3.c.
> Move the trace events along (but don't rename them).
> 
> leon3_irq_ack() is now locally used, declare it static to reduce
> its scope.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Reviewed-by: KONRAD Frederic <frederic.konrad@adacore.com>
Tested-by: KONRAD Frederic <frederic.konrad@adacore.com>

Thanks for the fix!

> ---
> RFC: The problem is we have hardware specific code in the
> architectural translation code. I wish there was a better
> alternative rather than moving this code to hw/sparc/.
> ---
>   target/sparc/cpu.h          |  6 ------
>   hw/sparc/leon3.c            | 37 ++++++++++++++++++++++++++++++++++++-
>   target/sparc/int32_helper.c | 37 -------------------------------------
>   hw/sparc/trace-events       |  2 ++
>   target/sparc/trace-events   |  4 ----
>   5 files changed, 38 insertions(+), 48 deletions(-)
> 
> diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
> index 4b2290650be..ff8ae73002a 100644
> --- a/target/sparc/cpu.h
> +++ b/target/sparc/cpu.h
> @@ -615,15 +615,9 @@ int cpu_cwp_inc(CPUSPARCState *env1, int cwp);
>   int cpu_cwp_dec(CPUSPARCState *env1, int cwp);
>   void cpu_set_cwp(CPUSPARCState *env1, int new_cwp);
>   
> -/* int_helper.c */
> -void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno);
> -
>   /* sun4m.c, sun4u.c */
>   void cpu_check_irqs(CPUSPARCState *env);
>   
> -/* leon3.c */
> -void leon3_irq_ack(void *irq_manager, int intno);
> -
>   #if defined (TARGET_SPARC64)
>   
>   static inline int compare_masked(uint64_t x, uint64_t y, uint64_t mask)
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index 7e16eea9e67..98e3789cf84 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -137,7 +137,36 @@ static void main_cpu_reset(void *opaque)
>       env->regbase[6] = s->sp;
>   }
>   
> -void leon3_irq_ack(void *irq_manager, int intno)
> +static void leon3_cache_control_int(CPUSPARCState *env)
> +{
> +    uint32_t state = 0;
> +
> +    if (env->cache_control & CACHE_CTRL_IF) {
> +        /* Instruction cache state */
> +        state = env->cache_control & CACHE_STATE_MASK;
> +        if (state == CACHE_ENABLED) {
> +            state = CACHE_FROZEN;
> +            trace_int_helper_icache_freeze();
> +        }
> +
> +        env->cache_control &= ~CACHE_STATE_MASK;
> +        env->cache_control |= state;
> +    }
> +
> +    if (env->cache_control & CACHE_CTRL_DF) {
> +        /* Data cache state */
> +        state = (env->cache_control >> 2) & CACHE_STATE_MASK;
> +        if (state == CACHE_ENABLED) {
> +            state = CACHE_FROZEN;
> +            trace_int_helper_dcache_freeze();
> +        }
> +
> +        env->cache_control &= ~(CACHE_STATE_MASK << 2);
> +        env->cache_control |= (state << 2);
> +    }
> +}
> +
> +static void leon3_irq_ack(void *irq_manager, int intno)
>   {
>       grlib_irqmp_ack((DeviceState *)irq_manager, intno);
>   }
> @@ -181,6 +210,12 @@ static void leon3_set_pil_in(void *opaque, int n, int level)
>       }
>   }
>   
> +static void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
> +{
> +    leon3_irq_ack(irq_manager, intno);
> +    leon3_cache_control_int(env);
> +}
> +
>   static void leon3_generic_hw_init(MachineState *machine)
>   {
>       ram_addr_t ram_size = machine->ram_size;
> diff --git a/target/sparc/int32_helper.c b/target/sparc/int32_helper.c
> index 817a463a179..d008dbdb65c 100644
> --- a/target/sparc/int32_helper.c
> +++ b/target/sparc/int32_helper.c
> @@ -136,40 +136,3 @@ void sparc_cpu_do_interrupt(CPUState *cs)
>       }
>   #endif
>   }
> -
> -#if !defined(CONFIG_USER_ONLY)
> -static void leon3_cache_control_int(CPUSPARCState *env)
> -{
> -    uint32_t state = 0;
> -
> -    if (env->cache_control & CACHE_CTRL_IF) {
> -        /* Instruction cache state */
> -        state = env->cache_control & CACHE_STATE_MASK;
> -        if (state == CACHE_ENABLED) {
> -            state = CACHE_FROZEN;
> -            trace_int_helper_icache_freeze();
> -        }
> -
> -        env->cache_control &= ~CACHE_STATE_MASK;
> -        env->cache_control |= state;
> -    }
> -
> -    if (env->cache_control & CACHE_CTRL_DF) {
> -        /* Data cache state */
> -        state = (env->cache_control >> 2) & CACHE_STATE_MASK;
> -        if (state == CACHE_ENABLED) {
> -            state = CACHE_FROZEN;
> -            trace_int_helper_dcache_freeze();
> -        }
> -
> -        env->cache_control &= ~(CACHE_STATE_MASK << 2);
> -        env->cache_control |= (state << 2);
> -    }
> -}
> -
> -void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
> -{
> -    leon3_irq_ack(irq_manager, intno);
> -    leon3_cache_control_int(env);
> -}
> -#endif
> diff --git a/hw/sparc/trace-events b/hw/sparc/trace-events
> index 355b07ae057..dfb53dc1a24 100644
> --- a/hw/sparc/trace-events
> +++ b/hw/sparc/trace-events
> @@ -19,3 +19,5 @@ sun4m_iommu_bad_addr(uint64_t addr) "bad addr 0x%"PRIx64
>   # leon3.c
>   leon3_set_irq(int intno) "Set CPU IRQ %d"
>   leon3_reset_irq(int intno) "Reset CPU IRQ %d"
> +int_helper_icache_freeze(void) "Instruction cache: freeze"
> +int_helper_dcache_freeze(void) "Data cache: freeze"
> diff --git a/target/sparc/trace-events b/target/sparc/trace-events
> index 6a064e23275..e925ddd1cc0 100644
> --- a/target/sparc/trace-events
> +++ b/target/sparc/trace-events
> @@ -15,10 +15,6 @@ int_helper_set_softint(uint32_t softint) "new 0x%08x"
>   int_helper_clear_softint(uint32_t softint) "new 0x%08x"
>   int_helper_write_softint(uint32_t softint) "new 0x%08x"
>   
> -# int32_helper.c
> -int_helper_icache_freeze(void) "Instruction cache: freeze"
> -int_helper_dcache_freeze(void) "Data cache: freeze"
> -
>   # win_helper.c
>   win_helper_gregset_error(uint32_t pstate) "ERROR in get_gregset: active pstate bits=0x%x"
>   win_helper_switch_pstate(uint32_t pstate_regs, uint32_t new_pstate_regs) "change_pstate: switching regs old=0x%x new=0x%x"
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-28  9:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27 19:26 [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without the leon3 machine Philippe Mathieu-Daudé
2021-04-27 19:26 ` [PATCH 1/2] hw/sparc: Allow building the leon3 machine stand-alone Philippe Mathieu-Daudé
2021-04-28  0:11   ` Richard Henderson
2021-04-28  8:38     ` Mark Cave-Ayland
2021-04-27 19:26 ` [RFC PATCH 2/2] hw/sparc: Allow building without the leon3 machine Philippe Mathieu-Daudé
2021-04-28  0:07   ` Richard Henderson
2021-04-28  9:21   ` Fred Konrad
2021-04-28  8:40 ` [PATCH 0/2] hw/sparc: Kconfig fixes to build with/without " Mark Cave-Ayland
2021-04-28  9:05 ` Fred Konrad

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.