From 6cb861137d40c91782042764c591ceb995f345fa Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Wed, 22 Oct 2014 17:51:09 +0200 Subject: regtools/socdesc: update library with a field useful functions Change-Id: Ib2891fe36b0594e8554bb354a29bc8b3485de20d Reviewed-on: http://gerrit.rockbox.org/1018 Reviewed-by: Amaury Pouly --- utils/regtools/lib/soc_desc.hpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'utils/regtools/lib/soc_desc.hpp') diff --git a/utils/regtools/lib/soc_desc.hpp b/utils/regtools/lib/soc_desc.hpp index 1b4985529c..bb8eb4ba8d 100644 --- a/utils/regtools/lib/soc_desc.hpp +++ b/utils/regtools/lib/soc_desc.hpp @@ -46,7 +46,7 @@ */ #define SOCDESC_VERSION_MAJOR 1 -#define SOCDESC_VERSION_MINOR 1 +#define SOCDESC_VERSION_MINOR 4 #define SOCDESC_VERSION_REV 1 #define SOCDESC_VERSION__(maj,min,rev) #maj"."#min"."#rev @@ -103,6 +103,7 @@ struct soc_reg_field_t soc_reg_field_t():first_bit(0), last_bit(31) {} + /** Return field bitmask in register */ soc_word_t bitmask() const { // WARNING beware of the case where first_bit=0 and last_bit=31 @@ -112,11 +113,32 @@ struct soc_reg_field_t return ((1 << (last_bit - first_bit + 1)) - 1) << first_bit; } + /** Extract field value from register value */ + soc_word_t extract(soc_word_t reg_val) const + { + return (reg_val & bitmask()) >> first_bit; + } + + /** Replace the field value in a register value */ + soc_word_t replace(soc_word_t reg_val, soc_word_t field_val) const + { + return (reg_val & ~bitmask()) | ((field_val << first_bit) & bitmask()); + } + bool is_reserved() const { return name.substr(0, 4) == "RSVD" || name.substr(0, 5) == "RSRVD"; } + /** Return field value index, or -1 if none */ + int find_value(soc_word_t v) const + { + for(size_t i = 0; i < value.size(); i++) + if(value[i].value == v) + return i; + return -1; + } + std::vector< soc_reg_field_value_t > value; std::vector< soc_error_t > errors(bool recursive); -- cgit v1.2.3