diff options
author | pixel <pixel> | 2004-01-03 15:04:46 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-01-03 15:04:46 +0000 |
commit | a422d1dcda810b2f129a9a5213f3f4b440be4bbc (patch) | |
tree | a0735a7f3c61f398fc13a45466ded187904bbe21 /includes | |
parent | 24ae6e6865351db7d3a9e58340e5a2684912544f (diff) |
Highly started work on mips disassembler + various little fixes.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/isobuilder.h | 4 | ||||
-rw-r--r-- | includes/mips.h | 57 | ||||
-rw-r--r-- | includes/mipsdis.h | 54 | ||||
-rw-r--r-- | includes/mipsdump.h | 73 | ||||
-rw-r--r-- | includes/mipsmem.h | 114 |
5 files changed, 254 insertions, 48 deletions
diff --git a/includes/isobuilder.h b/includes/isobuilder.h index e073500..3a5de00 100644 --- a/includes/isobuilder.h +++ b/includes/isobuilder.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: isobuilder.h,v 1.8 2003-12-11 16:53:42 pixel Exp $ */ +/* $Id: isobuilder.h,v 1.9 2004-01-03 15:04:47 pixel Exp $ */ #ifndef __ISOBUILDER_H__ #define __ISOBUILDER_H__ @@ -87,7 +87,7 @@ class isobuilder : public Base { static PVD createpvd(Handle *); static PVD createpvd(cdutils *); static PVD createpvd(Byte *); - void close(Handle * cue = 0, int mode = -1) throw (GeneralException); + void close(Handle * cue = 0, int mode = -1, int nsects = -1) throw (GeneralException); private: Handle * w; int sector, nsectors; diff --git a/includes/mips.h b/includes/mips.h index 814120f..8ace76f 100644 --- a/includes/mips.h +++ b/includes/mips.h @@ -1,53 +1,18 @@ #ifndef __MIPS_H__ #define __MIPS_H__ -#include <Exceptions.h> -#include <generic.h> -#include <Handle.h> -class mips : public Base { - public: - Uint8 Read8(Uint32); - Uint16 Read16(Uint32); - Uint32 Read32(Uint32); - void Write8(Uint32, Uint8); - void Write16(Uint32, Uint16); - void Write32(Uint32, Uint32); - void unpatch8(Uint32); - void unpatch16(Uint32); - void unpatch32(Uint32); - bool IsPatched(Uint32); - void LoadPSYQ(Handle *); - void SavePSYQ(Handle *); - Uint32 GetPC(); - void disassemble(Uint32); - private: - void patch(Uint32, int); - void unpatch(Uint32, int); - Uint8 psyqhead[0x800]; - Uint8 plainmemory[0x200000]; - Uint8 patches[0x200000]; - Uint8 patchesmap[0x200000 / 8]; - Uint32 paddr, psize, startpc; - - struct psyq { - 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; - }; -}; +#include "mipsdis.h" + +void decode(TDis * d, Uint32 pc); -class TDis : public Base { - public: - TDis(Uint32); - void setInstruction(String); - void setAddress(Uint32); - void addArgReg(int); - void addArgImm(Uint32); - void addArgRelative(Uint32); - void addArgAbsolute(Uint32); - private: - Uint32 pc; +enum registers { + Rzr, Rat, Rv0, Rv1, Ra0, Ra1, Ra2, Ra3, + Rt0, Rt1, Rt2, Rt3, Rt4, Rt5, Rt6, Rt7, + Rs0, Rs1, Rs2, Rs3, Rs4, Rs5, Rs6, Rs7, + Rt8, Rt9, Rk0, Rk1, Rgp, Rsp, Rfp, Rra, }; +extern char * registers[]; +extern char * CP0registers[]; + #endif diff --git a/includes/mipsdis.h b/includes/mipsdis.h new file mode 100644 index 0000000..5ce2506 --- /dev/null +++ b/includes/mipsdis.h @@ -0,0 +1,54 @@ +#ifndef __MIPSDIS_H__ +#define __MIPSDIS_H__ +#include <Exceptions.h> +#include <queue> +#include "mipsmem.h" + +class TDis : public Base { + public: + TDis(mipsmem *); + virtual mipsmem * getmem(); + virtual void add_branch(Uint32); + virtual void add_jump(Uint32); + virtual void add_function(Uint32); + virtual void SetTag(Uint32, int, bool); + virtual void Name(const String &); + virtual void PushGPReg(int); + virtual void PushCPReg(int); + virtual void PushImm(Uint32); + virtual void PushTarget(Uint32); + virtual void PushSa(Uint32); + virtual void PushOfB(int reg, Uint32, int); + virtual void PushOffset(Uint32); + virtual void PushFull(Uint32); + virtual void Invalid(); + virtual void Suspect(); + virtual void Comment(const String &); + + virtual void reset(); + + bool invalid; + std::priority_queue<int, std::vector<int>, std::greater<int> > bheap; + std::priority_queue<int, std::vector<int>, std::greater<int> > jheap; + std::priority_queue<int, std::vector<int>, std::greater<int> > fheap; + + Uint32 pc; + private: + mipsmem * mm; +}; + +class Disassembler : public Base { + public: + Disassembler(mipsmem *); + virtual ~Disassembler(); + void mainloop(); + void crawl_code(Uint32 = 0xffffffff); + private: + mipsmem * mm; + TDis * dis; + bool started; + bool infunction; +}; + + +#endif diff --git a/includes/mipsdump.h b/includes/mipsdump.h new file mode 100644 index 0000000..a6c6288 --- /dev/null +++ b/includes/mipsdump.h @@ -0,0 +1,73 @@ +#ifndef __MIPSDUMP_H__ +#define __MIPSDUMP_H__ + +#include <Exceptions.h> +#include <mipsdis.h> + +enum arg_type { + T_GPREGISTER, + T_CPREGISTER, + T_IMM8, + T_IMM16, + T_IMM32, + T_OFB, +}; + +union arg { + Uint32 v; + struct { + Uint32 o; + int r; + int w; + } OfB; +}; + +template<class T1, class T2> +struct mypair { + T1 left; + T2 right; +}; + +typedef mypair<int, arg> pairarg; + +class TDump : public TDis { + public: + TDump(mipsmem *); + virtual void add_branch(Uint32); + virtual void add_jump(Uint32); + virtual void add_function(Uint32); + virtual void SetTag(Uint32, int, bool); + virtual void Name(const String &); + virtual void PushGPReg(int); + virtual void PushCPReg(int); + virtual void PushImm(Uint32); + virtual void PushTarget(Uint32); + virtual void PushSa(Uint32); + virtual void PushOfB(int reg, Uint32, int); + virtual void PushOffset(Uint32); + virtual void PushFull(Uint32); + virtual void Invalid(); + virtual void Suspect(); + virtual void Comment(const String &); + + virtual void reset(); + + String name; + std::vector<pairarg> args; + String comments; + + Uint32 tg; + + bool invalid, hasbr, hastg, hasfc; +}; + +class Dumper : public Base { + public: + Dumper(mipsmem *); + void process(); + private: + TDump * dump; + mipsmem * mm; +}; + +#endif diff --git a/includes/mipsmem.h b/includes/mipsmem.h new file mode 100644 index 0000000..f763af8 --- /dev/null +++ b/includes/mipsmem.h @@ -0,0 +1,114 @@ +#ifndef __MIPSMEM_H__ +#define __MIPSMEM_H__ +#define PSXMEM 0x200000 + +#include <Exceptions.h> +#include <Handle.h> + +enum tags_t { + CODE, + DATA, + STOP, + INVALID, +}; + +class memdata; + +class func_t : public Base { + public: + func_t(); + virtual ~func_t(); + Uint32 endpc; + Uint8 stacksize; +}; + +class refto_t; +class reffrom_t : public Base { + public: + reffrom_t(refto_t *, memdata *); + virtual ~reffrom_t(); + memdata * getref(); + memdata * getmem(); + reffrom_t * getnext(); + private: + refto_t * refto; + reffrom_t * next, * prev; + memdata * header; +}; + +class refto_t : public Base { + public: + refto_t(Uint32, memdata *); + virtual ~refto_t(); + memdata * getref(); + memdata * getmem(); + private: + reffrom_t * reffrom; + memdata * mem; +}; + +class mipsmem; +class memdata : public Base { + public: + memdata(Uint32, mipsmem *); + virtual ~memdata(); + Uint32 getaddress(); + memdata * getmem(Uint32); + static memdata * getmem(Uint32, mipsmem *); + func_t * getfunc(); + refto_t * getrefto(); + reffrom_t * getreffrom(); + void setfunc(func_t *); + void setrefto(refto_t *); + void setreffrom(reffrom_t *); + private: + void checkdestroy(); + Uint32 address; + mipsmem * mm; + func_t * func; + refto_t * refto; + reffrom_t * reffrom; +}; + +class mipsmem : public Base { + public: + mipsmem(); + Uint8 Read8(Uint32 addr); + Uint16 Read16(Uint32 addr); + Uint32 Read32(Uint32 addr); + void Write8(Uint32 addr, Uint8); + void Write16(Uint32 addr, Uint16); + void Write32(Uint32 addr, Uint32); + void unpatch8(Uint32 addr); + void unpatch16(Uint32 addr); + void unpatch32(Uint32 addr); + bool IsPatched(Uint32 addr); + void LoadPSYQ(Handle *); + void SavePSYQ(Handle *); + bool GetTag(Uint32 addr, char tag); + void SetTag(Uint32 addr, char tag, bool); + memdata * GetDatas(Uint32 addr); + void SetDatas(Uint32 addr, memdata * p); + Uint32 GetPC(); + Uint32 GetLower(); + Uint32 GetUpper(); + private: + void patch(Uint32, int); + void unpatch(Uint32, int); + Uint8 psyqhead[0x800]; + Uint8 plainmemory[PSXMEM]; + Uint8 patches[PSXMEM]; + Uint8 patchesmap[PSXMEM / 8]; + Uint8 tags[PSXMEM]; + memdata * datas[PSXMEM]; + Uint32 paddr, psize, startpc; + + struct psyq { + 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; + }; +}; + +#endif |