* [PATCH] m68k: virt: correctly set the initial PC
@ 2021-05-04 13:18 Laurent Vivier
2021-05-04 14:13 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2021-05-04 13:18 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
Set initial PC to the entry of the loaded kernel.
This fixes kernel reboot with "-kernel" parameter.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
hw/m68k/virt.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e9a5d4c69b97..4fb3a7ebf0f2 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -88,14 +88,21 @@
#define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */
#define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */
+typedef struct {
+ M68kCPU *cpu;
+ hwaddr initial_pc;
+ hwaddr initial_stack;
+} ResetInfo;
+
static void main_cpu_reset(void *opaque)
{
- M68kCPU *cpu = opaque;
+ ResetInfo *reset_info = opaque;
+ M68kCPU *cpu = reset_info->cpu;
CPUState *cs = CPU(cpu);
cpu_reset(cs);
- cpu->env.aregs[7] = ldl_phys(cs->as, 0);
- cpu->env.pc = ldl_phys(cs->as, 4);
+ cpu->env.aregs[7] = reset_info->initial_stack;
+ cpu->env.pc = reset_info->initial_pc;
}
static void virt_init(MachineState *machine)
@@ -116,6 +123,7 @@ static void virt_init(MachineState *machine)
SysBusDevice *sysbus;
hwaddr io_base;
int i;
+ ResetInfo *reset_info;
if (ram_size > 3399672 * KiB) {
/*
@@ -127,9 +135,13 @@ static void virt_init(MachineState *machine)
exit(1);
}
+ reset_info = g_malloc0(sizeof(ResetInfo));
+
/* init CPUs */
cpu = M68K_CPU(cpu_create(machine->cpu_type));
- qemu_register_reset(main_cpu_reset, cpu);
+
+ reset_info->cpu = cpu;
+ qemu_register_reset(main_cpu_reset, reset_info);
/* RAM */
memory_region_add_subregion(get_system_memory(), 0, machine->ram);
@@ -209,7 +221,7 @@ static void virt_init(MachineState *machine)
error_report("could not load kernel '%s'", kernel_filename);
exit(1);
}
- stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
+ reset_info->initial_pc = elf_entry;
parameters_base = (high + 1) & ~1;
BOOTINFO1(cs->as, parameters_base, BI_MACHTYPE, MACH_VIRT);
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] m68k: virt: correctly set the initial PC
2021-05-04 13:18 [PATCH] m68k: virt: correctly set the initial PC Laurent Vivier
@ 2021-05-04 14:13 ` Philippe Mathieu-Daudé
2021-05-04 14:20 ` Laurent Vivier
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-04 14:13 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel
On 5/4/21 3:18 PM, Laurent Vivier wrote:
> Set initial PC to the entry of the loaded kernel.
>
> This fixes kernel reboot with "-kernel" parameter.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
> hw/m68k/virt.c | 22 +++++++++++++++++-----
> 1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
> index e9a5d4c69b97..4fb3a7ebf0f2 100644
> --- a/hw/m68k/virt.c
> +++ b/hw/m68k/virt.c
> @@ -88,14 +88,21 @@
> #define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */
> #define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */
>
> +typedef struct {
> + M68kCPU *cpu;
> + hwaddr initial_pc;
> + hwaddr initial_stack;
> +} ResetInfo;
> +
> static void main_cpu_reset(void *opaque)
> {
> - M68kCPU *cpu = opaque;
> + ResetInfo *reset_info = opaque;
> + M68kCPU *cpu = reset_info->cpu;
> CPUState *cs = CPU(cpu);
>
> cpu_reset(cs);
> - cpu->env.aregs[7] = ldl_phys(cs->as, 0);
> - cpu->env.pc = ldl_phys(cs->as, 4);
> + cpu->env.aregs[7] = reset_info->initial_stack;
> + cpu->env.pc = reset_info->initial_pc;
> }
>
> static void virt_init(MachineState *machine)
> @@ -116,6 +123,7 @@ static void virt_init(MachineState *machine)
> SysBusDevice *sysbus;
> hwaddr io_base;
> int i;
> + ResetInfo *reset_info;
>
> if (ram_size > 3399672 * KiB) {
> /*
> @@ -127,9 +135,13 @@ static void virt_init(MachineState *machine)
> exit(1);
> }
>
> + reset_info = g_malloc0(sizeof(ResetInfo));
> +
> /* init CPUs */
> cpu = M68K_CPU(cpu_create(machine->cpu_type));
> - qemu_register_reset(main_cpu_reset, cpu);
> +
> + reset_info->cpu = cpu;
> + qemu_register_reset(main_cpu_reset, reset_info);
>
> /* RAM */
> memory_region_add_subregion(get_system_memory(), 0, machine->ram);
> @@ -209,7 +221,7 @@ static void virt_init(MachineState *machine)
> error_report("could not load kernel '%s'", kernel_filename);
> exit(1);
> }
> - stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
> + reset_info->initial_pc = elf_entry;
Missing the stack?
reset_info->initial_stack = ldl_phys(cs->as, 0);
> parameters_base = (high + 1) & ~1;
>
> BOOTINFO1(cs->as, parameters_base, BI_MACHTYPE, MACH_VIRT);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] m68k: virt: correctly set the initial PC
2021-05-04 14:13 ` Philippe Mathieu-Daudé
@ 2021-05-04 14:20 ` Laurent Vivier
2021-05-04 14:30 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Vivier @ 2021-05-04 14:20 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Le 04/05/2021 à 16:13, Philippe Mathieu-Daudé a écrit :
> On 5/4/21 3:18 PM, Laurent Vivier wrote:
>> Set initial PC to the entry of the loaded kernel.
>>
>> This fixes kernel reboot with "-kernel" parameter.
>>
>> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
>> ---
>> hw/m68k/virt.c | 22 +++++++++++++++++-----
>> 1 file changed, 17 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
>> index e9a5d4c69b97..4fb3a7ebf0f2 100644
>> --- a/hw/m68k/virt.c
>> +++ b/hw/m68k/virt.c
>> @@ -88,14 +88,21 @@
>> #define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */
>> #define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */
>>
>> +typedef struct {
>> + M68kCPU *cpu;
>> + hwaddr initial_pc;
>> + hwaddr initial_stack;
>> +} ResetInfo;
>> +
>> static void main_cpu_reset(void *opaque)
>> {
>> - M68kCPU *cpu = opaque;
>> + ResetInfo *reset_info = opaque;
>> + M68kCPU *cpu = reset_info->cpu;
>> CPUState *cs = CPU(cpu);
>>
>> cpu_reset(cs);
>> - cpu->env.aregs[7] = ldl_phys(cs->as, 0);
>> - cpu->env.pc = ldl_phys(cs->as, 4);
>> + cpu->env.aregs[7] = reset_info->initial_stack;
>> + cpu->env.pc = reset_info->initial_pc;
>> }
>>
>> static void virt_init(MachineState *machine)
>> @@ -116,6 +123,7 @@ static void virt_init(MachineState *machine)
>> SysBusDevice *sysbus;
>> hwaddr io_base;
>> int i;
>> + ResetInfo *reset_info;
>>
>> if (ram_size > 3399672 * KiB) {
>> /*
>> @@ -127,9 +135,13 @@ static void virt_init(MachineState *machine)
>> exit(1);
>> }
>>
>> + reset_info = g_malloc0(sizeof(ResetInfo));
>> +
>> /* init CPUs */
>> cpu = M68K_CPU(cpu_create(machine->cpu_type));
>> - qemu_register_reset(main_cpu_reset, cpu);
>> +
>> + reset_info->cpu = cpu;
>> + qemu_register_reset(main_cpu_reset, reset_info);
>>
>> /* RAM */
>> memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>> @@ -209,7 +221,7 @@ static void virt_init(MachineState *machine)
>> error_report("could not load kernel '%s'", kernel_filename);
>> exit(1);
>> }
>> - stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
>> + reset_info->initial_pc = elf_entry;
> Missing the stack?
>
> reset_info->initial_stack = ldl_phys(cs->as, 0);
No, as it's a g_malloc0(), initial_stack is set to 0, so aregs[7] (SP) will be reset to 0 on reboot.
We could also set it to ram_size if we want something usable, but it's not needed for the kernel
entry point.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] m68k: virt: correctly set the initial PC
2021-05-04 14:20 ` Laurent Vivier
@ 2021-05-04 14:30 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-04 14:30 UTC (permalink / raw)
To: Laurent Vivier, qemu-devel
On 5/4/21 4:20 PM, Laurent Vivier wrote:
> Le 04/05/2021 à 16:13, Philippe Mathieu-Daudé a écrit :
>> On 5/4/21 3:18 PM, Laurent Vivier wrote:
>>> Set initial PC to the entry of the loaded kernel.
>>>
>>> This fixes kernel reboot with "-kernel" parameter.
>>>
>>> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
>>> ---
>>> hw/m68k/virt.c | 22 +++++++++++++++++-----
>>> 1 file changed, 17 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
>>> index e9a5d4c69b97..4fb3a7ebf0f2 100644
>>> --- a/hw/m68k/virt.c
>>> +++ b/hw/m68k/virt.c
>>> @@ -88,14 +88,21 @@
>>> #define VIRT_VIRTIO_MMIO_BASE 0xff010000 /* MMIO: 0xff010000 - 0xff01ffff */
>>> #define VIRT_VIRTIO_IRQ_BASE PIC_IRQ(2, 1) /* PIC: 2, 3, 4, 5, IRQ: ALL */
>>>
>>> +typedef struct {
>>> + M68kCPU *cpu;
>>> + hwaddr initial_pc;
>>> + hwaddr initial_stack;
>>> +} ResetInfo;
>>> +
>>> static void main_cpu_reset(void *opaque)
>>> {
>>> - M68kCPU *cpu = opaque;
>>> + ResetInfo *reset_info = opaque;
>>> + M68kCPU *cpu = reset_info->cpu;
>>> CPUState *cs = CPU(cpu);
>>>
>>> cpu_reset(cs);
>>> - cpu->env.aregs[7] = ldl_phys(cs->as, 0);
>>> - cpu->env.pc = ldl_phys(cs->as, 4);
>>> + cpu->env.aregs[7] = reset_info->initial_stack;
>>> + cpu->env.pc = reset_info->initial_pc;
>>> }
>>>
>>> static void virt_init(MachineState *machine)
>>> @@ -116,6 +123,7 @@ static void virt_init(MachineState *machine)
>>> SysBusDevice *sysbus;
>>> hwaddr io_base;
>>> int i;
>>> + ResetInfo *reset_info;
>>>
>>> if (ram_size > 3399672 * KiB) {
>>> /*
>>> @@ -127,9 +135,13 @@ static void virt_init(MachineState *machine)
>>> exit(1);
>>> }
>>>
>>> + reset_info = g_malloc0(sizeof(ResetInfo));
>>> +
>>> /* init CPUs */
>>> cpu = M68K_CPU(cpu_create(machine->cpu_type));
>>> - qemu_register_reset(main_cpu_reset, cpu);
>>> +
>>> + reset_info->cpu = cpu;
>>> + qemu_register_reset(main_cpu_reset, reset_info);
>>>
>>> /* RAM */
>>> memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>>> @@ -209,7 +221,7 @@ static void virt_init(MachineState *machine)
>>> error_report("could not load kernel '%s'", kernel_filename);
>>> exit(1);
>>> }
>>> - stl_phys(cs->as, 4, elf_entry); /* reset initial PC */
>>> + reset_info->initial_pc = elf_entry;
>> Missing the stack?
>>
>> reset_info->initial_stack = ldl_phys(cs->as, 0);
>
> No, as it's a g_malloc0(), initial_stack is set to 0, so aregs[7] (SP) will be reset to 0 on reboot.
> We could also set it to ram_size if we want something usable, but it's not needed for the kernel
> entry point.
Indeed I missed g_malloc*0*.
It would be clearer to use g_malloc() and explicitly set the initial
stack IMHO.
>
> Thanks,
>
> Laurent
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-04 14:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 13:18 [PATCH] m68k: virt: correctly set the initial PC Laurent Vivier
2021-05-04 14:13 ` Philippe Mathieu-Daudé
2021-05-04 14:20 ` Laurent Vivier
2021-05-04 14:30 ` Philippe Mathieu-Daudé
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.