Skip to content

Commit

Permalink
Merge pull request #39 from CT56567/main
Browse files Browse the repository at this point in the history
Add more CPU Instruction.
  • Loading branch information
Cherrytree56567 authored Oct 18, 2023
2 parents 7ee21bc + def65b6 commit 38c618d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: MSBuild

on:
Expand All @@ -7,7 +12,12 @@ on:
branches: [ "main" ]

env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: .

# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Release

permissions:
Expand All @@ -27,17 +37,8 @@ jobs:
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Initialize Sub-modules
run: |
git submodule init
git submodule update
- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Run PSEMU
shell: cmd
- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
cd x64/Release/
PSEMU.exe
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
12 changes: 9 additions & 3 deletions PSEMU/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ void CPU::fetch() {

Next_Instr.instruction = bus->load32(pc);

pc += 4;
current_pc = pc;
pc += next_pc;
next_pc += 4;

set_reg(std::get<0>(load), std::get<1>(load));

Expand Down Expand Up @@ -563,7 +565,11 @@ void CPU::op_mfc0(Instruction instruction) {
v = sr;
break;
case 13:
throw std::runtime_error("[CPU] ERROR: Unhandled read from CAUSE register");
v = cause;
break;
case 14:
v = epc;
break;
default:
throw std::runtime_error("[CPU] ERROR: Unhandled read from COP0R" + std::to_string(cop_r));
}
Expand Down Expand Up @@ -801,4 +807,4 @@ void CPU::op_slt(Instruction instruction) {
uint32_t v = s < t;

set_reg(d, v);
}
}
13 changes: 13 additions & 0 deletions PSEMU/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <tuple>
#include "Instruction.h"

enum Exception {
SysCall = 0x8
};

class CPU {
public:
CPU(Bus* bu) : bus(bu) {
Expand All @@ -19,6 +23,9 @@ class CPU {
sr = 0;
hi = 0;
lo = 0;
cause = 0;
epc = 0;
next_pc = pc + 4;
}

// CPU FUNCTIONS
Expand Down Expand Up @@ -70,6 +77,8 @@ class CPU {
void op_mfhi(Instruction instruction);
void op_slt(Instruction instruction);

void exception(Exception cause);

// HELPER FUNCTIONS
void set_reg(uint32_t index, uint32_t value) {
out_regs[index] = value;
Expand All @@ -79,6 +88,10 @@ class CPU {

Bus* bus;
uint32_t pc;
uint32_t next_pc;
uint32_t current_pc;
uint32_t cause;
uint32_t epc;
uint32_t regs[32];
uint32_t hi;
uint32_t lo;
Expand Down

0 comments on commit 38c618d

Please sign in to comment.