[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 40/56] hw/sparc/leon3: check cpu_id in the tiny bootloader
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 40/56] hw/sparc/leon3: check cpu_id in the tiny bootloader |
Date: |
Thu, 15 Feb 2024 18:57:34 +0100 |
From: Clément Chigot <chigot@adacore.com>
Now that SMP is possible, the asr17 must be checked in the little boot
code or the secondary CPU will reinitialize the Timer and the Uart.
Co-developed-by: Frederic Konrad <konrad.frederic@yahoo.fr>
Signed-off-by: Clément Chigot <chigot@adacore.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240131085047.18458-9-chigot@adacore.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sparc/leon3.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 1637900162..bea84f3ad6 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -99,12 +99,26 @@ static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr,
uint32_t val)
/*
* When loading a kernel in RAM the machine is expected to be in a different
- * state (eg: initialized by the bootloader). This little code reproduces
- * this behavior.
+ * state (eg: initialized by the bootloader). This little code reproduces
+ * this behavior. Also this code can be executed by the secondary cpus as
+ * well since it looks at the %asr17 register before doing any
+ * initialization, it allows to use the same reset address for all the
+ * cpus.
*/
static void write_bootloader(void *ptr, hwaddr kernel_addr)
{
uint32_t *p = ptr;
+ uint32_t *sec_cpu_branch_p = NULL;
+
+ /* If we are running on a secondary CPU, jump directly to the kernel. */
+
+ stl_p(p++, 0x85444000); /* rd %asr17, %g2 */
+ stl_p(p++, 0x8530a01c); /* srl %g2, 0x1c, %g2 */
+ stl_p(p++, 0x80908000); /* tst %g2 */
+ /* Filled below. */
+ sec_cpu_branch_p = p;
+ stl_p(p++, 0x0BADC0DE); /* bne xxx */
+ stl_p(p++, 0x01000000); /* nop */
/* Initialize the UARTs */
/* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
@@ -118,6 +132,10 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
/* *GPTIMER0_CONFIG = GPTIMER_ENABLE | GPTIMER_RESTART; */
p = gen_store_u32(p, 0x80000318, 3);
+ /* Now, the relative branch above can be computed. */
+ stl_p(sec_cpu_branch_p, 0x12800000
+ + (p - sec_cpu_branch_p));
+
/* JUMP to the entry point */
stl_p(p++, 0x82100000); /* mov %g0, %g1 */
stl_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
--
2.41.0
- [PULL 29/56] target/sparc: Provide hint about CPUSPARCState::irq_manager member, (continued)
- [PULL 29/56] target/sparc: Provide hint about CPUSPARCState::irq_manager member, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 30/56] hw/sparc/leon3: Remove duplicate code, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 32/56] hw/sparc/leon3: Have write_bootloader() take a void pointer argument, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 31/56] hw/sparc/leon3: Remove unused 'env' argument of write_bootloader(), Philippe Mathieu-Daudé, 2024/02/15
- [PULL 33/56] hw/sparc/grlib: split out the headers for each peripherals, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 36/56] hw/intc/grlib_irqmp: implements multicore irq, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 35/56] hw/intc/grlib_irqmp: implements the multiprocessor status register, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 37/56] target/sparc: implement asr17 feature for smp, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 34/56] hw/intc/grlib_irqmp: add ncpus property, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 38/56] hw/sparc/leon3: remove SP initialization, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 40/56] hw/sparc/leon3: check cpu_id in the tiny bootloader,
Philippe Mathieu-Daudé <=
- [PULL 41/56] hw/sparc/leon3: Pass DeviceState opaque argument to leon3_set_pil_in(), Philippe Mathieu-Daudé, 2024/02/15
- [PULL 39/56] hw/sparc/leon3: implement multiprocessor, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 42/56] hw/sparc/leon3: Pass DeviceState opaque argument to leon3_start_cpu(), Philippe Mathieu-Daudé, 2024/02/15
- [PULL 43/56] hw/sparc/leon3: Initialize GPIO before realizing CPU devices, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 45/56] MAINTAINERS: Add myself as reviewer for TCG Plugins, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 44/56] MAINTAINERS: replace Fabien by myself as Leon3 maintainer, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 47/56] hw/i386/q35: Use DEVICE() cast macro with PCIDevice object, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 48/56] hw/ide/ahci: Expose AHCIPCIState structure, Philippe Mathieu-Daudé, 2024/02/15
- [PULL 49/56] hw/ide/ahci: Rename AHCI PCI function as 'pdev', Philippe Mathieu-Daudé, 2024/02/15
- [PULL 50/56] hw/ide/ahci: Inline ahci_get_num_ports(), Philippe Mathieu-Daudé, 2024/02/15