mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-24 05:47:35 -04:00
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:
parent
707c7a19f1
commit
38ab04e988
5 changed files with 39 additions and 30 deletions
10
src/Makefile
10
src/Makefile
|
@ -1,7 +1,9 @@
|
|||
################################################################################
|
||||
# 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
|
||||
|
||||
|
@ -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
|
||||
# Harptool.
|
||||
harptool: harptool.o libharplib.a
|
||||
$(CXX) -static -o $@ harptool.o -L. -lharplib -pthread
|
||||
$(CXX) $(LDFLAGS) -static -o $@ harptool.o $(LDLIBS)
|
||||
|
||||
libharplib.so: $(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
|
||||
harptool.o : harptool.cpp include/types.h include/core.h include/enc.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 \
|
||||
include/core.h
|
||||
include/core.h include/debug.h
|
||||
obj.o : obj.cpp include/types.h include/obj.h include/util.h \
|
||||
include/asm-tokens.h include/debug.h
|
||||
util.o : util.cpp include/types.h include/util.h
|
||||
|
|
|
@ -240,7 +240,7 @@ static unsigned ceilLog2(RegNum x) {
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "include/debug.h"
|
||||
#include "include/types.h"
|
||||
#include "include/core.h"
|
||||
#include "include/enc.h"
|
||||
|
@ -31,11 +32,11 @@ HarpToolMode findMode(int argc, char** argv) {
|
|||
|
||||
if (argc == 0) return HARPTOOL_MODE_HELP;
|
||||
|
||||
CommandLineArgFlag("--help", "-h", "", mode_help);
|
||||
CommandLineArgFlag("-A", "--asm", "", mode_asm);
|
||||
CommandLineArgFlag("-D", "--disasm", "", mode_disasm);
|
||||
CommandLineArgFlag("-E", "--emu", "", mode_emu);
|
||||
CommandLineArgFlag("-L", "--ld", "", mode_ld);
|
||||
CommandLineArgFlag fh("--help", "-h", "", mode_help);
|
||||
CommandLineArgFlag fa("-A", "--asm", "", mode_asm);
|
||||
CommandLineArgFlag fd("-D", "--disasm", "", mode_disasm);
|
||||
CommandLineArgFlag fe("-E", "--emu", "", mode_emu);
|
||||
CommandLineArgFlag fl("-L", "--ld", "", mode_ld);
|
||||
|
||||
CommandLineArg::readArgs((argc == 0?0:1), argv);
|
||||
CommandLineArg::clearArgs();
|
||||
|
@ -53,9 +54,9 @@ int asm_main(int argc, char **argv) {
|
|||
bool showHelp;
|
||||
|
||||
/* Get command line arguments. */
|
||||
CommandLineArgFlag("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>("-o", "--output", "", outFileName);
|
||||
CommandLineArgSetter<string>("-a", "--arch", "", archString);
|
||||
CommandLineArgFlag fh("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
|
||||
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
|
||||
|
||||
CommandLineArg::readArgs(argc-1, argv);
|
||||
|
||||
|
@ -66,6 +67,8 @@ int asm_main(int argc, char **argv) {
|
|||
|
||||
ArchDef arch(archString);
|
||||
|
||||
D(0, "Created ArchDef for " << string(arch));
|
||||
|
||||
/* Create an appropriate encoder. */
|
||||
Encoder *enc;
|
||||
switch (arch.getEncChar()) {
|
||||
|
@ -96,6 +99,7 @@ int asm_main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* Read an Obj from the assembly file. */
|
||||
D(0, "Passing AsmReader ArchDef: " << string(arch));
|
||||
AsmReader ar(arch);
|
||||
Obj *o = ar.read(asmFile);
|
||||
|
||||
|
@ -120,6 +124,7 @@ int asm_main(int argc, char **argv) {
|
|||
delete enc;
|
||||
|
||||
/* Write a HOF binary. */
|
||||
D(0, "Creating a HOFWriter, passing it ArchDef: " << string(arch));
|
||||
HOFWriter hw(arch);
|
||||
hw.write(outFile, *o);
|
||||
outFile.close();
|
||||
|
@ -135,9 +140,9 @@ int disasm_main(int argc, char **argv) {
|
|||
|
||||
|
||||
/* Get command line arguments. */
|
||||
CommandLineArgFlag("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>("-a", "--arch", "", archString);
|
||||
CommandLineArgSetter<string>("-o", "--output", "", outFileName);
|
||||
CommandLineArgFlag fh("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
|
||||
CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
|
||||
|
||||
if (argc != 0) CommandLineArg::readArgs(argc-1, argv);
|
||||
|
||||
|
@ -205,9 +210,9 @@ int emu_main(int argc, char **argv) {
|
|||
bool showHelp;
|
||||
|
||||
/* Read the command line arguments. */
|
||||
CommandLineArgFlag("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>("-c", "--core", "", imgFileName);
|
||||
CommandLineArgSetter<string>("-a", "--arch", "", archString);
|
||||
CommandLineArgFlag fh("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>fc("-c", "--core", "", imgFileName);
|
||||
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
|
||||
|
||||
CommandLineArg::readArgs(argc, argv);
|
||||
|
||||
|
@ -249,11 +254,11 @@ int ld_main(int argc, char **argv) {
|
|||
Addr binOffset(0);
|
||||
|
||||
/* Get command line arguments. */
|
||||
CommandLineArgFlag("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>("-a", "--arch", "", archString);
|
||||
CommandLineArgSetter<string>("-f", "--format", "", formatString);
|
||||
CommandLineArgSetter<Addr>("--offset", "", binOffset);
|
||||
CommandLineArgSetter<string>("-o", "--output", "", outFileName);
|
||||
CommandLineArgFlag fh("-h", "--help", "", showHelp);
|
||||
CommandLineArgSetter<string>fa("-a", "--arch", "", archString);
|
||||
CommandLineArgSetter<string>ff("-f", "--format", "", formatString);
|
||||
CommandLineArgSetter<Addr> foffset("--offset", "", binOffset);
|
||||
CommandLineArgSetter<string>fo("-o", "--output", "", outFileName);
|
||||
|
||||
int firstInput(0), newArgc;
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "archdef.h"
|
||||
#include "enc.h"
|
||||
#include "mem.h"
|
||||
#include "debug.h"
|
||||
|
||||
namespace Harp {
|
||||
#ifdef EMU_INSTRUMENTATION
|
||||
|
|
|
@ -57,18 +57,19 @@ namespace Harp {
|
|||
{}
|
||||
|
||||
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) {
|
||||
addr = addr - base;
|
||||
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 {
|
||||
Addr mask = (1ll<<bits)-1;
|
||||
Addr mask = (1ull<<bits)-1;
|
||||
if (addr > mask) goto noFit;
|
||||
}
|
||||
|
||||
{ Byte mask((1<<remainder) - 1);
|
||||
{ Byte mask((1ull<<remainder) - 1);
|
||||
Size i;
|
||||
for (i = 0; i < bytes; i++) {
|
||||
data[offset+i] = addr & 0xff;
|
||||
addr >>= 8;
|
||||
|
@ -176,7 +177,7 @@ namespace Harp {
|
|||
|
||||
class HOFReader : public ObjReader {
|
||||
public:
|
||||
HOFReader(ArchDef arch) : arch(arch) {}
|
||||
HOFReader(ArchDef &arch) : arch(arch) {}
|
||||
Obj *read(std::istream &input);
|
||||
private:
|
||||
const ArchDef &arch;
|
||||
|
@ -192,7 +193,7 @@ namespace Harp {
|
|||
|
||||
class HOFWriter : public ObjWriter {
|
||||
public:
|
||||
HOFWriter(ArchDef arch) : arch(arch) {}
|
||||
HOFWriter(ArchDef &arch) : arch(arch) {}
|
||||
virtual void write(std::ostream &output, const Obj &obj);
|
||||
private:
|
||||
const ArchDef &arch;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue