summaryrefslogtreecommitdiff
path: root/lib/mipsdump.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mipsdump.cpp')
-rw-r--r--lib/mipsdump.cpp207
1 files changed, 207 insertions, 0 deletions
diff --git a/lib/mipsdump.cpp b/lib/mipsdump.cpp
new file mode 100644
index 0000000..ac77b33
--- /dev/null
+++ b/lib/mipsdump.cpp
@@ -0,0 +1,207 @@
+/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002-2003 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: mipsdump.cpp,v 1.1 2004-01-03 15:04:47 pixel Exp $ */
+
+#include "mipsdump.h"
+#include "mips.h"
+
+TDump::TDump(mipsmem * mm) : TDis(mm) {
+ reset();
+}
+
+void TDump::reset() {
+ invalid = false;
+ hasbr = false;
+ hastg = false;
+ hasfc = false;
+ name = "";
+ comments = "";
+ args.clear();
+}
+
+void TDump::add_branch(Uint32 _tg) {
+ tg = _tg;
+ hasbr = true;
+}
+
+void TDump::add_jump(Uint32 _tg) {
+ tg = _tg;
+ hastg = true;
+}
+
+void TDump::add_function(Uint32 _tg) {
+ tg = _tg;
+ hasfc = true;
+}
+
+void TDump::SetTag(Uint32 a, int t, bool v) {
+}
+
+void TDump::Name(const String & _name) {
+ name = _name;
+}
+
+void TDump::PushGPReg(int r) {
+ pairarg p;
+
+ p.left = T_GPREGISTER;
+ p.right.v = r;
+
+ args.push_back(p);
+}
+
+void TDump::PushCPReg(int r) {
+ pairarg p;
+
+ p.left = T_CPREGISTER;
+ p.right.v = r;
+
+ args.push_back(p);
+}
+
+void TDump::PushImm(Uint32 imm) {
+ pairarg p;
+
+ p.left = T_IMM16;
+ p.right.v = imm;
+
+ args.push_back(p);
+}
+
+void TDump::PushTarget(Uint32 target) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = target;
+
+ args.push_back(p);
+}
+
+void TDump::PushSa(Uint32 sa) {
+ pairarg p;
+
+ p.left = T_IMM8;
+ p.right.v = sa;
+
+ args.push_back(p);
+}
+
+void TDump::PushOfB(int reg, Uint32 offset, int width) {
+ pairarg p;
+
+ p.left = T_OFB;
+ p.right.OfB.o = offset;
+ p.right.OfB.r = reg;
+ p.right.OfB.w = width;
+
+ args.push_back(p);
+}
+
+void TDump::PushOffset(Uint32 offset) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = offset;
+
+ args.push_back(p);
+}
+
+void TDump::PushFull(Uint32 full) {
+ pairarg p;
+
+ p.left = T_IMM32;
+ p.right.v = full;
+
+ args.push_back(p);
+}
+
+void TDump::Invalid() {
+ invalid = true;
+}
+
+void TDump::Suspect() {
+}
+
+void TDump::Comment(const String & c) {
+ comments = c;
+}
+
+Dumper::Dumper(mipsmem * _mm) : dump(new TDump(_mm)), mm(_mm) {
+}
+
+void Dumper::process() {
+ Uint32 pc, code;
+ memdata * mem;
+
+ for (pc = 0x80000000; pc < (0x80000000 + PSXMEM); pc++) {
+ if (mm->GetTag(pc, CODE)) {
+ decode(dump, pc);
+ code = mm->Read32(pc);
+ printm(M_STATUS, "%8.8lX %8.8lX: " + dump->name + "\t", pc, code);
+ for (std::vector<pairarg>::iterator i = dump->args.begin(); i != dump->args.end(); i++) {
+ switch(i->left) {
+ case T_GPREGISTER:
+ printm(M_BARE, "$%s", registers[i->right.v]);
+ break;
+ case T_CPREGISTER:
+ printm(M_BARE, "$%s", CP0registers[i->right.v]);
+ break;
+ case T_IMM8:
+ printm(M_BARE, "0x%2.2lX", i->right.v);
+ break;
+ case T_IMM16:
+ printm(M_BARE, "0x%4.4lX", i->right.v);
+ break;
+ case T_IMM32:
+ printm(M_BARE, "0x%8.8lX", i->right.v);
+ break;
+ case T_OFB:
+ printm(M_BARE, "0x%4.4lX($%s)", i->right.OfB.o, registers[i->right.OfB.r]);
+ break;
+ }
+ if ((i + 1) != dump->args.end()) {
+ printm(M_BARE, ", ");
+ }
+ }
+ if (dump->comments != "") {
+ printm(M_BARE, "\t; " + dump->comments);
+ }
+ printm(M_BARE, "\n");
+ mem = mm->GetDatas(pc);
+ if (mem) {
+ reffrom_t * from;
+ refto_t * to;
+
+ from = mem->getreffrom();
+ to = mem->getrefto();
+
+ for (from = mem->getreffrom(); from; from = from->getnext()) {
+ printm(M_STATUS, " Reference from 0x%8.8lX\n", from->getref()->getaddress());
+ }
+
+ if (to) {
+ printm(M_STATUS, " Reference to 0x%8.8lX\n", to->getref()->getaddress());
+ }
+ }
+ pc += 3;
+ dump->reset();
+ }
+ }
+}