summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>2024-03-16 16:08:46 +0100
committerAmlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>2024-03-16 16:09:38 +0100
commit7e784649762d895209ab66bf8a3c7de08da0e12c (patch)
treebf24f2d3a8cadebdced35e47d84603ab6bc40017
parent900a95d61d7d544c63f9ae06e5f6d4af1c820667 (diff)
HCR-24: See below.
- Bug fixes and new bug reports filed. - Update language standard for cc program. - linker specifiy HCOR for PEF AMD64 abi now. Signed-off-by: Amlal El Mahrouss <113760121+Amlal-ElMahrouss@users.noreply.github.com>
-rw-r--r--Private/Toolchain/bin/Source/hello_world.s13
-rw-r--r--Private/Toolchain/cc.cc9
-rw-r--r--Private/Toolchain/ccplus.cc16
-rw-r--r--Private/Toolchain/i64asm.cc21
-rw-r--r--Private/Toolchain/link.cc3
5 files changed, 30 insertions, 32 deletions
diff --git a/Private/Toolchain/bin/Source/hello_world.s b/Private/Toolchain/bin/Source/hello_world.s
index 7d010e8..f90edbc 100644
--- a/Private/Toolchain/bin/Source/hello_world.s
+++ b/Private/Toolchain/bin/Source/hello_world.s
@@ -1,8 +1,7 @@
-# Path: Source/hello_world.cxx
-# Language: AMD64 HCore Assembly (Generated from C++)
-# Build Date: 2024-3-15
+!bits 64
+!org 0x1000
-export .text _CZZ_MAHR_MANGLEint@main
-mov r9, 50
-mov rax, r8
-ret \ No newline at end of file
+export .text main
+mov rcx, rax
+mov rax, rcx
+retf \ No newline at end of file
diff --git a/Private/Toolchain/cc.cc b/Private/Toolchain/cc.cc
index b55405b..8d084a4 100644
--- a/Private/Toolchain/cc.cc
+++ b/Private/Toolchain/cc.cc
@@ -166,7 +166,7 @@ class CompilerBackendCLang final : public ParserKit::CompilerBackend {
std::string Check(const char *text, const char *file);
bool Compile(const std::string &text, const char *file) override;
- const char *Language() override { return "C 64x0, Generic MP/UX target."; }
+ const char *Language() override { return "64x0 C17, MP/UX target."; }
};
static CompilerBackendCLang *kCompilerBackend = nullptr;
@@ -1219,7 +1219,8 @@ class AssemblyMountpointCLang final : public CompilerKit::AssemblyMountpoint {
static void cc_print_help() {
kSplashCxx();
- kPrintF("%s\n", "No help available.");
+ kPrintF("%s\n", "--asm: Select assembler, example:\n--asm=64x0");
+ kPrintF("%s\n", "--compiler: Select backend, example:\n--compiler=mahrouss");
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1267,7 +1268,7 @@ MPCC_MODULE(HCoreCompilerCLang64x0) {
return kOk;
}
- if (strcmp(argv[index], "--asm=masm") == 0) {
+ if (strcmp(argv[index], "--asm=64x0") == 0) {
delete kFactory.Unmount();
kFactory.Mount(new AssemblyMountpointCLang());
@@ -1276,7 +1277,7 @@ MPCC_MODULE(HCoreCompilerCLang64x0) {
continue;
}
- if (strcmp(argv[index], "--compiler=Amsterdam") == 0) {
+ if (strcmp(argv[index], "--compiler=mahrouss") == 0) {
if (!kCompilerBackend) kCompilerBackend = new CompilerBackendCLang();
continue;
diff --git a/Private/Toolchain/ccplus.cc b/Private/Toolchain/ccplus.cc
index 4d8f95f..b25b844 100644
--- a/Private/Toolchain/ccplus.cc
+++ b/Private/Toolchain/ccplus.cc
@@ -275,6 +275,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyMountpoint {
(*kState.fOutputAssembly)
<< "# Language: AMD64 HCore Assembly (Generated from C++)\n";
(*kState.fOutputAssembly) << "# Build Date: " << fmt << "\n\n";
+ (*kState.fOutputAssembly) << "!bits 64 " << "\n\n";
ParserKit::SyntaxLeafList syntax;
@@ -403,9 +404,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyMountpoint {
auto& front = scope.front();
- std::string reg = "r";
- reg += std::to_string(front.reg_cnt);
- ++front.reg_cnt;
+ std::string reg = "rcx";
front.vals.push_back(reg);
}
@@ -418,10 +417,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyMountpoint {
if (found_type) {
auto& front = scope.front();
- std::string reg = "r";
- reg += std::to_string(front.reg_cnt);
- ++front.reg_cnt;
-
+ std::string reg = "rcx";
front.vals.push_back(reg);
leaf.fUserValue = !is_pointer ? "mov %s, %s1\n" : "lea %s, %s1\n";
@@ -482,9 +478,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyMountpoint {
auto& front = scope.front();
- std::string reg = "r";
- reg += std::to_string(front.reg_cnt);
- ++front.reg_cnt;
+ std::string reg = "rcx";
leaf.fUserValue.replace(leaf.fUserValue.find("%s"), strlen("%s"),
reg);
@@ -519,7 +513,7 @@ class AssemblyMountpointClang final : public CompilerKit::AssemblyMountpoint {
ln[i] == '&' || ln[i] == '&' || ln[i] == '|' ||
ln[i] == ';') {
val.replace(val.find(val_reg), val_reg.size(),
- "r" + std::to_string(reg_cnt));
+ "rcx");
val_reg.clear();
++reg_cnt;
diff --git a/Private/Toolchain/i64asm.cc b/Private/Toolchain/i64asm.cc
index 04039fc..9c92dac 100644
--- a/Private/Toolchain/i64asm.cc
+++ b/Private/Toolchain/i64asm.cc
@@ -4,7 +4,14 @@
------------------------------------------- */
-/// bugs: 0
+/// bugs: 1
+/// mov rcx, rax
+/// mov rax, rcx
+/// prompts the same output.
+
+
+/// feature requests: 1
+/// add support for r8, r15 registers, also add support for ret.
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1061,23 +1068,19 @@ bool CompilerKit::EncoderAMD64::WriteLine(std::string &line,
kBytes.push_back(byte);
} else if (currentRegList[1].fName.find("ax") !=
+ std::string::npos ||
+ currentRegList[1].fName.find("cx") !=
std::string::npos) {
auto byte = 0xc0;
- byte += currentRegList[0].fModRM;
-
- kBytes.push_back(byte);
- } else {
- auto byte = 0xf0;
- byte += currentRegList[0].fModRM;
+ byte += (currentRegList[1].fName.find("cx") != std::string::npos) ? currentRegList[1].fModRM : currentRegList[0].fModRM;
kBytes.push_back(byte);
}
-
} else if (bits == 16) {
kBytes.emplace_back(0x66);
kBytes.emplace_back(0x89);
- assert(false);
+ // TODO: 16 bit move operation.
} else {
detail::print_error(
"Invalid combination of operands and registers.", "i64asm");
diff --git a/Private/Toolchain/link.cc b/Private/Toolchain/link.cc
index 04cdfe6..58407cf 100644
--- a/Private/Toolchain/link.cc
+++ b/Private/Toolchain/link.cc
@@ -433,7 +433,7 @@ MPCC_MODULE(HCoreLinker) {
switch (kArch) {
case CompilerKit::kPefArchAMD64: {
- abi += "MSFT";
+ abi += "HCOR";
break;
}
case CompilerKit::kPefArch32000:
@@ -459,6 +459,7 @@ MPCC_MODULE(HCoreLinker) {
CompilerKit::PEFCommandHeader uuid_header{};
std::random_device rd;
+
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));