diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-18 13:17:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-18 13:17:48 +0100 |
| commit | 70122df2b7ef965ff79405fe2732f153c9a4098f (patch) | |
| tree | f9b9741539499b22e9e92de8c10eefcd347bea2b | |
| parent | fbd41a98e2d9ab1e0e1eb63d46f066da3faf134e (diff) | |
MP/CC Revision 94:
- Merge 32x0/64x0 toolchain for PEF.
- Will work on a 32x0 assembler for PEF abi.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | 32x0-Drivers/bin/.gitkeep | 0 | ||||
| -rw-r--r-- | 32x0-Drivers/bin/Source/.gitkeep | 0 | ||||
| -rw-r--r-- | 64x0-Drivers/bin/.gitkeep | 0 | ||||
| -rw-r--r-- | Drivers/.gitignore (renamed from 64x0-Drivers/.gitignore) | 1 | ||||
| -rw-r--r-- | Drivers/64asm.cc (renamed from 64x0-Drivers/64asm.cc) | 2 | ||||
| -rw-r--r-- | Drivers/bccl.cc (renamed from 64x0-Drivers/bccl.cc) | 0 | ||||
| -rw-r--r-- | Drivers/bin/.gitkeep (renamed from 32x0-Drivers/.gitkeep) | 0 | ||||
| -rw-r--r-- | Drivers/bin/README.txt (renamed from 64x0-Drivers/bin/README.txt) | 0 | ||||
| -rw-r--r-- | Drivers/bin/Source/hello_world.32x (renamed from 32x0-Drivers/bin/Source/hello_world.32x) | 0 | ||||
| -rw-r--r-- | Drivers/bin/Source/hello_world.64x (renamed from 64x0-Drivers/bin/Source/decrement_until_zero.64x) | 0 | ||||
| -rw-r--r-- | Drivers/bpp.cc (renamed from 64x0-Drivers/bpp.cc) | 14 | ||||
| -rw-r--r-- | Drivers/ccplus.cc (renamed from 64x0-Drivers/ccplus.cc) | 0 | ||||
| -rw-r--r-- | Drivers/ld.cc (renamed from 64x0-Drivers/64ld.cc) | 66 | ||||
| -rw-r--r-- | Drivers/makefile (renamed from 64x0-Drivers/makefile) | 4 |
14 files changed, 51 insertions, 36 deletions
diff --git a/32x0-Drivers/bin/.gitkeep b/32x0-Drivers/bin/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/32x0-Drivers/bin/.gitkeep +++ /dev/null diff --git a/32x0-Drivers/bin/Source/.gitkeep b/32x0-Drivers/bin/Source/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/32x0-Drivers/bin/Source/.gitkeep +++ /dev/null diff --git a/64x0-Drivers/bin/.gitkeep b/64x0-Drivers/bin/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/64x0-Drivers/bin/.gitkeep +++ /dev/null diff --git a/64x0-Drivers/.gitignore b/Drivers/.gitignore index 49b6abe..323cdad 100644 --- a/64x0-Drivers/.gitignore +++ b/Drivers/.gitignore @@ -5,6 +5,7 @@ bin/bpp bin/cc bin/masm bin/64ld +bin/32ld bin/64asm bin/mkcdfs bin/ccplus diff --git a/64x0-Drivers/64asm.cc b/Drivers/64asm.cc index 4ca45e6..3a4b6dc 100644 --- a/64x0-Drivers/64asm.cc +++ b/Drivers/64asm.cc @@ -61,7 +61,7 @@ static CompilerKit::AERecordHeader kCurrentRecord{.fName = "", .fKind = Compiler static std::vector<CompilerKit::AERecordHeader> kRecords; static std::vector<std::string> kUndefinedSymbols; -static const std::string kUndefinedSymbol = ":64ld:"; +static const std::string kUndefinedSymbol = ":ld:"; static const std::string kRelocSymbol = ":mld:"; // \brief forward decl. diff --git a/64x0-Drivers/bccl.cc b/Drivers/bccl.cc index 952b7c4..952b7c4 100644 --- a/64x0-Drivers/bccl.cc +++ b/Drivers/bccl.cc diff --git a/32x0-Drivers/.gitkeep b/Drivers/bin/.gitkeep index e69de29..e69de29 100644 --- a/32x0-Drivers/.gitkeep +++ b/Drivers/bin/.gitkeep diff --git a/64x0-Drivers/bin/README.txt b/Drivers/bin/README.txt index 7530e5e..7530e5e 100644 --- a/64x0-Drivers/bin/README.txt +++ b/Drivers/bin/README.txt diff --git a/32x0-Drivers/bin/Source/hello_world.32x b/Drivers/bin/Source/hello_world.32x index e8c7d31..e8c7d31 100644 --- a/32x0-Drivers/bin/Source/hello_world.32x +++ b/Drivers/bin/Source/hello_world.32x diff --git a/64x0-Drivers/bin/Source/decrement_until_zero.64x b/Drivers/bin/Source/hello_world.64x index f342396..f342396 100644 --- a/64x0-Drivers/bin/Source/decrement_until_zero.64x +++ b/Drivers/bin/Source/hello_world.64x diff --git a/64x0-Drivers/bpp.cc b/Drivers/bpp.cc index ebf6317..0c8d45a 100644 --- a/64x0-Drivers/bpp.cc +++ b/Drivers/bpp.cc @@ -16,8 +16,8 @@ #define kMacroPrefix '%' // @author Amlal El Mahrouss (amlel) -// @file cpp.cc -// @brief MASM preprocessor. +// @file bpp.cc +// @brief BCCL preprocessor. typedef Int32(*cpp_parser_fn_t)(std::string& line, std::ifstream& hdr_file, std::ofstream& pp_out); @@ -383,7 +383,7 @@ void cpp_parse_file(std::ifstream& hdr_file, std::ofstream& pp_out) if (sym_vec.size() != macro.fArgs.size()) { - throw std::runtime_error("cpp: arguments count mismatch, except " + std::to_string(sym_vec.size()) + ", got: " + std::to_string(macro.fArgs.size())); + throw std::runtime_error("bpp: arguments count mismatch, except " + std::to_string(sym_vec.size()) + ", got: " + std::to_string(macro.fArgs.size())); return; } @@ -948,7 +948,7 @@ kIncludeFile: if (!open) { - throw std::runtime_error("cpp: no such include file: " + path); + throw std::runtime_error("bpp: no such include file: " + path); } } else @@ -956,14 +956,14 @@ kIncludeFile: std::ifstream header(kWoringDir + path); if (!header.is_open()) - throw std::runtime_error("cpp: no such include file: " + path); + throw std::runtime_error("bpp: no such include file: " + path); cpp_parse_file(header, pp_out); } } else { - std::cerr << ("cpp: unknown pre-processor directive, " + hdr_line) << "\n"; + std::cerr << ("bpp: unknown pre-processor directive, " + hdr_line) << "\n"; continue; } } @@ -1026,7 +1026,7 @@ int main(int argc, char** argv) if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "--help") == 0) { - printf("%s\n", "cpp v1.11, (c) Mahrouss Logic"); + printf("%s\n", "bpp v1.11, (c) Mahrouss Logic"); printf("%s\n", "--working-dir: set directory to working path."); printf("%s\n", "--include-dir: add directory to include path."); printf("%s\n", "--define: define macro."); diff --git a/64x0-Drivers/ccplus.cc b/Drivers/ccplus.cc index fc9d039..fc9d039 100644 --- a/64x0-Drivers/ccplus.cc +++ b/Drivers/ccplus.cc diff --git a/64x0-Drivers/64ld.cc b/Drivers/ld.cc index b8c7008..5bfb7a5 100644 --- a/64x0-Drivers/64ld.cc +++ b/Drivers/ld.cc @@ -1,7 +1,7 @@ /* * ======================================================== * - * 64ld + * ld * Copyright 2024, Mahrouss Logic, all rights reserved. * * ======================================================== @@ -31,7 +31,7 @@ //! @brief standard PEF entry. #define kPefStart "__start" -#define kToolVersion "64ld v2.1, (c) Mahrouss Logic 2024" +#define kToolVersion "ld v2.1, (c) Mahrouss Logic 2024" #define StringCompare(DST, SRC) strcmp(DST, SRC) @@ -57,14 +57,14 @@ static Bool kDuplicateSymbols = false; static Bool kVerbose = false; /* ld is to be found, mld is to be found at runtime. */ -static const char *kLdDefineSymbol = ":64ld:"; +static const char *kLdDefineSymbol = ":ld:"; static const char *kLdDynamicSym = ":mld:"; /* object code and list. */ static std::vector<std::string> kObjectList; static std::vector<char> kObjectBytes; -MPCC_MODULE(Linker64x0) +MPCC_MODULE(MPUXLinker) { bool is_executable = true; @@ -77,6 +77,8 @@ MPCC_MODULE(Linker64x0) kStdOut << "-verbose: Print program backtrace (verbose mode).\n"; kStdOut << "-shared: Output as a shared library.\n"; kStdOut << "-fat-binary: Output as FAT PEF.\n"; + kStdOut << "-m32x0: Output as 32x0 PEF.\n"; + kStdOut << "-m64x0: Output as 64x0 PEF.\n"; kStdOut << "-o: Select output filename.\n"; // bye @@ -95,6 +97,16 @@ MPCC_MODULE(Linker64x0) continue; } + else if (StringCompare(argv[i], "-m64x0") == 0) + { + kArch = CompilerKit::kPefArch64000; + continue; + } + else if (StringCompare(argv[i], "-m32x0") == 0) + { + kArch = CompilerKit::kPefArch32000; + continue; + } else if (StringCompare(argv[i], "-verbose") == 0) { kVerbose = true; @@ -122,7 +134,7 @@ MPCC_MODULE(Linker64x0) { if (argv[i][0] == '-') { - kStdOut << "64ld: unknown flag: " << argv[i] << "\n"; + kStdOut << "ld: unknown flag: " << argv[i] << "\n"; return -CXXKIT_EXEC_ERROR; } @@ -135,7 +147,7 @@ MPCC_MODULE(Linker64x0) // sanity check. if (kObjectList.empty()) { - kStdOut << "64ld: no input files." << std::endl; + kStdOut << "ld: no input files." << std::endl; return CXXKIT_EXEC_ERROR; } else @@ -147,7 +159,7 @@ MPCC_MODULE(Linker64x0) { // if filesystem doesn't find file // -> throw error. - kStdOut << "64ld: no such file: " << obj << std::endl; + kStdOut << "ld: no such file: " << obj << std::endl; return CXXKIT_EXEC_ERROR; } } @@ -156,7 +168,7 @@ MPCC_MODULE(Linker64x0) // PEF expects a valid architecture when outputing a binary. if (kArch == 0) { - kStdOut << "64ld: no target architecture set, can't continue." << std::endl; + kStdOut << "ld: no target architecture set, can't continue." << std::endl; return CXXKIT_EXEC_ERROR; } @@ -184,7 +196,7 @@ MPCC_MODULE(Linker64x0) { if (kVerbose) { - kStdOut << "64ld: error: " << strerror(errno) << "\n"; + kStdOut << "ld: error: " << strerror(errno) << "\n"; } return -CXXKIT_FILE_NOT_FOUND; @@ -214,14 +226,14 @@ MPCC_MODULE(Linker64x0) if (ae_header.fArch != kArch) { if (kVerbose) - kStdOut << "64ld: info: is a fat binary? : "; + kStdOut << "ld: info: is a fat binary? : "; if (!kFatBinaryEnable) { if (kVerbose) kStdOut << "no.\n"; - kStdOut << "64ld: error: object " << i << " is a different kind of architecture and output isn't treated as FAT binary." << std::endl; + kStdOut << "ld: error: object " << i << " is a different kind of architecture and output isn't treated as FAT binary." << std::endl; std::remove(kOutput.c_str()); return -CXXKIT_FAT_ERROR; @@ -240,7 +252,7 @@ MPCC_MODULE(Linker64x0) std::size_t cnt = ae_header.fCount; if (kVerbose) - kStdOut << "64ld: object header found, record count: " << cnt << "\n"; + kStdOut << "ld: object header found, record count: " << cnt << "\n"; pef_container.Count = cnt; @@ -287,7 +299,7 @@ MPCC_MODULE(Linker64x0) command_header.Size = ae_records[ae_record_index].fSize; if (kVerbose) - kStdOut << "64ld: object record: " << ae_records[ae_record_index].fName << " was marked.\n"; + kStdOut << "ld: object record: " << ae_records[ae_record_index].fName << " was marked.\n"; pef_command_hdrs.emplace_back(command_header); } @@ -310,7 +322,7 @@ MPCC_MODULE(Linker64x0) continue; } - kStdOut << "64ld: not an object: " << i << std::endl; + kStdOut << "ld: not an object: " << i << std::endl; std::remove(kOutput.c_str()); // don't continue, it is a fatal error. @@ -323,7 +335,7 @@ MPCC_MODULE(Linker64x0) if (kVerbose) { - kStdOut << "64ld: pef: wrote container header.\n"; + kStdOut << "ld: pef: wrote container header.\n"; } output_fc.seekp(std::streamsize(pef_container.HdrSz)); @@ -342,7 +354,7 @@ MPCC_MODULE(Linker64x0) std::string::npos) { if (kVerbose) - kStdOut << "64ld: found undefined symbol: " << pef_command_hdr.Name << "\n"; + kStdOut << "ld: found undefined symbol: " << pef_command_hdr.Name << "\n"; if (auto it = std::find(not_found.begin(), not_found.end(), std::string(pef_command_hdr.Name)); it == not_found.end()) @@ -392,7 +404,7 @@ MPCC_MODULE(Linker64x0) not_found.erase(it); if (kVerbose) - kStdOut << "64ld: found symbol: " << pef_command_hdr.Name << "\n"; + kStdOut << "ld: found symbol: " << pef_command_hdr.Name << "\n"; break; } @@ -408,9 +420,9 @@ MPCC_MODULE(Linker64x0) if (!kStartFound && is_executable) { if (kVerbose) - kStdOut << "64ld: undefined symbol: __start, you may have forget to link against your runtime library.\n"; + kStdOut << "ld: undefined symbol: __start, you may have forget to link against your runtime library.\n"; - kStdOut << "64ld: undefined entrypoint " << kPefStart << " for executable " << kOutput << "\n"; + kStdOut << "ld: undefined entrypoint " << kPefStart << " for executable " << kOutput << "\n"; } // step 4: write some pef commands. @@ -471,7 +483,7 @@ MPCC_MODULE(Linker64x0) std::string(pef_command_hdrs[cmd_hdr].Name).find(kLdDynamicSym) == std::string::npos) { - // ignore :64ld: headers, they do not contain code. + // ignore :ld: headers, they do not contain code. continue; } @@ -496,10 +508,10 @@ MPCC_MODULE(Linker64x0) { if (kVerbose) { - kStdOut << "64ld: ignore :64ld: command header...\n"; + kStdOut << "ld: ignore :ld: command header...\n"; } - // ignore :64ld: headers, they do not contain code. + // ignore :ld: headers, they do not contain code. continue; } @@ -513,7 +525,7 @@ MPCC_MODULE(Linker64x0) } if (kVerbose) - kStdOut << "64ld: found duplicate symbol: " << pef_command_hdr.Name << "\n"; + kStdOut << "ld: found duplicate symbol: " << pef_command_hdr.Name << "\n"; kDuplicateSymbols = true; } @@ -524,7 +536,7 @@ MPCC_MODULE(Linker64x0) { for (auto &symbol : duplicate_symbols) { - kStdOut << "64ld: multiple symbols of " << symbol << ".\n"; + kStdOut << "ld: multiple symbols of " << symbol << ".\n"; } std::remove(kOutput.c_str()); @@ -539,7 +551,7 @@ MPCC_MODULE(Linker64x0) } if (kVerbose) - kStdOut << "64ld: wrote code for: " << kOutput << "\n"; + kStdOut << "ld: wrote code for: " << kOutput << "\n"; // step 3: check if we have those symbols @@ -558,7 +570,7 @@ MPCC_MODULE(Linker64x0) { for (auto &unreferenced_symbol : unreferenced_symbols) { - kStdOut << "64ld: undefined symbol " << unreferenced_symbol << "\n"; + kStdOut << "ld: undefined symbol " << unreferenced_symbol << "\n"; } } @@ -568,7 +580,7 @@ MPCC_MODULE(Linker64x0) !unreferenced_symbols.empty()) { if (kVerbose) - kStdOut << "64ld: code for: " << kOutput << ", is corrupt, removing file...\n"; + kStdOut << "ld: code for: " << kOutput << ", is corrupt, removing file...\n"; std::remove(kOutput.c_str()); return -CXXKIT_EXEC_ERROR; diff --git a/64x0-Drivers/makefile b/Drivers/makefile index 7ca0f5d..e631cd4 100644 --- a/64x0-Drivers/makefile +++ b/Drivers/makefile @@ -9,9 +9,10 @@ LINK_CC=g++ -std=c++20 LINK_INC=-I../ -I../CompilerKit -LINK_SRC=64ld.cc +LINK_SRC=ld.cc LINK_OUTPUT=bin/ld LINK_ALT_OUTPUT=bin/64ld +LINK_ALT_2_OUTPUT=bin/32ld PP_SRC=bpp.cc PP_OUTPUT=bin/bpp @@ -43,6 +44,7 @@ cxx: ld ld: $(LINK_CC) $(LINK_INC) $(LINK_SRC) -o $(LINK_OUTPUT) cp $(LINK_OUTPUT) $(LINK_ALT_OUTPUT) + cp $(LINK_OUTPUT) $(LINK_ALT_2_OUTPUT) .PHONY: help help: |
