On Tue, 30 Nov 2021 at 22:53, abhijeet inamdar <abhijeetinamdar3...@gmail.com> wrote: > What difference does it make to define: > > DeviceState *nvic; > > nvic = qdev_create(NULL, TYPE_ARMV7M);
This creates a new device in freshly allocated memory, both initializing and realizing it, and returns a pointer to that newly created device. > vs > > DeviceState *armv7m; > > armv7m = DEVICE(&s->armv7m); This is not creating anything. It's just a cast -- it is exactly like "armv7m = (DeviceState*)(&s->armv7m);" except that it does a runtime typecheck that the pointer really is pointing to an initialized object of the right type. Unless the field s->armv7m has been previously correctly initialized, the typechecked cast will assert at runtime. > Can you please explain me because I'm confused between two machines > which I want to adapt for my custom machine which is based on > Cortex-M3. I think what you're looking at is that there are two ways of creating devices: * call functions that allocate memory, initialize a device in that memory, and return you a pointer; your device or machine state struct has fields which are "Foo *foo". * use "in-place" initialization, where the device or machine state struct has fields which are "Foo foo", and then you call functions which initialize that field. Mostly new QEMU code uses the second strategy, but there's still a fair bit of code that does the first. You should prefer the second, I think. -- PMM