From 14d90c9e1171655b864316c9c4aa34033fdd3a45 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 21 Sep 2009 03:37:45 +0200 Subject: Very first bit towards a Mips/PSX disassembler --- Cpu/Makefile | 16 ++++++++++++++++ Cpu/cpu-mips.cpp | 0 Cpu/cpu.cpp | 0 Database/database-types.h | 1 + Database/database.h | 6 ++++++ Database/internals/database-internal.cpp | 8 +++++--- Database/internals/database-internal.h | 4 ++-- Database/internals/database-segment.h | 1 + Loader/loader-psyq.cpp | 20 ++++++++++++++++++++ Makefile | 2 +- 10 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 Cpu/Makefile create mode 100644 Cpu/cpu-mips.cpp create mode 100644 Cpu/cpu.cpp create mode 100644 Loader/loader-psyq.cpp diff --git a/Cpu/Makefile b/Cpu/Makefile new file mode 100644 index 0000000..87835d6 --- /dev/null +++ b/Cpu/Makefile @@ -0,0 +1,16 @@ +TARGET = Cpu.a + +SRCS = \ +cpu.cpp \ +cpu-mips.cpp \ + +SPATH = + +CPPFLAGS = -I. -I../Database -I../Database/internals + +include ../Makefile.cfg + +$(TARGET): $(OBJS) + $(AR) $@ $^ + +-include $(DEPS) diff --git a/Cpu/cpu-mips.cpp b/Cpu/cpu-mips.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Cpu/cpu.cpp b/Cpu/cpu.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Database/database-types.h b/Database/database-types.h index 49db9b8..8ea61e6 100644 --- a/Database/database-types.h +++ b/Database/database-types.h @@ -40,6 +40,7 @@ typedef union { static inline Uint32 SEGID(absolute_ptr ptr) { return ptr.segment_id; } static inline Uint32 SEGOFFSET(absolute_ptr ptr) { return ptr.ptr; } +static inline absolute_ptr ABSPTR(Uint32 id, Uint32 ptr) { absolute_ptr r; r.segment_id = id; r.ptr = ptr; return r; } /** A function description. */ diff --git a/Database/database.h b/Database/database.h index be46598..222573d 100644 --- a/Database/database.h +++ b/Database/database.h @@ -22,6 +22,12 @@ class Database : public Base { return 0; } Uint32 GetNextSegId() { return currentId++; } + Segment * CreateSegment(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size = 0, const Byte * data = 0) { + DatabaseCell * r = new DatabaseCell(this, cpu, cpu_base, origin, size, extra_size, data); + return r->getSegment(); + } + void Serialize(Handle * out); + void Deserialize(Handle *in); private: DatabaseCell * start, * end; Uint32 currentId; diff --git a/Database/internals/database-internal.cpp b/Database/internals/database-internal.cpp index e564c01..ce54f44 100644 --- a/Database/internals/database-internal.cpp +++ b/Database/internals/database-internal.cpp @@ -1,14 +1,16 @@ #include "database-internal.h" #include "database.h" -DatabaseCell::DatabaseCell(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size, DatabaseCell * prev, Database * parent) : cpu(cpu), next(0), prev(prev), parent(parent) { - prev->next = this; +DatabaseCell::DatabaseCell(Database * parent, Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size, const Byte * data) : cpu(cpu), next(0), parent(parent) { + prev = parent->getEnd(); + if (prev) + prev->next = this; parent->setEnd(this); if (origin.raw_ptr) { Segment * origin_seg = parent->getSegment(SEGID(origin)); segment = new Segment(size, cpu_base, parent->GetNextSegId(), extra_size, origin_seg->getPristineMemory() + SEGOFFSET(origin)); } else { - segment = new Segment(size, cpu_base, parent->GetNextSegId(), extra_size); + segment = new Segment(size, cpu_base, parent->GetNextSegId(), extra_size, data); } } diff --git a/Database/internals/database-internal.h b/Database/internals/database-internal.h index 173eb62..4616d8c 100644 --- a/Database/internals/database-internal.h +++ b/Database/internals/database-internal.h @@ -17,9 +17,9 @@ class DatabaseCell : public Base { public: /** The constructor of a DatabaseCell. Note that if you specify the origin parameter, * it'll create a sub-segment based on the first one. Note also that this doesn't support - * the patching system, yet. + * the patching system, yet. data and origin are mutually exclusive. */ - DatabaseCell(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size, DatabaseCell * prev, Database * parent); + DatabaseCell(Database * parent, Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size = 0, const Byte * data = 0); ~DatabaseCell(); Uint32 getId() { return segment->getId(); } void LoadMemory(Handle * src) { segment->LoadMemory(src); } diff --git a/Database/internals/database-segment.h b/Database/internals/database-segment.h index f01ac38..dc4d157 100644 --- a/Database/internals/database-segment.h +++ b/Database/internals/database-segment.h @@ -44,6 +44,7 @@ class Segment : public Base { * @return the memory block of the segment. */ const Byte * getPristineMemory() { return plainmemory; } + const memory_tags_t * getMemoryTags() { return tags; } void Patch(Uint32 ptr, Byte val); void Restore(Uint32 ptr); bool IsPatched(Uint32 ptr); diff --git a/Loader/loader-psyq.cpp b/Loader/loader-psyq.cpp new file mode 100644 index 0000000..d6d8876 --- /dev/null +++ b/Loader/loader-psyq.cpp @@ -0,0 +1,20 @@ +#include "database.h" + +union psyq_header_t { + struct { + Uint8 id[8]; + Uint32 text, data, pc0, gp0, t_addr, t_size; + Uint32 d_addr, d_size, b_addr, b_size, s_addr, s_size; + Uint32 sp, fp, gp, ra, s0; + }; + Uint8 raw[0x800]; +}; + +class loader_psyq : public Base { + public: + static void load(Handle * input, Database * database) { + psyq_header_t head; + + input->read(&head, sizeof(head)); + } +}; diff --git a/Makefile b/Makefile index 52af23e..b7e3e1e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -DIRS=externals Utils Engine Lua Loader Database +DIRS=externals Database Cpu Engine Lua Loader Utils all: $(DIRS) -- cgit v1.2.3