qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] null-machine: Add support for the "-kernel" par


From: Thomas Huth
Subject: Re: [Qemu-devel] [PATCH] null-machine: Add support for the "-kernel" parameter
Date: Wed, 25 Jan 2017 17:04:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

On 25.01.2017 15:42, Laurent Vivier wrote:
> Le 25/01/2017 à 09:40, Thomas Huth a écrit :
>> We can have basic support for the "-kernel" parameter quite easily
>> by using the generic loader device. This should be enough for most
>> boards which do not need special machine-specific magic for loading
>> a kernel (and for those that need special magic, the generic "none"
>> machine is likely not suitable for using it as an instruction set
>> simulator board anyway).
>>
>> Signed-off-by: Thomas Huth <address@hidden>
>> ---
>>  PS: If we can't agree on using the generic loader here, I can also
>>      prepare a patch instead that simply prints out an error message
>>      if the user tried to use the "-kernel" parameter.
>>
>>  hw/core/null-machine.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c
>> index 27c8369..866e699 100644
>> --- a/hw/core/null-machine.c
>> +++ b/hw/core/null-machine.c
>> @@ -5,6 +5,7 @@
>>   *
>>   * Authors:
>>   *  Anthony Liguori   <address@hidden>
>> + *  Thomas Huth       <address@hidden>
>>   *
>>   * This work is licensed under the terms of the GNU GPL, version 2 or later.
>>   * See the COPYING file in the top-level directory.
>> @@ -16,6 +17,7 @@
>>  #include "qemu/error-report.h"
>>  #include "hw/hw.h"
>>  #include "hw/boards.h"
>> +#include "hw/core/generic-loader.h"
>>  #include "sysemu/sysemu.h"
>>  #include "exec/address-spaces.h"
>>  #include "cpu.h"
>> @@ -40,6 +42,18 @@ static void machine_none_init(MachineState *mch)
>>          memory_region_allocate_system_memory(ram, NULL, "ram", 
>> mch->ram_size);
>>          memory_region_add_subregion(get_system_memory(), 0, ram);
>>      }
>> +
>> +    /* Load kernel */
>> +    if (mch->kernel_filename) {
>> +        DeviceState *loader;
>> +
>> +        loader = qdev_create(sysbus_get_default(), TYPE_GENERIC_LOADER);
>> +        qdev_prop_set_string(loader, "file", mch->kernel_filename);
>> +        if (cpu) {
>> +            qdev_prop_set_uint32(loader, "cpu-num", cpu->cpu_index);
>> +        }
>> +        qdev_init_nofail(loader);
>> +    }
>>  }
> 
> It seems you need to check "-cpu" is set otherwise we have a segfault in
> the loader:
> 
> Thread 1 "qemu-system-m68" received signal SIGSEGV, Segmentation fault.
> ...
> #0  0x000055555564e5f8 in generic_loader_realize (dev=<optimized out>,
> errp=0x7fffffffd900) at hw/core/generic-loader.c:141
> 
> 140         if (!s->force_raw) {
> 141             size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL,
> 142                                big_endian, 0, 0, 0, s->cpu->as);
> 143
> 
> (gdb) p s->cpu
> $2 = (CPUState *) 0x0

Oh, nice catch! ... but I think this should rather be fixed in the
generic-loader instead, e.g. by using get_system_memory() instead of
s->cpu->as if s->cpu is NULL. Otherwise you can still trigger the crash
if using the loader device directly, e.g. with "-M none -device
loader,file=something". I'll send a separate patch for this...

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]