From 1f7ca9fd3964481318bbaddfb39acc5de8c7d65d Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 20 Sep 2009 23:10:31 +0200 Subject: Basic makefile structure; making the project at least compilable. --- .gitmodules | 3 +++ Database/Makefile | 17 +++++++++++++ Database/database-types.h | 5 ++++ Database/database.h | 22 +++++++++++++++++ Database/internals/database-internal.cpp | 5 ++-- Database/internals/database-internal.h | 4 ++-- Database/internals/database-references.cpp | 11 +++++---- Database/internals/database-references.h | 18 ++++++++------ Database/internals/database-segment.cpp | 16 ++++++++----- Database/internals/database-segment.h | 3 ++- Makefile | 17 +++++++++++++ Makefile.cfg | 38 ++++++++++++++++++++++++++++++ Utils/Makefile | 13 ++++++++++ Utils/allocator.h | 13 ++++++++++ Utils/log.cpp | 0 Utils/log.h | 8 +++++++ externals/Base | 1 + externals/Makefile | 24 +++++++++++++++++++ 18 files changed, 196 insertions(+), 22 deletions(-) create mode 100644 .gitmodules create mode 100644 Database/Makefile create mode 100644 Database/database.h create mode 100644 Makefile create mode 100644 Makefile.cfg create mode 100644 Utils/Makefile create mode 100644 Utils/allocator.h create mode 100644 Utils/log.cpp create mode 100644 Utils/log.h create mode 160000 externals/Base create mode 100644 externals/Makefile diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..34fa524 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "externals/Base"] + path = externals/Base + url = /pub/repo.git/Baltisot diff --git a/Database/Makefile b/Database/Makefile new file mode 100644 index 0000000..4e6b2ff --- /dev/null +++ b/Database/Makefile @@ -0,0 +1,17 @@ +TARGET = Database.a + +SRCS = \ +database-internal.cpp \ +database-references.cpp \ +database-segment.cpp \ + +SPATH = internals + +CPPFLAGS = -Iinternals -I. + +include ../Makefile.cfg + +$(TARGET): $(OBJS) + $(AR) $@ $^ + +-include $(DEPS) diff --git a/Database/database-types.h b/Database/database-types.h index 7d92f87..49db9b8 100644 --- a/Database/database-types.h +++ b/Database/database-types.h @@ -1,6 +1,8 @@ #ifndef __DATABASE_TYPES_H__ #define __DATABASE_TYPES_H__ +#include + /** The basic tags that describe the bytes of the database. The tag "CODE_FIRST_BYTE" is * mainly for multi-bytes instructions, in order to help the UI displaying * properly the instructions. @@ -36,6 +38,9 @@ typedef union { }; } absolute_ptr; +static inline Uint32 SEGID(absolute_ptr ptr) { return ptr.segment_id; } +static inline Uint32 SEGOFFSET(absolute_ptr ptr) { return ptr.ptr; } + /** A function description. */ diff --git a/Database/database.h b/Database/database.h new file mode 100644 index 0000000..dffaaf5 --- /dev/null +++ b/Database/database.h @@ -0,0 +1,22 @@ +#ifndef __DATABASE_H__ +#define __DATABASE_H__ + +#include "database-types.h" +#include "database-segment.h" +#include "database-internal.h" + +class Database : public Base { + public: + Database(); + ~Database(); + DatabaseCell * getStart() { return start; } + DatabaseCell * getEnd() { return end; } + void setStart(DatabaseCell * newStart) { start = newStart; } + void setEnd(DatabaseCell * newEnd) { end = newEnd; } + Segment * getSegment(Uint32 id); + Uint32 GetNextSegId(); + private: + DatabaseCell * start, * end; +}; + +#endif diff --git a/Database/internals/database-internal.cpp b/Database/internals/database-internal.cpp index e19222a..e564c01 100644 --- a/Database/internals/database-internal.cpp +++ b/Database/internals/database-internal.cpp @@ -1,10 +1,11 @@ #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; parent->setEnd(this); - if (origin) { - Segment * origin_seg = parent->GetSegment(SEGID(origin)); + 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); diff --git a/Database/internals/database-internal.h b/Database/internals/database-internal.h index f63b40e..5ca6050 100644 --- a/Database/internals/database-internal.h +++ b/Database/internals/database-internal.h @@ -19,9 +19,9 @@ class DatabaseCell : public Base { * it'll create a sub-segment based on the first one. Note also that this doesn't support * the patching system, yet. */ - DatabaseCell(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size, DatabaseCell * prev); + DatabaseCell(Cpu * cpu, Uint64 cpu_base, absolute_ptr origin, Uint32 size, Uint32 extra_size, DatabaseCell * prev, Database * parent); ~DatabaseCell(); - Uint32 getID() { return segment->GetID(); } + Uint32 getID() { return segment->getId(); } void LoadMemory(Handle * src) { segment->LoadMemory(src); } Segment * getSegment() { return segment; } Cpu * getCpu() { return cpu; } diff --git a/Database/internals/database-references.cpp b/Database/internals/database-references.cpp index c138698..30841bf 100644 --- a/Database/internals/database-references.cpp +++ b/Database/internals/database-references.cpp @@ -1,12 +1,15 @@ +#include + #include "database-references.h" +#include "database.h" RefFrom::RefFrom(RefTo * refTo, SegmentRefData * data) : refTo(refTo), data(data) { - assert(refto); + assert(refTo); assert(data); next = data->getRefFrom(); prev = 0; - data->firstRefFrom = this; + data->setFirstRefFrom(this); if (next) next->prev = this; } @@ -24,7 +27,7 @@ RefTo::RefTo(absolute_ptr ptr, SegmentRefData * data, Database * database) : dat assert(database); Segment * destSeg = database->getSegment(ptr.segment_id); assert(destSeg); - refFrom = new RefFrom(this, destSeg->getSegmentRefData(ptr.ptr); + refFrom = new RefFrom(this, destSeg->getSegmentRefData(ptr.ptr)); RefTo * t = data->getRefTo(); if (t) { @@ -34,7 +37,7 @@ RefTo::RefTo(absolute_ptr ptr, SegmentRefData * data, Database * database) : dat } RefTo::~RefTo() { - data->refTo = 0; + data->setRefTo(0); delete refFrom; } diff --git a/Database/internals/database-references.h b/Database/internals/database-references.h index 278b531..6ad64bd 100644 --- a/Database/internals/database-references.h +++ b/Database/internals/database-references.h @@ -1,9 +1,10 @@ #ifndef __DATABASE_REFERENCES_H__ #define __DATABASE_REFERENCES_H__ -class SegmentData; -class RefFrom; +#include "database-segment.h" + class RefTo; +class Database; /** The reference system, where the database will be able to hold references from and to memory pointers. */ @@ -11,8 +12,8 @@ class RefTo; class RefFrom : public Base { public: RefFrom(RefTo * refTo, SegmentRefData * data); - ~RefFrom() - SegmentRefData * getRefSegData() { return refTo->getSegRefData(); } + ~RefFrom(); + SegmentRefData * getRefSegData(); SegmentRefData * getSegRefData() { return data; } RefFrom * getNext() { return next; } private: @@ -23,19 +24,22 @@ class RefFrom : public Base { class RefTo : public Base { public: - RefTo(Uint32 ptr, SegmentRefData * data); + RefTo(absolute_ptr ptr, SegmentRefData * data, Database *); ~RefTo(); - SegmentRefData * getRefSegData() { return refFrom->getSegRefData(); } + SegmentRefData * getRefSegData(); SegmentRefData * getSegRefData() { return data; } private: RefFrom * refFrom; SegmentRefData * data; }; +inline SegmentRefData * RefFrom::getRefSegData() { return refTo->getSegRefData(); } +inline SegmentRefData * RefTo::getRefSegData() { return refFrom->getSegRefData(); } + class SegmentRefData : public Base { public: SegmentRefData(Uint32 ptr, Segment * seg); - ~SegmentRefData() + ~SegmentRefData(); Uint32 getPtr() { return ptr; } Segment * getSegment() { return seg; } SegmentRefData * getSegmentRefData(Uint32 ptr) { return seg->getSegmentRefData(ptr); } diff --git a/Database/internals/database-segment.cpp b/Database/internals/database-segment.cpp index 55689f8..8ee5b4b 100644 --- a/Database/internals/database-segment.cpp +++ b/Database/internals/database-segment.cpp @@ -1,6 +1,10 @@ +#include + +#include +#include #include "database-segment.h" -Segment::Segment(Uint32 size, Uint32 id, Uint64 cpu_base, Uint32 extra_size, const Byte * data) : patches(0), plainmemory(0), size(size), extra_size(extra_size), id(id), cpu_base(cpu_base) { +Segment::Segment(Uint32 size, Uint32 id, Uint64 cpu_base, Uint32 extra_size, const Byte * data) : plainmemory(0), patches(0), size(size), extra_size(extra_size), id(id), cpu_base(cpu_base) { Uint64 fullsize = size + extra_size; assert(size); @@ -8,7 +12,7 @@ Segment::Segment(Uint32 size, Uint32 id, Uint64 cpu_base, Uint32 extra_size, con if (data) { plainmemory = (Byte *) data; loaded = true; - allocated = false + allocated = false; } else { plainmemory = Allocator::alloc(size); loaded = false; @@ -23,7 +27,7 @@ Segment::~Segment() { Allocator::free(plainmemory); if (patches) Allocator::free(patches); - if (patchesmemory) + if (patchesmap) Allocator::free(patchesmap); Allocator::free(tags); Allocator::free(refData); @@ -82,10 +86,10 @@ void Segment::LoadMemory(Handle * src) { return; } - src->Read(plainmemory, size); + src->read(plainmemory, size); } -void setTag(Uint32 ptr, memory_tags_t tag) { +void Segment::setTag(Uint32 ptr, memory_tags_t tag) { if (ptr >= (size + extra_size)) { LOG(CONSOLE, ERROR, "Out of bound setTag attempt in segment %i at %08X\n", id, ptr); return; @@ -93,7 +97,7 @@ void setTag(Uint32 ptr, memory_tags_t tag) { tags[ptr] = tag; } -memory_tags_t getTag(Uint32 ptr) { +memory_tags_t Segment::getTag(Uint32 ptr) { if (ptr >= (size + extra_size)) { memory_tags_t z = { 0, 0 }; LOG(CONSOLE, ERROR, "Out of bound getTag attempt in segment %i at %08X\n", id, ptr); diff --git a/Database/internals/database-segment.h b/Database/internals/database-segment.h index a08b149..f01ac38 100644 --- a/Database/internals/database-segment.h +++ b/Database/internals/database-segment.h @@ -1,6 +1,7 @@ #ifndef __DATABASE_SEGMENT_H__ #define __DATABASE_SEGMENT_H__ +#include #include "database-types.h" class SegmentRefData; @@ -67,6 +68,6 @@ class Segment : public Base { Uint32 size, extra_size; Uint32 id; Uint64 cpu_base; -} +}; #endif diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1767149 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +DIRS=externals Utils Database + +all: $(DIRS) + +clean: clean-dirs + +clean-dirs: + for i in $(DIRS) ; do $(MAKE) -C $$i clean ; done + +.PHONY: $(DIRS) + +define DIR_template +$(1): + $$(MAKE) -C $$@ +endef + +$(foreach dir, $(DIRS), $(eval $(call DIR_template, $(dir)))) diff --git a/Makefile.cfg b/Makefile.cfg new file mode 100644 index 0000000..0b5a803 --- /dev/null +++ b/Makefile.cfg @@ -0,0 +1,38 @@ +vpath %.c $(SPATH) +vpath %.cc $(SPATH) +vpath %.cpp $(SPATH) + +AR = ar rcs +CC = gcc +CXX = g++ +RM = rm -f +LD = g++ + +HAVES += -DHAVE_VSSCANF -DHAVE_FCNTL -DHAVE_UNISTD_H -DHAVE_FORK -DHAVE_PIPE -DHAVE_FSYNC -DHAVE_MALLOC_H -DHAVE_ASPRINTF -DHAVE_BYTESWAP_H + +DEBUG_FLAGS = -g -D_DEBUG +RELEASE_FLAGS = -O3 -fno-strict-aliasing -DNDEBUG + +CPPFLAGS += -Wall -I../externals/Base/include -I../Utils +CPPFLAGS += -DWORDS_LITTLEENDIAN +CPPFLAGS += $(HAVES) +CPPFLAGS += $(DEBUG_FLAGS) + +OBJS = $(addsuffix .o, $(notdir $(basename $(SRCS)))) +DEPS = $(addsuffix .dep, $(notdir $(basename $(SRCS)))) + +all: dep $(TARGET) + +dep: $(DEPS) + +clean: + $(RM) $(OBJS) $(DEPS) $(TARGET) + +%.dep : %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -M -MF $@ $< + +%.dep : %.cc + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MF $@ $< + +%.dep : %.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MF $@ $< diff --git a/Utils/Makefile b/Utils/Makefile new file mode 100644 index 0000000..1b001a8 --- /dev/null +++ b/Utils/Makefile @@ -0,0 +1,13 @@ +TARGET = Utils.a + +SRCS = \ +log.cpp \ + +CPPFLAGS = -I. + +include ../Makefile.cfg + +$(TARGET): $(OBJS) + $(AR) $@ $^ + +-include $(DEPS) diff --git a/Utils/allocator.h b/Utils/allocator.h new file mode 100644 index 0000000..8b0fdb6 --- /dev/null +++ b/Utils/allocator.h @@ -0,0 +1,13 @@ +#ifndef __ALLOCATOR_H__ +#define __ALLOCATOR_H__ + +#include + +template +class Allocator { + public: + static T * alloc(int n) { return (T*) calloc(n, sizeof(T)); }; + static void free(T * & ptr) { free(ptr); ptr = 0; } +}; + +#endif diff --git a/Utils/log.cpp b/Utils/log.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Utils/log.h b/Utils/log.h new file mode 100644 index 0000000..33b03d7 --- /dev/null +++ b/Utils/log.h @@ -0,0 +1,8 @@ +#ifndef __LOG_H__ +#define __LOG_H__ + +#define LOG(...) +#define CONSOLE +#define ERROR + +#endif diff --git a/externals/Base b/externals/Base new file mode 160000 index 0000000..6d1dee6 --- /dev/null +++ b/externals/Base @@ -0,0 +1 @@ +Subproject commit 6d1dee65d5ad695670d73bf3e162b4b6e984af35 diff --git a/externals/Makefile b/externals/Makefile new file mode 100644 index 0000000..57d7d16 --- /dev/null +++ b/externals/Makefile @@ -0,0 +1,24 @@ +TARGET = externals.a + +SRCS = \ +Handle.cpp \ +String.cpp \ +Exceptions.cpp \ +Input.cpp \ +Output.cpp \ +Buffer.cpp \ +generic.cpp \ +checkargs.c \ +datecalc.c \ +hashtab.c \ +lookupa.c \ +recycle.c \ + +SPATH = Base/lib + +include ../Makefile.cfg + +$(TARGET): $(OBJS) + $(AR) $@ $^ + +-include $(DEPS) -- cgit v1.2.3