From ddaa28767b85743c6231a9a59a75c1bdc19f7d94 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 13 Jan 2024 09:03:13 +0100 Subject: Amend (revision I) CI: made it more portable. 64asm: add support for labels. abi: now we are in version two of PEF, each executable must think they start at '0' Signed-off-by: Amlal El Mahrouss --- CompilerKit/AsmKit/Arch/64k.hpp | 4 ++++ CompilerKit/AsmKit/AsmKit.hpp | 43 +++++++++++++++++++++++++++++++++++++++++ CompilerKit/StdKit/PEF.hpp | 9 ++++++--- 3 files changed, 53 insertions(+), 3 deletions(-) (limited to 'CompilerKit') diff --git a/CompilerKit/AsmKit/Arch/64k.hpp b/CompilerKit/AsmKit/Arch/64k.hpp index 2ef847d..b54161d 100644 --- a/CompilerKit/AsmKit/Arch/64k.hpp +++ b/CompilerKit/AsmKit/Arch/64k.hpp @@ -49,8 +49,12 @@ inline std::vector kOpcodes64x0 = { kAsmOpcodeDecl("ldw", 0b0001111, 0b100, kAsmImmediate) kAsmOpcodeDecl("lda", 0b0001111, 0b101, kAsmImmediate) kAsmOpcodeDecl("sta", 0b0001111, 0b001, kAsmImmediate) + // add/sub without carry flag kAsmOpcodeDecl("add", 0b0101011, 0b100, kAsmImmediate) kAsmOpcodeDecl("dec", 0b0101011, 0b101, kAsmImmediate) + // add/sub with carry flag + kAsmOpcodeDecl("addc", 0b0101011, 0b110, kAsmImmediate) + kAsmOpcodeDecl("decc", 0b0101011, 0b111, kAsmImmediate) kAsmOpcodeDecl("int", 0b1110011, 0b00, kAsmSyscall) kAsmOpcodeDecl("syscall", 0b1110011, 0b00, kAsmSyscall) kAsmOpcodeDecl("pha", 0b1110011, 0b00, kAsmNoArgs) diff --git a/CompilerKit/AsmKit/AsmKit.hpp b/CompilerKit/AsmKit/AsmKit.hpp index e1f9de9..046a621 100644 --- a/CompilerKit/AsmKit/AsmKit.hpp +++ b/CompilerKit/AsmKit/AsmKit.hpp @@ -60,4 +60,47 @@ namespace CompilerKit AssemblyMountpoint* fMounted{ nullptr }; }; + + class PlatformAssembler + { + public: + explicit PlatformAssembler() = default; + ~PlatformAssembler() = default; + + virtual std::string CheckLine(std::string &line, const std::string &file) = 0; + virtual bool WriteLine(std::string &line, const std::string &file) = 0; + virtual bool WriteNumber(const std::size_t &pos, std::string &from_what) = 0; + + }; + +#ifdef __ASM_NEED_64x0__ + + class PlatformAssembler64x0 final : public PlatformAssembler + { + public: + explicit PlatformAssembler64x0() = default; + ~PlatformAssembler64x0() = default; + + virtual std::string CheckLine(std::string &line, const std::string &file) override; + virtual bool WriteLine(std::string &line, const std::string &file) override; + virtual bool WriteNumber(const std::size_t& pos, std::string& from_what) override; + + }; + +#endif // __ASM_NEED_64x0__ + + union NumberCast final + { + explicit NumberCast(UInt64 raw) : raw(raw) {} + ~NumberCast() { raw = 0; } + + char number[8]; + UInt64 raw; + }; } + +#ifdef __MODULE_NEED__ +# define MODULE(name) int name(int argc, char** argv) +#else +# define MODULE(name) int main(int argc, char** argv) +#endif /* ifdef __MODULE_NEED__ */ \ No newline at end of file diff --git a/CompilerKit/StdKit/PEF.hpp b/CompilerKit/StdKit/PEF.hpp index 924593f..69ed99f 100644 --- a/CompilerKit/StdKit/PEF.hpp +++ b/CompilerKit/StdKit/PEF.hpp @@ -11,15 +11,18 @@ #include +// @file PEF.hpp +// @brief Preferred Executable Format + #define kPefMagic "PEF" #define kPefMagicFat "FEP" #define kPefMagicLen 3 -#define kPefVersion 1 +#define kPefVersion 2 #define kPefNameLen 64 -// Protable Executable Format, a format designed for any computer. +#define kPefBaseOrigin 0 namespace CompilerKit { @@ -51,7 +54,7 @@ namespace CompilerKit UInt32 Abi; UInt32 Cpu; UInt32 SubCpu; /* Cpu specific information */ - UIntPtr Start; + UIntPtr Start; /* Origin of code */ SizeType HdrSz; /* Size of header */ SizeType Count; /* container header count */ } __attribute__((packed)) PEFContainer; -- cgit v1.2.3