DataHoarder
e76befaed7
All checks were successful
continuous-integration/drone/push Build is passing
158 lines
5.8 KiB
C++
158 lines
5.8 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2020, rrcc FM10K-Documentation Contributors
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* * Neither the name of the copyright holder nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "Linker.h"
|
|
#include "instructions/Instruction.h"
|
|
|
|
class Assembler {
|
|
private:
|
|
const Linker &linker;
|
|
bool placeSymbols = true;
|
|
std::vector<uint8_t> bytes;
|
|
std::unordered_map<std::string, uint32_t> knownRegisters;
|
|
std::unordered_map<std::string, std::pair<uint32_t, bool>> entries;
|
|
|
|
uint32_t placeFunction(uint32_t base, const Function &function);
|
|
|
|
const Function *getFunctionByLabel(const std::string &l);
|
|
|
|
public:
|
|
|
|
Assembler(const Linker &linker) : linker(linker) {
|
|
|
|
}
|
|
|
|
typedef struct ImageConfig{
|
|
struct {
|
|
uint8_t spiTransferMode = 0;
|
|
uint8_t spiTransferSpeed = 7;
|
|
uint32_t baseAddress = 0x080000;
|
|
} header;
|
|
uint32_t buildVersion = 0x0000;
|
|
|
|
struct {
|
|
uint32_t baseAddress = 0x2000;
|
|
std::vector<std::string> entries;
|
|
uint16_t headerPrevShort = 0x0B52; //Have seen 0x0B52, 0x7B52, and 0x616E on FM10420
|
|
std::vector<uint8_t> headerExtraBytes = {
|
|
0x12, 0xE1, //Have seen 0x12E1, 0x0AE1, and 0x05E7 on FM10420
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
};
|
|
} properties;
|
|
|
|
std::vector<uint8_t> headerExtraBytes = {
|
|
0x40,0x08,0x00,0x00, // location 0x0014
|
|
0x40,0x0C,0x00,0x00,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x80,0x08,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x81,0xCF,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x83,0x96,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x85,0x5D,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x87,0x24,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x88,0xEB,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x8A,0xB2,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x8C,0x79,
|
|
0xDC/**0x44 in FM10420-QDA2*/,0x00,0x8E,0x40,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00, // location 0x0048, here a null terminated string can be placed with manufacturer info
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x02,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0xD3,0xEF, /**0x00,0x00,0x2B,0x6E in FM10420-QDA2*/
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00
|
|
};
|
|
std::string buildSignature;
|
|
|
|
} ImageConfig;
|
|
|
|
//Default max size 1 MiB
|
|
void assemble(const std::string& entrypointName, const ImageConfig& imageConfig, uint32_t maxImageSize = 0x100000);
|
|
|
|
void setPlaceSymbols(bool place) {
|
|
placeSymbols = place;
|
|
}
|
|
|
|
const auto &getImage() const {
|
|
return bytes;
|
|
}
|
|
|
|
enum class FunctionPlacementMode {
|
|
PlaceAll,
|
|
PlaceOnUse,
|
|
};
|
|
|
|
|
|
void setFunctionPlacementMode(FunctionPlacementMode mode) {
|
|
placementMode = mode;
|
|
}
|
|
|
|
private:
|
|
FunctionPlacementMode placementMode = FunctionPlacementMode::PlaceOnUse;
|
|
};
|