diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-03 23:40:16 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-03 23:40:16 +0100 |
| commit | b03f3d83efcbc012c4153da14eaf158bb50031d2 (patch) | |
| tree | dc004f8d0ef866c77fff7aa4ec271363b5417f9d | |
| parent | 05c51485d56b14f7cd3c05afebd920157d7a0b8b (diff) | |
tools: incremental changes, support for a C compiler will soon be here.
alongside the 32x0.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | C++Kit/AsmKit/Arch/32k.hpp | 4 | ||||
| -rw-r--r-- | C++Kit/AsmKit/Arch/64k.hpp | 4 | ||||
| -rw-r--r-- | C++Kit/AsmKit/AsmKit.cc (renamed from C++Kit/AsmKit/AsmKit.cpp) | 0 | ||||
| -rw-r--r-- | C++Kit/AsmKit/AsmKit.hpp | 8 | ||||
| -rw-r--r-- | C++Kit/StdKit/ErrorID.hpp | 2 | ||||
| -rw-r--r-- | C++Kit/StdKit/ErrorOr.hpp | 4 | ||||
| -rw-r--r-- | C++Kit/StdKit/Ref.hpp | 2 | ||||
| -rw-r--r-- | C++Kit/StdKit/String.cc (renamed from C++Kit/StdKit/String.cpp) | 4 | ||||
| -rw-r--r-- | C++Kit/StdKit/String.hpp | 4 | ||||
| -rw-r--r-- | CompilerDriver/.gitignore | 1 | ||||
| -rw-r--r-- | CompilerDriver/cc.cc (renamed from CompilerDriver/cc.cxx) | 5 | ||||
| -rw-r--r-- | CompilerDriver/ccplus.cc (renamed from CompilerDriver/ccplus.cxx) | 6 | ||||
| -rw-r--r-- | CompilerDriver/cpp.cc (renamed from CompilerDriver/cpp.cxx) | 0 | ||||
| -rw-r--r-- | CompilerDriver/ld.cc (renamed from CompilerDriver/ld.cxx) | 41 | ||||
| -rw-r--r-- | CompilerDriver/makefile | 16 | ||||
| -rw-r--r-- | CompilerDriver/masm.cc (renamed from CompilerDriver/masm.cxx) | 17 |
16 files changed, 68 insertions, 50 deletions
diff --git a/C++Kit/AsmKit/Arch/32k.hpp b/C++Kit/AsmKit/Arch/32k.hpp index cb948b5..2e73efa 100644 --- a/C++Kit/AsmKit/Arch/32k.hpp +++ b/C++Kit/AsmKit/Arch/32k.hpp @@ -28,7 +28,7 @@ #define kAsmHWord 1 #define kAsmWord 2 -struct NCOpcode +struct CpuCode32x0 { const char fName[16]; char fOpcode; @@ -41,7 +41,7 @@ struct NCOpcode #define kAsmHWordStr ".h" #define kAsmByteStr ".b" -inline std::vector<NCOpcode> kOpcodesStd = { +inline std::vector<CpuCode32x0> kOpcodes32x0 = { kAsmOpcodeDecl("nop", 0b0100011, 0b0000000, kAsmImmediate) // nothing to do. kAsmOpcodeDecl("jmp", 0b1110011, 0b0000011, kAsmJump) // jump to branch kAsmOpcodeDecl("move", 0b0100011, 0b101, kAsmImmediate) diff --git a/C++Kit/AsmKit/Arch/64k.hpp b/C++Kit/AsmKit/Arch/64k.hpp index c4ce648..00ab973 100644 --- a/C++Kit/AsmKit/Arch/64k.hpp +++ b/C++Kit/AsmKit/Arch/64k.hpp @@ -25,7 +25,7 @@ #define kAsmSyscall 0x02 #define kAsmJump 0x03 -struct NCOpcode +struct CpuCode64x0 { const char fName[16]; char fOpcode; @@ -33,7 +33,7 @@ struct NCOpcode char fFunct7; }; -inline std::vector<NCOpcode> kOpcodesStd = { +inline std::vector<CpuCode64x0> kOpcodes64x0 = { kAsmOpcodeDecl("np", 0b0100011, 0b0000000, kAsmImmediate) // mv r0, r0 kAsmOpcodeDecl("jb", 0b1110011, 0b0000011, kAsmJump) // jump to branch kAsmOpcodeDecl("jlr", 0b1110011, 0b0000111, kAsmJump) // jump and link return register diff --git a/C++Kit/AsmKit/AsmKit.cpp b/C++Kit/AsmKit/AsmKit.cc index d44874d..d44874d 100644 --- a/C++Kit/AsmKit/AsmKit.cpp +++ b/C++Kit/AsmKit/AsmKit.cc diff --git a/C++Kit/AsmKit/AsmKit.hpp b/C++Kit/AsmKit/AsmKit.hpp index 8674922..68ea4c0 100644 --- a/C++Kit/AsmKit/AsmKit.hpp +++ b/C++Kit/AsmKit/AsmKit.hpp @@ -27,11 +27,12 @@ namespace CxxKit CXXKIT_COPY_DEFAULT(AssemblyMountpoint); //@ brief compile to object file. - // Example C++ -> Assembly -> AE object. + // Example C++ -> MASM -> AE object. virtual Int32 CompileToFormat(StringView& src, Int32 arch) = 0; }; + /// @brief Simple assembly factory class AssemblyFactory final { public: @@ -44,9 +45,8 @@ namespace CxxKit enum { kArchAMD64, - kArchARM64, - kArchPowerPC, - kArchARC, + kArch32x0, + kArch64x0, kArchRISCV, kArchUnknown, }; diff --git a/C++Kit/StdKit/ErrorID.hpp b/C++Kit/StdKit/ErrorID.hpp index 4935a8e..ddbf83b 100644 --- a/C++Kit/StdKit/ErrorID.hpp +++ b/C++Kit/StdKit/ErrorID.hpp @@ -1,7 +1,7 @@ /* * ======================================================== * - * NewOS + * CxxKit * Copyright Western Company, all rights reserved. * * ======================================================== diff --git a/C++Kit/StdKit/ErrorOr.hpp b/C++Kit/StdKit/ErrorOr.hpp index 05e74e4..4b5d1d2 100644 --- a/C++Kit/StdKit/ErrorOr.hpp +++ b/C++Kit/StdKit/ErrorOr.hpp @@ -1,7 +1,7 @@ /* * ======================================================== * - * NewOS + * CxxKit * Copyright Western Company, all rights reserved. * * ======================================================== @@ -55,4 +55,4 @@ class ErrorOr final using ErrorOrAny = ErrorOr<voidPtr>; -} // namespace NewOS +} // namespace CxxKit diff --git a/C++Kit/StdKit/Ref.hpp b/C++Kit/StdKit/Ref.hpp index 2a32a60..4f4e822 100644 --- a/C++Kit/StdKit/Ref.hpp +++ b/C++Kit/StdKit/Ref.hpp @@ -2,7 +2,7 @@ /* * ======================================================== * - * NewOS + * CxxKit * Copyright Western Company, all rights reserved. * * ======================================================== diff --git a/C++Kit/StdKit/String.cpp b/C++Kit/StdKit/String.cc index b4199a8..be07c26 100644 --- a/C++Kit/StdKit/String.cpp +++ b/C++Kit/StdKit/String.cc @@ -1,7 +1,7 @@ /* * ======================================================== * - * hCore + * CxxKit * Copyright Western Company, all rights reserved. * * ======================================================== @@ -227,4 +227,4 @@ namespace CxxKit return *this; } -} // namespace hCore +} // namespace CxxKit diff --git a/C++Kit/StdKit/String.hpp b/C++Kit/StdKit/String.hpp index a3b1f5f..4addea8 100644 --- a/C++Kit/StdKit/String.hpp +++ b/C++Kit/StdKit/String.hpp @@ -1,7 +1,7 @@ /* * ======================================================== * - * NewOS + * CxxKit * Copyright Western Company, all rights reserved. * * ======================================================== @@ -69,4 +69,4 @@ namespace CxxKit static bool Equals(const char *lhs, const char *rhs); }; -} // namespace NewOS +} // namespace CxxKit diff --git a/CompilerDriver/.gitignore b/CompilerDriver/.gitignore index ce5ef93..23a095f 100644 --- a/CompilerDriver/.gitignore +++ b/CompilerDriver/.gitignore @@ -1,4 +1,5 @@ bin/ld +bin/mld bin/cpp bin/cc bin/masm diff --git a/CompilerDriver/cc.cxx b/CompilerDriver/cc.cc index 0a8647d..899734b 100644 --- a/CompilerDriver/cc.cxx +++ b/CompilerDriver/cc.cc @@ -1755,12 +1755,13 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// #define kPrintF printf -#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.13, (c) Western Company") +#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.14, (c) Western Company") static void cc_print_help() { kSplashCxx(); - kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile to a specific assembler syntax. (masm)"); + + kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile with a specific syntax. (64x0, 32x0)"); kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> dolvik)."); } diff --git a/CompilerDriver/ccplus.cxx b/CompilerDriver/ccplus.cc index d9ef3fe..f9f94e4 100644 --- a/CompilerDriver/ccplus.cxx +++ b/CompilerDriver/ccplus.cc @@ -464,18 +464,18 @@ public: ///////////////////////////////////////////////////////////////////////////////////////// #define kPrintF printf -#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.13, (c) Western Company.") +#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.14, (c) Western Company.") static void cxx_print_help() { kSplashCxx(); - kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile to a specific assembler syntax. (masm)"); + kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile with a specific syntax. (64x0, 32x0)"); kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> vanhalen++)."); } ///////////////////////////////////////////////////////////////////////////////////////// -#define kExt ".c" +#define kExt ".cc" int main(int argc, char** argv) { diff --git a/CompilerDriver/cpp.cxx b/CompilerDriver/cpp.cc index 6986e27..6986e27 100644 --- a/CompilerDriver/cpp.cxx +++ b/CompilerDriver/cpp.cc diff --git a/CompilerDriver/ld.cxx b/CompilerDriver/ld.cc index d316fe3..d9e1ffe 100644 --- a/CompilerDriver/ld.cxx +++ b/CompilerDriver/ld.cc @@ -28,9 +28,9 @@ #include <C++Kit/StdKit/AE.hpp> //! @brief standard PEF entry. -#define kPefStart "__start" +#define kPefStart "__start" -#define kToolVersion "ld v1.15, (c) Western Company" +#define kToolVersion "ld v1.17, (c) Western Company" #define StringCompare(dst, src) strcmp(dst, src) @@ -59,7 +59,6 @@ std::ofstream& operator<<(std::ofstream& fp, CxxKit::PEFCommandHeader& container } static std::string kOutput = "a.out"; - static Int32 kAbi = kAbiMpUx; static Int32 kSubArch = kPefNoSubCpu; static Int32 kArch = kPefNoCpu; @@ -88,7 +87,7 @@ int main(int argc, char** argv) kStdOut << "-v: Print program version.\n"; kStdOut << "-verbose: Print program backtrace (verbose mode).\n"; kStdOut << "-shared: Output as a shared library.\n"; - kStdOut << "-m64000: Link for the X64000.\n"; + kStdOut << "-m64000: Link for the 64x0.\n"; kStdOut << "-fatbin: Output as FAT PEF.\n"; kStdOut << "-o: Select output filename.\n"; @@ -165,12 +164,15 @@ int main(int argc, char** argv) { if (!std::filesystem::exists(obj)) { + // if filesystem doesn't find file + // -> throw error. kStdOut << "ld: no such file: " << obj << std::endl; return CXXKIT_EXEC_ERROR; } } } + // PEF expects a valid architecture when outputing a binary. if (kArch == 0) { kStdOut << "ld: no target architecture set, can't continue." << std::endl; @@ -179,10 +181,11 @@ int main(int argc, char** argv) CxxKit::PEFContainer pef_container{}; + int32_t archs = kArch; + pef_container.Count = 0UL; pef_container.Kind = CxxKit::kPefKindExec; pef_container.SubCpu = kSubArch; - pef_container.Cpu = kArch; pef_container.Linker = kPefLinkerNumId; // Western Company Linker pef_container.Abi = kAbi; // Multi-Processor UX ABI pef_container.Magic[0] = kPefMagic[kFatBinaryEnable ? 2 : 0]; @@ -190,7 +193,7 @@ int main(int argc, char** argv) pef_container.Magic[2] = kPefMagic[kFatBinaryEnable ? 0 : 2]; pef_container.Version = kPefVersion; - // specify the start address. + // specify the start address, can be 0x10000 pef_container.Start = kPefDeaultOrg; pef_container.HdrSz = sizeof(CxxKit::PEFContainer); @@ -206,13 +209,6 @@ int main(int argc, char** argv) return -CXXKIT_FILE_NOT_FOUND; } - output_fc << pef_container; - - if (kVerbose) - { - kStdOut << "ld: PEF: wrote container header.\n"; - } - //! Read AE to convert as PEF. std::vector<CxxKit::PEFCommandHeader> pef_command_hdrs; @@ -233,12 +229,12 @@ int main(int argc, char** argv) if (ae_header.fArch != kArch) { if (kVerbose) - kStdOut << "ld: PEF: is a fat binary? : "; + kStdOut << "ld: pef: is a fat binary? : "; if (!kFatBinaryEnable) { if (kVerbose) - kStdOut << "NO\n"; + kStdOut << "no.\n"; kStdOut << "ld: error: object " << i << " is a different kind of architecture and output isn't treated as FAT binary." << std::endl; @@ -249,7 +245,7 @@ int main(int argc, char** argv) { if (kVerbose) { - kStdOut << "YES\n"; + kStdOut << "yes.\n"; } } } @@ -258,6 +254,8 @@ int main(int argc, char** argv) ae_header.fMagic[1] == kAEMag1 && ae_header.fSize == sizeof(CxxKit::AEHeader)) { + // append arch type to archs varaible. + archs |= ae_header.fArch; std::size_t cnt = ae_header.fCount; if (kVerbose) @@ -331,13 +329,22 @@ ld_mark_header: continue; } - kStdOut << "ld: 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. return -CXXKIT_EXEC_ERROR; } + pef_container.Cpu = archs; + + output_fc << pef_container; + + if (kVerbose) + { + kStdOut << "ld: pef: wrote container header.\n"; + } + output_fc.seekp(std::streamsize(pef_container.HdrSz)); std::vector<std::string> not_found; diff --git a/CompilerDriver/makefile b/CompilerDriver/makefile index f22ded6..e1060d5 100644 --- a/CompilerDriver/makefile +++ b/CompilerDriver/makefile @@ -9,30 +9,31 @@ LINK_CC=g++ -std=c++20 LINK_INC=-I../ -I../C++Kit -LINK_SRC=ld.cxx +LINK_SRC=ld.cc LINK_OUTPUT=bin/ld +LINK_ALT_OUTPUT=bin/mld -PP_SRC=cpp.cxx +PP_SRC=cpp.cc PP_OUTPUT=bin/cpp CC2_OUTPUT=bin/cppfront CC2_SRC=cc2/source/cppfront.cpp -CC_SRC=ccplus.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp +CC_SRC=ccplus.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc CC_OUTPUT=bin/ccplus -CC_SRC=cc.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp +CC_SRC=cc.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc CC_OUTPUT=bin/cc -CXX_SRC=ccplus.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp +CXX_SRC=ccplus.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc CXX_OUTPUT=bin/ccplus -MASM_SRC=masm.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp +MASM_SRC=masm.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc MASM_OUTPUT=bin/masm .PHONY: all all: cxx - @echo "[make] done build" + @echo "[make] done build." .PHONY: cxx cxx: ld @@ -45,6 +46,7 @@ cxx: ld .PHONY: ld ld: $(LINK_CC) $(LINK_INC) $(LINK_SRC) -o $(LINK_OUTPUT) + cp $(LINK_OUTPUT) $(LINK_ALT_OUTPUT) .PHONY: help help: diff --git a/CompilerDriver/masm.cxx b/CompilerDriver/masm.cc index e3be378..849e141 100644 --- a/CompilerDriver/masm.cxx +++ b/CompilerDriver/masm.cc @@ -36,7 +36,7 @@ #define kWhite "\e[0;97m" #define kYellow "\e[0;33m" -#define kStdOut (std::cout << kWhite) +#define kStdOut (std::cout << kWhite) static char kOutputArch = CxxKit::kPefArch64000; @@ -122,7 +122,7 @@ int main(int argc, char** argv) { if (strcmp(argv[i], "-v") == 0) { - kStdOut << "masm: The MP-UX Assembler.\nmasm: Copyright (c) 2023 Western Company.\n"; + kStdOut << "masm: The MP-UX Assembler.\nmasm: v1.10\nmasm: Copyright (c) 2023 Western Company.\n"; return 0; } @@ -135,9 +135,16 @@ int main(int argc, char** argv) return 0; } - else if (strcmp(argv[i], "-m64000") == 0) + else if (strcmp(argv[i], "-m64000") == 0 || + strcmp(argv[i], "-m64x0") == 0) { kOutputArch = CxxKit::kPefArch64000; + + if (kVerbose) + { + kStdOut << "masm: Select 64x0 as object output.\n"; + } + continue; } else if (strcmp(argv[i], "-verbose") == 0) @@ -555,7 +562,7 @@ static std::string masm_check_line(std::string& line, const std::string& file) std::vector<std::string> opcodes_list = { "jb", "psh", "stw", "ldw", "lda", "sta" }; - for (auto& opcodes : kOpcodesStd) + for (auto& opcodes : kOpcodes64x0) { if (line.find(opcodes.fName) != std::string::npos) { @@ -739,7 +746,7 @@ static bool masm_write_number(std::size_t pos, std::string& jump_label) static void masm_read_instruction(std::string& line, const std::string& file) { - for (auto& opcodes : kOpcodesStd) + for (auto& opcodes : kOpcodes64x0) { if (ParserKit::find_word(line, opcodes.fName)) { |
