On 2023/12/18 下午5:00, Song Gao wrote:
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 2be6dfb037..4bfe24274a 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);
There are two places using 0xff00000ULL here, it had better be defined
as macro. Also can address for cmdline be before FDT base
address(0x100000) rather than strange value 0xff00000 ? -:)
+
+ 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);
@@ -63,6 +77,8 @@ static int64_t load_kernel_info(struct
loongarch_boot_info *info)
exit(1);
}
+ init_cmdline(info);
+
return kernel_entry;
}
@@ -73,6 +89,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);
}
}
@@ -129,6 +149,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
The macro COMMAND_LINE_SIZE is already defined in Linux header file,
maybe standard header file can be used.
/usr/include/asm-generic/setup.h
#define COMMAND_LINE_SIZE 512