Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/Variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(LTO_FLAG "-flto")
endif()
set(DEBUG_COMPILE_FLAGS -Wall -Wextra -Werror -Wno-pointer-arith -O0 -ggdb3 -Wno-unused-const-variable -Wno-missing-field-initializers -Wno-stringop-overflow -Wno-unknown-warning-option)
set(DEBUG_COMPILE_FLAGS -Wall -Wextra -Werror -Wno-pointer-arith -O0 -ggdb3 -Wno-unused-const-variable -Wno-missing-field-initializers -Wno-stringop-overflow -Wno-unknown-warning-option -D__HCPU_DEBUG)
set(FAST_COMPILE_FLAGS -Wall -Wextra -Werror -Wno-pointer-arith -O3 -Wno-unused-const-variable -Wno-missing-field-initializers -Wno-stringop-overflow -Wno-unknown-warning-option)
25 changes: 12 additions & 13 deletions src/Assembler/Core/BinaryTransformer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "Emulator/Core/CPU/Instructions/Opcodes.hpp"
#include "Logger/Logger.hpp"
#include <Emulator/Core/CPU/Instructions/Opcodes.hpp>
#include <Emulator/Core/CPU/Instructions/Flags.hpp>
#include <Core/BinaryTransformer.hpp>
#include <Core/Compiler.hpp>

#include <utility>
#include <Logger/Logger.hpp>
#include <Exit.hpp>

HyperCPU::OperandTypes HCAsm::BinaryTransformer::DetermineOperandTypes(Operand& op1, Operand& op2) {
Op1T tp1;
Expand All @@ -26,7 +25,7 @@ HyperCPU::OperandTypes HCAsm::BinaryTransformer::DetermineOperandTypes(Operand&
case HCAsm::OperandType::none:
tp1 = Op1T::NONE; break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}

switch (op2.type) {
Expand All @@ -45,7 +44,7 @@ HyperCPU::OperandTypes HCAsm::BinaryTransformer::DetermineOperandTypes(Operand&
case HCAsm::OperandType::none:
tp2 = Op2T::NONE; break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}

return QuickCast(QuickOR(tp1, tp2));
Expand All @@ -69,7 +68,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {

if (HasAddressAddition(instr.op1.type) && HasAddressAddition(instr.op2.type)) {
logger.Log(HyperCPU::LogLevel::ERROR, "You can't use memory address additions for two operands!");
std::exit(1);
EXIT(1);
} else if (HasAddressAddition(instr.op1.type) || HasAddressAddition(instr.op2.type)) {
encoded_operands |= 0b10000000;
if (HasAddressAddition(instr.op2.type)) {
Expand Down Expand Up @@ -107,7 +106,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
case HyperCPU::OperandTypes::RM_IMM:
if (instr.op1.mode == HCAsm::Mode::none) {
logger.Log(HyperCPU::LogLevel::ERROR, "Ambiguous operand size!");
std::exit(1);
EXIT(1);
}
[[fallthrough]];
case HyperCPU::OperandTypes::R_R:
Expand All @@ -120,7 +119,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
case HyperCPU::OperandTypes::IMM:
if (instr.op1.mode == Mode::none) {
logger.Log(HyperCPU::LogLevel::ERROR, "Undefined operand size!");
std::exit(1);
EXIT(1);
}
md = instr.op1.mode;
break;
Expand All @@ -132,7 +131,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
md = HCAsm::Mode::b8; // Placeholder
break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
encoded_operands |= (static_cast<std::uint8_t>(md) << 4);
encoded_operands |= static_cast<std::uint8_t>(types);
Expand Down Expand Up @@ -160,7 +159,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
case HCAsm::Mode::b32: res.push(static_cast<std::uint32_t>(std::get<std::uint64_t>(instr.op2.variant))); break;
case HCAsm::Mode::b64: res.push(static_cast<std::uint64_t>(std::get<std::uint64_t>(instr.op2.variant))); break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
break;
case HyperCPU::OperandTypes::R:
Expand All @@ -176,7 +175,7 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
case HCAsm::Mode::b32: res.push(static_cast<std::uint32_t>(std::get<std::uint64_t>(instr.op1.variant))); break;
case HCAsm::Mode::b64: res.push(static_cast<std::uint64_t>(std::get<std::uint64_t>(instr.op1.variant))); break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
break;
case HyperCPU::OperandTypes::M_R:
Expand All @@ -186,6 +185,6 @@ void HCAsm::BinaryTransformer::EncodeInstruction(HCAsm::Instruction& instr) {
case HyperCPU::OperandTypes::NONE:
break;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
}
7 changes: 3 additions & 4 deletions src/Assembler/Core/BinaryTransformer.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include <utility>

#include <Emulator/Core/CPU/Instructions/Flags.hpp>
#include <Core/Compiler.hpp>
#include <Exit.hpp>

#include <mapbox/eternal.hpp>

Expand Down Expand Up @@ -68,7 +67,7 @@ namespace HCAsm {
case OperandTypes::NONE: return HyperCPU::OperandTypes::NONE;
default:
logger.Log(HyperCPU::LogLevel::ERROR, "Invalid operand types!");
std::abort();
EXIT(1);
}
}

Expand All @@ -79,7 +78,7 @@ namespace HCAsm {
case HCAsm::Mode::b32: return HyperCPU::Mode::b32;
case HCAsm::Mode::b64: return HyperCPU::Mode::b64;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
}

Expand Down
31 changes: 15 additions & 16 deletions src/Assembler/Core/Compiler.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "Emulator/Core/CPU/Instructions/Opcodes.hpp"
#include "pog/line_spec.h"
#include <string>
#include <fstream>
#include <utility>
#include <iostream>

#include <Emulator/Core/CPU/Instructions/Opcodes.hpp>
#include <Core/BinaryTransformer.hpp>
#include <Emulator/Misc/print.hpp>
#include <Core/Compiler.hpp>
#include <Logger/Logger.hpp>
#include <Emulator/Misc/print.hpp>
#include <Exit.hpp>

#include <pog/line_spec.h>
#include <pog/pog.h>


Expand Down Expand Up @@ -181,8 +181,7 @@ constexpr inline std::uint8_t HCAsm::HCAsmCompiler::OperandSize(HCAsm::OperandTy
case HCAsm::OperandType::uint:
case HCAsm::OperandType::label:
return 8;
default: std::abort();
//default: std::unreachable();
default: UNREACHABLE();
}
}

Expand All @@ -200,7 +199,7 @@ std::uint8_t HCAsm::HCAsmCompiler::ModeToSize(const Operand& op) {
case Mode::b64:
return 8;
default:
std::abort();
ABORT();
}
}

Expand All @@ -216,7 +215,7 @@ std::uint8_t HCAsm::HCAsmCompiler::ModeToSize(Mode md) {
case Mode::b64:
return 8;
default:
std::abort();
ABORT();
}
}

Expand Down Expand Up @@ -254,7 +253,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
result += 1;
break;
default:
std::abort();
ABORT();
}
break;
case OperandType::mem_reg_add_int:
Expand All @@ -279,7 +278,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
result += 10;
break;
default:
std::abort();
ABORT();
}
break;
case OperandType::sint:
Expand All @@ -301,7 +300,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
++result;
break;
default:
std::abort();
ABORT();
}
break;
case OperandType::label:
Expand All @@ -310,7 +309,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
case OperandType::none:
break;
default:
std::abort();
ABORT();
}

