* Added reservation system (basically constants in BSM_SCRATCH)
* New token cast system to force an entry as Value (&) or Indirect (*)
This commit is contained in:
parent
06051ec67d
commit
8c93edd1f9
86
asm/api.asm
86
asm/api.asm
|
@ -2,50 +2,50 @@
|
|||
; Based on Intel datasheet and BSD-3 code.
|
||||
|
||||
|
||||
.constant api_SPI_LOCK_STATE, %0x800
|
||||
.constant api_PCIE_SBUS_LOCK_STATE, %0x801
|
||||
.constant api_SOFT_RESET_LOCK_STATE, %0x802
|
||||
.reserve api_SPI_LOCK_STATE, 0x000
|
||||
.reserve api_PCIE_SBUS_LOCK_STATE, 0x001
|
||||
.reserve api_SOFT_RESET_LOCK_STATE, 0x002
|
||||
|
||||
.constant api_RECOVERY_STATUS_VECTOR, %0x803
|
||||
.reserve api_RECOVERY_STATUS_VECTOR, 0x003
|
||||
|
||||
.constant api_PEP_MAC_BASE, %0x80a
|
||||
.constant api_CUSTOM_MAC_BASE, %0x864
|
||||
.reserve api_PEP_MAC_BASE, 0x00a
|
||||
.reserve api_CUSTOM_MAC_BASE, 0x064
|
||||
|
||||
.constant api_BSM_STATUS, %0x990
|
||||
.constant api_EEPROM_IMAGE_VERSION, %0x991
|
||||
.constant api_MASTER_FW_VERSION, %0x992
|
||||
.constant api_SERDES_FW_VERSION, %0x993
|
||||
.constant api_SERDES_STATUS_1, %0x994
|
||||
.constant api_SERDES_STATUS_2, %0x995
|
||||
.constant api_SERDES_STATUS_3, %0x996
|
||||
.constant api_SERDES_STATUS_4, %0x997
|
||||
.constant api_PCIE_MASTER_STATUS, %0x998
|
||||
.constant api_PCIE_SERDES_STATUS, %0x999
|
||||
.reserve api_BSM_STATUS, 0x190
|
||||
.reserve api_EEPROM_IMAGE_VERSION, 0x191
|
||||
.reserve api_MASTER_FW_VERSION, 0x192
|
||||
.reserve api_SERDES_FW_VERSION, 0x193
|
||||
.reserve api_SERDES_STATUS_1, 0x194
|
||||
.reserve api_SERDES_STATUS_2, 0x195
|
||||
.reserve api_SERDES_STATUS_3, 0x196
|
||||
.reserve api_SERDES_STATUS_4, 0x197
|
||||
.reserve api_PCIE_MASTER_STATUS, 0x198
|
||||
.reserve api_PCIE_SERDES_STATUS, 0x199
|
||||
|
||||
.constant api_DE_COLD_RESET_STATUS, %0x9ae
|
||||
.constant api_SBUS_RESET_STATUS, %0x9af
|
||||
.constant api_MEMORY_REPAIR_STATUS, %0x9b0
|
||||
.constant api_MEMORY_INIT_STATUS, %0x9b1
|
||||
.constant api_PCIE_PCS_DIS_STATUS, %0x9b2
|
||||
.constant api_PCIE_MASTER_FW_DL_STATUS, %0x9b3
|
||||
.constant api_PCIE_FW_CHECK_STATUS, %0x9b4
|
||||
.constant api_PCIE_SERDES_FW_DL_STATUS, %0x9b5
|
||||
.constant api_PCIE_SERDES_INIT_STATUS, %0x9b6
|
||||
.constant api_PCIE_PCS_EN_STATUS, %0x9b7
|
||||
.constant api_PCIE_DE_WARM_RESET_STATUS, %0x9b8
|
||||
.constant api_PCIE_ISR_STATUS_0, %0x9b9
|
||||
.constant api_PCIE_ISR_STATUS_1, %0x9ba
|
||||
.constant api_PCIE_ISR_STATUS_2, %0x9bb
|
||||
.constant api_PCIE_ISR_STATUS_3, %0x9bc
|
||||
.constant api_PCIE_ISR_STATUS_4, %0x9bd
|
||||
.constant api_PCIE_ISR_STATUS_5, %0x9be
|
||||
.constant api_PCIE_ISR_STATUS_6, %0x9bf
|
||||
.constant api_PCIE_ISR_STATUS_7, %0x9c0
|
||||
.constant api_PCIE_ISR_STATUS_8, %0x9c1
|
||||
.constant api_SERDES_OOR_STATUS_PASS_1, %0x9c2
|
||||
.constant api_SERDES_OOR_STATUS_PASS_2, %0x9c3
|
||||
.constant api_SW_LOCK_ERR_STATUS, %0x9c4
|
||||
.constant api_PCIE_EN_REFCLK_STATUS, %0x9c5
|
||||
.constant api_RE_RESET_MASK_STATUS_1, %0x9c6
|
||||
.constant api_RE_RESET_MASK_STATUS_2, %0x9c7
|
||||
.constant api_RE_RESET_ERR_STATUS, %0x9c8
|
||||
.reserve api_DE_COLD_RESET_STATUS, 0x1ae
|
||||
.reserve api_SBUS_RESET_STATUS, 0x1af
|
||||
.reserve api_MEMORY_REPAIR_STATUS, 0x1b0
|
||||
.reserve api_MEMORY_INIT_STATUS, 0x1b1
|
||||
.reserve api_PCIE_PCS_DIS_STATUS, 0x1b2
|
||||
.reserve api_PCIE_MASTER_FW_DL_STATUS, 0x1b3
|
||||
.reserve api_PCIE_FW_CHECK_STATUS, 0x1b4
|
||||
.reserve api_PCIE_SERDES_FW_DL_STATUS, 0x1b5
|
||||
.reserve api_PCIE_SERDES_INIT_STATUS, 0x1b6
|
||||
.reserve api_PCIE_PCS_EN_STATUS, 0x1b7
|
||||
.reserve api_PCIE_DE_WARM_RESET_STATUS, 0x1b8
|
||||
.reserve api_PCIE_ISR_STATUS_0, 0x1b9
|
||||
.reserve api_PCIE_ISR_STATUS_1, 0x1ba
|
||||
.reserve api_PCIE_ISR_STATUS_2, 0x1bb
|
||||
.reserve api_PCIE_ISR_STATUS_3, 0x1bc
|
||||
.reserve api_PCIE_ISR_STATUS_4, 0x1bd
|
||||
.reserve api_PCIE_ISR_STATUS_5, 0x1be
|
||||
.reserve api_PCIE_ISR_STATUS_6, 0x1bf
|
||||
.reserve api_PCIE_ISR_STATUS_7, 0x1c0
|
||||
.reserve api_PCIE_ISR_STATUS_8, 0x1c1
|
||||
.reserve api_SERDES_OOR_STATUS_PASS_1, 0x1c2
|
||||
.reserve api_SERDES_OOR_STATUS_PASS_2, 0x1c3
|
||||
.reserve api_SW_LOCK_ERR_STATUS, 0x1c4
|
||||
.reserve api_PCIE_EN_REFCLK_STATUS, 0x1c5
|
||||
.reserve api_RE_RESET_MASK_STATUS_1, 0x1c6
|
||||
.reserve api_RE_RESET_MASK_STATUS_2, 0x1c7
|
||||
.reserve api_RE_RESET_ERR_STATUS, 0x1c8
|
|
@ -1,4 +1,4 @@
|
|||
; Initialization function
|
||||
; Initialization function (aka crt0)
|
||||
|
||||
__rrcc_init:
|
||||
WRITE rrcc_STACK_POINTER, rrcc_STACK_START ; Reset Stack pointer to its starting position
|
||||
|
|
|
@ -258,7 +258,7 @@ uint32_t Assembler::placeFunction(uint32_t base, const Function &function) {
|
|||
debugData.emplace_back(v);
|
||||
}
|
||||
|
||||
auto loadInstruction = Instruction::Load({endOffset, 0}, 0, debugData); //Tag end of function, and data
|
||||
auto loadInstruction = Instruction::Load({endOffset, 0 /*TODO: can place 2 bits of data here!*/}, 0 /*TODO: can place 1 bit of data here!*/, debugData); //Tag end of function, and data
|
||||
auto data = loadInstruction.toBytes();
|
||||
|
||||
std::copy(data.begin(), data.end(), bytes.begin() + offset);
|
||||
|
|
|
@ -29,13 +29,17 @@
|
|||
|
||||
|
||||
enum class MgmtRegisters {
|
||||
MGMT_SCRATCH_0 = 0x8,
|
||||
MGMT_SCRATCH_0 = 0x8, //RRET
|
||||
MGMT_SCRATCH_1 = 0x9,
|
||||
|
||||
SRAM_ERR_IM_0 = 0x448,
|
||||
|
||||
SW_IM = 0x44E,
|
||||
|
||||
BSM_SCRATCH_START = 0x800,
|
||||
BSM_SCRATCH_END = 0xBFF,
|
||||
|
||||
BSM_ADDR_OFFSET_0 = 0xC04,
|
||||
BSM_ADDR_OFFSET_0 = 0xC04, // Read-only, 0x000000
|
||||
BSM_ADDR_OFFSET_1 = BSM_ADDR_OFFSET_0 + 1,
|
||||
BSM_ADDR_OFFSET_2 = BSM_ADDR_OFFSET_0 + 2,
|
||||
BSM_ADDR_OFFSET_3 = BSM_ADDR_OFFSET_0 + 3,
|
||||
|
@ -44,5 +48,5 @@ enum class MgmtRegisters {
|
|||
BSM_COUNTER_1 = 0xC09,
|
||||
|
||||
INTERNAL_REGISTER_ALWAYS_00000000 = BSM_ADDR_OFFSET_0, //Read only, set at 0
|
||||
INTERNAL_REGISTER_ALWAYS_FFFFFFFF = 0x448, //SRAM_ERR_IM_0 0x448 is default two x with 48 1b bits. RW but it's not changed by default. Alternatively SW_IM 0x44E is also set to 0xFFFFFFFF
|
||||
INTERNAL_REGISTER_ALWAYS_FFFFFFFF = SRAM_ERR_IM_0, //SRAM_ERR_IM_0 is default two x with 48 1b bits. RW but it's not changed by default. Alternatively SW_IM is also set to 0xFFFFFFFF
|
||||
};
|
|
@ -32,9 +32,7 @@
|
|||
|
||||
class Function {
|
||||
public:
|
||||
Function() {
|
||||
|
||||
}
|
||||
Function() = default;
|
||||
|
||||
std::string label;
|
||||
std::vector<Declaration> declarations;
|
||||
|
|
|
@ -34,6 +34,9 @@ void Linker::addFromParser(const Parser &p) {
|
|||
for (auto &v : p.getVariables()) {
|
||||
variables[v.first] = v.second;
|
||||
}
|
||||
for (auto &v : p.getReservations()) {
|
||||
reservations[v.first] = v.second;
|
||||
}
|
||||
}
|
||||
|
||||
void Linker::addFunction(const Function &f) {
|
||||
|
@ -83,3 +86,10 @@ uint32_t Linker::getIntegerConstant(const std::string &name, uint32_t defaultVal
|
|||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
void Linker::addReservation(uint32_t a, const std::string &v) {
|
||||
if(getReservations().find(a) != getReservations().end()){
|
||||
throw std::runtime_error(v + " already reserved as " + getReservations().at(a));
|
||||
}
|
||||
reservations[a] = v;
|
||||
}
|
||||
|
|
11
src/Linker.h
11
src/Linker.h
|
@ -32,15 +32,16 @@
|
|||
class Linker {
|
||||
std::vector<Function> functions;
|
||||
std::unordered_map<std::string, std::vector<Token>> variables;
|
||||
std::unordered_map<uint32_t, std::string> reservations;
|
||||
public:
|
||||
Linker() {
|
||||
|
||||
}
|
||||
Linker() = default;
|
||||
|
||||
void addFunction(const Function &f);
|
||||
|
||||
void addVariable(const std::string &k, const std::vector<Token> &v);
|
||||
|
||||
void addReservation(uint32_t a, const std::string &v);
|
||||
|
||||
void addFromParser(const Parser &p);
|
||||
|
||||
const std::vector<Function> &getTree() const {
|
||||
|
@ -51,6 +52,10 @@ public:
|
|||
return variables;
|
||||
}
|
||||
|
||||
const auto &getReservations() const {
|
||||
return reservations;
|
||||
}
|
||||
|
||||
std::string getTextConstant(const std::string& name, const std::string& defaultValue = "", bool throwOnNotFound = false) const;
|
||||
|
||||
uint32_t getIntegerConstant(const std::string& name, uint32_t defaultValue = 0, bool throwOnNotFound = false) const;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <iostream>
|
||||
#include "Parser.h"
|
||||
#include "BaseRegisters.h"
|
||||
|
||||
void Parser::parse() {
|
||||
offset = 0;
|
||||
|
@ -126,6 +127,28 @@ void Parser::parse() {
|
|||
foundToken = true;
|
||||
}
|
||||
break;
|
||||
case Token::Type::AsValue:
|
||||
if (currentValue == "&" && !currentDeclaration.tokens.empty()) {
|
||||
auto& prevValue = currentDeclaration.tokens.at(currentDeclaration.tokens.size() - 1);
|
||||
if(prevValue.getType() == Token::Type::Immediate || prevValue.getType() == Token::Type::CodeLabel || prevValue.getType() == Token::Type::CodeLocation || prevValue.getType() == Token::Type::RegisterLocation){
|
||||
prevValue.type = Token::Type::Immediate;
|
||||
}else{
|
||||
throw std::runtime_error("Cannot apply AsValue to value not numeric");
|
||||
}
|
||||
foundToken = true;
|
||||
}
|
||||
break;
|
||||
case Token::Type::AsIndirect:
|
||||
if (currentValue == "*" && !currentDeclaration.tokens.empty()) {
|
||||
auto& prevValue = currentDeclaration.tokens.at(currentDeclaration.tokens.size() - 1);
|
||||
if(prevValue.getType() == Token::Type::Immediate || prevValue.getType() == Token::Type::CodeLabel || prevValue.getType() == Token::Type::CodeLocation || prevValue.getType() == Token::Type::RegisterLocation){
|
||||
prevValue.type = Token::Type::RegisterLocation;
|
||||
}else{
|
||||
throw std::runtime_error("Cannot apply AsIndirect to value not numeric");
|
||||
}
|
||||
foundToken = true;
|
||||
}
|
||||
break;
|
||||
case Token::Type::Offset:
|
||||
if (isOffset(currentValue) && !currentDeclaration.tokens.empty()) {
|
||||
auto& prevValue = currentDeclaration.tokens.at(currentDeclaration.tokens.size() - 1);
|
||||
|
@ -138,15 +161,17 @@ void Parser::parse() {
|
|||
}
|
||||
break;
|
||||
case Token::Type::Directive:
|
||||
if (isDirective(currentValue) && currentValue == ".constant") {
|
||||
if (!currentFunction.label.empty()) {
|
||||
functions.emplace_back(std::move(currentFunction));
|
||||
currentFunction = Function();
|
||||
}
|
||||
if (isDirective(currentValue)) {
|
||||
if(currentValue == ".constant" || currentValue == ".reserve"){
|
||||
if (!currentFunction.label.empty()) {
|
||||
functions.emplace_back(std::move(currentFunction));
|
||||
currentFunction = Function();
|
||||
}
|
||||
|
||||
currentDeclaration.tokens.emplace_back(
|
||||
Token(t.first, currentValue));
|
||||
foundToken = true;
|
||||
currentDeclaration.tokens.emplace_back(
|
||||
Token(t.first, currentValue));
|
||||
foundToken = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Token::Type::BareValue:
|
||||
|
@ -194,6 +219,18 @@ void Parser::parse() {
|
|||
if (!currentDeclaration.tokens.empty()) {
|
||||
if (currentDeclaration.tokens.size() >= 3 &&
|
||||
currentDeclaration.tokens.at(0).getType() == Token::Type::Directive) {
|
||||
|
||||
if (currentDeclaration.tokens.at(0).getTextValue() == ".reserve") {
|
||||
if(reservations.find(currentDeclaration.tokens.at(2).getNumericValue()) == reservations.end()){
|
||||
uint32_t addr = currentDeclaration.tokens.at(2).getNumericValue();
|
||||
reservations[addr] = currentDeclaration.tokens.at(1).getTextValue();
|
||||
variables[currentDeclaration.tokens.at(1).getTextValue()] = {Token(Token::Type::RegisterLocation, std::to_string((uint32_t) MgmtRegisters::BSM_SCRATCH_START + addr), (uint32_t) MgmtRegisters::BSM_SCRATCH_START + addr)};
|
||||
}else{
|
||||
//Collision
|
||||
throw std::runtime_error("Reservation " + currentDeclaration.tokens.at(1).getTextValue() + " collides value " + std::to_string(currentDeclaration.tokens.at(2).getNumericValue()));
|
||||
}
|
||||
}
|
||||
|
||||
if (currentDeclaration.tokens.at(0).getTextValue() == ".constant") {
|
||||
std::vector<Token> tokens;
|
||||
for (auto it = currentDeclaration.tokens.begin() + 2;
|
||||
|
|
10
src/Parser.h
10
src/Parser.h
|
@ -40,6 +40,7 @@ class Parser {
|
|||
const std::vector<uint8_t> &bytes;
|
||||
std::vector<Function> functions;
|
||||
std::unordered_map<std::string, std::vector<Token>> variables;
|
||||
std::unordered_map<uint32_t, std::string> reservations;
|
||||
|
||||
|
||||
uint8_t getByte() {
|
||||
|
@ -97,12 +98,11 @@ class Parser {
|
|||
static bool isAlphaNumeric(const std::string &v);
|
||||
|
||||
public:
|
||||
Parser(const std::vector<uint8_t> &bytes, std::unordered_map<std::string, std::vector<Token>> variables) : bytes(
|
||||
bytes), variables(std::move(variables)) {
|
||||
Parser(const std::vector<uint8_t> &bytes, std::unordered_map<std::string, std::vector<Token>> variables, std::unordered_map<uint32_t, std::string> reservations) : offset(0), bytes(bytes), variables(std::move(variables)), reservations(std::move(reservations)) {
|
||||
|
||||
}
|
||||
|
||||
Parser(const std::vector<uint8_t> &bytes) : bytes(bytes) {
|
||||
Parser(const std::vector<uint8_t> &bytes) : offset(0), bytes(bytes) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,4 +115,8 @@ public:
|
|||
const auto &getVariables() const {
|
||||
return variables;
|
||||
}
|
||||
|
||||
const auto &getReservations() const {
|
||||
return reservations;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -53,6 +53,9 @@ public:
|
|||
|
||||
Offset, // {+-}{32-bit unsigned integer}, will apply to previous value
|
||||
|
||||
AsValue, // &
|
||||
AsIndirect, // *
|
||||
|
||||
// A comment is ;{....} anything that starts with ; . Reads until \n
|
||||
|
||||
//End of Token: \n\t[space],;
|
||||
|
|
|
@ -44,7 +44,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
for (auto &r : embeddedResources) {
|
||||
std::vector<uint8_t> bytes(r.begin(), r.end());
|
||||
Parser parser(bytes, linker.getVariables());
|
||||
Parser parser(bytes, linker.getVariables(), linker.getReservations());
|
||||
parser.parse();
|
||||
linker.addFromParser(parser);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
|
|||
while (!image.eof() && (c = image.get()) != EOF) {
|
||||
bytes.push_back(c);
|
||||
}
|
||||
Parser parser(bytes, linker.getVariables());
|
||||
Parser parser(bytes, linker.getVariables(), linker.getReservations());
|
||||
parser.parse();
|
||||
linker.addFromParser(parser);
|
||||
} else {
|
||||
|
@ -74,7 +74,7 @@ int main(int argc, char *argv[]) {
|
|||
//Load base init
|
||||
auto res = LOAD_RESOURCE(asm_init_asm);
|
||||
std::vector<uint8_t> bytes(res.begin(), res.end());
|
||||
Parser parser(bytes, linker.getVariables());
|
||||
Parser parser(bytes, linker.getVariables(), linker.getReservations());
|
||||
parser.parse();
|
||||
linker.addFromParser(parser);
|
||||
|
||||
|
|
Loading…
Reference in a new issue