On Fri, 9 Jul 2021 at 09:55, Hiroko Shimizu <[email protected]> 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. thanks -- PMM
