[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: Hiroko Shimizu
Subject: Re: using bit-field to define a qom register
Date: Sat, 10 Jul 2021 11:00:37 +0900

2021年7月9日(金) 20:27 Peter Maydell <peter.maydell@linaro.org>:
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

Thank you, I understand how to read/write.
Anyway, if you access the second bit, does the read/write function offset value become 1 bit automatically? 

reply via email to

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