Add init_cmline and set boot_info->a0, a1
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
hw/loongarch/boot.c | 21 +++++++++++++++++++++
include/hw/loongarch/virt.h | 2 ++
target/loongarch/cpu.h | 2 ++
3 files changed, 25 insertions(+)
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 40796d97bd..b3fbed2ea0 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -14,6 +14,20 @@
#include "qemu/error-report.h"
#include "sysemu/reset.h"
+static int init_cmdline(struct loongarch_boot_info *info)
+{
+ hwaddr cmdline_addr;
+ cmdline_addr = 0xff00000ULL;
+
+ pstrcpy_targphys("cmdline", 0xff00000ULL,
+ COMMAND_LINE_SIZE, info->kernel_cmdline);
+
+ info->a0 = 1;
+ info->a1 = cmdline_addr;
+
+ return 0;
+}
+
static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
{
return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
@@ -60,6 +74,8 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
}
}
+ init_cmdline(info);
+
return kernel_entry;
}
@@ -70,6 +86,10 @@ static void reset_load_elf(void *opaque)
cpu_reset(CPU(cpu));
if (env->load_elf) {
+ if (cpu == LOONGARCH_CPU(first_cpu)) {
+ env->gpr[4] = env->boot_info->a0;
+ env->gpr[5] = env->boot_info->a1;
+ }
cpu_set_pc(CPU(cpu), env->elf_address);
}
}
@@ -121,6 +141,7 @@ static void loongarch_direct_kernel_boot(LoongArchMachineState *lams,
lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
lacpu->env.load_elf = true;
lacpu->env.elf_address = kernel_addr;
+ lacpu->env.boot_info = info;
}
}
}
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index e4126dd0e7..d21de2cef4 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -31,6 +31,8 @@
#define VIRT_GED_MEM_ADDR (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN)
#define VIRT_GED_REG_ADDR (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN)
+#define COMMAND_LINE_SIZE 512
+
struct LoongArchMachineState {
/*< private >*/
MachineState parent_obj;
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 00d1fba597..c7c695138e 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -362,6 +362,8 @@ typedef struct CPUArchState {
uint64_t elf_address;
/* Store ipistate to access from this struct */
DeviceState *ipistate;
+
+ struct loongarch_boot_info *boot_info;
#endif
} CPULoongArchState;
--
2.25.1