Bug fix. Now works on 32-bit and with -O3.

git-svn-id: http://www.cdkersey.com/harp/harptool@120 0246edb2-e076-4747-b392-db732a341fa2
This commit is contained in:
chad
2013-01-18 11:07:23 +00:00
parent 707c7a19f1
commit 38ab04e988
5 changed files with 39 additions and 30 deletions

View File

@@ -1,7 +1,9 @@
################################################################################ ################################################################################
# HARPtools by Chad D. Kersey, Summer 2011 # # HARPtools by Chad D. Kersey, Summer 2011 #
################################################################################ ################################################################################
CXXFLAGS=-g #-DUSE_DEBUG=3 #-fPIC CXXFLAGS ?= -O3 # -g -DUSE_DEBUG=3 -fPIC
LDLIBS ?= -lharplib -pthread
LDFLAGS ?= -L.
LIB_OBJS=args.o obj.o mem.o core.o instruction.o enc.o util.o lex.yy.o LIB_OBJS=args.o obj.o mem.o core.o instruction.o enc.o util.o lex.yy.o
@@ -10,7 +12,7 @@ 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 # Use -static so we don't have to install the library in order to just run
# Harptool. # Harptool.
harptool: harptool.o libharplib.a harptool: harptool.o libharplib.a
$(CXX) -static -o $@ harptool.o -L. -lharplib -pthread $(CXX) $(LDFLAGS) -static -o $@ harptool.o $(LDLIBS)
libharplib.so: $(LIB_OBJS) libharplib.so: $(LIB_OBJS)
$(CXX) -shared -o $@ $(LIB_OBJS) $(CXX) -shared -o $@ $(LIB_OBJS)
@@ -23,9 +25,9 @@ enc.o : enc.cpp include/types.h include/util.h include/enc.h include/archdef.h\
include/instruction.h include/instruction.h
harptool.o : harptool.cpp include/types.h include/core.h include/enc.h \ harptool.o : harptool.cpp include/types.h include/core.h include/enc.h \
include/instruction.h include/mem.h include/obj.h \ include/instruction.h include/mem.h include/obj.h \
include/archdef.h include/args.h include/help.h include/archdef.h include/args.h include/help.h include/debug.h
instruction.o : instruction.cpp include/instruction.h include/obj.h \ instruction.o : instruction.cpp include/instruction.h include/obj.h \
include/core.h include/core.h include/debug.h
obj.o : obj.cpp include/types.h include/obj.h include/util.h \ obj.o : obj.cpp include/types.h include/obj.h include/util.h \
include/asm-tokens.h include/debug.h include/asm-tokens.h include/debug.h
util.o : util.cpp include/types.h include/util.h util.o : util.cpp include/types.h include/util.h

View File

