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
4 changes: 2 additions & 2 deletions .github/workflows/distro-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
set -e
DISTRO=$( cat /etc/*-release | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|fedora|gentoo|alpine)' | uniq )
if [ "$DISTRO" == "gentoo" ]; then source /etc/profile; fi
git clone https://github.com/HyperWinX/HyperCPU.git && cd HyperCPU
git switch "${{ github.head_ref }}"
git clone https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git && cd HyperCPU
git checkout ${{ github.event.pull_request.head.sha }}
git submodule update --init --recursive
cd dist/pog && git pull origin master && cd ../..
cmake -S. -Bbuild -DHCPU_COMPILER=clang -DHCPU_LTO=ON -DHCPU_SANITIZERS=OFF -DCMAKE_BUILD_TYPE=Release
Expand Down
12 changes: 5 additions & 7 deletions src/Assembler/Core/Compiler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <string>
#include <fstream>
#include <utility>
#include <pch.hpp>

#include <Emulator/Core/CPU/Instructions/Opcodes.hpp>
#include <Core/BinaryTransformer.hpp>
Expand Down Expand Up @@ -70,7 +68,7 @@ HCAsm::HCAsmCompiler::HCAsmCompiler(LogLevel lvl) : pool(32) {
parser.token("\\.b64")
.fullword()
.symbol(".b64");

parser.token("[a-zA-Z_][a-zA-Z0-9_]*")
.symbol("ident")
.action(TokenizeIdentifier);
Expand Down Expand Up @@ -164,7 +162,7 @@ HCAsm::CompilerState HCAsm::HCAsmCompiler::TransformToIR(std::string& src) {
parser.prepare();
logger.Log(LogLevel::DEBUG, "Parser prepared.");
logger.Log(LogLevel::DEBUG, "Compiling...");

parser.parse(src);
current_state = nullptr;
return state;
Expand Down Expand Up @@ -226,7 +224,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
default:
break;
}

std::uint8_t result = 3; // Opcode is always two bytes long + one byte for operand types
switch (instr.op1.type) {
case OperandType::reg: // R_*
Expand Down Expand Up @@ -318,7 +316,7 @@ std::uint8_t HCAsm::HCAsmCompiler::InstructionSize(HCAsm::Instruction& instr) {
HCAsm::BinaryResult HCAsm::HCAsmCompiler::TransformToBinary(HCAsm::CompilerState& ir) {
// Count code size - pass 1
logger.Log(LogLevel::DEBUG, "Running pass 1 - counting code size");

for (auto& instr : ir.ir) {
VisitVariant(instr,
[this, &ir](Instruction& instruction) mutable -> void {
Expand Down
12 changes: 4 additions & 8 deletions src/Assembler/Core/Compiler.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#pragma once

#include <type_traits>
#include <utility>
#include <string>
#include <vector>
#include <queue>
#include <pch.hpp>

#include <Emulator/Core/CPU/Instructions/Registers.hpp>
#include <Emulator/Core/CPU/Instructions/Opcodes.hpp>
Expand Down Expand Up @@ -75,7 +71,7 @@ namespace HCAsm {
struct Value {
std::variant<std::int64_t, std::uint64_t, std::string, Operand, Instruction> val;
};

struct Label {
std::string name;
std::uint64_t index;
Expand All @@ -98,7 +94,7 @@ namespace HCAsm {
std::memcpy(binary + ptr, &data, sizeof(data));
ptr += sizeof(data);
}

inline void push(const std::string& data) {
std::memcpy(binary + ptr, data.data(), data.length());
ptr += data.length();
Expand Down Expand Up @@ -254,5 +250,5 @@ namespace HCAsm {
std::uint8_t ModeToSize(const Operand& op);
std::uint8_t ModeToSize(Mode md);
};

}
5 changes: 2 additions & 3 deletions src/Assembler/Core/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <Core/Compiler.hpp>

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

using HCAsm::Value;

Expand Down Expand Up @@ -262,7 +261,7 @@ Value HCAsm::ParseOperand11(pog::Parser<Value>& parser, std::vector<pog::TokenWi
parser,
fmt::format("unknown data size specified: \"{}\"", mode));
}

return {
.val = Operand {
.type = HCAsm::OperandType::sint,
Expand Down Expand Up @@ -297,7 +296,7 @@ Value HCAsm::ParseOperand12(pog::Parser<Value>& parser, std::vector<pog::TokenWi
}
};
}

return {
.val = Operand {
.type = HCAsm::OperandType::reg,
Expand Down
5 changes: 0 additions & 5 deletions src/Assembler/Core/Tokenizers.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include <iostream>
#include <iomanip>
#include <sstream>

#include <Core/Compiler.hpp>


using HCAsm::Value;

[[gnu::visibility("hidden")]]
Expand Down
4 changes: 1 addition & 3 deletions src/Assembler/Main/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <csignal>
#include <filesystem>
#include <fstream>
#include <pch.hpp>

#include <Assembler/Utils/Extension.hpp>
#include <Assembler/Core/Compiler.hpp>
Expand Down
4 changes: 2 additions & 2 deletions src/Assembler/Utils/Extension.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <string>
#include <pch.hpp>

namespace HCAsm {
std::string CreateObjectFilename(std::string str);
}
}
10 changes: 1 addition & 9 deletions src/BacktraceProvider/BacktraceProvider.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#ifdef HCPU_ENABLE_LIBUNWIND

#include <memory>

#include <csignal>
#include <cstdlib>
#include <cstdio>
#include <cxxabi.h>

#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <backtrace.h>

#include <fmt/printf.h>
#include <fmt/base.h>

#include <BacktraceProvider/BacktraceProvider.hpp>
Expand Down Expand Up @@ -115,4 +107,4 @@ bool BacktraceController::HasFinished() {
return finished;
}

#endif
#endif
4 changes: 2 additions & 2 deletions src/BacktraceProvider/BacktraceProvider.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef HCPU_ENABLE_LIBUNWIND
#include <string_view>
#include <pch.hpp>

#include <backtrace.h>
#include <libunwind.h>
Expand Down Expand Up @@ -37,4 +37,4 @@ extern std::string_view catched_signal_type;

extern "C" void SignalHandler(int);

#endif
#endif
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ ExternalProject_Add(
add_library(emulator-core STATIC ${SOURCES_emulator-core})
target_include_directories(emulator-core PUBLIC ${GENERIC_INCLUDE_DIR} ${ROOT_DIR}/src/Emulator)
target_link_libraries(emulator-core ${LD_FLAGS} fmt)
target_precompile_headers(emulator-core PRIVATE pch.hpp)

add_library(assembler-core STATIC ${SOURCES_assembler-core})
target_include_directories(assembler-core PUBLIC ${GENERIC_INCLUDE_DIR} ${ROOT_DIR}/src/Assembler)
target_link_libraries(assembler-core pog)
target_precompile_headers(assembler-core PRIVATE pch.hpp)

add_library(backtrace-provider STATIC ${SOURCES_backtrace-provider})
target_include_directories(backtrace-provider PUBLIC ${GENERIC_INCLUDE_DIR})
add_dependencies(backtrace-provider libbacktrace)
target_precompile_headers(backtrace-provider PRIVATE pch.hpp)

add_executable(hcasm ${SOURCES_assembler-main})
target_include_directories(hcasm PUBLIC ${GENERIC_INCLUDE_DIR} ${ROOT_DIR}/src/Assembler)
target_link_libraries(hcasm assembler-core pog)
target_precompile_headers(hcasm PRIVATE pch.hpp)

add_executable(hcemul ${SOURCES_emulator-main})
target_include_directories(hcemul PUBLIC ${GENERIC_INCLUDE_DIR} ${ROOT_DIR}/src/Emulator)
target_link_libraries(hcemul emulator-core assembler-core)
target_precompile_headers(hcemul PRIVATE pch.hpp)

if (LIBUNWIND)
target_link_libraries(hcasm backtrace-provider -L${ROOT_DIR}/dist/libbacktrace backtrace)
Expand Down
7 changes: 2 additions & 5 deletions src/Emulator/Core/CPU/ALU.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once

#include <cstring>
#include <cstdint>

#include <type_traits>
#include <pch.hpp>

#define _MICROOP [[gnu::always_inline]] static constexpr inline

Expand Down Expand Up @@ -63,4 +60,4 @@ namespace HyperCPU{
// Simplify switching implementations
namespace HyperALU {
using namespace HyperCPU::StdALU;
}
}
2 changes: 1 addition & 1 deletion src/Emulator/Core/CPU/Assert.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <iostream>
#include <pch.hpp>


#define h_assert(expr, statement) if (!(expr)) { statement; }
4 changes: 2 additions & 2 deletions src/Emulator/Core/CPU/CPU.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Logger/Logger.hpp"
#include <functional>
#include <pch.hpp>

#include <Core/MemoryController/MemoryControllerST.hpp>
#include <Core/CPU/Decoders/IDecoder.hpp>
Expand Down Expand Up @@ -281,4 +281,4 @@ void HyperCPU::CPU::SetEntryPoint(std::uint32_t entry_point) {

const HyperCPU::Logger& HyperCPU::CPU::GetLogger() const noexcept {
return logger;
}
}
7 changes: 1 addition & 6 deletions src/Emulator/Core/CPU/CPU.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#pragma once

#include "Logger/Logger.hpp"
#include <cstddef>

#include <functional>
#include <optional>
#include <memory>
#include <atomic>
#include <pch.hpp>

#include <Core/MemoryController/IMemoryController.hpp>
#include <Core/CPU/Interrupts/ReservedInterrupts.hpp>
Expand Down
3 changes: 1 addition & 2 deletions src/Emulator/Core/CPU/Decoders/StdDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <cassert>
#include <cstring>
#include <pch.hpp>

#include <Core/CPU/Interrupts/ReservedInterrupts.hpp>
#include <Core/CPU/Instructions/AllowedFlags.hpp>
Expand Down
6 changes: 2 additions & 4 deletions src/Emulator/Core/CPU/IO/Simple.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <pch.hpp>

#include <termios.h>
#include <unistd.h>
Expand Down Expand Up @@ -75,4 +73,4 @@ void HyperCPU::SimpleIOImpl::EnablePrinting() {
newt.c_lflag |= ECHO;
newt.c_lflag |= ECHONL;
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
}
}
3 changes: 1 addition & 2 deletions src/Emulator/Core/CPU/IO/Simple.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <functional>
#include <cstdint>
#include <pch.hpp>

#include <termios.h>
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion src/Emulator/Core/CPU/Instructions/AllowedFlags.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cstdint>
#include <pch.hpp>

#include <Core/CPU/Instructions/AllowedFlags.hpp>

Expand Down
4 changes: 2 additions & 2 deletions src/Emulator/Core/CPU/Instructions/AllowedFlags.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#include <cstdint>
#include <pch.hpp>


namespace HyperCPU {
static constexpr std::uint8_t SUPPORT_ALL = 0b00011011;

extern const std::uint8_t allowed_op_modes[128][12];
}
}
4 changes: 2 additions & 2 deletions src/Emulator/Core/CPU/Instructions/Flags.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstdint>
#include <pch.hpp>


namespace HyperCPU {
Expand All @@ -27,4 +27,4 @@ namespace HyperCPU {
};

static constexpr std::uint_fast8_t MAX_OPERAND_TYPE = NONE;
}
}
2 changes: 1 addition & 1 deletion src/Emulator/Core/CPU/Instructions/Opcodes.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstdint>
#include <pch.hpp>


#define OPCODE_CASE(opcode) case static_cast<std::uint16_t>(opcode):
Expand Down
4 changes: 2 additions & 2 deletions src/Emulator/Core/CPU/Instructions/Registers.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <cstdint>
#include <pch.hpp>


#define REGISTER_CASE(reg) case static_cast<std::uint8_t>(reg):
Expand Down Expand Up @@ -68,4 +68,4 @@ namespace HyperCPU {
}
}
}
}
}
2 changes: 0 additions & 2 deletions src/Emulator/Core/CPU/InstructionsImpl/ADC.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <cstdint>

#include <Core/CPU/CPU.hpp>
#include <Core/CPU/ALU.hpp>

Expand Down
2 changes: 0 additions & 2 deletions src/Emulator/Core/CPU/Interrupts/InterruptHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <optional>

#include <Core/CPU/Interrupts/ReservedInterrupts.hpp>
#include <Core/CPU/Instructions/Opcodes.hpp>
#include <Assembler/Core/Compiler.hpp>
Expand Down
2 changes: 0 additions & 2 deletions src/Emulator/Core/CPU/OperandsEvaluation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <cstring>

#include <Core/CPU/Instructions/Registers.hpp>
#include <Misc/bit_cast.hpp>
#include <Core/CPU/CPU.hpp>
Expand Down
4 changes: 1 addition & 3 deletions src/Emulator/Core/MemoryController/IMemoryController.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <pch.hpp>

#include <Misc/print.hpp>

Expand Down
7 changes: 0 additions & 7 deletions src/Emulator/Core/MemoryController/MemoryControllerST.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#pragma once

#include <cstddef>
#include <cassert>
#include <cstdlib>
#include <cstring>

#include <stdexcept>

#include <Core/CPU/CPU.hpp>
#include <Core/CPU/Interrupts/ReservedInterrupts.hpp>
#include <Core/MemoryController/IMemoryController.hpp>
Expand Down
Loading