[Top][All Lists]

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

Re: using bit-field to define a qom register

From: Peter Maydell
Subject: Re: using bit-field to define a qom register
Date: Fri, 9 Jul 2021 12:27:04 +0100

On Fri, 9 Jul 2021 at 09:55, Hiroko Shimizu <hiroko07168@gmail.com> wrote:
> Hello,
> I would like to access a 4byte-register in 1bit unit.
> So, I was supposed to use a bit field to define a register like this.
> ----------------------------------------
> typedef struct register{
>     // define register B
>     uint32_t B1 : 1;
>     uint32_t B2 : 1;
>     uint32_t B3 : 30;
> }register;
> ------------------------------------------
> Then, How do you define this in VMStateDescription?
> And can I set a value to register.B2 from the ***_write function?

We don't recommend using C bitfields to define register types.
They're not portable (in the sense that the compiler may choose
to put the fields in either big or little endian order).
Better to use a plain uint32_t and then use bit-manipulation
to read and write the fields within it. QEMU provides functions
like extract32/deposit32 and also the FIELD macros in registerfields.h
to assist with this.

-- PMM

reply via email to

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