2017-01-27 16:20:21 +01:00
|
|
|
/*
|
|
|
|
* Register Definition API: field macros
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Xilinx Inc.
|
|
|
|
* Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef REGISTERFIELDS_H
|
|
|
|
#define REGISTERFIELDS_H
|
|
|
|
|
2018-02-01 12:18:28 +01:00
|
|
|
#include "qemu/bitops.h"
|
2017-12-13 06:17:36 +01:00
|
|
|
|
2017-01-27 16:20:21 +01:00
|
|
|
/* 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 };
|
|
|
|
|
2019-03-25 10:03:47 +01:00
|
|
|
#define REG8(reg, addr) \
|
|
|
|
enum { A_ ## reg = (addr) }; \
|
|
|
|
enum { R_ ## reg = (addr) };
|
|
|
|
|
|
|
|
#define REG16(reg, addr) \
|
|
|
|
enum { A_ ## reg = (addr) }; \
|
|
|
|
enum { R_ ## reg = (addr) / 2 };
|
|
|
|
|
2017-01-27 16:20:21 +01:00
|
|
|
/* Define SHIFT, LENGTH and MASK constants for a field within a register */
|
|
|
|
|
2017-12-13 06:17:34 +01:00
|
|
|
/* This macro will define R_FOO_BAR_MASK, R_FOO_BAR_SHIFT and R_FOO_BAR_LENGTH
|
2017-01-27 16:20:21 +01:00
|
|
|
* constants for field BAR in register FOO.
|
|
|
|
*/
|
|
|
|
#define FIELD(reg, field, shift, length) \
|
|
|
|
enum { R_ ## reg ## _ ## field ## _SHIFT = (shift)}; \
|
|
|
|
enum { R_ ## reg ## _ ## field ## _LENGTH = (length)}; \
|
|
|
|
enum { R_ ## reg ## _ ## field ## _MASK = \
|
|
|
|
MAKE_64BIT_MASK(shift, length)};
|
|
|
|
|
|
|
|
/* Extract a field from a register */
|
2019-03-25 10:03:47 +01:00
|
|
|
#define FIELD_EX8(storage, reg, field) \
|
|
|
|
extract8((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH)
|
|
|
|
#define FIELD_EX16(storage, reg, field) \
|
|
|
|
extract16((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH)
|
2017-01-27 16:20:21 +01:00
|
|
|
#define FIELD_EX32(storage, reg, field) \
|
|
|
|
extract32((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH)
|
2017-12-13 06:17:35 +01:00
|
|
|
#define FIELD_EX64(storage, reg, field) \
|
|
|
|
extract64((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH)
|
2017-01-27 16:20:21 +01:00
|
|
|
|
|
|
|
/* Extract a field from an array of registers */
|
|
|
|
#define ARRAY_FIELD_EX32(regs, reg, field) \
|
|
|
|
FIELD_EX32((regs)[R_ ## reg], reg, field)
|
|
|
|
|
|
|
|
/* Deposit a register field.
|
|
|
|
* Assigning values larger then the target field will result in
|
|
|
|
* compilation warnings.
|
|
|
|
*/
|
2019-03-25 10:03:47 +01:00
|
|
|
#define FIELD_DP8(storage, reg, field, val) ({ \
|
|
|
|
struct { \
|
|
|
|
unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \
|
2020-05-10 22:34:57 +02:00
|
|
|
} _v = { .v = val }; \
|
|
|
|
uint8_t _d; \
|
|
|
|
_d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
|
|
|
|
_d; })
|
2019-03-25 10:03:47 +01:00
|
|
|
#define FIELD_DP16(storage, reg, field, val) ({ \
|
|
|
|
struct { \
|
|
|
|
unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \
|
2020-05-10 22:34:57 +02:00
|
|
|
} _v = { .v = val }; \
|
|
|
|
uint16_t _d; \
|
|
|
|
_d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
|
|
|
|
_d; })
|
2017-01-27 16:20:21 +01:00
|
|
|
#define FIELD_DP32(storage, reg, field, val) ({ \
|
|
|
|
struct { \
|
|
|
|
unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \
|
2020-05-10 22:34:57 +02:00
|
|
|
} _v = { .v = val }; \
|
|
|
|
uint32_t _d; \
|
|
|
|
_d = deposit32((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
|
|
|
|
_d; })
|
2017-12-13 06:17:35 +01:00
|
|
|
#define FIELD_DP64(storage, reg, field, val) ({ \
|
|
|
|
struct { \
|
|
|
|
unsigned int v:R_ ## reg ## _ ## field ## _LENGTH; \
|
2020-05-10 22:34:57 +02:00
|
|
|
} _v = { .v = val }; \
|
|
|
|
uint64_t _d; \
|
|
|
|
_d = deposit64((storage), R_ ## reg ## _ ## field ## _SHIFT, \
|
|
|
|
R_ ## reg ## _ ## field ## _LENGTH, _v.v); \
|
|
|
|
_d; })
|
2017-01-27 16:20:21 +01:00
|
|
|
|
|
|
|
/* Deposit a field to array of registers. */
|
|
|
|
#define ARRAY_FIELD_DP32(regs, reg, field, val) \
|
|
|
|
(regs)[R_ ## reg] = FIELD_DP32((regs)[R_ ## reg], reg, field, val);
|
|
|
|
|
|
|
|
#endif
|