Skip to content
Snippets Groups Projects
Commit 9e95f9a9 authored by bdr7fv's avatar bdr7fv
Browse files

Spasm will now support nasm directives following ** operators. This was done...

Spasm will now support nasm directives following ** operators. This was done primarily to support inline data using directives like db dw dd dq etc. 




Former-commit-id: 270995b57eb0dd9ca5c2eab73465542a29e0e944
parent a86340fb
No related branches found
No related tags found
No related merge requests found
......@@ -19,8 +19,8 @@
CC=g++
CFLAGS= -Wall -g# -DUBUNTU -Wall -O3
INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include
LIBS=-L../../xform -lxform -L ../../beaengine/lib/Linux.gnu.Debug -lBeaEngine_s_d
INCLUDE=-I. -I../../include -I../../xform
LIBS=-L../../xform -lxform
.cpp.o .c.o:
$(CC) $(CFLAGS) $(INCLUDE) -c $<
......@@ -31,5 +31,5 @@ all: spasm
clean:
rm -f *.o core spasm *.map *.bspri *.asm *.bin
spasm: $(OBJS) spasm.cpp Makefile spasm.h spasm_main.cpp ben_lib.cpp ben_lib.h ../../xform/libxform.a ../../beaengine/lib/Linux.gnu.Debug/libBeaEngine_s_d.a
spasm: $(OBJS) spasm.cpp Makefile spasm.h spasm_main.cpp ben_lib.cpp ben_lib.h ../../xform/libxform.a
$(CC) -o spasm $(INCLUDE) $(CFLAGS) spasm_main.cpp spasm.cpp ben_lib.cpp $(OBJS) $(LIBS)
......@@ -12,8 +12,6 @@
#include <assert.h>
#include "ben_lib.h"
#include "beaengine/BeaEngine.h"
using namespace std;
......@@ -75,8 +73,12 @@ static unsigned int bin_fsize=0;
static unsigned char *memblock = NULL;
static unsigned int assem_cnt =0;
static const string size_label_start = "__SPASM_SIZE_LABEL_START";
static const string size_label_end = "__SPASM_SIZE_LABEL_END";
static void initBin(const string &binFile);
static bool getNextBin(bin_instruction_t &bin);
static bool getNextBin(bin_instruction_t &bin,unsigned int instr_count);
static void printSPRI(const string &symbolFilename, const string &outFile);
......@@ -260,7 +262,7 @@ static bool getNextSpasmLine(spasmline_t &spasmline)
return getNextSpasmLine(spasmline);
//comment only line check
if(regexec(&coPattern, line.c_str(), 0, NULL, 0)==0)
if(regexec(&coPattern, line.c_str(), 0, NULL, 0)==0)
{
spasmline.commentOnly = true;
//The comment is the entire line
......@@ -428,7 +430,22 @@ static void assemble(const string &assemblyFile)
assemblyLine += lineRH;
stringstream ss;
ss<<size_label_start<<assem_cnt;
string start_lbl = ss.str();
ss.str("");
ss<<size_label_end<<assem_cnt;
string end_lbl = ss.str();
ss.str("");
symMap[start_lbl]="";
symMap[end_lbl]="";
asmFile<<start_lbl<<":"<<endl;
asmFile<<assemblyLine<<endl;
asmFile<<end_lbl<<":"<<endl;
assem_cnt++;
}
......@@ -546,25 +563,26 @@ static bool hasNextBin()
return bin_index < bin_fsize;
}
static bool getNextBin(bin_instruction_t &bin)
static bool getNextBin(bin_instruction_t &bin,unsigned int instr_count)
{
DISASM disasm;
memset(&disasm, 0, sizeof(DISASM));
if(!hasNextBin())
return false;
disasm.Options = NasmSyntax + PrefixedNumeral;
stringstream ss;
if(sizeof(void*)==8)
disasm.Archi = 64;
else
disasm.Archi = 32;
ss<<size_label_start<<instr_count;
assert(symMap.find(ss.str()) != symMap.end());
if(bin_index >= bin_fsize)
return false;
string start_addr = symMap[ss.str()];
ss.str("");
disasm.EIP = (long long int) &memblock[bin_index];
int instr_len = Disasm(&disasm);
ss<<size_label_end<<instr_count;
assert(symMap.find(ss.str()) != symMap.end());
bin.size = (unsigned int) instr_len;
string end_addr = symMap[ss.str()];
bin.size = strtoul(end_addr.c_str(),NULL,16) - strtoul(start_addr.c_str(),NULL,16);
char tempstr[50];
sprintf(tempstr, "%x",bin.size);
......@@ -715,8 +733,9 @@ static void printSPRI(const string &symbolFilename, const string &outFileName)
//to generate the spri for its corresponding spri line.
bin_instruction_t binLine;
assert(getNextBin(binLine,pop_bin_cnt));
pop_bin_cnt++;
assert(getNextBin(binLine));
// handle callback handlers
if (op.compare("()") == 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment