diff options
author | Luca Barbieri <luca@luca-barbieri.com> | 2010-03-29 03:32:33 +0200 |
---|---|---|
committer | Luca Barbieri <luca@luca-barbieri.com> | 2010-03-29 03:32:33 +0200 |
commit | 99f09528d95ca69ed4ae35e9fffa6f5ca7943682 (patch) | |
tree | 004672fcb167d94dba77a9f629e42558c3d6ea9d /ramin.cpp | |
parent | 6198ea8e9182a845ebcee3753c82377b82c6b0ed (diff) |
add ramin.cpp, RAMIN dumper with object resolution
Diffstat (limited to 'ramin.cpp')
-rw-r--r-- | ramin.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/ramin.cpp b/ramin.cpp new file mode 100644 index 0000000..5a2df7f --- /dev/null +++ b/ramin.cpp @@ -0,0 +1,110 @@ +#include "nvlib.h" +#include <algorithm> +#include <tuple> +using namespace std; + +int main(int argc, char** argv) +{ + unique_ptr<nv_device> dev(nv_device::open_default()); + + vector<tuple<unsigned, unsigned, string> > objects; + + for(unsigned i = 0; i < dev->ramht->entries; ++i) { + nv_ramht_entry entry = dev->ramht->get_at(i); + if(!entry.valid) + continue; + ostringstream ss; + //ss << "RAMHT[" << dec << i << "] " << make_pair(&*dev, entry); + ss << (unsigned)entry.channel << ":" << hex08 << entry.handle; + nv_object obj(&*dev->ramin, entry.instance); + objects.push_back(make_tuple(entry.instance, entry.instance + obj.size, ss.str())); + } + + for(unsigned i = 0; i < dev->channels; ++i) { + unsigned grctx = dev->get_grctx(i); + if(!grctx) + continue; + ostringstream ss; + ss << "GRCTX(" << i << ")"; + objects.push_back(make_tuple(grctx, grctx + dev->grctx_size, ss.str())); + } + + for(unsigned i = 0; i < dev->channels; ++i) { + int fc_offset = dev->ramfc->fc[i]->offset_in(*dev->ramin); + if(fc_offset >= 0) { + ostringstream ss; + ss << "RAMFC(" << i << ")"; + objects.push_back(make_tuple((unsigned)fc_offset, (unsigned)(fc_offset + dev->ramfc->fc[i]->size), ss.str())); + } + } + + int ramht_offset = dev->ramht->offset_in(*dev->ramin); + if(ramht_offset >= 0) + objects.push_back(make_tuple((unsigned)ramht_offset, (unsigned)(ramht_offset + dev->ramht->size), string("RAMHT"))); + + int ramro_offset = dev->ramro->offset_in(*dev->ramin); + if(ramro_offset >= 0) + objects.push_back(make_tuple((unsigned)ramro_offset, (unsigned)(ramro_offset + dev->ramro->size), string("RAMRO"))); + + for(unsigned i = 0; i < objects.size(); ++i) { + get<1>(objects[i]) = -get<1>(objects[i]); + } + sort(objects.begin(), objects.end()); + for(unsigned i = 0; i < objects.size(); ++i) { + get<1>(objects[i]) = -get<1>(objects[i]); + } + + string object_name; + unsigned object_start = 0; + unsigned object_end = 0; + unsigned object_w; + unsigned ramin_w = 0; + int next_object_idx = 0; + string object_prefix; + + while((1u << (4 * ramin_w)) < dev->ramin->size) + ++ramin_w; + + for(unsigned i = 0; i < dev->ramin->size; i += 16) { + while(next_object_idx < (int)objects.size() && i > get<0>(objects[next_object_idx])) + ++next_object_idx; + + while(next_object_idx < (int)objects.size() && i == get<0>(objects[next_object_idx])) { + object_start = get<0>(objects[next_object_idx]); + object_end = get<1>(objects[next_object_idx]); + object_w = 0; + while((1u << (4 * object_w)) < (object_end - object_start)) + ++object_w; + object_name = get<2>(objects[next_object_idx]); + ++next_object_idx; + + goto update_prefix; + } + + if(i >= object_end) { + object_start = 0; + object_end = dev->ramin->size; + object_name = "RAMIN"; + object_w = ramin_w; +update_prefix: + object_prefix = "\t"; + while((((11 + object_name.size() + 3 + object_w) >> 3) + object_prefix.size()) < 4) + object_prefix += '\t'; + } + + unsigned v[4]; + for(unsigned j = 0; j < 4; ++j) + v[j] = dev->ramin->rd32(i + j * 4); + + if(!v[0] && !v[1] && !v[2] && !v[3]) + continue; + + cout << hex08 << i << " = " << object_name << '[' << hex << setfill('0') << setw(object_w) << i - object_start << "]:" << object_prefix; + + for(unsigned j = 0; j < 4; ++j) + cout << (j ? " " : "") << hex08 << v[j]; + cout << endl; + } + + return 0; +} |