Add .bitfield to define bitfields of each entry (usage .bitfield <name> offset, [size in bits]. Each entry also has .not, .offset, .size, .mask for extra template usage

This commit is contained in:
DataHoarder 2021-08-03 19:21:43 +02:00
parent 040d1d926a
commit 964765dcfc
3 changed files with 21 additions and 3 deletions

View file

@ -116,7 +116,14 @@
.constant CRM_PARAM_START, %0x002200 ;; 64 entries, each one 1 words
.constant CRM_PARAM_END, %0x002240
.constant PLL_PCIE_CTRL, %0x2241
.constant PLL_PCIE_STAT, %0x2242
.bitfield PLL_PCIE_STAT.PllLocked 0
.bitfield PLL_PCIE_STAT.PllFreqChange 1
.bitfield PLL_PCIE_STAT.MiscCtrl.FastCalibrationMode 2
.bitfield PLL_PCIE_STAT.MiscCtrl.AsyncPLLLoadSignal 6
.bitfield PLL_PCIE_STAT.MiscCtrl.InitialCoarseThermalBits 8, 2
.constant SBUS_PCIE_CFG, %0x2243
.constant SBUS_PCIE_COMMAND, %0x2244
.constant SBUS_PCIE_REQUEST, %0x2245

View file

@ -174,7 +174,7 @@ void Parser::parse() {
break;
case Token::Type::Directive:
if (isDirective(currentValue)) {
if(currentValue == ".constant" || currentValue == ".reserve"){
if(currentValue == ".constant" || currentValue == ".reserve" || currentValue == ".bitfield"){
if (!currentFunction.label.empty()) {
functions.emplace_back(std::move(currentFunction));
currentFunction = Function();
@ -271,6 +271,17 @@ void Parser::parse() {
tokens.push_back(*it);
}
variables[currentDeclaration.tokens.at(1).getTextValue()] = tokens;
}else if (currentDeclaration.tokens.at(0).getTextValue() == ".bitfield") {
auto& fieldName = currentDeclaration.tokens.at(1).getTextValue();
uint32_t fieldBitOffset = currentDeclaration.tokens.at(2).getNumericValue();
uint32_t fieldBitSize = currentDeclaration.tokens.size() > 3 ? currentDeclaration.tokens.at(3).getNumericValue() : 1;
uint32_t fieldBitMask = (1 << fieldBitSize) - 1;
variables[fieldName] = {Token(Token::Type::Immediate, std::to_string(fieldBitMask << fieldBitOffset), fieldBitMask << fieldBitOffset)};
variables[fieldName + ".not"] = {Token(Token::Type::Immediate, std::to_string((~(fieldBitMask << fieldBitOffset)) & 0xFFFFFFFF), (~(fieldBitMask << fieldBitOffset)) & 0xFFFFFFFF)};
variables[fieldName + ".offset"] = {Token(Token::Type::Immediate, std::to_string(fieldBitOffset), fieldBitOffset)};
variables[fieldName + ".size"] = {Token(Token::Type::Immediate, std::to_string(fieldBitSize), fieldBitSize)};
variables[fieldName + ".mask"] = {Token(Token::Type::Immediate, std::to_string(fieldBitMask), fieldBitMask)};
}
currentDeclaration = Declaration();
currentStateIndex = 0;

View file

@ -50,13 +50,13 @@ class Parser {
static std::vector<uint8_t> getAlphaValues() {
return {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_',};
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', '.',};
}
static std::vector<uint8_t> getAlphanumericValues() {
return {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9'};
}