From 0c44d8b4a0c738f122b9f3e5b8b719242bac5d50 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 21 Apr 2024 07:53:46 +0200 Subject: MHR-4: bug fixes and improved POWER and 64k assembler. - Error detection works on ppcasm again. - Fix compile_flags.txt for Zed. - Fix assembler messages inside 64asm and ppcasm. - Format source files according to clang-format. Signed-off-by: Amlal El Mahrouss --- Examples/Example64k.s | 3 +++ Examples/ExamplePowerPC.S | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 Examples/Example64k.s (limited to 'Examples') diff --git a/Examples/Example64k.s b/Examples/Example64k.s new file mode 100644 index 0000000..b56003a --- /dev/null +++ b/Examples/Example64k.s @@ -0,0 +1,3 @@ +mv r0, r3 +lda r19, 0x10000 +jlr diff --git a/Examples/ExamplePowerPC.S b/Examples/ExamplePowerPC.S index 82d2ca6..9615fe8 100644 --- a/Examples/ExamplePowerPC.S +++ b/Examples/ExamplePowerPC.S @@ -1,3 +1,5 @@ +; you you can never say! + b 0x1000 mflr r21 mtlr r21 -- cgit v1.2.3 From 209abc044af82897acce2ede571934af0d77b257 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 22 Apr 2024 10:34:40 +0200 Subject: MHR-4: Merging with unstable. Signed-off-by: Amlal El Mahrouss --- .gitignore | 1 + Examples/ExampleAMD64.asm | 7 ++++++- Headers/AsmKit/CPU/amd64.hpp | 3 +-- Headers/Defines.hpp | 2 ++ Sources/64asm.cc | 2 +- Sources/i64asm.cc | 15 ++++++++++++--- Sources/ppcasm.cc | 2 +- 7 files changed, 24 insertions(+), 8 deletions(-) (limited to 'Examples') diff --git a/.gitignore b/.gitignore index 48a4a74..ee93641 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ local.properties # NewOS/MP-UX executable *.exec +*.bin docs/ diff --git a/Examples/ExampleAMD64.asm b/Examples/ExampleAMD64.asm index 12f8f61..4f8625e 100644 --- a/Examples/ExampleAMD64.asm +++ b/Examples/ExampleAMD64.asm @@ -1,4 +1,9 @@ #org 0x7c00 -int 13 +nop +nop +nop +nop +nop + ret diff --git a/Headers/AsmKit/CPU/amd64.hpp b/Headers/AsmKit/CPU/amd64.hpp index ca3c7dd..42fbc26 100644 --- a/Headers/AsmKit/CPU/amd64.hpp +++ b/Headers/AsmKit/CPU/amd64.hpp @@ -43,7 +43,6 @@ inline std::vector kOpcodesAMD64 = { kAsmOpcodeDecl("ret", 0xC3) kAsmOpcodeDecl("sti", 0xfb) kAsmOpcodeDecl("cli", 0xfa) kAsmOpcodeDecl("hlt", 0xf4) kAsmOpcodeDecl("nop", 0x90) kAsmOpcodeDecl("mov", 0x48) - kAsmOpcodeDecl("call", 0xFF) kAsmOpcodeDecl("mv", 0x48) - kAsmOpcodeDecl("br", 0xE9)}; + kAsmOpcodeDecl("call", 0xFF)}; #define kAsmRegisterLimit 15 diff --git a/Headers/Defines.hpp b/Headers/Defines.hpp index 51b0dec..627e5b3 100644 --- a/Headers/Defines.hpp +++ b/Headers/Defines.hpp @@ -122,6 +122,8 @@ inline bool to_str(CharType *str, Int32 limit, Int32 base) noexcept { typedef char char_type; #define kObjectFileExt ".obj" +#define kBinaryFileExt ".bin" + #define kAsmFileExts \ { ".64x", ".32x", ".masm", ".s", ".S", ".asm" } diff --git a/Sources/64asm.cc b/Sources/64asm.cc index 0c3f9a7..566dfd8 100644 --- a/Sources/64asm.cc +++ b/Sources/64asm.cc @@ -144,7 +144,7 @@ MPCC_MODULE(NewOSAssembler64000) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); diff --git a/Sources/i64asm.cc b/Sources/i64asm.cc index d19c515..634c070 100644 --- a/Sources/i64asm.cc +++ b/Sources/i64asm.cc @@ -24,6 +24,7 @@ #define __ASM_NEED_AMD64__ 1 +#define kAssemblerPragmaSymStr "#" #define kAssemblerPragmaSym '#' #include @@ -192,7 +193,7 @@ MPCC_MODULE(NewOSAssemblerAMD64) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); @@ -520,8 +521,9 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string &line, std::string err_str; if (line.empty() || ParserKit::find_word(line, "import") || - ParserKit::find_word(line, "export") || ParserKit::find_word(line, "#") || - ParserKit::find_word(line, ";")) { + ParserKit::find_word(line, "export") || ParserKit::find_word(line, kAssemblerPragmaSymStr) || + ParserKit::find_word(line, ";") || + line[0] == kAssemblerPragmaSym) { if (line.find(';') != std::string::npos) { line.erase(line.find(';')); } else { @@ -577,6 +579,13 @@ std::string CompilerKit::EncoderAMD64::CheckLine(std::string &line, } } } + for (auto &opcodeAMD64 : kOpcodesAMD64) { + if (ParserKit::find_word(line, opcodeAMD64.fName)) { + return err_str; + } + } + + err_str += "\nUnrecognized instruction -> " + line; return err_str; } diff --git a/Sources/ppcasm.cc b/Sources/ppcasm.cc index 90e0429..f95020e 100644 --- a/Sources/ppcasm.cc +++ b/Sources/ppcasm.cc @@ -150,7 +150,7 @@ MPCC_MODULE(NewOSAssemblerPowerPC) { } } - object_output += kObjectFileExt; + object_output += kOutputAsBinary ? kBinaryFileExt : kObjectFileExt; std::ifstream file_ptr(argv[i]); std::ofstream file_ptr_out(object_output, std::ofstream::binary); -- cgit v1.2.3