From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8nE-0003lW-SZ for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG8nD-0005Th-Q4 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:51:56 -0400 Received: from mail-oi0-x242.google.com ([2607:f8b0:4003:c06::242]:34637) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8nD-0005Ta-Jg for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:51:55 -0400 Received: by mail-oi0-x242.google.com with SMTP id s17so13570151oih.1 for ; Thu, 23 Jun 2016 10:51:55 -0700 (PDT) MIME-Version: 1.0 Sender: alistair23@gmail.com In-Reply-To: References: <7d57d1d9d76bb4ac6c60b6509688e4589e5e9a95.1466626975.git.alistair.francis@xilinx.com> From: Alistair Francis Date: Thu, 23 Jun 2016 10:51:25 -0700 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v7 04/12] register: Define REG and FIELD macros List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Alistair Francis , Edgar Iglesias , QEMU Developers , Peter Crosthwaite , "Edgar E. Iglesias" , =?UTF-8?B?QWxleCBCZW5uw6ll?= , =?UTF-8?Q?Andreas_F=C3=A4rber?= , =?UTF-8?B?S09OUkFEIEZyw6lkw6lyaWM=?= On Thu, Jun 23, 2016 at 5:39 AM, Peter Maydell wrote: > On 22 June 2016 at 21:23, Alistair Francis wrote: >> From: Peter Crosthwaite >> >> Define some macros that can be used for defining registers and fields. >> >> The REG32 macro will define A_FOO, for the byte address of a register >> as well as R_FOO for the uint32_t[] register number (A_FOO / 4). >> >> The FIELD macro will define FOO_BAR_MASK, FOO_BAR_SHIFT and >> FOO_BAR_LENGTH constants for field BAR in register FOO. >> >> Finally, there are some shorthand helpers for extracting/depositing >> fields from registers based on these naming schemes. >> >> Usage can greatly reduce the verbosity of device code. >> >> The deposit and extract macros (eg FIELD_EX32, FIELD_DP32 etc.) can be >> used to generate extract and deposits without any repetition of the name >> stems. >> >> Signed-off-by: Peter Crosthwaite >> [ EI Changes: >> * Add Deposit macros >> ] >> Signed-off-by: Edgar E. Iglesias >> Signed-off-by: Alistair Francis >> --- > >> diff --git a/include/hw/register.h b/include/hw/register.h >> index e160150..216b679 100644 >> --- a/include/hw/register.h >> +++ b/include/hw/register.h >> @@ -150,4 +150,47 @@ void register_write_memory(void *opaque, hwaddr addr, uint64_t value, >> >> uint64_t register_read_memory(void *opaque, hwaddr addr, unsigned size); >> >> +/* Define constants for a 32 bit register */ >> + >> +/* This macro will define A_FOO, for the byte address of a register >> + * as well as R_FOO for the uint32_t[] register number (A_FOO / 4). >> + */ >> +#define REG32(reg, addr) \ >> + enum { A_ ## reg = (addr) }; \ >> + enum { R_ ## reg = (addr) / 4 }; >> + >> +/* Define SHIFT, LEGTH and MASK constants for a field within a register */ >> + > > "LENGTH". Fixed > >> +/* Deposit a register field. */ >> +#define FIELD_DP32(storage, reg, field, val) ({ \ >> + struct { \ >> + unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \ >> + } v = { .v = val }; \ >> + uint32_t d; \ >> + d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \ >> + R_ ## reg ## _ ## field ## _LENGTH, v.v); \ >> + d; }) > > If you insist on different semantics to deposit32() (which I > still think is a bad idea), can we at least have a comment > noting the difference? I have added a comment. > > (Do you get a warning for putting a signed negative value into > a field?) No, I don't see any warnings for forcing negative values in. Thanks, Alistair > > Otherwise > Reviewed-by: Peter Maydell > > thanks > -- PMM >