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
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build x86 emulator

on: [push,pull_request]

jobs:
build1:
name: Build x86 emulator on Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: libsdl-org/setup-sdl@main
id: sdl
with:
install-linux-dependencies: true
version: 2.30.9
- name: Generate build system
run: cmake .
- name: Build
run: cmake --build .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.DS_Store
.vscode
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.26.0)

find_package(SDL2 CONFIG REQUIRED)

project(X86_EMULATOR)

file(GLOB SOURCES src/*.cpp)

add_executable(x86
${SOURCES}
)

target_link_libraries(x86 ${SDL2_LIBRARIES})
target_include_directories(x86 PUBLIC
${SDL2_INCLUDE_DIRS}
)
target_include_directories(x86 PRIVATE include SDL2)
52 changes: 0 additions & 52 deletions Makefile

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@

<h2>Build</h2>

```
make
```bash
mkdir build
cmake ..
cmake --build .
```

<h2>Run</h2>
Expand Down
8 changes: 4 additions & 4 deletions include/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class DescriptorTableRegister;
#define DPL 0x60 // access_rightのDPLの該当部分

namespace CpuHelper {
inline template <typename type>
uint8_t GetDpl(type data) {
template <typename type>
inline uint8_t GetDpl(type data) {
return (data & DPL) >> 5;
}

inline template <typename type>
uint8_t GetRpl(type data) {
template <typename type>
inline uint8_t GetRpl(type data) {
return data & 0x03;
}
} // namespace CpuHelper
Expand Down
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <functional>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
Expand Down
64 changes: 32 additions & 32 deletions include/detail/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ type Cpu::Inc(type data) {
return data + 1;
}

inline template <typename type>
void Cpu::UpdateEflagsForInc(type d) {
template <typename type>
inline void Cpu::UpdateEflagsForInc(type d) {
type result = (type)(d + 1);
this->UpdateZF(result);
this->UpdateSF(result);
Expand All @@ -112,8 +112,8 @@ type Cpu::Dec(type data) {
return result;
}

inline template <typename type>
void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
template <typename type>
inline void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
this->UpdateZF(result);
this->UpdateSF(result);
this->UpdatePF(result);
Expand All @@ -134,46 +134,46 @@ void Cpu::UpdateEflagsForDec(type result, type d1, type d2) {
}
}

inline template <typename type>
type Cpu::Adc(type data1, type data2) {
template <typename type>
inline type Cpu::Adc(type data1, type data2) {
type carry = this->IsFlag(CF) ? 1 : 0;
this->UpdateEflagsForAdc(data1, data2, carry);
return data1 + data2 + carry;
}

inline template <typename type>
type Cpu::Xor(type data1, type data2) {
template <typename type>
inline type Cpu::Xor(type data1, type data2) {
type result = data1 ^ data2;
this->UpdateEflagsForAnd(result);
return result;
}

inline template <typename type>
type Cpu::Or(type data1, type data2) {
template <typename type>
inline type Cpu::Or(type data1, type data2) {
this->UpdateEflagsForAnd((type)(data1 | data2));
return data1 | data2;
}

inline template <typename type>
type Cpu::And(type data1, type data2) {
template <typename type>
inline type Cpu::And(type data1, type data2) {
this->UpdateEflagsForAnd((type)(data1 & data2));
return data1 & data2;
}

inline template <typename type>
type Cpu::Add(type data1, type data2) {
template <typename type>
inline type Cpu::Add(type data1, type data2) {
this->UpdateEflagsForAdd(data1, data2);
return data1 + data2;
}

inline template <typename type>
type Cpu::Sub(type data1, type data2) {
template <typename type>
inline type Cpu::Sub(type data1, type data2) {
this->UpdateEflagsForSub(data1, data2);
return data1 - data2;
}

inline template <typename type>
void Cpu::UpdateEflagsForSub(type data1, type data2) {
template <typename type>
inline void Cpu::UpdateEflagsForSub(type data1, type data2) {
this->UpdateZF((type)(data1 - data2));
this->UpdatePF(data1 - data2);
this->UpdateSF((type)(data1 - data2));
Expand Down Expand Up @@ -245,8 +245,8 @@ void Cpu::UpdateEflagsForAdc(type d1, type d2, type c) {
}
}

inline template <typename type>
void Cpu::UpdateEflagsForAdd(type d1, type d2) {
template <typename type>
inline void Cpu::UpdateEflagsForAdd(type d1, type d2) {
this->UpdateZF((type)(d1 + d2));
this->UpdateSF((type)(d1 + d2));
this->UpdatePF((type)(d1 + d2));
Expand Down Expand Up @@ -561,15 +561,15 @@ void Cpu::Scas(type data) {
}
}

inline template <typename type>
void Cpu::UpdateEflagsForShr(type result) {
template <typename type>
inline void Cpu::UpdateEflagsForShr(type result) {
this->UpdateZF((uint32_t)result);
this->UpdateSF(result);
this->UpdatePF((uint32_t)result);
}

inline template <typename type>
void Cpu::UpdateOF_Add(type result, type d1, type d2) {
template <typename type>
inline void Cpu::UpdateOF_Add(type result, type d1, type d2) {
switch (sizeof(result)) {
case 1:
this->eflags.flgs.OF = ((d1 & SIGN_FLG1) == (d2 & SIGN_FLG1)) &&
Expand All @@ -589,8 +589,8 @@ void Cpu::UpdateOF_Add(type result, type d1, type d2) {
}
}

inline template <typename type>
void Cpu::UpdateCfForSub(type data, int group) {
template <typename type>
inline void Cpu::UpdateCfForSub(type data, int group) {
switch (group) {
case 1:
this->eflags.flgs.CF = ((data >> 8) & 1) ? 1 : 0;
Expand All @@ -608,8 +608,8 @@ void Cpu::UpdateCfForSub(type data, int group) {
}
}

inline template <typename type>
void Cpu::UpdateSF(type data) {
template <typename type>
inline void Cpu::UpdateSF(type data) {
switch (sizeof(data)) {
case 1:
this->eflags.flgs.SF = ((data & SIGN_FLG1) == SIGN_FLG1) ? 1 : 0;
Expand All @@ -627,17 +627,17 @@ void Cpu::UpdateSF(type data) {
}
}

inline template <typename type>
void Cpu::UpdateEflagsForAnd(type data) {
template <typename type>
inline void Cpu::UpdateEflagsForAnd(type data) {
this->ClearFlag(CF);
this->ClearFlag(OF);
this->UpdateSF(data);
this->UpdateZF(data);
this->UpdatePF(data);
}

inline template <typename type>
void Cpu::UpdateEflagsForUnsignedMul(type data) {
template <typename type>
inline void Cpu::UpdateEflagsForUnsignedMul(type data) {
if (data == 0) {
this->ClearFlag(OF);
this->ClearFlag(CF);
Expand Down
16 changes: 8 additions & 8 deletions include/detail/Fifo.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "../Fifo.h"

inline template <typename type>
bool Fifo<type>::IsEmpty() {
template <typename type>
inline bool Fifo<type>::IsEmpty() {
std::lock_guard<std::mutex> lock(this->fifo_mtx);
return this->q.empty();
}

inline template <typename type>
type Fifo<type>::Pop() {
template <typename type>
inline type Fifo<type>::Pop() {
type element;
if (this->IsEmpty()) {
return element;
Expand All @@ -18,8 +18,8 @@ type Fifo<type>::Pop() {
return element;
}

inline template <typename type>
void Fifo<type>::Push(const type data) {
template <typename type>
inline void Fifo<type>::Push(const type data) {
std::lock_guard<std::mutex> lock(this->fifo_mtx);
if (this->q.size() == 16) {
return;
Expand All @@ -28,8 +28,8 @@ void Fifo<type>::Push(const type data) {
return;
}

inline template <typename type>
type Fifo<type>::Front() { //読み込むだけ
template <typename type>
inline type Fifo<type>::Front() { //読み込むだけ
type element;
if (this->IsEmpty()) {
return element;
Expand Down
4 changes: 2 additions & 2 deletions include/detail/Memory.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../Memory.h"

inline template <typename type>
void Memory::Write(const uint32_t addr, const type data) {
template <typename type>
inline void Memory::Write(const uint32_t addr, const type data) {
if ((mem_size_ - sizeof(data) + 1) <= addr) {
return;
}
Expand Down