summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-10-04 15:29:09 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-10-04 15:29:09 +0200
commit295e333c73cde26181ce61568b5ff89ec1561927 (patch)
treead65a2a489eddc4651232955331a8d4eca827b7a
parent6e6666a841f16fb5e8f9dd742dec9b756cb7870b (diff)
downloadsdma-firmware-295e333c73cde26181ce61568b5ff89ec1561927.tar.gz
sdma-firmware-295e333c73cde26181ce61568b5ff89ec1561927.tar.xz
Add SDMA Assembler from HBM as is
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rwxr-xr-xsdmaasm/SDMA_ASM.pro35
-rwxr-xr-xsdmaasm/helpers.cpp173
-rwxr-xr-xsdmaasm/helpers.h27
-rwxr-xr-xsdmaasm/instruction.cpp139
-rwxr-xr-xsdmaasm/instruction.h25
-rwxr-xr-xsdmaasm/instructionlist.cpp116
-rwxr-xr-xsdmaasm/instructionlist.h23
-rwxr-xr-xsdmaasm/instructionparser.cpp231
-rwxr-xr-xsdmaasm/instructionparser.h26
-rwxr-xr-xsdmaasm/main.cpp94
-rwxr-xr-xsdmaasm/readme.txt13
-rwxr-xr-xsdmaasm/sdma.inst51
-rwxr-xr-xsdmaasm/test.asm51
13 files changed, 1004 insertions, 0 deletions
diff --git a/sdmaasm/SDMA_ASM.pro b/sdmaasm/SDMA_ASM.pro
new file mode 100755
index 0000000..2fff245
--- /dev/null
+++ b/sdmaasm/SDMA_ASM.pro
@@ -0,0 +1,35 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-08-24T13:42:36
+#
+#-------------------------------------------------
+
+QT += core
+
+QT -= gui
+
+TARGET = SDMA_ASM
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += main.cpp \
+ instruction.cpp \
+ instructionlist.cpp \
+ instructionparser.cpp \
+ helpers.cpp
+
+HEADERS += \
+ instruction.h \
+ instructionlist.h \
+ instructionparser.h \
+ helpers.h
+
+OTHER_FILES += \
+ test.txt \
+ asm.txt \
+ sdma.inst \
+ readme.txt \
+ firmware.blob
diff --git a/sdmaasm/helpers.cpp b/sdmaasm/helpers.cpp
new file mode 100755
index 0000000..2d65b45
--- /dev/null
+++ b/sdmaasm/helpers.cpp
@@ -0,0 +1,173 @@
+/*
+* helpers.cpp
+*
+* This file contains static helper functions
+*
+* Copyright 2010 Tobias Wirtl, HBM <tobias.wirtl@hbm.com>
+*
+* The code contained herein is licensed under the GNU General Public
+* License. You may obtain a copy of the GNU General Public License
+* Version 2 or later at the following locations:
+*
+* http://www.opensource.org/licenses/gpl-license.html
+* http://www.gnu.org/copyleft/gpl.html
+*/
+
+
+#include "helpers.h"
+#include <iostream>
+#include <math.h>
+#include <sstream>
+
+
+Helpers::Helpers()
+{
+}
+
+void Helpers::splitStr(const string &toSplit, vector<string> *target, char seperator)
+{
+ unsigned int begin = 0;
+ unsigned int i;
+
+ for (i = 0; i < toSplit.size(); i++)
+ {
+ if (toSplit[i] == seperator || i + 1 ==toSplit.size())
+ {
+ if (i + 1 == toSplit.size()) i++;
+ target->push_back(toSplit.substr(begin,i-begin));
+ begin = i + 1;
+ }
+ }
+}
+
+
+
+int Helpers::strToInt(const string &aString)
+{
+ int result = 0;
+ int digit;
+ unsigned int i;
+
+ for (i = 0; i < aString.size(); i++)
+ {
+ if (aString[i] > 47 && aString[i] < 58)
+ {
+ digit = aString[i]-48;
+ result += digit*pow(10,aString.size()-(i+1));
+ }
+ else
+ cout<<"Warning: strToInt "<<aString[i]<<" -> not an integer value";
+ }
+ return result;
+}
+
+
+string Helpers::intToStr(const int &aInt)
+{
+ string result;
+ stringstream tmp;
+ tmp<<aInt;
+ tmp>>result;
+ return result;
+}
+
+
+int Helpers::hexStrToDecInt(const string &aString)
+{
+ int result = 0;
+ int digit;
+ unsigned int i;
+
+ for (i = 0; i < aString.size(); i++)
+ {
+ if ((aString[i] > 47 && aString[i] < 58) || (aString[i] > 96 && aString[i] < 103))
+ {
+ if (aString[i] < 58 )
+ digit = aString[i]-48;
+ else
+ digit = aString[i]-87;
+
+ result += digit*pow(16,aString.size()-(i+1));
+ }
+ else
+ cout<<"Warning: hexStrToDecInt "<<aString[i]<<" -> not a hex value";
+ }
+ return result;
+}
+
+int Helpers::binStrToDecInt(const string &aString)
+{
+ int result = 0;
+ int digit;
+ unsigned int i;
+
+ for (i = 0; i < aString.size(); i++)
+ {
+ if (aString[i] > 47 && aString[i] < 50)
+ {
+ digit = aString[i]-48;
+ result += digit*pow(2,aString.size()-(i+1));
+ }
+ else
+ cout<<"Warning: binStrToDecInt "<<aString[i]<<" -> not a binary value";
+ }
+ return result;
+}
+
+string Helpers::IntDecToBinaryStr(unsigned int i)
+{
+ string res;
+ while (i > 0)
+ {
+ if (i%2)
+ res = '1' + res;
+ else
+ res = '0' + res;
+ i = i / 2;
+ }
+
+ return res;
+}
+
+string Helpers::build2Complement(const string &binaryValues)
+{
+ bool added = false;
+ int i;
+ string result = binaryValues;
+ for(i = binaryValues.length()-1;i >= 0; i--)
+ {
+ //invert and add one
+ result[i] == '1' ? result[i] = '0' : result[i] = '1';
+ if (!added)
+ {
+ if (result[i] == '1')
+ result[i] = '0';
+ else
+ {
+ result[i] = '1';
+ added=true;
+ }
+ }
+ }
+ return result;
+}
+
+void Helpers::strToLower(string &aString)
+{
+ unsigned int i;
+ for(i = 0; i < aString.length();i++)
+ aString[i] = std::tolower(aString[i]);
+}
+
+string Helpers::replace(const string &sourceStr, const string &oldStr, const string &newStr)
+{
+ string tmp = sourceStr;
+ int i;
+ i = sourceStr.find(oldStr.c_str());
+ while (i > -1)
+ {
+ tmp.replace (i, oldStr.length(),newStr, 0, newStr.length() );
+ i = tmp.find(oldStr.c_str(),i+newStr.length());
+ }
+ return tmp;
+}
diff --git a/sdmaasm/helpers.h b/sdmaasm/helpers.h
new file mode 100755
index 0000000..440bec2
--- /dev/null
+++ b/sdmaasm/helpers.h
@@ -0,0 +1,27 @@
+#ifndef HELPERS_H
+#define HELPERS_H
+
+
+#include <vector>
+#include <string>
+
+using namespace std;
+
+class Helpers
+{
+public:
+ Helpers();
+ static void splitStr(const string &toSplit, vector<string> *target, char seperator);
+ static int strToInt(const string &aString);
+ static string intToStr(const int &aInt);
+ static int hexStrToDecInt(const string &aString);
+ static int binStrToDecInt(const string &aString);
+ static string IntDecToBinaryStr(unsigned int i);
+ static string build2Complement(const string &binaryValues);
+ static void strToLower(string &aString);
+ static string replace(const string &sourceStr, const string &oldStr, const string &newStr);
+
+};
+
+#endif // HELPERS_H
+
diff --git a/sdmaasm/instruction.cpp b/sdmaasm/instruction.cpp
new file mode 100755
index 0000000..433ce86
--- /dev/null
+++ b/sdmaasm/instruction.cpp
@@ -0,0 +1,139 @@
+/*
+* instruction.cpp
+*
+* This file contains static helper functions
+*
+* Copyright 2010 Tobias Wirtl, HBM <tobias.wirtl@hbm.com>
+*
+* The code contained herein is licensed under the GNU General Public
+* License. You may obtain a copy of the GNU General Public License
+* Version 2 or later at the following locations:
+*
+* http://www.opensource.org/licenses/gpl-license.html
+* http://www.gnu.org/copyleft/gpl.html
+*/
+
+#include "instruction.h"
+#include "vector"
+#include "helpers.h"
+#include <iostream>
+
+Instruction::Instruction(const string &instructionStr, const string &bitMask)
+{
+ this->instructionStr = instructionStr;
+ this->bitMask = bitMask;
+}
+
+
+//get the bitcode with filled params from a line of code (e.g. MOV 3 6)
+string Instruction::getBitcodeOfProgramLine(const string &programLine)
+{
+ unsigned int i1,i2, digitCounter;
+ vector<string> *splitLine = new vector<string>();
+ string result = this->bitMask;
+
+ Helpers::splitStr(programLine,splitLine,' ');
+ if (splitLine->size() >= this->getNumParams() + 1)
+ {
+ //get bit string of each parameter
+ for (i1 = 0; i1 < this->getNumParams(); i1++ )
+ {
+ digitCounter = 0;
+ string paramBits = this->getBitStr((*splitLine)[i1+1], this->getBitLengthParam(i1));
+ for (i2 = 0; i2 < this->bitMask.size(); i2++)
+ {
+ if (result[i2] == 97+i1)
+ result[i2] = paramBits[digitCounter++];
+ }
+ }
+ }
+ return result;
+}
+
+
+
+//get bitstring of a given parameter string in reg, dec, hex or bin
+string Instruction::getBitStr(const string &param, unsigned int length)
+{
+ int value = 0;
+ int negative = 0;
+ string result;
+
+ if (param[0] == '-')
+ negative = 1;
+ //get value of the parameter
+ if (param[negative] == 'r')
+ value = Helpers::strToInt(param.substr(1+negative,param.length()-(1+negative)));
+ else if (param[negative] == 'b')
+ value = Helpers::binStrToDecInt(param.substr(1+negative,param.length()-(1+negative)));
+ else if (param[negative] == 'h')
+ value = Helpers::hexStrToDecInt(param.substr(1+negative,param.length()-(1+negative)));
+ else
+ value = Helpers::strToInt(param.substr(negative,param.length()-(negative)));
+
+ result = Helpers::IntDecToBinaryStr(value);
+ //add leading zeros
+ while (result.length() < length)
+ result='0'+result;
+ if (result.length() > length)
+ {
+ result = result.substr(result.size()-length,length);
+ cout<<"Warning: parameter \""<<param<<"\" was cropped because the value was out of range!\n";
+ }
+
+ //build 2nd complement in ascii
+ if (negative)
+ result = Helpers::build2Complement(result);
+
+ return result;
+}
+
+
+unsigned int Instruction::getNumParams()
+{
+ char lastParamChar = '0';
+ int paramCount = 0;
+ for (unsigned int i = 0; i < bitMask.length(); i++)
+ {
+ if (bitMask[i] != '0' && bitMask[i] != '1' && bitMask[i] != lastParamChar)
+ {
+ lastParamChar = bitMask[i];
+ paramCount++;
+ }
+ }
+ return paramCount;
+}
+
+//get the bit length of the instructions parameters (zero based)
+unsigned int Instruction::getBitLengthParam(int paramNo)
+{
+ char paramChar = 0x61 + paramNo;
+ unsigned int i;
+ int counter = 0;
+ for (i = 0; i < this->bitMask.length();i++)
+ if (bitMask[i] == paramChar)
+ counter++;
+ return counter;
+}
+
+string Instruction::getBitMask()
+{
+ return this->bitMask;
+}
+
+string Instruction::getInstructionStr()
+{
+ return this->instructionStr;
+}
+
+string Instruction::getBitsOfParam(unsigned int paramNo, const string &bitcode)
+{
+ unsigned int i;
+ string result;
+ for (i = 0; i < this->bitMask.length();i++)
+ {
+ if (this->bitMask[i] == paramNo + 97)
+ result.push_back(bitcode[i]);
+ }
+ return result;
+}
diff --git a/sdmaasm/instruction.h b/sdmaasm/instruction.h
new file mode 100755
index 0000000..c0ff891
--- /dev/null
+++ b/sdmaasm/instruction.h
@@ -0,0 +1,25 @@
+#ifndef INSTRUCTION_H
+#define INSTRUCTION_H
+
+#include <string>
+
+using namespace std;
+
+class Instruction
+{
+private:
+ string instructionStr;
+ string bitMask;
+ string getBitStr(const string &param, unsigned int length);
+public:
+ Instruction(const string &instructionStr, const string &bitMask);
+ unsigned int getNumParams();
+ unsigned int getBitLengthParam(int paramNo);
+ string getBitcodeOfProgramLine(const string &programLine);
+ string getBitsOfParam(unsigned int paramNo, const string &bitcode);
+ string getBitMask();
+ string getInstructionStr();
+
+};
+
+#endif // INSTRUCTION_H
diff --git a/sdmaasm/instructionlist.cpp b/sdmaasm/instructionlist.cpp
new file mode 100755
index 0000000..71f921c
--- /dev/null
+++ b/sdmaasm/instructionlist.cpp
@@ -0,0 +1,116 @@
+/*
+* instructionlist.cpp
+*
+* This file contains static helper functions
+*
+* Copyright 2010 Tobias Wirtl, HBM <tobias.wirtl@hbm.com>
+*
+* The code contained herein is licensed under the GNU General Public
+* License. You may obtain a copy of the GNU General Public License
+* Version 2 or later at the following locations:
+*
+* http://www.opensource.org/licenses/gpl-license.html
+* http://www.gnu.org/copyleft/gpl.html
+*/
+
+#include "instructionlist.h"
+#include "helpers.h"
+#include <fstream>
+#include <exception>
+#include <iostream>
+
+
+using namespace std;
+
+
+InstructionList::InstructionList(const string &filename)
+{
+ ifstream inFile;
+ string bufInst;
+ string bufBitcode;
+ try
+ {
+ inFile.open(filename.c_str());
+ if (inFile.good())
+ {
+ do
+ {
+ inFile>>bufInst;
+ Helpers::strToLower(bufInst);
+ inFile>>bufBitcode;
+ this->instructions.push_back(new Instruction(bufInst,bufBitcode));
+ } while(!inFile.eof());
+ }
+ else
+ cout<<"Can't read instruction list from file: "<<filename;
+ }
+ catch(const exception &e)
+ {
+ cout<<"Error reading instruction list: "<<e.what();
+ }
+}
+
+
+unsigned int InstructionList::size()
+{
+ return this->instructions.size();
+}
+
+Instruction* InstructionList::getInstruction(int i)
+{
+ return this->instructions.at(i);
+}
+
+
+// get instruction object of a program row (null if not found)
+Instruction* InstructionList::getInstructionOfInstructionStr(const string &instructionStr)
+{
+ unsigned int i;
+ string tmp;
+ Instruction* result = 0;
+
+ for (i = 0; i < instructionStr.size(); i++)
+ {
+ if (instructionStr[i] != ' ')
+ tmp += instructionStr[i];
+ else
+ break;
+ }
+ for (i = 0; i < instructions.size(); i++)
+ {
+ if (instructions[i]->getInstructionStr() == tmp)
+ result = instructions[i];
+ }
+ return result;
+}
+
+//get instruction object of a bitcode (null if not found)
+Instruction* InstructionList::getInstructionOfBitcodeStr(const string &bitcodeStr)
+{
+ Instruction* result = 0;
+ unsigned int i1,i2;
+ string bitMask;
+ bool equal;
+
+ //string* fordebug = new string(bitcodeStr);
+
+ for(i1 = 0; i1 < this->instructions.size();i1++)
+ {
+ equal = true;
+ bitMask = instructions[i1]->getBitMask();
+ for (i2 = 0; i2 < 16; i2++)
+ {
+ if (bitcodeStr[i2] != bitMask[i2] && (bitMask[i2] == '1' || bitMask[i2] == '0'))
+ {
+ equal = false;
+ break;
+ }
+ }
+ if (equal)
+ {
+ result = instructions[i1];
+ break;
+ }
+ }
+ return result;
+}
diff --git a/sdmaasm/instructionlist.h b/sdmaasm/instructionlist.h
new file mode 100755
index 0000000..24cb0d3
--- /dev/null
+++ b/sdmaasm/instructionlist.h
@@ -0,0 +1,23 @@
+#ifndef INSTRUCTIONLIST_H
+#define INSTRUCTIONLIST_H
+
+#include <vector>
+#include <string>
+
+#include "instruction.h"
+
+using namespace std;
+
+class InstructionList
+{
+private:
+ std::vector<Instruction*> instructions;
+public:
+ InstructionList(const string &filename);
+ unsigned int size();
+ Instruction* getInstruction(int i);
+ Instruction* getInstructionOfInstructionStr(const string &instructionStr);
+ Instruction* getInstructionOfBitcodeStr(const string &bitcodeStr);
+};
+
+#endif // INSTRUCTIONLIST_H
diff --git a/sdmaasm/instructionparser.cpp b/sdmaasm/instructionparser.cpp
new file mode 100755
index 0000000..cb1938f
--- /dev/null
+++ b/sdmaasm/instructionparser.cpp
@@ -0,0 +1,231 @@
+/*
+* instructionparser.cpp
+*
+* This file contains static helper functions
+*
+* Copyright 2010 Tobias Wirtl, HBM <tobias.wirtl@hbm.com>
+*
+* The code contained herein is licensed under the GNU General Public
+* License. You may obtain a copy of the GNU General Public License
+* Version 2 or later at the following locations:
+*
+* http://www.opensource.org/licenses/gpl-license.html
+* http://www.gnu.org/copyleft/gpl.html
+*/
+
+#include "instructionparser.h"
+#include "helpers.h"
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <sstream>
+
+using namespace std;
+
+
+InstructionParser::InstructionParser(InstructionList *il)
+{
+ this->instructions = il;
+}
+
+/*
+// get instruction object of a program row (null if not found)
+Instruction* InstructionParser::getInstruction(const string &programLine)
+{
+ unsigned int i;
+ string tmp;
+ Instruction* result = 0;
+
+ for (i = 0; i < programLine.size(); i++)
+ {
+ if (programLine[i] != ' ')
+ tmp += programLine[i];
+ else
+ break;
+ }
+ for (i = 0; i < instructions->size(); i++)
+ {
+ if (instructions->getInstruction(i)->getInstructionStr() == tmp)
+ result = instructions->getInstruction(i);
+ }
+ return result;
+}*/
+
+
+//convert program lines to their binary derivate
+void InstructionParser::programLinesToBinary()
+{
+ unsigned int i = 0;
+ string bitcode;
+
+ programLinesBinary.clear();
+
+ cout<<setw(25)<<left<<"instruction"<<setw(20)<<"mask"<<"bitcode"<<"\n";
+ cout<<setw(61)<<setfill('-')<<"-"<<setfill(' ')<<"\n";
+ for (i = 0; i < programLines.size(); i++)
+ {
+ Instruction* instruction = this->instructions->getInstructionOfInstructionStr(programLines[i]);
+ if (instruction != 0)
+ {
+ bitcode = instruction->getBitcodeOfProgramLine(programLines[i]);
+ cout<<setw(25)<<left<<programLines[i]<<setw(20)<<instruction->getBitMask()<<bitcode<<"\n";
+ this->programLinesBinary.push_back(bitcode);
+ }
+ else
+ cout<<"Can't interpret \""<<programLines[i]<<"\" on Line "<<i+1<<"\n";
+ }
+}
+
+//read all lines of the file and prepare for parsing
+void InstructionParser::readProgramLines(const string &filename)
+{
+ char buf[101];
+ char prev;
+ unsigned int i;
+ string temp;
+
+ ifstream infile(filename.c_str());
+ programLines.clear();
+ if ( infile.is_open())
+ {
+ while (! infile.eof() )
+ {
+ temp.clear();
+ infile.getline (buf,100);
+ //clean line
+ prev = buf[0];
+ i = 0;
+ while(buf[i]!='\0')
+ {
+ buf[i] = std::tolower(buf[i]);
+ if (buf[i] == ',') buf[i] = ' ';
+ //ignore comments
+ if (buf[i] == '%') break;
+ //remove redundant free spaces and newlines
+ if( !(buf[i] == ' ' && prev == ' ')
+ && !(i == 0 && buf[i] == ' ')
+ && (buf[i] != '\n'))
+ temp += buf[i];
+ prev = buf[i];
+ i++;
+ }
+ //delete free space on the end
+ if (temp.size() > 0 && temp.at(temp.size()-1) == ' ')
+ temp = temp.substr(0,temp.size()-1);
+ //ignore empty rows
+ if (temp.size() > 0)
+ {
+ this->programLines.push_back(temp);
+ }
+ }
+ programLinesToBinary();
+ }
+ else
+ cout << "Can't open "<<filename<<"!\n";
+}
+
+void InstructionParser::binaryOutputToFile(const string &filename)
+{
+ ofstream outFile(filename.c_str(), std::ios::out|std::ios::binary);
+ unsigned int i;
+ unsigned int outputSize = this->programLinesBinary.size()*2;
+ char output[outputSize];
+
+ if (outFile.is_open())
+ {
+ for (i = 0; i < this->programLinesBinary.size(); i++)
+ {
+
+ output[i*2] = Helpers::binStrToDecInt(this->programLinesBinary[i].substr(0,8));
+ output[i*2 + 1] = Helpers::binStrToDecInt(this->programLinesBinary[i].substr(8,8));
+
+ }
+ outFile.write(output,outputSize);
+ outFile.close();
+ }
+ else
+ cout << "Can't open "<<filename<<"!";
+}
+
+
+void InstructionParser::instructionOutputToFile(const string &filename)
+{
+ unsigned int i;
+ ofstream outFile(filename.c_str());
+
+ if (outFile.is_open())
+ {
+ for (i = 0; i < programLines.size(); i++)
+ outFile<<programLines[i]<<'\n';
+ outFile.close();
+ }
+ else
+ cout << "Can't open "<<filename<<"!";
+}
+
+
+
+
+void InstructionParser::readTextBlob(const string &filename)
+{
+ string temp;
+ stringstream strStream;
+
+ programLinesBinary.clear();
+
+ ifstream infile(filename.c_str());
+ if ( infile.is_open())
+ {
+ while(infile>>temp)
+ strStream<<Helpers::replace(Helpers::replace(temp,","," "),"0x","");
+ while(strStream>>temp)
+ {
+ if (temp.length() == 4)
+ {
+ temp = Helpers::IntDecToBinaryStr( Helpers::hexStrToDecInt(temp));
+ while (temp.length() < 16)
+ temp='0'+temp; //XXX: inefficient
+ this->programLinesBinary.push_back(temp);
+ }
+ else
+ cout<<"Can't interpret "<<temp<<"!\n";
+ }
+ binaryToProgramLines();
+ }
+ else
+ cout << "Can't open "<<filename<<"!\n";
+
+}
+
+//convert binary vector entries into human readable (programLines)
+void InstructionParser::binaryToProgramLines()
+{
+ unsigned int i1, i2;
+ Instruction *inst;
+ string tmpParam, tmpInst;
+
+ this->programLines.clear();
+ for (i1 = 0; i1 < this->programLinesBinary.size();i1++)
+ {
+ inst = this->instructions->getInstructionOfBitcodeStr(programLinesBinary[i1]);
+ if (inst)
+ {
+
+ tmpInst = inst->getInstructionStr();
+ for (i2 = 0; i2 < inst->getNumParams(); i2++)
+ {
+ tmpParam = inst->getBitsOfParam(i2,programLinesBinary[i1]);
+ if (i2>0)
+ tmpInst += ", ";
+ else
+ tmpInst.push_back(' ');
+ tmpInst += Helpers::intToStr(Helpers::binStrToDecInt(tmpParam));
+ }
+ programLines.push_back(tmpInst);
+ //cout<<tmpInst<<"\n";
+ }
+ else
+ cout<<"Warning: Can't decode bitcode "<<programLinesBinary[i1]<<"!\n";
+ }
+
+}
diff --git a/sdmaasm/instructionparser.h b/sdmaasm/instructionparser.h
new file mode 100755
index 0000000..ed458f8
--- /dev/null
+++ b/sdmaasm/instructionparser.h
@@ -0,0 +1,26 @@
+#ifndef INSTRUCTIONPARSER_H
+#define INSTRUCTIONPARSER_H
+
+#include "instructionlist.h"
+#include "instruction.h"
+
+using namespace std;
+
+class InstructionParser
+{
+private:
+ InstructionList *instructions;
+ vector<string> programLines;
+ vector<string> programLinesBinary;
+ //Instruction* getInstruction(const string &instruction);
+ void programLinesToBinary();
+ void binaryToProgramLines();
+public:
+ InstructionParser(InstructionList *il);
+ void readProgramLines(const string &filename);
+ void readTextBlob(const string &filename);
+ void binaryOutputToFile(const string &filename);
+ void instructionOutputToFile(const string &filename);
+};
+
+#endif // INSTRUCTIONPARSER_H
diff --git a/sdmaasm/main.cpp b/sdmaasm/main.cpp
new file mode 100755
index 0000000..57fe9d5
--- /dev/null
+++ b/sdmaasm/main.cpp
@@ -0,0 +1,94 @@
+/*
+* main.cpp
+*
+* main
+*
+* Copyright 2010 Tobias Wirtl, HBM <tobias.wirtl@hbm.com>
+*
+* The code contained herein is licensed under the GNU General Public
+* License. You may obtain a copy of the GNU General Public License
+* Version 2 or later at the following locations:
+*
+* http://www.opensource.org/licenses/gpl-license.html
+* http://www.gnu.org/copyleft/gpl.html
+*/
+
+
+#include "instructionlist.h"
+#include "instruction.h"
+#include "instructionparser.h"
+#include <iostream>
+#include "helpers.h"
+
+//#define DEBUG
+
+
+int main(int argc, char *argv[])
+{
+
+ string mode;
+ string source;
+ string target;
+ string inlPath;
+
+#ifndef DEBUG
+ if (argc >= 4)
+ {
+ mode = argv[1];
+ source = argv[2];
+ target = argv[3];
+ inlPath = argv[4];
+#else
+
+ mode
+ asmPath = "../SDMA_ASM/asm.txt";
+ blobPath = "../SDMA_ASM/firmware.blob";
+ inlPath = "../SDMA_ASM/sdma.inst";
+ outFile = "../SDMA_ASM/out.hex";
+
+#endif
+ InstructionList* il = new InstructionList(inlPath);
+ InstructionParser parser(il);
+
+ cout <<"\nPath to source file: "<<source<<'\n'
+ <<"Path to instructions file: "<<inlPath<<'\n'
+ <<"Path to output file: "<<target<<"\n\n";
+
+
+ if (mode == "-a")
+ {
+ parser.readProgramLines(source);
+ parser.binaryOutputToFile(target);
+ }
+ else if (mode == "-d")
+ {
+ parser.readTextBlob(source);
+ parser.instructionOutputToFile(target);
+ cout<<"\ndone!\n";
+ }
+ else
+ cout<<"Unknown mode: "<<mode<<'\n';
+
+#ifndef DEBUG
+ }
+ else
+ cout <<"Assembler for the i.MX356 SDMA controller\n"
+ <<"Copyright HBM 2010\n\n"
+
+ <<"This program is licensed under the GNU General Public\n"
+ <<"License. You may obtain a copy of the GNU General Public License\n"
+ <<"Version 2 or later at the following locations:\n"
+ <<"http://www.opensource.org/licenses/gpl-license.html\n"
+ <<"http://www.gnu.org/copyleft/gpl.html\n\n"
+
+ <<"Usage: SDMA_ASM [mode] [source] [target] [instruction file]\n"
+ <<"possible modes \n"
+ <<"\t-d disassemble\thex blob --> code file \n"
+ <<"\t-a assemble\t\tcode file --> hexfile\n";
+#endif
+
+
+
+ return 0;
+}
+
diff --git a/sdmaasm/readme.txt b/sdmaasm/readme.txt
new file mode 100755
index 0000000..03b6a28
--- /dev/null
+++ b/sdmaasm/readme.txt
@@ -0,0 +1,13 @@
+possible parameter format:
+
+bin: b11110000
+hex: hF0
+dec: 240
+reg: r1,r2,r3,...,rn
+
+e.g.
+
+mov 4,0
+mov b100,b0
+mov h4,h0
+mov r4,r0
diff --git a/sdmaasm/sdma.inst b/sdmaasm/sdma.inst
new file mode 100755
index 0000000..fc2f7f1
--- /dev/null
+++ b/sdmaasm/sdma.inst
@@ -0,0 +1,51 @@
+done 00000aaa00000000
+notify 00000aaa00000001
+softBkpt 0000000000000101
+ret 0000000000000110
+clrf 000000aa00000111
+illegal 0000011100000111
+jmpr 00000aaa00001000
+jsrr 00000aaa00001001
+ldrpc 00000aaa00001010
+revb 00000aaa00010000
+revblo 00000aaa00010001
+rorb 00000aaa00010010
+ror1 00000aaa00010100
+lsr1 00000aaa00010101
+asr1 00000aaa00010110
+lsl1 00000aaa00010111
+bclri 00000aaa001bbbbb
+bseti 00000aaa010bbbbb
+btsti 00000aaa011bbbbb
+mov 00000aaa10001bbb
+xor 00000aaa10010bbb
+add 00000aaa10011bbb
+sub 00000aaa10100bbb
+or 00000aaa10101bbb
+andn 00000aaa10110bbb
+and 00000aaa10111bbb
+tst 00000aaa11000bbb
+cmpeq 00000aaa11001bbb
+cmplt 00000aaa11010bbb
+cmphs 00000aaa11011bbb
+cpShReg 0000011011100010
+ldi 00001aaabbbbbbbb
+xori 00010aaabbbbbbbb
+addi 00011aaabbbbbbbb
+subi 00100aaabbbbbbbb
+ori 00101aaabbbbbbbb
+andni 00110aaabbbbbbbb
+andi 00111aaabbbbbbbb
+tsti 01000aaabbbbbbbb
+cmpeqi 01001aaabbbbbbbb
+ld 01010aaabbbbbccc
+st 01011aaabbbbbccc
+ldf 01100aaabbbbbbbb
+stf 01101aaabbbbbbbb
+loop 011100aabbbbbbbb
+bf 01111100aaaaaaaa
+bt 01111101aaaaaaaa
+bsf 01111110aaaaaaaa
+bdf 01111111aaaaaaaa
+jmp 10aaaaaaaaaaaaaa
+jsr 11aaaaaaaaaaaaaa
diff --git a/sdmaasm/test.asm b/sdmaasm/test.asm
new file mode 100755
index 0000000..03c1e9a
--- /dev/null
+++ b/sdmaasm/test.asm
@@ -0,0 +1,51 @@
+done b000
+notify b111
+softBkpt
+ret
+clrf b11
+illegal
+jmpr b111
+jsrr b111
+ldrpc b111
+revb b111
+revblo b111
+rorb b111
+ror1 b111
+lsr1 b111
+asr1 b111
+lsl1 b111
+bclri b111,b11111
+bseti b111,b11111
+btsti b111,b11111
+mov b111,b111
+xor b111,b111
+add b111,b111
+sub b111,b111
+or b111,b111
+andn b111,b111
+and b111,b111
+tst b111,b111
+cmpeq b111,b111
+cmplt b111,b111
+cmphs b111,b111
+cpShReg
+ldi b111,b11111111
+xori b111,b11111111
+addi b111,b11111111
+subi b111,b11111111
+ori b111,b11111111
+andni b111,b11111111
+andi b111,b11111111
+tsti b111,b11111111
+cmpeqi b111,b11111111
+ld b111,b11111,b111
+st b111,b11111,b111
+ldf b111,b11111111
+stf b111,b11111111
+loop b11,b11111111
+bf b11111111
+bt b11111111
+bsf b11111111
+bdf b11111111
+jmp b11111111111111
+jsr b11111111111111