Compare commits

..
70 changed files with 1745 additions and 4672 deletions

No files matched your search

-43
View File
@@ -1,43 +0,0 @@
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install_dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install libsdl2-dev
- name: init_submodules
run: git submodule update --init --recursive
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DDPPC_68K_DEBUGGER=ON
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
+7 -8
View File
@@ -56,10 +56,10 @@ if (DPPC_68K_DEBUGGER)
add_subdirectory(thirdparty/capstone EXCLUDE_FROM_ALL)
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/core")
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
add_subdirectory("${PROJECT_SOURCE_DIR}/execution")
add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
@@ -80,7 +80,6 @@ add_subdirectory(thirdparty/cubeb EXCLUDE_FROM_ALL)
set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/core"
"${PROJECT_SOURCE_DIR}/devices"
"${PROJECT_SOURCE_DIR}/cpu/ppc"
"${PROJECT_SOURCE_DIR}/debugger"
@@ -101,10 +100,10 @@ file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:execution>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
@@ -124,10 +123,10 @@ if (DPPC_68K_DEBUGGER)
endif()
if (DPPC_BUILD_PPC_TESTS)
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:core>
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:execution>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
@@ -150,10 +149,10 @@ endif()
if (DPPC_BUILD_BENCHMARKS)
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:cpu_ppc>
$<TARGET_OBJECTS:debugger>
$<TARGET_OBJECTS:devices>
$<TARGET_OBJECTS:execution>
$<TARGET_OBJECTS:machines>
$<TARGET_OBJECTS:utils>
$<TARGET_OBJECTS:loguru>)
-8
View File
@@ -1,8 +0,0 @@
include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
)
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(core OBJECT ${SOURCES})
target_link_libraries(core)
-139
View File
@@ -1,139 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** Timer management system. */
#include <loguru.hpp>
#include "timermanager.h"
#include <cinttypes>
#include <memory>
TimerManager* TimerManager::timer_manager;
uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
{
if (!timeout || timeout <= MIN_TIMEOUT_NS) {
LOG_F(WARNING, "One-shot timer too short, timeout=%llu ns", timeout);
}
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + timeout;
ti->interval_ns = 0;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
{
if (!interval || interval <= MIN_TIMEOUT_NS) {
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", interval);
}
TimerInfo* ti = new TimerInfo;
ti->id = ++this->id;
ti->timeout_ns = this->get_time_now() + interval;
ti->interval_ns = interval;
ti->cb = cb;
std::shared_ptr<TimerInfo> timer_desc(ti);
// add new timer to the timer queue
this->timer_queue.push(timer_desc);
// notify listeners about changes in the timer queue
if (!this->cb_active) {
this->notify_timer_changes();
}
return ti->id;
}
void TimerManager::cancel_timer(uint32_t id)
{
TimerInfo* cur_timer = this->timer_queue.top().get();
if (cur_timer->id == id) {
this->timer_queue.pop();
} else {
this->timer_queue.remove_by_id(id);
}
if (!this->cb_active) {
this->notify_timer_changes();
}
}
uint64_t TimerManager::process_timers(uint64_t time_now)
{
TimerInfo* cur_timer;
if (this->timer_queue.empty()) {
return 0ULL;
}
// scan for expired timers
cur_timer = this->timer_queue.top().get();
while (cur_timer->timeout_ns <= time_now ||
cur_timer->timeout_ns <= (time_now + MIN_TIMEOUT_NS)) {
timer_cb cb = cur_timer->cb;
// re-arm cyclic timers
if (cur_timer->interval_ns) {
auto new_timer = this->timer_queue.top();
new_timer->timeout_ns = time_now + cur_timer->interval_ns;
this->timer_queue.pop();
this->timer_queue.push(new_timer);
} else {
// remove one-shot timers from queue
this->timer_queue.pop();
}
this->cb_active = true;
// invoke timer callback
cb();
this->cb_active = false;
// process next timer
if (this->timer_queue.empty()) {
return 0ULL;
}
cur_timer = this->timer_queue.top().get();
}
// return time slice in nanoseconds until next timer's expiry
return cur_timer->timeout_ns - time_now;
}
-120
View File
@@ -1,120 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TIMER_MANAGER_H
#define TIMER_MANAGER_H
#include <algorithm>
#include <cinttypes>
#include <functional>
#include <memory>
#include <queue>
#include <vector>
using namespace std;
#define MIN_TIMEOUT_NS 200
#define NS_PER_SEC 1E9
#define USECS_TO_NSECS(us) (us) * 1000
typedef function<void()> timer_cb;
/** Extend std::priority_queue as suggested here:
https://stackoverflow.com/a/36711682
to be able to remove arbitrary elements.
*/
template <typename T, class Container = std::vector<T>, class Compare = std::less<typename Container::value_type>>
class my_priority_queue : public std::priority_queue<T, Container, Compare> {
public:
bool remove_by_id(const uint32_t id){
auto it = std::find_if(
this->c.begin(), this->c.end(), [id](const T& el) { return el->id == id; });
if (it != this->c.end()) {
this->c.erase(it);
std::make_heap(this->c.begin(), this->c.end(), this->comp);
return true;
} else {
return false;
}
};
};
typedef struct TimerInfo {
uint32_t id;
uint64_t timeout_ns; // timer expiry
uint64_t interval_ns; // 0 for one-shot timers
timer_cb cb; // timer callback
} TimerInfo;
// Custom comparator for sorting our timer queue in ascending order
class MyGtComparator {
public:
bool operator()(const shared_ptr<TimerInfo>& l, const shared_ptr<TimerInfo>& r) {
return l.get()->timeout_ns > r.get()->timeout_ns;
}
};
class TimerManager {
public:
static TimerManager* get_instance() {
if (!timer_manager) {
timer_manager = new TimerManager();
}
return timer_manager;
};
// callback for retrieving current time
void set_time_now_cb(const function<uint64_t()> &cb) {
this->get_time_now = cb;
};
// callback for acknowledging time changes
void set_notify_changes_cb(const timer_cb &cb) {
this->notify_timer_changes = cb;
};
// return current virtual time in nanoseconds
uint64_t current_time_ns() { return get_time_now(); };
// creating and cancelling timers
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
void cancel_timer(uint32_t id);
uint64_t process_timers(uint64_t time_now);
private:
static TimerManager* timer_manager;
TimerManager(){}; // private constructor to implement a singleton
// timer queue
my_priority_queue<shared_ptr<TimerInfo>, vector<shared_ptr<TimerInfo>>, MyGtComparator> timer_queue;
function<uint64_t()> get_time_now;
function<void()> notify_timer_changes;
uint32_t id = 0;
bool cb_active = false; // true if a timer callback is executing
};
#endif // TIMER_MANAGER_H
+20 -24
View File
@@ -148,12 +148,8 @@ SUPERVISOR MODEL
536 - 543 are the Data BAT registers
**/
extern uint32_t opcode_value; // used for interpreting opcodes
extern uint64_t timebase_counter;
extern uint64_t tbr_wr_timestamp;
extern uint64_t tbr_wr_value;
extern uint64_t tbr_freq_hz;
extern uint32_t opcode_value; // used for interpreting opcodes
extern uint64_t timebase_counter; // used for storing time base value
// Additional steps to prevent overflow?
extern int32_t add_result;
@@ -196,12 +192,13 @@ extern uint64_t ppc_result64_b;
extern uint64_t ppc_result64_c;
extern uint64_t ppc_result64_d;
/* Flags for controlling interpreter execution. */
enum {
EXEF_BRANCH = 1 << 0,
EXEF_EXCEPTION = 1 << 1,
EXEF_RFI = 1 << 2,
EXEF_TIMER = 1 << 7
/* The precise end of a basic block. */
enum class BB_end_kind {
BB_NONE = 0, /* no basic block end is reached */
BB_BRANCH = 1, /* a branch instruction is encountered */
BB_EXCEPTION, /* an exception is occured */
BB_RFI /* the rfi instruction is encountered */
};
enum CR_select : int32_t {
@@ -209,9 +206,9 @@ enum CR_select : int32_t {
CR1_field = (0xF << 24),
};
enum CRx_bit : uint32_t {
CR_SO = 28,
CR_EQ = 29,
enum CRx_bit : uint32_t {
CR_SO = 28,
CR_EQ = 29,
CR_GT = 30,
CR_LT = 31 };
@@ -291,10 +288,12 @@ enum Exc_Cause : uint32_t {
TRAP = 1 << (31 - 14),
};
extern unsigned exec_flags;
// extern bool bb_end;
extern BB_end_kind bb_kind;
extern jmp_buf exc_env;
extern bool grab_exception;
extern bool grab_return;
extern bool power_on;
@@ -324,9 +323,8 @@ extern uint64_t exceptions_processed;
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version);
extern void ppc_mmu_init(uint32_t cpu_version);
void ppc_illegalop();
void ppc_fpu_off();
void ppc_ext_int();
[[noreturn]] void ppc_illegalop();
[[noreturn]] void ppc_fpu_off();
//void ppc_opcode4();
void ppc_opcode16();
@@ -362,7 +360,7 @@ void ppc_changecrf0(uint32_t set_result);
void ppc_fp_changecrf1();
/* Exception handlers. */
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
// MEMORY DECLARATIONS
@@ -617,8 +615,6 @@ extern void power_srq();
// G5+ instructions
extern uint64_t get_virt_time_ns(void);
extern void ppc_main_opcode(void);
extern void ppc_exec(void);
extern void ppc_exec_single(void);
@@ -627,7 +623,7 @@ extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
/* debugging support API */
void print_fprs(void); /* print content of the floating-point registers */
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
uint64_t get_reg(std::string& reg_name); /* get content of the register reg_name */
void set_reg(std::string& reg_name, uint64_t val); /* set reg_name to val */
#endif /* PPCEMU_H */
+7 -14
View File
@@ -21,20 +21,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** @file Handling of low-level PPC exceptions. */
#include <loguru.hpp>
#include "ppcemu.h"
#include "ppcmmu.h"
#include <setjmp.h>
#include <stdexcept>
#include <string>
jmp_buf exc_env; /* Global exception environment. */
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
grab_exception = true;
#ifdef CPU_PROFILING
exceptions_processed++;
#endif
bb_kind = BB_end_kind::BB_EXCEPTION;
switch (exception_type) {
case Except_Type::EXC_SYSTEM_RESET:
@@ -61,11 +61,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
case Except_Type::EXC_EXT_INT:
if (exec_flags & ~EXEF_TIMER) {
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
} else {
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFCUL) + 4;
}
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
ppc_next_instruction_address = 0x0500;
break;
@@ -100,7 +96,8 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
break;
default:
ABORT_F("Unknown exception occured: %X\n", exception_type);
// printf("Unknown exception occured: %X\n", exception_type);
// exit(-1);
break;
}
@@ -113,8 +110,6 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
ppc_next_instruction_address |= 0xFFF00000;
}
exec_flags = EXEF_EXCEPTION;
// perform context synchronization for recoverable exceptions
if (exception_type != Except_Type::EXC_MACHINE_CHECK &&
exception_type != Except_Type::EXC_SYSTEM_RESET) {
@@ -123,9 +118,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
mmu_change_mode();
if (exception_type != Except_Type::EXC_EXT_INT) {
longjmp(exc_env, 2); /* return to the main execution loop. */
}
longjmp(exc_env, 2); /* return to the main execution loop. */
}
+283 -271
View File
@@ -19,21 +19,21 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <core/timermanager.h>
#include <loguru.hpp>
#include "ppcemu.h"
#include "ppcmmu.h"
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <setjmp.h>
#include <stdexcept>
#include <stdio.h>
#include <string>
#include <loguru.hpp>
#include <unordered_map>
#include "ppcemu.h"
#include "ppcmmu.h"
#define NEW_TBR_UPDATE_ALGO
using namespace std;
using namespace dppc_interpreter;
@@ -46,6 +46,7 @@ SetPRS ppc_state;
bool rc_flag = 0; // Record flag
bool oe_flag = 0; // Overflow flag
bool grab_exception;
bool grab_return;
bool grab_breakpoint;
@@ -53,7 +54,7 @@ uint32_t ppc_cur_instruction; // Current instruction for the PPC
uint32_t ppc_effective_address;
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
unsigned exec_flags;
BB_end_kind bb_kind; /* basic block end */
/* copy of local variable bb_start_la. Need for correct
calculation of CPU cycles after setjmp that clobbers
@@ -61,15 +62,12 @@ unsigned exec_flags;
uint32_t glob_bb_start_la;
/* variables related to virtual time */
uint64_t g_icycles;
int icnt_factor;
/* global variables related to the timebase facility */
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
uint64_t tbr_wr_value; // last value written to the TBR
uint64_t tbr_freq_hz; // TBR driving frequency in Hz
uint64_t timebase_counter; // internal timebase counter
uint32_t decr; // current value of PPC DEC register
uint64_t cycles_count; /* contains number of cycles executed so far */
uint64_t old_cycles_count; /* previous value for cycles_count */
uint64_t timebase_counter; /* internal timebase counter */
uint32_t decr; /* current value of PPC DEC register */
uint8_t old_decr_msb; /* MSB value for previous DEC value */
uint8_t tbr_factor; /* cycles_count to TBR freq ratio in 2^x units */
#ifdef CPU_PROFILING
@@ -158,22 +156,28 @@ PPCOpcode SubOpcode31Grabber[1024] = { ppc_illegalop };
PPCOpcode SubOpcode59Grabber[32] = { ppc_illegalop };
PPCOpcode SubOpcode63Grabber[1024] = { ppc_illegalop };
#define UPDATE_TBR_DEC \
if ((delta = (cycles_count - old_cycles_count) >> tbr_factor)) { \
timebase_counter += delta; \
decr -= delta; \
if ((decr & 0x80000000) && !old_decr_msb) { \
old_decr_msb = decr >> 31; \
/* signal_decr_int(); */ \
} \
old_cycles_count += delta << tbr_factor; \
}
/** Exception helpers. */
void ppc_illegalop() {
[[noreturn]] void ppc_illegalop() {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
void ppc_fpu_off() {
[[noreturn]] void ppc_fpu_off() {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_OFF);
}
void ppc_ext_int() {
if (ppc_state.msr & 0x8000) {
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
}
}
/** Opcode decoding functions. */
void ppc_opcode16() {
@@ -282,279 +286,262 @@ void ppc_main_opcode()
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
}
uint64_t get_virt_time_ns()
{
return g_icycles << icnt_factor;
}
uint64_t process_events()
{
uint64_t slice_ns = TimerManager::get_instance()->process_timers(get_virt_time_ns());
if (slice_ns == 0) {
// execute 10.000 cycles
// if there are no pending timers
return g_icycles + 10000;
}
return g_icycles + ((slice_ns + (1 << icnt_factor)) >> icnt_factor);
}
void force_cycle_counter_reload()
{
// tell the interpreter loop to reload cycle counter
exec_flags |= EXEF_TIMER;
}
/** Execute PPC code as long as power is on. */
// inner interpreter loop
static void ppc_exec_inner()
{
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint8_t* pc_real;
max_cycles = 0;
while (power_on) {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
exec_flags = 0;
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
// interpret execution block
while (ppc_state.pc < eb_end) {
ppc_main_opcode();
if (g_icycles++ >= max_cycles) {
max_cycles = process_events();
}
if (exec_flags) {
if (!power_on)
break;
// reload cycle counter if requested
if (exec_flags & EXEF_TIMER) {
max_cycles = process_events();
if (!(exec_flags & ~EXEF_TIMER)) {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
exec_flags = 0;
continue;
}
}
// define next execution block
eb_start = ppc_next_instruction_address;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
if ((eb_start & PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
}
}
}
// outer interpreter loop
void ppc_exec()
{
uint32_t bb_start_la, page_start, delta;
uint8_t* pc_real;
/* start new basic block */
glob_bb_start_la = bb_start_la = ppc_state.pc;
bb_kind = BB_end_kind::BB_NONE;
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
/* reaching here means we got a low-level exception */
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
//pc_real = mmu_translate_imem(bb_start_la);
pc_real = mmu_translate_imem(bb_start_la);
page_start = bb_start_la & 0xFFFFF000;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
goto again;
}
/* initial MMU translation for the current code page. */
//pc_real = quickinstruction_translate(bb_start_la);
pc_real = mmu_translate_imem(bb_start_la);
/* set current code page limits */
page_start = bb_start_la & 0xFFFFF000;
again:
while (power_on) {
ppc_exec_inner();
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
page_start = bb_start_la & 0xFFFFF000;
pc_real = mmu_translate_imem(bb_start_la);
} else {
pc_real += (int)bb_start_la - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
} else {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
}
}
/** Execute one PPC instruction. */
void ppc_exec_single()
{
uint32_t delta;
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
/* reaching here means we got a low-level exception */
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count++;
UPDATE_TBR_DEC
#else
timebase_counter++;
#endif
ppc_state.pc = ppc_next_instruction_address;
exec_flags = 0;
bb_kind = BB_end_kind::BB_NONE;
return;
}
//quickinstruction_translate(ppc_state.pc);
mmu_translate_imem(ppc_state.pc);
ppc_main_opcode();
if (exec_flags) {
if (exec_flags & EXEF_TIMER) {
ppc_state.pc += 4;
} else {
ppc_state.pc = ppc_next_instruction_address;
}
exec_flags = 0;
if (bb_kind != BB_end_kind::BB_NONE) {
ppc_state.pc = ppc_next_instruction_address;
bb_kind = BB_end_kind::BB_NONE;
} else {
ppc_state.pc += 4;
}
g_icycles++;
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count++;
UPDATE_TBR_DEC
#else
timebase_counter++;
#endif
}
/** Execute PPC code until goal_addr is reached. */
// inner interpreter loop
static void ppc_exec_until_inner(const uint32_t goal_addr)
{
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint8_t* pc_real;
max_cycles = 0;
while (ppc_state.pc != goal_addr) {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
exec_flags = 0;
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
// interpret execution block
while ((ppc_state.pc != goal_addr) && (ppc_state.pc < eb_end)) {
ppc_main_opcode();
if (g_icycles++ >= max_cycles) {
max_cycles = process_events();
}
if (exec_flags) {
// reload cycle counter if requested
if (exec_flags & EXEF_TIMER) {
max_cycles = process_events();
if (!(exec_flags & ~EXEF_TIMER)) {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
exec_flags = 0;
continue;
}
}
// define next execution block
eb_start = ppc_next_instruction_address;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
if ((eb_start & PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
}
ppc_state.pc = eb_start;
exec_flags = 0;
} else {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
}
}
}
// outer interpreter loop
void ppc_exec_until(volatile uint32_t goal_addr)
{
uint32_t bb_start_la, page_start, delta;
uint8_t* pc_real;
/* start new basic block */
glob_bb_start_la = bb_start_la = ppc_state.pc;
bb_kind = BB_end_kind::BB_NONE;
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
/* reaching here means we got a low-level exception */
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
pc_real = mmu_translate_imem(bb_start_la);
page_start = bb_start_la & 0xFFFFF000;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
goto again;
}
/* initial MMU translation for the current code page. */
//pc_real = quickinstruction_translate(bb_start_la);
pc_real = mmu_translate_imem(bb_start_la);
/* set current code page limits */
page_start = bb_start_la & 0xFFFFF000;
again:
while (ppc_state.pc != goal_addr) {
ppc_exec_until_inner(goal_addr);
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
page_start = bb_start_la & 0xFFFFF000;
pc_real = mmu_translate_imem(bb_start_la);
} else {
pc_real += (int)bb_start_la - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
} else {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
}
}
/** Execute PPC code until control is reached the specified region. */
// inner interpreter loop
static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
{
uint64_t max_cycles;
uint32_t page_start, eb_start, eb_end;
uint32_t bb_start_la, page_start, delta;
uint8_t* pc_real;
max_cycles = 0;
/* start new basic block */
glob_bb_start_la = bb_start_la = ppc_state.pc;
bb_kind = BB_end_kind::BB_NONE;
if (setjmp(exc_env)) {
/* reaching here means we got a low-level exception */
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
//pc_real = quickinstruction_translate(bb_start_la);
pc_real = mmu_translate_imem(bb_start_la);
page_start = bb_start_la & 0xFFFFF000;
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
//printf("DBG Exec: got exception, continue at %X\n", ppc_state.pc);
goto again;
}
/* initial MMU translation for the current code page. */
pc_real = mmu_translate_imem(bb_start_la);
/* set current code page limits */
page_start = bb_start_la & 0xFFFFF000;
again:
while (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size) {
// define boundaries of the next execution block
// max execution block length = one memory page
eb_start = ppc_state.pc;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
exec_flags = 0;
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
// interpret execution block
while ((ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)
&& (ppc_state.pc < eb_end)) {
ppc_main_opcode();
if (g_icycles++ >= max_cycles) {
max_cycles = process_events();
}
if (exec_flags) {
// reload cycle counter if requested
if (exec_flags & EXEF_TIMER) {
max_cycles = process_events();
if (!(exec_flags & ~EXEF_TIMER)) {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
exec_flags = 0;
continue;
}
}
// define next execution block
eb_start = ppc_next_instruction_address;
eb_end = (eb_start + PAGE_SIZE) & PAGE_MASK;
if ((eb_start & PAGE_MASK) == page_start) {
pc_real += (int)eb_start - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
} else {
page_start = eb_start & PAGE_MASK;
pc_real = mmu_translate_imem(eb_start);
}
ppc_state.pc = eb_start;
exec_flags = 0;
ppc_main_opcode();
if (bb_kind != BB_end_kind::BB_NONE) {
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count += ((ppc_state.pc - bb_start_la) >> 2) + 1;
UPDATE_TBR_DEC
#else
timebase_counter += ((ppc_state.pc - bb_start_la) >> 2) + 1;
#endif
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
page_start = bb_start_la & 0xFFFFF000;
//pc_real = quickinstruction_translate(bb_start_la);
pc_real = mmu_translate_imem(bb_start_la);
} else {
ppc_state.pc += 4;
pc_real += 4;
pc_real += (int)bb_start_la - (int)ppc_state.pc;
ppc_set_cur_instruction(pc_real);
}
ppc_state.pc = bb_start_la;
bb_kind = BB_end_kind::BB_NONE;
//printf("DBG Exec: new basic block at %X, start_addr=%X\n", ppc_state.pc, start_addr);
} else {
ppc_state.pc += 4;
pc_real += 4;
ppc_set_cur_instruction(pc_real);
}
}
}
// outer interpreter loop
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
uint64_t instr_count, old_instr_count;
void test_timebase_update()
{
if (setjmp(exc_env)) {
// process low-level exceptions
//LOG_F(9, "PPC-EXEC: low_level exception raised!");
ppc_state.pc = ppc_next_instruction_address;
uint32_t delta, factor;
uint8_t old_decr_msb;
uint8_t intervals[10] = {4, 7, 10, 2, 16, 6, 3, 20, 12, 8};
timebase_counter = 0;
decr = 0x00000003;
old_decr_msb = decr >> 31;
old_instr_count = 0xFFFFFFFFFFFFFF80UL;//0xFFFFFFFFFFFFFFD0UL;
instr_count = 0xFFFFFFFFFFFFFF80UL;//0xFFFFFFFFFFFFFFD0UL;
factor = 4;
for (int i = 0; i < 10; i++) {
cycles_count += intervals[i];
if ((delta = (cycles_count - old_cycles_count) >> factor)) {
timebase_counter += delta;
decr -= delta;
if ((decr & 0x80000000) && !old_decr_msb) {
old_decr_msb = decr >> 31;
LOG_F(ERROR, "DEC exception signaled!\n");
}
old_instr_count += delta << factor;
LOG_F(INFO, "Iteration %d, TBR=0x%llX, DEC=0x%X", i, timebase_counter, decr);
LOG_F(INFO, " icount=0x%llX, old_icount=0x%llX\n", cycles_count, old_cycles_count);
}
}
while (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size) {
ppc_exec_dbg_inner(start_addr, size);
}
}
void initialize_ppc_opcode_tables() {
@@ -697,11 +684,26 @@ void initialize_ppc_opcode_tables() {
SubOpcode59Grabber[21] = ppc_fadds;
SubOpcode59Grabber[22] = ppc_fsqrts;
SubOpcode59Grabber[24] = ppc_fres;
SubOpcode59Grabber[25] = ppc_fmuls;
SubOpcode59Grabber[28] = ppc_fmsubs;
SubOpcode59Grabber[29] = ppc_fmadds;
SubOpcode59Grabber[30] = ppc_fnmsubs;
SubOpcode59Grabber[31] = ppc_fnmadds;
for (int i = 25; i < 1024; i += 32) {
SubOpcode59Grabber[i] = ppc_fmuls;
}
for (int i = 28; i < 1024; i += 32) {
SubOpcode59Grabber[i] = ppc_fmsubs;
}
for (int i = 29; i < 1024; i += 32) {
SubOpcode59Grabber[i] = ppc_fmadds;
}
for (int i = 30; i < 1024; i += 32) {
SubOpcode59Grabber[i] = ppc_fnmsubs;
}
for (int i = 31; i < 1024; i += 32) {
SubOpcode59Grabber[i] = ppc_fnmadds;
}
SubOpcode63Grabber[0] = ppc_fcmpu;
SubOpcode63Grabber[12] = ppc_frsp;
@@ -724,13 +726,28 @@ void initialize_ppc_opcode_tables() {
SubOpcode63Grabber[583] = ppc_mffs;
SubOpcode63Grabber[711] = ppc_mtfsf;
for (int i = 0; i < 1024; i += 32) {
SubOpcode63Grabber[i + 23] = ppc_fsel;
SubOpcode63Grabber[i + 25] = ppc_fmul;
SubOpcode63Grabber[i + 28] = ppc_fmsub;
SubOpcode63Grabber[i + 29] = ppc_fmadd;
SubOpcode63Grabber[i + 30] = ppc_fnmsub;
SubOpcode63Grabber[i + 31] = ppc_fnmadd;
for (int i = 23; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fsel;
}
for (int i = 25; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fmul;
}
for (int i = 28; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fmsub;
}
for (int i = 29; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fmadd;
}
for (int i = 30; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fnmsub;
}
for (int i = 31; i < 1024; i += 32) {
SubOpcode63Grabber[i] = ppc_fnmadd;
}
}
@@ -743,21 +760,16 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version) {
initialize_ppc_opcode_tables();
// initialize emulator timers
TimerManager::get_instance()->set_time_now_cb(&get_virt_time_ns);
TimerManager::get_instance()->set_notify_changes_cb(&force_cycle_counter_reload);
// initialize time base facility
g_icycles = 0;
icnt_factor = 4;
tbr_wr_timestamp = 0;
tbr_wr_value = 0;
tbr_freq_hz = 16705000; // FIXME: this should be set properly during machine initialization
exec_flags = 0;
/* initialize timer variables */
#ifdef NEW_TBR_UPDATE_ALGO
cycles_count = 0;
old_cycles_count = 0;
tbr_factor = 4;
#endif
timebase_counter = 0;
decr = 0;
old_decr_msb = decr >> 31;
/* zero all GPRs as prescribed for MPC601 */
/* For later PPC CPUs, GPR content is undefined */
@@ -907,10 +919,10 @@ bail_out:
throw std::invalid_argument(string("Unknown register ") + reg_name);
}
uint64_t get_reg(string reg_name) {
uint64_t get_reg(string& reg_name) {
return reg_op(reg_name, 0, false);
}
void set_reg(string reg_name, uint64_t val) {
void set_reg(string& reg_name, uint64_t val) {
reg_op(reg_name, val, true);
}
+51 -50
View File
@@ -153,22 +153,22 @@ void ppc_fp_changecrf1() {
int64_t round_to_nearest(double f) {
if (f >= 0.0) {
return static_cast<int32_t>(static_cast<int64_t> (std::ceil(f)));
return static_cast<int32_t>(static_cast<int64_t> (ceil(f)));
} else {
return static_cast<int32_t>(static_cast<int64_t> (std::floor(f)));
return static_cast<int32_t>(static_cast<int64_t> (floor(f)));
}
}
int64_t round_to_zero(double f) {
return static_cast<int32_t>(std::trunc(f));
return static_cast<int32_t>(trunc(f));
}
int64_t round_to_pos_inf(double f) {
return static_cast<int32_t>(std::ceil(f));
return static_cast<int32_t>(ceil(f));
}
int64_t round_to_neg_inf(double f) {
return static_cast<int32_t>(std::floor(f));
return static_cast<int32_t>(floor(f));
}
void update_fex() {
@@ -186,7 +186,7 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
switch (fpop) {
case FPOP::DIV:
if (std::isinf(input_a) && std::isinf(input_b)) {
if (isinf(input_a) && isinf(input_b)) {
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXIDI);
} else if ((input_a == FP_ZERO) && (input_b == FP_ZERO)) {
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXZDZ);
@@ -194,13 +194,13 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
update_fex();
break;
case FPOP::SUB:
if (std::isnan(input_a) && std::isnan(input_b)) {
if (isnan(input_a) && isnan(input_b)) {
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXISI);
}
update_fex();
break;
case FPOP::ADD:
if (std::isnan(input_a) && std::isnan(input_b)) {
if (isnan(input_a) && isnan(input_b)) {
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXISI);
}
update_fex();
@@ -216,7 +216,7 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
break;
case FPOP::FMSUB:
case FPOP::FNMSUB:
if (std::isnan(input_a) || std::isnan(input_b) || std::isnan(input_c)) {
if (isnan(input_a) || isnan(input_b) || isnan(input_c)) {
ppc_state.fpscr |= (FPSCR::FX | FPSCR::VXSNAN);
if (((input_a == FP_ZERO) && (input_c == FP_INFINITE)) ||
((input_c == FP_ZERO) && (input_a == FP_INFINITE))) {
@@ -228,7 +228,7 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
break;
case FPOP::FMADD:
case FPOP::FNMADD:
if (std::isnan(input_a) || std::isnan(input_b) || std::isnan(input_c)) {
if (isnan(input_a) || isnan(input_b) || isnan(input_c)) {
ppc_state.fpscr |= (FPSCR::VXSNAN | FPSCR::FPCC_FUNAN);
}
update_fex();
@@ -236,7 +236,8 @@ void ppc_confirm_inf_nan(int chosen_reg_1, int chosen_reg_2, int chosen_reg_3, b
}
}
static void fpresult_update(double set_result, bool confirm_arc) {
template <typename T, const FPOP fpop>
void fpresult_update(double set_result, bool confirm_arc) {
if (ppc_state.fpscr & 0x3)
ppc_state.cr |= 0x2;
@@ -248,7 +249,7 @@ static void fpresult_update(double set_result, bool confirm_arc) {
ppc_state.fpscr |= FPCC_ZERO;
}
if (std::isnan(set_result) || std::isinf(set_result)) {
if (isnan(set_result) || isinf(set_result)) {
ppc_state.fpscr |= FPCC_FPRCD;
}
}
@@ -282,10 +283,10 @@ void dppc_interpreter::ppc_fadd() {
ppc_dblresult64_d = double(val_reg_a + val_reg_b);
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
}
fpresult_update<double, ADD>(ppc_dblresult64_d, rc_flag);
}
else {
ppc_confirm_inf_nan<double, ADD>(reg_a, reg_b, 0, rc_flag);
}
@@ -299,9 +300,9 @@ void dppc_interpreter::ppc_fsub() {
ppc_dblresult64_d = double(val_reg_a - val_reg_b);
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, SUB>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, SUB>(reg_a, reg_b, 0, rc_flag);
}
@@ -315,9 +316,9 @@ void dppc_interpreter::ppc_fdiv() {
ppc_dblresult64_d = val_reg_a / val_reg_b;
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, DIV>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, DIV>(reg_a, reg_b, 0, rc_flag);
}
@@ -331,9 +332,9 @@ void dppc_interpreter::ppc_fmul() {
ppc_dblresult64_d = val_reg_a * val_reg_c;
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, MUL>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, MUL>(reg_a, reg_b, 0, rc_flag);
}
@@ -347,9 +348,9 @@ void dppc_interpreter::ppc_fmadd() {
ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, FMADD>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, FMADD>(reg_a, reg_b, reg_c);
}
@@ -364,9 +365,9 @@ void dppc_interpreter::ppc_fmsub() {
ppc_dblresult64_d = (val_reg_a * val_reg_c);
ppc_dblresult64_d -= val_reg_b;
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, FMSUB>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, FMSUB>(reg_a, reg_b, reg_c);
}
@@ -382,9 +383,9 @@ void dppc_interpreter::ppc_fnmadd() {
ppc_dblresult64_d += val_reg_b;
ppc_dblresult64_d = -(ppc_dblresult64_d);
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, FNMADD>(ppc_dblresult64_d, rc_flag);
}
else {
ppc_confirm_inf_nan<double, FNMADD>(reg_a, reg_b, reg_c);
@@ -401,9 +402,9 @@ void dppc_interpreter::ppc_fnmsub() {
ppc_dblresult64_d -= val_reg_b;
ppc_dblresult64_d = -(ppc_dblresult64_d);
if (!std::isnan(ppc_dblresult64_d) || !std::isinf(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d) || !isinf(ppc_dblresult64_d)) {
ppc_store_dfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<double, FNMSUB>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<double, FNMSUB>(reg_a, reg_b, reg_c);
}
@@ -417,10 +418,10 @@ void dppc_interpreter::ppc_fadds() {
ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
}
fpresult_update<float, ADD>(ppc_dblresult64_d, rc_flag);
}
else {
ppc_confirm_inf_nan<float, ADD>(reg_a, reg_b, 0);
}
@@ -434,9 +435,9 @@ void dppc_interpreter::ppc_fsubs() {
ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, SUB>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, SUB>(reg_a, reg_b, 0);
}
@@ -450,9 +451,9 @@ void dppc_interpreter::ppc_fdivs() {
ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, DIV>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, DIV>(reg_a, reg_b, 0);
}
@@ -466,9 +467,9 @@ void dppc_interpreter::ppc_fmuls() {
ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, MUL>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, MUL>(reg_a, 0, reg_c);
}
@@ -483,9 +484,9 @@ void dppc_interpreter::ppc_fmadds() {
ppc_dblresult64_d = static_cast<double>(
std::fma((float)val_reg_a, (float)val_reg_c, (float)val_reg_b));
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, FMADD>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, FMADD>(reg_a, reg_b, reg_c);
}
@@ -501,9 +502,9 @@ void dppc_interpreter::ppc_fmsubs() {
intermediate -= (float)val_reg_b;
ppc_dblresult64_d = static_cast<double>(intermediate);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, FMADD>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, FMSUB>(reg_a, reg_b, reg_c);
}
@@ -520,9 +521,9 @@ void dppc_interpreter::ppc_fnmadds() {
intermediate = -intermediate;
ppc_dblresult64_d = static_cast<double>(intermediate);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, FNMADD>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, FNMADD>(reg_a, reg_b, reg_c);
}
@@ -540,9 +541,9 @@ void dppc_interpreter::ppc_fnmsubs() {
ppc_dblresult64_d = static_cast<double>(intermediate);
if (!std::isnan(ppc_dblresult64_d)) {
if (!isnan(ppc_dblresult64_d)) {
ppc_store_sfpresult_flt(reg_d);
fpresult_update(ppc_dblresult64_d, rc_flag);
fpresult_update<float, FNMSUB>(ppc_dblresult64_d, rc_flag);
} else {
ppc_confirm_inf_nan<float, FNMSUB>(reg_a, reg_b, reg_c);
}
@@ -995,10 +996,10 @@ void dppc_interpreter::ppc_fcmpo() {
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
cmp_c |= (1 << CRx_bit::CR_SO);
}
if (db_test_a < db_test_b) {
cmp_c |= (1 << CRx_bit::CR_LT);
}
}
else if (db_test_a > db_test_b) {
cmp_c |= (1 << CRx_bit::CR_GT);
}
@@ -1029,10 +1030,10 @@ void dppc_interpreter::ppc_fcmpu() {
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
cmp_c |= (1 << CRx_bit::CR_SO);
}
if (db_test_a < db_test_b) {
cmp_c |= (1 << CRx_bit::CR_LT);
}
}
else if (db_test_a > db_test_b) {
cmp_c |= (1 << CRx_bit::CR_GT);
}
+1
View File
@@ -847,6 +847,7 @@ static void mpc601_bat_update(uint32_t bat_reg)
{
PPC_BAT_entry *ibat_entry, *dbat_entry;
uint32_t bsm, hi_mask;
uint8_t key, pp, prot;
int upper_reg_num;
upper_reg_num = bat_reg & 0xFFFFFFFE;
-2
View File
@@ -71,8 +71,6 @@ typedef struct PATResult {
} PATResult;
#define PAGE_SIZE_BITS 12
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
#define PAGE_MASK ~(PAGE_SIZE - 1)
#define TLB_SIZE 4096
#define TLB2_WAYS 4
#define TLB_INVALID_TAG 0xFFFFFFFF
+107 -101
View File
@@ -21,7 +21,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// General opcodes for the processor - ppcopcodes.cpp
#include <core/timermanager.h>
#include "ppcemu.h"
#include "ppcmmu.h"
#include <array>
@@ -859,21 +858,6 @@ void dppc_interpreter::ppc_mfspr() {
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
}
static inline uint64_t calc_tbr_value()
{
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
uint64_t tbr_inc = diff * tbr_freq_hz / NS_PER_SEC;
return (tbr_wr_value + tbr_inc);
}
static void update_timebase(uint64_t mask, uint64_t new_val)
{
uint64_t tbr_value = calc_tbr_value();
tbr_wr_value = (tbr_value & mask) | new_val;
tbr_wr_timestamp = get_virt_time_ns();
LOG_F(9, "New TBR value = 0x%llu", tbr_wr_value);
}
void dppc_interpreter::ppc_mtspr() {
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
reg_s = (ppc_cur_instruction >> 21) & 31;
@@ -893,11 +877,13 @@ void dppc_interpreter::ppc_mtspr() {
}
switch (ref_spr) {
// Mirror the TBRs in the SPR range to the user-mode TBRs.
case 284:
update_timebase(0xFFFFFFFF00000000ULL, ppc_state.gpr[reg_s]);
timebase_counter = (timebase_counter & 0xFFFFFFFF00000000ULL) + ppc_state.gpr[reg_s];
break;
case 285:
update_timebase(0x00000000FFFFFFFFULL, (uint64_t)(ppc_state.gpr[reg_s]) << 32);
timebase_counter = (timebase_counter & 0x00000000FFFFFFFFULL) +
(((uint64_t)(ppc_state.gpr[reg_s])) << 32);
break;
case 528:
case 529:
@@ -924,18 +910,15 @@ void dppc_interpreter::ppc_mtspr() {
void dppc_interpreter::ppc_mftb() {
uint32_t ref_spr = (((ppc_cur_instruction >> 11) & 31) << 5) | ((ppc_cur_instruction >> 16) & 31);
reg_d = (ppc_cur_instruction >> 21) & 31;
uint64_t tbr_value = calc_tbr_value();
switch (ref_spr) {
case 268:
ppc_state.gpr[reg_d] = tbr_value & 0xFFFFFFFFUL;
break;
case 269:
ppc_state.gpr[reg_d] = (tbr_value >> 32) & 0xFFFFFFFFUL;
break;
default:
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
case 268:
ppc_state.gpr[reg_d] = timebase_counter & 0xFFFFFFFFUL;
break;
case 269:
ppc_state.gpr[reg_d] = (timebase_counter >> 32) & 0xFFFFFFFFUL;
break;
default:
LOG_F(ERROR, "Invalid TBR access attempted !\n");
}
}
@@ -995,7 +978,7 @@ void dppc_interpreter::ppc_b() {
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = (uint32_t)(ppc_state.pc + adr_li);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
void dppc_interpreter::ppc_bl() {
@@ -1003,14 +986,14 @@ void dppc_interpreter::ppc_bl() {
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = (uint32_t)(ppc_state.pc + adr_li);
ppc_state.spr[SPR::LR] = (uint32_t)(ppc_state.pc + 4);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
void dppc_interpreter::ppc_ba() {
uint32_t quick_test = (ppc_cur_instruction & 0x03FFFFFC);
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = adr_li;
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
void dppc_interpreter::ppc_bla() {
@@ -1018,7 +1001,7 @@ void dppc_interpreter::ppc_bla() {
adr_li = (quick_test < 0x2000000) ? quick_test : (0xFC000000UL + quick_test);
ppc_next_instruction_address = adr_li;
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
void dppc_interpreter::ppc_bc() {
@@ -1036,7 +1019,7 @@ void dppc_interpreter::ppc_bc() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.pc + br_bd);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
}
@@ -1055,7 +1038,7 @@ void dppc_interpreter::ppc_bca() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = br_bd;
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
}
@@ -1074,7 +1057,7 @@ void dppc_interpreter::ppc_bcl() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.pc + br_bd);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
@@ -1094,7 +1077,7 @@ void dppc_interpreter::ppc_bcla() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = br_bd;
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
@@ -1108,7 +1091,7 @@ void dppc_interpreter::ppc_bcctr() {
if (cnd_ok) {
ppc_next_instruction_address = (ppc_state.spr[SPR::CTR] & 0xFFFFFFFCUL);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
}
@@ -1121,7 +1104,7 @@ void dppc_interpreter::ppc_bcctrl() {
if (cnd_ok) {
ppc_next_instruction_address = (ppc_state.spr[SPR::CTR] & 0xFFFFFFFCUL);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
@@ -1140,7 +1123,7 @@ void dppc_interpreter::ppc_bclr() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.spr[SPR::LR] & 0xFFFFFFFCUL);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
}
@@ -1158,7 +1141,7 @@ void dppc_interpreter::ppc_bclrl() {
if (ctr_ok && cnd_ok) {
ppc_next_instruction_address = (ppc_state.spr[SPR::LR] & 0xFFFFFFFCUL);
exec_flags = EXEF_BRANCH;
bb_kind = BB_end_kind::BB_BRANCH;
}
ppc_state.spr[SPR::LR] = ppc_state.pc + 4;
}
@@ -1243,8 +1226,7 @@ void dppc_interpreter::ppc_mcrf() {
void dppc_interpreter::ppc_crand() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) & (ppc_state.cr >> (31 - reg_b));
if (ir & 1) {
if ((ppc_state.cr & (0x80000000UL >> reg_a)) && (ppc_state.cr & (0x80000000UL >> reg_b))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
@@ -1261,43 +1243,37 @@ void dppc_interpreter::ppc_crandc() {
}
void dppc_interpreter::ppc_creqv() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) ^ (ppc_state.cr >> (31 - reg_b));
if (ir & 1) { // compliment is implemented by swapping the following if/else bodies
ppc_state.cr &= ~(0x80000000UL >> reg_d);
} else {
if (!((ppc_state.cr & (0x80000000UL >> reg_a)) ^ (ppc_state.cr & (0x80000000UL >> reg_b)))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
}
}
void dppc_interpreter::ppc_crnand() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) & (ppc_state.cr >> (31 - reg_b));
if (ir & 1) {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
} else {
if (!((ppc_state.cr & (0x80000000UL >> reg_a)) && (ppc_state.cr & (0x80000000UL >> reg_b)))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
}
}
void dppc_interpreter::ppc_crnor() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) | (ppc_state.cr >> (31 - reg_b));
if (ir & 1) {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
} else {
if (!((ppc_state.cr & (0x80000000UL >> reg_a)) || (ppc_state.cr & (0x80000000UL >> reg_b)))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
}
}
void dppc_interpreter::ppc_cror() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) | (ppc_state.cr >> (31 - reg_b));
if (ir & 1) {
if ((ppc_state.cr & (0x80000000UL >> reg_a)) || (ppc_state.cr & (0x80000000UL >> reg_b))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
}
}
void dppc_interpreter::ppc_crorc() {
ppc_grab_regsdab();
if ((ppc_state.cr & (0x80000000UL >> reg_a)) || !(ppc_state.cr & (0x80000000UL >> reg_b))) {
@@ -1308,8 +1284,7 @@ void dppc_interpreter::ppc_crorc() {
}
void dppc_interpreter::ppc_crxor() {
ppc_grab_regsdab();
uint8_t ir = (ppc_state.cr >> (31 - reg_a)) ^ (ppc_state.cr >> (31 - reg_b));
if (ir & 1) {
if ((ppc_state.cr & (0x80000000UL >> reg_a)) ^ (ppc_state.cr & (0x80000000UL >> reg_b))) {
ppc_state.cr |= (0x80000000UL >> reg_d);
} else {
ppc_state.cr &= ~(0x80000000UL >> reg_d);
@@ -1332,7 +1307,7 @@ void dppc_interpreter::ppc_rfi() {
mmu_change_mode();
grab_return = true;
exec_flags = EXEF_RFI;
bb_kind = BB_end_kind::BB_RFI;
}
void dppc_interpreter::ppc_sc() {
@@ -1946,33 +1921,41 @@ void dppc_interpreter::ppc_lswi() {
num_int_loads++;
#endif
ppc_grab_regsda();
ppc_effective_address = reg_a ? ppc_result_a : 0;
grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
grab_inb = grab_inb ? grab_inb : 32;
ppc_effective_address = reg_a ? ppc_result_a : 0;
grab_inb = (ppc_cur_instruction >> 11) & 31;
grab_inb = grab_inb ? grab_inb : 32;
uint32_t stringed_word = 0;
while (grab_inb > 0) {
switch (grab_inb) {
case 1:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
case 2:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 1) << 16;
//stringed_word += mem_grab_byte(ppc_effective_address + 1) << 16;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
case 3:
stringed_word = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 1) << 16;
//stringed_word += mem_grab_byte(ppc_effective_address + 1) << 16;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
//stringed_word += mem_grab_byte(ppc_effective_address + 2) << 8;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
default:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
//ppc_state.gpr[reg_d] = mem_grab_word(ppc_effective_address);
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address);
reg_d++;
if (reg_d >= 32) { // wrap around through GPR0
reg_d = 0;
}
ppc_effective_address += 4;
grab_inb -= 4;
}
@@ -1986,36 +1969,47 @@ void dppc_interpreter::ppc_lswx() {
ppc_grab_regsdab();
// Invalid instruction forms
if ((reg_d | reg_a) == 0 || (reg_d == reg_a) || (reg_d == reg_b)) {
if ((ppc_result_d == 0) && (ppc_result_a == 0)) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
if ((ppc_result_d == ppc_result_a) || (ppc_result_a == ppc_result_b)) {
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
}
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
grab_inb = ppc_state.spr[SPR::XER] & 0x7F;
grab_inb = ppc_state.spr[SPR::XER] & 127;
uint32_t stringed_word = 0;
while (grab_inb > 0) {
switch (grab_inb) {
case 1:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
case 2:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 1) << 16;
//stringed_word += mem_grab_byte(ppc_effective_address + 1) << 16;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
case 3:
stringed_word = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
stringed_word = mmu_read_vmem<uint8_t>(ppc_effective_address) << 24;
//stringed_word = mem_grab_byte(ppc_effective_address) << 24;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 1) << 16;
//stringed_word += mem_grab_byte(ppc_effective_address + 1) << 16;
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
//stringed_word += mem_grab_byte(ppc_effective_address + 2) << 8;
ppc_state.gpr[reg_d] = stringed_word;
grab_inb = 0;
break;
default:
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
//ppc_state.gpr[reg_d] = mem_grab_word(ppc_effective_address);
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address);
reg_d++;
if (reg_d >= 32) { // wrap around through GPR0
reg_d = 0;
}
ppc_effective_address += 4;
grab_inb -= 4;
}
@@ -2027,31 +2021,37 @@ void dppc_interpreter::ppc_stswi() {
num_int_stores++;
#endif
ppc_grab_regssa();
ppc_effective_address = reg_a ? ppc_result_a : 0;
grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
grab_inb = grab_inb ? grab_inb : 32;
ppc_effective_address = reg_a ? ppc_result_a : 0;
grab_inb = (ppc_cur_instruction >> 11) & 31;
grab_inb = (grab_inb & 32) == 0 ? 32 : grab_inb;
while (grab_inb > 0) {
switch (grab_inb) {
case 1:
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
mmu_write_vmem<uint8_t>(ppc_effective_address, (ppc_result_d >> 24));
//mem_write_byte(ppc_effective_address, (ppc_result_d >> 24));
grab_inb = 0;
break;
case 2:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
//mem_write_byte(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
//mem_write_byte((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
grab_inb = 0;
break;
case 3:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
mmu_write_vmem<uint8_t>(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
//mem_write_byte(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
//mem_write_byte((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 2), ((ppc_result_d >> 8) & 0xFF));
//mem_write_byte((ppc_effective_address + 2), ((ppc_result_d >> 8) & 0xFF));
grab_inb = 0;
break;
default:
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
reg_s++;
if (reg_s >= 32) { // wrap around through GPR0
reg_s = 0;
}
ppc_effective_address += 4;
grab_inb -= 4;
}
@@ -2069,24 +2069,30 @@ void dppc_interpreter::ppc_stswx() {
while (grab_inb > 0) {
switch (grab_inb) {
case 1:
mmu_write_vmem<uint8_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 24);
mmu_write_vmem<uint8_t>(ppc_effective_address, (ppc_result_d >> 24));
//mem_write_byte(ppc_effective_address, (ppc_result_d >> 24));
grab_inb = 0;
break;
case 2:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
//mem_write_byte(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
//mem_write_byte((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
grab_inb = 0;
break;
case 3:
mmu_write_vmem<uint16_t>(ppc_effective_address, ppc_state.gpr[reg_s] >> 16);
mmu_write_vmem<uint8_t>(ppc_effective_address + 2, (ppc_state.gpr[reg_s] >> 8) & 0xFF);
mmu_write_vmem<uint8_t>(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
//mem_write_byte(ppc_effective_address, ((ppc_result_d >> 24) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
//mem_write_byte((ppc_effective_address + 1), ((ppc_result_d >> 16) & 0xFF));
mmu_write_vmem<uint8_t>((ppc_effective_address + 2), ((ppc_result_d >> 8) & 0xFF));
//mem_write_byte((ppc_effective_address + 2), ((ppc_result_d >> 8) & 0xFF));
grab_inb = 0;
break;
default:
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_state.gpr[reg_s]);
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
//mem_write_dword(ppc_effective_address, ppc_result_d);
reg_s++;
if (reg_s >= 32) { // wrap around through GPR0
reg_s = 0;
}
ppc_effective_address += 4;
grab_inb -= 4;
}
+30 -16
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -65,7 +65,6 @@ static void show_help() {
cout << " as single instructions." << endl;
cout << " ni -- shortcut for next" << endl;
cout << " until X -- execute until address X is reached" << endl;
cout << " go -- exit debugger and continue emulator execution" << endl;
cout << " regs -- dump content of the GRPs" << endl;
cout << " set R=X -- assign value X to register R" << endl;
cout << " if R=loglevel, set the internal" << endl;
@@ -149,21 +148,25 @@ print_bin:
/** Execute one emulated 68k instruction. */
void exec_single_68k()
{
string reg;
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
/* PPC r24 contains 68k PC advanced by two bytes
as part of instruction prefetching */
cur_68k_pc = get_reg(string("R24")) - 2;
reg = "R24";
cur_68k_pc = get_reg(reg) - 2;
/* PPC r29 contains base address of the emulator opcode table */
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
reg = "R29";
emu_table_virt = get_reg(reg) & 0xFFF80000;
/* calculate address of the current opcode table entry as follows:
get_word(68k_PC) * entry_size + table_base */
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc) * 8 + emu_table_virt;
/* grab the PPC PC too */
ppc_pc = get_reg(string("PC"));
reg = "PC";
ppc_pc = get_reg(reg);
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
@@ -172,29 +175,39 @@ void exec_single_68k()
one by one until the execution goes outside the opcode table. */
while (ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
ppc_exec_single();
ppc_pc = get_reg(string("PC"));
reg = "PC";
ppc_pc = get_reg(reg);
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
}
/* Getting here means we're outside the emualtor opcode table.
Execute PPC code until we hit the opcode table again. */
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
}
/** Execute emulated 68k code until target_addr is reached. */
void exec_until_68k(uint32_t target_addr)
{
string reg;
uint32_t emu_table_virt, ppc_pc;
emu_table_virt = get_reg(string("R29")) & 0xFFF80000;
reg = "R29";
emu_table_virt = get_reg(reg) & 0xFFF80000;
while (target_addr != (get_reg(string("R24")) - 2)) {
ppc_pc = get_reg(string("PC"));
reg = "R24";
while (target_addr != (get_reg(reg) - 2)) {
reg = "PC";
ppc_pc = get_reg(reg);
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
ppc_exec_single();
} else {
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
}
reg = "R24";
}
}
@@ -212,14 +225,17 @@ void print_68k_regs()
reg = "R" + to_string(i + 16);
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
}
reg = "R1";
cout << "A7 : " << uppercase << hex << get_reg(reg) << endl;
cout << "A7 : " << uppercase << hex << get_reg(string("R1")) << endl;
reg = "R24";
cout << "PC: " << uppercase << hex << get_reg(reg) - 2 << endl;
cout << "PC: " << uppercase << hex << get_reg(string("R24")) - 2 << endl;
reg = "R25";
cout << "SR: " << uppercase << hex << ((get_reg(reg) & 0xFF) << 8) << endl;
cout << "SR: " << uppercase << hex << ((get_reg("R25") & 0xFF) << 8) << endl;
cout << "CCR: " << uppercase << hex << get_reg(string("R26")) << endl;
reg = "R26";
cout << "CCR: " << uppercase << hex << get_reg(reg) << endl;
}
#endif // ENABLE_68K_DEBUGGER
@@ -488,8 +504,6 @@ void enter_debugger() {
} catch (invalid_argument& exc) {
cout << exc.what() << endl;
}
} else if (cmd == "go") {
ppc_exec(); // won't return!
} else if (cmd == "disas" || cmd == "da") {
expr_str = "";
ss >> expr_str;
-1
View File
@@ -9,7 +9,6 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/floppy/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/ioctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
+2
View File
@@ -55,6 +55,8 @@ ADB_Bus::ADB_Bus() {
mouse_access_no = adb_relative;
}
ADB_Bus::~ADB_Bus() {}
bool ADB_Bus::listen(int device, int reg) {
if (device == keyboard_access_no) {
if (adb_keybd_listen(reg)) {
+1 -1
View File
@@ -51,7 +51,7 @@ enum adb_default_values {
class ADB_Bus {
public:
ADB_Bus();
~ADB_Bus() = default;
~ADB_Bus();
bool listen(int device, int reg);
bool talk(int device, int reg, uint16_t value);
+1 -10
View File
@@ -33,16 +33,7 @@ enum DmaPullResult : int {
class DmaOutChannel {
public:
virtual bool is_active() { return true; };
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
};
// Base class for bidirectional DMA channels.
class DmaBidirChannel {
public:
virtual bool is_active() { return true; };
virtual int push_data(const char* src_ptr, int len) = 0;
virtual bool is_active() = 0;
virtual DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data) = 0;
};
+18 -35
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -22,35 +22,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef HW_COMPONENT_H
#define HW_COMPONENT_H
#include <cinttypes>
#include <string>
/** types of different HW components */
enum HWCompType {
UNKNOWN = 0ULL, /* unknown component type */
MEM_CTRL = 1ULL << 0, /* memory controller */
ROM = 1ULL << 2, /* read-only memory */
RAM = 1ULL << 3, /* random access memory */
MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */
PCI_HOST = 1ULL << 5, /* PCI host */
PCI_DEV = 1ULL << 6, /* PCI device */
I2C_HOST = 1ULL << 8, /* I2C host */
I2C_DEV = 1ULL << 9, /* I2C device */
ADB_HOST = 1ULL << 12, /* ADB host */
ADB_DEV = 1ULL << 13, /* ADB device */
INT_CTRL = 1ULL << 16, /* interrupt controller */
SCSI_BUS = 1ULL << 20, /* SCSI bus */
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
SCSI_DEV = 1ULL << 22, /* SCSI device */
SND_SERVER = 1ULL << 31, /* host sound server */
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
enum HWCompType : int {
UNKNOWN = 0, /* unknown component type */
MEM_CTRL = 10, /* memory controller */
ROM = 20, /* read-only memory */
RAM = 30, /* random access memory */
MMIO_DEV = 40, /* memory mapped I/O device */
PCI_HOST = 50, /* PCI host */
PCI_DEV = 51, /* PCI device */
I2C_HOST = 60, /* I2C host */
I2C_DEV = 61, /* I2C device */
ADB_HOST = 70, /* ADB host */
ADB_DEV = 71, /* ADB device */
INT_CTRL = 80, /* interrupt controller */
SND_SERVER = 100, /* host sound server */
};
/** Base class for HW components. */
/** Abstract base class for HW components. */
class HWComponent {
public:
HWComponent() = default;
virtual ~HWComponent() = default;
virtual std::string get_name(void) {
@@ -60,21 +54,10 @@ public:
this->name = name;
};
virtual bool supports_type(HWCompType type) {
return !!(this->supported_types & type);
};
virtual void supports_types(uint64_t types) {
this->supported_types = types;
};
virtual int device_postinit() {
return 0;
};
virtual bool supports_type(HWCompType type) = 0;
protected:
std::string name;
uint64_t supported_types = HWCompType::UNKNOWN;
};
#endif /* HW_COMPONENT_H */
+3 -1
View File
@@ -47,7 +47,9 @@ public:
I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
};
virtual ~I2CBus() = default;
~I2CBus() {
std::memset(this->dev_list, 0, sizeof(this->dev_list));
};
virtual void register_device(uint8_t dev_addr, I2CDevice* dev_obj) {
if (this->dev_list[dev_addr]) {
+8 -2
View File
@@ -51,10 +51,13 @@ public:
this->id[1] = 0x5A;
this->id[2] = (id >> 8) & 0xFF;
this->id[3] = id & 0xFF;
supports_types(HWCompType::MMIO_DEV);
};
~NubusMacID() = default;
bool supports_type(HWCompType type) {
return type == HWCompType::MMIO_DEV;
};
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
return (offset < 4 ? this->id[offset] : 0);
};
@@ -77,10 +80,13 @@ class GossamerID : public MMIODevice {
public:
GossamerID(const uint16_t id) {
this->id = id, this->name = "Machine-id";
supports_types(HWCompType::MMIO_DEV);
};
~GossamerID() = default;
bool supports_type(HWCompType type) {
return type == HWCompType::MMIO_DEV;
};
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
return ((!offset && size == 2) ? this->id : 0);
};
-1
View File
@@ -30,7 +30,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** Abstract class representing a simple, memory-mapped I/O device */
class MMIODevice : public HWComponent {
public:
MMIODevice() = default;
virtual uint32_t read(uint32_t reg_start, uint32_t offset, int size) = 0;
virtual void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) = 0;
virtual ~MMIODevice() = default;
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -19,34 +19,20 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef HW_INTERRUPT_H
#define HW_INTERRUPT_H
/** @file NCR 53C94 SCSI controller emulation. */
#include "ncr53c94.h"
#include <loguru.hpp>
#include <cinttypes>
/** Enumerator for various interrupt sources. */
enum IntSrc : int {
VIA_CUDA = 1,
SCSI1 = 2,
SWIM3 = 3,
SCC = 4,
ETHERNET = 5,
NMI = 6,
};
uint8_t Ncr53C94::read(uint8_t reg_offset)
{
LOG_F(9, "NCR53C94: reading from register %d", reg_offset);
return 0;
}
/** Base class for interrupt controllers. */
class InterruptCtrl {
public:
InterruptCtrl() = default;
virtual ~InterruptCtrl() = default;
// register interrupt sources for a device
virtual uint32_t register_dev_int(IntSrc src_id) = 0;
virtual uint32_t register_dma_int(IntSrc src_id) = 0;
// acknowledge HW interrupt
virtual void ack_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
};
#endif // HW_INTERRUPT_H
void Ncr53C94::write(uint8_t reg_offset, uint8_t value)
{
LOG_F(INFO, "NCR53C94: writing 0x%X to %d register", value, reg_offset);
}
+89
View File
@@ -0,0 +1,89 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file NCR 53C94 SCSI controller definitions. */
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
The corresponding functionality is provided by the 53C94 compatible
cell in the custom Curio IC (Am79C950).
*/
#ifndef NCR53C94_H
#define NCR53C94_H
#include <cinttypes>
/** NCR 53C94 read registers */
namespace Read {
enum Reg53C94 : uint8_t {
Xfer_Cnt_LSB = 0,
Xfer_Cnt_MSB = 1,
FIFO = 2,
Command = 3,
Status = 4,
Interrupt = 5,
Seq_Step = 6,
FIFO_Flags = 7,
Config_1 = 8,
Config_2 = 0xB,
Config_3 = 0xC,
Config_4 = 0xD, // Curio extension?
Xfer_Cnt_Hi = 0xE, // Curio extension?
DMA = 0xF, // Curio extension?
};
};
/** NCR 53C94 write registers */
namespace Write {
enum Reg53C94 : uint8_t {
Xfer_Cnt_LSB = 0,
Xfer_Cnt_MSB = 1,
FIFO = 2,
Command = 3,
Dest_Bus_ID = 4,
Sel_Timeout = 5,
Synch_Period = 6,
Synch_Offset = 7,
Config_1 = 8,
Clk_Conv_Fac = 9,
Test_Mode = 0xA,
Config_2 = 0xB,
Config_3 = 0xC,
Config_4 = 0xD, // Curio extension?
Chip_ID = 0xE, // Curio extension?
DMA = 0xF, // Curio extension?
};
};
class Ncr53C94 {
public:
Ncr53C94() = default;
~Ncr53C94() = default;
// NCR 53C94 registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
private:
uint8_t chip_id;
};
#endif // NCR53C94_H
-360
View File
@@ -1,360 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file NCR53C94/Am53CF94 SCSI controller emulation. */
#include <core/timermanager.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/scsi/sc53c94.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id)
{
this->chip_id = chip_id;
this->my_bus_id = my_id;
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
reset_device();
}
int Sc53C94::device_postinit()
{
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
this->bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI1);
return 0;
}
void Sc53C94::reset_device()
{
// part-unique ID to be read using a magic sequence
this->set_xfer_count = this->chip_id << 16;
this->clk_factor = 2;
this->sel_timeout = 0;
this->is_initiator = true;
// clear command FIFO
this->cmd_fifo_pos = 0;
// clear data FIFO
this->data_fifo_pos = 0;
this->data_fifo[0] = 0;
this->seq_step = 0;
this->status = 0;
}
uint8_t Sc53C94::read(uint8_t reg_offset)
{
uint8_t int_status;
switch (reg_offset) {
case Read::Reg53C94::Command:
return this->cmd_fifo[0];
case Read::Reg53C94::Status:
return this->status;
case Read::Reg53C94::Int_Status:
int_status = this->int_status;
this->seq_step = 0;
this->int_status = 0;
this->update_irq();
return int_status;
case Read::Reg53C94::Seq_Step:
return this->seq_step;
case Read::Reg53C94::FIFO_Flags:
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
case Read::Reg53C94::Config_3:
return this->config3;
case Read::Reg53C94::Xfer_Cnt_Hi:
if (this->config2 & CFG2_ENF) {
return (this->xfer_count >> 16) & 0xFFU;
}
break;
default:
LOG_F(INFO, "SC53C94: reading from register %d", reg_offset);
}
return 0;
}
void Sc53C94::write(uint8_t reg_offset, uint8_t value)
{
switch (reg_offset) {
case Write::Reg53C94::Command:
update_command_reg(value);
break;
case Write::Reg53C94::FIFO:
fifo_push(value);
break;
case Write::Reg53C94::Dest_Bus_ID:
this->target_id = value & 7;
break;
case Write::Reg53C94::Sel_Timeout:
this->sel_timeout = value;
break;
case Write::Reg53C94::Sync_Offset:
this->sync_offset = value;
break;
case Write::Reg53C94::Clock_Factor:
this->clk_factor = value;
break;
case Write::Reg53C94::Config_1:
if ((value & 7) != this->my_bus_id) {
ABORT_F("SC53C94: HBA bus ID mismatch!");
}
this->config1 = value;
break;
case Write::Reg53C94::Config_2:
this->config2 = value;
break;
case Write::Reg53C94::Config_3:
this->config3 = value;
break;
default:
LOG_F(INFO, "SC53C94: writing 0x%X to %d register", value, reg_offset);
}
}
void Sc53C94::update_command_reg(uint8_t cmd)
{
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
LOG_F(WARNING, "SC53C94: command register blocked after RESET!");
return;
}
// NOTE: Reset Device (chip), Reset Bus and DMA Stop commands execute
// immediately while all others are placed into the command FIFO
switch (cmd & 0x7F) {
case CMD_RESET_DEVICE:
case CMD_RESET_BUS:
case CMD_DMA_STOP:
this->cmd_fifo_pos = 0; // put them at the bottom of the command FIFO
}
if (this->cmd_fifo_pos < 2) {
// put new command into the command FIFO
this->cmd_fifo[this->cmd_fifo_pos++] = cmd;
if (this->cmd_fifo_pos == 1) {
exec_command();
}
} else {
LOG_F(ERROR, "SC53C94: the top of the command FIFO overwritten!");
this->status |= 0x40; // signal IOE/Gross Error
}
}
void Sc53C94::exec_command()
{
uint8_t cmd = this->cmd_fifo[0] & 0x7F;
bool is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
if (is_dma_cmd) {
if (this->config2 & CFG2_ENF) { // extended mode: 24-bit
this->xfer_count = this->set_xfer_count & 0xFFFFFFUL;
} else { // standard mode: 16-bit
this->xfer_count = this->set_xfer_count & 0xFFFFUL;
}
}
// simple commands will be executed immediately
// complex commands will be broken into multiple steps
// and handled by the sequencer
switch (cmd) {
case CMD_NOP:
this->on_reset = false; // unblock the command register
exec_next_command();
break;
case CMD_CLEAR_FIFO:
this->data_fifo_pos = 0; // set the bottom of the FIFO to zero
this->data_fifo[0] = 0;
exec_next_command();
break;
case CMD_RESET_DEVICE:
reset_device();
this->on_reset = true; // block the command register
return;
case CMD_RESET_BUS:
LOG_F(INFO, "SC53C94: resetting SCSI bus...");
// assert RST line
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
// release RST line after 25 us
my_timer_id = TimerManager::get_instance()->add_oneshot_timer(
USECS_TO_NSECS(25),
[this]() {
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST);
});
if (!(config1 & 0x40)) {
LOG_F(INFO, "SC53C94: reset interrupt issued");
this->int_status |= INTSTAT_SRST;
}
exec_next_command();
break;
case CMD_SELECT_NO_ATN:
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
{SeqState::CMD_BEGIN, 3, INTSTAT_SR | INTSTAT_SO},
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
};
this->seq_step = 0;
this->cmd_steps = sel_no_atn_desc;
this->cur_state = SeqState::BUS_FREE;
sequencer();
LOG_F(INFO, "SC53C94: SELECT W/O ATN command started");
break;
case CMD_ENA_SEL_RESEL:
LOG_F(INFO, "SC53C94: ENABLE SELECTION/RESELECTION command executed");
exec_next_command();
break;
default:
LOG_F(ERROR, "SC53C94: invalid/unimplemented command 0x%X", cmd);
this->cmd_fifo_pos--; // remove invalid command from FIFO
this->int_status |= INTSTAT_ICMD;
}
}
void Sc53C94::exec_next_command()
{
if (this->cmd_fifo_pos) { // skip empty command FIFO
this->cmd_fifo_pos--; // remove completed command
if (this->cmd_fifo_pos) { // is there another command in the FIFO?
this->cmd_fifo[0] = this->cmd_fifo[1]; // top -> bottom
exec_command(); // execute it
}
}
}
void Sc53C94::fifo_push(const uint8_t data)
{
if (this->data_fifo_pos < 16) {
this->data_fifo[this->data_fifo_pos++] = data;
} else {
LOG_F(ERROR, "SC53C94: data FIFO overflow!");
this->status |= 0x40; // signal IOE/Gross Error
}
}
void Sc53C94::seq_defer_state(uint64_t delay_ns)
{
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
delay_ns,
[this]() {
// re-enter the sequencer with the state specified in next_state
this->cur_state = this->next_state;
this->sequencer();
});
}
void Sc53C94::sequencer()
{
switch (this->cur_state) {
case SeqState::IDLE:
break;
case SeqState::BUS_FREE:
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
this->next_state = SeqState::ARB_BEGIN;
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
} else { // continue waiting
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_FREE_DELAY);
}
break;
case SeqState::ARB_BEGIN:
if (!this->bus_obj->begin_arbitration(this->my_bus_id)) {
LOG_F(ERROR, "SC53C94: arbitration error, bus not free!");
this->bus_obj->release_ctrl_lines(this->my_bus_id);
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_CLEAR_DELAY);
break;
}
this->next_state = SeqState::ARB_END;
this->seq_defer_state(ARB_DELAY);
break;
case SeqState::ARB_END:
if (this->bus_obj->end_arbitration(this->my_bus_id)) { // arbitration won
this->next_state = this->cmd_steps->next_step;
this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY);
} else { // arbitration lost
LOG_F(INFO, "SC53C94: arbitration lost!");
this->bus_obj->release_ctrl_lines(this->my_bus_id);
this->next_state = SeqState::BUS_FREE;
this->seq_defer_state(BUS_CLEAR_DELAY);
}
break;
case SeqState::SEL_BEGIN:
this->is_initiator = true;
this->bus_obj->begin_selection(this->my_bus_id, this->target_id,
this->cur_cmd != CMD_SELECT_NO_ATN);
this->next_state = SeqState::SEL_END;
this->seq_defer_state(SEL_TIME_OUT);
break;
case SeqState::SEL_END:
if (this->bus_obj->end_selection(this->my_bus_id, this->target_id)) {
LOG_F(INFO, "SC53C94: selection completed");
this->cmd_steps++;
} else { // selection timeout
this->seq_step = this->cmd_steps->step_num;
this->int_status |= this->cmd_steps->status;
this->bus_obj->disconnect(this->my_bus_id);
this->cur_state = SeqState::IDLE;
this->update_irq();
exec_next_command();
}
break;
default:
ABORT_F("SC53C94: unimplemented sequencer state %d", this->cur_state);
}
}
void Sc53C94::update_irq()
{
uint8_t new_irq = !!(this->int_status != 0);
if (new_irq != this->irq) {
this->irq = new_irq;
this->status = (this->status & 0x7F) | (new_irq << 7);
this->int_ctrl->ack_int(this->irq_id, new_irq);
}
}
void Sc53C94::notify(ScsiMsg msg_type, int param)
{
switch (msg_type) {
case ScsiMsg::CONFIRM_SEL:
if (this->target_id == param) {
// cancel selection timeout timer
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
this->cur_state = SeqState::SEL_END;
sequencer();
} else {
LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message");
}
break;
default:
LOG_F(WARNING, "SC53C94: ignore notification message, type: %d", msg_type);
}
}
-191
View File
@@ -1,191 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file NCR53C94/Am53CF94 SCSI controller definitions. */
/* NOTE: Power Macintosh computers don't have a real NCR 53C94 chip.
The corresponding functionality is provided by the 53CF94 compatible
cell in the custom Curio IC (Am79C950).
*/
#ifndef SC_53C94_H
#define SC_53C94_H
#include "scsi.h"
#include "devices/common/hwinterrupt.h"
#include <cinttypes>
/** 53C94 read registers */
namespace Read {
enum Reg53C94 : uint8_t {
Xfer_Cnt_LSB = 0,
Xfer_Cnt_MSB = 1,
FIFO = 2,
Command = 3,
Status = 4,
Int_Status = 5,
Seq_Step = 6,
FIFO_Flags = 7,
Config_1 = 8,
Config_2 = 0xB,
Config_3 = 0xC,
Config_4 = 0xD, // Am53CF94 extension
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
};
};
/** 53C94 write registers */
namespace Write {
enum Reg53C94 : uint8_t {
Xfer_Cnt_LSB = 0,
Xfer_Cnt_MSB = 1,
FIFO = 2,
Command = 3,
Dest_Bus_ID = 4,
Sel_Timeout = 5,
Sync_Period = 6,
Sync_Offset = 7,
Config_1 = 8,
Clock_Factor = 9,
Test_Mode = 0xA,
Config_2 = 0xB,
Config_3 = 0xC,
Config_4 = 0xD, // Am53CF94 extension
Xfer_Cnt_Hi = 0xE, // Am53CF94 extension
Data_Align = 0xF
};
};
/** NCR53C94/Am53CF94 commands. */
enum {
CMD_NOP = 0,
CMD_CLEAR_FIFO = 1,
CMD_RESET_DEVICE = 2,
CMD_RESET_BUS = 3,
CMD_DMA_STOP = 4,
CMD_SELECT_NO_ATN = 0x41,
CMD_ENA_SEL_RESEL = 0x44,
};
/** Interrupt status register bits. */
enum {
INTSTAT_SRST = 0x80, // bus reset
INTSTAT_ICMD = 0x40, // invalid command
INTSTAT_DIS = 0x20, // disconnected
INTSTAT_SR = 0x10, // service request
INTSTAT_SO = 0x08, // successful operation
INTSTAT_RESEL = 0x04, // reselected
INTSTAT_SELA = 0x02, // selected as a target with attention
INTSTAT_SEL = 0x01, // selected as a target without attention
};
enum {
CFG2_ENF = 0x40, // Am53CF94: enable features (ENF) bit
};
/** Sequencer states. */
namespace SeqState {
enum {
IDLE = 0,
BUS_FREE,
ARB_BEGIN,
ARB_END,
SEL_BEGIN,
SEL_END,
CMD_BEGIN,
CMD_COMPLETE,
};
};
/** Sequence descriptor for sequencer commands. */
typedef struct {
int next_step;
int step_num;
int status;
} SeqDesc;
class Sc53C94 : public ScsiDevice {
public:
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
~Sc53C94() = default;
// HWComponent methods
int device_postinit();
// 53C94 registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
// ScsiDevice methods
void notify(ScsiMsg msg_type, int param);
protected:
void reset_device();
void update_command_reg(uint8_t cmd);
void exec_command();
void exec_next_command();
void fifo_push(const uint8_t data);
void sequencer();
void seq_defer_state(uint64_t delay_ns);
void update_irq();
private:
uint8_t chip_id;
uint8_t my_bus_id;
ScsiBus* bus_obj;
uint32_t my_timer_id;
uint8_t cmd_fifo[2];
uint8_t data_fifo[16];
int cmd_fifo_pos;
int data_fifo_pos;
bool on_reset = false;
uint32_t xfer_count;
uint32_t set_xfer_count;
uint8_t status;
uint8_t target_id;
uint8_t int_status;
uint8_t seq_step;
uint8_t sel_timeout;
uint8_t sync_offset;
uint8_t clk_factor;
uint8_t config1;
uint8_t config2;
uint8_t config3;
// sequencer state
uint32_t seq_timer_id;
uint32_t cur_state;
uint32_t next_state;
SeqDesc* cmd_steps;
bool is_initiator;
uint8_t cur_cmd;
// interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq = 0;
};
#endif // SC_53C94_H
-123
View File
@@ -1,123 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file SCSI bus definitions. */
#ifndef SCSI_H
#define SCSI_H
#include <devices/common/hwcomponent.h>
#include <array>
#include <cinttypes>
#include <string>
/** SCSI control signals.
Bit positions follow the MESH controller convention for easier mapping.
*/
enum {
SCSI_CTRL_IO = 1 << 0,
SCSI_CTRL_CD = 1 << 1,
SCSI_CTRL_MSG = 1 << 2,
SCSI_CTRL_ATN = 1 << 3,
SCSI_CTRL_ACK = 1 << 4,
SCSI_CTRL_REQ = 1 << 5,
SCSI_CTRL_SEL = 1 << 6,
SCSI_CTRL_BSY = 1 << 7,
SCSI_CTRL_RST = 1 << 8,
};
enum ScsiPhase : int {
BUS_FREE = 0,
ARBITRATION,
SELECTION,
RESELECTION,
RESET,
};
enum ScsiMsg : int {
CONFIRM_SEL = 1,
BUS_PHASE_CHANGE,
};
/** Standard SCSI bus timing values measured in ns. */
#define BUS_SETTLE_DELAY 400
#define BUS_FREE_DELAY 800
#define BUS_CLEAR_DELAY 800
#define ARB_DELAY 2400
#define SEL_ABORT_TIME 200000
#define SEL_TIME_OUT 250000000
#define SCSI_MAX_DEVS 8
class ScsiDevice : public HWComponent {
public:
ScsiDevice() = default;
~ScsiDevice() = default;
virtual void notify(ScsiMsg msg_type, int param) = 0;
private:
int scsi_id;
};
/** This class provides a higher level abstraction for the SCSI bus. */
class ScsiBus : public HWComponent {
public:
ScsiBus();
~ScsiBus() = default;
// low-level control/status
void register_device(int id, ScsiDevice* dev_obj);
void assert_ctrl_line(int id, uint16_t mask);
void release_ctrl_line(int id, uint16_t mask);
void release_ctrl_lines(int id);
int current_phase() { return this->cur_phase; };
// high-level control/status
bool begin_arbitration(int id);
bool end_arbitration(int id);
bool begin_selection(int initiator_id, int target_id, bool atn);
void confirm_selection(int target_id);
bool end_selection(int initiator_id, int target_id);
void disconnect(int dev_id);
protected:
void change_bus_phase(int initiator_id);
private:
std::string name;
// SCSI devices registered with this bus
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
// per-device state of the control lines
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS];
uint16_t ctrl_lines;
int cur_phase;
int arb_winner_id;
int initiator_id;
int target_id;
uint8_t data_lines;
};
#endif // SCSI_H
-181
View File
@@ -1,181 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file SCSI bus emulation. */
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/scsi.h>
#include <loguru.hpp>
#include <cinttypes>
ScsiBus::ScsiBus()
{
supports_types(HWCompType::SCSI_BUS);
for(int i = 0; i < SCSI_MAX_DEVS; i++) {
this->devices[i] = nullptr;
this->dev_ctrl_lines[i] = 0;
}
this->ctrl_lines = 0; // all control lines released
this->data_lines = 0; // data lines released
this->arb_winner_id = -1;
this->initiator_id = -1;
this->target_id = -1;
}
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
{
if (this->devices[id] != nullptr) {
ABORT_F("ScsiBus: device with ID %d already registered", id);
}
this->devices[id] = dev_obj;
}
void ScsiBus::change_bus_phase(int initiator_id)
{
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
if (i == initiator_id)
continue; // don't notify the initiator
if (this->devices[i] != nullptr) {
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
}
}
}
void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
{
uint16_t new_state = 0xFFFFU & mask;
this->dev_ctrl_lines[initiator_id] = new_state;
if (new_state == this->ctrl_lines) {
return;
}
this->ctrl_lines = new_state;
if (new_state & SCSI_CTRL_RST) {
this->cur_phase = ScsiPhase::RESET;
change_bus_phase(initiator_id);
}
}
void ScsiBus::release_ctrl_line(int id, uint16_t mask)
{
uint16_t new_state = 0;
this->dev_ctrl_lines[id] &= ~mask;
// OR control lines of all devices together
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
new_state |= this->dev_ctrl_lines[i];
}
if (this->ctrl_lines & SCSI_CTRL_RST) {
if (!(new_state & SCSI_CTRL_RST)) {
this->ctrl_lines = new_state;
this->cur_phase = ScsiPhase::BUS_FREE;
change_bus_phase(id);
}
}
}
void ScsiBus::release_ctrl_lines(int id)
{
this->release_ctrl_line(id, 0xFFFFUL);
}
bool ScsiBus::begin_arbitration(int initiator_id)
{
if (this->cur_phase == ScsiPhase::BUS_FREE) {
this->data_lines |= 1 << initiator_id;
this->cur_phase = ScsiPhase::ARBITRATION;
change_bus_phase(initiator_id);
return true;
} else {
return false;
}
}
bool ScsiBus::end_arbitration(int initiator_id)
{
int highest_id = -1;
// find the highest ID bit on the data lines
for (int id = 7; id >= 0; id--) {
if (this->data_lines & (1 << id)) {
highest_id = id;
break;
}
}
if (highest_id >= 0) {
this->arb_winner_id = highest_id;
}
return highest_id == initiator_id;
}
bool ScsiBus::begin_selection(int initiator_id, int target_id, bool atn)
{
// perform bus integrity checks
if (this->cur_phase != ScsiPhase::ARBITRATION || this->arb_winner_id != initiator_id)
return false;
this->data_lines |= (1 << initiator_id) | (1 << target_id);
if (atn) {
assert_ctrl_line(initiator_id, SCSI_CTRL_ATN);
}
this->initiator_id = initiator_id;
this->cur_phase = ScsiPhase::SELECTION;
change_bus_phase(initiator_id);
return true;
}
void ScsiBus::confirm_selection(int target_id)
{
this->target_id = target_id;
// notify initiator about selection confirmation from target
if (this->initiator_id >= 0) {
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
}
}
bool ScsiBus::end_selection(int initiator_id, int target_id)
{
// check for selection confirmation from target
return this->target_id == target_id;
}
void ScsiBus::disconnect(int dev_id)
{
this->release_ctrl_lines(dev_id);
if (!(this->ctrl_lines & SCSI_CTRL_BSY) && !(this->ctrl_lines & SCSI_CTRL_SEL)) {
this->cur_phase = ScsiPhase::BUS_FREE;
change_bus_phase(dev_id);
}
}
+50 -203
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -19,15 +19,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** High-level VIA-CUDA combo device emulation.
*/
/** VIA-CUDA combo device emulation.
Author: Max Poliakovski 2019
*/
#include <core/timermanager.h>
#include <devices/common/adb/adb.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/viacuda.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <memaccess.h>
#include <cinttypes>
@@ -38,8 +37,6 @@ using namespace std;
ViaCuda::ViaCuda() {
this->name = "ViaCuda";
supports_types(HWCompType::ADB_HOST | HWCompType::I2C_HOST);
// VIA reset clears all internal registers to logic 0
// except timers/counters and the shift register
// as stated in the 6522 datasheet
@@ -48,6 +45,7 @@ ViaCuda::ViaCuda() {
this->via_regs[VIA_DIRB] = 0;
this->via_regs[VIA_DIRA] = 0;
this->via_regs[VIA_IER] = 0;
this->via_regs[VIA_SR] = 0;
this->via_regs[VIA_ACR] = 0;
this->via_regs[VIA_PCR] = 0;
this->via_regs[VIA_IFR] = 0;
@@ -59,40 +57,15 @@ ViaCuda::ViaCuda() {
this->via_regs[VIA_T2CL] = 0xFF;
this->via_regs[VIA_T2CH] = 0xFF;
this->_via_ifr = 0; // all flags cleared
this->_via_ier = 0; // all interrupts disabled
this->irq = 0; // IRQ is not active
// intialize counters/timers
this->t1_counter = 0xFFFF;
this->t1_active = false;
this->t2_counter = 0xFFFF;
this->t2_active = false;
// calculate VIA clock duration in ns
this->via_clk_dur = 1.0f / VIA_CLOCK_HZ * NS_PER_SEC;
// PRAM is part of Cuda
this->pram_obj = std::unique_ptr<NVram> (new NVram("pram.bin", 256));
// ADB bus is driven by Cuda
this->adb_bus = std::unique_ptr<ADB_Bus> (new ADB_Bus());
this->adb_obj = new ADB_Bus();
this->cuda_init();
this->int_ctrl = nullptr;
this->init();
}
int ViaCuda::device_postinit()
{
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::VIA_CUDA);
return 0;
}
void ViaCuda::cuda_init() {
void ViaCuda::init() {
this->old_tip = 0;
this->old_byteack = 0;
this->treq = 1;
@@ -102,44 +75,46 @@ void ViaCuda::cuda_init() {
}
uint8_t ViaCuda::read(int reg) {
uint8_t res;
LOG_F(9, "Read VIA reg %d", reg);
res = this->via_regs[reg & 0xF];
/* reading from some VIA registers triggers special actions */
switch (reg & 0xF) {
case VIA_B:
return (this->via_regs[VIA_B]);
res = this->via_regs[VIA_B];
break;
case VIA_A:
case VIA_ANH:
LOG_F(WARNING, "Attempted read from VIA Port A!");
break;
case VIA_IER:
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
case VIA_IFR:
return this->_via_ifr;
case VIA_T1CL:
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
case VIA_T1CH:
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
res = this->via_regs[VIA_T1CL];
this->via_regs[VIA_IFR] &= ~IFR_T1;
case VIA_T2CL:
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
return this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
case VIA_T2CH:
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
res = this->via_regs[VIA_T2CL];
this->via_regs[VIA_IFR] &= ~IFR_T2;
case VIA_SR:
this->_via_ifr &= ~VIA_IF_SR;
update_irq();
res = this->via_regs[VIA_SR];
this->via_regs[VIA_IFR] &= ~IFR_SR;
case VIA_IFR:
res = this->via_regs[VIA_IFR];
if (this->via_regs[VIA_IFR] & this->via_regs[VIA_IER])
res |= 0x80;
break;
case VIA_IER:
res |= 0x80; /* bit 7 always reads as "1" */
}
return (this->via_regs[reg & 0xF]);
return res;
}
void ViaCuda::write(int reg, uint8_t value) {
this->via_regs[reg & 0xF] = value;
switch (reg & 0xF) {
case VIA_B:
this->via_regs[VIA_B] = value;
write(value);
break;
case VIA_A:
@@ -148,167 +123,45 @@ void ViaCuda::write(int reg, uint8_t value) {
break;
case VIA_DIRB:
LOG_F(9, "VIA_DIRB = 0x%X", value);
this->via_regs[VIA_DIRB] = value;
break;
case VIA_DIRA:
LOG_F(9, "VIA_DIRA = 0x%X", value);
this->via_regs[VIA_DIRA] = value;
break;
case VIA_PCR:
LOG_F(9, "VIA_PCR = 0x%X", value);
this->via_regs[VIA_PCR] = value;
break;
case VIA_ACR:
LOG_F(9, "VIA_ACR = 0x%X", value);
break;
case VIA_IFR:
// for each "1" in value clear the corresponding flags
this->_via_ifr &= ~value;
update_irq();
this->via_regs[VIA_ACR] = value;
break;
case VIA_IER:
if (value & 0x80) {
this->_via_ier |= value & 0x7F;
} else {
this->_via_ier &= ~value;
}
update_irq();
this->via_regs[VIA_IER] = (value & 0x80) ? value & 0x7F : this->via_regs[VIA_IER] & ~value;
LOG_F(9, "VIA_IER updated to 0x%X", this->via_regs[VIA_IER]);
print_enabled_ints();
break;
case VIA_T1CH:
if (this->via_regs[VIA_ACR] & 0xC0) {
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
}
// cancel active T1 timer task
if (this->t1_active) {
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
this->t1_active = false;
}
// clear T1 flag in IFR
this->_via_ifr &= ~VIA_IF_T1;
update_irq();
// load initial value into counter 1
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
// set up timout timer for T1
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
[this]() {
this->assert_t1_int();
}
);
this->t1_active = true;
break;
case VIA_T2CH:
if (this->via_regs[VIA_ACR] & 0x20) {
ABORT_F("VIA T2 pulse count mode not supported!");
}
// cancel active T2 timer task
if (this->t2_active) {
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
this->t2_active = false;
}
// clear T2 flag in IFR
this->_via_ifr &= ~VIA_IF_T2;
update_irq();
// load initial value into counter 2
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
// TODO: delay for one phase 2 clock
// sample current vCPU time and remember it
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
// set up timeout timer for T2
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
[this]() {
this->assert_t2_int();
}
);
this->t2_active = true;
break;
case VIA_SR:
this->_via_ifr &= ~VIA_IF_SR;
update_irq();
break;
default:
this->via_regs[reg & 0xF] = value;
}
}
uint16_t ViaCuda::calc_counter_val(const uint16_t last_val, const uint64_t& last_time)
{
// calcualte current counter value based on elapsed time and timer frequency
uint64_t cur_time = TimerManager::get_instance()->current_time_ns();
uint32_t diff = (cur_time - last_time) / this->via_clk_dur;
return last_val - diff;
}
void ViaCuda::print_enabled_ints() {
const char* via_int_src[] = {"CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1"};
for (int i = 0; i < 7; i++) {
if (this->_via_ier & (1 << i))
if (this->via_regs[VIA_IER] & (1 << i))
LOG_F(INFO, "VIA %s interrupt enabled", via_int_src[i]);
}
}
inline void ViaCuda::update_irq() {
uint8_t new_irq = !!(this->_via_ifr & this->_via_ier & 0x7F);
this->_via_ifr = (this->_via_ifr & 0x7F) | (new_irq << 7);
if (new_irq != this->irq) {
this->irq = new_irq;
this->int_ctrl->ack_int(this->irq_id, new_irq);
}
}
inline bool ViaCuda::ready() {
return ((this->via_regs[VIA_DIRB] & 0x38) == 0x30);
}
void ViaCuda::assert_sr_int() {
this->sr_timer_on = false;
this->_via_ifr |= VIA_IF_SR;
update_irq();
}
void ViaCuda::assert_t1_int() {
this->_via_ifr |= VIA_IF_T1;
this->t1_active = false;
update_irq();
}
void ViaCuda::assert_t2_int() {
this->_via_ifr |= VIA_IF_T2;
this->t2_active = false;
update_irq();
}
void ViaCuda::assert_ctrl_line(ViaLine line)
{
switch (line) {
case ViaLine::CA1:
this->_via_ifr |= VIA_IF_CA1;
break;
case ViaLine::CA2:
this->_via_ifr |= VIA_IF_CA2;
break;
case ViaLine::CB1:
this->_via_ifr |= VIA_IF_CB1;
break;
case ViaLine::CB2:
this->_via_ifr |= VIA_IF_CB1;
break;
default:
ABORT_F("Assertion of unknown VIA line requested!");
}
update_irq();
}
void ViaCuda::schedule_sr_int(uint64_t timeout_ns) {
if (this->sr_timer_on) {
TimerManager::get_instance()->cancel_timer(this->sr_timer_id);
this->sr_timer_on = false;
}
this->sr_timer_id = TimerManager::get_instance()->add_oneshot_timer(
timeout_ns,
[this]() { this->assert_sr_int(); });
this->sr_timer_on = true;
inline void ViaCuda::assert_sr_int() {
this->via_regs[VIA_IFR] |= 0x84;
}
void ViaCuda::write(uint8_t new_state) {
@@ -351,24 +204,18 @@ void ViaCuda::write(uint8_t new_state) {
this->out_count = 0;
}
// send dummy byte as idle acknowledge or attention
//assert_sr_int();
schedule_sr_int(USECS_TO_NSECS(61));
assert_sr_int(); /* send dummy byte as idle acknowledge or attention */
} else {
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
if (this->in_count < sizeof(this->in_buf)) {
if (this->in_count < 16) {
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
// tell the system we've read the byte after 71 usecs
schedule_sr_int(USECS_TO_NSECS(71));
//assert_sr_int();
assert_sr_int(); /* tell the system we've read the data */
} else {
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
}
} else { /* data transfer: Cuda --> Host */
(this->*out_handler)();
//assert_sr_int();
// tell the system we've written next byte after 88 usecs
schedule_sr_int(USECS_TO_NSECS(88));
assert_sr_int(); /* tell the system we've written the data */
}
}
}
@@ -465,10 +312,10 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
} else if ((cmd & 0xC) == 8) {
LOG_F(9, "Cuda: ADB Listen command requested");
int adb_reg = cmd_byte & 0x3;
if (adb_bus->listen(adb_dev, adb_reg)) {
if (adb_obj->listen(adb_dev, adb_reg)) {
response_header(CUDA_PKT_ADB, 0);
for (int data_ptr = 0; data_ptr < adb_bus->get_output_len(); data_ptr++) {
this->in_buf[(2 + data_ptr)] = adb_bus->get_output_byte(data_ptr);
for (int data_ptr = 0; data_ptr < adb_obj->get_output_len(); data_ptr++) {
this->in_buf[(2 + data_ptr)] = adb_obj->get_output_byte(data_ptr);
}
} else {
response_header(CUDA_PKT_ADB, 2);
@@ -477,7 +324,7 @@ void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
LOG_F(9, "Cuda: ADB Talk command requested");
response_header(CUDA_PKT_ADB, 0);
int adb_reg = cmd_byte & 0x3;
if (adb_bus->talk(adb_dev, adb_reg, this->in_buf[2])) {
if (adb_obj->talk(adb_dev, adb_reg, this->in_buf[2])) {
response_header(CUDA_PKT_ADB, 0);
} else {
response_header(CUDA_PKT_ADB, 2);
+37 -79
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -21,10 +21,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/** VIA-CUDA combo device emulation.
Author: Max Poliakovski 2019
Versatile interface adapter (VIA) is an old I/O controller that can be found
in nearly every Macintosh computer. In the 68k era, VIA was used to control
various peripheral devices. In a Power Macintosh, its function is limited
to the I/O interface with the Cuda MCU. I therefore decided to put VIA
various peripherial devices. In a Power Macintosh, its function is limited
to the I/O interface for the Cuda MCU. I therefore decided to put VIA
emulation code here.
Cuda MCU is a multipurpose IC built around a custom version of the Motorola
@@ -45,14 +47,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/common/adb/adb.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/common/i2c/i2c.h>
#include <devices/common/nvram.h>
#include <memory>
#define VIA_CLOCK_HZ 783360
/** VIA register offsets. */
enum {
VIA_B = 0x00, /* input/output register B */
@@ -73,22 +72,18 @@ enum {
VIA_ANH = 0x0F, /* input/output register A, no handshake */
};
/** VIA interrupt flags */
enum {
VIA_IF_CA2 = 1 << 0,
VIA_IF_CA1 = 1 << 1,
VIA_IF_SR = 1 << 2,
VIA_IF_CB2 = 1 << 3,
VIA_IF_CB1 = 1 << 4,
VIA_IF_T2 = 1 << 5,
VIA_IF_T1 = 1 << 6
};
enum class ViaLine {
CA1,
CA2,
CB1,
CB2
/** IFR and IER register bits */
enum {
IER_SET = 0x80,
IER_CLR = 0x00,
IFR_CA2 = 0x01,
IFR_CA1 = 0x02,
IFR_SR = 0x04,
IFR_CB2 = 0x08,
IFR_CB1 = 0x10,
IFR_T2 = 0x20,
IFR_T1 = 0x40,
};
/** Cuda communication signals. */
@@ -140,8 +135,6 @@ enum {
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
};
#define CUDA_IN_BUF_SIZE 256
/** PRAM addresses within Cuda's internal memory */
#define CUDA_PRAM_START 0x100 // starting address of PRAM
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
@@ -156,55 +149,28 @@ public:
ViaCuda();
~ViaCuda() = default;
// HWComponent methods
int device_postinit();
bool supports_type(HWCompType type) {
return (type == HWCompType::ADB_HOST || type == HWCompType::I2C_HOST);
};
uint8_t read(int reg);
void write(int reg, uint8_t value);
void assert_ctrl_line(ViaLine line);
private:
// VIA virtual HW registers
uint8_t via_regs[16];
float via_clk_dur; // one VIA clock duration = 1,27655 us
// VIA internal state
uint32_t sr_timer_id = 0;
bool sr_timer_on = false;
// timer 1 state
bool t1_active;
uint16_t t1_counter;
uint32_t t1_timer_id = 0;
uint64_t t1_start_time = 0;
// timer 2 state
bool t2_active;
uint16_t t2_counter;
uint32_t t2_timer_id = 0;
uint64_t t2_start_time = 0;
// VIA interrupt related stuff
InterruptCtrl* int_ctrl;
uint32_t irq_id;
uint8_t _via_ifr;
uint8_t _via_ier;
uint8_t irq;
uint8_t via_regs[16]; /* VIA virtual registers */
/* Cuda state. */
uint8_t old_tip;
uint8_t old_byteack;
uint8_t treq;
uint8_t in_buf[CUDA_IN_BUF_SIZE];
int32_t in_count;
uint8_t out_buf[16];
int32_t out_count;
int32_t out_pos;
uint8_t poll_rate;
int32_t real_time = 0;
bool file_server;
uint8_t old_tip;
uint8_t old_byteack;
uint8_t treq;
uint8_t in_buf[16];
int32_t in_count;
uint8_t out_buf[16];
int32_t out_count;
int32_t out_pos;
uint8_t poll_rate;
int32_t real_time = 0;
bool file_server;
uint16_t device_mask = 0;
bool is_open_ended; // true if current transaction is open-ended
@@ -214,22 +180,14 @@ private:
void (ViaCuda::*out_handler)(void);
void (ViaCuda::*next_out_handler)(void);
std::unique_ptr<NVram> pram_obj;
std::unique_ptr<ADB_Bus> adb_bus;
std::unique_ptr<NVram> pram_obj;
ADB_Bus* adb_obj;
// VIA methods
void print_enabled_ints(); // print enabled VIA interrupts and their sources
void init_ints();
void update_irq();
void assert_sr_int();
void assert_t1_int();
void assert_t2_int();
void schedule_sr_int(uint64_t timeout_ns);
uint16_t calc_counter_val(const uint16_t last_val, const uint64_t& last_time);
void print_enabled_ints(); /* print enabled VIA interrupts and their sources */
// CUDA methods
void cuda_init();
void init();
bool ready();
void assert_sr_int();
void write(uint8_t new_state);
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
void error_response(uint32_t error);
-258
View File
@@ -1,258 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Support for reading and writing of various floppy images. */
#include "floppyimg.h"
#include <loguru.hpp>
#include <memaccess.h>
#include <cinttypes>
#include <cstring>
#include <fstream>
#include <string>
static FlopImgType identify_image(std::ifstream& img_file)
{
// WOZ images identification strings
static uint8_t WOZ1_SIG[] = {0x57, 0x4F, 0x5A, 0x31, 0xFF, 0x0A, 0x0D, 0x0A};
static uint8_t WOZ2_SIG[] = {0x57, 0x4F, 0x5A, 0x32, 0xFF, 0x0A, 0x0D, 0x0A};
uint8_t buf[8] = { 0 };
img_file.seekg(0, std::ios::beg);
img_file.read((char *)buf, sizeof(buf));
// WOZ files are easily identified
if (!std::memcmp(buf, WOZ1_SIG, sizeof(buf))) {
return FlopImgType::WOZ1;
} else if (!std::memcmp(buf, WOZ2_SIG, sizeof(buf))) {
return FlopImgType::WOZ2;
} else {
for (int offset = 0; offset <=84; offset += 84) {
// rewind to logical block 2
img_file.seekg(2*BLOCK_SIZE + offset, std::ios::beg);
img_file.read((char *)buf, sizeof(buf));
// check for HFS/MFS signature at the start of the logical block 2
if ((buf[0] == 0x42 && buf[1] == 0x44) ||
(buf[0] == 0xD2 && buf[1] == 0xD7)) {
if (offset) {
return FlopImgType::DC42;
} else {
return FlopImgType::RAW;
}
}
}
}
return FlopImgType::UNKNOWN;
}
static int64_t get_hfs_vol_size(const uint8_t *mdb_data)
{
uint16_t drNmAlBlks = READ_WORD_BE_A(&mdb_data[18]);
uint32_t drAlBlkSiz = READ_DWORD_BE_A(&mdb_data[20]);
// calculate size of the volume bitmap
uint32_t vol_bmp_size = (((drNmAlBlks + 8) >> 3) + 512) & 0xFFFFFE00UL;
return (drNmAlBlks * drAlBlkSiz + vol_bmp_size + 3*BLOCK_SIZE);
}
//======================= RAW IMAGE CONVERTER ============================
RawFloppyImg::RawFloppyImg(std::string& file_path) : FloppyImgConverter()
{
this->img_path = file_path;
}
/** For raw images, we're going to ensure that the data fits into
one of the supported floppy disk sizes as well as image size
matches the size of the embedded HFS/MFS volume.
Then we'll attempt to guess disk format based on image size.
*/
int RawFloppyImg::calc_phys_params()
{
std::ifstream img_file;
img_file.open(img_path, std::ios::in | std::ios::binary);
if (img_file.fail()) {
img_file.close();
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
return -1;
}
// determine image size
img_file.seekg(0, img_file.end);
this->img_size = img_file.tellg();
img_file.seekg(0, img_file.beg);
// verify image size
if (this->img_size < 5*BLOCK_SIZE) {
img_file.close();
LOG_F(ERROR, "RawFloppyImg: image too short!");
return -1;
}
if (this->img_size > MFM_HD_SIZE) {
img_file.close();
LOG_F(ERROR, "RawFloppyImg: image too big!");
return -1;
}
// read Master Directory Block from logical block 2
uint8_t buf[512] = { 0 };
img_file.seekg(2*BLOCK_SIZE, img_file.beg);
img_file.read((char *)buf, sizeof(buf));
img_file.close();
uint64_t vol_size = 0;
if (buf[0] == 0x42 && buf[1] == 0x44) {
// check HFS volume size
vol_size = get_hfs_vol_size(buf);
} else if (buf[0] == 0xD2 && buf[1] == 0xD7) {
// check MFS volume size
} else {
LOG_F(ERROR, "RawFloppyImg: unknown volume type!");
return -1;
}
if (vol_size > this->img_size) {
LOG_F(INFO, "RawFloppyImg: volume size > image size!");
LOG_F(INFO, "Volume size: %llu, Image size: %d", vol_size, this->img_size);
return -1;
}
// raw images don't include anything than raw disk data
this->data_size = this->img_size;
// guess disk format from image file size
static struct {
int capacity;
int rec_method;
int num_tracks;
int num_sectors;
int num_sides;
int density;
} size_to_params[] = {
{ 409600, 0, 80, 800, 1, 0}, // 400K GCR
{ 819200, 0, 80, 800, 2, 0}, // 800K GCR
{ 737280, 1, 80, 1440, 2, 0}, // 720K MFM
{1474560, 1, 80, 2880, 2, 1}, // 1440K MFM
};
this->rec_method = -1;
for (int i = 0; i < 4; i++) {
if (this->img_size == size_to_params[i].capacity) {
this->rec_method = size_to_params[i].rec_method;
this->num_tracks = size_to_params[i].num_tracks;
this->num_sectors = size_to_params[i].num_sectors;
this->num_sides = size_to_params[i].num_sides;
this->density = size_to_params[i].density;
// fake format byte for GCR disks
if (!this->rec_method) {
this->format_byte = (this->num_sides == 2) ? 0x22 : 0x2;
} else {
// For MFM disks this byte indicates sector size in blocks
this->format_byte = 2;
}
break;
}
}
if (this->rec_method == -1) {
LOG_F(ERROR, "RawFloppyImg: could't determine disk format from image size!");
return -1;
}
return 0;
}
/** Retrieve raw disk data. */
int RawFloppyImg::get_raw_disk_data(char* buf)
{
std::ifstream img_file;
img_file.open(img_path, std::ios::in | std::ios::binary);
if (img_file.fail()) {
img_file.close();
LOG_F(ERROR, "RawFloppyImg: Could not open specified floppy image!");
return -1;
}
img_file.seekg(0, img_file.beg);
img_file.read(buf, this->data_size);
img_file.close();
return 0;
}
/** Convert low-level disk data to high-level image data. */
int RawFloppyImg::export_data()
{
return 0;
}
FloppyImgConverter* open_floppy_image(std::string& img_path)
{
FloppyImgConverter *fconv;
std::ifstream img_file;
img_file.open(img_path, std::ios::in | std::ios::binary);
if (img_file.fail()) {
img_file.close();
LOG_F(ERROR, "Could not open specified floppy image!");
return nullptr;
}
FlopImgType itype = identify_image(img_file);
img_file.close();
switch(itype) {
case FlopImgType::RAW:
LOG_F(INFO, "Raw floppy image");
fconv = new RawFloppyImg(img_path);
break;
case FlopImgType::DC42:
LOG_F(INFO, "Disk Copy 4.2 image");
break;
case FlopImgType::WOZ1:
case FlopImgType::WOZ2:
LOG_F(INFO, "WOZ v%s image\n", (itype == FlopImgType::WOZ2) ? "2" : "1");
break;
default:
LOG_F(ERROR, "Unknown/unsupported image format!");
return nullptr;
}
if (fconv->calc_phys_params()) {
delete fconv;
return nullptr;
}
return fconv;
}
-87
View File
@@ -1,87 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Definitions for working with various floppy images. */
#ifndef FLOPPY_IMG_H
#define FLOPPY_IMG_H
#include <cinttypes>
#include <string>
#define BLOCK_SIZE 512 // size in bytes of a logical block
#define MFM_HD_SIZE (BLOCK_SIZE*2880) // maximal size of a high-density floppy
/** Floppy image types. */
enum class FlopImgType {
RAW, // raw image without metadata or low-level formatting
DC42, // Disk Copy 4.2 image
WOZ1, // WOZ v1 image with metadata and low-level data retained
WOZ2, // WOZ v2 image with metadata and low-level data retained
UNKNOWN, // invalid/unknown image format
};
/** Interface for floppy image converters. */
class FloppyImgConverter {
public:
FloppyImgConverter() = default;
virtual ~FloppyImgConverter() = default;
virtual int calc_phys_params(void) = 0;
virtual int get_raw_disk_data(char* buf) = 0;
virtual int export_data(void) = 0;
int get_data_size() { return this->data_size; };
int get_disk_rec_method() { return this->rec_method; };
int get_number_of_tracks() { return this->num_tracks; };
int get_number_of_sides() { return this->num_sides; };
int get_sectors_per_side() { return this->num_sectors; };
int get_rec_density() { return this->density; };
uint8_t get_format_byte() { return this->format_byte; };
protected:
std::string img_path;
int img_size;
int data_size; // disk data size without image format specific stuff
int rec_method;
int num_tracks;
int num_sides;
int num_sectors;
int density;
uint8_t format_byte; // GCR format byte from sector header
};
/** Converter for raw floppy images. */
class RawFloppyImg : public FloppyImgConverter {
public:
RawFloppyImg(std::string& file_path);
~RawFloppyImg() = default;
int calc_phys_params(void);
int get_raw_disk_data(char* buf);
int export_data(void);
};
extern FloppyImgConverter* open_floppy_image(std::string& img_path);
#endif // FLOPPY_IMG_H
-256
View File
@@ -1,256 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Macintosh Superdrive emulation. */
#include <devices/floppy/floppyimg.h>
#include <devices/floppy/superdrive.h>
#include <loguru.hpp>
#include <cinttypes>
#include <memory>
using namespace MacSuperdrive;
MacSuperDrive::MacSuperDrive()
{
this->name = "Superdrive";
this->supported_types = HWCompType::FLOPPY_DRV;
this->media_kind = MediaKind::high_density;
this->has_disk = 0; // drive is empty
this->eject_latch = 0; // eject latch is off
this->drive_mode = RecMethod::MFM; // assume MFM mode by default
this->motor_stat = 0; // spindle motor is off
this->cur_track = 0; // current head position
this->is_ready = 0; // drive not ready
}
void MacSuperDrive::command(uint8_t addr, uint8_t value)
{
uint8_t new_motor_stat;
LOG_F(9, "Superdrive: command addr=0x%X, value=%d", addr, value);
switch(addr) {
case CommandAddr::Step_Direction:
this->step_dir = value ? -1 : 1;
break;
case CommandAddr::Do_Step:
if (!value) {
this->cur_track += this->step_dir;
if (this->cur_track < 0)
this->cur_track = 0;
this->track_zero = this->cur_track == 0;
}
break;
case CommandAddr::Motor_On_Off:
new_motor_stat = value ^ 1;
if (this->motor_stat != new_motor_stat) {
this->motor_stat = new_motor_stat;
if (new_motor_stat) {
this->is_ready = 1;
LOG_F(INFO, "Superdrive: turn spindle motor on");
} else {
LOG_F(INFO, "Superdrive: turn spindle motor off");
}
}
break;
case CommandAddr::Reset_Eject_Latch:
if (value) {
this->eject_latch = 0;
}
break;
case CommandAddr::Switch_Drive_Mode:
if (this->drive_mode != (value ^ 1)) {
switch_drive_mode(value ^ 1); // reverse logic
this->is_ready = 1;
}
break;
default:
LOG_F(WARNING, "Superdrive: unimplemented command, addr=0x%X", addr);
}
}
uint8_t MacSuperDrive::status(uint8_t addr)
{
LOG_F(9, "Superdrive: status request, addr = 0x%X", addr);
switch(addr) {
case StatusAddr::Step_Status:
return 1; // not sure what should be returned here
case StatusAddr::Motor_Status:
return this->motor_stat ^ 1; // reverse logic
case StatusAddr::Eject_Latch:
return this->eject_latch;
case StatusAddr::Select_Head_0:
this->cur_head = 0;
return 1; // not sure what should be returned here
case StatusAddr::MFM_Support:
return 1; // Superdrive does support MFM encoding scheme
case StatusAddr::Double_Sided:
return 1; // yes, Superdrive is double sided
case StatusAddr::Drive_Exists:
return 0; // tell the world I'm here
case StatusAddr::Disk_In_Drive:
return this->has_disk ^ 1; // reverse logic (active low)!
case StatusAddr::Write_Protect:
return this->wr_protect ^ 1; // reverse logic
case StatusAddr::Track_Zero:
return this->track_zero ^ 1; // reverse logic
case StatusAddr::Select_Head_1:
this->cur_head = 1;
return 1; // not sure what should be returned here
case StatusAddr::Drive_Mode:
return this->drive_mode;
case StatusAddr::Drive_Ready:
return this->is_ready ^ 1; // reverse logic
case StatusAddr::Media_Kind:
return this->media_kind ^ 1; // reverse logic!
default:
LOG_F(WARNING, "Superdrive: unimplemented status request, addr=0x%X", addr);
return 0;
}
}
int MacSuperDrive::insert_disk(std::string& img_path, bool write_flag = 0)
{
if (this->has_disk) {
LOG_F(ERROR, "Superdrive: drive is not empty!");
return -1;
}
FloppyImgConverter* img_conv = open_floppy_image(img_path);
if (img_conv != nullptr) {
this->img_conv = std::unique_ptr<FloppyImgConverter>(img_conv);
set_disk_phys_params();
// allocate memory for raw disk data
this->disk_data = std::unique_ptr<char[]>(new char[this->img_conv->get_data_size()]);
// swallow all raw disk data at once!
this->img_conv->get_raw_disk_data(this->disk_data.get());
// disk is write-enabled by default
this->wr_protect = write_flag;
// everything is set up, let's say we got a disk
this->has_disk = 1;
} else {
this->has_disk = 0;
}
return 0;
}
void MacSuperDrive::set_disk_phys_params()
{
this->rec_method = this->img_conv->get_disk_rec_method();
this->num_tracks = this->img_conv->get_number_of_tracks();
this->num_sides = this->img_conv->get_number_of_sides();
this->media_kind = this->img_conv->get_rec_density();
this->format_byte = this->img_conv->get_format_byte();
switch_drive_mode(this->rec_method);
}
void MacSuperDrive::switch_drive_mode(int mode)
{
if (mode == RecMethod::GCR) {
// Apple GCR speeds per group of 16 tracks
static int gcr_rpm_per_group[5] = {394, 429, 472, 525, 590};
// initialize three lookup tables:
// sectors per track
// rpm per track
// logical block number of the first sector in each track
// for easier navigation
for (int grp = 0, blk_num = 0; grp < 5; grp++) {
for (int trk = 0; trk < 16; trk++) {
this->sectors_per_track[grp * 16 + trk] = 12 - grp;
this->rpm_per_track[grp * 16 + trk] = gcr_rpm_per_group[grp];
this->track2lblk[grp * 16 + trk] = blk_num;
blk_num += (12 - grp) * this->num_sides;
}
}
this->drive_mode = RecMethod::GCR;
} else {
int sectors_per_track = this->media_kind ? 18 : 9;
// MFM disks use constant number of sectors per track
// and the fixed rotational speed of 300 RPM
for (int trk = 0; trk < 80; trk++) {
this->sectors_per_track[trk] = sectors_per_track;
this->rpm_per_track[trk] = 300;
this->track2lblk[trk] = trk * sectors_per_track * 2;
}
this->drive_mode = RecMethod::MFM;
}
}
double MacSuperDrive::get_current_track_delay()
{
return (1.0f / (this->rpm_per_track[this->cur_track] / 60));
}
double MacSuperDrive::get_sector_delay()
{
return this->get_current_track_delay() / this->sectors_per_track[this->cur_track];
}
void MacSuperDrive::init_track_search(int pos)
{
if (pos == -1) {
// pick random sector number
this->cur_sector = this->sectors_per_track[this->cur_track] / 2;
} else {
this->cur_sector = pos;
}
}
SectorHdr MacSuperDrive::next_sector_header()
{
this->cur_sector++;
if (this->cur_sector >= this->sectors_per_track[this->cur_track]) {
this->cur_sector = 0;
}
// MFM sector numbering is 1-based so we need to bump sector number
int sector_num = this->cur_sector + ((this->rec_method == RecMethod::MFM) ? 1 : 0);
return SectorHdr {
this->cur_track,
this->cur_head,
sector_num,
this->format_byte
};
}
char* MacSuperDrive::get_sector_data_ptr(int sector_num)
{
return this->disk_data.get() +
((this->track2lblk[this->cur_track] +
(this->cur_head * this->sectors_per_track[this->cur_track]) +
sector_num - 1) * 512
);
}
-130
View File
@@ -1,130 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Macintosh Superdrive definitions. */
#ifndef MAC_SUPERDRIVE_H
#define MAC_SUPERDRIVE_H
#include <devices/common/hwcomponent.h>
#include <devices/floppy/floppyimg.h>
#include <cinttypes>
#include <memory>
#include <string>
namespace MacSuperdrive {
/** Apple Drive status request addresses. */
enum StatusAddr : uint8_t {
Step_Status = 1,
Motor_Status = 2,
Eject_Latch = 3,
Select_Head_0 = 4,
MFM_Support = 5,
Double_Sided = 6,
Drive_Exists = 7,
Disk_In_Drive = 8,
Write_Protect = 9,
Track_Zero = 0xA,
Select_Head_1 = 0xC,
Drive_Mode = 0xD,
Drive_Ready = 0xE,
Media_Kind = 0xF
};
/** Apple Drive command addresses. */
enum CommandAddr : uint8_t {
Step_Direction = 0,
Do_Step = 1,
Motor_On_Off = 2,
Reset_Eject_Latch = 4,
Switch_Drive_Mode = 5,
};
/** Type of media currently in the drive. */
enum MediaKind : uint8_t {
low_density = 0,
high_density = 1, // 1 or 2 MB disk
};
/** Disk recording method. */
enum RecMethod : int {
GCR = 0,
MFM = 1
};
typedef struct SectorHdr {
int track;
int side;
int sector;
int format;
} SectorHdr;
class MacSuperDrive : public HWComponent {
public:
MacSuperDrive();
~MacSuperDrive() = default;
void command(uint8_t addr, uint8_t value);
uint8_t status(uint8_t addr);
int insert_disk(std::string& img_path, bool write_flag);
double get_current_track_delay();
double get_sector_delay();
void init_track_search(int pos);
SectorHdr next_sector_header();
char* get_sector_data_ptr(int sector_num);
protected:
void set_disk_phys_params();
void switch_drive_mode(int mode);
private:
uint8_t has_disk;
uint8_t eject_latch;
uint8_t motor_stat; // spindle motor status: 1 - on, 0 - off
uint8_t drive_mode; // drive mode: 0 - GCR, 1 - MFM
uint8_t is_ready;
uint8_t track_zero; // 1 - if head is at track zero
int step_dir; // step direction -1/+1
int cur_track; // track number the head is currently at
int cur_head; // current head number: 1 - upper, 0 - lower
int cur_sector; // current sector number
// physical parameters of the currently inserted disk
uint8_t media_kind;
uint8_t wr_protect;
uint8_t format_byte;
int rec_method;
int num_tracks;
int num_sides;
int sectors_per_track[80];
int rpm_per_track[80];
int track2lblk[80]; // convert track number to first logical block number
std::unique_ptr<FloppyImgConverter> img_conv;
std::unique_ptr<char[]> disk_data;
};
}; // namespace MacSuperdrive
#endif // MAC_SUPERDRIVE_H
-323
View File
@@ -1,323 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Sander-Wozniak Machine 3 (SWIM3) emulation. */
#include <core/timermanager.h>
#include <devices/common/hwinterrupt.h>
#include <devices/floppy/superdrive.h>
#include <devices/floppy/swim3.h>
#include <loguru.hpp>
#include <machines/machinebase.h>
#include <cinttypes>
#include <memory>
using namespace Swim3;
Swim3Ctrl::Swim3Ctrl()
{
this->name = "SWIM3";
this->supported_types = HWCompType::FLOPPY_CTRL;
this->setup_reg = 0;
this->mode_reg = 0;
this->int_reg = 0;
this->int_flags = 0;
this->int_mask = 0;
this->error = 0;
this->xfer_cnt = 0;
this->first_sec = 0xFF;
// Attach virtual Superdrive to the internal drive connector
// TODO: make SWIM3/drive wiring user selectable
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
(new MacSuperdrive::MacSuperDrive());
gMachineObj->add_subdevice("Superdrive", this->int_drive.get());
}
int Swim3Ctrl::device_postinit()
{
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SWIM3);
return 0;
};
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
{
uint8_t status_addr, old_int_flags, old_error;
switch(reg_offset) {
case Swim3Reg::Error:
old_error = this->error;
this->error = 0;
return old_error;
case Swim3Reg::Phase:
return this->phase_lines;
case Swim3Reg::Setup:
return this->setup_reg;
case Swim3Reg::Handshake_Mode1:
if (this->mode_reg & 2) { // internal drive?
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
return ((this->int_drive->status(status_addr) & 1) << 2);
}
return 4;
case Swim3Reg::Interrupt_Flags:
old_int_flags = this->int_flags;
this->int_flags = 0; // read from this register clears all flags
update_irq();
return old_int_flags;
case Swim3Reg::Current_Track:
return this->cur_track;
case Swim3Reg::Current_Sector:
return this->cur_sector;
case Swim3Reg::Gap_Format:
return this->format;
case Swim3Reg::First_Sector:
return this->first_sec;
case Swim3Reg::Sectors_To_Xfer:
return this->xfer_cnt;
case Swim3Reg::Interrupt_Mask:
return this->int_mask;
default:
LOG_F(INFO, "SWIM3: reading from 0x%X register", reg_offset);
}
return 0;
}
void Swim3Ctrl::write(uint8_t reg_offset, uint8_t value)
{
uint8_t old_mode_reg;
switch(reg_offset) {
case Swim3Reg::Param_Data:
this->pram = value;
break;
case Swim3Reg::Phase:
this->phase_lines = value & 0xF;
if (value & 8) {
if (this->mode_reg & 2) { // internal drive?
this->int_drive->command(
((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3),
(value >> 2) & 1
);
}
}
break;
case Swim3Reg::Setup:
this->setup_reg = value;
break;
case Swim3Reg::Status_Mode0:
// ones in value clear the corresponding bits in the mode register
if ((this->mode_reg & value) & (SWIM3_GO | SWIM3_GO_STEP)) {
if (value & SWIM3_GO_STEP) {
stop_stepping();
} else {
stop_disk_access();
}
}
this->mode_reg &= ~value;
break;
case Swim3Reg::Handshake_Mode1:
// ones in value set the corresponding bits in the mode register
if ((this->mode_reg ^ value) & (SWIM3_GO | SWIM3_GO_STEP)) {
if (value & SWIM3_GO_STEP) {
start_stepping();
} else {
start_disk_access();
}
}
this->mode_reg |= value;
break;
case Swim3Reg::Step:
this->step_count = value;
break;
case Swim3Reg::Gap_Format:
this->gap_size = value;
break;
case Swim3Reg::First_Sector:
this->first_sec = value;
break;
case Swim3Reg::Sectors_To_Xfer:
this->xfer_cnt = value;
break;
case Swim3Reg::Interrupt_Mask:
this->int_mask = value;
break;
default:
LOG_F(INFO, "SWIM3: writing 0x%X to register 0x%X", value, reg_offset);
}
}
void Swim3Ctrl::update_irq()
{
if (this->mode_reg & SWIM3_INT_ENA) {
uint8_t new_irq = !!(this->int_flags & this->int_mask);
if (new_irq != this->irq) {
this->irq = new_irq;
this->int_ctrl->ack_int(this->irq_id, new_irq);
}
}
}
void Swim3Ctrl::do_step()
{
if (this->mode_reg & SWIM3_GO_STEP && this->step_count) { // are we still stepping?
// instruct the drive to perform single step in current direction
this->int_drive->command(MacSuperdrive::CommandAddr::Do_Step, 0);
if (--this->step_count == 0) {
if (this->step_timer_id) {
this->stop_stepping();
}
this->int_flags |= INT_STEP_DONE;
update_irq();
}
}
}
void Swim3Ctrl::start_stepping()
{
if (!this->step_count) {
LOG_F(WARNING, "SWIM3: step_count is zero while go_step is active!");
return;
}
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
LOG_F(ERROR, "SWIM3: another stepping action is running!");
return;
}
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
LOG_F(ERROR, "SWIM3: stepping attempt while disk access is in progress!");
return;
}
if ((((this->mode_reg & 0x20) >> 3) | (this->phase_lines & 3))
!= MacSuperdrive::CommandAddr::Do_Step) {
LOG_F(WARNING, "SWIM3: invalid command address on the phase lines!");
return;
}
this->mode_reg |= SWIM3_GO_STEP;
// step count > 1 requires periodic task
if (this->step_count > 1) {
this->step_timer_id = TimerManager::get_instance()->add_cyclic_timer(
USECS_TO_NSECS(80),
[this]() {
this->do_step();
}
);
}
// perform the first step immediately
do_step();
}
void Swim3Ctrl::stop_stepping()
{
// cancel stepping task
if (this->step_timer_id) {
TimerManager::get_instance()->cancel_timer(this->step_timer_id);
}
this->step_timer_id = 0;
this->step_count = 0; // not sure this one is required
}
void Swim3Ctrl::start_disk_access()
{
if (this->mode_reg & SWIM3_GO || this->access_timer_id) {
LOG_F(ERROR, "SWIM3: another disk access is running!");
return;
}
if (this->mode_reg & SWIM3_GO_STEP || this->step_timer_id) {
LOG_F(ERROR, "SWIM3: disk access attempt while stepping is in progress!");
return;
}
if (this->mode_reg & SWIM3_WR_MODE) {
LOG_F(ERROR, "SWIM3: writing not implemented yet");
return;
}
this->mode_reg |= SWIM3_GO;
LOG_F(9, "SWIM3: disk access started!");
if (this->first_sec == 0xFF) {
// $FF means no sector to match ->
// generate ID_read interrups as long as the GO bit is set
this->int_drive->init_track_search(-1); // start at random sector
} else {
this->cur_sector = this->first_sec;
}
// HACK: figure out from bits in int_mask register which kind of disk access is requested
if (this->int_mask & INT_ID_READ) { // read address header
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
[this]() {
// get next sector's address field
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
// set up the corresponding SWIM3 registers
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
this->format = addr.format;
// generate ID_read interrupt
this->int_flags |= INT_ID_READ;
update_irq();
}
);
} else { // otherwise, read sector data
this->access_timer_id = TimerManager::get_instance()->add_cyclic_timer(
static_cast<uint64_t>(this->int_drive->get_sector_delay() * NS_PER_SEC + 0.5f),
[this]() {
// transfer sector data over DMA
this->dma_ch->push_data(this->int_drive->get_sector_data_ptr(this->cur_sector), 512);
// get next address field
MacSuperdrive::SectorHdr addr = this->int_drive->next_sector_header();
// set up the corresponding SWIM3 registers
this->cur_track = ((addr.side & 1) << 7) | (addr.track & 0x7F);
this->cur_sector = 0x80 /* CRC/checksum valid */ | (addr.sector & 0x7F);
this->format = addr.format;
if (--this->xfer_cnt == 0) {
this->stop_disk_access();
// generate sector_done interrupt
this->int_flags |= INT_SECT_DONE;
update_irq();
}
}
);
}
}
void Swim3Ctrl::stop_disk_access()
{
// cancel disk access timer
if (this->access_timer_id) {
TimerManager::get_instance()->cancel_timer(this->access_timer_id);
}
this->access_timer_id = 0;
}
-127
View File
@@ -1,127 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Sander-Wozniak Machine 3 (SWIM3) definitions. */
#ifndef SWIM3_H
#define SWIM3_H
#include <devices/common/dmacore.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/hwinterrupt.h>
#include <devices/floppy/superdrive.h>
#include <cinttypes>
#include <memory>
/** SWIM3 registers offsets. */
namespace Swim3 {
enum Swim3Reg : uint8_t {
Data = 0,
Timer = 1,
Error = 2,
Param_Data = 3,
Phase = 4,
Setup = 5,
Status_Mode0 = 6, // read: Status, write: zeroes to the mode register
Handshake_Mode1 = 7, // read: Handshake, write: ones to the mode register
Interrupt_Flags = 8,
Step = 9,
Current_Track = 10,
Current_Sector = 11,
Gap_Format = 12,
First_Sector = 13,
Sectors_To_Xfer = 14,
Interrupt_Mask = 15
};
/** Mode register bits. */
enum {
SWIM3_INT_ENA = 0x01,
SWIM3_GO = 0x08,
SWIM3_WR_MODE = 0x10,
SWIM3_GO_STEP = 0x80,
};
/** Interrupt flags. */
enum {
INT_STEP_DONE = 0x02,
INT_ID_READ = 0x04,
INT_SECT_DONE = 0x08,
};
class Swim3Ctrl : public HWComponent {
public:
Swim3Ctrl();
~Swim3Ctrl() = default;
int device_postinit();
// SWIM3 registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
void set_dma_channel(DmaBidirChannel *dma_ch) {
this->dma_ch = dma_ch;
};
protected:
void update_irq();
void start_stepping();
void do_step();
void stop_stepping();
void start_disk_access();
void stop_disk_access();
private:
std::unique_ptr<MacSuperdrive::MacSuperDrive> int_drive;
DmaBidirChannel* dma_ch;
uint8_t setup_reg;
uint8_t mode_reg;
uint8_t error;
uint8_t phase_lines;
uint8_t int_reg;
uint8_t int_flags; // interrupt flags
uint8_t int_mask;
uint8_t pram; // parameter RAM: two nibbles = {late_time, early_time}
uint8_t step_count;
uint8_t cur_track;
uint8_t cur_sector;
uint8_t format; // format byte from the last GCR/MFM address field
uint8_t first_sec;
uint8_t xfer_cnt;
uint8_t gap_size;
int step_timer_id = 0;
int access_timer_id = 0;
// Interrupt related stuff
InterruptCtrl* int_ctrl = nullptr;
uint32_t irq_id = 0;
uint8_t irq = 0;
};
}; // namespace Swim3
#endif // SWIM3_H
+130 -254
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -24,88 +24,134 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Author: Max Poliakovski
*/
#include <core/timermanager.h>
#include <cpu/ppc/ppcemu.h>
#include <cpu/ppc/ppcmmu.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/scsi/sc53c94.h>
#include <devices/common/scsi/ncr53c94.h>
#include <devices/common/viacuda.h>
#include <devices/ethernet/mace.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/amic.h>
#include <devices/serial/escc.h>
#include <machines/machinebase.h>
#include <devices/memctrl/memctrlbase.h>
#include <devices/video/displayid.h>
#include <devices/video/pdmonboard.h>
#include <algorithm>
#include <cinttypes>
#include <loguru.hpp>
#include <memory>
AMIC::AMIC() : MMIODevice()
AMIC::AMIC()
{
this->name = "Apple Memory-mapped I/O Controller";
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
// register I/O devices
this->scsi = std::unique_ptr<Sc53C94> (new Sc53C94());
gMachineObj->add_subdevice("Curio_SCSI0", this->scsi.get());
this->escc = std::unique_ptr<EsccController> (new EsccController());
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
// initialize sound HW
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
// initialize on-board video
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
this->def_vid = std::unique_ptr<PdmOnboardVideo> (new PdmOnboardVideo());
// intialize floppy disk HW
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
this->floppy_dma = std::unique_ptr<AmicFloppyDma> (new AmicFloppyDma());
this->swim3->set_dma_channel(this->floppy_dma.get());
gMachineObj->add_subdevice("SWIM3", this->swim3.get());
}
int AMIC::device_postinit()
{
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
// add memory mapped I/O region for the AMIC control registers
/* add memory mapped I/O region for the AMIC control registers */
if (!mem_ctrl->add_mmio_region(0x50F00000, 0x00040000, this)) {
LOG_F(ERROR, "Couldn't register AMIC registers!");
}
// AMIC drives the VIA CA1 internally to generate 60.15 Hz interrupts
this->pseudo_vbl_tid = TimerManager::get_instance()->add_cyclic_timer(
static_cast<uint64_t>((1.0f/60.15) * NS_PER_SEC + 0.5f),
[this]() {
this->viacuda->assert_ctrl_line(ViaLine::CA1);
});
this->scsi = std::unique_ptr<Ncr53C94> (new Ncr53C94());
this->escc = std::unique_ptr<EsccController> (new EsccController());
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
this->awacs->set_dma_out(this->snd_out_dma.get());
}
bool AMIC::supports_type(HWCompType type) {
if ((type == HWCompType::MMIO_DEV)
|| (type == HWCompType::INT_CTRL)) {
return true;
} else {
return false;
}
}
//Interrupt Register
void AMIC::process_interrupt(uint32_t cookie) {
bool confirm_interrupt = false;
uint32_t bit_field = 0;
if (this->int_ctrl_reg & 0x40) {
confirm_interrupt = true;
}
switch (cookie) {
case DEV_ID::VIA_CUDA:
if (this->viacuda->read(VIA_IFR)) {
bit_field = (1 << VIA1_Interrupt);
confirm_interrupt = true;
}
else if (via2_slot_int_enable || via2_int_enable) {
bit_field = (1 << VIA2_Interrupt);
confirm_interrupt = true;
}
break;
case DEV_ID::SCC_B:
case DEV_ID::SCC_A:
bit_field = (1 << SCC_Interrupt);
confirm_interrupt = true;
break;
case DEV_ID::ETHERNET:
bit_field = (1 << Eth_Interrupt);
confirm_interrupt = true;
break;
case DEV_ID::Swim3_DMA:
case DEV_ID::ETHERNET_DMA_OUT:
case DEV_ID::ETHERNET_DMA_IN:
case DEV_ID::SCC_A_DMA_OUT:
case DEV_ID::SCC_A_DMA_IN:
case DEV_ID::SCC_B_DMA_OUT:
case DEV_ID::SCC_B_DMA_IN:
if (dma_int_reg0) {
bit_field = (1 << DMA_Interrupt);
confirm_interrupt = true;
}
break;
case DEV_ID::SOUND_DMA_OUT:
case DEV_ID::SOUND_DMA_IN:
if (dma_int_reg1) {
bit_field = (1 << DMA_Interrupt);
confirm_interrupt = true;
}
break;
case DEV_ID::NMI:
bit_field = (1 << NMI_Interrupt);
confirm_interrupt = true;
break;
}
if (confirm_interrupt)
ack_interrupt(bit_field);
}
uint32_t AMIC::ack_interrupt(uint32_t device_bits) {
bool confirm_interrupt = false;
bool ack_bit = this->int_ctrl_reg & 0x80;
if (device_bits & this->int_ctrl_reg)
confirm_interrupt = true;
if (confirm_interrupt && ack_bit)
ack_cpu_interrupt();
return 0;
}
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
{
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size) {
uint32_t phase_val;
// subdevices registers
switch(offset >> 12) {
case 0: // VIA1 registers
case 1:
process_interrupt(VIA_CUDA);
return this->viacuda->read(offset >> 9);
case 4: // SCC registers
return this->escc->read((offset >> 1) & 0xF);
this->escc->read_compat((offset >> 1) & 0xF);
this->process_interrupt(SCC_A);
return 0;
case 0xA: // MACE registers
return this->mace->read((offset >> 4) & 0xF);
case 0x10: // SCSI registers
@@ -115,7 +161,7 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
case AMICReg::Snd_Stat_0:
case AMICReg::Snd_Stat_1:
case AMICReg::Snd_Stat_2:
return (this->awacs->read_stat() >> (offset & 3) * 8) & 0xFF;
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
case AMICReg::Snd_Phase0:
case AMICReg::Snd_Phase1:
case AMICReg::Snd_Phase2:
@@ -131,43 +177,18 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
case AMICReg::Snd_Out_DMA:
return this->snd_out_dma->read_stat();
}
break;
case 0x16: // SWIM3 registers
case 0x17:
return this->swim3->read((offset >> 9) & 0xF);
}
switch(offset) {
case AMICReg::Ariel_Config:
return this->def_vid->get_vdac_config();
case AMICReg::VIA2_IFR:
case AMICReg::VIA2_IFR_RBV:
return this->via2_ifr;
case AMICReg::VIA2_IER:
case AMICReg::VIA2_IER_RBV:
return this->via2_ier;
case AMICReg::Video_Mode:
return this->def_vid->get_video_mode();
case AMICReg::Monitor_Id:
return this->mon_id;
case AMICReg::Int_Ctrl:
return (this->int_ctrl & 0xC0) | (this->dev_irq_lines & 0x3F);
case AMICReg::Diag_Reg:
return 0xFFU; // this value allows the machine to boot normally
case AMICReg::DMA_Base_Addr_0:
case AMICReg::DMA_Base_Addr_1:
case AMICReg::DMA_Base_Addr_2:
case AMICReg::DMA_Base_Addr_3:
return (this->dma_base >> (3 - (offset & 3)) * 8) & 0xFF;
case AMICReg::SCSI_DMA_Ctrl:
return this->scsi_dma_cs;
case AMICReg::Floppy_Addr_Ptr_0:
case AMICReg::Floppy_Addr_Ptr_1:
case AMICReg::Floppy_Addr_Ptr_2:
case AMICReg::Floppy_Addr_Ptr_3:
return (this->floppy_addr_ptr >> (3 - (offset & 3)) * 8) & 0xFF;
case AMICReg::Floppy_DMA_Ctrl:
return this->floppy_dma->read_stat();
case AMICReg::Int_Ctrl:
if (this->int_ctrl_reg & 0x80) {
ack_cpu_interrupt();
}
return this->int_ctrl_reg;
default:
LOG_F(WARNING, "Unknown AMIC register read, offset=%x", offset);
}
@@ -185,7 +206,7 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
this->viacuda->write(offset >> 9, value);
return;
case 4:
this->escc->write((offset >> 1) & 0xF, value);
this->escc->write_compat((offset >> 1) & 0xF, value);
return;
case 0xA: // MACE registers
this->mace->write((offset >> 4) & 0xF, value);
@@ -207,12 +228,16 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
);
}
this->process_interrupt(DEV_ID::DAVBUS);
return;
case AMICReg::Snd_Buf_Size_Hi:
case AMICReg::Snd_Buf_Size_Lo:
SET_SIZE_BYTE(this->snd_buf_size, offset, value);
mask = 0xFF00U >> (8 * (offset & 1));
this->snd_buf_size = (this->snd_buf_size & ~mask) |
((value & 0xFF) << (8 * ((offset & 1) ^1)));
this->snd_buf_size &= ~3; // sound buffer size is always a multiple of 4
LOG_F(9, "AMIC: Sound buffer size set to 0x%X", this->snd_buf_size);
this->process_interrupt(DEV_ID::DAVBUS);
return;
case AMICReg::Snd_Out_Ctrl:
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
@@ -236,70 +261,41 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
return;
case AMICReg::Snd_Out_DMA:
this->snd_out_dma->write_dma_out_ctrl(value);
this->dma_int_reg1 |= 0x2;
this->process_interrupt(DEV_ID::SOUND_DMA_OUT);
return;
}
case 0x16: // SWIM3 registers
case 0x17:
this->swim3->write((offset >> 9) & 0xF, value);
return;
}
switch(offset) {
case AMICReg::VIA2_Slot_IER:
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
via2_slot_int_enable = value;
break;
case AMICReg::VIA2_IER:
if (value & 0x80) {
this->via2_ier |= value & 0x7F;
} else {
this->via2_ier &= ~value;
}
LOG_F(INFO, "AMIC VIA2 Interrupt Enable Register updated, val=%x", value);
via2_int_enable = value;
break;
case AMICReg::Ariel_Clut_Index:
this->def_vid->set_clut_index(value);
break;
case AMICReg::Ariel_Clut_Color:
this->def_vid->set_clut_color(value);
break;
case AMICReg::Ariel_Config:
this->def_vid->set_vdac_config(value);
break;
case AMICReg::Video_Mode:
this->def_vid->set_video_mode(value);
break;
case AMICReg::Pixel_Depth:
this->def_vid->set_pixel_depth(value);
break;
case AMICReg::Monitor_Id: {
// extract and convert pin directions (0 - input, 1 - output)
uint8_t dirs = ~value & 7;
if (!dirs && !(value & 8)) {
LOG_F(INFO, "AMIC: Monitor sense lines tristated");
}
// propagate bit 3 to all pins configured as output
// set levels of all intput pins to "1"
uint8_t levels = (7 ^ dirs) | (((value & 8) ? 7 : 0) & dirs);
// read monitor sense lines and store the result in the bits 4-6
this->mon_id = (this->mon_id & 0xF) |
(this->disp_id->read_monitor_sense(levels, dirs) << 4);
}
case AMICReg::Video_Mode_Reg:
LOG_F(INFO, "AMIC Video Mode Register set to %x", value);
break;
case AMICReg::Int_Ctrl:
// reset CPU interrupt bit if requested
if (value & AMIC_INT_CLR) {
this->int_ctrl &= ~AMIC_INT_CLR;
LOG_F(INFO, "AMIC Interrupt Control Register set to %X", value);
if (value & 0x80) {
value &= 0xC0;
ack_cpu_interrupt();
}
// keep interrupt mode bit
// and discard read-only IQR state bits
this->int_ctrl |= value & AMIC_INT_MODE;
this->int_ctrl_reg = value;
break;
case AMICReg::DMA_Base_Addr_0:
case AMICReg::DMA_Base_Addr_1:
case AMICReg::DMA_Base_Addr_2:
case AMICReg::DMA_Base_Addr_3:
SET_ADDR_BYTE(this->dma_base, offset, value);
this->dma_base &= 0xFFFC0000UL;
mask = 0xFF000000UL >> (8 * (offset & 3));
this->dma_base = (this->dma_base & ~mask) |
((value & 0xFF) << (8 * (3 - (offset & 3))));
LOG_F(9, "AMIC: DMA base address set to 0x%X", this->dma_base);
this->process_interrupt(DEV_ID::PERCH_DMA);
break;
case AMICReg::Enet_DMA_Xmt_Ctrl:
LOG_F(INFO, "AMIC Ethernet Transmit DMA Ctrl updated, val=%x", value);
@@ -311,23 +307,8 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
case AMICReg::Enet_DMA_Rcv_Ctrl:
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
break;
case AMICReg::Floppy_Addr_Ptr_2:
case AMICReg::Floppy_Addr_Ptr_3:
SET_ADDR_BYTE(this->floppy_addr_ptr, offset, value);
break;
case AMICReg::Floppy_Byte_Cnt_Hi:
case AMICReg::Floppy_Byte_Cnt_Lo:
SET_SIZE_BYTE(this->floppy_byte_cnt, offset, value);
break;
case AMICReg::Floppy_DMA_Ctrl:
if (value & 1) { // RST bit set?
this->floppy_addr_ptr = this->dma_base + 0x15000;
this->floppy_dma->reset(this->floppy_addr_ptr);
}
if (value & 2) { // RUN bit set?
this->floppy_dma->reinit(this->floppy_addr_ptr, this->floppy_byte_cnt);
}
this->floppy_dma->write_ctrl(value);
case AMICReg::SWIM3_DMA_Ctrl:
LOG_F(INFO, "AMIC SWIM3 DMA Ctrl updated, val=%x", value);
break;
case AMICReg::SCC_DMA_Xmt_A_Ctrl:
LOG_F(INFO, "AMIC SCC Transmit Ch A DMA Ctrl updated, val=%x", value);
@@ -347,76 +328,18 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
}
}
// ======================== Interrupt related stuff ==========================
uint32_t AMIC::register_dev_int(IntSrc src_id) {
switch (src_id) {
case IntSrc::VIA_CUDA:
return 1;
case IntSrc::SCSI1:
return 0x800;
case IntSrc::SWIM3:
return 0x2000;
default:
ABORT_F("AMIC: unknown interrupt source %d", src_id);
}
return 0;
}
uint32_t AMIC::register_dma_int(IntSrc src_id) {
ABORT_F("AMIC: register_dma_int() not implemented");
return 0;
}
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
// dispatch AMIC interrupts from various sources
if (irq_id < 0x100) {
this->ack_cpu_int(irq_id, irq_line_state);
} else if (irq_id < 0x10000) {
this->ack_via2_int(irq_id >> 8, irq_line_state);
} else {
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
}
}
void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
if (irq_line_state) {
this->via2_ifr |= irq_id;
} else {
this->via2_ifr &= ~irq_id;
}
uint8_t new_irq = !!(this->via2_ifr & this->via2_ier & 0x7F);
this->via2_ifr = (this->via2_ifr & 0x7F) | (new_irq << 7);
if (new_irq != this->via2_irq) {
this->via2_irq = new_irq;
this->ack_cpu_int(2, new_irq);
}
}
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
if (this->int_ctrl & AMIC_INT_MODE) { // 68k interrupt emulation mode?
this->int_ctrl |= 0x80; // set CPU interrupt bit
if (irq_line_state) {
this->dev_irq_lines |= irq_id;
} else {
this->dev_irq_lines &= ~irq_id;
}
ppc_ext_int();
} else {
ABORT_F("AMIC: interrupt mode 0 not implemented");
}
}
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
ABORT_F("AMIC: ack_dma_int() not implemented");
}
// ============================ Sound DMA stuff ================================
// =========================== DMA related stuff =============================
AmicSndOutDma::AmicSndOutDma()
{
this->dma_out_ctrl = 0;
this->enabled = false;
}
bool AmicSndOutDma::is_active()
{
return true;
}
void AmicSndOutDma::init(uint32_t buf_base, uint32_t buf_samples)
{
this->out_buf0 = buf_base + AMIC_SND_BUF0_OFFS;
@@ -480,50 +403,3 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
*avail_len = len;
return DmaPullResult::MoreData;
}
// ============================ Floppy DMA stuff ===============================
void AmicFloppyDma::reset(const uint32_t addr_ptr)
{
this->stat &= 0x48; // clear interrupt flag, RUN and RST bits
this->addr_ptr = addr_ptr;
this->byte_count = 0;
}
void AmicFloppyDma::reinit(const uint32_t addr_ptr, const uint16_t byte_cnt)
{
this->addr_ptr = addr_ptr;
this->byte_count = byte_cnt;
}
void AmicFloppyDma::write_ctrl(uint8_t value)
{
// copy over DIR, IE and RUN bits
this->stat = (this->stat & 0x81) | (value & 0x4A);
// clear interrupt flag if requested
if (value & 0x80) {
this->stat &= 0x7F;
}
}
int AmicFloppyDma::push_data(const char* src_ptr, int len)
{
len = std::min((int)this->byte_count, len);
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len);
std::memcpy(p_data, src_ptr, len);
this->addr_ptr += len;
this->byte_count -= len;
if (!this->byte_count) {
LOG_F(WARNING, "AMIC: DMA interrupts not implemented yet");
}
return 0;
}
DmaPullResult AmicFloppyDma::pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data)
{
return DmaPullResult::NoMoreData;
}
+43 -101
View File
@@ -24,30 +24,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef AMIC_H
#define AMIC_H
#include <devices/common/hwinterrupt.h>
#include <devices/common/mmiodevice.h>
#include <devices/common/scsi/sc53c94.h>
#include <devices/common/scsi/ncr53c94.h>
#include <devices/common/viacuda.h>
#include <devices/ethernet/mace.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/interruptctrl.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
#include <devices/video/displayid.h>
#include <devices/video/pdmonboard.h>
#include <cinttypes>
#include <memory>
/** Interrupt related constants. */
#define AMIC_INT_CLR 0x80 // clears CPU interrupt
#define AMIC_INT_MODE 0x40 // interrupt mode: 0 - native, 1 - 68k-style
/** AMIC sound buffers are located at fixed offsets from DMA base. */
#define AMIC_SND_BUF0_OFFS 0x10000
#define AMIC_SND_BUF1_OFFS 0x12000
// PDM HWInit source defines two constants: kExpBit = 0x80 and kCmdBit = 0x40
// I don't know what they mean but it seems that their combination will
// I don't know what they means but it seems that their combination will
// cause sound control parameters to be transferred to the sound chip.
#define PDM_SND_CTRL_VALID 0xC0
@@ -61,6 +54,7 @@ public:
AmicSndOutDma();
~AmicSndOutDma() = default;
bool is_active();
void init(uint32_t buf_base, uint32_t buf_samples);
void enable() { this->enabled = true; };
void disable() { this->enabled = false; };
@@ -81,37 +75,6 @@ private:
uint32_t cur_buf_pos;
};
/** AMIC-specific floppy DMA implementation. */
class AmicFloppyDma : public DmaBidirChannel {
public:
AmicFloppyDma() = default;
~AmicFloppyDma() = default;
void reinit(const uint32_t addr_ptr, const uint16_t byte_cnt);
void reset(const uint32_t addr_ptr);
void write_ctrl(const uint8_t value);
uint8_t read_stat() { return this->stat; };
int push_data(const char* src_ptr, int len);
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
uint8_t **p_data);
private:
uint32_t addr_ptr;
uint16_t byte_count;
uint8_t stat;
};
// macro for byte wise updating of AMIC DMA address registers
#define SET_ADDR_BYTE(reg, offset, value) \
mask = 0xFF000000UL >> (8 * ((offset) & 3)); \
(reg) = ((reg) & ~mask) | (((value) & 0xFF) << (8 * (3 - ((offset) & 3))));
// macro for byte wise updating of AMIC DMA size registers
#define SET_SIZE_BYTE(reg, offset, value) \
mask = 0xFF00U >> (8 * ((offset) & 1)); \
(reg) = ((reg) & ~mask) | (((value) & 0xFF) << (8 * (((offset) & 1) ^ 1)));
/* AMIC registers offsets from AMIC base (0x50F00000). */
enum AMICReg : uint32_t {
// Sound control registers
@@ -131,25 +94,21 @@ enum AMICReg : uint32_t {
Snd_In_DMA = 0x14014, // sound input DMA status/control register
Snd_Out_DMA = 0x14018, // sound output DMA status/control register
// Video DAC (Ariel II) control registers
Ariel_Clut_Index = 0x24000,
Ariel_Clut_Color = 0x24001,
Ariel_Config = 0x24002,
// VIA2 registers
VIA2_IFR = 0x26003,
VIA2_Slot_INT = 0x26002,
VIA2_Slot_IER = 0x26012,
VIA2_INT = 0x26003,
VIA2_IER = 0x26013,
VIA2_IFR_RBV = 0x27A03, // RBV-compatible mirror for the VIA2_IFR
VIA2_IER_RBV = 0x27C13, // RBV-compatible mirror for the VIA2_IER
// Video control registers
Video_Mode = 0x28000,
Pixel_Depth = 0x28001,
Monitor_Id = 0x28002,
Video_Mode_Reg = 0x28000,
// Interrupt registers
Int_Ctrl = 0x2A000,
DMA_Int_0 = 0x2A008,
Bus_Error_Int_0 = 0x2A009,
DMA_Int_1 = 0x2A00A,
Bus_Error_Int_1 = 0x2A00B,
// Undocumented diagnostics register
Diag_Reg = 0x2C000,
@@ -162,84 +121,67 @@ enum AMICReg : uint32_t {
Enet_DMA_Xmt_Ctrl = 0x31C20,
SCSI_DMA_Ctrl = 0x32008,
Enet_DMA_Rcv_Ctrl = 0x32028,
// Floppy (SWIM3) DMA registers
Floppy_Addr_Ptr_0 = 0x32060,
Floppy_Addr_Ptr_1 = 0x32061,
Floppy_Addr_Ptr_2 = 0x32062,
Floppy_Addr_Ptr_3 = 0x32063,
Floppy_Byte_Cnt_Hi = 0x32064,
Floppy_Byte_Cnt_Lo = 0x32065,
Floppy_DMA_Ctrl = 0x32068,
SWIM3_DMA_Ctrl = 0x32068,
SCC_DMA_Xmt_A_Ctrl = 0x32088,
SCC_DMA_Rcv_A_Ctrl = 0x32098,
SCC_DMA_Xmt_B_Ctrl = 0x320A8,
SCC_DMA_Rcv_B_Ctrl = 0x320B8,
};
/** Apple Memory-mapped I/O controller device. */
enum AMICIntReg : uint32_t {
VIA1_Interrupt = 0,
VIA2_Interrupt = 1,
SCC_Interrupt = 2,
Eth_Interrupt = 3,
DMA_Interrupt = 4,
NMI_Interrupt = 5,
INT_Mode = 6,
ACK_Bit = 7,
};
enum {
FDC_PENDING = 0x40,
};
/** Apple Memory-mapped I/O controller device. */
class AMIC : public MMIODevice, public InterruptCtrl {
public:
AMIC();
~AMIC() = default;
// HWComponent methods
int device_postinit();
bool supports_type(HWCompType type);
void process_interrupt(uint32_t cookie);
uint32_t ack_interrupt(uint32_t device_bits);
/* MMIODevice methods */
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
// InterruptCtrl methods
uint32_t register_dev_int(IntSrc src_id);
uint32_t register_dma_int(IntSrc src_id);
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
protected:
void ack_via2_int(uint32_t irq_id, uint8_t irq_line_state);
void ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state);
void dma_reg_write(uint32_t offset, uint32_t value, int size);
private:
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
uint32_t dma_base = 0; // DMA physical base address
uint16_t snd_buf_size = 0; // sound buffer size in bytes
uint8_t snd_out_ctrl = 0;
uint32_t dma_base = 0; // DMA physical base address
uint16_t snd_buf_size = 0; // sound buffer size in bytes
uint8_t snd_out_ctrl = 0;
// floppy DMA state
uint32_t floppy_addr_ptr;
uint16_t floppy_byte_cnt;
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
uint8_t int_ctrl = 0;
uint8_t dev_irq_lines = 0; // state of the IRQ lines
// pseudo VIA2 state
uint8_t via2_ier = 0;
uint8_t via2_ifr = 0;
uint8_t via2_irq = 0;
uint32_t pseudo_vbl_tid; // ID for the pseudo-VBL timer
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
uint8_t int_ctrl_reg = 0;
uint8_t dma_int_reg0 = 0;
uint8_t dma_int_reg1 = 0;
uint8_t via2_int_enable = 0;
uint8_t via2_slot_int_enable = 0;
// AMIC subdevices instances
std::unique_ptr<Sc53C94> scsi;
std::unique_ptr<Ncr53C94> scsi;
std::unique_ptr<EsccController> escc;
std::unique_ptr<MaceController> mace;
std::unique_ptr<ViaCuda> viacuda;
std::unique_ptr<AwacDevicePdm> awacs;
std::unique_ptr<AmicSndOutDma> snd_out_dma;
std::unique_ptr<AmicFloppyDma> floppy_dma;
// on-board video
std::unique_ptr<DisplayID> disp_id;
std::unique_ptr<PdmOnboardVideo> def_vid;
uint8_t mon_id;
std::unique_ptr<Swim3::Swim3Ctrl> swim3;
};
#endif // AMIC_H
+85 -50
View File
@@ -21,10 +21,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/dbdma.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/viacuda.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/macio.h>
#include <devices/ioctrl/interruptctrl.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
#include <endianswap.h>
@@ -44,8 +43,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
this->nvram = std::unique_ptr<NVram> (new NVram());
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
@@ -60,11 +57,40 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
std::bind(&AwacsScreamer::dma_end, this->screamer.get())
);
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
this->escc = std::unique_ptr<EsccController> (new EsccController());
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
this->escc = std::unique_ptr<EsccController>(new EsccController());
}
uint32_t HeathrowIC::register_device(DEV_ID dev_id){
return (1 << dev_id);
};
void HeathrowIC::process_interrupt(uint32_t cookie) {
bool confirm_interrupt = false;
uint32_t bit_field = 0;
switch (cookie) {
case DEV_ID::SOUND_DMA_OUT:
bit_field = (1 << DEV_ID::SOUND_DMA_OUT);
break;
case DEV_ID::SCSI0:
bit_field = (1 << DEV_ID::SCSI0);
break;
case DEV_ID::VIA_CUDA:
bit_field = (1 << DEV_ID::VIA_CUDA);
break;
case DEV_ID::SWIM3:
bit_field = (1 << DEV_ID::SWIM3);
break;
case DEV_ID::DAVBUS:
bit_field = (1 << DEV_ID::DAVBUS);
break;
}
if (confirm_interrupt)
ack_interrupt(bit_field);
};
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
return this->pci_cfg_hdr[reg_offs & 0xFF];
}
@@ -98,6 +124,7 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
switch (offset >> 8) {
case 8:
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
this->ack_interrupt(DEV_ID::SOUND_DMA_OUT);
break;
default:
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
@@ -134,18 +161,13 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
case 0x10:
res = this->mesh->read((offset >> 4) & 0xF);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
return this->escc->read((offset >> 1) & 0xF);
}
// fallthrough
case 0x13: // ESCC MacRISC addressing
case 0x12: // ESCC compatible
return this->escc->read_compat((offset >> 4) & 0xF);
case 0x13: // ESCC MacRISC
return this->escc->read((offset >> 4) & 0xF);
case 0x14:
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
break;
case 0x15: // SWIM3
return this->swim3->read(offset & 0xF);
case 0x16:
case 0x17:
res = this->viacuda->read((offset - 0x16000) >> 9);
@@ -175,25 +197,22 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
break;
case 0x10:
this->mesh->write((offset >> 4) & 0xF, value);
this->process_interrupt(DEV_ID::SCSI0);
break;
case 0x12: // ESCC compatible addressing
if ((offset & 0xFF) < 16) {
this->escc->write((offset >> 1) & 0xF, value);
break;
}
// fallthrough
case 0x13: // ESCC MacRISC addressing
case 0x12: // ESCC compatible
this->escc->write_compat((offset >> 4) & 0xF, value);
break;
case 0x13: // ESCC MacRISC
this->escc->write((offset >> 4) & 0xF, value);
break;
case 0x14:
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
break;
case 0x15:
this->swim3->write(offset & 0xF, value);
this->process_interrupt(DEV_ID::DAVBUS);
break;
case 0x16:
case 0x17:
this->viacuda->write((offset - 0x16000) >> 9, value);
this->process_interrupt(DEV_ID::VIA_CUDA);
break;
default:
if (sub_addr >= 0x60) {
@@ -208,29 +227,37 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
uint32_t res = 0;
switch (offset & 0xFC) {
case 0x10:
LOG_F(0, "read from MIO:Int_Events2 register \n");
res = this->retrieve_reg(REG_ID::events2);
break;
case 0x14:
LOG_F(9, "read from MIO:Int_Mask2 register \n");
res = this->int_mask2;
LOG_F(0, "read from MIO:Int_Mask2 register \n");
res = this->retrieve_reg(REG_ID::mask2);
break;
case 0x18:
LOG_F(9, "read from MIO:Int_Clear2 register \n");
res = this->int_clear2;
LOG_F(0, "read from MIO:Int_Clear2 register \n");
res = this->retrieve_reg(REG_ID::clear2);
break;
case 0x1C:
LOG_F(9, "read from MIO:Int_Levels2 register \n");
res = this->int_levels2;
LOG_F(0, "read from MIO:Int_Levels2 register \n");
res = this->retrieve_reg(REG_ID::levels2);
break;
case 0x20:
LOG_F(0, "read from MIO:Int_Events1 register \n");
res = this->retrieve_reg(REG_ID::events1);
break;
case 0x24:
LOG_F(9, "read from MIO:Int_Mask1 register \n");
res = this->int_mask1;
LOG_F(0, "read from MIO:Int_Mask1 register \n");
res = this->retrieve_reg(REG_ID::mask1);
break;
case 0x28:
LOG_F(9, "read from MIO:Int_Clear1 register \n");
res = this->int_clear1;
LOG_F(0, "read from MIO:Int_Clear1 register \n");
res = this->retrieve_reg(REG_ID::clear1);
break;
case 0x2C:
LOG_F(9, "read from MIO:Int_Levels1 register \n");
res = this->int_levels1;
LOG_F(0, "read from MIO:Int_Levels1 register \n");
res = this->retrieve_reg(REG_ID::levels1);
break;
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
@@ -250,29 +277,37 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
switch (offset & 0xFC) {
case 0x10:
LOG_F(0, "write %x to MIO:Int_Events2 register \n", value);
this->update_reg(REG_ID::events2, value);
break;
case 0x14:
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
this->int_mask2 = value;
LOG_F(0, "write %x to MIO:Int_Mask2 register \n", value);
this->update_reg(REG_ID::mask2, value);
break;
case 0x18:
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
this->int_clear2 = value;
LOG_F(0, "write %x to MIO:Int_Clear2 register \n", value);
this->update_reg(REG_ID::clear2, value);
break;
case 0x1C:
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
this->int_levels2 = value;
LOG_F(0, "write %x to MIO:Int_Levels2 register \n", value);
this->update_reg(REG_ID::levels2, value);
break;
case 0x20:
LOG_F(0, "write %x to MIO:Int_Events1 register \n", value);
this->update_reg(REG_ID::events1, value);
break;
case 0x24:
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
this->int_mask1 = value;
LOG_F(0, "write %x to MIO:Int_Mask1 register \n", value);
this->update_reg(REG_ID::mask1, value);
break;
case 0x28:
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
this->int_clear1 = value;
LOG_F(0, "write %x to MIO:Int_Clear1 register \n", value);
this->update_reg(REG_ID::clear1, value);
break;
case 0x2C:
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
this->int_levels1 = value;
LOG_F(0, "write %x to MIO:Int_Levels1 register \n", value);
this->update_reg(REG_ID::levels1, value);
break;
case 0x34:
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
@@ -292,7 +327,7 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
void HeathrowIC::feature_control(const uint32_t value)
{
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
LOG_F(0, "write %x to MIO:Feat_Ctrl register \n", value);
this->feat_ctrl = value;
+108
View File
@@ -0,0 +1,108 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <cpu/ppc/ppcemu.h>
#include <devices/ioctrl/interruptctrl.h>
#include <cinttypes>
#include <string>
#include <loguru.hpp>
using namespace std;
InterruptCtrl::InterruptCtrl() {
}
void InterruptCtrl::update_reg(REG_ID retrieve_reg, uint32_t bit_setting) {
switch (retrieve_reg) {
case mask1:
int_mask1 = bit_setting;
break;
case clear1:
int_clear1 = bit_setting;
int_events1 &= ~int_clear1;
break;
case events1:
int_events1 = bit_setting;
break;
case levels1:
int_levels1 = bit_setting;
break;
case mask2:
int_mask2 = bit_setting;
break;
case clear2:
int_clear2 = bit_setting;
int_events2 &= ~int_clear2;
break;
case events2:
int_events2 = bit_setting;
break;
case levels2:
int_levels2 = bit_setting;
break;
}
}
uint32_t InterruptCtrl::retrieve_reg(REG_ID retrieve_reg) {
switch (retrieve_reg) {
case mask1:
return int_mask1;
break;
case clear1:
return int_clear1;
break;
case events1:
return int_events1;
break;
case levels1:
return int_levels1;
break;
case mask2:
return int_mask2;
break;
case clear2:
return int_clear2;
break;
case events2:
return int_events2;
break;
case levels2:
return int_levels2;
break;
}
}
uint32_t InterruptCtrl::ack_interrupt(uint32_t device_bits) {
bool confirm_interrupt = false;
int_events1 |= device_bits;
if (int_events1 & int_mask1)
confirm_interrupt = true;
if (confirm_interrupt)
ack_cpu_interrupt();
return 0;
}
void InterruptCtrl::ack_cpu_interrupt() {
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0x0);
}
+97
View File
@@ -0,0 +1,97 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef HWINTERRUPT_H
#define HWINTERRUPT_H
#include <devices/common/hwcomponent.h>
#include <cinttypes>
#include <memory>
enum DEV_ID {
SCSI_DMA = 0,
Swim3_DMA = 1,
IDE0_DMA = 2,
IDE1_DMA = 3,
SCC_A_DMA_OUT = 4,
SCC_A_DMA_IN = 5,
SCC_B_DMA_OUT = 6,
SCC_B_DMA_IN = 7,
SOUND_DMA_OUT = 8,
SOUND_DMA_IN = 9,
VIDEO_OUT = 10,
VIDEO_IN = 11,
SCSI0 = 12,
IDE0 = 13,
IDE1 = 14,
SCC_A = 15,
SCC_B = 16,
DAVBUS = 17,
VIA_CUDA = 18,
SWIM3 = 19,
NMI = 20,
PERCH_DMA = 21,
PERCH = 22,
ETHERNET_DMA_OUT = 23,
ETHERNET_DMA_IN = 24,
ETHERNET = 25,
SCSI1 = 26,
};
enum REG_ID {
mask1 = 0,
clear1 = 1,
events1 = 2,
levels1 = 3,
mask2 = 4,
clear2 = 5,
events2 = 6,
levels2 = 7,
};
class InterruptCtrl {
public:
InterruptCtrl();
~InterruptCtrl() = default;
uint32_t ack_interrupt(uint32_t device_bits);
virtual uint32_t register_device(DEV_ID dev_id){
return 0;
};
void update_reg(REG_ID retrieve_reg, uint32_t bit_setting);
uint32_t retrieve_reg(REG_ID retrieve_reg);
void ack_cpu_interrupt();
protected:
uint32_t int_events1 = 0;
uint32_t int_mask1 = 0;
uint32_t int_clear1 = 0;
uint32_t int_levels1 = 0;
uint32_t int_events2 = 0;
uint32_t int_mask2 = 0;
uint32_t int_clear2 = 0;
uint32_t int_levels2 = 0;
};
#endif /* HWINTERRUPT_H */
+18 -15
View File
@@ -52,13 +52,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#define MACIO_H
#include <devices/common/dbdma.h>
#include <devices/common/hwcomponent.h>
#include <devices/common/mmiodevice.h>
#include <devices/common/nvram.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h>
#include <devices/common/scsi/mesh.h>
#include <devices/common/viacuda.h>
#include <devices/floppy/swim3.h>
#include <devices/ioctrl/interruptctrl.h>
#include <devices/memctrl/memctrlbase.h>
#include <devices/serial/escc.h>
#include <devices/sound/awacs.h>
@@ -92,11 +93,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
VIA-CUDA register space: 0x00016000, size: 0x00002000
*/
class HeathrowIC : public PCIDevice {
class HeathrowIC : public PCIDevice,
public InterruptCtrl {
public:
HeathrowIC();
~HeathrowIC() = default;
bool supports_type(HWCompType type) {
return (type == HWCompType::MMIO_DEV) || (type == HWCompType::INT_CTRL);
};
/* PCI device methods */
bool supports_io_space(void) {
return false;
@@ -109,6 +116,9 @@ public:
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
uint32_t register_device(DEV_ID dev_id);
void process_interrupt(uint32_t cookie);
protected:
uint32_t dma_read(uint32_t offset, int size);
void dma_write(uint32_t offset, uint32_t value, int size);
@@ -138,24 +148,17 @@ private:
0x00,
0x00 // unknown defaults
};
uint32_t int_mask2 = 0;
uint32_t int_clear2 = 0;
uint32_t int_levels2 = 0;
uint32_t int_mask1 = 0;
uint32_t int_clear1 = 0;
uint32_t int_levels1 = 0;
uint32_t macio_id = 0xF0700008UL;
uint32_t feat_ctrl = 0; // features control register
uint32_t aux_ctrl = 0; // aux features control register
/* device cells */
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
std::unique_ptr<NVram> nvram; // NVRAM cell
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
std::unique_ptr<EsccController> escc; // ESCC serial controller
std::unique_ptr<Swim3::Swim3Ctrl> swim3; // floppy disk controller
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
std::unique_ptr<NVram> nvram; // NVRAM cell
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
std::unique_ptr<EsccController> escc; // ESCC serial controller
std::unique_ptr<DMAChannel> snd_out_dma;
};
+12 -7
View File
@@ -24,26 +24,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
Author: Max Poliakovski
*/
#include <devices/common/hwcomponent.h>
#include <devices/memctrl/hmc.h>
HMC::HMC() : MemCtrlBase()
{
this->name = "Highspeed Memory Controller";
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
/* add memory mapped I/O region for the HMC control register */
add_mmio_region(0x50F40000, 0x10000, this);
this->ctrl_reg = 0ULL;
this->config_reg = 0ULL;
this->bit_pos = 0;
}
bool HMC::supports_type(HWCompType type) {
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) {
return true;
} else {
return false;
}
}
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
{
if (!offset)
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
return !!(this->config_reg & (1ULL << this->bit_pos++));
else
return 0; /* FIXME: what should be returned for invalid offsets? */
}
@@ -55,8 +60,8 @@ void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
switch(offset) {
case 0:
bit = 1ULL << this->bit_pos++;
this->ctrl_reg = (value & 1) ? this->ctrl_reg | bit :
this->ctrl_reg & ~bit;
this->config_reg = (value & 1) ? this->config_reg | bit :
this->config_reg & ~bit;
break;
case 8: /* writing to HMCBase + 8 resets internal bit position */
this->bit_pos = 0;
+4 -9
View File
@@ -31,31 +31,26 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef HMC_H
#define HMC_H
#include <devices/common/hwcomponent.h>
#include <devices/common/mmiodevice.h>
#include <devices/memctrl/memctrlbase.h>
#include <cinttypes>
/** Bit in the HMC control register telling us where the frame bufffer
for the on-board video is located. */
#define HMC_VBASE_BIT 33
class HMC : public MemCtrlBase, public MMIODevice {
public:
HMC();
~HMC() = default;
bool supports_type(HWCompType type);
/* MMIODevice methods */
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
uint64_t get_control_reg(void) {
return this->ctrl_reg;
};
private:
int bit_pos;
uint64_t ctrl_reg;
uint64_t config_reg;
};
#endif // HMC_H
+9 -3
View File
@@ -39,9 +39,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") {
this->name = "Grackle";
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV |
HWCompType::PCI_HOST | HWCompType::PCI_DEV);
/* add PCI/ISA I/O space, 64K for now */
add_mmio_region(0xFE000000, 0x10000, this);
@@ -56,6 +53,15 @@ MPC106::~MPC106() {
this->pci_0_bus.clear();
}
bool MPC106::supports_type(HWCompType type) {
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV ||
type == HWCompType::PCI_HOST || type == HWCompType::PCI_DEV) {
return true;
} else {
return false;
}
}
uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) {
uint32_t result;
+3
View File
@@ -35,6 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef MPC106_H_
#define MPC106_H_
#include <devices/common/hwcomponent.h>
#include <devices/common/mmiodevice.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/common/pci/pcihost.h>
@@ -49,6 +50,8 @@ public:
MPC106();
~MPC106();
bool supports_type(HWCompType type);
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
+4 -1
View File
@@ -63,11 +63,14 @@ public:
SpdSdram168(uint8_t addr) {
this->dev_addr = addr;
this->pos = 0;
supports_types(HWCompType::RAM);
};
~SpdSdram168() = default;
bool supports_type(HWCompType type) {
return type == HWCompType::RAM;
};
void set_capacity(int capacity_megs) {
switch (capacity_megs) {
case 32:
+37 -168
View File
@@ -1,6 +1,6 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
@@ -35,48 +35,22 @@ EsccController::EsccController()
this->reg_ptr = 0;
}
void EsccController::reset()
{
this->master_int_cntrl &= 0xFC;
this->master_int_cntrl |= 0xC0;
this->ch_a->reset(true);
this->ch_b->reset(true);
}
uint8_t EsccController::read(uint8_t reg_offset)
{
uint8_t result = 0;
switch(reg_offset) {
case EsccReg::Port_B_Cmd:
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
if (this->reg_ptr == 2) {
// TODO: implement interrupt vector modifications
result = this->int_vec;
} else {
result = this->ch_b->read_reg(this->reg_ptr);
}
this->reg_ptr = 0;
break;
case EsccReg::Port_A_Cmd:
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
if (this->reg_ptr == 2) {
return this->int_vec;
} else {
return this->ch_a->read_reg(this->reg_ptr);
}
this->reg_ptr = 0;
break;
case EsccReg::Port_B_Data:
return this->ch_b->receive_byte();
case EsccReg::Port_A_Data:
return this->ch_a->receive_byte();
default:
LOG_F(9, "ESCC: reading from unimplemented register %d", reg_offset);
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
}
return result;
return 0;
}
void EsccController::write(uint8_t reg_offset, uint8_t value)
@@ -88,43 +62,47 @@ void EsccController::write(uint8_t reg_offset, uint8_t value)
case EsccReg::Port_A_Cmd:
this->write_internal(this->ch_a.get(), value);
break;
case EsccReg::Port_B_Data:
this->ch_b->send_byte(value);
default:
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
}
}
uint8_t EsccController::read_compat(uint8_t reg_offset)
{
switch(reg_offset) {
case Compat::EsccReg::Port_B_Cmd:
LOG_F(9, "ESCC: reading Port B register RR%d", this->reg_ptr);
this->reg_ptr = 0;
break;
case EsccReg::Port_A_Data:
this->ch_a->send_byte(value);
case Compat::EsccReg::Port_A_Cmd:
LOG_F(9, "ESCC: reading Port A register RR%d", this->reg_ptr);
this->reg_ptr = 0;
break;
default:
LOG_F(9, "ESCC: writing 0x%X to unimplemented register %d", value, reg_offset);
LOG_F(INFO, "ESCC: reading register %d", reg_offset);
}
return 0;
}
void EsccController::write_compat(uint8_t reg_offset, uint8_t value)
{
switch(reg_offset) {
case Compat::EsccReg::Port_B_Cmd:
this->write_internal(this->ch_b.get(), value);
break;
case Compat::EsccReg::Port_A_Cmd:
this->write_internal(this->ch_a.get(), value);
break;
default:
LOG_F(INFO, "ESCC: writing 0x%X to register %d", value, reg_offset);
}
}
void EsccController::write_internal(EsccChannel *ch, uint8_t value)
{
if (this->reg_ptr) {
// chip-specific registers
if (this->reg_ptr == 9) {
// see if some reset is requested
switch(value & 0xC0) {
case RESET_CH_B:
this->master_int_cntrl &= 0xDF;
this->ch_b->reset(false);
break;
case RESET_CH_A:
this->master_int_cntrl &= 0xDF;
this->ch_a->reset(false);
break;
case RESET_ESCC:
this->reset();
break;
}
this->master_int_cntrl = value & 0x3F;
} else if (this->reg_ptr == 2) {
this->int_vec = value;
} else { // channel-specific registers
ch->write_reg(this->reg_ptr, value);
}
ch->write_reg(this->reg_ptr, value);
this->reg_ptr = 0;
} else {
this->reg_ptr = value & 7;
@@ -136,118 +114,9 @@ void EsccController::write_internal(EsccChannel *ch, uint8_t value)
}
}
// ======================== ESCC Channel methods ==============================
void EsccChannel::reset(bool hw_reset)
{
this->write_regs[1] &= 0x24;
this->write_regs[3] &= 0xFE;
this->write_regs[4] |= 0x04;
this->write_regs[5] &= 0x61;
this->write_regs[15] = 0xF8;
this->read_regs[0] &= 0x3C;
this->read_regs[0] |= 0x44;
this->read_regs[1] = 0x06;
this->read_regs[3] = 0x00;
this->read_regs[10] = 0x00;
// initialize DPLL
this->dpll_active = 0;
this->dpll_mode = DpllMode::NRZI;
this->dpll_clock_src = 0;
// initialize Baud Rate Generator (BRG)
this->brg_active = 0;
this->brg_clock_src = 0;
if (hw_reset) {
this->write_regs[10] = 0;
this->write_regs[11] = 8;
this->write_regs[14] &= 0xC0;
this->write_regs[14] |= 0x20;
} else {
this->write_regs[10] &= 0x60;
this->write_regs[14] &= 0xC3;
this->write_regs[14] |= 0x20;
}
}
void EsccChannel::write_reg(int reg_num, uint8_t value)
{
switch (reg_num) {
case 3:
if (value & 0x11) {
if ((this->write_regs[3] ^ value) & 0x10) {
this->write_regs[3] |= 0x10;
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
LOG_F(9, "ESCC: Hunt mode entered.");
}
if (value & 1) {
this->write_regs[3] |= 0x1;
LOG_F(9, "ESCC: receiver enabled.");
}
}
this->write_regs[3] = (this->write_regs[3] & 0x11) | (value & 0xEE);
return;
case 7:
if (this->write_regs[15] & 1) {
this->wr7_enh = value;
return;
}
break;
case 14:
switch (value >> 5) {
case DPLL_ENTER_SRC_MODE:
this->dpll_active = 1;
this->read_regs[10] &= 0x3F;
break;
case DPLL_DISABLE:
this->dpll_active = 0;
// fallthrough
case DPLL_RST_MISSING_CLK:
this->read_regs[10] &= 0x3F;
break;
case DPLL_SET_SRC_BGR:
this->dpll_clock_src = 0;
break;
case DPLL_SET_SRC_RTXC:
this->dpll_clock_src = 1;
break;
case DPLL_SET_FM_MODE:
this->dpll_mode = DpllMode::FM;
break;
case DPLL_SET_NRZI_MODE:
this->dpll_mode = DpllMode::NRZI;
break;
default:
LOG_F(WARNING, "ESCC: unimplemented DPLL command %d", value >> 5);
}
if (value & 0x1C) { // Local Loopback, Auto Echo DTR/REQ bits set
LOG_F(WARNING, "ESCC: unexpected value in WR14 = 0x%X", value);
}
if (this->brg_active ^ (value & 1)) {
this->brg_active = value & 1;
LOG_F(9, "ESCC: BRG %s", this->brg_active ? "enabled" : "disabled");
}
return;
}
this->write_regs[reg_num] = value;
}
uint8_t EsccChannel::read_reg(int reg_num)
{
return this->read_regs[reg_num];
}
void EsccChannel::send_byte(uint8_t value)
{
// Put one byte into the Data FIFO
}
uint8_t EsccChannel::receive_byte()
{
// Remove one byte from the Receive FIFO
return 0xFF;
LOG_F(9, "ESCC: writing 0x%X to Channel %s WR%d", value, this->name.c_str(),
reg_num);
}
+26 -52
View File
@@ -28,21 +28,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory>
#include <string>
/** ESCC register positions */
/* Please note that the registers below are provided
by Apple I/O controllers for accessing ESCC in a
more convenient way. Actual physical addresses
are controller dependent. */
enum EsccReg : uint8_t {
Port_B_Cmd = 0,
Port_A_Cmd = 1,
Port_B_Data = 2, // direct access to WR8/RR8
Port_A_Data = 3, // direct access to WR8/RR8
Enh_Reg_B = 4, // undocumented Apple extension
Enh_Reg_A = 5, // undocumented Apple extension
/** ESCC compatible (aka Macintosh legacy) register addressing */
namespace Compat {
enum EsccReg : uint8_t {
Port_B_Cmd = 0,
Port_A_Cmd = 1,
Port_B_Data = 2,
Port_A_Data = 3,
Enh_Reg_B = 4,
Enh_Reg_A = 5,
};
};
/** LocalTalk LTPC registers provided by a MacIO controller. */
/** ESCC MacRISC style register addressing */
enum EsccReg : uint8_t {
Port_B_Cmd = 0,
Port_B_Data = 1,
Port_A_Cmd = 2,
Port_A_Data = 3,
Enh_Reg_B = 4,
Enh_Reg_A = 5,
};
/** LocalTalk registers (same in both addressing schemes) */
enum LocalTalkReg : uint8_t {
Rec_Count = 8,
Start_A = 9,
@@ -54,51 +62,17 @@ enum WR0Cmd : uint8_t {
Point_High = 1,
};
/** ESCC reset commands. */
enum {
RESET_ESCC = 0xC0,
RESET_CH_A = 0x80,
RESET_CH_B = 0x40
};
/** DPLL commands in WR14. */
enum {
DPLL_ENTER_SRC_MODE = 1,
DPLL_RST_MISSING_CLK = 2,
DPLL_DISABLE = 3,
DPLL_SET_SRC_BGR = 4,
DPLL_SET_SRC_RTXC = 5,
DPLL_SET_FM_MODE = 6,
DPLL_SET_NRZI_MODE = 7
};
enum DpllMode : uint8_t {
NRZI = 0,
FM = 1
};
/** ESCC Channel class. */
class EsccChannel {
public:
EsccChannel(std::string name) { this->name = name; };
~EsccChannel() = default;
void reset(bool hw_reset);
uint8_t read_reg(int reg_num);
void write_reg(int reg_num, uint8_t value);
void send_byte(uint8_t value);
uint8_t receive_byte();
private:
std::string name;
uint8_t read_regs[16];
uint8_t write_regs[16];
uint8_t wr7_enh;
uint8_t dpll_active;
uint8_t dpll_mode;
uint8_t dpll_clock_src;
uint8_t brg_active;
uint8_t brg_clock_src;
};
/** ESCC Controller class. */
@@ -107,21 +81,21 @@ public:
EsccController();
~EsccController() = default;
// ESCC registers access
// ESCC MacRISC registers access
uint8_t read(uint8_t reg_offset);
void write(uint8_t reg_offset, uint8_t value);
// ESCC compatible registers access
uint8_t read_compat(uint8_t reg_offset);
void write_compat(uint8_t reg_offset, uint8_t value);
private:
void reset();
void write_internal(EsccChannel* ch, uint8_t value);
std::unique_ptr<EsccChannel> ch_a;
std::unique_ptr<EsccChannel> ch_b;
int reg_ptr; // register pointer for reading/writing (same for both channels)
uint8_t master_int_cntrl;
uint8_t int_vec;
};
#endif // ESCC_H
+5 -4
View File
@@ -46,10 +46,7 @@ enum {
class SoundServer : public HWComponent {
public:
SoundServer() {
supports_types(HWCompType::SND_SERVER);
this->start();
};
SoundServer() { this->start(); };
~SoundServer() { this->shutdown(); };
int start();
@@ -58,6 +55,10 @@ public:
int start_out_stream();
void close_out_stream();
bool supports_type(HWCompType type) {
return type == HWCompType::SND_SERVER;
};
private:
int status; /* server status */
cubeb *cubeb_ctx;
+71 -75
View File
@@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <devices/common/hwcomponent.h>
#include <devices/common/pci/pcidevice.h>
#include <devices/video/atirage.h>
#include <devices/video/displayid.h>
@@ -30,7 +29,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <chrono>
#include <cstdint>
#include <map>
#include <memory>
/* Mach64 post dividers. */
static const int mach64_post_div[8] = {
@@ -93,12 +91,10 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
{
uint8_t asic_id;
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
this->vram_size = vmem_size_mb << 20; // convert MBs to bytes
/* allocate video RAM */
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
this->vram_ptr = new uint8_t[this->vram_size];
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
to operate properly */
@@ -120,11 +116,20 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
WRITE_DWORD_LE_A(&this->pci_cfg[0x3C], 0x00080100);
/* stuff default values into chip registers */
WRITE_DWORD_LE_A(&this->mm_regs[ATI_CONFIG_CHIP_ID],
WRITE_DWORD_LE_A(&this->block_io_regs[ATI_CONFIG_CHIP_ID],
(asic_id << 24) | dev_id);
/* initialize display identification */
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
this->disp_id = new DisplayID(Disp_Id_Kind::DDC2B);
}
ATIRage::~ATIRage()
{
if (this->vram_ptr) {
delete this->vram_ptr;
}
delete (this->disp_id);
}
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
@@ -139,25 +144,24 @@ const char* ATIRage::get_reg_name(uint32_t reg_offset) {
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
uint32_t res;
// perform register-specific pre-read action
switch (offset & ~3) {
case ATI_GP_IO:
break;
case ATI_CLOCK_CNTL:
/* reading from internal PLL registers */
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
!(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
return this->plls[this->mm_regs[ATI_CLOCK_CNTL+1] >> 2];
!(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
return this->plls[this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2];
}
break;
case ATI_DAC_REGS:
if (offset == ATI_DAC_DATA) {
this->mm_regs[ATI_DAC_DATA] =
this->palette[this->mm_regs[ATI_DAC_R_INDEX]][this->comp_index];
this->block_io_regs[ATI_DAC_DATA] =
this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index];
this->comp_index++; /* move to next color component */
if (this->comp_index >= 3) {
/* autoincrement reading index - move to next palette entry */
(this->mm_regs[ATI_DAC_R_INDEX])++;
(this->block_io_regs[ATI_DAC_R_INDEX])++;
this->comp_index = 0;
}
}
@@ -169,66 +173,63 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
get_reg_name(offset),
offset,
size,
read_mem(&this->mm_regs[offset], size));
read_mem(&this->block_io_regs[offset], size));
}
// reading internal registers with necessary endian conversion
res = read_mem(&this->mm_regs[offset], size);
res = read_mem(&this->block_io_regs[offset], size);
return res;
}
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
{
uint8_t gpio_levels, gpio_dirs;
void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
uint32_t gpio_val;
uint16_t gpio_dir;
// writing internal registers with necessary endian conversion
write_mem(&this->mm_regs[offset], value, size);
/* size-dependent endian conversion */
write_mem(&this->block_io_regs[offset], value, size);
// perform register-specific post-write action
switch (offset & ~3) {
case ATI_CRTC_OFF_PITCH:
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]));
LOG_F(INFO, "ATI Rage: CRTC_OFF_PITCH=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]));
break;
case ATI_CRTC_GEN_CNTL:
if (this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
if (this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
this->crtc_enable();
} else {
this->crtc_on = false;
}
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2));
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40));
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_ENABLE=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2));
LOG_F(INFO, "ATI Rage: CRTC_GEN_CNTL:CRTC_DISPLAY_DIS=%d", !!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40));
break;
case ATI_CUR_OFFSET:
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]));
LOG_F(INFO, "ATI Rage: CUR_OFFSET=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]));
break;
case ATI_CUR_HORZ_VERT_POSN:
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_POSN]));
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_POSN=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_POSN]));
break;
case ATI_CUR_HORZ_VERT_OFF:
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]));
LOG_F(INFO, "ATI Rage: CUR_HORZ_VERT_OFF=0x%08X", READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]));
break;
case ATI_GP_IO:
if (offset < (ATI_GP_IO + 2)) {
gpio_levels = this->mm_regs[ATI_GP_IO+1];
gpio_levels = ((gpio_levels & 0x30) >> 3) | (gpio_levels & 1);
gpio_dirs = this->mm_regs[ATI_GP_IO+3];
gpio_dirs = ((gpio_dirs & 0x30) >> 3) | (gpio_dirs & 1);
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
this->mm_regs[ATI_GP_IO+1] = ((gpio_levels & 6) << 3) | (gpio_levels & 1);
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
gpio_dir = (gpio_val >> 16) & 0x3FFF;
WRITE_WORD_LE_A(
&this->block_io_regs[ATI_GP_IO],
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
}
break;
case ATI_CLOCK_CNTL:
/* writing to internal PLL registers */
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
(this->mm_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
int pll_addr = this->mm_regs[ATI_CLOCK_CNTL+1] >> 2;
uint8_t pll_data = this->mm_regs[ATI_CLOCK_CNTL+2];
(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
int pll_addr = this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2;
uint8_t pll_data = this->block_io_regs[ATI_CLOCK_CNTL+2];
this->plls[pll_addr] = pll_data;
LOG_F(INFO, "ATI Rage: PLL #%d set to 0x%02X", pll_addr, pll_data);
} else if (offset == ATI_CLOCK_CNTL && size == 1) {
LOG_F(INFO, "ATI Rage: CLOCK_SEL = 0x%02X",
this->mm_regs[ATI_CLOCK_CNTL] & 3);
this->block_io_regs[ATI_CLOCK_CNTL] & 3);
}
break;
case ATI_DAC_REGS:
@@ -239,24 +240,24 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
this->comp_index = 0;
break;
case ATI_DAC_DATA:
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF;
this->comp_index++; /* move to next color component */
if (this->comp_index >= 3) {
LOG_F(
INFO,
"ATI DAC palette entry #%d set to R=%X, G=%X, B=%X",
this->mm_regs[ATI_DAC_W_INDEX],
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][0],
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][1],
this->palette[this->mm_regs[ATI_DAC_W_INDEX]][2]);
this->block_io_regs[ATI_DAC_W_INDEX],
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0],
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1],
this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]);
/* autoincrement writing index - move to next palette entry */
(this->mm_regs[ATI_DAC_W_INDEX])++;
(this->block_io_regs[ATI_DAC_W_INDEX])++;
this->comp_index = 0;
}
}
break;
case ATI_GEN_TEST_CNTL:
LOG_F(INFO, "HW cursor: %s", this->mm_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
LOG_F(INFO, "HW cursor: %s", this->block_io_regs[ATI_GEN_TEST_CNTL] & 0x80 ? "on" : "off");
break;
default:
LOG_F(
@@ -264,16 +265,16 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
"ATI Rage: %s register at 0x%X set to 0x%X",
get_reg_name(offset),
offset & ~3,
READ_DWORD_LE_A(&this->mm_regs[offset & ~3]));
READ_DWORD_LE_A(&this->block_io_regs[offset & ~3]));
}
if ((this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
if ((this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
!(this->block_io_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
int32_t src_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
this->fb_pitch = ((READ_DWORD_LE_A(&this->block_io_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
this->fb_ptr = &this->vram_ptr[src_offset];
this->fb_ptr = this->vram_ptr + src_offset;
this->update_screen();
}
}
@@ -400,11 +401,11 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
if (offset < this->vram_size) {
/* read from little-endian VRAM region */
return read_mem(&this->vram_ptr[offset], size);
return read_mem(this->vram_ptr + offset, size);
}
else if (offset >= BE_FB_OFFSET) {
/* read from big-endian VRAM region */
return read_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], size);
return read_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), size);
}
else if (offset >= MM_REGS_0_OFF) {
/* read from memory-mapped registers, block 0 */
@@ -432,11 +433,11 @@ void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int siz
if (offset < this->vram_size) {
/* write to little-endian VRAM region */
write_mem(&this->vram_ptr[offset], value, size);
write_mem(this->vram_ptr + offset, value, size);
}
else if (offset >= BE_FB_OFFSET) {
/* write to big-endian VRAM region */
write_mem_rev(&this->vram_ptr[offset - BE_FB_OFFSET], value, size);
write_mem_rev(this->vram_ptr + (offset - BE_FB_OFFSET), value, size);
}
else if (offset >= MM_REGS_0_OFF) {
/* write to memory-mapped registers, block 0 */
@@ -463,13 +464,13 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
const char* what = "Pixel format:";
switch (this->mm_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
switch (this->block_io_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
case 1:
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
break;
case 2:
// check the undocumented DAC_DIRECT bit
if (this->mm_regs[ATI_DAC_CNTL+1] & 4) {
if (this->block_io_regs[ATI_DAC_CNTL+1] & 4) {
LOG_F(INFO, "%s 8 bpp direct color (RGB322)", what);
} else {
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
@@ -489,21 +490,21 @@ void ATIRage::verbose_pixel_format(int crtc_index) {
break;
default:
LOG_F(ERROR, "ATI Rage: CRTC pixel format %d not supported",
this->mm_regs[ATI_CRTC_GEN_CNTL+2] & 7);
this->block_io_regs[ATI_CRTC_GEN_CNTL+2] & 7);
}
}
void ATIRage::crtc_enable() {
/* active (visible) width is specified in characters (8 px) - 1 */
this->active_width = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
this->active_width = (this->block_io_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
/* active (visible) height is specified in lines - 1 */
this->active_height =
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
if ((this->plls[PLL_VCLK_CNTL] & 3) == 3) {
/* look up which VPLL ouput is requested */
int clock_sel = this->mm_regs[ATI_CLOCK_CNTL] & 3;
int clock_sel = this->block_io_regs[ATI_CLOCK_CNTL] & 3;
/* calculate VPLL output frequency */
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
@@ -520,22 +521,17 @@ void ATIRage::crtc_enable() {
/* calculate display refresh rate */
int hori_total =
((READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_H_TOTAL_DISP])
((READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_H_TOTAL_DISP])
& 0x1FFUL) + 1) * 8;
int vert_total =
(READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
this->refresh_rate = pixel_clock / hori_total / vert_total;
// specify framebuffer converter (hardcoded for now)
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
this->convert_frame_8bpp(dst_buf, dst_pitch);
};
LOG_F(INFO, "ATI Rage: primary CRT controller enabled:");
LOG_F(INFO, "Video mode: %s",
(this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
LOG_F(INFO, "Video width: %d px", this->active_width);
LOG_F(INFO, "Video height: %d px", this->active_height);
verbose_pixel_format(0);
@@ -552,15 +548,15 @@ void ATIRage::crtc_enable() {
void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
uint8_t *src_buf, *src_row, *dst_row, px4;
int horz_offset = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
int vert_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
int horz_offset = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) & 0x3F;
int vert_offset = (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_HORZ_VERT_OFF]) >> 16) & 0x3F;
src_buf = &this->vram_ptr[(READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_OFFSET]) * 8)];
src_buf = this->vram_ptr + (READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_OFFSET]) * 8);
int cur_height = 64 - vert_offset;
uint32_t color0 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
uint32_t color1 = READ_DWORD_LE_A(&this->mm_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
uint32_t color0 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR0]) | 0x000000FFUL;
uint32_t color1 = READ_DWORD_LE_A(&this->block_io_regs[ATI_CUR_CLR1]) | 0x000000FFUL;
for (int h = 0; h < cur_height; h++) {
dst_row = &dst_buf[h * dst_pitch];
+9 -6
View File
@@ -27,7 +27,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/video/videoctrl.h>
#include <cinttypes>
#include <memory>
/* PCI related definitions. */
enum {
@@ -197,12 +196,16 @@ constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
class ATIRage : public PCIDevice, public VideoCtrlBase {
public:
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
~ATIRage() = default;
~ATIRage();
/* MMIODevice methods */
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
bool supports_type(HWCompType type) {
return type == HWCompType::MMIO_DEV;
};
/* PCI device methods */
bool supports_io_space(void) {
return true;
@@ -226,19 +229,19 @@ protected:
void draw_hw_cursor(uint8_t *dst_buf, int dst_pitch);
private:
uint8_t mm_regs[2048] = {0}; // internal registers
uint8_t block_io_regs[2048] = {0};
uint8_t pci_cfg[256] = {0}; // PCI configuration space
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
uint8_t plls[64] = {0}; // internal PLL registers
/* Video RAM variables */
std::unique_ptr<uint8_t[]> vram_ptr;
uint32_t vram_size;
uint8_t* vram_ptr;
uint32_t aperture_base;
std::unique_ptr<DisplayID> disp_id;
DisplayID* disp_id;
int comp_index; /* color component index for DAC palette access */
};
+52 -75
View File
@@ -23,109 +23,86 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <devices/video/displayid.h>
#include <loguru.hpp>
#include <machines/machineproperties.h>
#include <cinttypes>
#include <map>
#include <string>
/** Mapping between monitor IDs and their sense codes. */
static const std::map<std::string, uint16_t> MonitorIdToCode = {
{ "MacColor21in" , 0x00FF },
{ "PortraitGS" , 0x01FF },
{ "MacRGB12in" , 0x02FF },
{ "TwoPageGS" , 0x03FF },
{ "NTSC" , 0x04FF },
{ "MacRGB15in" , 0x05FF },
{ "HiRes12-14in" , 0x06FF },
{ "Multiscan15in" , 0x0603 },
{ "Multiscan17in" , 0x060B },
{ "Multiscan20in" , 0x0623 },
{ "AppleVision1710" , 0x062B }, // this code is assigned to several different monitors!
{ "PALEncoder" , 0x0700 }, // no clue what it means
{ "NTSCEncoder" , 0x0714 }, // no clue what it means
{ "VGA-SVGA" , 0x0717 },
{ "MacRGB16in" , 0x072D },
{ "MacRGB19in" , 0x073A },
{ "PAL" , 0x0730 },
{ "NotConnected" , 0x07FF }
};
DisplayID::DisplayID()
DisplayID::DisplayID(Disp_Id_Kind id_kind)
{
// assume a DDC monitor is connected by default
this->id_kind = Disp_Id_Kind::DDC2B;
this->id_kind = id_kind;
std::string mon_id = GET_STR_PROP("mon_id");
if (!mon_id.empty()) {
if (MonitorIdToCode.count(mon_id)) {
auto sense_code = MonitorIdToCode.at(mon_id);
this->std_sense_code = (sense_code >> 8) & 0xFFU;
this->ext_sense_code = (sense_code >> 0) & 0xFFU;
this->id_kind = Disp_Id_Kind::AppleSense;
LOG_F(INFO, "DisplayID mode set to AppleSense");
LOG_F(INFO, "Standard sense code: 0x%d", this->std_sense_code);
LOG_F(INFO, "Extended sense code: 0x%X", this->ext_sense_code);
}
}
/* Initialize Apple monitor codes */
this->std_sense_code = 6;
this->ext_sense_code = 0x2B;
/* Initialize DDC I2C bus */
this->next_state = I2CState::STOP;
this->prev_state = I2CState::STOP;
this->last_sda = 1;
this->last_scl = 1;
this->data_out = 0x3000;
this->data_ptr = 0;
}
uint8_t DisplayID::read_monitor_sense(uint8_t levels, uint8_t dirs)
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
{
this->last_sda = sda;
this->last_scl = scl;
if (scl) {
this->data_out |= 0x1000;
} else {
this->data_out &= ~0x1000U;
}
if (sda) {
this->data_out |= 0x2000;
} else {
this->data_out &= ~0x2000U;
}
return this->data_out;
}
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs)
{
uint8_t scl, sda;
uint16_t result;
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
LOG_F(WARNING, "DisplayID: Monitor sense lines tristated!");
}
switch(this->id_kind) {
case Disp_Id_Kind::DDC2B:
/* If GPIO pins are in the output mode, pick up their levels.
/* if GPIO pins are in the output mode, pick up their values
In the input mode, GPIO pins will be read "high" */
scl = (dirs & 2) ? !!(levels & 2) : 1;
sda = (dirs & 4) ? !!(levels & 4) : 1;
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
return update_ddc_i2c(sda, scl);
case Disp_Id_Kind::AppleSense:
switch ((dirs << 3) | levels) {
case 0x23: // Sense line 2 pulled low
return ((this->ext_sense_code >> 4) & 3);
case 0x15: // Sense line 1 pulled low
return (((this->ext_sense_code & 8) >> 1) |
((this->ext_sense_code & 4) >> 2));
case 0xE: // Sense line 0 pulled low
return ((this->ext_sense_code & 3) << 1);
switch (dirs & 0x3100) {
case 0:
result = ((this->std_sense_code & 6) << 11) | ((this->std_sense_code & 1) << 8);
break;
case 0x2000: /* Sense line 2 is low */
result = ((this->ext_sense_code & 0x20) << 7) | ((this->ext_sense_code & 0x10) << 4);
break;
case 0x1000: /* Sense line 1 is low */
result = ((this->ext_sense_code & 8) << 10) | ((this->ext_sense_code & 4) << 6);
break;
case 0x100: /* Sense line 0 is low */
result = ((this->ext_sense_code & 2) << 12) | ((this->ext_sense_code & 1) << 12);
break;
default:
return this->std_sense_code;
result = 0x3100U;
}
return result;
}
}
uint8_t DisplayID::set_result(uint8_t sda, uint8_t scl)
{
uint16_t data_out;
this->last_sda = sda;
this->last_scl = scl;
data_out = 0;
if (scl) {
data_out |= 2;
}
if (sda) {
data_out |= 4;
}
return data_out;
}
uint8_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
{
bool clk_gone_high = false;
+5 -4
View File
@@ -55,14 +55,14 @@ enum I2CState : uint8_t {
class DisplayID {
public:
DisplayID();
DisplayID(Disp_Id_Kind id_kind);
~DisplayID() = default;
uint8_t read_monitor_sense(uint8_t levels, uint8_t dirs);
uint16_t read_monitor_sense(uint16_t data, uint16_t dirs);
protected:
uint8_t set_result(uint8_t sda, uint8_t scl);
uint8_t update_ddc_i2c(uint8_t sda, uint8_t scl);
uint16_t set_result(uint8_t sda, uint8_t scl);
uint16_t update_ddc_i2c(uint8_t sda, uint8_t scl);
private:
Disp_Id_Kind id_kind;
@@ -75,6 +75,7 @@ private:
uint8_t prev_state;
uint8_t last_sda;
uint8_t last_scl;
uint16_t data_out;
int bit_count; /* number of bits processed so far */
uint8_t byte; /* byte value being currently transferred */
uint8_t dev_addr; /* current device address */
-269
View File
@@ -1,269 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file PDM on-board video emulation. */
#include <core/timermanager.h>
#include <cpu/ppc/ppcmmu.h>
#include <devices/memctrl/hmc.h>
#include <devices/video/pdmonboard.h>
#include <devices/video/videoctrl.h>
#include <machines/machinebase.h>
#include <loguru.hpp>
#include <cinttypes>
PdmOnboardVideo::PdmOnboardVideo()
: VideoCtrlBase()
{
this->video_mode = PDM_VMODE_OFF;
this->blanking = 0x80;
this->crtc_on = false;
this->vdac_mode = 8;
this->pixel_depth = 0;
// get pointer to the Highspeed Memory controller
this->hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
}
void PdmOnboardVideo::set_video_mode(uint8_t new_mode)
{
switch(new_mode & 0x7F) {
case PdmVideoMode::Portrait:
case PdmVideoMode::Rgb12in:
case PdmVideoMode::Rgb13in:
case PdmVideoMode::Rgb16in:
case PdmVideoMode::VGA:
if (this->video_mode != (new_mode & 0x1F)) {
this->video_mode = new_mode & 0x1F;
LOG_F(INFO, "PDM-Video: video mode set to 0x%X", this->video_mode);
}
if (this->blanking != (new_mode & 0x80)) {
this->blanking = new_mode & 0x80;
if (this->blanking) {
this->disable_video_internal();
} else {
this->enable_video_internal();
}
}
break;
default:
LOG_F(9, "PDM-Video: video disabled, new mode = 0x%X", new_mode & 0x1F);
this->video_mode = new_mode & 0x1F;
this->blanking = 0x80;
this->crtc_on = false;
}
}
void PdmOnboardVideo::set_pixel_depth(uint8_t depth)
{
static uint8_t pix_depths[8] = {1, 2, 4, 8, 16, 0xFF, 0xFF, 0xFF};
uint8_t new_pix_depth = pix_depths[depth];
if (new_pix_depth == 0xFF) {
ABORT_F("PDM-Video: invalid pixel depth code %d specified!", depth);
}
if (new_pix_depth != this->pixel_depth) {
this->pixel_depth = new_pix_depth;
this->set_depth_internal(this->active_width);
LOG_F(INFO, "PDM-Video: pixel depth changed to %dbpp", new_pix_depth);
}
}
void PdmOnboardVideo::set_vdac_config(uint8_t mode)
{
this->vdac_mode = mode;
if ((mode & 0xF8) != 8) {
LOG_F(WARNING, "Ariel control changed to unknown value 0x%X", mode);
}
}
void PdmOnboardVideo::set_clut_index(uint8_t index)
{
this->clut_index = index;
this->comp_index = 0;
}
void PdmOnboardVideo::set_clut_color(uint8_t color)
{
this->clut_color[this->comp_index++] = color;
if (this->comp_index >= 3) {
// TODO: combine separate components into a single ARGB value
this->palette[this->clut_index][0] = this->clut_color[0];
this->palette[this->clut_index][1] = this->clut_color[1];
this->palette[this->clut_index][2] = this->clut_color[2];
this->palette[this->clut_index][3] = 255;
this->clut_index++; // assume the HW works like that
this->comp_index = 0; // assume the HW works like that
}
}
void PdmOnboardVideo::set_depth_internal(int pitch)
{
switch (this->pixel_depth) {
case 1:
this->convert_fb_cb = [this](uint8_t* dst_buf, int dst_pitch) {
this->convert_frame_1bpp(dst_buf, dst_pitch);
};
this->fb_pitch = pitch >> 3; // one byte contains 8 pixels
break;
case 8:
this->convert_fb_cb = [this](uint8_t* dst_buf, int dst_pitch) {
this->convert_frame_8bpp(dst_buf, dst_pitch);
};
this->fb_pitch = pitch; // one byte contains 1 pixel
break;
default:
ABORT_F("PDM-Video: pixel depth %d not implemented yet!", this->pixel_depth);
}
}
void PdmOnboardVideo::enable_video_internal()
{
int new_width, new_height, hori_blank, vert_blank;
// ensure all video parameters contain safe values
switch(this->video_mode) {
case PdmVideoMode::Portrait:
case PdmVideoMode::Rgb16in:
case PdmVideoMode::VGA:
if (this->pixel_depth > 8) {
ABORT_F("PDM-Video: no 16bpp support in mode %d!", this->video_mode);
}
default:
break;
}
// set video mode parameters
switch(this->video_mode) {
case PdmVideoMode::Portrait:
new_width = 640;
new_height = 870;
hori_blank = 192;
vert_blank = 48;
this->pixel_clock = 57283200;
break;
case PdmVideoMode::Rgb12in:
new_width = 512;
new_height = 384;
hori_blank = 128;
vert_blank = 23;
this->pixel_clock = 15667200;
break;
case PdmVideoMode::Rgb13in:
new_width = 640;
new_height = 480;
hori_blank = 256;
vert_blank = 45;
this->pixel_clock = 31334400;
break;
case PdmVideoMode::Rgb16in:
new_width = 832;
new_height = 624;
hori_blank = 320;
vert_blank = 43;
this->pixel_clock = 57283200;
break;
case PdmVideoMode::VGA:
new_width = 640;
new_height = 480;
hori_blank = 160;
vert_blank = 45;
this->pixel_clock = 25175000;
break;
default:
ABORT_F("PDM-Video: invalid video mode %d", this->video_mode);
}
if (new_width != this->active_width || new_height != this->active_height) {
LOG_F(WARNING, "Display window resizing not implemented yet!");
}
// figure out where our framebuffer is located
uint64_t hmc_control = this->hmc_obj->get_control_reg();
uint32_t fb_base_phys = ((hmc_control >> HMC_VBASE_BIT) & 1) ? 0 : 0x100000;
LOG_F(INFO, "PDM-Video: framebuffer phys base addr = 0x%X", fb_base_phys);
// set framebuffer address and pitch
this->fb_ptr = mmu_get_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX);
this->active_width = new_width;
this->active_height = new_height;
this->set_depth_internal(new_width);
// set up video refresh timer
double refresh_rate_hz = (double)(this->pixel_clock) / (new_width + hori_blank) / (new_height + vert_blank);
LOG_F(INFO, "PDM-Video: refresh rate set to %f Hz", refresh_rate_hz);
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate_hz * NS_PER_SEC + 0.5);
TimerManager::get_instance()->add_cyclic_timer(
refresh_interval,
[this]() {
this->update_screen();
}
);
this->update_screen();
LOG_F(INFO, "PDM-Video: video enabled");
this->crtc_on = true;
}
void PdmOnboardVideo::disable_video_internal()
{
this->crtc_on = false;
LOG_F(INFO, "PDM-Video: video disabled");
}
/** Ariel II has a weird 1bpp mode where a white pixel is mapped to
CLUT entry #127 (%01111111) and a black pixel to #255 (%11111111).
It requres a non-standard conversion routine implementend below.
*/
void PdmOnboardVideo::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
{
uint8_t *src_buf, *src_row, pix;
uint32_t *dst_row;
int src_pitch, width;
uint32_t pixels[2];
// prepare cached ARGB values for white & black pixels
pixels[0] = (0xFF << 24) | (this->palette[127][0] << 16) |
(this->palette[127][1] << 8) | this->palette[127][2];
pixels[1] = (0xFF << 24) | (this->palette[255][0] << 16) |
(this->palette[255][1] << 8) | this->palette[255][2];
src_buf = this->fb_ptr;
src_pitch = this->fb_pitch;
width = this->active_width >> 3;
for (int h = 0; h < this->active_height; h++) {
src_row = &src_buf[h * src_pitch];
dst_row = (uint32_t *)(&dst_buf[h * dst_pitch]);
for (int x = 0; x < width; x++) {
pix = src_row[x];
for (int i = 0; i < 8; i++, pix <<= 1, dst_row++) {
*dst_row = pixels[(pix >> 7) & 1];
}
}
}
}
-82
View File
@@ -1,82 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** @file Definitions for the PDM on-board video. */
#ifndef PDM_ONBOARD_H
#define PDM_ONBOARD_H
#include <devices/memctrl/hmc.h>
#include <devices/video/videoctrl.h>
#include <cinttypes>
#define PDM_VMODE_OFF 0x1F
/** Max. size of our framebuffer in bytes (RGB 13-inch, 16 bpp) */
#define PDM_FB_SIZE_MAX (640 * 480 * 2)
/** Fixed video modes supported by the PDM on-board video. */
enum PdmVideoMode : uint8_t {
Portrait = 1,
Rgb12in = 2,
Rgb13in = 6,
Rgb16in = 9,
VGA = 0xB
};
class PdmOnboardVideo : public VideoCtrlBase {
public:
PdmOnboardVideo();
~PdmOnboardVideo() = default;
uint8_t get_video_mode() {
return ((this->video_mode & 0x1F) | this->blanking);
};
void set_video_mode(uint8_t new_mode);
void set_pixel_depth(uint8_t depth);
void set_vdac_config(uint8_t config);
uint8_t get_vdac_config() {
return this->vdac_mode;
};
void set_clut_index(uint8_t index);
void set_clut_color(uint8_t color);
protected:
void set_depth_internal(int pitch);
void enable_video_internal();
void disable_video_internal();
void convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch);
private:
uint8_t video_mode;
uint8_t pixel_depth;
uint8_t blanking;
uint8_t vdac_mode;
uint8_t clut_index;
uint8_t comp_index;
uint8_t clut_color[3];
HMC* hmc_obj;
};
#endif // PDM_ONBOARD_H
+6 -13
View File
@@ -28,20 +28,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <chrono>
#include <cinttypes>
VideoCtrlBase::VideoCtrlBase(int width, int height)
VideoCtrlBase::VideoCtrlBase()
{
LOG_F(INFO, "Create display window...");
this->active_width = width;
this->active_height = height;
// Create display window
this->display_wnd = SDL_CreateWindow(
"DingusPPC Display",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
this->active_width,
this->active_height,
640,
480,
SDL_WINDOW_OPENGL
);
@@ -101,8 +98,9 @@ void VideoCtrlBase::update_screen()
SDL_LockTexture(this->disp_texture, NULL, (void **)&dst_buf, &dst_pitch);
// texture update callback to get ARGB data from guest framebuffer
this->convert_fb_cb(dst_buf, dst_pitch);
// call texture update method (hardcoded for now)
// TODO: convert it to a callback
this->convert_frame_8bpp(dst_buf, dst_pitch);
SDL_UnlockTexture(this->disp_texture);
SDL_RenderClear(this->renderer);
@@ -123,11 +121,6 @@ void VideoCtrlBase::update_screen()
SDL_Delay(15);
}
void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
{
// TODO: implement me!
}
void VideoCtrlBase::convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch)
{
uint8_t *src_buf, *src_row, *dst_row, pix;
+2 -7
View File
@@ -27,18 +27,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <SDL.h>
#include <cinttypes>
#include <functional>
class VideoCtrlBase {
public:
VideoCtrlBase(int width = 640, int height = 480);
VideoCtrlBase();
~VideoCtrlBase();
void update_screen(void);
// converters for various framebuffer pixel depths
virtual void convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch);
virtual void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
void convert_frame_8bpp(uint8_t *dst_buf, int dst_pitch);
protected:
/* CRT controller parameters */
@@ -54,8 +51,6 @@ protected:
uint8_t* fb_ptr;
int fb_pitch;
std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb;
private:
SDL_Window *display_wnd;
SDL_Renderer *renderer;
+7
View File
@@ -0,0 +1,7 @@
include_directories("${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(execution OBJECT ${SOURCES})
target_link_libraries(execution PRIVATE cubeb)
+111
View File
@@ -0,0 +1,111 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <chrono>
#include <cinttypes>
#include <ctime>
#include <iostream>
#include <interpreter_loop.h>
#include <loguru.hpp>
#include <cpu/ppc/ppcemu.h>
std::chrono::high_resolution_clock::time_point global; // global timer
std::chrono::high_resolution_clock::time_point cuda_timer; // updates every 11 ms
std::chrono::high_resolution_clock::time_point disp_timer; // updates every 16 ms
using namespace std;
const uint64_t cuda_update = 11000;
const uint64_t display_update = 16667;
bool cuda_priority = 0;
bool disp_priority = 0;
uint64_t elapsed_times[3] = {0}; // Elapsed time to reach a cycle (for display)
uint64_t routine_bench[3] = {0}; // Estimated time (in microseconds) to cycle through functions
uint64_t routine_runtime[3] = {0, cuda_update, display_update}; // Time to elapse before execution
enum general_routine_timepoint { OVERALL_UPDATE_TIME, CUDA_UPDATE_TIME, DISPLAY_UPDATE_TIME };
void round_robin_bench() {
// Benchmark how much time elapses during a minimal CPU block
std::chrono::high_resolution_clock::time_point dummy = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 4096; i++) {
dppc_interpreter::ppc_ori(); //execute NOPs as a basic test
}
std::chrono::high_resolution_clock::time_point dummy2 = std::chrono::high_resolution_clock::now();
routine_bench[OVERALL_UPDATE_TIME] =
std::chrono::duration_cast<std::chrono::microseconds>(dummy2 - dummy).count();
std::cout << "Initial test: " << routine_bench[OVERALL_UPDATE_TIME] << endl;
}
void interpreter_update_counters() {
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
elapsed_times[OVERALL_UPDATE_TIME] =
std::chrono::duration_cast<std::chrono::microseconds>(end - global).count();
elapsed_times[CUDA_UPDATE_TIME] =
std::chrono::duration_cast<std::chrono::microseconds>(end - cuda_timer).count();
elapsed_times[DISPLAY_UPDATE_TIME] =
std::chrono::duration_cast<std::chrono::microseconds>(end - disp_timer).count();
// Calculate if the threshold for updating a time-critical section has reached or is about to be reached
if ((elapsed_times[CUDA_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
routine_runtime[CUDA_UPDATE_TIME]) {
cuda_priority = true;
elapsed_times[CUDA_UPDATE_TIME] = 0;
cuda_timer = end;
}
if ((elapsed_times[DISPLAY_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
routine_runtime[DISPLAY_UPDATE_TIME]) {
disp_priority = true;
elapsed_times[DISPLAY_UPDATE_TIME] = 0;
disp_timer = end;
}
}
void interpreter_main_loop() {
// Round robin algorithm goes here
round_robin_bench();
global = std::chrono::high_resolution_clock::now();
cuda_timer = global;
disp_timer = global;
for (;;) {
if (cuda_priority) {
LOG_F(9, "Placeholder for Cuda Update function!\n");
cuda_priority = false;
}
if (disp_priority) {
LOG_F(9, "Placeholder for Display Update function! \n");
disp_priority = false;
}
ppc_exec();
interpreter_update_counters();
}
}
+23
View File
@@ -0,0 +1,23 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
void interpreter_update_counters();
void interpreter_main_loop();
-17
View File
@@ -119,20 +119,3 @@ HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
return NULL;
}
}
int MachineBase::postinit_devices()
{
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
if (it->second->device_postinit()) {
return -1;
}
}
for (auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
if (it->second->device_postinit()) {
return -1;
}
}
return 0;
}
-1
View File
@@ -43,7 +43,6 @@ public:
void add_alias(std::string name, std::string alias);
HWComponent* get_comp_by_name(std::string name);
HWComponent* get_comp_by_type(HWCompType type);
int postinit_devices();
private:
std::string name;
+3 -37
View File
@@ -67,8 +67,6 @@ static const map<uint32_t, std::tuple<string, const char*>> rom_identity = {
{0x5A616E7A, {"pm4400", "Power Mac 4400/7220"}}, // Zanzibar
};
static const vector<string> WriteToggle = {"ON", "on", "OFF", "off"};
static const PropMap GossamerSettings = {
{"rambank1_size",
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
@@ -78,19 +76,6 @@ static const PropMap GossamerSettings = {
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
{"gfxmem_size",
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
{"mon_id",
new StrProperty("")},
{"fdd_img",
new StrProperty("")},
{"fdd_wr_prot", new StrProperty("OFF", WriteToggle)},
};
/** Monitors supported by the PDM on-board video. */
/* see displayid.cpp for the full list of supported monitor IDs. */
static const vector<string> PDMBuiltinMonitorIDs = {
"PortraitGS", "MacRGB12in", "MacRGB15in", "HiRes12-14in", "VGA-SVGA",
"MacRGB16in", "Multiscan15in", "Multiscan17in", "Multiscan20in",
"NotConnected"
};
static const PropMap PDMSettings = {
@@ -98,12 +83,6 @@ static const PropMap PDMSettings = {
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
{"rambank2_size",
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
{"mon_id",
new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)},
{"fdd_img",
new StrProperty("")},
{"fdd_wr_prot",
new StrProperty("OFF", WriteToggle)},
};
static const map<string, string> PropHelp = {
@@ -111,9 +90,6 @@ static const map<string, string> PropHelp = {
{"rambank2_size", "specifies RAM bank 2 size in MB"},
{"rambank3_size", "specifies RAM bank 3 size in MB"},
{"gfxmem_size", "specifies video memory size in MB"},
{"fdd_img", "specifies path to floppy disk image"},
{"fdd_wr_prot", "toggles floppy disks write protection"},
{"mon_id", "specifies which monitor to emulate"},
};
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
@@ -229,20 +205,10 @@ void list_properties() {
for (auto& p : get<0>(mach.second)) {
cout << setw(13) << p.first << "\t\t" << PropHelp.at(p.first)
<< endl;
cout << setw(13) << "\t\t\t" "Valid values: ";
switch(p.second->get_type()) {
case PROP_TYPE_INTEGER:
cout << dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
if (p.second->get_type() == PROP_TYPE_INTEGER) {
cout << setw(13) << "\t\t\t" "Valid values: " <<
dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
<< endl;
break;
case PROP_TYPE_STRING:
cout << dynamic_cast<StrProperty*>(p.second)->get_valid_values_as_str()
<< endl;
break;
default:
break;
}
cout << endl;
}
+3 -17
View File
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/machineid.h>
#include <devices/floppy/floppyimg.h>
#include <devices/ioctrl/macio.h>
#include <devices/memctrl/mpc106.h>
#include <devices/memctrl/spdram.h>
@@ -90,9 +89,9 @@ int create_gossamer(std::string& id) {
}
/* configure RAM slots */
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
/* register ATI 3D Rage Pro video card with the PCI host bridge */
gMachineObj->add_component("ATIRage",
@@ -103,19 +102,6 @@ int create_gossamer(std::string& id) {
/* Init virtual CPU and request MPC750 CPU aka G3 */
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
// post-initialize all devices
if (gMachineObj->postinit_devices()) {
LOG_F(ERROR, "Could not post-initialize devices!\n");
return -1;
}
/* check for a floppy image to be inserted into the virtual superdrive */
std::string fdd_path = GET_STR_PROP("fdd_img");
std::string fd_write_prot = GET_STR_PROP("fdd_wr_prot");
if (!fdd_path.empty()) {
open_floppy_image(fdd_path);
}
LOG_F(INFO, "Initialization complete.\n");
return 0;
+1 -32
View File
@@ -26,8 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cpu/ppc/ppcemu.h>
#include <devices/common/machineid.h>
#include <devices/common/scsi/scsi.h>
#include <devices/floppy/superdrive.h>
#include <devices/ioctrl/amic.h>
#include <devices/memctrl/hmc.h>
#include <devices/sound/soundserver.h>
@@ -60,7 +58,7 @@ int create_pdm(std::string& id) {
/* get raw pointer to HMC object */
HMC* hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
// allocate machine ID register and tell we're running PowerMac 6100
/* allocate machine ID register and tell we're running PowerMac 6100 */
// TODO: add a possibility to select another machine
// to be used with the same ROM
gMachineObj->add_component("MachineID", new NubusMacID(0x3010));
@@ -85,38 +83,9 @@ int create_pdm(std::string& id) {
return -1;
}
/* add internal SCSI bus */
gMachineObj->add_component("SCSI0", new ScsiBus);
/* Init virtual CPU and request MPC601 */
ppc_cpu_init(hmc_obj, PPC_VER::MPC601);
// post-initialize all devices
if (gMachineObj->postinit_devices()) {
LOG_F(ERROR, "Could not post-initialize devices!\n");
return -1;
}
// if a floppy image was given "insert" it into the virtual superdrive
std::string fd_image_path = GET_STR_PROP("fdd_img");
std::string fd_write_prot = GET_STR_PROP("fdd_wr_prot");
if (!fd_image_path.empty()) {
using namespace MacSuperdrive;
MacSuperDrive* fdd = dynamic_cast<MacSuperDrive*>
(gMachineObj->get_comp_by_name("Superdrive"));
bool write_flag = false;
if (!fd_write_prot.empty()) {
if ((fd_write_prot.compare("ON") == 0) || (fd_write_prot.compare("on") == 0)) {
write_flag = true;
}
}
fdd->insert_disk(fd_image_path, write_flag);
}
LOG_F(INFO, "Initialization completed.\n");
return 0;
+61
View File
@@ -0,0 +1,61 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <machines/machineproperties.h>
#include <map>
static std::map<std::string, StrProperty> PowerMac6100_Properties = {
{"machineid", StrProperty("PowerMacG3")},
{"cputype", StrProperty("PPC_MPC750")},
{"motherboard", StrProperty("Grackle")},
{"ioboard", StrProperty("Heathrow")},
{"rambank1", StrProperty("8")},
{"minram", StrProperty("32")},
{"maxram", StrProperty("256")},
{"gfxcard", StrProperty("Nubus_Video")},
{"gfxmem", StrProperty("2")}
};
static std::map<std::string, StrProperty> PowerMacG3_Properties = {
{"machineid", StrProperty("PowerMacG3")},
{"cputype", StrProperty("PPC_MPC750")},
{"motherboard", StrProperty("Grackle")},
{"ioboard", StrProperty("Heathrow")},
{"rambank1", StrProperty("64")},
{"minram", StrProperty("32")},
{"maxram", StrProperty("256")},
{"gfxcard", StrProperty("ATI_Rage_Pro")},
{"gfxmem", StrProperty("2")}
};
static std::map<std::string, uint32_t> PPC_CPUs = {
{"PPC_MPC601", 0x00010001},
{"PPC_MPC603", 0x00030001},
{"PPC_MPC604", 0x00040001},
{"PPC_MPC603E", 0x00060101},
{"PPC_MPC750", 0x00080200}
};
static std::map<std::string, uint32_t> GFX_CARDs = {
{"ATI_Rage_Pro", 0x10024750},
{"ATI_Rage_128_Pro", 0x10025052}
};
-133
View File
@@ -1,133 +0,0 @@
/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-21 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "machineproperties.h"
#include <algorithm>
#include <cinttypes>
#include <string>
#include <sstream>
void StrProperty::set_string(std::string str)
{
if (!this->check_val(str)) {
LOG_F(ERROR, "Invalid property value '%s'!", str.c_str());
LOG_F(ERROR, "Valid values: %s!",
this->get_valid_values_as_str().c_str());
} else {
this->val = str;
}
}
std::string StrProperty::get_valid_values_as_str()
{
std::stringstream ss;
switch (this->check_type) {
case CHECK_TYPE_LIST: {
bool first = true;
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
if (!first)
ss << ", ";
ss << "'" << *it << "'";
first = false;
}
}
return ss.str();
default:
return std::string("Any");
}
}
bool StrProperty::check_val(std::string str)
{
switch (this->check_type) {
case CHECK_TYPE_LIST:
if (find(this->vec.begin(), this->vec.end(), str) != this->vec.end())
return true;
else
return false;
default:
return true;
}
}
uint32_t IntProperty::get_int()
{
try {
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
/* perform value check */
if (!this->check_val(result)) {
LOG_F(ERROR, "Invalid property value %d!", result);
LOG_F(ERROR, "Valid values: %s!",
this->get_valid_values_as_str().c_str());
this->set_string(to_string(this->int_val));
} else {
this->int_val = result;
}
} catch (string bad_string) {
LOG_F(ERROR, "Could not convert string %s to an integer!",
bad_string.c_str());
}
return this->int_val;
}
string IntProperty::get_valid_values_as_str()
{
std::stringstream ss;
switch (this->check_type) {
case CHECK_TYPE_RANGE:
ss << "[" << this->min << "..." << this->max << "]";
return ss.str();
case CHECK_TYPE_LIST: {
bool first = true;
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
if (!first)
ss << ", ";
ss << *it;
first = false;
}
return ss.str();
}
default:
return std::string("Any");
}
}
bool IntProperty::check_val(uint32_t val)
{
switch (this->check_type) {
case CHECK_TYPE_RANGE:
if (val < this->min || val > this->max)
return false;
else
return true;
case CHECK_TYPE_LIST:
if (find(this->vec.begin(), this->vec.end(), val) != this->vec.end())
return true;
else
return false;
default:
return true;
}
}
+68 -33
View File
@@ -19,13 +19,17 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <endianswap.h>
#include <loguru.hpp>
#include <algorithm>
#include <cinttypes>
#include <limits>
#include <string>
#include <map>
#include <memory>
#include <string>
#include <limits>
#include <sstream>
#include <utility>
#include <vector>
#ifndef MACHINE_PROPERTIES_H
@@ -33,6 +37,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
using namespace std;
#define ILLEGAL_DEVICE_VALUE 0x168A523B
/** Property types. */
enum PropType : int {
PROP_TYPE_UNKNOWN = 0,
@@ -60,15 +66,15 @@ public:
/* Clone method for copying derived property objects. */
virtual BasicProperty* clone() const = 0;
virtual string get_string() {
string get_string() {
return this->val;
}
virtual void set_string(string str) {
void set_string(string str) {
this->val = str;
}
virtual PropType get_type() {
PropType get_type() {
return this->type;
}
@@ -82,33 +88,9 @@ protected:
class StrProperty : public BasicProperty {
public:
StrProperty(string str)
: BasicProperty(PROP_TYPE_STRING, str)
{
this->check_type = CHECK_TYPE_NONE;
this->vec.clear();
}
/* construct a string property with a list of valid values. */
StrProperty(string str, vector<string> vec)
: BasicProperty(PROP_TYPE_STRING, str)
{
this->check_type = CHECK_TYPE_LIST;
this->vec = vec;
}
: BasicProperty(PROP_TYPE_STRING, str) {}
BasicProperty* clone() const { return new StrProperty(*this); }
/* override BasicProperty::set_string() and perform checks */
void set_string(string str);
string get_valid_values_as_str();
protected:
bool check_val(string str);
private:
CheckType check_type;
vector<string> vec;
};
/** Property class that holds an integer value. */
@@ -149,12 +131,65 @@ public:
BasicProperty* clone() const { return new IntProperty(*this); }
uint32_t get_int();
uint32_t get_int() {
try {
uint32_t result = strtoul(this->get_string().c_str(), 0, 0);
string get_valid_values_as_str();
/* perform value check */
if (!this->check_val(result)) {
LOG_F(ERROR, "Invalid property value %d!", result);
LOG_F(ERROR, "Valid values: %s!",
this->get_valid_values_as_str().c_str());
this->set_string(to_string(this->int_val));
} else {
this->int_val = result;
}
} catch (string bad_string) {
LOG_F(ERROR, "Could not convert string %s to an integer!",
bad_string.c_str());
}
return this->int_val;
}
string get_valid_values_as_str() {
stringstream ss;
switch (this->check_type) {
case CHECK_TYPE_RANGE:
ss << "[" << this->min << "..." << this->max << "]";
return ss.str();
case CHECK_TYPE_LIST: {
bool first = true;
for (auto it = begin(this->vec); it != end(this->vec); ++it) {
if (!first)
ss << ", ";
ss << *it;
first = false;
}
return ss.str();
}
default:
return string("None");
}
}
protected:
bool check_val(uint32_t val);
bool check_val(uint32_t val) {
switch (this->check_type) {
case CHECK_TYPE_RANGE:
if (val < this->min || val > this->max)
return false;
else
return true;
case CHECK_TYPE_LIST:
if (find(this->vec.begin(), this->vec.end(), val) != this->vec.end())
return true;
else
return false;
default:
return true;
}
}
private:
uint32_t int_val;
+10 -11
View File
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
// This is where the magic begins
#include "debugger/debugger.h"
#include "execution/interpreter_loop.h"
#include "machines/machinefactory.h"
#include "machines/machineproperties.h"
#include "utils/profiler.h"
@@ -197,17 +198,15 @@ int main(int argc, char** argv) {
signal(SIGABRT, sigabrt_handler);
switch (execution_mode) {
case 0:
for (;;) {
ppc_exec();
}
break;
case 1:
enter_debugger();
break;
default:
LOG_F(ERROR, "Invalid EXECUTION MODE");
return 0;
case 0:
interpreter_main_loop();
break;
case 1:
enter_debugger();
break;
default:
LOG_F(ERROR, "Invalid EXECUTION MODE");
return 0;
}
bail:
+3 -3
View File
@@ -28,7 +28,7 @@ as found in various PowerMacintosh models.
### Old World Macs
| ROM dump/Machine | BootROM codename | OF version | OF image offset |
| ROM dump/Machine | BootROM codename | OF version | OF image offset |
|:------------------------------------:|:----------------:|:-------------:|:---------------:|
| Power Macintosh 7300/7600/8600/9600 | TNT | 1.0.5 | 0x330000 |
| Bandai Pippin | Pip | 1.0.5 | 0x330000 |
@@ -130,9 +130,9 @@ Apple's OpenFirmware contains a small kernel implemented in the native PowerPC c
1. In response to power coming on, HWInit code in the Power Macintosh ROM performs initialization of the memory controller and the basic I/O facilities as well as some self-testing. After that, the startup chime is played.
2. HWInit passes control to OpenFirmware kernel that prepares OF execution from RAM. OF builds the **device tree** - a platform-independent description of the attached HW.
3. OF returns control to HWInit that initializes several low-level data structures required by the Nanokernel.
4. HWInit passes control to the Nanokernel that initializes the native execution enviroment and the 68k emulator.
4. HWInit passes control to the Nanokernel that initializes the low-level virtual machine and the 68k emulator.
5. 68k emulator executes the start-up code in the Macintosh ROM that initializes various managers.
6. The device tree generated by the OpenFirmware in step 2 is imported by the Expansion Bus Manager initialization code and stored in the **NameRegistry**.
6. The device tree generated by the OpenFirmware in step 2 is imported by the Expansion Bus Manager initialization and stored in the **NameRegistry**.
7. An operating system is located and loaded.
### New World Macs