From 9a2556dbc309c6ffe4e945dcd8685ab6092cc903 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 20 Aug 2024 21:43:27 +0200 Subject: + big refactors, now using the 'NDK' name. Signed-off-by: Amlal El Mahrouss --- dev/crtdll/__mpcc_alloca.hxx | 15 - dev/crtdll/__mpcc_defines.hxx | 83 -- dev/crtdll/__mpcc_exception.hxx | 27 - dev/crtdll/__mpcc_hint.hxx | 20 - dev/crtdll/__mpcc_malloc.hxx | 30 - dev/crtdll/__mpcc_power.inc | 35 - dev/crtdll/__ndk_alloca.hxx | 15 + dev/crtdll/__ndk_defines.hxx | 83 ++ dev/crtdll/__ndk_exception.hxx | 27 + dev/crtdll/__ndk_hint.hxx | 20 + dev/crtdll/__ndk_malloc.hxx | 30 + dev/crtdll/__ndk_power.inc | 35 + dev/ndkdll/Asm/Asm.hxx | 217 +++ dev/ndkdll/Asm/CPU/32x0.hxx | 95 ++ dev/ndkdll/Asm/CPU/64x0.hxx | 108 ++ dev/ndkdll/Asm/CPU/amd64.hxx | 57 + dev/ndkdll/Asm/CPU/arm64.hxx | 26 + dev/ndkdll/Asm/CPU/ppc.hxx | 1929 +++++++++++++++++++++++++ dev/ndkdll/AsmKit/AsmKit.hxx | 217 --- dev/ndkdll/AsmKit/CPU/32x0.hxx | 95 -- dev/ndkdll/AsmKit/CPU/64x0.hxx | 108 -- dev/ndkdll/AsmKit/CPU/amd64.hxx | 57 - dev/ndkdll/AsmKit/CPU/arm64.hxx | 26 - dev/ndkdll/AsmKit/CPU/ppc.hxx | 1929 ------------------------- dev/ndkdll/Defines.hxx | 14 +- dev/ndkdll/Macros.hxx | 14 +- dev/ndkdll/NFC/AE.hxx | 2 +- dev/ndkdll/NFC/ErrorID.hxx | 16 +- dev/ndkdll/NFC/String.hxx | 2 +- dev/ndkdll/Parser.hxx | 4 +- dev/ndkdll/Private/Imaging/TPM.hxx | 17 - dev/ndkdll/Sources/Assembler32x0.cxx | 2 +- dev/ndkdll/Sources/Assembler64x0.cxx | 2 +- dev/ndkdll/Sources/AssemblerAMD64.cxx | 2 +- dev/ndkdll/Sources/AssemblerPower.cxx | 4 +- dev/ndkdll/Sources/AssemblyFactory.cxx | 6 +- dev/ndkdll/Sources/BasicPreProcessor.cxx | 4 +- dev/ndkdll/Sources/CCompiler64x0.cxx | 8 +- dev/ndkdll/Sources/CCompilerPower64.cxx | 10 +- dev/ndkdll/Sources/CPlusPlusCompilerAMD64.cxx | 16 +- dev/ndkdll/Sources/Detail/asmutils.hxx | 2 +- dev/ndkdll/Sources/Detail/compilerutils.hxx | 2 +- dev/ndkdll/Sources/Linker.cxx | 22 +- 43 files changed, 2708 insertions(+), 2725 deletions(-) delete mode 100644 dev/crtdll/__mpcc_alloca.hxx delete mode 100644 dev/crtdll/__mpcc_defines.hxx delete mode 100644 dev/crtdll/__mpcc_exception.hxx delete mode 100644 dev/crtdll/__mpcc_hint.hxx delete mode 100644 dev/crtdll/__mpcc_malloc.hxx delete mode 100644 dev/crtdll/__mpcc_power.inc create mode 100644 dev/crtdll/__ndk_alloca.hxx create mode 100644 dev/crtdll/__ndk_defines.hxx create mode 100644 dev/crtdll/__ndk_exception.hxx create mode 100644 dev/crtdll/__ndk_hint.hxx create mode 100644 dev/crtdll/__ndk_malloc.hxx create mode 100644 dev/crtdll/__ndk_power.inc create mode 100644 dev/ndkdll/Asm/Asm.hxx create mode 100644 dev/ndkdll/Asm/CPU/32x0.hxx create mode 100644 dev/ndkdll/Asm/CPU/64x0.hxx create mode 100644 dev/ndkdll/Asm/CPU/amd64.hxx create mode 100644 dev/ndkdll/Asm/CPU/arm64.hxx create mode 100644 dev/ndkdll/Asm/CPU/ppc.hxx delete mode 100644 dev/ndkdll/AsmKit/AsmKit.hxx delete mode 100644 dev/ndkdll/AsmKit/CPU/32x0.hxx delete mode 100644 dev/ndkdll/AsmKit/CPU/64x0.hxx delete mode 100644 dev/ndkdll/AsmKit/CPU/amd64.hxx delete mode 100644 dev/ndkdll/AsmKit/CPU/arm64.hxx delete mode 100644 dev/ndkdll/AsmKit/CPU/ppc.hxx delete mode 100644 dev/ndkdll/Private/Imaging/TPM.hxx (limited to 'dev') diff --git a/dev/crtdll/__mpcc_alloca.hxx b/dev/crtdll/__mpcc_alloca.hxx deleted file mode 100644 index 9871c60..0000000 --- a/dev/crtdll/__mpcc_alloca.hxx +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -typedef void* ptr_type; -typedef __SIZE_TYPE__ size_type; - -inline ptr_type __mpcc_alloca_gcc(size_type sz) -{ - return __builtin_alloca(sz); -} diff --git a/dev/crtdll/__mpcc_defines.hxx b/dev/crtdll/__mpcc_defines.hxx deleted file mode 100644 index 19ed8a4..0000000 --- a/dev/crtdll/__mpcc_defines.hxx +++ /dev/null @@ -1,83 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#ifndef __MPCC_DEF__ -#define __MPCC_DEF__ - -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ - -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; -typedef void* voidptr_t; -typedef void* any_t; -typedef char* caddr_t; - -#ifndef NULL -#define NULL ((voidptr_t)0) -#endif // !null - -#ifdef __GNUC__ -#include -#define __mpcc_alloca(sz) __mpcc_alloca_gcc(sz) -#define __packed__ __attribute__((packed)) -#elif defined(__MPCC__) -#define __packed__ __mpcc_packed__ -#define __alloca(sz) __mpcc_alloca(sz) -#endif - -#define __deref(ptr) (*(ptr)) - -#ifdef __cplusplus -#define __init_decl() \ - extern "C" \ - { - - -#define __fini_decl() \ - }; \ - - -#else -#define __init_decl() -#define __fini_decl() -#endif - -typedef long long off_t; -typedef unsigned long long uoff_t; - -typedef union float_cast { - struct - { - unsigned int mantissa : 23; - unsigned int exponent : 8; - unsigned int sign : 1; - }; - - float f; -} __packed__ float_cast_t; - -typedef union double_cast { - struct - { - unsigned long long int mantissa : 52; - unsigned int exponent : 11; - unsigned int sign : 1; - }; - - double f; -} __packed__ double_cast_t; - -#endif // ifndef __GNUC__ - -#endif /* __MPCC_DEF__ */ diff --git a/dev/crtdll/__mpcc_exception.hxx b/dev/crtdll/__mpcc_exception.hxx deleted file mode 100644 index dac42ad..0000000 --- a/dev/crtdll/__mpcc_exception.hxx +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -/// This file is an implementation of __throw* family of functions. - -#include -#include -#include - -namespace std -{ - inline void __throw_general(void) - { - throw std::runtime_error("NDK C++ Runtime error."); - } - - inline void __throw_domain_error(const char* error) - { - std::cout << "NDK C++: Domain error: " << error << "\r"; - __throw_general(); - } -} // namespace std diff --git a/dev/crtdll/__mpcc_hint.hxx b/dev/crtdll/__mpcc_hint.hxx deleted file mode 100644 index 02dbc94..0000000 --- a/dev/crtdll/__mpcc_hint.hxx +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#pragma compiler(hint_manifest) - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/dev/crtdll/__mpcc_malloc.hxx b/dev/crtdll/__mpcc_malloc.hxx deleted file mode 100644 index eeaa67b..0000000 --- a/dev/crtdll/__mpcc_malloc.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include - -namespace stdx -{ - /// @brief allocate a new class. - /// @tparam KindClass the class type to allocate. - template - inline void* allocate(Args&&... args) - { - return new KindClass(std::forward(args)...); - } - - /// @brief free a class. - /// @tparam KindClass the class type to allocate. - template - inline void release(KindClass ptr) - { - if (!ptr) - return; - delete ptr; - } -} // namespace stdx diff --git a/dev/crtdll/__mpcc_power.inc b/dev/crtdll/__mpcc_power.inc deleted file mode 100644 index 90b1364..0000000 --- a/dev/crtdll/__mpcc_power.inc +++ /dev/null @@ -1,35 +0,0 @@ -# Path: SDK/__mpcc_power.inc -# Language: NDK POWER Assembly support for GNU. -# Build Date: 2024-6-4 - -%ifdef __CODETOOLS__ - -%def lda li -%def sta stw -%def ldw li - -%def r0 0 -%def r1 1 -%def r2 2 -%def r3 3 -%def r4 4 -%def r5 5 -%def r6 6 -%def r7 7 -%def r8 8 -%def r9 9 -%def r10 10 -%def r11 11 -%def r12 12 -%def r13 13 -%def r14 14 -%def r15 15 -%def r16 16 -%def r17 17 -%def r18 18 -%def r19 19 -%def r20 20 - -%endif - -%def nop mr 0, 0 diff --git a/dev/crtdll/__ndk_alloca.hxx b/dev/crtdll/__ndk_alloca.hxx new file mode 100644 index 0000000..48732a0 --- /dev/null +++ b/dev/crtdll/__ndk_alloca.hxx @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +inline ptr_type __ndk_alloca_gcc(size_type sz) +{ + return __builtin_alloca(sz); +} diff --git a/dev/crtdll/__ndk_defines.hxx b/dev/crtdll/__ndk_defines.hxx new file mode 100644 index 0000000..4af1fba --- /dev/null +++ b/dev/crtdll/__ndk_defines.hxx @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#ifndef __NDK_DEF__ +#define __NDK_DEF__ + +#ifndef __GNUC__ + +typedef __SIZE_TYPE__ size_t; + +#ifdef __LP64__ +typedef long int ssize_t; +#else +typedef int ssize_t; +#endif // __LP64__ + +typedef size_t ptrdiff_t; +typedef size_t uintptr_t; +typedef void* voidptr_t; +typedef void* any_t; +typedef char* caddr_t; + +#ifndef NULL +#define NULL ((voidptr_t)0) +#endif // !null + +#ifdef __GNUC__ +#include +#define __ndk_alloca(sz) __ndk_alloca_gcc(sz) +#define __packed__ __attribute__((packed)) +#elif defined(__NDK__) +#define __packed__ __ndk_packed__ +#define __alloca(sz) __ndk_alloca(sz) +#endif + +#define __deref(ptr) (*(ptr)) + +#ifdef __cplusplus +#define __init_decl() \ + extern "C" \ + { + + +#define __fini_decl() \ + }; \ + + +#else +#define __init_decl() +#define __fini_decl() +#endif + +typedef long long off_t; +typedef unsigned long long uoff_t; + +typedef union float_cast { + struct + { + unsigned int mantissa : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + }; + + float f; +} __packed__ float_cast_t; + +typedef union double_cast { + struct + { + unsigned long long int mantissa : 52; + unsigned int exponent : 11; + unsigned int sign : 1; + }; + + double f; +} __packed__ double_cast_t; + +#endif // ifndef __GNUC__ + +#endif /* __NDK_DEF__ */ diff --git a/dev/crtdll/__ndk_exception.hxx b/dev/crtdll/__ndk_exception.hxx new file mode 100644 index 0000000..dac42ad --- /dev/null +++ b/dev/crtdll/__ndk_exception.hxx @@ -0,0 +1,27 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +/// This file is an implementation of __throw* family of functions. + +#include +#include +#include + +namespace std +{ + inline void __throw_general(void) + { + throw std::runtime_error("NDK C++ Runtime error."); + } + + inline void __throw_domain_error(const char* error) + { + std::cout << "NDK C++: Domain error: " << error << "\r"; + __throw_general(); + } +} // namespace std diff --git a/dev/crtdll/__ndk_hint.hxx b/dev/crtdll/__ndk_hint.hxx new file mode 100644 index 0000000..02dbc94 --- /dev/null +++ b/dev/crtdll/__ndk_hint.hxx @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#pragma compiler(hint_manifest) + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/dev/crtdll/__ndk_malloc.hxx b/dev/crtdll/__ndk_malloc.hxx new file mode 100644 index 0000000..eeaa67b --- /dev/null +++ b/dev/crtdll/__ndk_malloc.hxx @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include + +namespace stdx +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template + inline void* allocate(Args&&... args) + { + return new KindClass(std::forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template + inline void release(KindClass ptr) + { + if (!ptr) + return; + delete ptr; + } +} // namespace stdx diff --git a/dev/crtdll/__ndk_power.inc b/dev/crtdll/__ndk_power.inc new file mode 100644 index 0000000..cada02e --- /dev/null +++ b/dev/crtdll/__ndk_power.inc @@ -0,0 +1,35 @@ +# Path: SDK/__ndk_power.inc +# Language: NDK POWER Assembly support for GNU. +# Build Date: 2024-6-4 + +%ifdef __CODETOOLS__ + +%def lda li +%def sta stw +%def ldw li + +%def r0 0 +%def r1 1 +%def r2 2 +%def r3 3 +%def r4 4 +%def r5 5 +%def r6 6 +%def r7 7 +%def r8 8 +%def r9 9 +%def r10 10 +%def r11 11 +%def r12 12 +%def r13 13 +%def r14 14 +%def r15 15 +%def r16 16 +%def r17 17 +%def r18 18 +%def r19 19 +%def r20 20 + +%endif + +%def nop mr 0, 0 diff --git a/dev/ndkdll/Asm/Asm.hxx b/dev/ndkdll/Asm/Asm.hxx new file mode 100644 index 0000000..fb90143 --- /dev/null +++ b/dev/ndkdll/Asm/Asm.hxx @@ -0,0 +1,217 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +namespace NDK +{ + // + // @brief Frontend to Assembly mountpoint. + // + class AssemblyInterface + { + public: + explicit AssemblyInterface() = default; + virtual ~AssemblyInterface() = default; + + NDK_COPY_DEFAULT(AssemblyInterface); + + //@ brief compile to object file. + // Example C++ -> MASM -> AE object. + virtual Int32 CompileToFormat(std::string& src, Int32 arch) = 0; + }; + + /// @brief Simple assembly factory + class AssemblyFactory final + { + public: + explicit AssemblyFactory() = default; + ~AssemblyFactory() = default; + + NDK_COPY_DEFAULT(AssemblyFactory); + + public: + enum + { + kArchAMD64, + kArch32x0, + kArch64x0, + kArchRISCV, + kArchPowerPC, + kArchUnknown, + }; + + Int32 Compile(std::string& sourceFile, const Int32& arch) noexcept; + + void Mount(AssemblyInterface* mountPtr) noexcept; + AssemblyInterface* Unmount() noexcept; + + private: + AssemblyInterface* fMounted{nullptr}; + }; + + union NumberCastBase { + NumberCastBase() = default; + ~NumberCastBase() = default; + }; + + union NumberCast64 final { + NumberCast64() = default; + explicit NumberCast64(UInt64 raw) + : raw(raw) + { + } + ~NumberCast64() + { + raw = 0; + } + + CharType number[8]; + UInt64 raw; + }; + + union NumberCast32 final { + NumberCast32() = default; + explicit NumberCast32(UInt32 raw) + : raw(raw) + { + } + ~NumberCast32() + { + raw = 0; + } + + CharType number[4]; + UInt32 raw; + }; + + union NumberCast16 final { + NumberCast16() = default; + explicit NumberCast16(UInt16 raw) + : raw(raw) + { + } + ~NumberCast16() + { + raw = 0; + } + + CharType number[2]; + UInt16 raw; + }; + + union NumberCast8 final { + NumberCast8() = default; + explicit NumberCast8(UInt8 raw) + : raw(raw) + { + } + ~NumberCast8() + { + raw = 0; + } + + CharType number; + UInt8 raw; + }; + + class EncoderInterface + { + public: + explicit EncoderInterface() = default; + virtual ~EncoderInterface() = default; + + NDK_COPY_DEFAULT(EncoderInterface); + + 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_AMD64__ + + class EncoderAMD64 final : public EncoderInterface + { + public: + explicit EncoderAMD64() = default; + ~EncoderAMD64() override = default; + + NDK_COPY_DEFAULT(EncoderAMD64); + + 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; + + virtual bool WriteNumber16(const std::size_t& pos, std::string& from_what); + virtual bool WriteNumber32(const std::size_t& pos, std::string& from_what); + virtual bool WriteNumber8(const std::size_t& pos, std::string& from_what); + }; + +#endif // __ASM_NEED_AMD64__ + +#ifdef __ASM_NEED_64x0__ + + class Encoder64x0 final : public EncoderInterface + { + public: + explicit Encoder64x0() = default; + ~Encoder64x0() override = default; + + NDK_COPY_DEFAULT(Encoder64x0); + + 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__ + +#ifdef __ASM_NEED_32x0__ + + class Encoder32x0 final : public EncoderInterface + { + public: + explicit Encoder32x0() = default; + ~Encoder32x0() override = default; + + NDK_COPY_DEFAULT(Encoder32x0); + + 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_32x0__ + +#ifdef __ASM_NEED_PPC__ + + class EncoderPowerPC final : public EncoderInterface + { + public: + explicit EncoderPowerPC() = default; + ~EncoderPowerPC() override = default; + + NDK_COPY_DEFAULT(EncoderPowerPC); + + 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_32x0__ +} // namespace NDK diff --git a/dev/ndkdll/Asm/CPU/32x0.hxx b/dev/ndkdll/Asm/CPU/32x0.hxx new file mode 100644 index 0000000..018dea9 --- /dev/null +++ b/dev/ndkdll/Asm/CPU/32x0.hxx @@ -0,0 +1,95 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include + +// @brief 32x0 support. +// @file CPU/32x0.hpp + +#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ + {.fName = __NAME, \ + .fOpcode = __OPCODE, \ + .fFunct3 = __FUNCT3, \ + .fFunct7 = __FUNCT7}, + +#define kAsmImmediate 0x01 +#define kAsmSyscall 0x02 +#define kAsmJump 0x03 +#define kAsmNoArgs 0x04 + +#define kAsmByte 0 +#define kAsmHWord 1 +#define kAsmWord 2 + +struct CpuCode32x0 +{ + const char fName[32]; + char fOpcode; + char fSize; + char fFunct3; + char fFunct7; +}; + +#define kAsmDWordStr ".dword" /* 64 bit */ +#define kAsmWordStr ".word" /* 32-bit */ +#define kAsmHWordStr ".half" /* 16-bit */ +#define kAsmByteStr ".byte" /* 8-bit */ + +inline std::vector kOpcodes32x0 = { + kAsmOpcodeDecl("nop", 0b0100011, 0b000, kAsmNoArgs) // nothing to do. + kAsmOpcodeDecl("br", 0b1110011, 0b001, kAsmJump) // jump to branch + kAsmOpcodeDecl("mr", 0b0100011, 0b101, kAsmImmediate) // move registers + kAsmOpcodeDecl("psh", 0b0111011, 0b000, kAsmImmediate) // push to sp + kAsmOpcodeDecl("pop", 0b0111011, 0b001, kAsmImmediate) // pop from sp. + kAsmOpcodeDecl("cls", 0b0111011, 0b010, + kAsmImmediate) // setup stack and call, store address to CR. + kAsmOpcodeDecl("rts", 0b0111011, 0b110, + kAsmImmediate) // pull stack and return form CR. + kAsmOpcodeDecl("int", 0b0111111, 0b000, kAsmSyscall) // raise interrupt +}; + +// \brief 64x0 register prefix +// example: r32, r0 +// r32 -> sp +// r0 -> hw zero + +#define kAsmRegisterPrefix "r" +#define kAsmRegisterLimit 16 +#define kAsmPcRegister 17 +#define kAsmCrRegister 18 +#define kAsmSpRegister 5 + +/* return address register */ +#define kAsmRetRegister 19 + +///////////////////////////////////////////////////////////////////////////// + +// SYSTEM CALL ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | OFF | + +// IMMEDIATE ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | +// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | REG | +// | OPCODE | FUNCT3 | FUNCT7 | REG | REG | OFF | + +// REG TO REG ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | REG | REG2 | + +//////////////////////////////// + +// LOAD/CALL INTERRUPTS + +// SET A HANDLER IN ADDRESS: TODO: find one +// DISABLE INTERRUPTS +// PROCESS INTERRUPT +// ENABLE INTERRUPTS + +//////////////////////////////// diff --git a/dev/ndkdll/Asm/CPU/64x0.hxx b/dev/ndkdll/Asm/CPU/64x0.hxx new file mode 100644 index 0000000..99a88b1 --- /dev/null +++ b/dev/ndkdll/Asm/CPU/64x0.hxx @@ -0,0 +1,108 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include +#include + +// @brief 64x0 support. +// @file CPU/64x0.hpp + +#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ + {.fName = __NAME, \ + .fOpcode = __OPCODE, \ + .fFunct3 = __FUNCT3, \ + .fFunct7 = __FUNCT7}, + +#define kAsmImmediate 0x01 +#define kAsmRegToReg 0x02 +#define kAsmSyscall 0x03 +#define kAsmJump 0x04 +#define kAsmNoArgs 0x00 + +typedef char e64k_character_t; +typedef uint8_t e64k_num_t; + +struct CpuOpcode64x0 +{ + const e64k_character_t fName[32]; + e64k_num_t fOpcode; + e64k_num_t fFunct3; + e64k_num_t fFunct7; +}; + +inline std::vector kOpcodes64x0 = { + kAsmOpcodeDecl("nop", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. + kAsmOpcodeDecl("np", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. + kAsmOpcodeDecl("jlr", 0b1110011, 0b0000111, + kAsmJump) // jump to linked return register + kAsmOpcodeDecl("jrl", 0b1110011, 0b0001111, + kAsmJump) // jump from return register. + kAsmOpcodeDecl("mv", 0b0100011, 0b101, kAsmRegToReg) + kAsmOpcodeDecl("bg", 0b1100111, 0b111, kAsmRegToReg) + kAsmOpcodeDecl("bl", 0b1100111, 0b011, kAsmRegToReg) + kAsmOpcodeDecl("beq", 0b1100111, 0b000, kAsmRegToReg) + kAsmOpcodeDecl("bne", 0b1100111, 0b001, kAsmRegToReg) + kAsmOpcodeDecl("bge", 0b1100111, 0b101, kAsmRegToReg) + kAsmOpcodeDecl("ble", 0b1100111, 0b100, kAsmRegToReg) + kAsmOpcodeDecl("stw", 0b0001111, 0b100, kAsmImmediate) + 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("sub", 0b0101011, 0b101, kAsmImmediate) + // add/sub with carry flag + kAsmOpcodeDecl("addc", 0b0101011, 0b110, kAsmImmediate) + kAsmOpcodeDecl("decc", 0b0101011, 0b111, kAsmImmediate) + kAsmOpcodeDecl("int", 0b1110011, 0b00, kAsmSyscall) + kAsmOpcodeDecl("pha", 0b1110011, 0b00, kAsmNoArgs) + kAsmOpcodeDecl("pla", 0b1110011, 0b01, kAsmNoArgs)}; + +// \brief 64x0 register prefix +// example: r32, r0 +// r32 -> sp +// r0 -> hw zero + +#define kAsmFloatZeroRegister 0 +#define kAsmZeroRegister 0 + +#define kAsmRegisterPrefix "r" +#define kAsmRegisterLimit 30 +#define kAsmPcRegister 17 +#define kAsmCrRegister 18 +#define kAsmSpRegister 5 + +/* return address register */ +#define kAsmRetRegister 19 + +///////////////////////////////////////////////////////////////////////////// + +// SYSTEM CALL/JUMP ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | OFF | + +// IMMEDIATE ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | +// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | REG | +// | OPCODE | FUNCT3 | FUNCT7 | REG | REG | OFF | + +// REG TO REG ADDRESSING + +// | OPCODE | FUNCT3 | FUNCT7 | REG | REG2 | + +//////////////////////////////// + +// LOAD/CALL INTERRUPTS + +// SET A HANDLER IN ADDRESS: +// DISABLE INTERRUPTS +// PROCESS INTERRUPT +// ENABLE INTERRUPTS + +//////////////////////////////// diff --git a/dev/ndkdll/Asm/CPU/amd64.hxx b/dev/ndkdll/Asm/CPU/amd64.hxx new file mode 100644 index 0000000..4067ec7 --- /dev/null +++ b/dev/ndkdll/Asm/CPU/amd64.hxx @@ -0,0 +1,57 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include + +// @brief AMD64 support. +// @file CPU/amd64.hpp + +#define kAsmOpcodeDecl(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, + +typedef char i64_character_t; +typedef uint8_t i64_byte_t; +typedef uint16_t i64_hword_t; +typedef uint32_t i64_word_t; + +struct CpuOpcodeAMD64 +{ + std::string fName; + i64_byte_t fPrefixBytes[4]; + i64_hword_t fOpcode; + i64_hword_t fModReg; + i64_word_t fDisplacment; + i64_word_t fImmediate; +}; + +/// these two are edge cases +#define kAsmIntOpcode 0xCC +#define kasmIntOpcodeAlt 0xCD + +#define kAsmJumpOpcode 0x0F80 +#define kJumpLimit 30 +#define kJumpLimitStandard 0xE3 +#define kJumpLimitStandardLimit 0xEB + +inline std::vector kOpcodesAMD64 = { + kAsmOpcodeDecl("int", 0xCD) + kAsmOpcodeDecl("into", 0xCE) + kAsmOpcodeDecl("intd", 0xF1) + kAsmOpcodeDecl("int3", 0xC3) + kAsmOpcodeDecl("iret", 0xCF) + kAsmOpcodeDecl("retf", 0xCB) + kAsmOpcodeDecl("retn", 0xC3) + kAsmOpcodeDecl("ret", 0xC3) + kAsmOpcodeDecl("sti", 0xfb) + kAsmOpcodeDecl("cli", 0xfa) + kAsmOpcodeDecl("hlt", 0xf4) + kAsmOpcodeDecl("nop", 0x90) + kAsmOpcodeDecl("mov", 0x48) + kAsmOpcodeDecl("call", 0xFF) +}; + +#define kAsmRegisterLimit 15 diff --git a/dev/ndkdll/Asm/CPU/arm64.hxx b/dev/ndkdll/Asm/CPU/arm64.hxx new file mode 100644 index 0000000..85e2f75 --- /dev/null +++ b/dev/ndkdll/Asm/CPU/arm64.hxx @@ -0,0 +1,26 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief ARM64 encoding support. +/// @file CPU/arm64.hpp + +struct CpuOpcodeArm64; + +/// @brief ARM64 opcode header. +struct CpuOpcodeArm64 final +{ + uint8_t fOpcode; // opcode + uint8_t fRegisterLeft; // left register index + uint8_t fRegisterRight; // right register index + bool fRegisterLeftHooked; + bool fRegisterRightHooked; + uint32_t fImmediateValue; // immediate 32-bit value + bool fImmediateValueHooked; +}; diff --git a/dev/ndkdll/Asm/CPU/ppc.hxx b/dev/ndkdll/Asm/CPU/ppc.hxx new file mode 100644 index 0000000..e3ea6c5 --- /dev/null +++ b/dev/ndkdll/Asm/CPU/ppc.hxx @@ -0,0 +1,1929 @@ +/* ------------------------------------------- + + Some modifications are copyrighted under: + ZKA Technologies + + Original author: + Apple Inc + +------------------------------------------- */ + +#pragma once + +#include + +/// @note Based of: +/// https://opensource.apple.com/source/cctools/cctools-750/as/ppc-opcode.h.auto.html + +/* + * These defines are use in the cpus field of the instructions. If the field + * is zero it can execute on all cpus. The defines are or'ed together. This + * information is used to set the cpusubtype in the resulting object file. + */ +#define CPU601 0x1 +#define IMPL64 0x2 +#define OPTIONAL 0x4 +#define VMX 0x8 +#define CPU970 0x10 /* added to OPTIONAL insts that the 970 has */ +#define CPUMAHROUSS 0x12 /* optional mahrouss insts. */ + +enum optype +{ + NONE, /* no operand */ + JBSR, /* jbsr pseudo op */ + PCREL, /* PC relative (branch offset) */ + BADDR, /* Branch address (sign extended absolute address) */ + D, /* 16 bit displacement */ + DS, /* 14 bit displacement (double word) */ + SI, /* signed 16 bit immediate */ + UI, /* unsigned 16 bit immediate */ + HI, /* high 16 bit immediate (with truncation) */ + GREG, /* general register */ + G0REG, /* general register r1-r31 or 0 */ + FREG, /* float register */ + VREG, /* vector register */ + SGREG, /* segment register */ + SPREG, /* special register (or 10 bit number, 5 bit halves reversed) */ + BCND, /* branch condition opcode */ + CRF, /* condition register field */ + CRFONLY, /* condition register field only no expression allowed */ + sh, /* 6 bit number (0 - 63) (sh field, split and reversed) */ + mb, /* 6 bit number (0 - 63) (mb field, mb5 || mb0:4 reversed) */ + NUM, /* number */ + SNUM, /* signed number */ + NUM0, /* number (where 1< -#include -#include - -namespace NDK -{ - // - // @brief Frontend to Assembly mountpoint. - // - class AssemblyInterface - { - public: - explicit AssemblyInterface() = default; - virtual ~AssemblyInterface() = default; - - MPCC_COPY_DEFAULT(AssemblyInterface); - - //@ brief compile to object file. - // Example C++ -> MASM -> AE object. - virtual Int32 CompileToFormat(std::string& src, Int32 arch) = 0; - }; - - /// @brief Simple assembly factory - class AssemblyFactory final - { - public: - explicit AssemblyFactory() = default; - ~AssemblyFactory() = default; - - MPCC_COPY_DEFAULT(AssemblyFactory); - - public: - enum - { - kArchAMD64, - kArch32x0, - kArch64x0, - kArchRISCV, - kArchPowerPC, - kArchUnknown, - }; - - Int32 Compile(std::string& sourceFile, const Int32& arch) noexcept; - - void Mount(AssemblyInterface* mountPtr) noexcept; - AssemblyInterface* Unmount() noexcept; - - private: - AssemblyInterface* fMounted{nullptr}; - }; - - union NumberCastBase { - NumberCastBase() = default; - ~NumberCastBase() = default; - }; - - union NumberCast64 final { - NumberCast64() = default; - explicit NumberCast64(UInt64 raw) - : raw(raw) - { - } - ~NumberCast64() - { - raw = 0; - } - - CharType number[8]; - UInt64 raw; - }; - - union NumberCast32 final { - NumberCast32() = default; - explicit NumberCast32(UInt32 raw) - : raw(raw) - { - } - ~NumberCast32() - { - raw = 0; - } - - CharType number[4]; - UInt32 raw; - }; - - union NumberCast16 final { - NumberCast16() = default; - explicit NumberCast16(UInt16 raw) - : raw(raw) - { - } - ~NumberCast16() - { - raw = 0; - } - - CharType number[2]; - UInt16 raw; - }; - - union NumberCast8 final { - NumberCast8() = default; - explicit NumberCast8(UInt8 raw) - : raw(raw) - { - } - ~NumberCast8() - { - raw = 0; - } - - CharType number; - UInt8 raw; - }; - - class EncoderInterface - { - public: - explicit EncoderInterface() = default; - virtual ~EncoderInterface() = default; - - MPCC_COPY_DEFAULT(EncoderInterface); - - 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_AMD64__ - - class EncoderAMD64 final : public EncoderInterface - { - public: - explicit EncoderAMD64() = default; - ~EncoderAMD64() override = default; - - MPCC_COPY_DEFAULT(EncoderAMD64); - - 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; - - virtual bool WriteNumber16(const std::size_t& pos, std::string& from_what); - virtual bool WriteNumber32(const std::size_t& pos, std::string& from_what); - virtual bool WriteNumber8(const std::size_t& pos, std::string& from_what); - }; - -#endif // __ASM_NEED_AMD64__ - -#ifdef __ASM_NEED_64x0__ - - class Encoder64x0 final : public EncoderInterface - { - public: - explicit Encoder64x0() = default; - ~Encoder64x0() override = default; - - MPCC_COPY_DEFAULT(Encoder64x0); - - 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__ - -#ifdef __ASM_NEED_32x0__ - - class Encoder32x0 final : public EncoderInterface - { - public: - explicit Encoder32x0() = default; - ~Encoder32x0() override = default; - - MPCC_COPY_DEFAULT(Encoder32x0); - - 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_32x0__ - -#ifdef __ASM_NEED_PPC__ - - class EncoderPowerPC final : public EncoderInterface - { - public: - explicit EncoderPowerPC() = default; - ~EncoderPowerPC() override = default; - - MPCC_COPY_DEFAULT(EncoderPowerPC); - - 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_32x0__ -} // namespace NDK diff --git a/dev/ndkdll/AsmKit/CPU/32x0.hxx b/dev/ndkdll/AsmKit/CPU/32x0.hxx deleted file mode 100644 index 018dea9..0000000 --- a/dev/ndkdll/AsmKit/CPU/32x0.hxx +++ /dev/null @@ -1,95 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include - -// @brief 32x0 support. -// @file CPU/32x0.hpp - -#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ - {.fName = __NAME, \ - .fOpcode = __OPCODE, \ - .fFunct3 = __FUNCT3, \ - .fFunct7 = __FUNCT7}, - -#define kAsmImmediate 0x01 -#define kAsmSyscall 0x02 -#define kAsmJump 0x03 -#define kAsmNoArgs 0x04 - -#define kAsmByte 0 -#define kAsmHWord 1 -#define kAsmWord 2 - -struct CpuCode32x0 -{ - const char fName[32]; - char fOpcode; - char fSize; - char fFunct3; - char fFunct7; -}; - -#define kAsmDWordStr ".dword" /* 64 bit */ -#define kAsmWordStr ".word" /* 32-bit */ -#define kAsmHWordStr ".half" /* 16-bit */ -#define kAsmByteStr ".byte" /* 8-bit */ - -inline std::vector kOpcodes32x0 = { - kAsmOpcodeDecl("nop", 0b0100011, 0b000, kAsmNoArgs) // nothing to do. - kAsmOpcodeDecl("br", 0b1110011, 0b001, kAsmJump) // jump to branch - kAsmOpcodeDecl("mr", 0b0100011, 0b101, kAsmImmediate) // move registers - kAsmOpcodeDecl("psh", 0b0111011, 0b000, kAsmImmediate) // push to sp - kAsmOpcodeDecl("pop", 0b0111011, 0b001, kAsmImmediate) // pop from sp. - kAsmOpcodeDecl("cls", 0b0111011, 0b010, - kAsmImmediate) // setup stack and call, store address to CR. - kAsmOpcodeDecl("rts", 0b0111011, 0b110, - kAsmImmediate) // pull stack and return form CR. - kAsmOpcodeDecl("int", 0b0111111, 0b000, kAsmSyscall) // raise interrupt -}; - -// \brief 64x0 register prefix -// example: r32, r0 -// r32 -> sp -// r0 -> hw zero - -#define kAsmRegisterPrefix "r" -#define kAsmRegisterLimit 16 -#define kAsmPcRegister 17 -#define kAsmCrRegister 18 -#define kAsmSpRegister 5 - -/* return address register */ -#define kAsmRetRegister 19 - -///////////////////////////////////////////////////////////////////////////// - -// SYSTEM CALL ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | OFF | - -// IMMEDIATE ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | -// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | REG | -// | OPCODE | FUNCT3 | FUNCT7 | REG | REG | OFF | - -// REG TO REG ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | REG | REG2 | - -//////////////////////////////// - -// LOAD/CALL INTERRUPTS - -// SET A HANDLER IN ADDRESS: TODO: find one -// DISABLE INTERRUPTS -// PROCESS INTERRUPT -// ENABLE INTERRUPTS - -//////////////////////////////// diff --git a/dev/ndkdll/AsmKit/CPU/64x0.hxx b/dev/ndkdll/AsmKit/CPU/64x0.hxx deleted file mode 100644 index 99a88b1..0000000 --- a/dev/ndkdll/AsmKit/CPU/64x0.hxx +++ /dev/null @@ -1,108 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include -#include - -// @brief 64x0 support. -// @file CPU/64x0.hpp - -#define kAsmOpcodeDecl(__NAME, __OPCODE, __FUNCT3, __FUNCT7) \ - {.fName = __NAME, \ - .fOpcode = __OPCODE, \ - .fFunct3 = __FUNCT3, \ - .fFunct7 = __FUNCT7}, - -#define kAsmImmediate 0x01 -#define kAsmRegToReg 0x02 -#define kAsmSyscall 0x03 -#define kAsmJump 0x04 -#define kAsmNoArgs 0x00 - -typedef char e64k_character_t; -typedef uint8_t e64k_num_t; - -struct CpuOpcode64x0 -{ - const e64k_character_t fName[32]; - e64k_num_t fOpcode; - e64k_num_t fFunct3; - e64k_num_t fFunct7; -}; - -inline std::vector kOpcodes64x0 = { - kAsmOpcodeDecl("nop", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. - kAsmOpcodeDecl("np", 0b0000000, 0b0000000, kAsmNoArgs) // no-operation. - kAsmOpcodeDecl("jlr", 0b1110011, 0b0000111, - kAsmJump) // jump to linked return register - kAsmOpcodeDecl("jrl", 0b1110011, 0b0001111, - kAsmJump) // jump from return register. - kAsmOpcodeDecl("mv", 0b0100011, 0b101, kAsmRegToReg) - kAsmOpcodeDecl("bg", 0b1100111, 0b111, kAsmRegToReg) - kAsmOpcodeDecl("bl", 0b1100111, 0b011, kAsmRegToReg) - kAsmOpcodeDecl("beq", 0b1100111, 0b000, kAsmRegToReg) - kAsmOpcodeDecl("bne", 0b1100111, 0b001, kAsmRegToReg) - kAsmOpcodeDecl("bge", 0b1100111, 0b101, kAsmRegToReg) - kAsmOpcodeDecl("ble", 0b1100111, 0b100, kAsmRegToReg) - kAsmOpcodeDecl("stw", 0b0001111, 0b100, kAsmImmediate) - 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("sub", 0b0101011, 0b101, kAsmImmediate) - // add/sub with carry flag - kAsmOpcodeDecl("addc", 0b0101011, 0b110, kAsmImmediate) - kAsmOpcodeDecl("decc", 0b0101011, 0b111, kAsmImmediate) - kAsmOpcodeDecl("int", 0b1110011, 0b00, kAsmSyscall) - kAsmOpcodeDecl("pha", 0b1110011, 0b00, kAsmNoArgs) - kAsmOpcodeDecl("pla", 0b1110011, 0b01, kAsmNoArgs)}; - -// \brief 64x0 register prefix -// example: r32, r0 -// r32 -> sp -// r0 -> hw zero - -#define kAsmFloatZeroRegister 0 -#define kAsmZeroRegister 0 - -#define kAsmRegisterPrefix "r" -#define kAsmRegisterLimit 30 -#define kAsmPcRegister 17 -#define kAsmCrRegister 18 -#define kAsmSpRegister 5 - -/* return address register */ -#define kAsmRetRegister 19 - -///////////////////////////////////////////////////////////////////////////// - -// SYSTEM CALL/JUMP ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | OFF | - -// IMMEDIATE ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | -// | OPCODE | FUNCT3 | FUNCT7 | REG | OFF | REG | -// | OPCODE | FUNCT3 | FUNCT7 | REG | REG | OFF | - -// REG TO REG ADDRESSING - -// | OPCODE | FUNCT3 | FUNCT7 | REG | REG2 | - -//////////////////////////////// - -// LOAD/CALL INTERRUPTS - -// SET A HANDLER IN ADDRESS: -// DISABLE INTERRUPTS -// PROCESS INTERRUPT -// ENABLE INTERRUPTS - -//////////////////////////////// diff --git a/dev/ndkdll/AsmKit/CPU/amd64.hxx b/dev/ndkdll/AsmKit/CPU/amd64.hxx deleted file mode 100644 index 4067ec7..0000000 --- a/dev/ndkdll/AsmKit/CPU/amd64.hxx +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include - -// @brief AMD64 support. -// @file CPU/amd64.hpp - -#define kAsmOpcodeDecl(__NAME, __OPCODE) {.fName = __NAME, .fOpcode = __OPCODE}, - -typedef char i64_character_t; -typedef uint8_t i64_byte_t; -typedef uint16_t i64_hword_t; -typedef uint32_t i64_word_t; - -struct CpuOpcodeAMD64 -{ - std::string fName; - i64_byte_t fPrefixBytes[4]; - i64_hword_t fOpcode; - i64_hword_t fModReg; - i64_word_t fDisplacment; - i64_word_t fImmediate; -}; - -/// these two are edge cases -#define kAsmIntOpcode 0xCC -#define kasmIntOpcodeAlt 0xCD - -#define kAsmJumpOpcode 0x0F80 -#define kJumpLimit 30 -#define kJumpLimitStandard 0xE3 -#define kJumpLimitStandardLimit 0xEB - -inline std::vector kOpcodesAMD64 = { - kAsmOpcodeDecl("int", 0xCD) - kAsmOpcodeDecl("into", 0xCE) - kAsmOpcodeDecl("intd", 0xF1) - kAsmOpcodeDecl("int3", 0xC3) - kAsmOpcodeDecl("iret", 0xCF) - kAsmOpcodeDecl("retf", 0xCB) - kAsmOpcodeDecl("retn", 0xC3) - kAsmOpcodeDecl("ret", 0xC3) - kAsmOpcodeDecl("sti", 0xfb) - kAsmOpcodeDecl("cli", 0xfa) - kAsmOpcodeDecl("hlt", 0xf4) - kAsmOpcodeDecl("nop", 0x90) - kAsmOpcodeDecl("mov", 0x48) - kAsmOpcodeDecl("call", 0xFF) -}; - -#define kAsmRegisterLimit 15 diff --git a/dev/ndkdll/AsmKit/CPU/arm64.hxx b/dev/ndkdll/AsmKit/CPU/arm64.hxx deleted file mode 100644 index 85e2f75..0000000 --- a/dev/ndkdll/AsmKit/CPU/arm64.hxx +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------- - -Copyright ZKA Technologies - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief ARM64 encoding support. -/// @file CPU/arm64.hpp - -struct CpuOpcodeArm64; - -/// @brief ARM64 opcode header. -struct CpuOpcodeArm64 final -{ - uint8_t fOpcode; // opcode - uint8_t fRegisterLeft; // left register index - uint8_t fRegisterRight; // right register index - bool fRegisterLeftHooked; - bool fRegisterRightHooked; - uint32_t fImmediateValue; // immediate 32-bit value - bool fImmediateValueHooked; -}; diff --git a/dev/ndkdll/AsmKit/CPU/ppc.hxx b/dev/ndkdll/AsmKit/CPU/ppc.hxx deleted file mode 100644 index e3ea6c5..0000000 --- a/dev/ndkdll/AsmKit/CPU/ppc.hxx +++ /dev/null @@ -1,1929 +0,0 @@ -/* ------------------------------------------- - - Some modifications are copyrighted under: - ZKA Technologies - - Original author: - Apple Inc - -------------------------------------------- */ - -#pragma once - -#include - -/// @note Based of: -/// https://opensource.apple.com/source/cctools/cctools-750/as/ppc-opcode.h.auto.html - -/* - * These defines are use in the cpus field of the instructions. If the field - * is zero it can execute on all cpus. The defines are or'ed together. This - * information is used to set the cpusubtype in the resulting object file. - */ -#define CPU601 0x1 -#define IMPL64 0x2 -#define OPTIONAL 0x4 -#define VMX 0x8 -#define CPU970 0x10 /* added to OPTIONAL insts that the 970 has */ -#define CPUMAHROUSS 0x12 /* optional mahrouss insts. */ - -enum optype -{ - NONE, /* no operand */ - JBSR, /* jbsr pseudo op */ - PCREL, /* PC relative (branch offset) */ - BADDR, /* Branch address (sign extended absolute address) */ - D, /* 16 bit displacement */ - DS, /* 14 bit displacement (double word) */ - SI, /* signed 16 bit immediate */ - UI, /* unsigned 16 bit immediate */ - HI, /* high 16 bit immediate (with truncation) */ - GREG, /* general register */ - G0REG, /* general register r1-r31 or 0 */ - FREG, /* float register */ - VREG, /* vector register */ - SGREG, /* segment register */ - SPREG, /* special register (or 10 bit number, 5 bit halves reversed) */ - BCND, /* branch condition opcode */ - CRF, /* condition register field */ - CRFONLY, /* condition register field only no expression allowed */ - sh, /* 6 bit number (0 - 63) (sh field, split and reversed) */ - mb, /* 6 bit number (0 - 63) (mb field, mb5 || mb0:4 reversed) */ - NUM, /* number */ - SNUM, /* signed number */ - NUM0, /* number (where 1< #include -#define MPCC_EXEC_ERROR -30 -#define MPCC_FILE_NOT_FOUND -31 -#define MPCC_DIR_NOT_FOUND -32 -#define MPCC_FILE_EXISTS -33 -#define MPCC_TOO_LONG -34 -#define MPCC_INVALID_DATA -35 -#define MPCC_UNIMPLEMENTED -36 -#define MPCC_FAT_ERROR -37 +#define NDK_EXEC_ERROR -30 +#define NDK_FILE_NOT_FOUND -31 +#define NDK_DIR_NOT_FOUND -32 +#define NDK_FILE_EXISTS -33 +#define NDK_TOO_LONG -34 +#define NDK_INVALID_DATA -35 +#define NDK_UNIMPLEMENTED -36 +#define NDK_FAT_ERROR -37 diff --git a/dev/ndkdll/NFC/String.hxx b/dev/ndkdll/NFC/String.hxx index 3a9b6ff..c42c412 100644 --- a/dev/ndkdll/NFC/String.hxx +++ b/dev/ndkdll/NFC/String.hxx @@ -42,7 +42,7 @@ namespace NDK } } - MPCC_COPY_DEFAULT(StringView); + NDK_COPY_DEFAULT(StringView); CharType* Data(); const CharType* CData() const; diff --git a/dev/ndkdll/Parser.hxx b/dev/ndkdll/Parser.hxx index 8abeae7..20a2995 100644 --- a/dev/ndkdll/Parser.hxx +++ b/dev/ndkdll/Parser.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace NDK @@ -21,7 +21,7 @@ namespace NDK explicit CompilerBackend() = default; virtual ~CompilerBackend() = default; - MPCC_COPY_DEFAULT(CompilerBackend); + NDK_COPY_DEFAULT(CompilerBackend); // NOTE: cast this to your user defined ast. typedef void* AstType; diff --git a/dev/ndkdll/Private/Imaging/TPM.hxx b/dev/ndkdll/Private/Imaging/TPM.hxx deleted file mode 100644 index dbd90fe..0000000 --- a/dev/ndkdll/Private/Imaging/TPM.hxx +++ /dev/null @@ -1,17 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -/** - @brief The Explicit Partition Map scheme. -*/ - -#ifndef __IMAGING_TPM_HXX__ -#define __IMAGING_TPM_HXX__ - -struct TPM_IMAGE_HEADER; -struct TPM_FILE_RECORD; - -#endif // ifndef __IMAGING_TPM_HXX__ diff --git a/dev/ndkdll/Sources/Assembler32x0.cxx b/dev/ndkdll/Sources/Assembler32x0.cxx index 213e335..42e1bb4 100644 --- a/dev/ndkdll/Sources/Assembler32x0.cxx +++ b/dev/ndkdll/Sources/Assembler32x0.cxx @@ -19,7 +19,7 @@ #define __ASM_NEED_32x0__ 1 -#include +#include #include #include #include diff --git a/dev/ndkdll/Sources/Assembler64x0.cxx b/dev/ndkdll/Sources/Assembler64x0.cxx index 552b547..a02ed03 100644 --- a/dev/ndkdll/Sources/Assembler64x0.cxx +++ b/dev/ndkdll/Sources/Assembler64x0.cxx @@ -19,7 +19,7 @@ #define __ASM_NEED_64x0__ 1 -#include +#include #include #include #include diff --git a/dev/ndkdll/Sources/AssemblerAMD64.cxx b/dev/ndkdll/Sources/AssemblerAMD64.cxx index 24686b4..73782de 100644 --- a/dev/ndkdll/Sources/AssemblerAMD64.cxx +++ b/dev/ndkdll/Sources/AssemblerAMD64.cxx @@ -27,7 +27,7 @@ #define kAssemblerPragmaSymStr "#" #define kAssemblerPragmaSym '#' -#include +#include #include #include #include diff --git a/dev/ndkdll/Sources/AssemblerPower.cxx b/dev/ndkdll/Sources/AssemblerPower.cxx index 1d4f3d3..231829f 100644 --- a/dev/ndkdll/Sources/AssemblerPower.cxx +++ b/dev/ndkdll/Sources/AssemblerPower.cxx @@ -18,7 +18,7 @@ #define __ASM_NEED_PPC__ 1 #include -#include +#include #include #include #include @@ -299,7 +299,7 @@ asm_fail_exit: if (kVerbose) kStdOut << "power-as: Exit failed.\n"; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/dev/ndkdll/Sources/AssemblyFactory.cxx b/dev/ndkdll/Sources/AssemblyFactory.cxx index 506652c..51c5d56 100644 --- a/dev/ndkdll/Sources/AssemblyFactory.cxx +++ b/dev/ndkdll/Sources/AssemblyFactory.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include #include /** @@ -20,7 +20,7 @@ #include -//! @file AsmKit.cpp +//! @file Asm.cpp //! @brief AssemblyKit source implementation. namespace NDK @@ -30,7 +30,7 @@ namespace NDK const Int32& arch) noexcept { if (sourceFile.length() < 1 || !fMounted) - return MPCC_UNIMPLEMENTED; + return NDK_UNIMPLEMENTED; return fMounted->CompileToFormat(sourceFile, arch); } diff --git a/dev/ndkdll/Sources/BasicPreProcessor.cxx b/dev/ndkdll/Sources/BasicPreProcessor.cxx index 3056f13..c843824 100644 --- a/dev/ndkdll/Sources/BasicPreProcessor.cxx +++ b/dev/ndkdll/Sources/BasicPreProcessor.cxx @@ -58,7 +58,7 @@ class bpp_pragma final { explicit bpp_pragma() = default; ~bpp_pragma() = default; - MPCC_COPY_DEFAULT(bpp_pragma); + NDK_COPY_DEFAULT(bpp_pragma); std::string fMacroName; bpp_parser_fn_t fParse; @@ -877,7 +877,7 @@ NDK_MODULE(NewOSPreprocessor) { kFiles.emplace_back(argv[index]); } - if (kFiles.empty()) return MPCC_EXEC_ERROR; + if (kFiles.empty()) return NDK_EXEC_ERROR; for (auto &file : kFiles) { if (!std::filesystem::exists(file)) continue; diff --git a/dev/ndkdll/Sources/CCompiler64x0.cxx b/dev/ndkdll/Sources/CCompiler64x0.cxx index 3a6ffd2..3244c34 100644 --- a/dev/ndkdll/Sources/CCompiler64x0.cxx +++ b/dev/ndkdll/Sources/CCompiler64x0.cxx @@ -10,7 +10,7 @@ /// BUGS: 0 /// TODO: none -#include +#include #include #include #include @@ -148,7 +148,7 @@ public: explicit CompilerBackend64x0() = default; ~CompilerBackend64x0() override = default; - MPCC_COPY_DEFAULT(CompilerBackend64x0); + NDK_COPY_DEFAULT(CompilerBackend64x0); std::string Check(const char* text, const char* file); bool Compile(const std::string& text, const char* file) override; @@ -371,7 +371,7 @@ bool CompilerBackend64x0::Compile(const std::string& text, const char* file) if (expr.find(")") != std::string::npos) expr.erase(expr.find(")")); - kIfFunction = "__MPCC_IF_PROC_"; + kIfFunction = "__NDK_IF_PROC_"; kIfFunction += std::to_string(time_off._Raw); syntaxLeaf.fUserValue = "\tlda r12, import "; @@ -1301,7 +1301,7 @@ public: explicit AssemblyCCInterface() = default; ~AssemblyCCInterface() override = default; - MPCC_COPY_DEFAULT(AssemblyCCInterface); + NDK_COPY_DEFAULT(AssemblyCCInterface); [[maybe_unused]] static Int32 Arch() noexcept { diff --git a/dev/ndkdll/Sources/CCompilerPower64.cxx b/dev/ndkdll/Sources/CCompilerPower64.cxx index 528ed8f..222b64f 100644 --- a/dev/ndkdll/Sources/CCompilerPower64.cxx +++ b/dev/ndkdll/Sources/CCompilerPower64.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include #include @@ -24,7 +24,7 @@ /// @author Amlal El Mahrouss (amlel) /// @file cc.cxx -/// @brief POWER C Compiler. +/// @brief POWER64 C Compiler. ///////////////////// @@ -139,7 +139,7 @@ public: explicit CompilerBackendPower64() = default; ~CompilerBackendPower64() override = default; - MPCC_COPY_DEFAULT(CompilerBackendPower64); + NDK_COPY_DEFAULT(CompilerBackendPower64); std::string Check(const char* text, const char* file); bool Compile(const std::string& text, const char* file) override; @@ -381,7 +381,7 @@ bool CompilerBackendPower64::Compile(const std::string& text, const char* file) if (expr.find(")") != std::string::npos) expr.erase(expr.find(")")); - kIfFunction = "__MPCC_IF_PROC_"; + kIfFunction = "__NDK_IF_PROC_"; kIfFunction += std::to_string(time_off._Raw); syntaxLeaf.fUserValue = @@ -1324,7 +1324,7 @@ public: explicit AssemblyMountpointCLang() = default; ~AssemblyMountpointCLang() override = default; - MPCC_COPY_DEFAULT(AssemblyMountpointCLang); + NDK_COPY_DEFAULT(AssemblyMountpointCLang); [[maybe_unused]] static Int32 Arch() noexcept { diff --git a/dev/ndkdll/Sources/CPlusPlusCompilerAMD64.cxx b/dev/ndkdll/Sources/CPlusPlusCompilerAMD64.cxx index 535a3fb..02e4812 100644 --- a/dev/ndkdll/Sources/CPlusPlusCompilerAMD64.cxx +++ b/dev/ndkdll/Sources/CPlusPlusCompilerAMD64.cxx @@ -20,7 +20,7 @@ // import, @MLAutoRelease { ... }, fn foo() -> auto { ... } -#include +#include #include #include @@ -33,13 +33,13 @@ #include #include -/* ZKA C++ driver */ +/* ZKA C++ Compiler driver */ /* This is part of NDK. */ /* (c) ZKA Technologies */ /// @author Amlal El Mahrouss (amlel) /// @file cc.cxx -/// @brief Optimized C++ Compiler. +/// @brief Optimized C++ Compiler Driver. /// @todo Throw error for scoped inside scoped variables when they get referenced outside. /// @todo Add class/struct/enum support. @@ -55,7 +55,7 @@ ///////////////////////////////////// -// INTERNALS OF THE C COMPILER +// INTERNALS OF THE C++ COMPILER ///////////////////////////////////// @@ -105,7 +105,7 @@ namespace detail /// @param reason the reason of the error. /// @param file where does it originate from? void print_error_asm(std::string reason, std::string file) noexcept; - + struct CompilerType { std::string fName; @@ -151,7 +151,7 @@ public: explicit CompilerBackendCPlusPlus() = default; ~CompilerBackendCPlusPlus() override = default; - MPCC_COPY_DEFAULT(CompilerBackendCPlusPlus); + NDK_COPY_DEFAULT(CompilerBackendCPlusPlus); bool Compile(const std::string& text, const char* file) override; @@ -404,7 +404,7 @@ bool CompilerBackendCPlusPlus::Compile(const std::string& text, ch = '_'; } - syntax_tree.fUserValue = "export .code64 __MPCC_" + fnName + "\n"; + syntax_tree.fUserValue = "export .code64 __NDK_" + fnName + "\n"; ++kLevelFunction; } @@ -732,7 +732,7 @@ public: explicit AssemblyCPlusPlusInterface() = default; ~AssemblyCPlusPlusInterface() override = default; - MPCC_COPY_DEFAULT(AssemblyCPlusPlusInterface); + NDK_COPY_DEFAULT(AssemblyCPlusPlusInterface); [[maybe_unused]] static Int32 Arch() noexcept diff --git a/dev/ndkdll/Sources/Detail/asmutils.hxx b/dev/ndkdll/Sources/Detail/asmutils.hxx index 2451a28..b52329d 100644 --- a/dev/ndkdll/Sources/Detail/asmutils.hxx +++ b/dev/ndkdll/Sources/Detail/asmutils.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include using namespace NDK; diff --git a/dev/ndkdll/Sources/Detail/compilerutils.hxx b/dev/ndkdll/Sources/Detail/compilerutils.hxx index ba3fb79..84312a2 100644 --- a/dev/ndkdll/Sources/Detail/compilerutils.hxx +++ b/dev/ndkdll/Sources/Detail/compilerutils.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #define kZero64Section ".zero64" diff --git a/dev/ndkdll/Sources/Linker.cxx b/dev/ndkdll/Sources/Linker.cxx index 9243531..fe1690e 100644 --- a/dev/ndkdll/Sources/Linker.cxx +++ b/dev/ndkdll/Sources/Linker.cxx @@ -16,7 +16,7 @@ #include //! Assembler Kit -#include +#include //! Preferred Executable Format #include @@ -180,7 +180,7 @@ NDK_MODULE(NewOSLinker) if (argv[i][0] == '/') { kStdOut << "link: unknown flag: " << argv[i] << "\n"; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } kObjectList.emplace_back(argv[i]); @@ -192,14 +192,14 @@ NDK_MODULE(NewOSLinker) if (kOutput.empty()) { kStdOut << "link: no output filename set." << std::endl; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } // sanity check. if (kObjectList.empty()) { kStdOut << "link: no input files." << std::endl; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } else { @@ -213,7 +213,7 @@ NDK_MODULE(NewOSLinker) // if filesystem doesn't find file // -> throw error. kStdOut << "link: no such file: " << obj << std::endl; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } } } @@ -222,7 +222,7 @@ NDK_MODULE(NewOSLinker) if (kArch == 0) { kStdOut << "link: no target architecture set, can't continue." << std::endl; - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } NDK::PEFContainer pef_container{}; @@ -253,7 +253,7 @@ NDK_MODULE(NewOSLinker) kStdOut << "link: error: " << strerror(errno) << "\n"; } - return MPCC_FILE_NOT_FOUND; + return NDK_FILE_NOT_FOUND; } //! Read AE to convert as PEF. @@ -292,7 +292,7 @@ NDK_MODULE(NewOSLinker) << std::endl; std::remove(kOutput.c_str()); - return MPCC_FAT_ERROR; + return NDK_FAT_ERROR; } else { @@ -398,7 +398,7 @@ NDK_MODULE(NewOSLinker) std::remove(kOutput.c_str()); // don't continue, it is a fatal error. - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } pef_container.Cpu = archs; @@ -689,7 +689,7 @@ NDK_MODULE(NewOSLinker) } std::remove(kOutput.c_str()); - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } // step 2.5: write program bytes. @@ -732,7 +732,7 @@ NDK_MODULE(NewOSLinker) << ", is corrupt, removing file...\n"; std::remove(kOutput.c_str()); - return MPCC_EXEC_ERROR; + return NDK_EXEC_ERROR; } return 0; -- cgit v1.2.3