@@ -240,7 +240,7 @@ static unsigned ceilLog2(RegNum x) {
} }
static Word mask(Size bits) { static Word mask(Size bits) {
return (1l<<bits)-1; return (1ull<<bits)-1;
} }
static void getSizes(const ArchDef &arch, Size &n, Size& o, Size &r, Size &p, static void getSizes(const ArchDef &arch, Size &n, Size& o, Size &r, Size &p,

View File

@@ -8,6 +8,7 @@
#include <fstream> #include <fstream>
#include <stdlib.h> #include <stdlib.h>
#include "include/debug.h"
#include "include/types.h" #include "include/types.h"
#include "include/core.h" #include "include/core.h"
#include "include/enc.h" #include "include/enc.h"
@@ -31,11 +32,11 @@ HarpToolMode findMode(int argc, char** argv) {
if (argc == 0) return HARPTOOL_MODE_HELP; if (argc == 0) return HARPTOOL_MODE_HELP;
CommandLineArgFlag("--help", "-h", "", mode_help); CommandLineArgFlag fh("--help", "-h", "", mode_help);
CommandLineArgFlag("-A", "--asm", "", mode_asm); CommandLineArgFlag fa("-A", "--asm", "", mode_asm);
CommandLineArgFlag("-D", "--disasm", "", mode_disasm); CommandLineArgFlag fd("-D", "--disasm", "", mode_disasm);
CommandLineArgFlag("-E", "--emu", "", mode_emu); CommandLineArgFlag fe("-E", "--emu", "", mode_emu);
CommandLineArgFlag("-L", "--ld", "", mode_ld); CommandLineArgFlag fl("-L", "--ld", "", mode_ld);
CommandLineArg::readArgs((argc == 0?0:1), argv); CommandLineArg::readArgs((argc == 0?0:1), argv);
CommandLineArg::clearArgs(); CommandLineArg::clearArgs();
@@ -53,9 +54,9 @@ int asm_main(int argc, char **argv) {
bool showHelp; bool showHelp;
/* Get command line arguments. */ /* Get command line arguments. */
CommandLineArgFlag("-h", "--help", "", showHelp); CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>("-o", "--output", "", outFileName); CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
CommandLineArgSetter<string>("-a", "--arch", "", archString); CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArg::readArgs(argc-1, argv); CommandLineArg::readArgs(argc-1, argv);
@@ -66,6 +67,8 @@ int asm_main(int argc, char **argv) {
ArchDef arch(archString); ArchDef arch(archString);
D(0, "Created ArchDef for " << string(arch));
/* Create an appropriate encoder. */ /* Create an appropriate encoder. */
Encoder *enc; Encoder *enc;
switch (arch.getEncChar()) { switch (arch.getEncChar()) {
@@ -96,6 +99,7 @@ int asm_main(int argc, char **argv) {
} }
/* Read an Obj from the assembly file. */ /* Read an Obj from the assembly file. */
D(0, "Passing AsmReader ArchDef: " << string(arch));
AsmReader ar(arch); AsmReader ar(arch);
Obj *o = ar.read(asmFile); Obj *o = ar.read(asmFile);
@@ -120,6 +124,7 @@ int asm_main(int argc, char **argv) {
delete enc; delete enc;
/* Write a HOF binary. */ /* Write a HOF binary. */
D(0, "Creating a HOFWriter, passing it ArchDef: " << string(arch));
HOFWriter hw(arch); HOFWriter hw(arch);
hw.write(outFile, *o); hw.write(outFile, *o);
outFile.close(); outFile.close();
@@ -135,9 +140,9 @@ int disasm_main(int argc, char **argv) {
/* Get command line arguments. */ /* Get command line arguments. */
CommandLineArgFlag("-h", "--help", "", showHelp); CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>("-a", "--arch", "", archString); CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArgSetter<string>("-o", "--output", "", outFileName); CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
if (argc != 0) CommandLineArg::readArgs(argc-1, argv); if (argc != 0) CommandLineArg::readArgs(argc-1, argv);
@@ -205,9 +210,9 @@ int emu_main(int argc, char **argv) {
bool showHelp; bool showHelp;
/* Read the command line arguments. */ /* Read the command line arguments. */
CommandLineArgFlag("-h", "--help", "", showHelp); CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>("-c", "--core", "", imgFileName); CommandLineArgSetter<string>fc("-c", "--core", "", imgFileName);
CommandLineArgSetter<string>("-a", "--arch", "", archString); CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArg::readArgs(argc, argv); CommandLineArg::readArgs(argc, argv);
@@ -249,11 +254,11 @@ int ld_main(int argc, char **argv) {
Addr binOffset(0); Addr binOffset(0);
/* Get command line arguments. */ /* Get command line arguments. */
CommandLineArgFlag("-h", "--help", "", showHelp); CommandLineArgFlag fh("-h", "--help", "", showHelp);
CommandLineArgSetter<string>("-a", "--arch", "", archString); CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
CommandLineArgSetter<string>("-f", "--format", "", formatString); CommandLineArgSetter<string>ff("-f", "--format", "", formatString);
CommandLineArgSetter<Addr>("--offset", "", binOffset); CommandLineArgSetter<Addr> foffset("--offset", "", binOffset);
CommandLineArgSetter<string>("-o", "--output", "", outFileName); CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
int firstInput(0), newArgc; int firstInput(0), newArgc;
for (size_t i = 0; i < argc; i++) { for (size_t i = 0; i < argc; i++) {

View File

@@ -11,6 +11,7 @@
#include "archdef.h" #include "archdef.h"
#include "enc.h" #include "enc.h"
#include "mem.h" #include "mem.h"
#include "debug.h"
namespace Harp { namespace Harp {
#ifdef EMU_INSTRUMENTATION #ifdef EMU_INSTRUMENTATION

View File

@@ -57,18 +57,19 @@ namespace Harp {
{} {}
virtual void bind(Addr addr, Addr base = 0) { virtual void bind(Addr addr, Addr base = 0) {
Size bytes = bits/8, remainder = bits%8, i; Size bytes(bits/8), remainder(bits%8);
if (relative) { if (relative) {
addr = addr - base; addr = addr - base;
Word_s addr_s(addr); Word_s addr_s(addr);
if ((addr_s >> bits) != -1 && (addr_s >> bits) != 0) goto noFit; if ((addr_s >> bits) != ~0ull && (addr_s >> bits) != 0) goto noFit;
} else { } else {
Addr mask = (1ll<<bits)-1; Addr mask = (1ull<<bits)-1;
if (addr > mask) goto noFit; if (addr > mask) goto noFit;
} }
{ Byte mask((1<<remainder) - 1); { Byte mask((1ull<<remainder) - 1);
Size i;
for (i = 0; i < bytes; i++) { for (i = 0; i < bytes; i++) {
data[offset+i] = addr & 0xff; data[offset+i] = addr & 0xff;
addr >>= 8; addr >>= 8;
@@ -176,7 +177,7 @@ namespace Harp {
class HOFReader : public ObjReader { class HOFReader : public ObjReader {
public: public:
HOFReader(ArchDef arch) : arch(arch) {} HOFReader(ArchDef &arch) : arch(arch) {}
Obj *read(std::istream &input); Obj *read(std::istream &input);
private: private:
const ArchDef &arch; const ArchDef &arch;
@@ -192,7 +193,7 @@ namespace Harp {
class HOFWriter : public ObjWriter { class HOFWriter : public ObjWriter {
public: public:
HOFWriter(ArchDef arch) : arch(arch) {} HOFWriter(ArchDef &arch) : arch(arch) {}
virtual void write(std::ostream &output, const Obj &obj); virtual void write(std::ostream &output, const Obj &obj);
private: private:
const ArchDef &arch; const ArchDef &arch;