qemu-arm
[Top][All Lists]
Advanced

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

Re: Custom ARM Board: Setting BE32 endianness


From: Peter Maydell
Subject: Re: Custom ARM Board: Setting BE32 endianness
Date: Fri, 13 Mar 2020 10:11:46 +0000

On Fri, 13 Mar 2020 at 09:56, Tanay Gupta <address@hidden> wrote:
>
> Thanks for the help, Peter!
>
> I have referred to the versatilepb board for setting the property.
>
> This is what I'm doing now, in my machine_init:
>
> Object* cpuobj = obj_new(machine->cpu_type);
> object_property_set_bool(cpuobj, true, "cfgend", &error_fatal);
> object_property_set_bool(cpuobj, true, "realized", &error_fatal);
>
> ARMCPU* armcpu = ARM_CPU(cpuobj);
> CPUState* cpu = CPU(armcpu);
> cpu_set_pc(cpu, 0x40000000);
>
> <board code>
>
> boot_info.entry = 0x40000000;

The 'entry' field in boot_info is used internally by
arm_load_kernel(): you are not supposed to set it
yourself.

> arm_load_kernel(armcpu, machine, &boot_info);
>
> In the code above, I am not able to change the pc of the cpu. cpu_set_pc does 
> set the pc, but its value gets changed back to 0 on the call to 
> arm_load_kernel.
>
> Could you tell me how I can set the pc in this case?

Don't try to set the PC from board code. Follow the
way other boards work, and you will usually find
things go easier.

> I don't use the -kernel option, because I'm loading the binaries to memory in 
> the <board code> section.

Roughly, QEMU for Arm has three expected ways to start:
 * loading a Linux kernel, which is booted via the kernel
   specification for how you start a kernel (this happens
   if you use -kernel and pass it something that is not
   an ELF file)
 * loading an ELF file, in which case execution starts
   at the ELF entrypoint (if you use -kernel with an ELF,
   or if you use the "generic loader")
 * running a "bios/boot rom", which is expected to be
   loaded into memory/flash by the board code in the
   right place so that when the CPU starts execution
   from its normal default reset address it will run the
   boot code

If the files you're loading to memory work like
the 'boot rom' then you can load them in the board
code, but you should not then be needing to set the
PC at all, because they should be in the right place
for the reset PC (which is either 0, or 0xffff0000
if the CPU is one which sets SCTLR.V on reset.)

Otherwise, you can use the 'generic loader' device
(see docs/generic-loader.txt) to load files, set the PC,
etc. (If your binary is an ELF file the PC gets set from
its entry point.)

> Also, I get a segfault if I don't set the "realized" property. Is setting it 
> like I have the proper way to do it?

Yes. QEMU devices have a multi-stage initialization:
 * init the device
 * set properties on it
 * "realize" it

The realize step is the final "all device properties
have been set, complete initialization" part. Trying
to use a device that has not been realized is a bug
and will cause random bad behaviour like crashes.

thanks
-- PMM



reply via email to

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