summaryrefslogtreecommitdiff
path: root/utils/regtools/tester.cpp
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-12 19:49:26 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-12 19:49:26 +0200
commit7143ea681c377fe5901bd79801366a26ae0d394a (patch)
tree34fdaaa83590130b57b187878a89394505950b82 /utils/regtools/tester.cpp
parent11da9d23fe323ce452fcd04a10a0ddf78eaa63ea (diff)
downloadrockbox-7143ea681c377fe5901bd79801366a26ae0d394a.tar.gz
rockbox-7143ea681c377fe5901bd79801366a26ae0d394a.zip
imxtools: move regtools to its own directory
The register tools are in no way stmp specific. The XML description of the registers is powerful enough to describe the STMP register which should be more than enough to describe virtually all other SoCs. The generators follow the STMP coding convention but others could be used as well. Change-Id: If1a9f56e4a3594161688de34adbea698e5aaecd8
Diffstat (limited to 'utils/regtools/tester.cpp')
-rw-r--r--utils/regtools/tester.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/utils/regtools/tester.cpp b/utils/regtools/tester.cpp
new file mode 100644
index 0000000000..a46d310f2a
--- /dev/null
+++ b/utils/regtools/tester.cpp
@@ -0,0 +1,126 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "desc_parser.hpp"
22#include <stdio.h>
23#include <stdlib.h>
24
25void print_value_desc(const soc_reg_field_value_t& value)
26{
27 printf(" VALUE %s (%#x)\n", value.name.c_str(), value.value);
28}
29
30void print_field_desc(const soc_reg_field_t& field)
31{
32 printf(" FIELD %s (%d:%d)\n", field.name.c_str(), field.last_bit,
33 field.first_bit);
34 for(size_t i = 0; i < field.values.size(); i++)
35 print_value_desc(field.values[i]);
36}
37
38std::string compute_sct(soc_reg_flags_t f)
39{
40 if(f & REG_HAS_SCT) return "SCT";
41 else return "";
42}
43
44void print_reg_desc(const soc_reg_t& reg, bool in_multi)
45{
46 if(in_multi)
47 {
48 printf(" REG %s (%#x)\n", reg.name.c_str(), reg.addr);
49 }
50 else
51 {
52 std::string sct = compute_sct(reg.flags);
53 printf(" REG %s %s(%#x)\n", reg.name.c_str(), sct.c_str(), reg.addr);
54 for(size_t i = 0; i < reg.fields.size(); i++)
55 print_field_desc(reg.fields[i]);
56 }
57}
58
59void print_multireg_desc(const soc_multireg_t& mreg)
60{
61 std::string sct = compute_sct(mreg.flags);
62 printf(" MULTIREG %s %s(%#x * %d, +%#x)\n", mreg.name.c_str(), sct.c_str(),
63 mreg.base, mreg.count, mreg.offset);
64 for(size_t i = 0; i < mreg.regs.size(); i++)
65 print_reg_desc(mreg.regs[i], true);
66 for(size_t i = 0; i < mreg.fields.size(); i++)
67 print_field_desc(mreg.fields[i]);
68}
69
70
71void print_dev_desc(const soc_dev_t& dev, bool in_multi)
72{
73 if(in_multi)
74 {
75 printf(" DEV %s (%#x)\n", dev.name.c_str(), dev.addr);
76 }
77 else
78 {
79 printf(" DEV %s (%#x, %s, %s)\n", dev.name.c_str(), dev.addr,
80 dev.long_name.c_str(), dev.desc.c_str());
81 for(size_t i = 0; i < dev.multiregs.size(); i++)
82 print_multireg_desc(dev.multiregs[i]);
83 for(size_t i = 0; i < dev.regs.size(); i++)
84 print_reg_desc(dev.regs[i], false);
85 }
86}
87
88void print_multidev_desc(const soc_multidev_t& dev)
89{
90 printf(" MULTIDEV %s (%s, %s)\n", dev.name.c_str(), dev.long_name.c_str(),
91 dev.desc.c_str());
92 for(size_t i = 0; i < dev.devs.size(); i++)
93 print_dev_desc(dev.devs[i], true);
94 for(size_t i = 0; i < dev.multiregs.size(); i++)
95 print_multireg_desc(dev.multiregs[i]);
96 for(size_t i = 0; i < dev.regs.size(); i++)
97 print_reg_desc(dev.regs[i], false);
98}
99
100void print_soc_desc(const soc_t& soc)
101{
102 printf("SOC %s (%s)\n", soc.name.c_str(), soc.desc.c_str());
103 for(size_t i = 0; i < soc.devs.size(); i++)
104 print_dev_desc(soc.devs[i], false);
105 for(size_t i = 0; i < soc.multidevs.size(); i++)
106 print_multidev_desc(soc.multidevs[i]);
107}
108
109void usage()
110{
111 printf("usage: tester <desc file>\n");
112 exit(1);
113}
114
115int main(int argc, char **argv)
116{
117 if(argc != 2)
118 usage();
119 std::vector< soc_t > socs;
120 bool ret = parse_soc_desc(argv[1], socs);
121 printf("parse result: %d\n", ret);
122 if(ret)
123 for(size_t i = 0; i < socs.size(); i++)
124 print_soc_desc(socs[i]);
125 return 0;
126} \ No newline at end of file