From e0056e1f59f157caf64f4b7c7b5acea38879fc40 Mon Sep 17 00:00:00 2001 From: "JASON-6700K\\jandersen" Date: Sat, 3 Feb 2024 14:07:46 -0500 Subject: [PATCH] import: overlay helper tool, for generating linker script symbols --- bin/overlayhelper.exe | Bin 0 -> 22528 bytes bin/overlayhelper/source/bctypes.h | 48 ++++ bin/overlayhelper/source/cfile.cpp | 208 ++++++++++++++++++ bin/overlayhelper/source/cfile.h | 27 +++ bin/overlayhelper/source/memstream.h | 164 ++++++++++++++ bin/overlayhelper/source/overlayhelper.cpp | 70 ++++++ bin/overlayhelper/vcxproj/overlayhelper.sln | 31 +++ .../vcxproj/overlayhelper.vcxproj | 147 +++++++++++++ .../vcxproj/overlayhelper.vcxproj.filters | 26 +++ 9 files changed, 721 insertions(+) create mode 100644 bin/overlayhelper.exe create mode 100644 bin/overlayhelper/source/bctypes.h create mode 100644 bin/overlayhelper/source/cfile.cpp create mode 100644 bin/overlayhelper/source/cfile.h create mode 100644 bin/overlayhelper/source/memstream.h create mode 100644 bin/overlayhelper/source/overlayhelper.cpp create mode 100644 bin/overlayhelper/vcxproj/overlayhelper.sln create mode 100644 bin/overlayhelper/vcxproj/overlayhelper.vcxproj create mode 100644 bin/overlayhelper/vcxproj/overlayhelper.vcxproj.filters diff --git a/bin/overlayhelper.exe b/bin/overlayhelper.exe new file mode 100644 index 0000000000000000000000000000000000000000..7770bb0658b63333739147d5be8f51be5b969ea4 GIT binary patch literal 22528 zcmeHv4R}=5wf3H5CJ7UWq@|6GPkhQw-WN-@EoXlS~5W z)AqT~eZKGM;W=mRz4qE`@4fcgYp=cb1ozjQSt4W1h&LK#tObxBoA`eDrys>*t~oS@ z{c_ZasVxTAiK#`ERerhNSGUnuS|gX0*4EYq?JW<=$E8>8Vzo z^%GZDJonE1DUZe8zT_V~_6OwOyO93qc>&WNRRtXV=-UF0dh~aIPbH6fv zuE_y3i?q!^fYJ$!B?;6JWV?YN;o(VSCEH?^^t!-mOk#lObPOfgw^uUuCM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vas?B26)PtP88Pye2Q zJ#25vUi03Jz4G3yy|%r4Z{gm?Cz_ww^@RN7{3mTs@+S+QT=OJ2mtbuGH16KLyL0!z NZY2Nl{68Rp{|hw7gCGC^ literal 0 HcmV?d00001 diff --git a/bin/overlayhelper/source/bctypes.h b/bin/overlayhelper/source/bctypes.h new file mode 100644 index 0000000..d2b2a5f --- /dev/null +++ b/bin/overlayhelper/source/bctypes.h @@ -0,0 +1,48 @@ +/* + bctypes.h + + Because I need Standard Types +*/ + +#ifndef _bctypes_h +#define _bctypes_h + +typedef signed char i8; +typedef unsigned char u8; +typedef signed short i16; +typedef unsigned short u16; +typedef signed long i32; +typedef unsigned long u32; + +typedef signed long long i64; +typedef unsigned long long u64; + +// If we're using C, I still like having a bool around +#ifndef __cplusplus +typedef i32 bool; +#define false (0) +#define true (!false) +#define nullptr 0 +#endif + +typedef float f32; +typedef float r32; +typedef double f64; +typedef double r64; + + +#define null (0) + +// Odd Types +typedef union { +// u128 ul128; + u64 ul64[2]; + u32 ui32[4]; +} QWdata; + + +#endif // _bctypes_h + +// EOF - bctypes.h + + diff --git a/bin/overlayhelper/source/cfile.cpp b/bin/overlayhelper/source/cfile.cpp new file mode 100644 index 0000000..78cde94 --- /dev/null +++ b/bin/overlayhelper/source/cfile.cpp @@ -0,0 +1,208 @@ +// +// cfile.cpp +// +#include "cfile.h" +#include + +//------------------------------------------------------------------------------ +// Static Helpers + +static bool contains(char x, const char* pSeparators) +{ + while (*pSeparators) + { + if (x == *pSeparators) + { + return true; + } + pSeparators++; + } + + return false; +} + +static std::vector split(const std::string& s, const char* separators) +{ + std::vector output; + std::string::size_type prev_pos = 0, pos = 0; + + for (int index = 0; index < s.length(); ++index) + { + pos = index; + + // if the index is a separator + if (contains(s[index], separators)) + { + // if we've skipped a token, collect it + if (prev_pos != index) + { + output.push_back(s.substr(prev_pos, index-prev_pos)); + + // skip white space here + while (index < s.length()) + { + if (contains(s[index], separators)) + { + ++index; + } + else + { + prev_pos = index; + pos = index; + break; + } + } + } + else + { + prev_pos++; + } + } + } + + output.push_back(s.substr(prev_pos, pos-prev_pos+1)); // Last word + + return output; +} + +// make this string lowercase +static void tolower(std::string& s) +{ + for (int index = 0; index < s.length(); ++index) + { + s[index] = tolower( s[index] ); + } +} + +static std::string next_token(std::vector& tokens, MemoryStream& memStream) +{ + std::string result = ""; + + if (tokens.size() >= 1) + { + result = tokens[0]; + tokens.erase(tokens.cbegin()); + } + else + { + while (memStream.NumBytesAvailable()) + { + std::string lineData = memStream.ReadLine(); + tokens = split(lineData, "[](), \t"); + + if (tokens.size() >= 1) + { + return next_token(tokens, memStream); + } + } + + } + return result; +} + +//------------------------------------------------------------------------------ +CFile::CFile( std::string filepath ) + : m_filepath( filepath ) +{ + FILE* pFile = nullptr; + errno_t err = fopen_s(&pFile, filepath.c_str(), "rb"); + + if (0==err) + { + fseek(pFile, 0, SEEK_END); + size_t length = ftell(pFile); + fseek(pFile, 0, SEEK_SET); + + //printf("\n// CFile %s - %lld bytes\n", filepath.c_str(), length); + //printf("// Reading %s\n", filepath.c_str()); + //printf("//\n"); + //printf("// This file generated by overlayhelper.exe\n"); + //printf("//\n"); + //printf("//\n"); + + u8* pData = new u8[ length ]; + + fread(pData, sizeof(u8), length / sizeof(u8), pFile); + + // Now we have a buffer, with the whole C File + // Looking to parse 2 types of things + // CODE_BLOCK macros + // DATA_BLOCK macros + // INCBIN macros + { + MemoryStream memStream(pData, length); + + while (memStream.NumBytesAvailable()) + { + std::string lineData = memStream.ReadLine(); + + // symbols are case sensitive + + // we care about the first 32 bit value in hex, and the last value on the line, the symbol + std::vector tokens = split(lineData, "[](), \t"); + + if (tokens.size() >= 2) + { + std::string token = next_token(tokens, memStream); + + if (token == "INCBIN") + { + // section + token = next_token(tokens, memStream); + token = next_token(tokens, memStream); + + printf("incbin_%s_start_high = incbin_%s_start>>16;\n", token.c_str(),token.c_str()); + printf("incbin_%s_start_BLOCK = incbin_%s_start/0x2000;\n", token.c_str(),token.c_str()); + printf("incbin_%s_length = incbin_%s_end-incbin_%s_start;\n", token.c_str(),token.c_str(),token.c_str()); + printf("incbin_%s_length_high = incbin_%s_length>>16;\n", token.c_str(),token.c_str()); + + } + else if ( (token == "CODE_BLOCK") || + (token == "DATA_BLOCK") ) + { + // We aren't as good as the C Preprocessor, but we will allow this + // to span 1 line, because RickJr has weird syntax + + // First get the block number + token = next_token(tokens, memStream); + u32 block_num = strtoul(token.c_str(), nullptr, 0); + + // Next we need the function name + do + { + token = next_token(tokens, memStream); + + } while (token=="static" || token =="volatile"); + + // now token has return type + + token = next_token(tokens, memStream); + + // now token finally has our function or data name + printf("%s_BLOCK = %d;\n", token.c_str(), block_num); // just need the block number for mapper + } + } + } + } + + delete[] pData; + + fclose(pFile); + + //printf("\n// Read Completed\n"); + } + else + { + printf("// CFile could not open %s\n", filepath.c_str()); + printf("//\n"); + } +} + +//------------------------------------------------------------------------------ + +CFile::~CFile() +{ +} + +//------------------------------------------------------------------------------ + diff --git a/bin/overlayhelper/source/cfile.h b/bin/overlayhelper/source/cfile.h new file mode 100644 index 0000000..d29cb19 --- /dev/null +++ b/bin/overlayhelper/source/cfile.h @@ -0,0 +1,27 @@ +// +// CFile Class +// + +#ifndef CFILE_H_ +#define CFILE_H_ + +#include +#include + +#include "bctypes.h" +#include "memstream.h" + +//------------------------------------------------------------------------------ + +class CFile +{ +public: + CFile( std::string filepath ); + ~CFile(); + +private: + std::string m_filepath; +}; + +#endif // CFILE_H_ + diff --git a/bin/overlayhelper/source/memstream.h b/bin/overlayhelper/source/memstream.h new file mode 100644 index 0000000..5adc146 --- /dev/null +++ b/bin/overlayhelper/source/memstream.h @@ -0,0 +1,164 @@ +// +// Jason's Memory Stream Helper thing +// Serialize a byte stream into real types +// +// Currently only support Little Endian +// + +#ifndef MEMSTREAM_H_ +#define MEMSTREAM_H_ + + +#include + +// Prototypes +void *memcpy(void *dest, const void *src, size_t n); + +class MemoryStream +{ +public: + MemoryStream(unsigned char* pStreamStart, size_t streamSize) + : m_pStreamStart( pStreamStart ) + , m_streamSize(streamSize) + , m_pStreamCurrent( pStreamStart ) + {} + + ~MemoryStream() + { + m_pStreamStart = nullptr; + m_streamSize = 0; + m_pStreamCurrent = nullptr; + } + + // Really Dumb Reader Template + template + T Read() + { + T result; + + memcpy(&result, m_pStreamCurrent, sizeof(T)); + m_pStreamCurrent += sizeof(T); + + return result; + } + + template + void Read(T& result) + { + memcpy(&result, m_pStreamCurrent, sizeof(result)); + m_pStreamCurrent += sizeof(result); + } + + void ReadBytes(u8* pDest, size_t numBytes) + { + memcpy(pDest, m_pStreamCurrent, numBytes); + m_pStreamCurrent += numBytes; + } + + std::string ReadPString() + { + std::string result; + + u8 length = *m_pStreamCurrent++; + + result.insert(0, (char*)m_pStreamCurrent, (size_t)length); + + m_pStreamCurrent += length; + + return result; + } + + std::string ReadLine() + { + unsigned char* pStreamEnd = m_pStreamStart + m_streamSize; + + std::string result; + + u8 *pEndOfLine = m_pStreamCurrent; + + while (pEndOfLine < pStreamEnd) + { + if ((0x0a != *pEndOfLine) && (0x0d != *pEndOfLine)) + { + pEndOfLine++; + } + else + { + break; + } + } + + size_t length = pEndOfLine - m_pStreamCurrent; + + if (length) + { + // Capture the line + result.insert(0, (char*)m_pStreamCurrent, (size_t)length); + m_pStreamCurrent += length; + } + + // Figure out if that loop broke out because we hit the end of the file + while (pEndOfLine < pStreamEnd) + { + if ((0x0a == *pEndOfLine) || (0x0d == *pEndOfLine)) + { + pEndOfLine++; + } + else + { + break; + } + } + + m_pStreamCurrent = pEndOfLine; + if (m_pStreamCurrent > pStreamEnd) + { + m_pStreamCurrent = pStreamEnd; + } + return result; + + } + + size_t SeekCurrent(int delta) + { + m_pStreamCurrent += delta; + return m_pStreamCurrent - m_pStreamStart; + } + + size_t SeekSet(size_t offset) + { + m_pStreamCurrent = m_pStreamStart + offset; + return m_pStreamCurrent - m_pStreamStart; + } + + unsigned char* GetPointer() { return m_pStreamCurrent; } + + size_t NumBytesAvailable() { + + unsigned char* pStreamEnd = m_pStreamStart + m_streamSize; + + if (pStreamEnd - m_pStreamCurrent >= 0) + { + return pStreamEnd - m_pStreamCurrent; + } + else + { + return 0; + } + } + + + +private: + + unsigned char* m_pStreamStart; + size_t m_streamSize; + + unsigned char* m_pStreamCurrent; + +}; + + +#endif // MEMSTREAM_H_ + + diff --git a/bin/overlayhelper/source/overlayhelper.cpp b/bin/overlayhelper/source/overlayhelper.cpp new file mode 100644 index 0000000..cef6483 --- /dev/null +++ b/bin/overlayhelper/source/overlayhelper.cpp @@ -0,0 +1,70 @@ +// overlayhelper +// +// - generate linker script crap, so that we can resolve addresses larger +// than 32-bit with mos llvm (hacky work around for 16 bit address linker) + +#include +#include + +#include "cfile.h" + +//------------------------------------------------------------------------------ +void helpText() +{ + printf("overlayhelper - v1.0\n"); + printf("--------------------\n"); + printf("Convert macros found in C code, into mos-llvm .ld linker format\n"); + printf("\noverlayhelper [options] \n"); + printf(" -v verbose\n\n"); + + exit(-1); +} + +//------------------------------------------------------------------------------ + +int main(int argc, char* argv[]) +{ + char* pInfilePath = nullptr; + bool bVerbose = false; + + for (int idx = 1; idx < argc; ++idx ) + { + char* arg = argv[ idx ]; + + if ('-' == arg[0]) + { + // Parse as an option + if ('v'==arg[1]) + { + bVerbose = true; + } + } + else if (nullptr == pInfilePath) + { + // Assume the first non-option is an input file path + pInfilePath = argv[ idx ]; + } + else + { + // Oh Crap, we have a non-option, but we don't know what to do with + // it + printf("ERROR: Invalid option, Arg %d = %s\n\n", idx, argv[ idx ]); + helpText(); + } + } + + if (pInfilePath) + { + // Load the .c File + CFile *pCFile = new CFile(std::string(pInfilePath)); + delete pCFile; + } + else + { + helpText(); + } + + + return 0; +} + diff --git a/bin/overlayhelper/vcxproj/overlayhelper.sln b/bin/overlayhelper/vcxproj/overlayhelper.sln new file mode 100644 index 0000000..a2c004f --- /dev/null +++ b/bin/overlayhelper/vcxproj/overlayhelper.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "overlayhelper", "overlayhelper.vcxproj", "{77D5186F-C388-4740-8BA7-23997A659FB8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {77D5186F-C388-4740-8BA7-23997A659FB8}.Debug|x64.ActiveCfg = Debug|x64 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Debug|x64.Build.0 = Debug|x64 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Debug|x86.ActiveCfg = Debug|Win32 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Debug|x86.Build.0 = Debug|Win32 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Release|x64.ActiveCfg = Release|x64 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Release|x64.Build.0 = Release|x64 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Release|x86.ActiveCfg = Release|Win32 + {77D5186F-C388-4740-8BA7-23997A659FB8}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4AE0A6E5-5981-4BAE-96E2-DDD5656B0B2E} + EndGlobalSection +EndGlobal diff --git a/bin/overlayhelper/vcxproj/overlayhelper.vcxproj b/bin/overlayhelper/vcxproj/overlayhelper.vcxproj new file mode 100644 index 0000000..b8a9574 --- /dev/null +++ b/bin/overlayhelper/vcxproj/overlayhelper.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {77d5186f-c388-4740-8ba7-23997a659fb8} + overlayhelper + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)\..\.. + + + $(SolutionDir)\..\.. + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/overlayhelper/vcxproj/overlayhelper.vcxproj.filters b/bin/overlayhelper/vcxproj/overlayhelper.vcxproj.filters new file mode 100644 index 0000000..15e4d2b --- /dev/null +++ b/bin/overlayhelper/vcxproj/overlayhelper.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + + + Source Files + + + Source Files + + + Source Files + + + + + Source Files + + + + \ No newline at end of file