return result;
Expand Down Expand Up @@ -346,7 +345,7 @@ HCAsm::BinaryResult HCAsm::HCAsmCompiler::TransformToBinary(HCAsm::CompilerState
case Mode::b64:
return 8;
default:
std::abort();
ABORT();
}
}();
});
Expand Down Expand Up @@ -374,7 +373,7 @@ HCAsm::BinaryResult HCAsm::HCAsmCompiler::TransformToBinary(HCAsm::CompilerState
BinaryResult binary = { new unsigned char[ir.code_size] };
if (!binary.binary) {
logger.Log(LogLevel::ERROR, "Failed to allocate memory for binary data!");
std::abort();
ABORT();
}

logger.Log(LogLevel::DEBUG, "Running pass 3 - compiling");
Expand Down Expand Up @@ -409,7 +408,7 @@ HCAsm::BinaryResult HCAsm::HCAsmCompiler::TransformToBinary(HCAsm::CompilerState
case Mode::b64:
binary.push(static_cast<std::uint64_t>(std::get<std::uint64_t>(raw.value.variant)));
break;
default: std::abort();
default: ABORT();
}
},
[](Label&){});
Expand Down Expand Up @@ -451,7 +450,7 @@ std::string_view HCAsm::FindLine(const pog::LineSpecialization& line_spec, const
"", std::to_string(err_token.line_spec.line).length(),
"", err_token.line_spec.offset,
std::string(err_token.line_spec.length, '^'));
std::exit(1);
EXIT(1);
}

