From 4428bcd1b7afbeb9be5cf269c43cb591dac5d7ef Mon Sep 17 00:00:00 2001 From: chad Date: Thu, 17 Jan 2013 09:04:30 +0000 Subject: [PATCH] Additional debugging info. git-svn-id: http://www.cdkersey.com/harp/harptool@115 0246edb2-e076-4747-b392-db732a341fa2 --- src/BUGS | 1 + src/Makefile | 8 ++++---- src/include/core.h | 4 ++-- src/include/debug.h | 6 +++++- src/mem.cpp | 2 +- src/obj.cpp | 9 ++++++++- src/test/sieve.s | 28 ++++++++++++++++++++-------- 7 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/BUGS b/src/BUGS index e69de29b..106e120e 100644 --- a/src/BUGS +++ b/src/BUGS @@ -0,0 +1 @@ +_ Large expanses of space intentionally \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 1fc782d3..e0a8eb0b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,11 @@ ################################################################################ # HARPtools by Chad D. Kersey, Summer 2011 # ################################################################################ -CXXFLAGS=-g -fPIC -DUSE_DEBUG=3 +CXXFLAGS=-g -DUSE_DEBUG=1 #-fPIC LIB_OBJS=args.o obj.o mem.o core.o instruction.o enc.o util.o lex.yy.o -all: harptool libharplib.so libharplib.a #libqsim-harp.so +all: harptool # libharplib.so libharplib.a libqsim-harp.so # Use -static so we don't have to install the library in order to just run # Harptool. @@ -26,9 +26,9 @@ harptool.o : harptool.cpp include/types.h include/core.h include/enc.h \ include/archdef.h include/args.h include/help.h instruction.o : instruction.cpp include/instruction.h include/obj.h obj.o : obj.cpp include/types.h include/obj.h include/util.h \ - include/asm-tokens.h + include/asm-tokens.h include/debug.h util.o : util.cpp include/types.h include/util.h -mem.o : mem.cpp include/types.h include/util.h include/mem.h +mem.o : mem.cpp include/types.h include/util.h include/mem.h include/debug.h core.o : core.cpp include/types.h include/util.h include/mem.h \ include/debug.h include/archdef.h diff --git a/src/include/core.h b/src/include/core.h index 4ec87d34..9dbc5470 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -20,8 +20,8 @@ namespace Harp { template class Reg { public: - Reg(): cpuId(0), regNum(0) {} - Reg(Word c, Word n): cpuId(c), regNum(n) {} + Reg(): cpuId(0), regNum(0), val(0) {} + Reg(Word c, Word n): cpuId(c), regNum(n), val(0) {} Reg &operator=(T r) { val = r; doWrite(); return *this; } operator T() { doRead(); return val; } diff --git a/src/include/debug.h b/src/include/debug.h index 9f83f763..42a296c7 100644 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -10,10 +10,14 @@ #define D(lvl, x) do { \ using namespace std; \ if ((lvl) <= USE_DEBUG) { \ - cout << "DEBUG " << __FILE__ << ':' << dec << __LINE__ << ": " \ + cerr << "DEBUG " << __FILE__ << ':' << dec << __LINE__ << ": " \ << x << endl; \ } \ } while(0) + +#define D_RAW(x) do { \ + std::cerr << x; \ +} while (0) #else #define D(lvl, x) do {} while(0) diff --git a/src/mem.cpp b/src/mem.cpp index 732e7402..bffff41e 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -24,7 +24,7 @@ RamMemDevice::RamMemDevice(const char *filename, Size wordSize) : ifstream input(filename); if (!input) { - cout << "Error reading file \"" << filename << "\" into RomMemDevice.\n"; + cout << "Error reading file \"" << filename << "\" into RamMemDevice.\n"; exit(1); } diff --git a/src/obj.cpp b/src/obj.cpp index 14c77fbf..d71c149a 100644 --- a/src/obj.cpp +++ b/src/obj.cpp @@ -5,6 +5,7 @@ #include "include/obj.h" #include "include/util.h" #include "include/asm-tokens.h" +#include "include/debug.h" #include #include @@ -485,9 +486,13 @@ void HOFWriter::write(std::ostream &output, const Obj &obj) { for (Size i = 0; i < obj.chunks.size(); i++) { offsets[i] = output.tellp(); - /* Chunk name */ + // Is it a data chunk? DataChunk *dc = dynamic_cast(obj.chunks[i]); if (!dc) { cout << "HOFWriter::write(): invalid chunk type.\n"; exit(1); } + + D(1, "Writing chunk \"" << dc->name << "\", size=" << dc->contents.size()); + + // Chunk name output.write(dc->name.c_str(), dc->name.length() + 1); /* Padding */ @@ -625,6 +630,8 @@ Obj *HOFReader::read(std::istream &input) { dc->refs.push_back(r); } + D(1, "Reading chunk \"" << name << "\", size " << dSize); + /* Get the contents. */ input.read((char*)&dc->contents[0], dSize); dc->size = size; diff --git a/src/test/sieve.s b/src/test/sieve.s index 82c5dc9b..3ea73b1c 100644 --- a/src/test/sieve.s +++ b/src/test/sieve.s @@ -6,24 +6,33 @@ *******************************************************************************/ /* sieve of erastophanes: Find some primes. */ -.def SIZE 0x2000 /* TODO: How should I write constants? */ +.def SIZE 0x1000 .align 4096 .perm x .entry .global -entry: ldi %r7, hello - jali %r5, puts +entry: ldi %r7, hello; jali %r5, puts; + ldi %r0, #2; /* i = 2 */ -loop1: muli %r1, %r0, __WORD; +loop1: addi %r7, %r0, #0; + jali %r5, printdec; + + muli %r1, %r0, __WORD; + ldi %r7, wrstr; + jali %r5, puts; st %r0, %r1, array; + ldi %r7, wrfin; + jali %r5, puts; addi %r0, %r0, #1; subi %r1, %r0, SIZE; rtop @p0, %r1; @p0 ? jmpi loop1; - ldi %r0, #1; - + ldi %r7, xstr; + jali %r5, puts; + + ldi %r0, #1; loop2: addi %r0, %r0, #1; muli %r1, %r0, __WORD; ld %r1, %r1, array; @@ -69,10 +78,13 @@ loop4: ld %r1, %r0, array; trap; /* All traps currently cause a halt. */ .perm rw /* TODO: How should I write section permissions? */ -/* TODO: String literals! */ .string hello "\"Harp!\" is how a harp seal says hello!\n" +.string wrstr "Doing write\n" +.string wrfin "Done write\n" +.string xstr "Exiting loop\n" .global .word array 0 /* Basically, 0 and 1 are pre-cleared. */ .word _0 0 /* Given a name, contents are zero. */ -.word 0x1ffe /* Empty space of size SIZE-2 bytes. */ +_arr: +.word 0xffe /* Empty space of size SIZE-2 words. */