summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/regtools/headergen_v2.cpp183
1 files changed, 173 insertions, 10 deletions
diff --git a/utils/regtools/headergen_v2.cpp b/utils/regtools/headergen_v2.cpp
index 66d677c0b3..18620c2501 100644
--- a/utils/regtools/headergen_v2.cpp
+++ b/utils/regtools/headergen_v2.cpp
@@ -537,6 +537,10 @@ private:
537 bool generate_register(std::ostream& os, const pseudo_node_inst_t& reg); 537 bool generate_register(std::ostream& os, const pseudo_node_inst_t& reg);
538 bool generate_macro_header(error_context_t& ectx); 538 bool generate_macro_header(error_context_t& ectx);
539protected: 539protected:
540 /// return true to generate support macros
541 /// if false then all macros are disabled except MT_REG_ADDR, MT_REG_VAR,
542 /// and MT_FIELD_*. Also the macro header is not created
543 virtual bool has_support_macros() const = 0;
540 /// return true to generate selector files 544 /// return true to generate selector files
541 virtual bool has_selectors() const = 0; 545 virtual bool has_selectors() const = 0;
542 /// [selector only] return the directory name for the soc 546 /// [selector only] return the directory name for the soc
@@ -942,16 +946,30 @@ bool common_generator::generate_register(std::ostream& os, const pseudo_node_ins
942 type_xfix(MT_REG_NAME, false); 946 type_xfix(MT_REG_NAME, false);
943 std::string macro_index = type_xfix(MT_REG_INDEX, true) + var_basename + 947 std::string macro_index = type_xfix(MT_REG_INDEX, true) + var_basename +
944 type_xfix(MT_REG_INDEX, false); 948 type_xfix(MT_REG_INDEX, false);
945 /* print VAR macro */ 949 /* print VAR macro:
946 ctx.add(macro_var + param_str, macro_name(MN_VARIABLE) + "(" + var_basename + param_str + ")"); 950 * if we have support macros then we generate something like HW(basename)
951 * where HW is some support macros to support complex operations. Otherwise
952 * we just generate something like (*(volatile unsigned uintN_t)basename_addr) */
953 if(!has_support_macros())
954 {
955 std::ostringstream oss;
956 oss << "(*(volatile uint" << regr.get()->width << "_t *)" << macro_addr + param_str << ")";
957 ctx.add(macro_var + param_str, oss.str());
958 }
959 else
960 ctx.add(macro_var + param_str, macro_name(MN_VARIABLE) + "(" + var_basename + param_str + ")");
947 /* print ADDR macro */ 961 /* print ADDR macro */
948 ctx.add(macro_addr + param_str, var_addr[i]); 962 ctx.add(macro_addr + param_str, var_addr[i]);
949 /* print TYPE macro */ 963 /* disable macros if needed */
950 ctx.add(macro_type + param_str, register_type_name(var_access[i], regr.get()->width)); 964 if(has_support_macros())
951 /* print PREFIX macro */ 965 {
952 ctx.add(macro_prefix + param_str, basename); 966 /* print TYPE macro */
953 /* print INDEX macro */ 967 ctx.add(macro_type + param_str, register_type_name(var_access[i], regr.get()->width));
954 ctx.add(macro_index + param_str, param_str); 968 /* print PREFIX macro */
969 ctx.add(macro_prefix + param_str, basename);
970 /* print INDEX macro */
971 ctx.add(macro_index + param_str, param_str);
972 }
955 } 973 }
956 /* print fields */ 974 /* print fields */
957 std::vector< field_ref_t > fields = regr.fields(); 975 std::vector< field_ref_t > fields = regr.fields();
@@ -993,6 +1011,9 @@ bool common_generator::generate_register(std::ostream& os, const pseudo_node_ins
993 1011
994bool common_generator::generate_macro_header(error_context_t& ectx) 1012bool common_generator::generate_macro_header(error_context_t& ectx)
995{ 1013{
1014 /* only generate if we need support macros */
1015 if(!has_support_macros())
1016 return true;
996 std::ofstream fout((m_outdir + "/" + macro_header()).c_str()); 1017 std::ofstream fout((m_outdir + "/" + macro_header()).c_str());
997 if(!fout) 1018 if(!fout)
998 { 1019 {
@@ -1533,8 +1554,9 @@ bool common_generator::generate(error_context_t& ectx)
1533 print_guard(fout, guard, true); 1554 print_guard(fout, guard, true);
1534 1555
1535 /* if we generate selectors, we include the macro header in them, otherwise 1556 /* if we generate selectors, we include the macro header in them, otherwise
1536 * we include the macro header right here */ 1557 * we include the macro header right here. If we don't need support macros,
1537 if(!has_selectors()) 1558 * we also don't include it. */
1559 if(!has_selectors() && has_support_macros())
1538 { 1560 {
1539 fout << "\n"; 1561 fout << "\n";
1540 fout << "#include \"" << macro_header() << "\"\n"; 1562 fout << "#include \"" << macro_header() << "\"\n";
@@ -1614,6 +1636,11 @@ bool common_generator::generate(error_context_t& ectx)
1614 1636
1615class jz_generator : public common_generator 1637class jz_generator : public common_generator
1616{ 1638{
1639 bool has_support_macros() const
1640 {
1641 return true;
1642 }
1643
1617 bool has_selectors() const 1644 bool has_selectors() const
1618 { 1645 {
1619 return m_soc.size() >= 2; 1646 return m_soc.size() >= 2;
@@ -1774,6 +1801,11 @@ class jz_generator : public common_generator
1774 1801
1775class imx_generator : public common_generator 1802class imx_generator : public common_generator
1776{ 1803{
1804 bool has_support_macros() const
1805 {
1806 return true;
1807 }
1808
1777 bool has_selectors() const 1809 bool has_selectors() const
1778 { 1810 {
1779 return m_soc.size() >= 2; 1811 return m_soc.size() >= 2;
@@ -1930,6 +1962,135 @@ class imx_generator : public common_generator
1930}; 1962};
1931 1963
1932/** 1964/**
1965 * Generator: atj
1966 */
1967
1968class atj_generator : public common_generator
1969{
1970 bool has_support_macros() const
1971 {
1972 // no support macros
1973 return false;
1974 }
1975
1976 bool has_selectors() const
1977 {
1978 return false;
1979 }
1980
1981 std::string selector_soc_dir(const soc_ref_t& ref) const
1982 {
1983 return ref.get()->name;
1984 }
1985
1986 std::string selector_include_header() const
1987 {
1988 // unused
1989 return "<error>";
1990 }
1991
1992 std::string selector_soc_macro(const soc_ref_t& ref) const
1993 {
1994 // unused
1995 return "<error>";
1996 }
1997
1998 std::string register_header(const node_inst_t& inst) const
1999 {
2000 /* one register header per top-level block */
2001 if(inst.is_root())
2002 return "<error>";
2003 if(inst.parent().is_root())
2004 return tolower(inst.node().name()) + ".h";
2005 else
2006 return register_header(inst.parent());
2007 }
2008
2009 std::string macro_name(macro_name_t macro) const
2010 {
2011 // no macros are generated
2012 return "<macro_name>";
2013 }
2014
2015 std::string macro_header() const
2016 {
2017 // unused
2018 return "<error>";
2019 }
2020
2021 bool register_flag(const node_inst_t& inst, register_flag_t flag) const
2022 {
2023 /* make everything parametrized */
2024 switch(flag)
2025 {
2026 case RF_GENERATE_ALL_INST: return false;
2027 case RF_GENERATE_PARAM_INST: return true;
2028 default: return false;
2029 }
2030 }
2031
2032 std::string type_xfix(macro_type_t type, bool prefix) const
2033 {
2034 switch(type)
2035 {
2036 case MT_REG_ADDR: return prefix ? "" : "_ADDR";
2037 case MT_REG_VAR: return prefix ? "" : "";
2038 case MT_FIELD_BP: return prefix ? "BP_" : "";
2039 case MT_FIELD_BM: return prefix ? "BM_" : "";
2040 case MT_FIELD_BV: return prefix ? "BV_" : "";
2041 case MT_FIELD_BF: return prefix ? "BF_" : "";
2042 case MT_FIELD_BFM: return prefix ? "BFM_" : "";
2043 case MT_FIELD_BFV: return prefix ? "BF_" : "_V";
2044 case MT_FIELD_BFMV: return prefix ? "BFM_" : "_V";
2045 default: return "<xfix>";
2046 }
2047 }
2048
2049 std::string variant_xfix(const std::string& variant, bool prefix) const
2050 {
2051 return "<variant>";
2052 }
2053
2054 std::string inst_prefix(const node_inst_t& inst) const
2055 {
2056 /* separate blocks with _: block_reg */
2057 return "_";
2058 }
2059
2060 std::string field_prefix() const
2061 {
2062 /* separate fields with _: block_reg_field */
2063 return "_";
2064 }
2065
2066 std::string enum_prefix() const
2067 {
2068 /* separate enums with __: block_reg_field__enum */
2069 return "__";
2070 }
2071
2072 std::string enum_name(const enum_ref_t& enum_) const
2073 {
2074 return enum_.get()->name;
2075 }
2076
2077 access_type_t register_access(const std::string& variant, access_t access) const
2078 {
2079 return AT_RW;
2080 }
2081
2082 bool has_sct() const
2083 {
2084 return false;
2085 }
2086
2087 std::string sct_variant(macro_name_t name) const
2088 {
2089 return "<variant>";
2090 }
2091};
2092
2093/**
1933 * Driver 2094 * Driver
1934 */ 2095 */
1935 2096
@@ -1939,6 +2100,8 @@ abstract_generator *get_generator(const std::string& name)
1939 return new jz_generator(); 2100 return new jz_generator();
1940 else if(name == "imx") 2101 else if(name == "imx")
1941 return new imx_generator(); 2102 return new imx_generator();
2103 else if(name == "atj")
2104 return new atj_generator();
1942 else 2105 else
1943 return 0; 2106 return 0;
1944} 2107}