void HCAsm::WriteResultFile(HyperCPU::FileType type, HCAsm::BinaryResult& result, std::ofstream& output, std::uint32_t code_size, std::uint32_t entry_point) {
Expand Down
7 changes: 4 additions & 3 deletions src/Assembler/Core/Compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
#include <queue>

#include <Emulator/Core/CPU/Instructions/Registers.hpp>
#include <Emulator/Core/CPU/Instructions/Flags.hpp>
#include <Emulator/Core/CPU/Instructions/Opcodes.hpp>
#include <Emulator/Core/CPU/Instructions/Flags.hpp>
#include <Emulator/Misc/unreachable.hpp>
#include <Emulator/Main/Main.hpp>
#include <Logger/Logger.hpp>
#include <Exit.hpp>

#include <pog/parser.h>
#include <pog/line_spec.h>
#include <pog/parser.h>

#include <hpool.hpp>

Expand Down Expand Up @@ -189,7 +190,7 @@ namespace HCAsm {
case Registers::XLLL3:
return Mode::b8;
default:
unreachable();
UNREACHABLE();
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/Assembler/Main/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <filesystem>
#include <fstream>

#include <Assembler/Core/Compiler.hpp>
#include <Logger/Logger.hpp>
#include <Logger/Colors.hpp>
#include <Assembler/Utils/Extension.hpp>
#include <Assembler/Core/Compiler.hpp>
#include <Emulator/Main/Main.hpp>
#include <NotImplemented.hpp>
#include <Logger/Logger.hpp>
#include <Logger/Colors.hpp>
#include <Exit.hpp>

#include <argparse/argparse.hpp>

Expand Down Expand Up @@ -40,7 +41,7 @@ int main(int argc, char** argv) {
program.parse_args(argc, argv);
} catch (const std::exception& err) {
std::cerr << err.what() << '\n';
std::exit(1);
EXIT(1);
}

auto source = program.get<std::string>("source");
Expand All @@ -63,14 +64,14 @@ int main(int argc, char** argv) {
// Verify that files are available
if (!std::filesystem::is_regular_file(source)) {
HCAsm::logger.Log(HyperCPU::LogLevel::ERROR, "Source file \"{}\" is not a regular file!", source);
std::exit(1);
EXIT(1);
}

std::ifstream src(source);
std::ofstream dst(result, std::ios::binary | std::ios::ate);
if (!src.is_open()) {
HCAsm::logger.Log(HyperCPU::LogLevel::ERROR, "Failed to open source file!");
std::exit(1);
EXIT(1);
}

HCAsm::logger.Log(HyperCPU::LogLevel::DEBUG, "Source and destination files handles acquired");
Expand Down
4 changes: 4 additions & 0 deletions src/Emulator/Core/CPU/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,7 @@ bool HyperCPU::CPU::CanExecuteInterrupts() {
void HyperCPU::CPU::SetEntryPoint(std::uint32_t entry_point) {
*xip = entry_point;
}

const HyperCPU::Logger& HyperCPU::CPU::GetLogger() const noexcept {
return logger;
}
6 changes: 3 additions & 3 deletions src/Emulator/Core/CPU/CPU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <Core/CPU/Decoders/StdDecoder.hpp>
#include <Core/CPU/IO/Simple.hpp>


#define DECLARE_INSTR(name) void Exec##name(const IInstruction& instr, void* op1, void* op2)

namespace HyperCPU {
Expand All @@ -34,7 +33,7 @@ namespace HyperCPU {
std::unique_ptr<Decoder> m_decoder;

// Data
HyperCPU::Logger logger;
const HyperCPU::Logger logger;
std::size_t core_count;
std::size_t total_mem;
bool halted;
Expand Down Expand Up @@ -126,12 +125,13 @@ namespace HyperCPU {
std::unique_ptr<SimpleIOImpl> io_ctl;

public:
explicit CPU(std::size_t core_count, std::size_t mem_size, char* binary = nullptr, std::uint64_t binary_size = 0);
CPU(std::size_t core_count, std::size_t mem_size, char* binary = nullptr, std::uint64_t binary_size = 0);

void Run();

bool CanExecuteInterrupts();
void SetEntryPoint(std::uint32_t entry_point);
const HyperCPU::Logger& GetLogger() const noexcept;

~CPU();
};
Expand Down
10 changes: 5 additions & 5 deletions src/Emulator/Core/CPU/Decoders/StdDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <Core/CPU/Instructions/AllowedFlags.hpp>
#include <Core/CPU/Instructions/Registers.hpp>
#include <Core/CPU/Instructions/Opcodes.hpp>
#include <Core/CPU/Decoders/StdDecoder.hpp>
#include <Core/CPU/Instructions/Flags.hpp>
#include <Core/CPU/Decoders/IDecoder.hpp>
#include <Core/CPU/Decoders/StdDecoder.hpp>
#include <Misc/unreachable.hpp>
#include <Core/CPU/Assert.hpp>
#include <Core/CPU/CPU.hpp>
#include <Misc/unreachable.hpp>
#include <utility>
#include <Exit.hpp>


#define dcdr_assert(expr) RaiseException((expr)); if (cpu && cpu->pending_interrupt.has_value()) return {.m_opcode = _CONT, .m_opcode_mode = b64, .m_op_types = NONE, .m_op1 = 0, .m_op2 = 0, .addr_extension_status = HyperCPU::AddrExtensionStatus::Disabled, .extension = 0}
Expand All @@ -20,7 +20,7 @@ void HyperCPU::Decoder::RaiseException(bool expr) noexcept {
if (!(expr)) {
if (cpu == nullptr) {
std::cerr << "Invalid opcode!\n";
std::exit(1);
EXIT(1);
} else {
cpu->TriggerInterrupt(HyperCPU::cpu_exceptions::IO);
}
Expand All @@ -38,7 +38,7 @@ bool HyperCPU::Decoder::CheckSupportedOperandSize(std::uint8_t byte, Mode mode)
case b64:
return byte & 0b00000011;
default:
HyperCPU::unreachable();
UNREACHABLE();
}
}

Expand Down
Loading