mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
127
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7708f987d5 | ||
|
|
4d5062c601 | ||
|
|
152b371253 | ||
|
|
a0c3f9f76c | ||
|
|
0b26a593cd | ||
|
|
23d0fb33d0 | ||
|
|
b9e45e075b | ||
|
|
b24227b139 | ||
|
|
48571a6ac4 | ||
|
|
155234ad89 | ||
|
|
cfb1999caf | ||
|
|
36cb84eaaa | ||
|
|
aa5ef742f6 | ||
|
|
47d2e235a3 | ||
|
|
576912dd55 | ||
|
|
5b366e592c | ||
|
|
170a9d78e7 | ||
|
|
63b10175bf | ||
|
|
a5fb124e69 | ||
|
|
72d45fb0de | ||
|
|
f754f63f8f | ||
|
|
8cf290c034 | ||
|
|
b408a02ef9 | ||
|
|
67146028bf | ||
|
|
acdb14a10a | ||
|
|
dcd4384d46 | ||
|
|
8348370142 | ||
|
|
6b3cdad877 | ||
|
|
6b40caf63a | ||
|
|
99f596ea19 | ||
|
|
637844269f | ||
|
|
ec5bf8e985 | ||
|
|
4bbc5ab0af | ||
|
|
6cfde29f00 | ||
|
|
c115a887d8 | ||
|
|
4cdb81e822 | ||
|
|
f4f7edcc28 | ||
|
|
ae97d7bcc7 | ||
|
|
5f48a3ab5b | ||
|
|
9db3076a48 | ||
|
|
6eb6a5892d | ||
|
|
0ebcd15a3d | ||
|
|
04acf120d6 | ||
|
|
278799795c | ||
|
|
c47cbb354d | ||
|
|
8ff2125312 | ||
|
|
a69763c6de | ||
|
|
5e32b599d6 | ||
|
|
fd6327ab62 | ||
|
|
45528bfc6d | ||
|
|
c690049246 | ||
|
|
932f2bbceb | ||
|
|
a7ef177164 | ||
|
|
300965ab10 | ||
|
|
d2e7c9a5df | ||
|
|
ee9c692115 | ||
|
|
de1f0c8a9b | ||
|
|
52a64168d7 | ||
|
|
b571ff8412 | ||
|
|
762319055c | ||
|
|
cd9ccb66ed | ||
|
|
ac64f9e30d | ||
|
|
16123dea45 | ||
|
|
814260f0b6 | ||
|
|
439509b408 | ||
|
|
07f57a1e9b | ||
|
|
0c9ddaccf7 | ||
|
|
b23bb04dac | ||
|
|
a7601c36bd | ||
|
|
1a883ba73e | ||
|
|
2e50b364c4 | ||
|
|
b4b41a47b2 | ||
|
|
5b90a3e21d | ||
|
|
ca83f7e8ef | ||
|
|
337a9d6dd0 | ||
|
|
ddf139a659 | ||
|
|
6b8fe50f50 | ||
|
|
233ab778b6 | ||
|
|
4872af1053 | ||
|
|
0ca1ebf724 | ||
|
|
632479b1ba | ||
|
|
9b81891467 | ||
|
|
7b2e1d90e6 | ||
|
|
6fa6b4d4dc | ||
|
|
6efe6f13a9 | ||
|
|
c254749493 | ||
|
|
fd9f8c90a5 | ||
|
|
0a0761c7e0 | ||
|
|
e9d91175c4 | ||
|
|
0c0166b565 | ||
|
|
7bb7ff9f0f | ||
|
|
c2cd076662 | ||
|
|
a9f73e7384 | ||
|
|
14c7d18bdb | ||
|
|
5787d49e9b | ||
|
|
25150268cd | ||
|
|
f7a1412ec7 | ||
|
|
a424d48447 | ||
|
|
e76e3afa87 | ||
|
|
482fe3eb80 | ||
|
|
4de2afc0c5 | ||
|
|
742003b6f3 | ||
|
|
10b8366219 | ||
|
|
4364c89fd4 | ||
|
|
d11d693b52 | ||
|
|
357fc3a73a | ||
|
|
1051a7fb9b | ||
|
|
0687b0c60e | ||
|
|
fc26be3e24 | ||
|
|
f733859e28 | ||
|
|
a4cac2df81 | ||
|
|
4886b4d52a | ||
|
|
3c5a0ad8c1 | ||
|
|
ac267b3daa | ||
|
|
cb347434d3 | ||
|
|
3a7e3c1986 | ||
|
|
d113c4cf7a | ||
|
|
7a8b534c07 | ||
|
|
73d0356058 | ||
|
|
ee7b2838bc | ||
|
|
6f247f64cd | ||
|
|
0b2fd60308 | ||
|
|
f809124a2e | ||
|
|
586828b375 | ||
|
|
e36150a5ca | ||
|
|
0f8e68d4bf | ||
|
|
c543d0936c |
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(dingusppc)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
@@ -50,7 +50,7 @@ As of now, only the Power Macintosh G3 Beige is implemented.
|
||||
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++20 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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/>.
|
||||
*/
|
||||
|
||||
/** Poor man's signals & slots mechanism implementation. */
|
||||
|
||||
// Inspired by http://schneegans.github.io/tutorials/2015/09/20/signal-slot
|
||||
|
||||
#ifndef CORE_SIGNAL_H
|
||||
#define CORE_SIGNAL_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
template <typename... Args>
|
||||
class CoreSignal {
|
||||
public:
|
||||
CoreSignal() = default;
|
||||
~CoreSignal() = default;
|
||||
|
||||
// Connects a std::function type slot to the signal.
|
||||
// The return value can be used to disconnect the slot.
|
||||
int connect_func(std::function<void(Args...)> const& slot) const {
|
||||
_slots.insert(std::make_pair(++_current_id, slot));
|
||||
return _current_id;
|
||||
}
|
||||
|
||||
// Connects a class method type slot to the signal.
|
||||
// The return value can be used to disconnect the slot.
|
||||
template <typename T>
|
||||
int connect_method(T *inst, void (T::*func)(Args...)) {
|
||||
return connect_func([=](Args... args) {
|
||||
(inst->*func)(args...);
|
||||
});
|
||||
}
|
||||
|
||||
// Calls all connected slots.
|
||||
void emit(Args... args) {
|
||||
for (auto const& it : _slots) {
|
||||
it.second(args...);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::map<int, std::function<void(Args...)>> _slots;
|
||||
mutable unsigned int _current_id { 0 };
|
||||
};
|
||||
|
||||
#endif // CORE_SIGNAL_H
|
||||
+27
-3
@@ -42,7 +42,7 @@ void EventManager::poll_events()
|
||||
WindowEvent we;
|
||||
we.sub_type = event.window.event;
|
||||
we.window_id = event.window.windowID;
|
||||
this->post_event(we);
|
||||
this->_window_signal.emit(we);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -54,12 +54,36 @@ void EventManager::poll_events()
|
||||
key_ups++;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
mouse_motions++;
|
||||
case SDL_MOUSEMOTION: {
|
||||
MouseEvent me;
|
||||
me.xrel = event.motion.xrel;
|
||||
me.yrel = event.motion.yrel;
|
||||
me.flags = MOUSE_EVENT_MOTION;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 1;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
MouseEvent me;
|
||||
me.buttons_state = 0;
|
||||
me.flags = MOUSE_EVENT_BUTTON;
|
||||
this->_mouse_signal.emit(me);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
unhandled_events++;
|
||||
}
|
||||
}
|
||||
|
||||
// perform post-processing
|
||||
this->_post_signal.emit();
|
||||
}
|
||||
+52
-33
@@ -22,33 +22,47 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef EVENT_MANAGER_H
|
||||
#define EVENT_MANAGER_H
|
||||
|
||||
#include <core/coresignal.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
enum EventType : uint16_t {
|
||||
EVENT_UNKNOWN = 0,
|
||||
EVENT_WINDOW = 100,
|
||||
EVENT_KEYBOARD = 200,
|
||||
EVENT_MOUSE = 300,
|
||||
};
|
||||
|
||||
class BaseEvent {
|
||||
class WindowEvent {
|
||||
public:
|
||||
BaseEvent(EventType type) { this->type = type; };
|
||||
EventType type;
|
||||
};
|
||||
|
||||
class WindowEvent : public BaseEvent {
|
||||
public:
|
||||
WindowEvent() : BaseEvent(EventType::EVENT_WINDOW) {};
|
||||
WindowEvent() = default;
|
||||
~WindowEvent() = default;
|
||||
|
||||
uint16_t sub_type;
|
||||
uint32_t window_id;
|
||||
};
|
||||
|
||||
enum : uint32_t {
|
||||
MOUSE_EVENT_MOTION = 1 << 0,
|
||||
MOUSE_EVENT_BUTTON = 1 << 1,
|
||||
KEYBOARD_EVENT_DOWN = 1 << 0,
|
||||
KEYBOARD_EVENT_UP = 1 << 1,
|
||||
};
|
||||
|
||||
class MouseEvent {
|
||||
public:
|
||||
MouseEvent() = default;
|
||||
~MouseEvent() = default;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t xrel;
|
||||
uint32_t yrel;
|
||||
uint8_t buttons_state;
|
||||
};
|
||||
|
||||
class KeyboardEvent {
|
||||
public:
|
||||
KeyboardEvent() = default;
|
||||
~KeyboardEvent() = default;
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t key;
|
||||
uint16_t keys_state;
|
||||
};
|
||||
|
||||
class EventManager {
|
||||
public:
|
||||
static EventManager* get_instance() {
|
||||
@@ -58,31 +72,36 @@ public:
|
||||
return event_manager;
|
||||
};
|
||||
|
||||
using EventHandler = std::function<void(const BaseEvent&)>;
|
||||
|
||||
void poll_events();
|
||||
|
||||
void register_handler(const EventType event_type, EventHandler&& eh) {
|
||||
this->_handlers[event_type].emplace_back(std::move(eh));
|
||||
};
|
||||
template <typename T>
|
||||
void add_window_handler(T *inst, void (T::*func)(const WindowEvent&)) {
|
||||
_window_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
void post_event(const BaseEvent& event) {
|
||||
auto type = event.type;
|
||||
template <typename T>
|
||||
void add_mouse_handler(T *inst, void (T::*func)(const MouseEvent&)) {
|
||||
_mouse_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
if( _handlers.find(type) == _handlers.end() )
|
||||
return;
|
||||
template <typename T>
|
||||
void add_keyboard_handler(T* inst, void (T::*func)(const KeyboardEvent&)) {
|
||||
_keyboard_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
auto&& handlers = _handlers.at(type);
|
||||
|
||||
for(auto&& handler : handlers)
|
||||
handler(event);
|
||||
template <typename T>
|
||||
void add_post_handler(T *inst, void (T::*func)()) {
|
||||
_post_signal.connect_method(inst, func);
|
||||
}
|
||||
|
||||
private:
|
||||
static EventManager* event_manager;
|
||||
EventManager() {}; // private constructor to implement a singleton
|
||||
|
||||
std::map<EventType, std::list<EventHandler>> _handlers;
|
||||
CoreSignal<const WindowEvent&> _window_signal;
|
||||
CoreSignal<const MouseEvent&> _mouse_signal;
|
||||
CoreSignal<const KeyboardEvent&> _keyboard_signal;
|
||||
CoreSignal<> _post_signal;
|
||||
|
||||
uint64_t events_captured = 0;
|
||||
uint64_t unhandled_events = 0;
|
||||
|
||||
+30
-4
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -55,16 +55,38 @@ uint32_t TimerManager::add_oneshot_timer(uint64_t timeout, timer_cb cb)
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
uint32_t TimerManager::add_immediate_timer(timer_cb cb) {
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + 10;
|
||||
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, uint64_t delay, timer_cb cb)
|
||||
{
|
||||
if (!interval || interval <= MIN_TIMEOUT_NS) {
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns", (long long unsigned)interval);
|
||||
LOG_F(WARNING, "Cyclic timer interval too short, timeout=%llu ns",
|
||||
(long long unsigned)interval);
|
||||
}
|
||||
|
||||
TimerInfo* ti = new TimerInfo;
|
||||
|
||||
ti->id = ++this->id;
|
||||
ti->timeout_ns = this->get_time_now() + interval;
|
||||
ti->timeout_ns = this->get_time_now() + delay;
|
||||
ti->interval_ns = interval;
|
||||
ti->cb = cb;
|
||||
|
||||
@@ -81,6 +103,10 @@ uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb)
|
||||
return ti->id;
|
||||
}
|
||||
|
||||
uint32_t TimerManager::add_cyclic_timer(uint64_t interval, timer_cb cb) {
|
||||
return this->add_cyclic_timer(interval, interval, cb);
|
||||
}
|
||||
|
||||
void TimerManager::cancel_timer(uint32_t id)
|
||||
{
|
||||
TimerInfo* cur_timer = this->timer_queue.top().get();
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -103,7 +103,9 @@ public:
|
||||
|
||||
// creating and cancelling timers
|
||||
uint32_t add_oneshot_timer(uint64_t timeout, timer_cb cb);
|
||||
uint32_t add_immediate_timer(timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, timer_cb cb);
|
||||
uint32_t add_cyclic_timer(uint64_t interval, uint64_t delay, timer_cb cb);
|
||||
void cancel_timer(uint32_t id);
|
||||
|
||||
uint64_t process_timers(uint64_t time_now);
|
||||
|
||||
@@ -101,7 +101,7 @@ const char* opc_bim_str[6] = {/* boolean immediate instructions */
|
||||
"andi.",
|
||||
"andis."};
|
||||
|
||||
const char* opc_logic[16] = {/* indexed load/store opcodes */
|
||||
const char* opc_logic[16] = {/* logic instructions */
|
||||
"and",
|
||||
"andc",
|
||||
"",
|
||||
|
||||
+11
-1
@@ -44,6 +44,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
//#define CPU_PROFILING // enable CPU profiling
|
||||
|
||||
/** type of compiler used during execution */
|
||||
enum EXEC_MODE:uint32_t {
|
||||
interpreter = 0,
|
||||
debugger = 1,
|
||||
threaded_int = 2,
|
||||
jit = 3
|
||||
};
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
@@ -165,6 +173,7 @@ extern uint64_t rtc_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint32_t dec_wr_value;
|
||||
extern uint32_t tbr_freq_ghz;
|
||||
extern uint64_t tbr_period_ns;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
@@ -311,6 +320,7 @@ extern bool grab_return;
|
||||
|
||||
extern bool power_on;
|
||||
extern bool int_pin;
|
||||
extern bool dec_exception_pending;
|
||||
|
||||
extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
@@ -335,7 +345,7 @@ extern uint64_t exceptions_processed;
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init(uint32_t cpu_version);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_fpu_off();
|
||||
|
||||
+22
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -56,7 +56,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ISI:
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
if (exec_flags & ~EXEF_TIMER) {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_next_instruction_address;
|
||||
} else {
|
||||
ppc_state.spr[SPR::SRR0] = ppc_state.pc & 0xFFFFFFFCUL;
|
||||
}
|
||||
ppc_next_instruction_address = 0x0400;
|
||||
break;
|
||||
|
||||
@@ -85,7 +89,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
ppc_state.spr[SPR::SRR0] = (ppc_state.pc & 0xFFFFFFFC) + 4;
|
||||
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_next_instruction_address = 0x0900;
|
||||
break;
|
||||
|
||||
@@ -100,7 +108,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
default:
|
||||
ABORT_F("Unknown exception occured: %X\n", (unsigned)exception_type);
|
||||
ABORT_F("Unknown exception occurred: %X\n", (unsigned)exception_type);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -123,7 +131,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
if (exception_type != Except_Type::EXC_EXT_INT) {
|
||||
if (exception_type != Except_Type::EXC_EXT_INT && exception_type != Except_Type::EXC_DECR) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
@@ -134,11 +142,11 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
|
||||
switch (exception_type) {
|
||||
case Except_Type::EXC_SYSTEM_RESET:
|
||||
exc_descriptor = "System reset exception occured";
|
||||
exc_descriptor = "System reset exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_MACHINE_CHECK:
|
||||
exc_descriptor = "Machine check exception occured";
|
||||
exc_descriptor = "Machine check exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DSI:
|
||||
@@ -156,31 +164,31 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_EXT_INT:
|
||||
exc_descriptor = "External interrupt exception occured";
|
||||
exc_descriptor = "External interrupt exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_ALIGNMENT:
|
||||
exc_descriptor = "Alignment exception occured";
|
||||
exc_descriptor = "Alignment exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_PROGRAM:
|
||||
exc_descriptor = "Program exception occured";
|
||||
exc_descriptor = "Program exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_NO_FPU:
|
||||
exc_descriptor = "Floating-Point unavailable exception occured";
|
||||
exc_descriptor = "Floating-Point unavailable exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_DECR:
|
||||
exc_descriptor = "Decrementer exception occured";
|
||||
exc_descriptor = "Decrementer exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_SYSCALL:
|
||||
exc_descriptor = "Syscall exception occured";
|
||||
exc_descriptor = "Syscall exception occurred";
|
||||
break;
|
||||
|
||||
case Except_Type::EXC_TRACE:
|
||||
exc_descriptor = "Trace exception occured";
|
||||
exc_descriptor = "Trace exception occurred";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+21
-15
@@ -39,6 +39,8 @@ using namespace dppc_interpreter;
|
||||
|
||||
MemCtrlBase* mem_ctrl_instance = 0;
|
||||
|
||||
bool is_601 = false;
|
||||
|
||||
bool power_on = 1;
|
||||
|
||||
SetPRS ppc_state;
|
||||
@@ -55,6 +57,7 @@ uint32_t ppc_next_instruction_address; // Used for branching, setting up the
|
||||
|
||||
unsigned exec_flags; // execution control flags
|
||||
bool int_pin = false; // interrupt request pin state: true - asserted
|
||||
bool dec_exception_pending = false;
|
||||
|
||||
/* copy of local variable bb_start_la. Need for correct
|
||||
calculation of CPU cycles after setjmp that clobbers
|
||||
@@ -69,7 +72,8 @@ int icnt_factor;
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
|
||||
uint64_t rtc_timestamp; // stores vCPU virtual time of the last RTC write
|
||||
uint64_t tbr_wr_value; // last value written to the TBR
|
||||
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a 32 bit fraction less than 1.0.
|
||||
uint32_t tbr_freq_ghz; // TBR/RTC driving frequency in GHz expressed as a 32 bit fraction less than 1.0 (999.999999 MHz maximum).
|
||||
uint64_t tbr_period_ns; // TBR/RTC period in ns expressed as a 64 bit value with 32 fractional bits (<1 Hz minimum).
|
||||
uint64_t timebase_counter; // internal timebase counter
|
||||
uint64_t dec_wr_timestamp; // stores vCPU virtual time of the last DEC write
|
||||
uint32_t dec_wr_value; // last value written to the DEC register
|
||||
@@ -331,10 +335,10 @@ static void ppc_exec_inner()
|
||||
// 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;
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
@@ -360,12 +364,12 @@ static void ppc_exec_inner()
|
||||
}
|
||||
// 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) {
|
||||
if (!(exec_flags & EXEF_RFI) && (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;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
@@ -436,10 +440,10 @@ static void ppc_exec_until_inner(const uint32_t 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;
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
@@ -463,12 +467,12 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
}
|
||||
// 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) {
|
||||
if (!(exec_flags & EXEF_RFI) && (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;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
@@ -511,10 +515,10 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t 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;
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
page_start = eb_start & PAGE_MASK;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
|
||||
// interpret execution block
|
||||
@@ -539,12 +543,12 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
}
|
||||
// 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) {
|
||||
if (!(exec_flags & EXEF_RFI) && (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;
|
||||
eb_end = page_start + PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
@@ -768,6 +772,7 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq)
|
||||
rtc_timestamp = 0;
|
||||
tbr_wr_value = 0;
|
||||
tbr_freq_ghz = (tb_freq << 32) / NS_PER_SEC;
|
||||
tbr_period_ns = ((uint64_t)NS_PER_SEC << 32) / tb_freq;
|
||||
|
||||
exec_flags = 0;
|
||||
|
||||
@@ -806,8 +811,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq)
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::PVR] = cpu_version;
|
||||
is_601 = (cpu_version >> 16) == 1;
|
||||
|
||||
if ((cpu_version & 0xFFFF0000) == 0x00010000) {
|
||||
if (is_601) {
|
||||
/* MPC601 sets MSR[ME] bit during hard reset / Power-On */
|
||||
ppc_state.msr = 0x1040;
|
||||
} else {
|
||||
@@ -815,7 +821,7 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq)
|
||||
ppc_state.spr[SPR::DEC] = 0xFFFFFFFFUL;
|
||||
}
|
||||
|
||||
ppc_mmu_init(cpu_version);
|
||||
ppc_mmu_init();
|
||||
|
||||
/* redirect code execution to reset vector */
|
||||
ppc_state.pc = 0xFFF00100;
|
||||
|
||||
+220
-112
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,7 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
/* pointer to exception handler to be called when a MMU exception is occured. */
|
||||
/* pointer to exception handler to be called when a MMU exception is occurred. */
|
||||
void (*mmu_exception_handler)(Except_Type exception_type, uint32_t srr1_bits);
|
||||
|
||||
/* pointers to BAT update functions. */
|
||||
@@ -43,8 +43,6 @@ std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
PPC_BAT_entry ibat_array[4] = {{0}};
|
||||
PPC_BAT_entry dbat_array[4] = {{0}};
|
||||
|
||||
bool is_601_MMU = false;
|
||||
|
||||
//#define MMU_PROFILING // uncomment this to enable MMU profiling
|
||||
//#define TLB_PROFILING // uncomment this to enable SoftTLB profiling
|
||||
|
||||
@@ -79,11 +77,11 @@ uint64_t num_entry_replacements = 0; // number of entry replacements
|
||||
#endif // TLB_PROFILING
|
||||
|
||||
/** remember recently used physical memory regions for quicker translation. */
|
||||
AddressMapEntry last_read_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_write_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_read_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_write_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_exec_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
AddressMapEntry last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0, nullptr, nullptr};
|
||||
|
||||
void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
@@ -309,26 +307,36 @@ static PATResult page_address_translation(uint32_t la, bool is_instr_fetch,
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size, bool* is_writable)
|
||||
{
|
||||
MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
|
||||
MMIODevice *devobj = nullptr;
|
||||
uint8_t *host_va = nullptr;
|
||||
uint32_t dev_base = 0;
|
||||
bool is_writable;
|
||||
AddressMapEntry *cur_dma_rgn;
|
||||
|
||||
if (addr >= last_dma_area.start && (addr + size) <= last_dma_area.end) {
|
||||
if (is_writable)
|
||||
*is_writable = last_dma_area.type & RT_RAM;
|
||||
return last_dma_area.mem_ptr + (addr - last_dma_area.start);
|
||||
cur_dma_rgn = &last_dma_area;
|
||||
} else {
|
||||
AddressMapEntry* entry = mem_ctrl_instance->find_range(addr);
|
||||
if (entry && entry->type & (RT_ROM | RT_RAM)) {
|
||||
last_dma_area.start = entry->start;
|
||||
last_dma_area.end = entry->end;
|
||||
last_dma_area.mem_ptr = entry->mem_ptr;
|
||||
last_dma_area.type = entry->type;
|
||||
if (is_writable)
|
||||
*is_writable = entry->type & RT_RAM;
|
||||
return last_dma_area.mem_ptr + (addr - last_dma_area.start);
|
||||
} else {
|
||||
ABORT_F("SOS: DMA access to unmapped memory %08X!\n", addr);
|
||||
}
|
||||
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
|
||||
if (!cur_dma_rgn || (addr + size) > cur_dma_rgn->end)
|
||||
ABORT_F("SOS: DMA access to unmapped physical memory %08X!\n", addr);
|
||||
|
||||
last_dma_area = *cur_dma_rgn;
|
||||
}
|
||||
|
||||
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio)
|
||||
ABORT_F("SOS: DMA access to a MMIO region is not allowed");
|
||||
|
||||
if (cur_dma_rgn->type & (RT_ROM | RT_RAM)) {
|
||||
host_va = cur_dma_rgn->mem_ptr + (addr - cur_dma_rgn->start);
|
||||
is_writable = last_dma_area.type & RT_RAM;
|
||||
} else { // RT_MMIO
|
||||
devobj = cur_dma_rgn->devobj;
|
||||
dev_base = cur_dma_rgn->start;
|
||||
is_writable = true; // all MMIO devices must provide a write method
|
||||
}
|
||||
|
||||
return MapDmaResult{cur_dma_rgn->type, is_writable, host_va, devobj, dev_base};
|
||||
}
|
||||
|
||||
// primary ITLB for all MMU modes
|
||||
@@ -501,7 +509,7 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
/* instruction address translation if enabled */
|
||||
if (ppc_state.msr & 0x20) {
|
||||
// attempt block address translation first
|
||||
if (is_601_MMU) {
|
||||
if (is_601) {
|
||||
bat_res = mpc601_block_address_translation(guest_va);
|
||||
} else {
|
||||
bat_res = ppc_block_address_translation<BATType::IBAT>(guest_va);
|
||||
@@ -526,9 +534,9 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
}
|
||||
|
||||
// look up host virtual address
|
||||
AddressMapEntry* reg_desc = mem_ctrl_instance->find_range(phys_addr);
|
||||
if (reg_desc) {
|
||||
if (reg_desc->type & RT_MMIO) {
|
||||
AddressMapEntry* rgn_desc = mem_ctrl_instance->find_range(phys_addr);
|
||||
if (rgn_desc) {
|
||||
if (rgn_desc->type & RT_MMIO) {
|
||||
ABORT_F("Instruction fetch from MMIO region at 0x%08X!\n", phys_addr);
|
||||
}
|
||||
// refill the secondary TLB
|
||||
@@ -536,8 +544,8 @@ static TLBEntry* itlb2_refill(uint32_t guest_va)
|
||||
tlb_entry = tlb2_target_entry<TLBType::ITLB>(tag);
|
||||
tlb_entry->tag = tag;
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->host_va_offs_r = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
(phys_addr - reg_desc->start);
|
||||
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
|
||||
(phys_addr - rgn_desc->start);
|
||||
} else {
|
||||
ABORT_F("Instruction fetch from unmapped memory at 0x%08X!\n", phys_addr);
|
||||
}
|
||||
@@ -557,7 +565,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & 0x10) {
|
||||
// attempt block address translation first
|
||||
if (is_601_MMU) {
|
||||
if (is_601) {
|
||||
bat_res = mpc601_block_address_translation(guest_va);
|
||||
} else {
|
||||
bat_res = ppc_block_address_translation<BATType::DBAT>(guest_va);
|
||||
@@ -599,19 +607,20 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
}
|
||||
|
||||
// look up host virtual address
|
||||
AddressMapEntry* reg_desc = mem_ctrl_instance->find_range(phys_addr);
|
||||
if (reg_desc) {
|
||||
AddressMapEntry* rgn_desc = mem_ctrl_instance->find_range(phys_addr);
|
||||
if (rgn_desc) {
|
||||
// refill the secondary TLB
|
||||
tlb_entry = tlb2_target_entry<TLBType::DTLB>(tag);
|
||||
tlb_entry->tag = tag;
|
||||
if (reg_desc->type & RT_MMIO) { // MMIO region
|
||||
if (rgn_desc->type & RT_MMIO) { // MMIO region
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_IO;
|
||||
tlb_entry->reg_desc = reg_desc;
|
||||
tlb_entry->rgn_desc = rgn_desc;
|
||||
tlb_entry->dev_base_va = guest_va - (phys_addr - rgn_desc->start);
|
||||
} else { // memory region backed by host memory
|
||||
tlb_entry->flags = flags | TLBFlags::PAGE_MEM;
|
||||
tlb_entry->host_va_offs_r = (int64_t)reg_desc->mem_ptr - guest_va +
|
||||
(phys_addr - reg_desc->start);
|
||||
if (reg_desc->type == RT_ROM) {
|
||||
tlb_entry->host_va_offs_r = (int64_t)rgn_desc->mem_ptr - guest_va +
|
||||
(phys_addr - rgn_desc->start);
|
||||
if (rgn_desc->type == RT_ROM) {
|
||||
// redirect writes to the dummy page for ROM regions
|
||||
tlb_entry->host_va_offs_w = (int64_t)&dummy_page - guest_va;
|
||||
} else {
|
||||
@@ -620,7 +629,16 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
}
|
||||
return tlb_entry;
|
||||
} else {
|
||||
LOG_F(WARNING, "Access to unmapped physical memory, phys_addr=0x%08X", phys_addr);
|
||||
static uint32_t last_phys_addr = -1;
|
||||
static uint32_t first_phys_addr = -1;
|
||||
if (phys_addr != last_phys_addr + 4) {
|
||||
if (last_phys_addr != -1 && last_phys_addr != first_phys_addr) {
|
||||
LOG_F(WARNING, " ... phys_addr=0x%08X", last_phys_addr);
|
||||
}
|
||||
first_phys_addr = phys_addr;
|
||||
LOG_F(WARNING, "Access to unmapped physical memory, phys_addr=0x%08X", first_phys_addr);
|
||||
}
|
||||
last_phys_addr = phys_addr;
|
||||
return &UnmappedMem;
|
||||
}
|
||||
}
|
||||
@@ -642,26 +660,26 @@ static inline TLBEntry* lookup_secondary_tlb(uint32_t guest_va, uint32_t tag) {
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
} else if (tlb_entry[1].tag == tag) {
|
||||
tlb_entry = &tlb_entry[1];
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits = 0x2;
|
||||
tlb_entry[1].lru_bits = 0x3;
|
||||
tlb_entry[2].lru_bits &= 0x1;
|
||||
tlb_entry[3].lru_bits &= 0x1;
|
||||
tlb_entry = &tlb_entry[1];
|
||||
} else if (tlb_entry[2].tag == tag) {
|
||||
tlb_entry = &tlb_entry[2];
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x3;
|
||||
tlb_entry[3].lru_bits = 0x2;
|
||||
tlb_entry = &tlb_entry[2];
|
||||
} else if (tlb_entry[3].tag == tag) {
|
||||
tlb_entry = &tlb_entry[3];
|
||||
// update LRU bits
|
||||
tlb_entry[0].lru_bits &= 0x1;
|
||||
tlb_entry[1].lru_bits &= 0x1;
|
||||
tlb_entry[2].lru_bits = 0x2;
|
||||
tlb_entry[3].lru_bits = 0x3;
|
||||
tlb_entry = &tlb_entry[3];
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -810,43 +828,73 @@ void tlb_flush_entries(TLBFlags type)
|
||||
|
||||
// Flush entries from the secondary TLBs
|
||||
for (i = 0; i < TLB_SIZE * TLB2_WAYS; i++) {
|
||||
if (dtlb2_mode1[i].flags & type) {
|
||||
dtlb2_mode1[i].tag = TLB_INVALID_TAG;
|
||||
if (m1_tlb[i].flags & type) {
|
||||
m1_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb2_mode2[i].flags & type) {
|
||||
dtlb2_mode2[i].tag = TLB_INVALID_TAG;
|
||||
if (m2_tlb[i].flags & type) {
|
||||
m2_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
|
||||
if (dtlb2_mode3[i].flags & type) {
|
||||
dtlb2_mode3[i].tag = TLB_INVALID_TAG;
|
||||
if (m3_tlb[i].flags & type) {
|
||||
m3_tlb[i].tag = TLB_INVALID_TAG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool gTLBFlushBatEntries = false;
|
||||
bool gTLBFlushPatEntries = false;
|
||||
bool gTLBFlushIBatEntries = false;
|
||||
bool gTLBFlushDBatEntries = false;
|
||||
bool gTLBFlushIPatEntries = false;
|
||||
bool gTLBFlushDPatEntries = false;
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_bat_entries()
|
||||
{
|
||||
if (!gTLBFlushBatEntries)
|
||||
return;
|
||||
|
||||
tlb_flush_entries<tlb_type>(TLBE_FROM_BAT);
|
||||
|
||||
gTLBFlushBatEntries = false;
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
if (!gTLBFlushIBatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_BAT);
|
||||
gTLBFlushIBatEntries = false;
|
||||
} else {
|
||||
if (!gTLBFlushDBatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_BAT);
|
||||
gTLBFlushDBatEntries = false;
|
||||
}
|
||||
}
|
||||
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_pat_entries()
|
||||
{
|
||||
if (!gTLBFlushPatEntries)
|
||||
return;
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
if (!gTLBFlushIPatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::ITLB>(TLBE_FROM_PAT);
|
||||
gTLBFlushIPatEntries = false;
|
||||
} else {
|
||||
if (!gTLBFlushDPatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::DTLB>(TLBE_FROM_PAT);
|
||||
gTLBFlushDPatEntries = false;
|
||||
}
|
||||
}
|
||||
|
||||
tlb_flush_entries<tlb_type>(TLBE_FROM_PAT);
|
||||
|
||||
gTLBFlushPatEntries = false;
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_all_entries()
|
||||
{
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
if (!gTLBFlushIBatEntries && !gTLBFlushIPatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::ITLB>((TLBFlags)(TLBE_FROM_BAT | TLBE_FROM_PAT));
|
||||
gTLBFlushIBatEntries = false;
|
||||
gTLBFlushIPatEntries = false;
|
||||
} else {
|
||||
if (!gTLBFlushDBatEntries && !gTLBFlushDPatEntries)
|
||||
return;
|
||||
tlb_flush_entries<TLBType::DTLB>((TLBFlags)(TLBE_FROM_BAT | TLBE_FROM_PAT));
|
||||
gTLBFlushDBatEntries = false;
|
||||
gTLBFlushDPatEntries = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void mpc601_bat_update(uint32_t bat_reg)
|
||||
@@ -880,10 +928,13 @@ static void mpc601_bat_update(uint32_t bat_reg)
|
||||
}
|
||||
|
||||
// MPC601 has unified BATs so we're going to flush both ITLB and DTLB
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
if (!gTLBFlushIBatEntries || !gTLBFlushIPatEntries || !gTLBFlushDBatEntries || !gTLBFlushDPatEntries) {
|
||||
gTLBFlushIBatEntries = true;
|
||||
gTLBFlushIPatEntries = true;
|
||||
gTLBFlushDBatEntries = true;
|
||||
gTLBFlushDPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::ITLB>);
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -905,9 +956,10 @@ static void ppc_ibat_update(uint32_t bat_reg)
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::ITLB>);
|
||||
if (!gTLBFlushIBatEntries || !gTLBFlushIPatEntries) {
|
||||
gTLBFlushIBatEntries = true;
|
||||
gTLBFlushIPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::ITLB>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -929,9 +981,10 @@ static void ppc_dbat_update(uint32_t bat_reg)
|
||||
bat_entry->phys_hi = ppc_state.spr[upper_reg_num + 1] & hi_mask;
|
||||
bat_entry->bepi = ppc_state.spr[upper_reg_num] & hi_mask;
|
||||
|
||||
if (!gTLBFlushBatEntries) {
|
||||
gTLBFlushBatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_bat_entries<TLBType::DTLB>);
|
||||
if (!gTLBFlushDBatEntries || !gTLBFlushDPatEntries) {
|
||||
gTLBFlushDBatEntries = true;
|
||||
gTLBFlushDPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_all_entries<TLBType::DTLB>);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -940,8 +993,9 @@ void mmu_pat_ctx_changed()
|
||||
{
|
||||
// Page address translation context changed so we need to flush
|
||||
// all PAT entries from both ITLB and DTLB
|
||||
if (!gTLBFlushPatEntries) {
|
||||
gTLBFlushPatEntries = true;
|
||||
if (!gTLBFlushIPatEntries || !gTLBFlushDPatEntries) {
|
||||
gTLBFlushIPatEntries = true;
|
||||
gTLBFlushDPatEntries = true;
|
||||
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::ITLB>);
|
||||
add_ctx_sync_action(&tlb_flush_pat_entries<TLBType::DTLB>);
|
||||
}
|
||||
@@ -960,7 +1014,7 @@ void mmu_print_regs()
|
||||
i, ppc_state.spr[529+i*2]);
|
||||
}
|
||||
|
||||
if (!is_601_MMU) {
|
||||
if (!is_601) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
LOG_F(INFO, "DBAT%dU = 0x%X, DBAT%dL = 0x%X",
|
||||
i, ppc_state.spr[536+i*2],
|
||||
@@ -978,9 +1032,10 @@ void mmu_print_regs()
|
||||
}
|
||||
|
||||
// Forward declarations.
|
||||
static uint32_t read_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t size);
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t value,
|
||||
uint32_t size);
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value);
|
||||
|
||||
template <class T>
|
||||
inline T mmu_read_vmem(uint32_t guest_va)
|
||||
@@ -1025,11 +1080,28 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_reads_total++;
|
||||
#endif
|
||||
return (
|
||||
tlb2_entry->reg_desc->devobj->read(tlb2_entry->reg_desc->start,
|
||||
guest_va - tlb2_entry->reg_desc->start,
|
||||
sizeof(T))
|
||||
);
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
{
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
4) << 32) |
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
guest_va + 4 - tlb2_entry->dev_base_va,
|
||||
4)
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (
|
||||
tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
sizeof(T))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1039,7 +1111,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
return read_unaligned(guest_va, host_va, sizeof(T));
|
||||
return read_unaligned<T>(guest_va, host_va);
|
||||
}
|
||||
|
||||
// handle aligned memory accesses
|
||||
@@ -1134,9 +1206,24 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
#ifdef MMU_PROFILING
|
||||
iomem_writes_total++;
|
||||
#endif
|
||||
tlb2_entry->reg_desc->devobj->write(tlb2_entry->reg_desc->start,
|
||||
guest_va - tlb2_entry->reg_desc->start,
|
||||
value, sizeof(T));
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
{
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
value >> 32, 4);
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
guest_va + 4 - tlb2_entry->dev_base_va,
|
||||
(uint32_t)value, 4);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
guest_va - tlb2_entry->dev_base_va,
|
||||
value, sizeof(T));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1147,7 +1234,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
write_unaligned(guest_va, host_va, value, sizeof(T));
|
||||
write_unaligned<T>(guest_va, host_va, value);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1174,42 +1261,53 @@ template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint64_t value);
|
||||
|
||||
static uint32_t read_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t size)
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
T result = 0;
|
||||
|
||||
// is it a misaligned cross-page read?
|
||||
if (((guest_va & 0xFFF) + size) > 0x1000) {
|
||||
if (((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_r++;
|
||||
#endif
|
||||
// Break such a memory access into multiple, bytewise accesses.
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
for (int i = 0; i < size; guest_va++, i++) {
|
||||
for (int i = 0; i < sizeof(T); guest_va++, i++) {
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va);
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_reads++;
|
||||
#endif
|
||||
switch(size) {
|
||||
switch(sizeof(T)) {
|
||||
case 1:
|
||||
return *host_va;
|
||||
case 2:
|
||||
return READ_WORD_BE_U(host_va);
|
||||
case 4:
|
||||
return READ_DWORD_BE_U(host_va);
|
||||
case 8: // FIXME: should we raise alignment exception here?
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
return READ_QWORD_BE_U(host_va);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t value,
|
||||
uint32_t size)
|
||||
// explicitely instantiate all required read_unaligned variants
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
{
|
||||
// is it a misaligned cross-page write?
|
||||
if (((guest_va & 0xFFF) + size) > 0x1000) {
|
||||
if (((guest_va & 0xFFF) + sizeof(T)) > 0x1000) {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_crossp_w++;
|
||||
#endif
|
||||
@@ -1217,29 +1315,41 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t value,
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
|
||||
uint32_t shift = (size - 1) * 8;
|
||||
uint32_t shift = (sizeof(T) - 1) * 8;
|
||||
|
||||
for (int i = 0; i < size; shift -= 8, guest_va++, i++) {
|
||||
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
|
||||
mmu_write_vmem<uint8_t>(guest_va, (value >> shift) & 0xFF);
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
unaligned_writes++;
|
||||
#endif
|
||||
switch(size) {
|
||||
switch(sizeof(T)) {
|
||||
case 1:
|
||||
*host_va = value;
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_U(host_va, value);
|
||||
break;
|
||||
case 4:
|
||||
WRITE_DWORD_BE_U(host_va, value);
|
||||
break;
|
||||
case 8: // FIXME: should we raise alignment exception here?
|
||||
case 8:
|
||||
if (guest_va & 3) {
|
||||
ppc_exception_handler(Except_Type::EXC_ALIGNMENT, 0x0);
|
||||
}
|
||||
WRITE_QWORD_BE_U(host_va, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// explicitely instantiate all required write_unaligned variants
|
||||
template void write_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va, uint64_t value);
|
||||
|
||||
|
||||
/* MMU profiling. */
|
||||
#ifdef MMU_PROFILING
|
||||
|
||||
@@ -1589,26 +1699,26 @@ static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
tlb2_entry[2].lru_bits &= 0x1;
|
||||
tlb2_entry[3].lru_bits &= 0x1;
|
||||
} else if (tlb2_entry[1].tag == tag) {
|
||||
tlb2_entry = &tlb2_entry[1];
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits = 0x2;
|
||||
tlb2_entry[1].lru_bits = 0x3;
|
||||
tlb2_entry[2].lru_bits &= 0x1;
|
||||
tlb2_entry[3].lru_bits &= 0x1;
|
||||
tlb2_entry = &tlb2_entry[1];
|
||||
} else if (tlb2_entry[2].tag == tag) {
|
||||
tlb2_entry = &tlb2_entry[2];
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits &= 0x1;
|
||||
tlb2_entry[1].lru_bits &= 0x1;
|
||||
tlb2_entry[2].lru_bits = 0x3;
|
||||
tlb2_entry[3].lru_bits = 0x2;
|
||||
tlb2_entry = &tlb2_entry[2];
|
||||
} else if (tlb2_entry[3].tag == tag) {
|
||||
tlb2_entry = &tlb2_entry[3];
|
||||
// update LRU bits
|
||||
tlb2_entry[0].lru_bits &= 0x1;
|
||||
tlb2_entry[1].lru_bits &= 0x1;
|
||||
tlb2_entry[2].lru_bits = 0x2;
|
||||
tlb2_entry[3].lru_bits = 0x3;
|
||||
tlb2_entry = &tlb2_entry[3];
|
||||
} else { // secondary TLB miss ->
|
||||
// perform full address translation and refill the secondary TLB
|
||||
tlb2_entry = dtlb2_refill(guest_va, 0);
|
||||
@@ -1621,7 +1731,7 @@ static inline uint64_t tlb_translate_addr(uint32_t guest_va)
|
||||
tlb1_entry->host_va_offs_r = tlb2_entry->host_va_offs_r;
|
||||
return tlb1_entry->host_va_offs_r + guest_va;
|
||||
} else { // an attempt to access a memory-mapped device
|
||||
return guest_va - tlb2_entry->reg_desc->start;
|
||||
return guest_va - tlb2_entry->rgn_desc->start;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1868,7 +1978,7 @@ uint8_t* quickinstruction_translate(uint32_t addr) {
|
||||
|
||||
return real_addr;
|
||||
}
|
||||
#endif
|
||||
#endif // Old and slow code
|
||||
|
||||
uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
uint32_t save_dsisr, save_dar;
|
||||
@@ -1914,19 +2024,17 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void ppc_mmu_init(uint32_t cpu_version)
|
||||
void ppc_mmu_init()
|
||||
{
|
||||
mmu_exception_handler = ppc_exception_handler;
|
||||
|
||||
if ((cpu_version >> 16) == 1) {
|
||||
// use 601-style BATs
|
||||
if (is_601) {
|
||||
// use 601-style unified BATs
|
||||
ibat_update = &mpc601_bat_update;
|
||||
is_601_MMU = true;
|
||||
} else {
|
||||
// use PPC-style BATs
|
||||
ibat_update = &ppc_ibat_update;
|
||||
dbat_update = &ppc_dbat_update;
|
||||
is_601_MMU = false;
|
||||
}
|
||||
|
||||
// invalidate all IDTLB entries
|
||||
|
||||
+20
-5
@@ -70,6 +70,17 @@ typedef struct PATResult {
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
/** DMA memory mapping result. */
|
||||
typedef struct MapDmaResult {
|
||||
uint32_t type;
|
||||
bool is_writable;
|
||||
// for memory regions
|
||||
uint8_t* host_va;
|
||||
// for MMIO regions
|
||||
MMIODevice* dev_obj;
|
||||
uint32_t dev_base;
|
||||
} MapDmaResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define PAGE_SIZE (1 << PAGE_SIZE_BITS)
|
||||
#define PAGE_MASK ~(PAGE_SIZE - 1)
|
||||
@@ -82,11 +93,15 @@ typedef struct TLBEntry {
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
int64_t host_va_offs_r;
|
||||
AddressMapEntry* reg_desc;
|
||||
struct { // for memory pages
|
||||
int64_t host_va_offs_r;
|
||||
int64_t host_va_offs_w;
|
||||
};
|
||||
struct { // for MMIO pages
|
||||
AddressMapEntry* rgn_desc;
|
||||
int64_t dev_base_va;
|
||||
};
|
||||
};
|
||||
int64_t host_va_offs_w;
|
||||
int64_t unused;
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
@@ -102,7 +117,7 @@ enum TLBFlags : uint16_t {
|
||||
extern std::function<void(uint32_t bat_reg)> ibat_update;
|
||||
extern std::function<void(uint32_t bat_reg)> dbat_update;
|
||||
|
||||
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size, bool* is_writable);
|
||||
extern MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
|
||||
+61
-11
@@ -849,8 +849,12 @@ void dppc_interpreter::ppc_mtmsr() {
|
||||
// generate External Interrupt Exception
|
||||
// if CPU interrupt line is asserted
|
||||
if (ppc_state.msr & 0x8000 && int_pin) {
|
||||
LOG_F(WARNING, "MTMSR: CPU INT pending, generate CPU exception");
|
||||
//LOG_F(WARNING, "MTMSR: CPU INT pending, generate CPU exception");
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
||||
} else if ((ppc_state.msr & 0x8000) && dec_exception_pending) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "MTMSR: decrementer exception triggered");
|
||||
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
||||
} else {
|
||||
mmu_change_mode();
|
||||
}
|
||||
@@ -894,9 +898,46 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
}
|
||||
|
||||
|
||||
static uint32_t decrementer_timer_id = 0;
|
||||
|
||||
static void trigger_decrementer_exception() {
|
||||
decrementer_timer_id = 0;
|
||||
dec_wr_value = -1;
|
||||
dec_wr_timestamp = get_virt_time_ns();
|
||||
if (ppc_state.msr & 0x8000) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "decrementer exception triggered");
|
||||
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
||||
}
|
||||
else {
|
||||
//LOG_F(WARNING, "decrementer exception pending");
|
||||
dec_exception_pending = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void update_decrementer(uint32_t val) {
|
||||
dec_wr_value = val;
|
||||
dec_wr_timestamp = get_virt_time_ns();
|
||||
|
||||
dec_exception_pending = false;
|
||||
|
||||
if (is_601)
|
||||
return;
|
||||
|
||||
if (decrementer_timer_id) {
|
||||
//LOG_F(WARNING, "decrementer cancel timer");
|
||||
TimerManager::get_instance()->cancel_timer(decrementer_timer_id);
|
||||
}
|
||||
|
||||
uint64_t time_out;
|
||||
uint32_t time_out_lo;
|
||||
_u32xu64(val, tbr_period_ns, time_out, time_out_lo);
|
||||
//LOG_F(WARNING, "decrementer:0x%08X ns:%llu", val, time_out);
|
||||
decrementer_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
time_out,
|
||||
trigger_decrementer_exception
|
||||
);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mfspr() {
|
||||
@@ -1401,6 +1442,15 @@ void dppc_interpreter::ppc_rfi() {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ppc_state.msr & 0x8000) && dec_exception_pending) {
|
||||
dec_exception_pending = false;
|
||||
//LOG_F(WARNING, "decrementer exception from rfi msr:0x%X", ppc_state.msr);
|
||||
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
||||
ppc_exception_handler(Except_Type::EXC_DECR, 0);
|
||||
ppc_state.spr[SPR::SRR0] = save_srr0;
|
||||
return;
|
||||
}
|
||||
|
||||
ppc_next_instruction_address = ppc_state.spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
||||
|
||||
do_ctx_sync(); // RFI is context synchronizing
|
||||
@@ -1487,12 +1537,14 @@ void dppc_interpreter::ppc_dcbz() {
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
|
||||
ppc_effective_address &= 0xFFFFFFE0; // align EA on a 32-byte boundary
|
||||
ppc_effective_address &= 0xFFFFFFE0UL; // align EA on a 32-byte boundary
|
||||
|
||||
//mem_write_qword(ppc_effective_address, 0);
|
||||
//mem_write_qword((ppc_effective_address + 8), 0);
|
||||
//mem_write_qword((ppc_effective_address + 16), 0);
|
||||
//mem_write_qword((ppc_effective_address + 24), 0);
|
||||
// the following is not especially efficient but necessary
|
||||
// to make BlockZero under Mac OS 8.x and later to work
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address + 0, 0);
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address + 8, 0);
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address + 16, 0);
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address + 24, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1638,19 +1690,17 @@ void dppc_interpreter::ppc_stwcx() {
|
||||
#ifdef CPU_PROFILING
|
||||
num_int_stores++;
|
||||
#endif
|
||||
// PLACEHOLDER CODE FOR STWCX - We need to check for reserve memory
|
||||
if (rc_flag == 0) {
|
||||
ppc_illegalop();
|
||||
} else {
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
ppc_state.cr &= 0x0FFFFFFFUL; // clear CR0
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000UL) >> 3; // copy XER[SO] to CR0[SO]
|
||||
if (ppc_state.reserve) {
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, ppc_result_d);
|
||||
//mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x30000000 : 0x20000000;
|
||||
ppc_state.reserve = false;
|
||||
} else {
|
||||
ppc_state.cr |= (ppc_state.spr[SPR::XER] & 0x80000000) ? 0x10000000 : 0;
|
||||
ppc_state.cr |= 0x20000000UL; // set CR0[EQ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/memctrl/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/serial/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/sound/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/video/*.cpp"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus emulation. */
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
AdbBus::AdbBus(std::string name) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::ADB_HOST);
|
||||
this->devices.clear();
|
||||
}
|
||||
|
||||
void AdbBus::register_device(AdbDevice* dev_obj) {
|
||||
this->devices.push_back(dev_obj);
|
||||
}
|
||||
|
||||
uint8_t AdbBus::process_command(const uint8_t* in_data, int data_size) {
|
||||
uint8_t dev_addr, dev_reg;
|
||||
|
||||
this->output_count = 0;
|
||||
|
||||
if (!data_size)
|
||||
return ADB_STAT_OK;
|
||||
|
||||
uint8_t cmd_byte = in_data[0];
|
||||
uint8_t cmd = cmd_byte & 0xF;
|
||||
|
||||
if(!cmd) { // SendReset
|
||||
LOG_F(9, "%s: SendReset issued", this->name.c_str());
|
||||
for (auto dev : this->devices)
|
||||
dev->reset();
|
||||
} else if (cmd == 1) { // Flush
|
||||
dev_addr = cmd_byte >> 4;
|
||||
|
||||
LOG_F(9, "%s: Flush issued, dev_addr=0x%X", this->name.c_str(), dev_addr);
|
||||
} else if ((cmd & 0xC) == 8) { // Listen
|
||||
dev_addr = cmd_byte >> 4;
|
||||
dev_reg = cmd_byte & 3;
|
||||
|
||||
LOG_F(9, "%s: Listen R%d issued, dev_addr=0x%X", this->name.c_str(),
|
||||
dev_reg, dev_addr);
|
||||
|
||||
this->input_buf = in_data + 1;
|
||||
this->input_count = data_size - 1;
|
||||
|
||||
for (auto dev : this->devices)
|
||||
dev->listen(dev_addr, dev_reg);
|
||||
} else if ((cmd & 0xC) == 0xC) { // Talk
|
||||
dev_addr = cmd_byte >> 4;
|
||||
dev_reg = cmd_byte & 3;
|
||||
|
||||
LOG_F(9, "%s: Talk R%d issued, dev_addr=0x%X", this->name.c_str(),
|
||||
dev_reg, dev_addr);
|
||||
|
||||
this->got_answer = false;
|
||||
|
||||
for (auto dev : this->devices)
|
||||
this->got_answer = dev->talk(dev_addr, dev_reg);
|
||||
|
||||
if (!this->got_answer)
|
||||
return ADB_STAT_TIMEOUT;
|
||||
} else {
|
||||
ABORT_F("%s: unsupported ADB command 0x%X", this->name.c_str(), cmd_byte);
|
||||
}
|
||||
|
||||
return ADB_STAT_OK;
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbBus_Descriptor = {
|
||||
AdbBus::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbBus, AdbBus_Descriptor);
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus definitions. */
|
||||
|
||||
#ifndef ADB_BUS_H
|
||||
#define ADB_BUS_H
|
||||
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define ADB_MAX_DATA_SIZE 8
|
||||
|
||||
/** ADB status. */
|
||||
enum {
|
||||
ADB_STAT_OK = 0,
|
||||
ADB_STAT_SRQ_ACTIVE = 1 << 0,
|
||||
ADB_STAT_TIMEOUT = 1 << 1,
|
||||
ADB_STAT_AUTOPOLL = 1 << 6,
|
||||
};
|
||||
|
||||
class AdbDevice; // forward declaration to prevent compiler errors
|
||||
|
||||
class AdbBus : public HWComponent {
|
||||
public:
|
||||
AdbBus(std::string name);
|
||||
~AdbBus() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbBus>(new AdbBus("ADB-BUS"));
|
||||
}
|
||||
|
||||
void register_device(AdbDevice* dev_obj);
|
||||
uint8_t process_command(const uint8_t* in_data, int data_size);
|
||||
uint8_t get_output_count() { return this->output_count; };
|
||||
|
||||
// callbacks meant to be called by devices
|
||||
const uint8_t* get_input_buf() { return this->input_buf; };
|
||||
uint8_t* get_output_buf() { return this->output_buf; };
|
||||
uint8_t get_input_count() { return this->input_count; };
|
||||
void set_output_count(uint8_t count) { this->output_count = count; };
|
||||
bool already_answered() { return this->got_answer; };
|
||||
|
||||
private:
|
||||
std::vector<AdbDevice*> devices;
|
||||
|
||||
bool got_answer = false;
|
||||
const uint8_t* input_buf = nullptr;
|
||||
uint8_t output_buf[ADB_MAX_DATA_SIZE] = {};
|
||||
uint8_t input_count = 0;
|
||||
uint8_t output_count = 0;
|
||||
};
|
||||
|
||||
#endif // ADB_BUS_H
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Base class for Apple Desktop Bus devices. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
AdbDevice::AdbDevice(std::string name) {
|
||||
this->set_name(name);
|
||||
this->supports_types(HWCompType::ADB_DEV);
|
||||
}
|
||||
|
||||
int AdbDevice::device_postinit() {
|
||||
// register itself with the ADB host
|
||||
this->host_obj = dynamic_cast<AdbBus*>(gMachineObj->get_comp_by_type(HWCompType::ADB_HOST));
|
||||
this->host_obj->register_device(this);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
bool AdbDevice::talk(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
if (dev_addr == this->my_addr && !this->got_collision) {
|
||||
// see if another device already responded to this command
|
||||
if (this->host_obj->already_answered()) {
|
||||
this->got_collision = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(reg_num & 3) {
|
||||
case 0:
|
||||
return this->get_register_0();
|
||||
case 1:
|
||||
return this->get_register_1();
|
||||
case 2:
|
||||
return this->get_register_2();
|
||||
case 3:
|
||||
return this->get_register_3();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbDevice::listen(const uint8_t dev_addr, const uint8_t reg_num) {
|
||||
if (dev_addr == this->my_addr) {
|
||||
switch(reg_num & 3) {
|
||||
case 0:
|
||||
this->set_register_0();
|
||||
case 1:
|
||||
this->set_register_1();
|
||||
case 2:
|
||||
this->set_register_2();
|
||||
case 3:
|
||||
this->set_register_3();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AdbDevice::get_register_3() {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
out_buf[0] = this->gen_random_address() | (this->exc_event_flag << 6) |
|
||||
(this->srq_flag << 5);
|
||||
out_buf[1] = this->dev_handler_id;
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t AdbDevice::gen_random_address() {
|
||||
return (TimerManager::get_instance()->current_time_ns() + 8) & 0xF;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Base class for Apple Desktop Bus devices. */
|
||||
|
||||
#ifndef ADB_DEVICE_H
|
||||
#define ADB_DEVICE_H
|
||||
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
/** Common ADB device addresses/types. */
|
||||
enum {
|
||||
ADB_ADDR_KBD = 2, // keyboards
|
||||
ADB_ADDR_RELPOS = 3, // relative position devices (mouse)
|
||||
ADB_ADDR_ABSPOS = 4, // absolute position devices (graphic tablets)
|
||||
};
|
||||
|
||||
class AdbBus; // forward declaration to prevent compiler errors
|
||||
|
||||
class AdbDevice : public HWComponent {
|
||||
public:
|
||||
AdbDevice(std::string name);
|
||||
~AdbDevice() = default;
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
virtual void reset() = 0;
|
||||
virtual bool talk(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual void listen(const uint8_t dev_addr, const uint8_t reg_num);
|
||||
virtual uint8_t get_address() { return this->my_addr; };
|
||||
|
||||
protected:
|
||||
uint8_t gen_random_address();
|
||||
|
||||
virtual bool get_register_0() { return false; };
|
||||
virtual bool get_register_1() { return false; };
|
||||
virtual bool get_register_2() { return false; };
|
||||
virtual bool get_register_3();
|
||||
|
||||
virtual void set_register_0() {};
|
||||
virtual void set_register_1() {};
|
||||
virtual void set_register_2() {};
|
||||
virtual void set_register_3() {};
|
||||
|
||||
uint8_t exc_event_flag = 0;
|
||||
uint8_t srq_flag = 0;
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t dev_handler_id = 0;
|
||||
bool got_collision = false;
|
||||
|
||||
AdbBus* host_obj = nullptr;
|
||||
};
|
||||
|
||||
#endif // ADB_DEVICE_H
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus Keyboard emulation. */
|
||||
|
||||
#include <devices/common/adb/adbkeyboard.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
AdbKeyboard::AdbKeyboard(std::string name) : AdbDevice(name) {
|
||||
EventManager::get_instance()->add_keyboard_handler(this, &AdbKeyboard::event_handler);
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void AdbKeyboard::event_handler(const KeyboardEvent& event) {
|
||||
if (event.flags & KEYBOARD_EVENT_DOWN) {
|
||||
}
|
||||
else if (event.flags & KEYBOARD_EVENT_UP) {
|
||||
}
|
||||
}
|
||||
|
||||
void AdbKeyboard::reset() {
|
||||
this->my_addr = ADB_ADDR_KBD;
|
||||
this->dev_handler_id = 2; // Extended ADB keyboard
|
||||
this->exc_event_flag = 2;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
}
|
||||
|
||||
bool AdbKeyboard::get_register_0() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_2() {
|
||||
}
|
||||
|
||||
void AdbKeyboard::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 3: // extended keyboard protocol isn't supported yet
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbKeyboard_Descriptor = {
|
||||
AdbKeyboard::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbKeyboard, AdbKeyboard_Descriptor);
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus Keyboard definitions. */
|
||||
|
||||
#ifndef ADB_KEYBOARD_H
|
||||
#define ADB_KEYBOARD_H
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class AdbKeyboard : public AdbDevice {
|
||||
public:
|
||||
AdbKeyboard(std::string name);
|
||||
~AdbKeyboard() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbKeyboard>(new AdbKeyboard("ADB-KEYBOARD"));
|
||||
}
|
||||
|
||||
void reset() override;
|
||||
void event_handler(const KeyboardEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
void set_register_2() override;
|
||||
void set_register_3() override;
|
||||
|
||||
|
||||
private:
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
};
|
||||
|
||||
#endif // ADB_KEYBOARD_H
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus Mouse emulation. */
|
||||
|
||||
#include <devices/common/adb/adbmouse.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
AdbMouse::AdbMouse(std::string name) : AdbDevice(name) {
|
||||
EventManager::get_instance()->add_mouse_handler(this, &AdbMouse::event_handler);
|
||||
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void AdbMouse::event_handler(const MouseEvent& event) {
|
||||
if (event.flags & MOUSE_EVENT_MOTION) {
|
||||
this->x_rel += event.xrel;
|
||||
this->y_rel += event.yrel;
|
||||
} else if (event.flags & MOUSE_EVENT_BUTTON) {
|
||||
this->buttons_state = event.buttons_state;
|
||||
this->changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AdbMouse::reset() {
|
||||
this->my_addr = ADB_ADDR_RELPOS;
|
||||
this->dev_handler_id = 1;
|
||||
this->exc_event_flag = 1;
|
||||
this->srq_flag = 1; // enable service requests
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->buttons_state = 0;
|
||||
this->changed = false;
|
||||
}
|
||||
|
||||
bool AdbMouse::get_register_0() {
|
||||
if (this->x_rel || this->y_rel || this->changed) {
|
||||
uint8_t* out_buf = this->host_obj->get_output_buf();
|
||||
|
||||
uint8_t button1_state = (this->buttons_state ^ 1) << 7;
|
||||
|
||||
// report Y-axis motion
|
||||
if (this->y_rel < -64)
|
||||
out_buf[0] = 0x40 | button1_state;
|
||||
else if (this->y_rel > 63)
|
||||
out_buf[0] = 0x3F | button1_state;
|
||||
else
|
||||
out_buf[0] = (this->y_rel & 0x7F) | button1_state;
|
||||
|
||||
// report X-axis motion
|
||||
if (this->x_rel < -64)
|
||||
out_buf[1] = 0x40 | 0x80;
|
||||
else if (this->x_rel > 63)
|
||||
out_buf[1] = 0x3F | 0x80;
|
||||
else
|
||||
out_buf[1] = (this->x_rel & 0x7F) | 0x80;
|
||||
|
||||
// reset accumulated motion data and button change flag
|
||||
this->x_rel = 0;
|
||||
this->y_rel = 0;
|
||||
this->changed = false;
|
||||
|
||||
this->host_obj->set_output_count(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AdbMouse::set_register_3() {
|
||||
if (this->host_obj->get_input_count() < 2) // ensure we got enough data
|
||||
return;
|
||||
|
||||
const uint8_t* in_data = this->host_obj->get_input_buf();
|
||||
|
||||
switch (in_data[1]) {
|
||||
case 0:
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
this->srq_flag = !!(in_data[0] & 0x20);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
this->dev_handler_id = in_data[1];
|
||||
break;
|
||||
case 4: // extended mouse protocol isn't supported yet
|
||||
break;
|
||||
case 0xFE: // move to a new address if there was no collision
|
||||
if (!this->got_collision) {
|
||||
this->my_addr = in_data[0] & 0xF;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unknown handler ID = 0x%X", this->name.c_str(), in_data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription AdbMouse_Descriptor = {
|
||||
AdbMouse::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AdbMouse, AdbMouse_Descriptor);
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Apple Desktop Bus Mouse definitions. */
|
||||
|
||||
#ifndef ADB_MOUSE_H
|
||||
#define ADB_MOUSE_H
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/common/adb/adbdevice.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class AdbMouse : public AdbDevice {
|
||||
public:
|
||||
AdbMouse(std::string name);
|
||||
~AdbMouse() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AdbMouse>(new AdbMouse("ADB-MOUSE"));
|
||||
}
|
||||
|
||||
void reset() override;
|
||||
void event_handler(const MouseEvent& event);
|
||||
|
||||
bool get_register_0() override;
|
||||
void set_register_3() override;
|
||||
|
||||
private:
|
||||
int32_t x_rel = 0;
|
||||
int32_t y_rel = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
bool changed = false;
|
||||
};
|
||||
|
||||
#endif // ADB_MOUSE_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,7 +19,7 @@ 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 Heathrow hard drive controller */
|
||||
/** @file Basic ATA device emulation. */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
@@ -30,33 +30,33 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaBaseDevice::AtaBaseDevice(const std::string name)
|
||||
{
|
||||
AtaBaseDevice::AtaBaseDevice(const std::string name, uint8_t type) {
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IDE_DEV);
|
||||
|
||||
device_reset();
|
||||
this->device_type = type;
|
||||
|
||||
device_reset(false);
|
||||
device_set_signature();
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_reset(const uint8_t dev_head_val)
|
||||
{
|
||||
this->r_error = 1; // Device 0 passed, Device 1 passed or not present
|
||||
void AtaBaseDevice::device_reset(bool is_soft_reset) {
|
||||
LOG_F(INFO, "%s: %s-reset triggered", this->name.c_str(),
|
||||
is_soft_reset ? "soft" : "hard");
|
||||
|
||||
// Diagnostic code
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_set_signature() {
|
||||
this->r_sect_count = 1;
|
||||
this->r_sect_num = 1;
|
||||
this->r_dev_ctrl = 0;
|
||||
this->r_dev_head = 0;
|
||||
|
||||
// set protocol signature
|
||||
if (this->device_type == DEVICE_TYPE_ATAPI) {
|
||||
this->r_cylinder_lo = 0x14;
|
||||
this->r_cylinder_hi = 0xEB;
|
||||
this->r_dev_head = dev_head_val;
|
||||
} else { // assume ATA by default
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_dev_head = 0;
|
||||
this->r_status = DRDY | DSC;
|
||||
}
|
||||
// set ATA protocol signature
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_status = DRDY | DSC; // DSC=1 is required for ATA devices
|
||||
}
|
||||
|
||||
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
@@ -117,13 +117,37 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::DEV_CTRL:
|
||||
if (!(this->r_dev_ctrl & SRST) && (value & SRST)) {
|
||||
LOG_F(INFO, "%s: soft reset triggered", this->name.c_str());
|
||||
this->r_status |= BSY;
|
||||
}
|
||||
this->r_dev_ctrl = value;
|
||||
this->device_control(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_control(const uint8_t new_ctrl) {
|
||||
// perform ATA Soft Reset if requested
|
||||
if ((this->r_dev_ctrl ^ new_ctrl) & SRST) {
|
||||
if (new_ctrl & SRST) { // SRST set -> phase 0 aka self-test
|
||||
this->r_status |= BSY;
|
||||
this->device_reset(true);
|
||||
} else { // SRST cleared -> phase 1 aka signature and error report
|
||||
if (!this->my_dev_id && this->host_obj->is_device1_present())
|
||||
this->r_error |= 0x80;
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
|
||||
if (this->my_dev_id && this->r_error == 1) {
|
||||
this->host_obj->assert_pdiag();
|
||||
}
|
||||
}
|
||||
}
|
||||
this->r_dev_ctrl = new_ctrl;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::update_intrq(uint8_t new_intrq_state) {
|
||||
if (!this->is_selected() || (this->r_dev_ctrl & IEN))
|
||||
return;
|
||||
|
||||
this->intrq_state = new_intrq_state;
|
||||
this->host_obj->report_intrq(new_intrq_state);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,31 +25,53 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATA_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include "endianswap.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
class AtaBaseDevice : public HWComponent, public AtaInterface
|
||||
{
|
||||
public:
|
||||
AtaBaseDevice(const std::string name);
|
||||
AtaBaseDevice(const std::string name, uint8_t type);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr);
|
||||
void write(const uint8_t reg_addr, const uint16_t value);
|
||||
void set_host(IdeChannel* host) { this->host_obj = host; };
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
int get_device_id() { return this->my_dev_id; };
|
||||
int get_device_id() override { return this->my_dev_id; };
|
||||
|
||||
void device_reset(const uint8_t dev_head_val = 0);
|
||||
void pdiag_callback() override {
|
||||
this->r_error &= 0x7F;
|
||||
};
|
||||
|
||||
private:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
virtual void device_reset(bool is_soft_reset);
|
||||
virtual void device_set_signature();
|
||||
void device_control(const uint8_t new_ctrl);
|
||||
void update_intrq(uint8_t new_intrq_state);
|
||||
|
||||
bool has_data() {
|
||||
return data_ptr && xfer_cnt;
|
||||
}
|
||||
|
||||
uint16_t get_data() {
|
||||
return BYTESWAP_16(*this->data_ptr++);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
|
||||
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
|
||||
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
|
||||
uint8_t intrq_state = 0; // INTRQ deasserted
|
||||
|
||||
IdeChannel* host_obj = nullptr;
|
||||
|
||||
// IDE aka task file registers
|
||||
uint8_t r_error;
|
||||
@@ -61,7 +83,13 @@ protected:
|
||||
uint8_t r_dev_head;
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_dev_ctrl;
|
||||
uint8_t r_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08;
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint8_t data_buf[512] = {};
|
||||
int data_pos = 0;
|
||||
int xfer_cnt = 0;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -44,27 +44,47 @@ enum {
|
||||
|
||||
/** ATA register offsets. */
|
||||
enum ATA_Reg : int {
|
||||
DATA = 0x0,
|
||||
ERROR = 0x1, // error (read)
|
||||
FEATURES = 0x1, // features (write)
|
||||
SEC_COUNT = 0x2, // sector count
|
||||
SEC_NUM = 0x3, // sector number
|
||||
CYL_LOW = 0x4, // cylinder low
|
||||
CYL_HIGH = 0x5, // cylinder high
|
||||
DEVICE_HEAD = 0x6, // device/head
|
||||
STATUS = 0x7, // status (read)
|
||||
COMMAND = 0x7, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
DATA = 0x00, // 16-bit data (read & write)
|
||||
ERROR = 0x01, // error (read)
|
||||
FEATURES = 0x01, // features (write)
|
||||
SEC_COUNT = 0x02, // sector count
|
||||
SEC_NUM = 0x03, // sector number
|
||||
CYL_LOW = 0x04, // cylinder low
|
||||
CYL_HIGH = 0x05, // cylinder high
|
||||
DEVICE_HEAD = 0x06, // device/head
|
||||
STATUS = 0x07, // status (read)
|
||||
COMMAND = 0x07, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
};
|
||||
|
||||
/** ATAPI specific register offsets. */
|
||||
enum ATAPI_Reg : int {
|
||||
INT_REASON = 0x2, // interrupt reason (read-only)
|
||||
BYTE_COUNT_LO = 0x4, // byte count (bits 0-7)
|
||||
BYTE_COUNT_HI = 0x5, // byte count (bits 8-15)
|
||||
};
|
||||
|
||||
/** ATAPI Interrupt Reason bits. */
|
||||
enum ATAPI_Int_Reason : uint8_t {
|
||||
CoD = 1 << 0,
|
||||
IO = 1 << 1,
|
||||
RELEASE = 1 << 2,
|
||||
};
|
||||
|
||||
/** ATAPI Features bits. */
|
||||
enum ATAPI_Features : uint8_t {
|
||||
DMA = 1 << 0,
|
||||
OVERLAP = 1 << 1
|
||||
};
|
||||
|
||||
/** Status register bits. */
|
||||
enum ATA_Status : int {
|
||||
ERR = 0x1,
|
||||
IDX = 0x2,
|
||||
CORR = 0x4,
|
||||
DRQ = 0x8,
|
||||
enum ATA_Status : uint8_t {
|
||||
ERR = 0x01,
|
||||
IDX = 0x02,
|
||||
CORR = 0x04,
|
||||
DRQ = 0x08,
|
||||
DSC = 0x10,
|
||||
DWF = 0x20,
|
||||
DRDY = 0x40,
|
||||
@@ -72,28 +92,28 @@ enum ATA_Status : int {
|
||||
};
|
||||
|
||||
/** Error register bits. */
|
||||
enum ATA_Error : int {
|
||||
ANMF = 0x1, //no address mark
|
||||
TK0NF = 0x2, //track 0 not found
|
||||
ABRT = 0x4, //abort command
|
||||
MCR = 0x8,
|
||||
enum ATA_Error : uint8_t {
|
||||
ANMF = 0x01, //no address mark
|
||||
TK0NF = 0x02, //track 0 not found
|
||||
ABRT = 0x04, //abort command
|
||||
MCR = 0x08,
|
||||
IDNF = 0x10, //id mark not found
|
||||
MC = 0x20, //media change request
|
||||
UNC = 0x40,
|
||||
BBK = 0x80 //bad block
|
||||
BBK = 0x80, //bad block
|
||||
};
|
||||
|
||||
/** Bit definition for the device control register. */
|
||||
enum ATA_CTRL : int{
|
||||
IEN = 0x2,
|
||||
SRST = 0x4,
|
||||
enum ATA_CTRL : uint8_t {
|
||||
IEN = 0x02,
|
||||
SRST = 0x04,
|
||||
HOB = 0x80,
|
||||
};
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : int {
|
||||
enum ATA_Cmd : uint8_t {
|
||||
NOP = 0x00,
|
||||
RESET_ATAPI = 0x08,
|
||||
ATAPI_SOFT_RESET = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
@@ -107,8 +127,9 @@ enum ATA_Cmd : int {
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
PACKET = 0xA0,
|
||||
IDFY_PKT_DEV = 0xA1,
|
||||
ATAPI_PACKET = 0xA0,
|
||||
ATAPI_IDFY_DEV = 0xA1,
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
@@ -116,6 +137,7 @@ enum ATA_Cmd : int {
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
SET_FEATURES = 0xEF,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
@@ -128,7 +150,8 @@ public:
|
||||
virtual uint16_t read(const uint8_t reg_addr) = 0;
|
||||
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
|
||||
|
||||
virtual int get_device_id() = 0;
|
||||
virtual int get_device_id() = 0;
|
||||
virtual void pdiag_callback() {};
|
||||
};
|
||||
|
||||
/** Dummy ATA device. */
|
||||
@@ -137,7 +160,7 @@ public:
|
||||
AtaNullDevice() = default;
|
||||
~AtaNullDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) {
|
||||
uint16_t read(const uint8_t reg_addr) override {
|
||||
// return all one's except DD7 if no device is present
|
||||
// DD7 corresponds to the BSY bit of the status register
|
||||
// The host should have a pull-down resistor on DD7
|
||||
@@ -146,10 +169,10 @@ public:
|
||||
return 0xFF7FU;
|
||||
};
|
||||
|
||||
void write(const uint8_t reg_addr, const uint16_t val) {};
|
||||
void write(const uint8_t reg_addr, const uint16_t val) override {};
|
||||
|
||||
// invalid device ID means no real device is present
|
||||
int get_device_id() { return ata_interface::DEVICE_ID_INVALID; };
|
||||
int get_device_id() override { return ata_interface::DEVICE_ID_INVALID; };
|
||||
};
|
||||
|
||||
#endif // ATA_INTERFACE_H
|
||||
@@ -31,8 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaHardDisk::AtaHardDisk() : AtaBaseDevice("ATA-HD")
|
||||
{
|
||||
AtaHardDisk::AtaHardDisk() : AtaBaseDevice("ATA-HD", DEVICE_TYPE_ATA) {
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
@@ -56,9 +55,6 @@ int AtaHardDisk::perform_command()
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RESET_ATAPI:
|
||||
device_reset();
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
~AtaHardDisk() = default;
|
||||
|
||||
void insert_image(std::string filename);
|
||||
int perform_command();
|
||||
int perform_command() override;
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Basic ATAPI interface emulation. */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atapibasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtapiBaseDevice::AtapiBaseDevice(const std::string name)
|
||||
: AtaBaseDevice(name, DEVICE_TYPE_ATAPI) {
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::device_set_signature() {
|
||||
this->r_int_reason = 1; // shadows ATA r_sect_count
|
||||
this->r_sect_num = 1; // required for protocol identification in OF 2.x
|
||||
this->r_dev_head = 0;
|
||||
|
||||
// set ATAPI protocol signature
|
||||
this->r_byte_count = 0xEB14;
|
||||
this->r_status_save = this->r_status; // for restoring on the first command
|
||||
this->r_status = 0;
|
||||
}
|
||||
|
||||
uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (has_data()) {
|
||||
uint16_t ret_data = get_data();
|
||||
this->xfer_cnt -= 2;
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->r_status &= ~DRQ;
|
||||
|
||||
if ((this->r_int_reason & ATAPI_Int_Reason::IO) &&
|
||||
!(this->r_int_reason & ATAPI_Int_Reason::CoD)
|
||||
) {
|
||||
if (this->data_available()) {
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status |= BSY;
|
||||
this->update_intrq(1); // Is this going to work here? The interrupt happens before returning ret_data.
|
||||
}
|
||||
else if (this->status_expected) {
|
||||
this->present_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret_data;
|
||||
} else {
|
||||
return 0xFFFFU;
|
||||
}
|
||||
case ATA_Reg::ERROR:
|
||||
return this->r_error;
|
||||
case ATAPI_Reg::INT_REASON:
|
||||
return this->r_int_reason;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
return this->r_sect_num;
|
||||
case ATAPI_Reg::BYTE_COUNT_LO:
|
||||
return this->r_byte_count & 0xFFU;
|
||||
case ATAPI_Reg::BYTE_COUNT_HI:
|
||||
return (this->r_byte_count >> 8) & 0xFFU;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
return this->r_dev_head;
|
||||
case ATA_Reg::STATUS:
|
||||
this->update_intrq(0);
|
||||
return this->r_status;
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
if (this->r_status & BSY && this->data_available()) {
|
||||
this->r_byte_count = this->request_data();
|
||||
this->data_out_phase();
|
||||
}
|
||||
return this->r_status;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to read unknown register: %x", reg_addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (has_data()) {
|
||||
*this->data_ptr++ = BYTESWAP_16(value);
|
||||
this->xfer_cnt -= 2;
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->r_status &= ~DRQ;
|
||||
if (this->r_int_reason & CoD) {
|
||||
this->perform_packet_command();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::FEATURES:
|
||||
this->r_features = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
case ATA_Reg::SEC_NUM:
|
||||
break; // unused in ATAPI, NoOp them here for compatibility
|
||||
case ATAPI_Reg::BYTE_COUNT_LO:
|
||||
this->r_byte_count = (this->r_byte_count & 0xFF00U) | (value & 0xFFU);
|
||||
break;
|
||||
case ATAPI_Reg::BYTE_COUNT_HI:
|
||||
this->r_byte_count = (this->r_byte_count & 0xFFU) | ((value & 0xFFU) << 8);
|
||||
break;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
this->r_dev_head = value;
|
||||
break;
|
||||
case ATA_Reg::COMMAND:
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::DEV_CTRL:
|
||||
this->device_control(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiBaseDevice::perform_command() {
|
||||
this->r_error &= ~ATA_Error::ABRT;
|
||||
this->r_status &= ~ATA_Status::ERR;
|
||||
this->r_status |= BSY;
|
||||
|
||||
switch (this->r_command) {
|
||||
case ATAPI_PACKET:
|
||||
this->data_ptr = (uint16_t *)this->cmd_pkt;
|
||||
this->xfer_cnt = sizeof(this->cmd_pkt);
|
||||
this->r_int_reason &= ~ATAPI_Int_Reason::IO; // host->device
|
||||
this->r_int_reason |= ATAPI_Int_Reason::CoD; // command packet
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_IDFY_DEV:
|
||||
std::memset(this->data_buf, 0, 512);
|
||||
this->data_buf[0] = 0xC0;
|
||||
this->data_buf[1] = 0x85;
|
||||
this->data_ptr = (uint16_t *)this->data_buf;
|
||||
this->data_pos = 0;
|
||||
this->xfer_cnt = 512;
|
||||
this->status_expected = false;
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case SET_FEATURES:
|
||||
switch (this->r_features) {
|
||||
case 3: // set transfer mode
|
||||
LOG_F(INFO, "%s: xfer_type=0x%X, mode=0x%X", this->name.c_str(),
|
||||
this->r_sect_count >> 3, this->r_sect_count & 7);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported subcommand 0x%X in SET_FEATURES",
|
||||
this->name.c_str(), this->r_features);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), this->r_command);
|
||||
this->r_error |= ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::data_out_phase() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO; // device->host
|
||||
this->r_int_reason &= ~ATAPI_Int_Reason::CoD; // data
|
||||
this->signal_data_ready();
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::signal_data_ready() {
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
|
||||
void AtapiBaseDevice::present_status() {
|
||||
this->r_int_reason |= ATAPI_Int_Reason::IO;
|
||||
this->r_int_reason |= ATAPI_Int_Reason::CoD;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Base class for ATAPI devices. */
|
||||
|
||||
#ifndef ATAPI_BASE_DEVICE_H
|
||||
#define ATAPI_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
class AtapiBaseDevice : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtapiBaseDevice(const std::string name);
|
||||
~AtapiBaseDevice() = default;
|
||||
|
||||
void device_set_signature() override;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
|
||||
// methods to be implemented in the particular device
|
||||
int perform_command() override;
|
||||
virtual void perform_packet_command() = 0;
|
||||
virtual int request_data() = 0;
|
||||
virtual bool data_available() = 0;
|
||||
|
||||
// methods with default implementation
|
||||
virtual void data_out_phase();
|
||||
virtual void signal_data_ready();
|
||||
virtual void present_status();
|
||||
|
||||
protected:
|
||||
uint8_t r_int_reason;
|
||||
uint16_t r_byte_count;
|
||||
bool status_expected = false;
|
||||
|
||||
uint8_t cmd_pkt[12] = {};
|
||||
};
|
||||
|
||||
#endif // ATAPI_BASE_DEVICE_H
|
||||
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 ATAPI CDROM implementation. */
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/atapicdrom.h>
|
||||
#include <devices/common/scsi/scsi.h> // ATAPI CDROM reuses SCSI commands (sic!)
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtapiCdrom::AtapiCdrom(std::string name) : AtapiBaseDevice(name) {
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->status_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
int AtapiCdrom::device_postinit() {
|
||||
std::string cdr_config = GET_STR_PROP("cdr_config");
|
||||
if (cdr_config.empty()) {
|
||||
LOG_F(ERROR, "%s: cdr_config property is empty", this->name.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string bus_id;
|
||||
uint32_t dev_num;
|
||||
|
||||
parse_device_path(cdr_config, bus_id, dev_num);
|
||||
|
||||
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
|
||||
bus_obj->register_device(dev_num, this);
|
||||
|
||||
std::string cdr_image_path = GET_STR_PROP("cdr_img");
|
||||
if (!cdr_image_path.empty()) {
|
||||
this->insert_image(cdr_image_path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtapiCdrom::perform_packet_command() {
|
||||
uint32_t lba, xfer_len;
|
||||
|
||||
this->r_status |= BSY;
|
||||
this->sector_areas = 0;
|
||||
if (this->doing_sector_areas) {
|
||||
this->doing_sector_areas = false;
|
||||
LOG_F(WARNING, "%s: doing_sector_areas reset", this->name.c_str());
|
||||
}
|
||||
|
||||
switch (this->cmd_pkt[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
if (this->medium_present())
|
||||
this->status_good();
|
||||
else
|
||||
this->status_error(ScsiSense::NOT_READY, ScsiError::MEDIUM_NOT_PRESENT);
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
xfer_len = this->request_sense(this->data_buf, this->sense_key, this->asc, this->ascq);
|
||||
if (!xfer_len) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->xfer_cnt = this->inquiry(this->cmd_pkt, this->data_buf);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
if ((this->cmd_pkt[4] & 3) == 2) {
|
||||
LOG_F(WARNING, "CD-ROM eject requested");
|
||||
}
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
LOG_F(INFO, "%s: medium removal %s", this->name.c_str(),
|
||||
this->cmd_pkt[4] & 1 ? "prevented" : "allowed");
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->xfer_cnt = this->report_capacity(this->data_buf);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->status_good();
|
||||
xfer_len = this->read_toc(this->cmd_pkt, this->data_buf);
|
||||
if (!xfer_len) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->xfer_cnt = std::min((uint32_t)this->r_byte_count, xfer_len);
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->xfer_cnt = this->mode_sense_ex(this->cmd_pkt, this->data_buf);
|
||||
if (!this->xfer_cnt) {
|
||||
this->present_status();
|
||||
} else {
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_buf;
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
}
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = this->cmd_pkt[1] << 16 | READ_WORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = this->cmd_pkt[4];
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = READ_DWORD_BE_U(&this->cmd_pkt[6]);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->xfer_cnt = this->read_begin(xfer_len, this->r_byte_count);
|
||||
this->r_byte_count = this->xfer_cnt;
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
LOG_F(INFO, "%s: speed set to %d kBps", this->name.c_str(),
|
||||
READ_WORD_BE_U(&this->cmd_pkt[2]));
|
||||
this->status_good();
|
||||
this->present_status();
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
{
|
||||
lba = READ_DWORD_BE_U(&this->cmd_pkt[2]);
|
||||
xfer_len = (this->cmd_pkt[6] << 16) | READ_WORD_BE_U(&this->cmd_pkt[7]);
|
||||
if (this->cmd_pkt[1] || (this->cmd_pkt[9] & ~0xf8) || ((this->cmd_pkt[9] & 0xf8) == 0) || this->cmd_pkt[10])
|
||||
LOG_F(WARNING, "%s: unsupported READ_CD params: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
this->name.c_str(),
|
||||
this->cmd_pkt[0], this->cmd_pkt[1], this->cmd_pkt[2], this->cmd_pkt[3], this->cmd_pkt[4], this->cmd_pkt[5],
|
||||
this->cmd_pkt[6], this->cmd_pkt[7], this->cmd_pkt[8], this->cmd_pkt[9], this->cmd_pkt[10], this->cmd_pkt[11]
|
||||
);
|
||||
if (this->r_features & ATAPI_Features::DMA) {
|
||||
LOG_F(WARNING, "ATAPI DMA transfer requsted");
|
||||
}
|
||||
this->set_fpos(lba);
|
||||
this->sector_areas = cmd_pkt[9];
|
||||
this->doing_sector_areas = true;
|
||||
this->current_block = lba;
|
||||
this->current_block_byte = 0;
|
||||
|
||||
int bytes_prolog = 0;
|
||||
int bytes_data = 0;
|
||||
int bytes_epilog = 0;
|
||||
|
||||
// For Mode 1 CD-ROMs:
|
||||
if (this->sector_areas & 0x80) bytes_prolog += 12; // Sync
|
||||
if (this->sector_areas & 0x20) bytes_prolog += 4; // Header
|
||||
if (this->sector_areas & 0x40) bytes_prolog += 0; // SubHeader
|
||||
if (this->sector_areas & 0x10) bytes_data += 2048; // User
|
||||
if (this->sector_areas & 0x08) bytes_epilog += 288; // Auxiliary
|
||||
if (this->sector_areas & 0x02) bytes_epilog += 294; // ErrorFlags
|
||||
if (this->sector_areas & 0x01) bytes_epilog += 96; // SubChannel
|
||||
|
||||
int bytes_per_block = bytes_prolog + bytes_data + bytes_epilog;
|
||||
|
||||
int disk_image_byte_count;
|
||||
|
||||
if (bytes_per_block == 0) {
|
||||
disk_image_byte_count = 0xffff;
|
||||
}
|
||||
else {
|
||||
disk_image_byte_count = (this->r_byte_count / bytes_per_block) * this->block_size; // whole blocks
|
||||
if ((this->r_byte_count % bytes_per_block) > bytes_prolog) { // partial block
|
||||
int disk_image_byte_count_partial_block = (this->r_byte_count % bytes_per_block) - bytes_prolog; // remove prolog from partial block
|
||||
if (disk_image_byte_count_partial_block > this->block_size) { // partial block includes some epilog?
|
||||
disk_image_byte_count_partial_block = this->block_size; // // remove epilog from partial block
|
||||
}
|
||||
// add partial block
|
||||
disk_image_byte_count += disk_image_byte_count_partial_block;
|
||||
}
|
||||
}
|
||||
|
||||
int disk_image_bytes_received = this->read_begin(xfer_len, disk_image_byte_count);
|
||||
|
||||
int bytes_received = (disk_image_bytes_received / this->block_size) * bytes_per_block + bytes_prolog + (disk_image_bytes_received % this->block_size); // whole blocks + prolog + partial block
|
||||
if (bytes_received > this->r_byte_count) { // if partial epilog or partial prolog
|
||||
bytes_received = this->r_byte_count; // confine to r_byte_count
|
||||
}
|
||||
this->r_byte_count = bytes_received;
|
||||
this->xfer_cnt = bytes_received;
|
||||
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
this->status_good();
|
||||
this->data_out_phase();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported ATAPI command 0x%X", this->name.c_str(),
|
||||
this->cmd_pkt[0]);
|
||||
this->status_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CMD);
|
||||
this->present_status();
|
||||
}
|
||||
}
|
||||
|
||||
int AtapiCdrom::request_data() {
|
||||
// continuation of READ_CD above
|
||||
|
||||
this->data_ptr = (uint16_t*)this->data_cache.get();
|
||||
|
||||
this->xfer_cnt = this->read_more();
|
||||
|
||||
return this->xfer_cnt;
|
||||
}
|
||||
|
||||
static const uint8_t mode_1_sync[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
|
||||
|
||||
uint16_t AtapiCdrom::get_data() {
|
||||
uint16_t ret_data;
|
||||
|
||||
if (doing_sector_areas) {
|
||||
// For Mode 1 CD-ROMs:
|
||||
int area_start;
|
||||
int area_end = 0;
|
||||
|
||||
ret_data = 0xffff;
|
||||
|
||||
if (this->sector_areas & 0x80) {
|
||||
area_start = area_end;
|
||||
area_end += 12; // Sync
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = BYTESWAP_16(*((uint16_t*)(&mode_1_sync[current_block_byte - area_start])));
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x20) {
|
||||
area_start = area_end;
|
||||
area_end += 4; // Header
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
AddrMsf msf = lba_to_msf(this->current_block + 150);
|
||||
uint8_t header[4];
|
||||
header[0] = msf.min;
|
||||
header[1] = msf.sec;
|
||||
header[2] = msf.frm;
|
||||
header[3] = 0x01; // Mode 1
|
||||
ret_data = BYTESWAP_16(*((uint16_t*)(&header[current_block_byte - area_start])));
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x40) {
|
||||
area_start = area_end;
|
||||
area_end += 0; // SubHeader
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x10) {
|
||||
area_start = area_end;
|
||||
area_end += 2048; // User
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = AtaBaseDevice::get_data();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x08) {
|
||||
area_start = area_end;
|
||||
area_end += 288; // Auxiliary
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x02) {
|
||||
area_start = area_end;
|
||||
area_end += 294; // ErrorFlags
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->sector_areas & 0x01) {
|
||||
area_start = area_end;
|
||||
area_end += 96; // SubChannel
|
||||
if (this->current_block_byte >= area_start && this->current_block_byte < area_end) {
|
||||
ret_data = 0;
|
||||
}
|
||||
}
|
||||
|
||||
current_block_byte += 2;
|
||||
if (current_block_byte >= area_end)
|
||||
current_block_byte = 0;
|
||||
}
|
||||
else {
|
||||
ret_data = AtaBaseDevice::get_data();
|
||||
}
|
||||
|
||||
return ret_data;
|
||||
}
|
||||
|
||||
void AtapiCdrom::status_good() {
|
||||
this->status_expected = true;
|
||||
this->r_error = 0;
|
||||
this->sense_key = 0;
|
||||
this->r_status &= ~ATA_Status::ERR;
|
||||
}
|
||||
|
||||
void AtapiCdrom::status_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->status_expected = true;
|
||||
this->sense_key = sense_key;
|
||||
this->asc = asc;
|
||||
this->r_error = (sense_key << 4) | ATA_Error::ABRT;
|
||||
this->r_status |= ATA_Status::ERR;
|
||||
}
|
||||
|
||||
static const PropMap AtapiCdromProperties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtapiCdromDescriptor =
|
||||
{AtapiCdrom::create, {}, AtapiCdromProperties};
|
||||
|
||||
REGISTER_DEVICE(AtapiCdrom, AtapiCdromDescriptor);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 ATAPI CDROM definitions. */
|
||||
|
||||
#ifndef ATAPI_CDROM_H
|
||||
#define ATAPI_CDROM_H
|
||||
|
||||
#include <devices/common/ata/atapibasedevice.h>
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class AtapiCdrom : public AtapiBaseDevice, public CdromDrive {
|
||||
public:
|
||||
AtapiCdrom(std::string name);
|
||||
~AtapiCdrom() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AtapiCdrom>(new AtapiCdrom("ATAPI-CDROM"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void perform_packet_command() override;
|
||||
|
||||
int request_data() override;
|
||||
|
||||
bool data_available() override {
|
||||
return this->data_left() != 0;
|
||||
}
|
||||
|
||||
void status_good();
|
||||
void status_error(uint8_t sense_key, uint8_t asc);
|
||||
|
||||
uint16_t get_data();
|
||||
private:
|
||||
uint8_t sense_key = 0;
|
||||
uint8_t asc = 0;
|
||||
uint8_t ascq = 0;
|
||||
|
||||
bool doing_sector_areas = false;
|
||||
uint8_t sector_areas;
|
||||
uint32_t current_block;
|
||||
uint16_t current_block_byte;
|
||||
};
|
||||
|
||||
#endif // ATAPI_CDROM_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,10 +26,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from and to the host.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
@@ -42,8 +44,28 @@ IdeChannel::IdeChannel(const std::string name)
|
||||
this->set_name(name);
|
||||
this->supports_types(HWCompType::IDE_BUS);
|
||||
|
||||
this->devices[0] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
this->devices[1] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
this->device_stub = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
|
||||
this->devices[0] = this->device_stub.get();
|
||||
this->devices[1] = this->device_stub.get();
|
||||
}
|
||||
|
||||
int IdeChannel::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(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
|
||||
if (id < 0 || id >= 2)
|
||||
ABORT_F("%s: invalid device ID", this->name.c_str());
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this);
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
@@ -38,21 +39,42 @@ public:
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDEO"));
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
};
|
||||
|
||||
std::unique_ptr<AtaInterface> devices[2];
|
||||
bool is_device1_present() {
|
||||
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
}
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
AtaInterface* devices[2];
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
+155
-62
@@ -38,62 +38,20 @@ void DMAChannel::set_callbacks(DbdmaCallback start_cb, DbdmaCallback stop_cb) {
|
||||
|
||||
/* Load DMACmd from physical memory. */
|
||||
void DMAChannel::fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd) {
|
||||
memcpy((uint8_t*)p_cmd, mmu_get_dma_mem(cmd_addr, 16, nullptr), 16);
|
||||
MapDmaResult res = mmu_map_dma_mem(cmd_addr, 16, false);
|
||||
memcpy((uint8_t*)p_cmd, res.host_va, 16);
|
||||
}
|
||||
|
||||
uint8_t DMAChannel::interpret_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
bool is_writable, branch_taken = false;
|
||||
MapDmaResult res;
|
||||
|
||||
if (this->cmd_in_progress) {
|
||||
// return current command if there is data to transfer
|
||||
if (this->queue_len)
|
||||
return this->cur_cmd;
|
||||
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
|
||||
// get command code
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i", "b" and "w" bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
if (is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
|
||||
if (cmd_desc[2] & 3) {
|
||||
ABORT_F("DBDMA: cmd.w bit not implemented");
|
||||
}
|
||||
|
||||
// react to cmd.b bit
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0xC) != 0xC) {
|
||||
uint16_t br_mask = this->branch_select >> 16;
|
||||
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
|
||||
if ((cmd_desc[2] & 0xC) == 0x8) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
}
|
||||
}
|
||||
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
// all INPUT and OUTPUT commands update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::STORE_QUAD && is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len & 0xFFFFUL);
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
this->cmd_ptr += 16;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
fetch_cmd(this->cmd_ptr, &cmd_struct);
|
||||
@@ -111,18 +69,23 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
LOG_F(ERROR, "Key > 0 not implemented");
|
||||
break;
|
||||
}
|
||||
this->queue_data = mmu_get_dma_mem(cmd_struct.address, cmd_struct.req_count, &is_writable);
|
||||
res = mmu_map_dma_mem(cmd_struct.address, cmd_struct.req_count, false);
|
||||
this->queue_data = res.host_va;
|
||||
this->queue_len = cmd_struct.req_count;
|
||||
this->cmd_in_progress = true;
|
||||
break;
|
||||
case DBDMA_Cmd::STORE_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command STORE_QUAD");
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
LOG_F(9, "Invalid key %d in STORE_QUAD", cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, true);
|
||||
break;
|
||||
case DBDMA_Cmd::LOAD_QUAD:
|
||||
LOG_F(ERROR, "Unsupported DMA Command LOAD_QUAD");
|
||||
if ((cmd_struct.cmd_key & 7) != 6)
|
||||
LOG_F(9, "Invalid key %d in LOAD_QUAD", cmd_struct.cmd_key & 7);
|
||||
this->xfer_quad(&cmd_struct, false);
|
||||
break;
|
||||
case DBDMA_Cmd::NOP:
|
||||
LOG_F(ERROR, "Unsupported DMA Command NOP");
|
||||
this->finish_cmd();
|
||||
break;
|
||||
case DBDMA_Cmd::STOP:
|
||||
this->ch_stat &= ~CH_STAT_ACTIVE;
|
||||
@@ -137,21 +100,133 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
return this->cur_cmd;
|
||||
}
|
||||
|
||||
void DMAChannel::update_irq() {
|
||||
bool is_writable;
|
||||
void DMAChannel::finish_cmd() {
|
||||
DMACmd cmd_struct;
|
||||
bool branch_taken = false;
|
||||
|
||||
// obtain real pointer to the descriptor of the command to be finished
|
||||
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
uint8_t *cmd_desc = res.host_va;
|
||||
|
||||
// get command code
|
||||
this->cur_cmd = cmd_desc[3] >> 4;
|
||||
|
||||
// all commands except STOP update cmd.xferStatus and
|
||||
// perform actions under control of "i", "b" and "w" bits
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.w (wait) bits
|
||||
if (cmd_desc[2] & 3) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 3) != 3) {
|
||||
uint16_t wt_mask = this->wait_select >> 16;
|
||||
cond = (this->ch_stat & wt_mask) == (this->wait_select & wt_mask);
|
||||
if ((cmd_desc[2] & 3) == 2) {
|
||||
cond = !cond; // wait if cond = false
|
||||
}
|
||||
}
|
||||
|
||||
if (cond)
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.is_writable)
|
||||
WRITE_WORD_LE_A(&cmd_desc[14], this->ch_stat | CH_STAT_ACTIVE);
|
||||
|
||||
// react to cmd.b (branch) bits
|
||||
if (cmd_desc[2] & 0xC) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0xC) != 0xC) {
|
||||
uint16_t br_mask = this->branch_select >> 16;
|
||||
cond = (this->ch_stat & br_mask) == (this->branch_select & br_mask);
|
||||
if ((cmd_desc[2] & 0xC) == 0x8) {
|
||||
cond = !cond; // branch if cond = false
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
this->cmd_ptr = READ_DWORD_LE_A(&cmd_desc[8]);
|
||||
branch_taken = true;
|
||||
}
|
||||
}
|
||||
|
||||
this->update_irq();
|
||||
}
|
||||
|
||||
// all INPUT and OUTPUT commands update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::STORE_QUAD && res.is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len & 0xFFFFUL);
|
||||
}
|
||||
|
||||
if (!branch_taken)
|
||||
this->cmd_ptr += 16;
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_quad(const DMACmd *cmd_desc, const bool is_store) {
|
||||
MapDmaResult res;
|
||||
uint8_t *src, *dst;
|
||||
uint32_t addr;
|
||||
|
||||
// parse and fix reqCount
|
||||
uint32_t xfer_size = cmd_desc->req_count & 7;
|
||||
if (xfer_size & 4) {
|
||||
xfer_size = 4;
|
||||
} else if (xfer_size & 2) {
|
||||
xfer_size = 2;
|
||||
} else {
|
||||
xfer_size = 1;
|
||||
}
|
||||
|
||||
addr = cmd_desc->address & ~(xfer_size - 1);
|
||||
|
||||
// prepare data pointers and perform data transfer
|
||||
if (is_store) {
|
||||
res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
src = res.host_va + 8; // move src to cmd.data32
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
if (res.type & RT_MMIO) {
|
||||
res.dev_obj->write(res.dev_base, addr - res.dev_base,
|
||||
read_mem_rev(src, xfer_size), xfer_size);
|
||||
} else if (res.is_writable) {
|
||||
std::memcpy(res.host_va, src, xfer_size);
|
||||
}
|
||||
} else {
|
||||
res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
if (res.is_writable) {
|
||||
dst = res.host_va + 8; // move dst to cmd.data32
|
||||
|
||||
res = mmu_map_dma_mem(addr, xfer_size, true);
|
||||
if (res.type & RT_MMIO) {
|
||||
write_mem_rev(dst,
|
||||
res.dev_obj->read(res.dev_base, addr - res.dev_base, xfer_size),
|
||||
xfer_size);
|
||||
} else {
|
||||
std::memcpy(dst, res.host_va, xfer_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd_desc->cmd_bits & 0xC)
|
||||
ABORT_F("DBDMA: cmd_bits.b should be zero for LOAD/STORE_QUAD!");
|
||||
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
void DMAChannel::update_irq() {
|
||||
// obtain real pointer to the descriptor of the completed command
|
||||
uint8_t *cmd_desc = mmu_get_dma_mem(this->cmd_ptr, 16, &is_writable);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->cmd_ptr, 16, false);
|
||||
uint8_t *cmd_desc = res.host_va;
|
||||
|
||||
// STOP doesn't generate interrupts
|
||||
if (this->cur_cmd < DBDMA_Cmd::STOP) {
|
||||
// react to cmd.i (interrupt) bits
|
||||
if (cmd_desc[2] & 0x30) {
|
||||
bool cond = true;
|
||||
if ((cmd_desc[2] & 0x30) != 0x30) {
|
||||
uint16_t int_mask = this->int_select >> 16;
|
||||
cond = (this->ch_stat & int_mask) == (this->int_select & int_mask);
|
||||
if ((cmd_desc[2] & 0x30) == 0x20) { // branch if cond cleared?
|
||||
cond = !cond;
|
||||
if ((cmd_desc[2] & 0x30) == 0x20) {
|
||||
cond = !cond; // generate interrupt if cond = false
|
||||
}
|
||||
}
|
||||
if (cond) {
|
||||
@@ -162,24 +237,22 @@ void DMAChannel::update_irq() {
|
||||
}
|
||||
|
||||
uint32_t DMAChannel::reg_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
if (size != 4) {
|
||||
ABORT_F("DBDMA: non-DWORD read from a DMA channel not supported");
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case DMAReg::CH_CTRL:
|
||||
res = 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
break;
|
||||
return 0; // ChannelControl reads as 0 (DBDMA spec 5.5.1, table 74)
|
||||
case DMAReg::CH_STAT:
|
||||
res = BYTESWAP_32(this->ch_stat);
|
||||
break;
|
||||
return BYTESWAP_32(this->ch_stat);
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
return BYTESWAP_32(this->cmd_ptr);
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
@@ -240,15 +313,24 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
break;
|
||||
case DMAReg::CH_STAT:
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI: // Mac OS X writes this optional register with zero
|
||||
LOG_F(9, "CommandPtrHi set to 0x%X", value);
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
if (!(this->ch_stat & CH_STAT_RUN) && !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->cmd_ptr = value;
|
||||
LOG_F(9, "CommandPtrLo set to 0x%X", this->cmd_ptr);
|
||||
}
|
||||
break;
|
||||
case DMAReg::INT_SELECT:
|
||||
this->int_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
case DMAReg::BRANCH_SELECT:
|
||||
this->branch_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
case DMAReg::WAIT_SELECT:
|
||||
this->wait_select = value & 0xFF00FFUL;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel register 0x%X", offset);
|
||||
}
|
||||
@@ -334,6 +416,17 @@ void DMAChannel::start() {
|
||||
|
||||
if (this->start_cb)
|
||||
this->start_cb();
|
||||
|
||||
this->cmd_in_progress = false;
|
||||
|
||||
// some DBDMA programs contain commands that don't transfer data
|
||||
// between a device and memory (LOAD_QUAD, STORE_QUAD, NOP and STOP).
|
||||
// We thus interprete the DBDMA program until a data transfer between
|
||||
// a device and memory is queued or the channel becomes idle/dead.
|
||||
while (!this->cmd_in_progress && !(this->ch_stat & CH_STAT_DEAD) &&
|
||||
(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
this->interpret_cmd();
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::resume() {
|
||||
|
||||
@@ -39,9 +39,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
enum DMAReg : uint32_t {
|
||||
CH_CTRL = 0,
|
||||
CH_STAT = 4,
|
||||
CMD_PTR_HI = 8,
|
||||
CMD_PTR_LO = 12,
|
||||
INT_SELECT = 16,
|
||||
BRANCH_SELECT = 20,
|
||||
WAIT_SELECT = 24,
|
||||
};
|
||||
|
||||
/** Channel Status bits (DBDMA spec, 5.5.3) */
|
||||
@@ -101,6 +103,8 @@ public:
|
||||
protected:
|
||||
void fetch_cmd(uint32_t cmd_addr, DMACmd* p_cmd);
|
||||
uint8_t interpret_cmd(void);
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, const bool is_store);
|
||||
void update_irq();
|
||||
|
||||
void start(void);
|
||||
@@ -118,6 +122,7 @@ private:
|
||||
uint8_t* queue_data = 0;
|
||||
uint32_t int_select = 0;
|
||||
uint32_t branch_select = 0;
|
||||
uint32_t wait_select = 0;
|
||||
|
||||
bool cmd_in_progress = false;
|
||||
uint8_t cur_cmd;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,29 +26,30 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
/** types of different HW components */
|
||||
enum HWCompType {
|
||||
UNKNOWN = 0ULL, /* unknown component type */
|
||||
MEM_CTRL = 1ULL << 0, /* memory controller */
|
||||
NVRAM = 1ULL << 1, /* non-volatile random access memory */
|
||||
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 */
|
||||
IDE_BUS = 1ULL << 23, /* IDE bus */
|
||||
IDE_DEV = 1ULL << 25, /* IDE device */
|
||||
SND_CODEC = 1ULL << 30, /* Sound codec */
|
||||
SND_SERVER = 1ULL << 31, /* host sound server */
|
||||
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
|
||||
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
|
||||
enum HWCompType : uint64_t {
|
||||
UNKNOWN = 0ULL, // unknown component type
|
||||
MEM_CTRL = 1ULL << 0, // memory controller
|
||||
NVRAM = 1ULL << 1, // non-volatile random access memory
|
||||
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
|
||||
IDE_BUS = 1ULL << 23, // IDE bus
|
||||
IDE_DEV = 1ULL << 25, // IDE device
|
||||
SND_CODEC = 1ULL << 30, // sound codec
|
||||
SND_SERVER = 1ULL << 31, // host sound server
|
||||
FLOPPY_CTRL = 1ULL << 32, // floppy disk controller
|
||||
FLOPPY_DRV = 1ULL << 33, // floppy disk drive
|
||||
ETHER_MAC = 1ULL << 40, // Ethernet media access controller
|
||||
};
|
||||
|
||||
/** Base class for HW components. */
|
||||
@@ -81,4 +82,4 @@ protected:
|
||||
uint64_t supported_types = HWCompType::UNKNOWN;
|
||||
};
|
||||
|
||||
#endif /* HW_COMPONENT_H */
|
||||
#endif // HW_COMPONENT_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,13 +27,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//#define DEBUG_CPU_INT // uncomment this to enable hacks for debugging HW interrupts
|
||||
|
||||
/** Enumerator for various interrupt sources. */
|
||||
enum IntSrc : int {
|
||||
enum IntSrc : uint32_t {
|
||||
VIA_CUDA = 1,
|
||||
SCSI1 = 2,
|
||||
SWIM3 = 3,
|
||||
SCC = 4,
|
||||
ETHERNET = 5,
|
||||
NMI = 6,
|
||||
IDE0 = 7,
|
||||
IDE1 = 8,
|
||||
};
|
||||
|
||||
/** Base class for interrupt controllers. */
|
||||
|
||||
+73
-33
@@ -89,7 +89,7 @@ bool OfConfigAppl::validate() {
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
uint16_t OfConfigAppl::checksum_partition() {
|
||||
uint32_t acc = 0;
|
||||
@@ -178,7 +178,7 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
}
|
||||
|
||||
return _config_vars;
|
||||
};
|
||||
}
|
||||
|
||||
void OfConfigAppl::update_partition() {
|
||||
// set checksum in the header to zero
|
||||
@@ -300,7 +300,7 @@ bool OfConfigAppl::set_var(std::string& var_name, std::string& value) {
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
uint8_t OfConfigChrp::checksum_hdr(const uint8_t* data)
|
||||
{
|
||||
@@ -391,27 +391,47 @@ const OfConfigImpl::config_dict& OfConfigChrp::get_config_vars() {
|
||||
|
||||
this->_config_vars.clear();
|
||||
|
||||
this->data_length = 0;
|
||||
|
||||
if (!this->validate())
|
||||
return _config_vars;
|
||||
|
||||
for (int pos = 0; pos < 4096;) {
|
||||
char *pname = (char *)&this->buf[pos];
|
||||
bool got_name = false;
|
||||
|
||||
// scan property name until '=' is encountered
|
||||
// or max length is reached
|
||||
for (len = 0; len < 32; pos++, len++) {
|
||||
if (pname[len] == '=' || pname[len] == '\0')
|
||||
for (len = 0; ; pos++, len++) {
|
||||
if (len >= 32) {
|
||||
cout << "name > 31 chars" << endl;
|
||||
break;
|
||||
}
|
||||
if (pos >= 4096) {
|
||||
cout << "no = sign before end of partition" << endl;
|
||||
break;
|
||||
}
|
||||
if (pname[len] == '=') {
|
||||
if (len) {
|
||||
got_name = true;
|
||||
}
|
||||
else {
|
||||
cout << "got = sign but no name" << endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pname[len] == '\0') {
|
||||
if (len) {
|
||||
cout << "no = sign before termminating null" << endl;
|
||||
}
|
||||
else {
|
||||
// empty property name -> free space reached
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// empty property name -> free space reached
|
||||
if (!len) {
|
||||
this->data_length = pos;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pname[len] != '=') {
|
||||
cout << "no = sign found or name > 31 chars" << endl;
|
||||
if (!got_name) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -436,8 +456,11 @@ const OfConfigImpl::config_dict& OfConfigChrp::get_config_vars() {
|
||||
|
||||
this->_config_vars.push_back(std::make_pair(prop_name, pval));
|
||||
pos++; // skip past null terminator
|
||||
|
||||
this->data_length = pos; // point to after null
|
||||
}
|
||||
|
||||
//cout << "Read " << this->data_length << " bytes from nvram." << endl;
|
||||
return this->_config_vars;
|
||||
}
|
||||
|
||||
@@ -447,7 +470,7 @@ bool OfConfigChrp::update_partition() {
|
||||
memset(this->buf, 0, 4096);
|
||||
|
||||
for (auto& var : this->_config_vars) {
|
||||
if ((var.first.length() + var.second.length() + 2) >= 4096) {
|
||||
if ((pos + var.first.length() + var.second.length() + 2) > 4096) {
|
||||
cout << "No room in the partition!" << endl;
|
||||
return false;
|
||||
}
|
||||
@@ -464,6 +487,7 @@ bool OfConfigChrp::update_partition() {
|
||||
this->nvram_obj->write_byte(this->data_offset + i, this->buf[i]);
|
||||
}
|
||||
|
||||
//cout << "Wrote " << pos << " bytes to nvram." << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -471,25 +495,25 @@ bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
|
||||
if (!this->validate())
|
||||
return false;
|
||||
|
||||
bool found = false;
|
||||
// see if we're about to change a flag
|
||||
if (var_name.back() == '?') {
|
||||
if (value != "true" && value != "false") {
|
||||
cout << "Flag value can be 'true' or 'false'" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned free_space = 4096 - this->data_length;
|
||||
bool found = false;
|
||||
|
||||
// see if the user tries to change an existing property
|
||||
for (auto& var : this->_config_vars) {
|
||||
if (var.first == var_name) {
|
||||
found = true;
|
||||
|
||||
// see if we're about to change a flag
|
||||
if (var_name.back() == '?') {
|
||||
if (value != "true" && value != "false") {
|
||||
cout << "Flag value can be 'true' or 'false'" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (value.length() > var.second.length()) {
|
||||
unsigned free_space = 4096 - this->data_length;
|
||||
if ((value.length() - var.second.length()) >= free_space) {
|
||||
cout << "No room for new data!" << endl;
|
||||
if ((value.length() - var.second.length()) > free_space) {
|
||||
cout << "No room for updated nvram variable!" << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -500,12 +524,15 @@ bool OfConfigChrp::set_var(std::string& var_name, std::string& value) {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return false;
|
||||
if ((var_name.length() + value.length() + 2) > free_space) {
|
||||
cout << "No room for new nvram variable!" << endl;
|
||||
return false;
|
||||
}
|
||||
this->_config_vars.push_back(std::make_pair(var_name, value));
|
||||
}
|
||||
|
||||
return this->update_partition();
|
||||
};
|
||||
}
|
||||
|
||||
int OfConfigUtils::init()
|
||||
{
|
||||
@@ -541,16 +568,27 @@ bool OfConfigUtils::open_container() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void OfConfigUtils::printenv() {
|
||||
OfConfigImpl::config_dict vars;
|
||||
static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = 0;
|
||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void OfConfigUtils::printenv() {
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
vars = this->cfg_impl->get_config_vars();
|
||||
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
for (auto& var : vars) {
|
||||
cout << setw(34) << left << var.first << var.second << endl;
|
||||
std::string val = var.second;
|
||||
ReplaceAll(val, "\r\n", "\n");
|
||||
ReplaceAll(val, "\r", "\n");
|
||||
ReplaceAll(val, "\n", "\n "); // 34 spaces
|
||||
cout << setw(34) << left << var.first << val << endl; // name column has width 34
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,6 +597,8 @@ void OfConfigUtils::setenv(string var_name, string value)
|
||||
if (!this->open_container())
|
||||
return;
|
||||
|
||||
OfConfigImpl::config_dict vars = this->cfg_impl->get_config_vars();
|
||||
|
||||
if (!this->cfg_impl->set_var(var_name, value)) {
|
||||
cout << " Please try again" << endl;
|
||||
} else {
|
||||
|
||||
@@ -299,7 +299,7 @@ static const DeviceDescription Bandit1_Descriptor = {
|
||||
};
|
||||
|
||||
static const DeviceDescription PsxPci1_Descriptor = {
|
||||
Bandit::create_psx_first, {}, {}
|
||||
Bandit::create_psx_first, {}, Bandit_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
|
||||
@@ -34,7 +34,7 @@ using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("Scsi0"));
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
@@ -46,23 +46,32 @@ int MeshController::device_postinit()
|
||||
void MeshController::reset(bool is_hard_reset)
|
||||
{
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->fifo_cnt = 0;
|
||||
this->int_mask = 0;
|
||||
this->xfer_count = 0;
|
||||
this->src_id = 7;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = 2; // guessed
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MeshController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
return this->xfer_count & 0xFFU;
|
||||
case MeshReg::XferCount1:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
return this->bus_obj->test_ctrl_lines(0xFFU);
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::FIFOCount:
|
||||
return this->fifo_cnt;
|
||||
case MeshReg::Exception:
|
||||
return 0;
|
||||
case MeshReg::Error:
|
||||
@@ -71,6 +80,10 @@ uint8_t MeshController::read(uint8_t reg_offset)
|
||||
return this->int_mask;
|
||||
case MeshReg::Interrupt:
|
||||
return this->int_stat;
|
||||
case MeshReg::DestID:
|
||||
return this->dst_id;
|
||||
case MeshReg::SyncParms:
|
||||
return this->sync_params;
|
||||
case MeshReg::MeshID:
|
||||
return this->chip_id; // tell them who we are
|
||||
default:
|
||||
@@ -94,9 +107,9 @@ void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(new_stat, mask);
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(new_stat, mask);
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
@@ -135,6 +148,7 @@ void MeshController::perform_command(const uint8_t cmd)
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
@@ -142,15 +156,24 @@ void MeshController::perform_command(const uint8_t cmd)
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::BusFree:
|
||||
LOG_F(INFO, "MESH: BusFree stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::EnaReselect:
|
||||
LOG_F(INFO, "MESH: EnaReselect stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::DisReselect:
|
||||
LOG_F(INFO, "MESH: DisReselect command requested");
|
||||
LOG_F(9, "MESH: DisReselect stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO command requested");
|
||||
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
|
||||
@@ -61,6 +61,8 @@ enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
BusFree = 9,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF,
|
||||
@@ -107,6 +109,7 @@ public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
this->chip_id = mesh_id;
|
||||
this->set_name("MESH");
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
@@ -138,7 +141,9 @@ private:
|
||||
uint8_t dst_id;
|
||||
uint8_t cur_cmd;
|
||||
uint8_t error;
|
||||
uint8_t fifo_cnt;
|
||||
uint8_t exception;
|
||||
uint32_t xfer_count;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
uint16_t bus_stat;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -42,7 +42,7 @@ Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice(my_id)
|
||||
|
||||
int Sc53C94::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
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*>(
|
||||
@@ -170,7 +170,7 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
|
||||
// update DMA status
|
||||
if ((this->cmd_fifo[0] & 0x80)) {
|
||||
if (this->is_dma_cmd) {
|
||||
this->xfer_count -= 2;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
@@ -189,6 +189,21 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
return data_word;
|
||||
}
|
||||
|
||||
void Sc53C94::pseudo_dma_write(uint16_t data) {
|
||||
this->fifo_push((data >> 8) & 0xFFU);
|
||||
this->fifo_push(data & 0xFFU);
|
||||
|
||||
// update DMA status
|
||||
if (this->is_dma_cmd) {
|
||||
this->xfer_count -= 2;
|
||||
if (!this->xfer_count) {
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
//this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
@@ -220,9 +235,10 @@ void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
void Sc53C94::exec_command()
|
||||
{
|
||||
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
|
||||
bool is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
|
||||
|
||||
if (is_dma_cmd) {
|
||||
this->is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
|
||||
|
||||
if (this->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
|
||||
@@ -468,7 +484,7 @@ void Sc53C94::sequencer()
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->cmd_fifo[0] & 0x80) {
|
||||
if (this->is_dma_cmd) {
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
}
|
||||
@@ -481,7 +497,7 @@ void Sc53C94::sequencer()
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
if (!(this->cmd_fifo[0] & 0x80)) {
|
||||
if (!(this->is_dma_cmd)) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
@@ -537,7 +553,7 @@ void Sc53C94::update_irq()
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
{
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
@@ -595,7 +611,7 @@ bool Sc53C94::rcv_data()
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((this->cmd_fifo[0] & 0x80) && this->cur_bus_phase == ScsiPhase::DATA_IN) {
|
||||
if (this->is_dma_cmd && this->cur_bus_phase == ScsiPhase::DATA_IN) {
|
||||
req_count = std::min((int)this->xfer_count, DATA_FIFO_MAX - this->data_fifo_pos);
|
||||
} else {
|
||||
req_count = 1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -34,6 +34,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
@@ -144,6 +145,8 @@ typedef struct {
|
||||
int status;
|
||||
} SeqDesc;
|
||||
|
||||
typedef std::function<void(const uint8_t drq_state)> DrqCb;
|
||||
|
||||
class Sc53C94 : public ScsiDevice {
|
||||
public:
|
||||
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
|
||||
@@ -160,6 +163,7 @@ public:
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
uint16_t pseudo_dma_read();
|
||||
void pseudo_dma_write(uint16_t data);
|
||||
|
||||
// real DMA control
|
||||
void real_dma_xfer(int direction);
|
||||
@@ -168,8 +172,12 @@ public:
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
|
||||
void set_drq_callback(DrqCb cb) {
|
||||
this->drq_cb = cb;
|
||||
}
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool has_data() { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
@@ -222,6 +230,7 @@ private:
|
||||
SeqDesc* cmd_steps;
|
||||
bool is_initiator;
|
||||
uint8_t cur_cmd;
|
||||
bool is_dma_cmd = false;
|
||||
int cur_bus_phase;
|
||||
|
||||
// interrupt related stuff
|
||||
@@ -231,6 +240,7 @@ private:
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
DrqCb drq_cb = nullptr;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
+43
-22
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** SCSI control signals.
|
||||
@@ -84,21 +85,22 @@ enum ScsiMsg : int {
|
||||
MESSAGE_END,
|
||||
};
|
||||
|
||||
enum ScsiCommand : int {
|
||||
TEST_UNIT_READY = 0x0,
|
||||
REWIND = 0x1,
|
||||
REQ_SENSE = 0x3,
|
||||
FORMAT = 0x4,
|
||||
READ_BLK_LIMITS = 0x5,
|
||||
READ_6 = 0x8,
|
||||
WRITE_6 = 0xA,
|
||||
SEEK_6 = 0xB,
|
||||
enum ScsiCommand : uint8_t {
|
||||
TEST_UNIT_READY = 0x00,
|
||||
REWIND = 0x01,
|
||||
REQ_SENSE = 0x03,
|
||||
FORMAT = 0x04,
|
||||
READ_BLK_LIMITS = 0x05,
|
||||
READ_6 = 0x08,
|
||||
WRITE_6 = 0x0A,
|
||||
SEEK_6 = 0x0B,
|
||||
INQUIRY = 0x12,
|
||||
VERIFY_6 = 0x13,
|
||||
MODE_SELECT_6 = 0x15,
|
||||
RELEASE_UNIT = 0x17,
|
||||
ERASE_6 = 0x19,
|
||||
MODE_SENSE_6 = 0x1A,
|
||||
START_STOP_UNIT = 0x1B,
|
||||
DIAG_RESULTS = 0x1C,
|
||||
SEND_DIAGS = 0x1D,
|
||||
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
@@ -107,9 +109,15 @@ enum ScsiCommand : int {
|
||||
WRITE_10 = 0x2A,
|
||||
VERIFY_10 = 0x2F,
|
||||
READ_LONG_10 = 0x35,
|
||||
WRITE_BUFFER = 0x3B,
|
||||
READ_BUFFER = 0x3C,
|
||||
MODE_SENSE_10 = 0x5A,
|
||||
READ_12 = 0xA8,
|
||||
|
||||
// CD-ROM specific commands
|
||||
READ_TOC = 0x43,
|
||||
SET_CD_SPEED = 0xBB,
|
||||
READ_CD = 0xBE,
|
||||
};
|
||||
|
||||
enum ScsiSense : int {
|
||||
@@ -128,15 +136,16 @@ enum ScsiSense : int {
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x0,
|
||||
NO_SECTOR = 0x1,
|
||||
WRITE_FAULT = 0x3,
|
||||
DEV_NOT_READY = 0x4,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
@@ -161,8 +170,8 @@ public:
|
||||
};
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
virtual void next_step(ScsiBus* bus_obj);
|
||||
virtual void notify(ScsiMsg msg_type, int param);
|
||||
virtual void next_step();
|
||||
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
|
||||
virtual void switch_phase(const int new_phase);
|
||||
|
||||
@@ -173,6 +182,10 @@ public:
|
||||
virtual bool prepare_data() = 0;
|
||||
virtual void process_command() = 0;
|
||||
|
||||
void set_bus_object_ptr(ScsiBus *bus_obj_ptr) {
|
||||
this->bus_obj = bus_obj_ptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
@@ -194,9 +207,17 @@ protected:
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
class ScsiBus : public HWComponent {
|
||||
public:
|
||||
ScsiBus();
|
||||
ScsiBus(const std::string name);
|
||||
~ScsiBus() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("SCSIO"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<ScsiBus>(new ScsiBus("SCSI1"));
|
||||
}
|
||||
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,12 +23,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
ScsiBus::ScsiBus()
|
||||
ScsiBus::ScsiBus(const std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::SCSI_BUS);
|
||||
|
||||
for(int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
@@ -50,6 +52,8 @@ void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
}
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
dev_obj->set_bus_object_ptr(this);
|
||||
}
|
||||
|
||||
void ScsiBus::change_bus_phase(int initiator_id)
|
||||
@@ -58,7 +62,7 @@ void ScsiBus::change_bus_phase(int initiator_id)
|
||||
if (i == initiator_id)
|
||||
continue; // don't notify the initiator
|
||||
if (this->devices[i] != nullptr) {
|
||||
this->devices[i]->notify(this, ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +223,7 @@ void ScsiBus::confirm_selection(int target_id)
|
||||
|
||||
// notify initiator about selection confirmation from target
|
||||
if (this->initiator_id >= 0) {
|
||||
this->devices[this->initiator_id]->notify(this, ScsiMsg::CONFIRM_SEL, target_id);
|
||||
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +259,7 @@ bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step(this);
|
||||
this->devices[this->target_id]->next_step();
|
||||
}
|
||||
|
||||
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
|
||||
@@ -273,3 +277,14 @@ void ScsiBus::disconnect(int dev_id)
|
||||
change_bus_phase(dev_id);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Scsi0_Descriptor = {
|
||||
ScsiBus::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Scsi1_Descriptor = {
|
||||
ScsiBus::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Scsi0, Scsi0_Descriptor);
|
||||
REGISTER_DEVICE(Scsi1, Scsi1_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
void ScsiDevice::notify(ScsiMsg msg_type, int param)
|
||||
{
|
||||
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
|
||||
switch (param) {
|
||||
@@ -35,19 +35,18 @@ void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
break;
|
||||
case ScsiPhase::SELECTION:
|
||||
// check if something tries to select us
|
||||
if (bus_obj->get_data_lines() & (1 << scsi_id)) {
|
||||
if (this->bus_obj->get_data_lines() & (1 << scsi_id)) {
|
||||
LOG_F(9, "ScsiDevice %d selected", this->scsi_id);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
BUS_SETTLE_DELAY,
|
||||
[this, bus_obj]() {
|
||||
[this]() {
|
||||
// don't confirm selection if BSY or I/O are asserted
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
return;
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
|
||||
bus_obj->confirm_selection(this->scsi_id);
|
||||
this->initiator_id = bus_obj->get_initiator_id();
|
||||
this->bus_obj = bus_obj;
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
|
||||
this->bus_obj->confirm_selection(this->scsi_id);
|
||||
this->initiator_id = this->bus_obj->get_initiator_id();
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
if (this->msg_buf[0] != 0x80) {
|
||||
LOG_F(INFO, "ScsiDevice: received message 0x%X", this->msg_buf[0]);
|
||||
@@ -73,7 +72,7 @@ void ScsiDevice::switch_phase(const int new_phase)
|
||||
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
|
||||
}
|
||||
|
||||
void ScsiDevice::next_step(ScsiBus* bus_obj)
|
||||
void ScsiDevice::next_step()
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
@@ -98,7 +97,7 @@ void ScsiDevice::next_step(ScsiBus* bus_obj)
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::BUS_FREE:
|
||||
bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
this->bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
this->switch_phase(ScsiPhase::BUS_FREE);
|
||||
break;
|
||||
default:
|
||||
|
||||
+108
-36
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -53,7 +53,7 @@ void ScsiHardDisk::insert_image(std::string filename) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE;
|
||||
} else {
|
||||
ABORT_F("ScsiHardDisk: could not determine file size using stat()");
|
||||
ABORT_F("SCSI-HD: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
@@ -72,14 +72,10 @@ void ScsiHardDisk::process_command() {
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
uint8_t* cmd = this->cmd_buf;
|
||||
|
||||
if (cmd[0] != 0 && cmd[0] != 8 && cmd[0] != 0xA && cmd[0] != 0x28
|
||||
&& cmd[0] != 0x2A && cmd[0] != 0x25) {
|
||||
ABORT_F("SCSI-HD: untested command 0x%X", cmd[0]);
|
||||
}
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
test_unit_ready();
|
||||
@@ -92,8 +88,7 @@ void ScsiHardDisk::process_command() {
|
||||
req_sense(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
alloc_len = (cmd[3] << 8) + cmd[4];
|
||||
inquiry(alloc_len);
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
@@ -125,16 +120,16 @@ void ScsiHardDisk::process_command() {
|
||||
mode_select_6(param_len);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
page_code = cmd[2] & 0x1F;
|
||||
subpage_code = cmd[3];
|
||||
alloc_len = cmd[4];
|
||||
mode_sense_6(page_code, subpage_code, alloc_len);
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
read_capacity_10();
|
||||
this->read_capacity_10();
|
||||
break;
|
||||
case ScsiCommand::READ_BUFFER:
|
||||
read_buffer();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unrecognized command: %x", cmd[0]);
|
||||
LOG_F(WARNING, "SCSI-HD: unrecognized command: %x", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +137,7 @@ bool ScsiHardDisk::prepare_data() {
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = this->cur_buf_cnt;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
@@ -154,14 +149,14 @@ bool ScsiHardDisk::prepare_data() {
|
||||
} else {
|
||||
this->img_buffer[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->cur_buf_cnt = 1;
|
||||
this->data_size = 1;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->img_buffer[0] = this->msg_code;
|
||||
this->cur_buf_cnt = 1;
|
||||
this->data_size = 1;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unexpected phase in prepare_data");
|
||||
LOG_F(WARNING, "SCSI-HD: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -180,21 +175,33 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
}
|
||||
|
||||
void ScsiHardDisk::inquiry(uint16_t alloc_len) {
|
||||
if (alloc_len >= 48) {
|
||||
uint8_t empty_filler[1 << 17] = {0x0};
|
||||
std::memcpy(img_buffer, empty_filler, (1 << 17));
|
||||
img_buffer[2] = 0x1;
|
||||
img_buffer[3] = 0x2;
|
||||
img_buffer[4] = 0x31;
|
||||
img_buffer[7] = 0x1C;
|
||||
void ScsiHardDisk::inquiry() {
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("SCSI-HD: invalid page number in INQUIRY");
|
||||
}
|
||||
|
||||
if (alloc_len >= 36) {
|
||||
this->img_buffer[0] = 0; // device type: Direct-access block device
|
||||
this->img_buffer[1] = 0; // non-removable media
|
||||
this->img_buffer[2] = 2; // ANSI version: SCSI-2
|
||||
this->img_buffer[3] = 1; // response data format
|
||||
this->img_buffer[4] = 0; // additional length
|
||||
this->img_buffer[5] = 0;
|
||||
this->img_buffer[6] = 0;
|
||||
this->img_buffer[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(img_buffer + 8, vendor_info, 8);
|
||||
std::memcpy(img_buffer + 16, prod_info, 16);
|
||||
std::memcpy(img_buffer + 32, rev_info, 8);
|
||||
std::memcpy(img_buffer + 40, serial_info, 8);
|
||||
std::memcpy(img_buffer + 32, rev_info, 4);
|
||||
|
||||
this->bytes_out = 36;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
LOG_F(WARNING, "Allocation length too small: %d", alloc_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +219,57 @@ int ScsiHardDisk::mode_select_6(uint8_t param_len) {
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiHardDisk::mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len) {
|
||||
LOG_F(WARNING, "Page Code %d; Subpage Code: %d", page_code, subpage_code);
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiHardDisk::mode_sense_6() {
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
uint8_t page_ctrl = this->cmd_buf[2] >> 6;
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
this->img_buffer[ 0] = 13; // initial data size
|
||||
this->img_buffer[ 1] = 0; // medium type
|
||||
this->img_buffer[ 2] = 0; // medium is write enabled
|
||||
this->img_buffer[ 3] = 8; // block description length
|
||||
|
||||
this->img_buffer[ 4] = 0; // density code
|
||||
this->img_buffer[ 5] = (this->total_blocks >> 16) & 0xFFU;
|
||||
this->img_buffer[ 6] = (this->total_blocks >> 8) & 0xFFU;
|
||||
this->img_buffer[ 7] = (this->total_blocks ) & 0xFFU;
|
||||
this->img_buffer[ 8] = 0;
|
||||
this->img_buffer[ 9] = 0; // sector size MSB
|
||||
this->img_buffer[10] = 2; // sector size
|
||||
this->img_buffer[11] = 0; // sector size LSB
|
||||
|
||||
this->img_buffer[12] = page_code;
|
||||
|
||||
switch(page_code) {
|
||||
case 3: // Format device page
|
||||
this->img_buffer[13] = 22; // data size - 1
|
||||
std::memset(&this->img_buffer[14], 0, 22);
|
||||
// default values taken from Empire 540/1080S manual
|
||||
this->img_buffer[15] = 6; // tracks per defect zone
|
||||
this->img_buffer[17] = 1; // alternate sectors per zone
|
||||
this->img_buffer[23] = 92; // sectors per track in the outermost zone
|
||||
this->img_buffer[27] = 1; // interleave factor
|
||||
this->img_buffer[29] = 19; // track skew factor
|
||||
this->img_buffer[31] = 25; // cylinder skew factor
|
||||
this->img_buffer[32] = 0x80; // SSEC=1, HSEC=0, RMB=0, SURF=0, INS=0
|
||||
WRITE_WORD_BE_U(&this->img_buffer[24], 512); // bytes per sector
|
||||
break;
|
||||
case 0x30: // Copyright page for Apple certified drives
|
||||
this->img_buffer[13] = 22; // data size - 1
|
||||
std::memcpy(&this->img_buffer[14], Apple_Copyright_Page_Data, 22);
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
|
||||
};
|
||||
|
||||
// adjust for overall mode sense data length
|
||||
this->img_buffer[0] += this->img_buffer[13] + 1;
|
||||
|
||||
this->bytes_out = std::min(alloc_len, (uint8_t)this->img_buffer[0]);
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_capacity_10() {
|
||||
@@ -237,8 +293,7 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
WRITE_DWORD_BE_A(&img_buffer[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&img_buffer[4], blk_len);
|
||||
|
||||
this->cur_buf_cnt = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->bytes_out = 8;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
@@ -262,8 +317,7 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
this->hdd_img.read(img_buffer, transfer_size);
|
||||
|
||||
this->cur_buf_cnt = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->bytes_out = transfer_size;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
@@ -296,6 +350,24 @@ void ScsiHardDisk::rewind() {
|
||||
this->hdd_img.seekg(0, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_buffer() {
|
||||
uint8_t mode = this->cmd_buf[1];
|
||||
uint32_t alloc_len = (this->cmd_buf[6] << 24) | (this->cmd_buf[7] << 16) |
|
||||
this->cmd_buf[8];
|
||||
|
||||
switch(mode) {
|
||||
case 0: // Combined header and data mode
|
||||
WRITE_DWORD_BE_A(&this->img_buffer[0], 0x10000); // report buffer size of 64K
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI-HD: unsupported mode %d in READ_BUFFER", mode);
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
static const PropMap SCSI_HD_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
{"hdd_wr_prot", new BinProperty(0)},
|
||||
|
||||
@@ -51,20 +51,22 @@ protected:
|
||||
int send_diagnostic();
|
||||
int mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len);
|
||||
void mode_sense_6();
|
||||
void format();
|
||||
void inquiry(uint16_t alloc_len);
|
||||
void inquiry();
|
||||
void read_capacity_10();
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void seek(uint32_t lba);
|
||||
void rewind();
|
||||
void read_buffer();
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
int bytes_out = 0;
|
||||
|
||||
char img_buffer[1 << 21]; // TODO: add proper buffer management!
|
||||
|
||||
@@ -75,8 +77,7 @@ private:
|
||||
//inquiry info
|
||||
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
||||
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
|
||||
char rev_info[8] = {'d', 'i', '0', '0', '0', '0', '0', '1'};
|
||||
char serial_info[8] = {'0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
char rev_info[4] = {'d', 'i', '0', '1'};
|
||||
};
|
||||
|
||||
#endif // SCSI_HD_H
|
||||
+71
-49
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** High-level VIA-CUDA combo device emulation.
|
||||
*/
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -33,6 +33,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -75,8 +77,11 @@ ViaCuda::ViaCuda() {
|
||||
// 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());
|
||||
// establish ADB bus connection
|
||||
this->adb_bus_obj = dynamic_cast<AdbBus*>(gMachineObj->get_comp_by_type(HWCompType::ADB_HOST));
|
||||
|
||||
// autopoll handler will be called during post-processing of the host events
|
||||
EventManager::get_instance()->add_post_handler(this, &ViaCuda::autopoll_handler);
|
||||
|
||||
this->cuda_init();
|
||||
|
||||
@@ -325,20 +330,18 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
LOG_F(9, "Cuda state changed!");
|
||||
|
||||
this->old_tip = new_tip;
|
||||
this->old_byteack = new_byteack;
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
process_packet();
|
||||
|
||||
/* start response transaction */
|
||||
// start response transaction
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
@@ -350,7 +353,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; /* assert TREQ */
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
@@ -359,7 +362,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { /* data transfer: Host --> Cuda */
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->in_count < sizeof(this->in_buf)) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
@@ -367,7 +370,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
} else {
|
||||
LOG_F(WARNING, "Cuda input buffer too small. Truncating data!");
|
||||
}
|
||||
} else { /* data transfer: Cuda --> Host */
|
||||
} else { // data transfer: Cuda --> Host
|
||||
(this->*out_handler)();
|
||||
// tell the system we've written next byte after 88 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(88));
|
||||
@@ -389,17 +392,19 @@ void ViaCuda::pram_out_handler()
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
LOG_F(9, "OutBufHandler: sending next byte 0x%X", this->out_buf[this->out_pos]);
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
if (!this->is_open_ended && this->out_pos >= this->out_count) {
|
||||
// tell the host this will be the last byte
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
} else if (this->is_open_ended) {
|
||||
LOG_F(9, "OutBufHandler: switching to next handler");
|
||||
this->out_handler = this->next_out_handler;
|
||||
this->next_out_handler = &ViaCuda::null_out_handler;
|
||||
(this->*out_handler)();
|
||||
} else {
|
||||
LOG_F(9, "Sending last byte");
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; /* negate TREQ */
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
@@ -407,7 +412,7 @@ void ViaCuda::out_buf_handler() {
|
||||
void ViaCuda::response_header(uint32_t pkt_type, uint32_t pkt_flag) {
|
||||
this->out_buf[0] = pkt_type;
|
||||
this->out_buf[1] = pkt_flag;
|
||||
this->out_buf[2] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_buf[2] = this->in_buf[1]; // copy original cmd
|
||||
this->out_count = 3;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
@@ -419,7 +424,7 @@ void ViaCuda::error_response(uint32_t error) {
|
||||
this->out_buf[0] = CUDA_PKT_ERROR;
|
||||
this->out_buf[1] = error;
|
||||
this->out_buf[2] = this->in_buf[0];
|
||||
this->out_buf[3] = this->in_buf[1]; /* copy original cmd */
|
||||
this->out_buf[3] = this->in_buf[1]; // copy original cmd
|
||||
this->out_count = 4;
|
||||
this->out_pos = 0;
|
||||
this->out_handler = &ViaCuda::out_buf_handler;
|
||||
@@ -437,7 +442,7 @@ void ViaCuda::process_packet() {
|
||||
switch (this->in_buf[0]) {
|
||||
case CUDA_PKT_ADB:
|
||||
LOG_F(9, "Cuda: ADB packet received");
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
this->process_adb_command();
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
LOG_F(9, "Cuda: pseudo command packet received");
|
||||
@@ -454,39 +459,50 @@ void ViaCuda::process_packet() {
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::process_adb_command(uint8_t cmd_byte, int data_count) {
|
||||
int adb_dev = cmd_byte >> 4; // 2 for keyboard, 3 for mouse
|
||||
int cmd = cmd_byte & 0xF;
|
||||
void ViaCuda::process_adb_command() {
|
||||
uint8_t adb_stat, output_size;
|
||||
|
||||
if (!cmd) {
|
||||
LOG_F(9, "Cuda: ADB SendReset command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else if (cmd == 1) {
|
||||
LOG_F(9, "Cuda: ADB Flush command requested");
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} 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)) {
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
adb_stat = this->adb_bus_obj->process_command(&this->in_buf[1],
|
||||
this->in_count - 1);
|
||||
response_header(CUDA_PKT_ADB, adb_stat);
|
||||
output_size = this->adb_bus_obj->get_output_count();
|
||||
if (output_size) {
|
||||
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
|
||||
this->out_count += output_size;
|
||||
}
|
||||
}
|
||||
|
||||
void ViaCuda::autopoll_handler() {
|
||||
uint8_t adb_status, output_size;
|
||||
|
||||
if (!this->autopoll_enabled)
|
||||
return;
|
||||
|
||||
// send TALK R0 command to address 3 (mouse)
|
||||
uint8_t in_data[2] = { 0x3C, 0};
|
||||
|
||||
adb_status = this->adb_bus_obj->process_command(in_data, 1);
|
||||
|
||||
if (adb_status == ADB_STAT_OK) {
|
||||
if (!this->old_tip || !this->treq) {
|
||||
LOG_F(WARNING, "Cuda transaction probably in progress");
|
||||
}
|
||||
} else if ((cmd & 0xC) == 0xC) {
|
||||
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])) {
|
||||
response_header(CUDA_PKT_ADB, 0);
|
||||
} else {
|
||||
response_header(CUDA_PKT_ADB, 2);
|
||||
|
||||
// prepare autopoll packet
|
||||
response_header(CUDA_PKT_ADB, adb_status | ADB_STAT_AUTOPOLL);
|
||||
this->out_buf[2] = 0x3C; // put the proper ADB command
|
||||
output_size = this->adb_bus_obj->get_output_count();
|
||||
if (output_size) {
|
||||
std::memcpy(&this->out_buf[3], this->adb_bus_obj->get_output_buf(), output_size);
|
||||
this->out_count += output_size;
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "Cuda: unsupported ADB command 0x%X", cmd);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
|
||||
// assert TREQ
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
schedule_sr_int(USECS_TO_NSECS(30));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,8 +514,10 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
case CUDA_START_STOP_AUTOPOLL:
|
||||
if (this->in_buf[2]) {
|
||||
LOG_F(INFO, "Cuda: autopoll started, rate: %d ms", this->poll_rate);
|
||||
this->autopoll_enabled = true;
|
||||
} else {
|
||||
LOG_F(INFO, "Cuda: autopoll stopped");
|
||||
this->autopoll_enabled = false;
|
||||
}
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
@@ -712,8 +730,12 @@ void ViaCuda::i2c_comb_transaction(
|
||||
}
|
||||
}
|
||||
|
||||
static const vector<string> Cuda_Subdevices = {
|
||||
"AdbBus", "AdbMouse", "AdbKeyboard"
|
||||
};
|
||||
|
||||
static const DeviceDescription ViaCuda_Descriptor = {
|
||||
ViaCuda::create, {}, {}
|
||||
ViaCuda::create, Cuda_Subdevices, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -43,7 +43,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIACUDA_H
|
||||
#define VIACUDA_H
|
||||
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/adb/adbbus.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
@@ -223,7 +223,9 @@ private:
|
||||
void (ViaCuda::*next_out_handler)(void);
|
||||
|
||||
std::unique_ptr<NVram> pram_obj;
|
||||
std::unique_ptr<ADB_Bus> adb_bus;
|
||||
|
||||
AdbBus* adb_bus_obj = nullptr;
|
||||
bool autopoll_enabled = false;
|
||||
|
||||
// VIA methods
|
||||
void print_enabled_ints(); // print enabled VIA interrupts and their sources
|
||||
@@ -241,7 +243,7 @@ private:
|
||||
void response_header(uint32_t pkt_type, uint32_t pkt_flag);
|
||||
void error_response(uint32_t error);
|
||||
void process_packet();
|
||||
void process_adb_command(uint8_t cmd_byte, int data_count);
|
||||
void process_adb_command();
|
||||
void pseudo_command(int cmd, int data_count);
|
||||
|
||||
void null_out_handler(void);
|
||||
@@ -249,6 +251,8 @@ private:
|
||||
void out_buf_handler(void);
|
||||
void i2c_handler(void);
|
||||
|
||||
void autopoll_handler();
|
||||
|
||||
/* I2C related methods */
|
||||
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(
|
||||
|
||||
@@ -0,0 +1,455 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 BigMac Ethernet controller emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/ethernet/bigmac.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
BigMac::BigMac(uint8_t id) {
|
||||
set_name("BigMac");
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
|
||||
|
||||
this->chip_id = id;
|
||||
this->chip_reset();
|
||||
}
|
||||
|
||||
void BigMac::chip_reset() {
|
||||
this->event_mask = 0xFFFFU; // disable HW events causing on-chip interrupts
|
||||
this->stat = 0;
|
||||
|
||||
this->phy_reset();
|
||||
this->mii_reset();
|
||||
this->srom_reset();
|
||||
}
|
||||
|
||||
uint16_t BigMac::read(uint16_t reg_offset) {
|
||||
switch (reg_offset) {
|
||||
case BigMacReg::XIFC:
|
||||
return this->tx_if_ctrl;
|
||||
case BigMacReg::CHIP_ID:
|
||||
return this->chip_id;
|
||||
case BigMacReg::MIF_CSR:
|
||||
return (this->mif_csr_old & ~Mif_Data_In) | (this->mii_in_bit << 3);
|
||||
case BigMacReg::GLOB_STAT: {
|
||||
uint16_t old_stat = this->stat;
|
||||
this->stat = 0; // clear-on-read
|
||||
return old_stat;
|
||||
}
|
||||
case BigMacReg::EVENT_MASK:
|
||||
return this->event_mask;
|
||||
case BigMacReg::SROM_CSR:
|
||||
return (this->srom_csr_old & ~Srom_Data_In) | (this->srom_in_bit << 2);
|
||||
case BigMacReg::TX_SW_RST:
|
||||
return this->tx_reset;
|
||||
case BigMacReg::TX_CONFIG:
|
||||
return this->tx_config;
|
||||
case BigMacReg::PEAK_ATT: {
|
||||
uint8_t old_val = this->peak_attempts;
|
||||
this->peak_attempts = 0; // clear-on-read
|
||||
return old_val;
|
||||
}
|
||||
case BigMacReg::NC_CNT:
|
||||
return this->norm_coll_cnt;
|
||||
case BigMacReg::EX_CNT:
|
||||
return this->excs_coll_cnt;
|
||||
case BigMacReg::LT_CNT:
|
||||
return this->late_coll_cnt;
|
||||
case BigMacReg::RX_CONFIG:
|
||||
return this->rx_config;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented register at 0x%X", this->name.c_str(),
|
||||
reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BigMac::write(uint16_t reg_offset, uint16_t value) {
|
||||
switch (reg_offset) {
|
||||
case BigMacReg::XIFC:
|
||||
this->tx_if_ctrl = value;
|
||||
break;
|
||||
case BigMacReg::TX_FIFO_CSR:
|
||||
this->tx_fifo_enable = !!(value & 1);
|
||||
this->tx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
break;
|
||||
case BigMacReg::TX_FIFO_TH:
|
||||
this->tx_fifo_tresh = value;
|
||||
break;
|
||||
case BigMacReg::RX_FIFO_CSR:
|
||||
this->rx_fifo_enable = !!(value & 1);
|
||||
this->rx_fifo_size = (((value >> 1) & 0xFF) + 1) << 7;
|
||||
break;
|
||||
case BigMacReg::MIF_CSR:
|
||||
if (value & Mif_Data_Out_En) {
|
||||
// send bits one by one on each low-to-high transition of Mif_Clock
|
||||
if (((this->mif_csr_old ^ value) & Mif_Clock) && (value & Mif_Clock))
|
||||
this->mii_xmit_bit(!!(value & Mif_Data_Out));
|
||||
} else {
|
||||
if (((this->mif_csr_old ^ value) & Mif_Clock) && (value & Mif_Clock))
|
||||
this->mii_rcv_bit();
|
||||
}
|
||||
this->mif_csr_old = value;
|
||||
break;
|
||||
case BigMacReg::EVENT_MASK:
|
||||
this->event_mask = value;
|
||||
break;
|
||||
case BigMacReg::SROM_CSR:
|
||||
if (value & Srom_Chip_Select) {
|
||||
// exchange data on each low-to-high transition of Srom_Clock
|
||||
if (((this->srom_csr_old ^ value) & Srom_Clock) && (value & Srom_Clock))
|
||||
this->srom_xmit_bit(!!(value & Srom_Data_Out));
|
||||
} else {
|
||||
this->srom_reset();
|
||||
}
|
||||
this->srom_csr_old = value;
|
||||
break;
|
||||
case BigMacReg::TX_SW_RST:
|
||||
if (value == 1) {
|
||||
LOG_F(INFO, "%s: transceiver soft reset asserted", this->name.c_str());
|
||||
this->tx_reset = 0; // acknowledge SW reset
|
||||
}
|
||||
break;
|
||||
case BigMacReg::TX_CONFIG:
|
||||
this->tx_config = value;
|
||||
break;
|
||||
case BigMacReg::NC_CNT:
|
||||
this->norm_coll_cnt = value;
|
||||
break;
|
||||
case BigMacReg::NT_CNT:
|
||||
this->net_coll_cnt = value;
|
||||
break;
|
||||
case BigMacReg::EX_CNT:
|
||||
this->excs_coll_cnt = value;
|
||||
break;
|
||||
case BigMacReg::LT_CNT:
|
||||
this->late_coll_cnt = value;
|
||||
break;
|
||||
case BigMacReg::RNG_SEED:
|
||||
this->rng_seed = value;
|
||||
break;
|
||||
case BigMacReg::RX_SW_RST:
|
||||
if (!value) {
|
||||
LOG_F(INFO, "%s: receiver soft reset asserted", this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case BigMacReg::RX_CONFIG:
|
||||
this->rx_config = value;
|
||||
break;
|
||||
case BigMacReg::MAC_ADDR_0:
|
||||
case BigMacReg::MAC_ADDR_1:
|
||||
case BigMacReg::MAC_ADDR_2:
|
||||
this->mac_addr_flt[8 - ((reg_offset >> 4) & 0xF)] = value;
|
||||
break;
|
||||
case BigMacReg::RX_FRM_CNT:
|
||||
this->rcv_frame_cnt = value;
|
||||
break;
|
||||
case BigMacReg::RX_LE_CNT:
|
||||
this->len_err_cnt = value;
|
||||
break;
|
||||
case BigMacReg::RX_AE_CNT:
|
||||
this->align_err_cnt = value;
|
||||
break;
|
||||
case BigMacReg::RX_FE_CNT:
|
||||
this->fcs_err_cnt = value;
|
||||
break;
|
||||
case BigMacReg::RX_CVE_CNT:
|
||||
this->cv_err_cnt = value;
|
||||
break;
|
||||
case BigMacReg::HASH_TAB_0:
|
||||
case BigMacReg::HASH_TAB_1:
|
||||
case BigMacReg::HASH_TAB_2:
|
||||
case BigMacReg::HASH_TAB_3:
|
||||
this->hash_table[(reg_offset >> 4) & 3] = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: unimplemented register at 0x%X is written with 0x%X",
|
||||
this->name.c_str(), reg_offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
// ================ Media Independent Interface (MII) emulation ================
|
||||
bool BigMac::mii_rcv_value(uint16_t& var, uint8_t num_bits, uint8_t next_bit) {
|
||||
var = (var << 1) | (next_bit & 1);
|
||||
this->mii_bit_counter++;
|
||||
if (this->mii_bit_counter >= num_bits) {
|
||||
this->mii_bit_counter = 0;
|
||||
return true; // all bits have been received -> return true
|
||||
}
|
||||
return false; // more bits expected
|
||||
}
|
||||
|
||||
void BigMac::mii_rcv_bit() {
|
||||
switch(this->mii_state) {
|
||||
case MII_FRAME_SM::Preamble:
|
||||
this->mii_in_bit = 1; // required for OSX
|
||||
this->mii_reset();
|
||||
break;
|
||||
case MII_FRAME_SM::Turnaround:
|
||||
this->mii_in_bit = 0;
|
||||
this->mii_bit_counter = 16;
|
||||
this->mii_state = MII_FRAME_SM::Read_Data;
|
||||
break;
|
||||
case MII_FRAME_SM::Read_Data:
|
||||
if (this->mii_bit_counter) {
|
||||
--this->mii_bit_counter;
|
||||
this->mii_in_bit = (this->mii_data >> this->mii_bit_counter) & 1;
|
||||
if (!this->mii_bit_counter) {
|
||||
this->mii_state = MII_FRAME_SM::Preamble;
|
||||
}
|
||||
} else { // out of sync (shouldn't happen)
|
||||
this->mii_reset();
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Stop:
|
||||
this->mii_reset();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unhandled state %d in mii_rcv_bit", this->name.c_str(),
|
||||
this->mii_state);
|
||||
this->mii_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void BigMac::mii_xmit_bit(const uint8_t bit_val) {
|
||||
switch(this->mii_state) {
|
||||
case MII_FRAME_SM::Preamble:
|
||||
if (bit_val) {
|
||||
this->mii_bit_counter++;
|
||||
if (this->mii_bit_counter >= 32) {
|
||||
this->mii_state = MII_FRAME_SM::Start;
|
||||
this->mii_in_bit = 1; // checked in OSX
|
||||
this->mii_bit_counter = 0;
|
||||
}
|
||||
} else { // zero bit -> out of sync
|
||||
this->mii_reset();
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Start:
|
||||
if (this->mii_rcv_value(this->mii_start, 2, bit_val)) {
|
||||
LOG_F(9, "MII_Start=0x%X", this->mii_start);
|
||||
this->mii_state = MII_FRAME_SM::Opcode;
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Opcode:
|
||||
if (this->mii_rcv_value(this->mii_opcode, 2, bit_val)) {
|
||||
LOG_F(9, "MII_Opcode=0x%X", this->mii_opcode);
|
||||
this->mii_state = MII_FRAME_SM::Phy_Address;
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Phy_Address:
|
||||
if (this->mii_rcv_value(this->mii_phy_address, 5, bit_val)) {
|
||||
LOG_F(9, "MII_PHY_Address=0x%X", this->mii_phy_address);
|
||||
this->mii_state = MII_FRAME_SM::Reg_Address;
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Reg_Address:
|
||||
if (this->mii_rcv_value(this->mii_reg_address, 5, bit_val)) {
|
||||
LOG_F(9, "MII_REG_Address=0x%X", this->mii_reg_address);
|
||||
|
||||
if (this->mii_start != 1)
|
||||
LOG_F(ERROR, "%s: unsupported frame type %d", this->name.c_str(),
|
||||
this->mii_start);
|
||||
if (this->mii_phy_address)
|
||||
LOG_F(ERROR, "%s: unsupported PHY address %d", this->name.c_str(),
|
||||
this->mii_phy_address);
|
||||
switch (this->mii_opcode) {
|
||||
case 1: // write
|
||||
this->mii_state = MII_FRAME_SM::Turnaround;
|
||||
break;
|
||||
case 2: // read
|
||||
this->mii_data = this->phy_reg_read(this->mii_reg_address);
|
||||
this->mii_state = MII_FRAME_SM::Turnaround;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: invalid MII opcode %d", this->name.c_str(),
|
||||
this->mii_opcode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Turnaround:
|
||||
if (this->mii_rcv_value(this->mii_turnaround, 2, bit_val)) {
|
||||
if (this->mii_turnaround != 2)
|
||||
LOG_F(ERROR, "%s: unexpected turnaround 0x%X", this->name.c_str(),
|
||||
this->mii_turnaround);
|
||||
this->mii_state = MII_FRAME_SM::Write_Data;
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Write_Data:
|
||||
if (this->mii_rcv_value(this->mii_data, 16, bit_val)) {
|
||||
LOG_F(9, "%s: MII data received = 0x%X", this->name.c_str(),
|
||||
this->mii_data);
|
||||
this->phy_reg_write(this->mii_reg_address, this->mii_data);
|
||||
this->mii_state = MII_FRAME_SM::Stop;
|
||||
}
|
||||
break;
|
||||
case MII_FRAME_SM::Stop:
|
||||
if (this->mii_rcv_value(this->mii_stop, 2, bit_val)) {
|
||||
LOG_F(9, "MII_Stop=0x%X", this->mii_stop);
|
||||
this->mii_reset();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unhandled state %d in mii_xmit_bit", this->name.c_str(),
|
||||
this->mii_state);
|
||||
this->mii_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void BigMac::mii_reset() {
|
||||
mii_start = 0;
|
||||
mii_opcode = 0;
|
||||
mii_phy_address = 0;
|
||||
mii_reg_address = 0;
|
||||
mii_turnaround = 0;
|
||||
mii_data = 0;
|
||||
mii_stop = 0;
|
||||
this->mii_bit_counter = 0;
|
||||
this->mii_state = MII_FRAME_SM::Preamble;
|
||||
}
|
||||
|
||||
// ===================== Ethernet PHY interface emulation =====================
|
||||
void BigMac::phy_reset() {
|
||||
// TODO: add PHY type property to be able to select another PHY (DP83843)
|
||||
if (this->chip_id == EthernetCellId::Paddington) {
|
||||
this->phy_oui = 0x1E0400; // LXT970 aka ST10040 PHY
|
||||
this->phy_model = 0;
|
||||
this->phy_rev = 0;
|
||||
} else { // assume Heathrow with LXT907 PHY
|
||||
this->phy_oui = 0; // LXT907 doesn't support MII, MDIO is pulled low
|
||||
this->phy_model = 0;
|
||||
this->phy_rev = 0;
|
||||
}
|
||||
this->phy_anar = 0xA1; // tell the world we support 10BASE-T and 100BASE-TX
|
||||
}
|
||||
|
||||
uint16_t BigMac::phy_reg_read(uint8_t reg_num) {
|
||||
switch(reg_num) {
|
||||
case PHY_BMCR:
|
||||
return this->phy_bmcr;
|
||||
case PHY_BMSR:
|
||||
return 0x7809; // value from LXT970 datasheet
|
||||
case PHY_ID1:
|
||||
return (this->phy_oui >> 6) & 0xFFFFU;
|
||||
case PHY_ID2:
|
||||
return ((this->phy_oui << 10) | (phy_model << 4) | phy_rev) & 0xFFFFU;
|
||||
case PHY_ANAR:
|
||||
return this->phy_anar;
|
||||
default:
|
||||
LOG_F(ERROR, "Reading unimplemented PHY register %d", reg_num);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BigMac::phy_reg_write(uint8_t reg_num, uint16_t value) {
|
||||
switch(reg_num) {
|
||||
case PHY_BMCR:
|
||||
if (value & 0x8000) {
|
||||
LOG_F(INFO, "PHY reset requested");
|
||||
value &= ~0x8000; // Reset bit is self-clearing
|
||||
}
|
||||
this->phy_bmcr = value;
|
||||
break;
|
||||
case PHY_ANAR:
|
||||
this->phy_anar = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Writing unimplemented PHY register %d", reg_num);
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== MAC Serial EEPROM emulation ========================
|
||||
void BigMac::srom_reset() {
|
||||
this->srom_csr_old = 0;
|
||||
this->srom_bit_counter = 0;
|
||||
this->srom_opcode = 0;
|
||||
this->srom_address = 0;
|
||||
this->srom_state = Srom_Start;
|
||||
}
|
||||
|
||||
bool BigMac::srom_rcv_value(uint16_t& var, uint8_t num_bits, uint8_t next_bit) {
|
||||
var = (var << 1) | (next_bit & 1);
|
||||
this->srom_bit_counter++;
|
||||
if (this->srom_bit_counter >= num_bits) {
|
||||
this->srom_bit_counter = 0;
|
||||
return true; // all bits have been received -> return true
|
||||
}
|
||||
return false; // more bits expected
|
||||
}
|
||||
|
||||
void BigMac::srom_xmit_bit(const uint8_t bit_val) {
|
||||
switch(this->srom_state) {
|
||||
case Srom_Start:
|
||||
if (bit_val)
|
||||
this->srom_state = Srom_Opcode;
|
||||
else
|
||||
this->srom_reset();
|
||||
break;
|
||||
case Srom_Opcode:
|
||||
if (this->srom_rcv_value(this->srom_opcode, 2, bit_val)) {
|
||||
switch(this->srom_opcode) {
|
||||
case 2: // read
|
||||
this->srom_state = Srom_Address;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported SROM opcode %d", this->name.c_str(),
|
||||
this->srom_opcode);
|
||||
this->srom_reset();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Srom_Address:
|
||||
if (this->srom_rcv_value(this->srom_address, 6, bit_val)) {
|
||||
LOG_F(9, "SROM address received = 0x%X", this->srom_address);
|
||||
this->srom_bit_counter = 16;
|
||||
this->srom_state = Srom_Read_Data;
|
||||
}
|
||||
break;
|
||||
case Srom_Read_Data:
|
||||
if (this->srom_bit_counter) {
|
||||
this->srom_bit_counter--;
|
||||
this->srom_in_bit = (this->srom_data[this->srom_address] >> this->srom_bit_counter) & 1;
|
||||
if (!this->srom_bit_counter) {
|
||||
this->srom_address++;
|
||||
this->srom_bit_counter = 16;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unhandled state %d in srom_xmit_bit", this->name.c_str(),
|
||||
this->srom_state);
|
||||
this->srom_reset();
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription BigMac_Heathrow_Descriptor = {
|
||||
BigMac::create_for_heathrow, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription BigMac_Paddington_Descriptor = {
|
||||
BigMac::create_for_paddington, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(BigMacHeathrow, BigMac_Heathrow_Descriptor);
|
||||
REGISTER_DEVICE(BigMacPaddington, BigMac_Paddington_Descriptor);
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 BigMac Ethernet controller definitions. */
|
||||
|
||||
#ifndef BIG_MAC_H
|
||||
#define BIG_MAC_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/* Ethernet cell IDs for various MacIO ASICs. */
|
||||
enum EthernetCellId : uint8_t {
|
||||
Heathrow = 0xB1,
|
||||
Paddington = 0xC7,
|
||||
};
|
||||
|
||||
/* BigMac HW registers. */
|
||||
enum BigMacReg : uint16_t {
|
||||
XIFC = 0x000, // transceiver interface control
|
||||
TX_FIFO_CSR = 0x100,
|
||||
TX_FIFO_TH = 0x110,
|
||||
RX_FIFO_CSR = 0x120,
|
||||
CHIP_ID = 0x170,
|
||||
MIF_CSR = 0x180,
|
||||
GLOB_STAT = 0x200, // Apple: kSTAT, Sun: Global Status Register
|
||||
EVENT_MASK = 0x210, // ambiguously called INT_DISABLE in the Apple source
|
||||
SROM_CSR = 0x190,
|
||||
TX_SW_RST = 0x420,
|
||||
TX_CONFIG = 0x430,
|
||||
PEAK_ATT = 0x4E0, // Apple: kPAREG, Sun: PeakAttempts Register
|
||||
NC_CNT = 0x500, // Normal Collision Counter
|
||||
NT_CNT = 0x510, // Apple: Network Collision Counter
|
||||
EX_CNT = 0x520, // Excessive Collision Counter
|
||||
LT_CNT = 0x530, // Late Collision Counter
|
||||
RNG_SEED = 0x540,
|
||||
RX_SW_RST = 0x620,
|
||||
RX_CONFIG = 0x630,
|
||||
MAC_ADDR_2 = 0x660,
|
||||
MAC_ADDR_1 = 0x670,
|
||||
MAC_ADDR_0 = 0x680,
|
||||
RX_FRM_CNT = 0x690, // Receive Frame Counter
|
||||
RX_LE_CNT = 0x6A0, // Length Error Counter
|
||||
RX_AE_CNT = 0x6B0, // Alignment Error Counter
|
||||
RX_FE_CNT = 0x6C0, // FCS Error Counter
|
||||
RX_CVE_CNT = 0x6E0, // Code Violation Error Counter
|
||||
HASH_TAB_3 = 0x700,
|
||||
HASH_TAB_2 = 0x710,
|
||||
HASH_TAB_1 = 0x720,
|
||||
HASH_TAB_0 = 0x730,
|
||||
};
|
||||
|
||||
/* MIF_CSR bit definitions. */
|
||||
enum {
|
||||
Mif_Clock = 1 << 0,
|
||||
Mif_Data_Out = 1 << 1,
|
||||
Mif_Data_Out_En = 1 << 2,
|
||||
Mif_Data_In = 1 << 3
|
||||
};
|
||||
|
||||
/* SROM_CSR bit definitions. */
|
||||
enum {
|
||||
Srom_Chip_Select = 1 << 0,
|
||||
Srom_Clock = 1 << 1,
|
||||
Srom_Data_In = 1 << 2,
|
||||
Srom_Data_Out = 1 << 3,
|
||||
};
|
||||
|
||||
/* Serial EEPROM states (see ST93C46 datasheet). */
|
||||
enum {
|
||||
Srom_Start,
|
||||
Srom_Opcode,
|
||||
Srom_Address,
|
||||
Srom_Read_Data,
|
||||
};
|
||||
|
||||
/* MII frame states. */
|
||||
enum MII_FRAME_SM {
|
||||
Preamble,
|
||||
Start,
|
||||
Opcode,
|
||||
Phy_Address,
|
||||
Reg_Address,
|
||||
Turnaround,
|
||||
Read_Data,
|
||||
Write_Data,
|
||||
Stop
|
||||
};
|
||||
|
||||
/* PHY control/status registers. */
|
||||
enum {
|
||||
PHY_BMCR = 0,
|
||||
PHY_BMSR = 1,
|
||||
PHY_ID1 = 2,
|
||||
PHY_ID2 = 3,
|
||||
PHY_ANAR = 4,
|
||||
};
|
||||
|
||||
class BigMac : public HWComponent {
|
||||
public:
|
||||
BigMac(uint8_t id);
|
||||
~BigMac() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_heathrow() {
|
||||
return std::unique_ptr<BigMac>(new BigMac(EthernetCellId::Heathrow));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_paddington() {
|
||||
return std::unique_ptr<BigMac>(new BigMac(EthernetCellId::Paddington));
|
||||
}
|
||||
|
||||
// BigMac register accessors
|
||||
uint16_t read(uint16_t reg_offset);
|
||||
void write(uint16_t reg_offset, uint16_t value);
|
||||
|
||||
protected:
|
||||
void chip_reset();
|
||||
|
||||
// MII methods
|
||||
bool mii_rcv_value(uint16_t& var, uint8_t num_bits, uint8_t next_bit);
|
||||
void mii_rcv_bit();
|
||||
void mii_xmit_bit(const uint8_t bit_val);
|
||||
void mii_reset();
|
||||
|
||||
// PHY control/status methods
|
||||
void phy_reset();
|
||||
uint16_t phy_reg_read(uint8_t reg_num);
|
||||
void phy_reg_write(uint8_t reg_num, uint16_t value);
|
||||
|
||||
// MAC Serial EEPROM methods
|
||||
void srom_reset();
|
||||
bool srom_rcv_value(uint16_t& var, uint8_t num_bits, uint8_t next_bit);
|
||||
void srom_xmit_bit(const uint8_t bit_val);
|
||||
|
||||
private:
|
||||
uint8_t chip_id; // BigMac Chip ID
|
||||
|
||||
// BigMac state
|
||||
uint16_t tx_reset = 0; // self-clearing one-bit register
|
||||
uint16_t tx_if_ctrl = 0;
|
||||
uint16_t rng_seed;
|
||||
uint16_t norm_coll_cnt = 0;
|
||||
uint16_t net_coll_cnt = 0;
|
||||
uint16_t excs_coll_cnt = 0;
|
||||
uint16_t late_coll_cnt = 0;
|
||||
uint16_t rcv_frame_cnt = 0;
|
||||
uint8_t len_err_cnt = 0;
|
||||
uint8_t align_err_cnt = 0;
|
||||
uint8_t fcs_err_cnt = 0;
|
||||
uint8_t cv_err_cnt = 0;
|
||||
uint8_t peak_attempts = 0;
|
||||
uint8_t tx_fifo_tresh = 0;
|
||||
bool tx_fifo_enable = false;
|
||||
bool rx_fifo_enable = false;
|
||||
uint16_t tx_fifo_size = 0;
|
||||
uint16_t rx_fifo_size = 0;
|
||||
uint16_t hash_table[4] = {};
|
||||
uint16_t mac_addr_flt[3] = {};
|
||||
uint16_t tx_config = 0;
|
||||
uint16_t rx_config = 0;
|
||||
|
||||
// Interrupt state
|
||||
uint16_t event_mask = 0xFFFFU; // inverted mask: 0 - enabled, 1 - disabled
|
||||
uint16_t stat = 0;
|
||||
|
||||
// MII state
|
||||
uint8_t mif_csr_old = 0;
|
||||
uint8_t mii_bit_counter = 0;
|
||||
uint16_t mii_start = 0;
|
||||
uint16_t mii_stop = 0;
|
||||
uint16_t mii_opcode = 0;
|
||||
uint16_t mii_phy_address = 0;
|
||||
uint16_t mii_reg_address = 0;
|
||||
uint16_t mii_turnaround = 0;
|
||||
uint16_t mii_data = 0;
|
||||
uint8_t mii_in_bit = 1;
|
||||
MII_FRAME_SM mii_state = MII_FRAME_SM::Preamble;
|
||||
|
||||
// PHY state
|
||||
uint32_t phy_oui;
|
||||
uint8_t phy_model;
|
||||
uint8_t phy_rev;
|
||||
uint16_t phy_bmcr;
|
||||
uint16_t phy_anar;
|
||||
|
||||
// MAC SROM state
|
||||
uint8_t srom_csr_old = 0;
|
||||
uint8_t srom_bit_counter = 0;
|
||||
uint16_t srom_opcode = 0;
|
||||
uint16_t srom_address = 0;
|
||||
uint8_t srom_in_bit = 0;
|
||||
uint8_t srom_state = Srom_Start;
|
||||
uint16_t srom_data[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0xDEAD, 0xBEEF, 0xBABE}; // bogus MAC!!!
|
||||
};
|
||||
|
||||
#endif // BIG_MAC_H
|
||||
+138
-47
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,7 +47,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
AMIC::AMIC() : MMIODevice()
|
||||
{
|
||||
this->name = "Apple Memory-mapped I/O Controller";
|
||||
this->set_name("Apple Memory-mapped I/O Controller");
|
||||
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
@@ -55,6 +55,13 @@ AMIC::AMIC() : MMIODevice()
|
||||
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
|
||||
this->scsi_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
|
||||
this->scsi->set_dma_channel(this->scsi_dma.get());
|
||||
this->scsi->set_drq_callback([this](const uint8_t drq_state) {
|
||||
if (drq_state & 1)
|
||||
via2_ifr |= VIA2_INT_SCSI_DRQ;
|
||||
else
|
||||
via2_ifr &= ~VIA2_INT_SCSI_DRQ;
|
||||
this->update_via2_irq();
|
||||
});
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
@@ -67,12 +74,14 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
// initialize sound HW
|
||||
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
|
||||
this->snd_out_dma->init_interrupts(this, 2 << 8);
|
||||
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());
|
||||
this->def_vid->init_interrupts(this, SLOT_INT_VBL << 16);
|
||||
|
||||
// initialize floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
@@ -152,9 +161,13 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
switch(offset) {
|
||||
case AMICReg::Ariel_Config:
|
||||
return this->def_vid->get_vdac_config();
|
||||
case AMICReg::VIA2_Slot_IFR:
|
||||
return this->via2_slot_ifr;
|
||||
case AMICReg::VIA2_IFR:
|
||||
case AMICReg::VIA2_IFR_RBV:
|
||||
return this->via2_ifr;
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
return this->via2_slot_ier;
|
||||
case AMICReg::VIA2_IER:
|
||||
case AMICReg::VIA2_IER_RBV:
|
||||
return this->via2_ier;
|
||||
@@ -164,6 +177,10 @@ uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
return this->mon_id;
|
||||
case AMICReg::Int_Ctrl:
|
||||
return (this->int_ctrl & 0xC0) | (this->dev_irq_lines & 0x3F);
|
||||
case AMICReg::DMA_IFR_0:
|
||||
return this->dma_ifr0;
|
||||
case AMICReg::DMA_IFR_1:
|
||||
return this->dma_ifr1;
|
||||
case AMICReg::Diag_Reg:
|
||||
return 0xFE | this->emmo_pin;
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
@@ -203,7 +220,10 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
this->mace->write((offset >> 4) & 0x1F, value);
|
||||
return;
|
||||
case 0x10:
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
if (offset & 0x100)
|
||||
this->scsi->pseudo_dma_write(value);
|
||||
else
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
return;
|
||||
case 0x14: // Sound registers
|
||||
switch(offset) {
|
||||
@@ -230,14 +250,14 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
LOG_F(9, "AMIC Sound Out Ctrl updated, val=%x", value);
|
||||
if ((value & 1) != (this->snd_out_ctrl & 1)) {
|
||||
if (value & 1) {
|
||||
LOG_F(9, "AMIC Sound Out DMA enabled!");
|
||||
LOG_F(INFO, "AMIC Sound Out DMA enabled!");
|
||||
this->snd_out_dma->init(this->dma_base & ~0x3FFFF,
|
||||
this->snd_buf_size);
|
||||
this->snd_out_dma->enable();
|
||||
this->awacs->set_sample_rate((this->snd_out_ctrl >> 1) & 3);
|
||||
this->awacs->dma_out_start();
|
||||
} else {
|
||||
LOG_F(9, "AMIC Sound Out DMA disabled!");
|
||||
LOG_F(INFO, "AMIC Sound Out DMA disabled!");
|
||||
this->snd_out_dma->disable();
|
||||
}
|
||||
}
|
||||
@@ -257,21 +277,35 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::VIA2_Slot_IFR:
|
||||
if (value & SLOT_INT_VBL) {
|
||||
// clear pending VBL int
|
||||
this->ack_slot_int(SLOT_INT_VBL, 0);
|
||||
}
|
||||
break;
|
||||
case AMICReg::VIA2_IFR:
|
||||
// for each "1" in value clear the corresponding IRQ bit
|
||||
// TODO: is bit 7 read only?
|
||||
// TODO: update interrupts?
|
||||
this->via2_ifr &= ~(value & 0x7F);
|
||||
// if bit 7 is set, clear the corresponding IRQ bit for each "1" in value
|
||||
if (value & 0x80) {
|
||||
this->via2_ifr &= ~(value & 0x7F);
|
||||
this->update_via2_irq();
|
||||
} else { // writing any value to VIA2_IFR with bit 7 cleared has no effect
|
||||
LOG_F(WARNING, "%s: bit 7 of VIA2_IFR is cleared!", this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
if (value & 0x80)
|
||||
this->via2_slot_ier |= value & 0x7F;
|
||||
else
|
||||
this->via2_slot_ier &= ~value;
|
||||
break;
|
||||
case AMICReg::VIA2_IER:
|
||||
case AMICReg::VIA2_IER_RBV:
|
||||
if (value & 0x80) {
|
||||
this->via2_ier |= value & 0x7F;
|
||||
} else {
|
||||
this->via2_ier &= ~value;
|
||||
}
|
||||
this->update_via2_irq();
|
||||
break;
|
||||
case AMICReg::Ariel_Clut_Index:
|
||||
this->def_vid->set_clut_index(value);
|
||||
@@ -304,16 +338,16 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
break;
|
||||
case AMICReg::Int_Ctrl:
|
||||
// reset CPU interrupt bit if requested
|
||||
if (value & AMIC_INT_CLR) {
|
||||
if (this->int_ctrl & 0x80) {
|
||||
this->int_ctrl &= ~AMIC_INT_CLR;
|
||||
if (value & CPU_INT_CLEAR) {
|
||||
if (this->int_ctrl & CPU_INT_FLAG) {
|
||||
this->int_ctrl &= ~CPU_INT_FLAG;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "AMIC: CPU INT latch cleared");
|
||||
}
|
||||
}
|
||||
// keep interrupt mode bit
|
||||
// and discard read-only IQR state bits
|
||||
this->int_ctrl |= value & AMIC_INT_MODE;
|
||||
this->int_ctrl |= value & CPU_INT_MODE;
|
||||
break;
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
case AMICReg::DMA_Base_Addr_1:
|
||||
@@ -388,11 +422,13 @@ void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
uint32_t AMIC::register_dev_int(IntSrc src_id) {
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1;
|
||||
return CPU_INT_VIA1;
|
||||
case IntSrc::SCSI1:
|
||||
return 0x800;
|
||||
return VIA2_INT_SCSI_IRQ << 8;
|
||||
case IntSrc::SWIM3:
|
||||
return 0x2000;
|
||||
return VIA2_INT_SWIM3 << 8;
|
||||
case IntSrc::NMI:
|
||||
return CPU_INT_NMI;
|
||||
default:
|
||||
ABORT_F("AMIC: unknown interrupt source %d", src_id);
|
||||
}
|
||||
@@ -405,39 +441,63 @@ uint32_t AMIC::register_dma_int(IntSrc src_id) {
|
||||
}
|
||||
|
||||
void AMIC::ack_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
// dispatch AMIC interrupts from various sources
|
||||
// dispatch cascaded AMIC interrupts from various sources
|
||||
// irq_id format: 00DDCCBBAA where
|
||||
// - AA -> CPU interrupts
|
||||
// - BB -> pseudo VIA2 interrupts
|
||||
// - CC -> slot interrupts
|
||||
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 if (irq_id < 0x1000000) {
|
||||
this->ack_slot_int(irq_id >> 16, irq_line_state);
|
||||
} else {
|
||||
ABORT_F("AMIC: unknown interrupt source ID 0x%X", irq_id);
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::ack_slot_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
// CAUTION: reverse logic (0 - true, 1 - false) in the IFR register!
|
||||
if (irq_line_state) {
|
||||
this->via2_slot_ifr &= ~irq_id;
|
||||
} else {
|
||||
this->via2_slot_ifr |= irq_id;
|
||||
}
|
||||
uint8_t new_irq = !!(~this->via2_slot_ifr & this->via2_slot_ier & 0x7F);
|
||||
if (new_irq != this->via2_slot_irq) {
|
||||
this->via2_slot_irq = new_irq;
|
||||
this->ack_via2_int(VIA2_INT_ALL_SLOT, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::update_via2_irq() {
|
||||
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(CPU_INT_VIA2, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
this->update_via2_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?
|
||||
if (this->int_ctrl & CPU_INT_MODE) { // 68k interrupt emulation mode?
|
||||
if (irq_line_state) {
|
||||
this->dev_irq_lines |= irq_id;
|
||||
} else {
|
||||
this->dev_irq_lines &= ~irq_id;
|
||||
}
|
||||
if (!(this->int_ctrl & 0x80)) {
|
||||
this->int_ctrl |= 0x80; // set CPU interrupt bit
|
||||
if (!(this->int_ctrl & CPU_INT_FLAG)) {
|
||||
this->int_ctrl |= CPU_INT_FLAG;
|
||||
ppc_assert_int();
|
||||
LOG_F(5, "AMIC: CPU INT asserted, source: %d", irq_id);
|
||||
} else {
|
||||
@@ -445,12 +505,29 @@ void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
}
|
||||
|
||||
} else {
|
||||
ABORT_F("AMIC: interrupt mode 0 not implemented");
|
||||
ABORT_F("AMIC: native interrupt mode not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void AMIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
ABORT_F("AMIC: ack_dma_int() not implemented");
|
||||
if (irq_id >= 0x100) { // DMA Interrupt Flags 1
|
||||
irq_id = (irq_id >> 8) & 0xFFU;
|
||||
if (irq_line_state)
|
||||
this->dma_ifr1 |= irq_id;
|
||||
else
|
||||
this->dma_ifr1 &= ~irq_id;
|
||||
} else { // DMA Interrupt Flags 0
|
||||
irq_id &= 0xFFU;
|
||||
if (irq_line_state)
|
||||
this->dma_ifr0 |= irq_id;
|
||||
else
|
||||
this->dma_ifr0 &= ~irq_id;
|
||||
}
|
||||
uint8_t new_irq = (this->dma_ifr0 || this->dma_ifr1) ? 1 : 0;
|
||||
if (new_irq != this->dma_irq) {
|
||||
this->dma_irq = new_irq;
|
||||
this->ack_cpu_int(CPU_INT_ALL_DMA, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================ Sound DMA stuff ================================
|
||||
@@ -469,6 +546,7 @@ void AmicSndOutDma::init(uint32_t buf_base, uint32_t buf_samples)
|
||||
|
||||
this->snd_buf_num = 0;
|
||||
this->cur_buf_pos = 0;
|
||||
this->irq_level = 0;
|
||||
}
|
||||
|
||||
uint8_t AmicSndOutDma::read_stat()
|
||||
@@ -476,12 +554,25 @@ uint8_t AmicSndOutDma::read_stat()
|
||||
return this->dma_out_ctrl;
|
||||
}
|
||||
|
||||
void AmicSndOutDma::update_irq() {
|
||||
uint8_t new_level = !!((this->dma_out_ctrl >> 4) & this->dma_out_ctrl);
|
||||
if (new_level != this->irq_level) {
|
||||
this->irq_level = new_level;
|
||||
TimerManager::get_instance()->add_immediate_timer([this] {
|
||||
this->int_ctrl->ack_dma_int(this->irq_id, this->irq_level);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void AmicSndOutDma::write_dma_out_ctrl(uint8_t value)
|
||||
{
|
||||
// clear interrupt flags
|
||||
value &= ~PDM_DMA_INTS_MASK;
|
||||
this->dma_out_ctrl = value;
|
||||
LOG_F(9, "AMIC: Sound out DMA control set to 0x%X", value);
|
||||
if (value & PDM_DMA_INTS_MASK) {
|
||||
this->dma_out_ctrl &= ~(value & PDM_DMA_INTS_MASK);
|
||||
this->update_irq();
|
||||
}
|
||||
// enable sound output DMA interrupts
|
||||
this->dma_out_ctrl |= value & 0x0FU;
|
||||
}
|
||||
|
||||
DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
@@ -494,13 +585,15 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
if (!this->snd_buf_num) {
|
||||
// signal buffer 0 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF0;
|
||||
// TODO: generate IE0 interrupt if enabled
|
||||
} else {
|
||||
// signal buffer 1 drained
|
||||
this->dma_out_ctrl |= PDM_DMA_IF1;
|
||||
// TODO: generate IE1 interrupt if enabled
|
||||
}
|
||||
|
||||
// generate sound out DMA interrupt if (IF0 & IE0)
|
||||
// or (IF1 & IE1) or (ERR_IF & ERR_IE)
|
||||
this->update_irq();
|
||||
|
||||
// check DMA enable flag after buffer 1 was processed
|
||||
// if it's false stop delivering sound data
|
||||
// this will effectively stop audio playback
|
||||
@@ -516,9 +609,10 @@ DmaPullResult AmicSndOutDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
|
||||
uint32_t len = std::min((uint32_t)rem_len, req_len);
|
||||
|
||||
*p_data = mmu_get_dma_mem(
|
||||
MapDmaResult res = mmu_map_dma_mem(
|
||||
(this->snd_buf_num ? this->out_buf1 : this->out_buf0) + this->cur_buf_pos,
|
||||
len, nullptr);
|
||||
len, false);
|
||||
*p_data = res.host_va;
|
||||
this->cur_buf_pos += len;
|
||||
*avail_len = len;
|
||||
return DmaPullResult::MoreData;
|
||||
@@ -551,12 +645,11 @@ void AmicFloppyDma::write_ctrl(uint8_t value)
|
||||
|
||||
int AmicFloppyDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
bool is_writable;
|
||||
|
||||
len = std::min((int)this->byte_count, len);
|
||||
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len, &is_writable);
|
||||
if (!is_writable) {
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
uint8_t *p_data = res.host_va;
|
||||
if (!res.is_writable) {
|
||||
ABORT_F("AMIC: attempting DMA write to read-only memory");
|
||||
}
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
@@ -603,9 +696,8 @@ void AmicScsiDma::write_ctrl(uint8_t value)
|
||||
|
||||
int AmicScsiDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
bool is_writable;
|
||||
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len, &is_writable);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, len, false);
|
||||
uint8_t *p_data = res.host_va;
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += len;
|
||||
@@ -616,16 +708,15 @@ int AmicScsiDma::push_data(const char* src_ptr, int len)
|
||||
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
bool is_writable;
|
||||
|
||||
*p_data = mmu_get_dma_mem(this->addr_ptr, req_len, &is_writable);
|
||||
MapDmaResult res = mmu_map_dma_mem(this->addr_ptr, req_len, false);
|
||||
*p_data = res.host_va;
|
||||
this->addr_ptr += req_len;
|
||||
*avail_len = req_len;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
|
||||
static vector<string> Amic_Subdevices = {
|
||||
"Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
"Scsi0", "Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription Amic_Descriptor = {
|
||||
|
||||
+68
-16
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -39,8 +39,39 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#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
|
||||
|
||||
/** CPU interrupt register bits. */
|
||||
enum : uint8_t {
|
||||
CPU_INT_VIA1 = 1 << 0, // (R) VIA1 interrupts
|
||||
CPU_INT_VIA2 = 1 << 1, // (R) pseudo VIA2 interrupts
|
||||
CPU_INT_ESCC = 1 << 2, // (R) ESCC interrupt
|
||||
CPU_INT_ENET = 1 << 3, // (R) ethernet interrupt
|
||||
CPU_INT_ALL_DMA = 1 << 4, // (R) all DMA interrupts are signalled here
|
||||
CPU_INT_NMI = 1 << 5, // (R) non-maskable interrupt
|
||||
CPU_INT_MODE = 1 << 6, // (R/W) interrupt mode: 0 - native, 1 - 68k-style
|
||||
CPU_INT_CLEAR = 1 << 7, // (R/W) writing "1" clears CPU interrupt flag
|
||||
CPU_INT_FLAG = 1 << 7 // special constant for manipulating CPU int flag
|
||||
};
|
||||
|
||||
/** Pseudo VIA2 interrupt flag/enable register bits. */
|
||||
enum : uint8_t {
|
||||
VIA2_INT_SCSI_DRQ = 1 << 0, // (R) SCSI DRQ interrupt
|
||||
VIA2_INT_ALL_SLOT = 1 << 1, // (R) all slot interrupts are signalled here
|
||||
VIA2_INT_SCSI_IRQ = 1 << 3, // (R) SCSI IRQ interrupt
|
||||
VIA2_INT_SOUND = 1 << 4, // (R) sound chip (AWACS) interrupt
|
||||
VIA2_INT_SWIM3 = 1 << 5, // (R) floppy disk controller interrupt
|
||||
VIA2_INT_IRQ = 1 << 7, // (R) all VIA2 interrupts are signalled here
|
||||
};
|
||||
|
||||
/** Slot interrupt flag/enable register bits. */
|
||||
enum : uint8_t {
|
||||
SLOT_INT_SLOT_0 = 1 << 2, // (R) ColdFusion Nubus slot 0 interrupt
|
||||
SLOT_INT_SLOT_1 = 1 << 3, // (R) ColdFusion Nubus slot 1 interrupt
|
||||
SLOT_INT_SLOT_2 = 1 << 4, // (R) ColdFusion Nubus slot 2 interrupt
|
||||
SLOT_INT_SLOT_VDS = 1 << 5, // (R) ColdFusion video direct slot interrupt
|
||||
SLOT_INT_SLOT_PDS = 1 << 5, // (R) PDM processor direct slot interrupt
|
||||
SLOT_INT_VBL = 1 << 6, // (R) built-in video VBL interrupt
|
||||
};
|
||||
|
||||
/** AMIC sound buffers are located at fixed offsets from DMA base. */
|
||||
#define AMIC_SND_BUF0_OFFS 0x10000
|
||||
@@ -65,20 +96,30 @@ public:
|
||||
void enable() { this->enabled = true; };
|
||||
void disable() { this->enabled = false; };
|
||||
uint8_t read_stat();
|
||||
void update_irq();
|
||||
void write_dma_out_ctrl(uint8_t value);
|
||||
uint32_t get_cur_buf_pos() { return this->cur_buf_pos; };
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
uint8_t dma_out_ctrl;
|
||||
void init_interrupts(InterruptCtrl *int_ctrl, uint32_t irq_id) {
|
||||
this->int_ctrl = int_ctrl;
|
||||
this->irq_id = irq_id;
|
||||
};
|
||||
|
||||
uint32_t out_buf0;
|
||||
uint32_t out_buf1;
|
||||
uint32_t out_buf_len;
|
||||
uint32_t snd_buf_num;
|
||||
uint32_t cur_buf_pos;
|
||||
private:
|
||||
bool enabled = false;
|
||||
uint8_t dma_out_ctrl;
|
||||
|
||||
uint32_t out_buf0;
|
||||
uint32_t out_buf1;
|
||||
uint32_t out_buf_len;
|
||||
uint32_t snd_buf_num;
|
||||
uint32_t cur_buf_pos;
|
||||
|
||||
InterruptCtrl *int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq_level = 0;
|
||||
};
|
||||
|
||||
/** AMIC-specific floppy DMA implementation. */
|
||||
@@ -158,6 +199,7 @@ enum AMICReg : uint32_t {
|
||||
Ariel_Config = 0x24002,
|
||||
|
||||
// VIA2 registers
|
||||
VIA2_Slot_IFR = 0x26002,
|
||||
VIA2_IFR = 0x26003,
|
||||
VIA2_Slot_IER = 0x26012,
|
||||
VIA2_IER = 0x26013,
|
||||
@@ -171,9 +213,9 @@ enum AMICReg : uint32_t {
|
||||
|
||||
// Interrupt registers
|
||||
Int_Ctrl = 0x2A000,
|
||||
DMA_Int_0 = 0x2A008,
|
||||
DMA_IFR_0 = 0x2A008,
|
||||
Bus_Err_Int_0 = 0x2A009,
|
||||
DMA_Int_1 = 0x2A00A,
|
||||
DMA_IFR_1 = 0x2A00A,
|
||||
Bus_Err_Int_1 = 0x2A00B,
|
||||
|
||||
// Undocumented diagnostics register
|
||||
@@ -233,8 +275,10 @@ public:
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
void ack_slot_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
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 update_via2_irq();
|
||||
|
||||
private:
|
||||
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
|
||||
@@ -259,10 +303,18 @@ private:
|
||||
uint8_t int_ctrl = 0;
|
||||
uint8_t dev_irq_lines = 0; // state of the IRQ lines
|
||||
|
||||
// DMA IRQ flag registers
|
||||
uint8_t dma_ifr0 = 0;
|
||||
uint8_t dma_ifr1 = 0;
|
||||
uint8_t dma_irq = 0;
|
||||
|
||||
// pseudo VIA2 state
|
||||
uint8_t via2_ier = 0;
|
||||
uint8_t via2_ifr = 0;
|
||||
uint8_t via2_irq = 0;
|
||||
uint8_t via2_ier = 0;
|
||||
uint8_t via2_ifr = 0;
|
||||
uint8_t via2_irq = 0;
|
||||
uint8_t via2_slot_ier = 0; // normal logic
|
||||
uint8_t via2_slot_ifr = 0x7F; // reverse logic
|
||||
uint8_t via2_slot_irq = 0; // normal logic
|
||||
|
||||
uint32_t pseudo_vbl_tid; // ID for the pseudo-VBL timer
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
}
|
||||
|
||||
static const vector<string> GCSubdevices = {
|
||||
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "Mace", "Swim3"
|
||||
"NVRAM", "ViaCuda", "Escc", "Scsi0", "Sc53C94", "Mace", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription GC_Descriptor = {
|
||||
|
||||
+149
-24
@@ -77,8 +77,9 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
std::bind(&AwacsScreamer::dma_out_stop, this->snd_codec)
|
||||
);
|
||||
|
||||
// connect SCSI HW
|
||||
// connect SCSI HW and the corresponding DMA channel
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("Mesh"));
|
||||
this->scsi_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
|
||||
// connect IDE HW
|
||||
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
|
||||
@@ -93,6 +94,11 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
this->floppy_dma->register_dma_int(this, 2);
|
||||
|
||||
// connect Ethernet HW
|
||||
this->bmac = dynamic_cast<BigMac*>(gMachineObj->get_comp_by_type(HWCompType::ETHER_MAC));
|
||||
this->enet_xmit_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->enet_rcv_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
@@ -114,9 +120,15 @@ void HeathrowIC::notify_bar_change(int bar_num)
|
||||
|
||||
uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 1:
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
return this->scsi_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case 8:
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
return this->enet_xmit_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
return this->enet_rcv_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
||||
@@ -127,10 +139,19 @@ uint32_t HeathrowIC::dma_read(uint32_t offset, int size) {
|
||||
|
||||
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset >> 8) {
|
||||
case 1:
|
||||
case MIO_OHARE_DMA_MESH:
|
||||
this->scsi_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 8:
|
||||
case MIO_OHARE_DMA_ETH_XMIT:
|
||||
this->enet_xmit_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_ETH_RCV:
|
||||
this->enet_rcv_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_OHARE_DMA_AUDIO_OUT:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
@@ -153,9 +174,12 @@ uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
case 8:
|
||||
res = dma_read(offset - 0x8000, size);
|
||||
break;
|
||||
case 0x10:
|
||||
case 0x10: // SCSI
|
||||
res = this->mesh->read((offset >> 4) & 0xF);
|
||||
break;
|
||||
case 0x11: // Ethernet
|
||||
res = BYTESWAP_SIZED(this->bmac->read(offset & 0xFFFU), size);
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
@@ -201,9 +225,12 @@ void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int
|
||||
case 8:
|
||||
dma_write(offset - 0x8000, value, size);
|
||||
break;
|
||||
case 0x10:
|
||||
case 0x10: // SCSI
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x11: // Ethernet
|
||||
this->bmac->write(offset & 0xFFFU, BYTESWAP_SIZED(value, size));
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
@@ -288,12 +315,8 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
|
||||
break;
|
||||
case MIO_INT_CLEAR2:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events2 = 0;
|
||||
clear_cpu_int();
|
||||
} else {
|
||||
this->int_events2 &= BYTESWAP_32(value);
|
||||
}
|
||||
this->int_events2 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
|
||||
clear_cpu_int();
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask1 = BYTESWAP_32(value);
|
||||
@@ -301,12 +324,13 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) && (value & MACIO_INT_CLR)) {
|
||||
this->int_events1 = 0;
|
||||
clear_cpu_int();
|
||||
this->int_events2 = 0;
|
||||
} else {
|
||||
this->int_events1 &= BYTESWAP_32(value);
|
||||
this->int_events1 &= ~(BYTESWAP_32(value) & 0x7FFFFFFFUL);
|
||||
}
|
||||
clear_cpu_int();
|
||||
break;
|
||||
case MIO_OHARE_ID:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x", value, offset, ppc_state.pc);
|
||||
@@ -340,10 +364,14 @@ void HeathrowIC::feature_control(const uint32_t value)
|
||||
uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 7;
|
||||
case IntSrc::SCSI1:
|
||||
return 1 << 1;
|
||||
case IntSrc::IDE0:
|
||||
return 1 << 2;
|
||||
case IntSrc::IDE1:
|
||||
return 1 << 3;
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 7;
|
||||
case IntSrc::SWIM3:
|
||||
return 1 << 8;
|
||||
default:
|
||||
@@ -359,9 +387,50 @@ uint32_t HeathrowIC::register_dma_int(IntSrc src_id)
|
||||
|
||||
void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
#if 1
|
||||
if (irq_id >= (1 << 20)) { // does this irq_id belong to the second set?
|
||||
irq_id >>= (20 - 10); // adjust for non-DMA interrupt bits of the 2nd set
|
||||
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events2 on all transitions
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels2 & irq_id))) {
|
||||
this->int_events2 |= irq_id;
|
||||
} else {
|
||||
this->int_events2 &= ~irq_id;
|
||||
}
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels2 |= irq_id;
|
||||
} else {
|
||||
this->int_levels2 &= ~irq_id;
|
||||
}
|
||||
} else {
|
||||
irq_id <<= 11; // adjust for non-DMA interrupt bits of the first set
|
||||
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events1 on all transitions
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels1 & irq_id))) {
|
||||
this->int_events1 |= irq_id;
|
||||
} else {
|
||||
this->int_events1 &= ~irq_id;
|
||||
}
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels1 |= irq_id;
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
if (irq_id > 0x200000) {
|
||||
irq_id >>= 21;
|
||||
if (irq_id >= (1 << 20)) { // irq_id in the range of int_events2?
|
||||
irq_id >>= (20 - 10); // adjust for non-DMA interrupt bits of int_events2
|
||||
this->int_events2 |= irq_id; // signal IRQ line change
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
@@ -383,14 +452,40 @@ void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
} else {
|
||||
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
|
||||
LOG_F(WARNING, "%s: native interrupt mode not implemented", this->name.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_events1 |= irq_id; // signal IRQ line change
|
||||
#if 1
|
||||
if (irq_id >= (1 << 10)) { // does this irq_id belong to the second set?
|
||||
irq_id >>= 10; // adjust for DMA interrupt bits of the 2nd set
|
||||
// native mode: set IRQ bits in int_events2 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events2 on all transitions
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels2 & irq_id))) {
|
||||
this->int_events2 |= irq_id;
|
||||
} else {
|
||||
this->int_events2 &= ~irq_id;
|
||||
}
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels2 |= irq_id;
|
||||
} else {
|
||||
this->int_levels2 &= ~irq_id;
|
||||
}
|
||||
} else {
|
||||
// native mode: set IRQ bits in int_events1 on a 0-to-1 transition
|
||||
// emulated mode: set IRQ bits in int_events1 on all transitions
|
||||
if ((this->int_mask1 & MACIO_INT_MODE) ||
|
||||
(irq_line_state && !(this->int_levels1 & irq_id))) {
|
||||
this->int_events1 |= irq_id;
|
||||
} else {
|
||||
this->int_events1 &= ~irq_id;
|
||||
}
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
@@ -398,10 +493,38 @@ void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
|
||||
this->signal_cpu_int();
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
if (irq_id >= (1 << 10)) { // irq_id in the range of int_events2?
|
||||
irq_id >>= 10; // adjust for DMA interrupt bits of int_events2
|
||||
this->int_events2 |= irq_id; // signal IRQ line change
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels2 |= irq_id;
|
||||
} else {
|
||||
this->int_levels2 &= ~irq_id;
|
||||
}
|
||||
} else {
|
||||
this->int_events1 |= irq_id; // signal IRQ line change
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels1 |= irq_id;
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
this->signal_cpu_int();
|
||||
} else {
|
||||
ABORT_F("%s: native interrupt mode not implemented", this->name.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void HeathrowIC::signal_cpu_int() {
|
||||
@@ -425,7 +548,9 @@ void HeathrowIC::clear_cpu_int()
|
||||
}
|
||||
|
||||
static const vector<string> Heathrow_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3", "Ide0", "Ide1"};
|
||||
"NVRAM", "ViaCuda", "Scsi0", "Mesh", "Escc", "Swim3", "Ide0", "Ide1",
|
||||
"BigMacHeathrow"
|
||||
};
|
||||
|
||||
static const DeviceDescription Heathrow_Descriptor = {
|
||||
HeathrowIC::create, Heathrow_Subdevices, {}
|
||||
|
||||
+23
-2
@@ -40,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
DMA space. Access to emulated legacy devices is accomplished by reading from/
|
||||
writing to MIO's PCI address space at predefined offsets.
|
||||
|
||||
MIO includes a DMA controller that offers 15 DMA channels implementing
|
||||
MIO includes a DMA controller that offers up to 12 DMA channels implementing
|
||||
Apple's own DMA protocol called descriptor-based DMA (DBDMA).
|
||||
|
||||
Official documentation (that is somewhat incomplete and erroneous) can be
|
||||
@@ -60,6 +60,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/bigmac.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
@@ -218,6 +219,22 @@ enum {
|
||||
MIO_OHARE_FEAT_CTRL = 0x38, // feature control register
|
||||
};
|
||||
|
||||
/** O'Hare/Heathrow DBDMA channels. */
|
||||
enum : uint8_t {
|
||||
MIO_OHARE_DMA_MESH = 0,
|
||||
MIO_OHARE_DMA_FLOPPY = 1,
|
||||
MIO_OHARE_DMA_ETH_XMIT = 2,
|
||||
MIO_OHARE_DMA_ETH_RCV = 3,
|
||||
MIO_OHARE_DMA_ESSC_A_XMIT = 4,
|
||||
MIO_OHARE_DMA_ESSC_A_RCV = 5,
|
||||
MIO_OHARE_DMA_ESSC_B_XMIT = 6,
|
||||
MIO_OHARE_DMA_ESSC_B_RCV = 7,
|
||||
MIO_OHARE_DMA_AUDIO_OUT = 8,
|
||||
MIO_OHARE_DMA_AUDIO_IN = 9,
|
||||
MIO_OHARE_DMA_IDE0 = 0xB,
|
||||
MIO_OHARE_DMA_IDE1 = 0xC
|
||||
};
|
||||
|
||||
class HeathrowIC : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
HeathrowIC();
|
||||
@@ -278,10 +295,14 @@ private:
|
||||
IdeChannel* ide_0; // Internal ATA
|
||||
IdeChannel* ide_1; // Media Bay ATA
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
BigMac* bmac; // Ethernet MAC cell
|
||||
|
||||
// DMA channels
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> scsi_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> enet_xmit_dma;
|
||||
std::unique_ptr<DMAChannel> enet_rcv_dma;
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
#endif /* MACIO_H */
|
||||
@@ -226,7 +226,7 @@ void OHare::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
}
|
||||
|
||||
static const vector<string> OHare_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3"
|
||||
"NVRAM", "ViaCuda", "Scsi0", "Mesh", "Escc", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription OHare_Descriptor = {
|
||||
|
||||
@@ -107,9 +107,8 @@ AwacDevicePdm::AwacDevicePdm() : AwacsBase("AWAC-PDM")
|
||||
|
||||
uint32_t AwacDevicePdm::read_stat()
|
||||
{
|
||||
LOG_F(INFO, "%s: status requested!", this->name.c_str());
|
||||
// TODO: return valid status including manufacturer & device IDs
|
||||
return 0;
|
||||
// TODO: implement all other status bits
|
||||
return (AWAC_REV_AWACS << 12) | (AWAC_MAKER_CRYSTAL << 8);
|
||||
}
|
||||
|
||||
void AwacDevicePdm::write_ctrl(uint32_t addr, uint16_t value)
|
||||
|
||||
@@ -148,8 +148,9 @@ public:
|
||||
virtual void snd_ctrl_write(uint32_t offset, uint32_t value, int size) = 0;
|
||||
};
|
||||
|
||||
/** AWACs Screamer manufacturer and revision. */
|
||||
/** AWACs manufacturers and revisions. */
|
||||
#define AWAC_MAKER_CRYSTAL 1
|
||||
#define AWAC_REV_AWACS 2
|
||||
#define AWAC_REV_SCREAMER 3
|
||||
|
||||
/** Screamer sound codec. */
|
||||
|
||||
@@ -117,6 +117,8 @@ void SoundServer::shutdown()
|
||||
case SND_STREAM_OPENED:
|
||||
close_out_stream();
|
||||
/* fall through */
|
||||
case SND_STREAM_CLOSED:
|
||||
/* fall through */
|
||||
case SND_SERVER_UP:
|
||||
/* fall through */
|
||||
case SND_API_READY:
|
||||
@@ -219,5 +221,6 @@ void SoundServer::close_out_stream()
|
||||
{
|
||||
cubeb_stream_stop(this->out_stream);
|
||||
cubeb_stream_destroy(this->out_stream);
|
||||
this->status = SND_STREAM_CLOSED;
|
||||
LOG_F(9, "Sound output stream closed.");
|
||||
}
|
||||
@@ -41,7 +41,8 @@ enum {
|
||||
SND_SERVER_DOWN = 0,
|
||||
SND_API_READY,
|
||||
SND_SERVER_UP,
|
||||
SND_STREAM_OPENED
|
||||
SND_STREAM_OPENED,
|
||||
SND_STREAM_CLOSED
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Block storage device implementation. */
|
||||
|
||||
#include <devices/storage/blockstoragedevice.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size) {
|
||||
this->block_size = block_size;
|
||||
this->cache_size = cache_blocks * this->block_size;
|
||||
|
||||
// allocate device cache and fill it with zeroes
|
||||
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
|
||||
}
|
||||
|
||||
BlockStorageDevice::~BlockStorageDevice() {
|
||||
if (this->img_file)
|
||||
this->img_file.close();
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_host_file(std::string file_path) {
|
||||
this->is_ready = false;
|
||||
|
||||
this->img_file.open(file_path, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(file_path.c_str(), &stat_buf);
|
||||
if (rc)
|
||||
return -1;
|
||||
|
||||
this->size_bytes = stat_buf.st_size;
|
||||
this->size_blocks = this->size_bytes / this->block_size;
|
||||
this->set_fpos(0);
|
||||
|
||||
this->is_ready = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_fpos(const uint32_t lba) {
|
||||
this->cur_fpos = lba * this->block_size;
|
||||
this->img_file.seekg(this->cur_fpos, this->img_file.beg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::read_begin(int nblocks, uint32_t max_len) {
|
||||
uint32_t xfer_len = std::min(this->cache_size, max_len);
|
||||
uint32_t read_size = nblocks * this->block_size;
|
||||
if (read_size > xfer_len) {
|
||||
this->remain_size = read_size - xfer_len;
|
||||
read_size = xfer_len;
|
||||
} else {
|
||||
this->remain_size = 0;
|
||||
}
|
||||
|
||||
this->img_file.read(this->data_cache.get(), read_size);
|
||||
this->cur_fpos += read_size;
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::read_more() {
|
||||
uint32_t read_size;
|
||||
|
||||
if (!this->remain_size)
|
||||
return 0;
|
||||
|
||||
if (this->remain_size > this->cache_size) {
|
||||
this->remain_size -= this->cache_size;
|
||||
read_size = this->cache_size;
|
||||
} else {
|
||||
read_size = this->remain_size;
|
||||
this->remain_size = 0;
|
||||
}
|
||||
|
||||
this->img_file.read(this->data_cache.get(), read_size);
|
||||
this->cur_fpos += read_size;
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::write_begin(char *buf, int nblocks) {
|
||||
if (!this->is_writeable)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Block storage device definitions. */
|
||||
|
||||
#ifndef BLOCK_STORAGE_DEVICE_H
|
||||
#define BLOCK_STORAGE_DEVICE_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class BlockStorageDevice {
|
||||
public:
|
||||
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512);
|
||||
~BlockStorageDevice();
|
||||
|
||||
void set_block_size(const int blk_size) { this->block_size = blk_size; };
|
||||
|
||||
int set_host_file(std::string file_path);
|
||||
|
||||
int set_fpos(const uint32_t lba);
|
||||
int read_begin(int nblocks, uint32_t max_len);
|
||||
int data_left() { return this->remain_size; };
|
||||
int read_more();
|
||||
int write_begin(char *buf, int nblocks);
|
||||
|
||||
protected:
|
||||
std::fstream img_file = {};
|
||||
uint64_t size_bytes = 0; // image file size in bytes
|
||||
uint64_t size_blocks = 0; // image file size in blocks
|
||||
uint64_t cur_fpos = 0; // current image file pointer position
|
||||
uint32_t block_size = 512; // physical block size
|
||||
uint32_t cache_size = 0; // cache size
|
||||
uint32_t remain_size = 0;
|
||||
bool is_writeable = false;
|
||||
bool is_ready = false; // ready for operation
|
||||
|
||||
std::unique_ptr<char[]> data_cache;
|
||||
};
|
||||
|
||||
#endif // BLOCK_STORAGE_DEVICE_H
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Virtual CD-ROM device implementation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h> // reuse SCSI definitions
|
||||
#include <devices/storage/cdromdrive.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
CdromDrive::CdromDrive() : BlockStorageDevice(31, 2048) {
|
||||
this->is_writeable = false;
|
||||
}
|
||||
|
||||
void CdromDrive::insert_image(std::string filename) {
|
||||
this->set_host_file(filename);
|
||||
|
||||
// create single track descriptor
|
||||
this->tracks[0] = {1, /*.trk_num*/ 0x14, /*.adr_ctrl*/ 0 /*.start_lba*/};
|
||||
this->num_tracks = 1;
|
||||
|
||||
// create Lead-out descriptor containing all data
|
||||
this->tracks[1] = {LEAD_OUT_TRK_NUM, /*.trk_num*/ 0x14, /*.adr_ctrl*/
|
||||
static_cast<uint32_t>(this->size_blocks + 1) /*.start_lba*/};
|
||||
}
|
||||
|
||||
static char cdrom_vendor_dingus_id[] = "DINGUS ";
|
||||
static char cdrom_product_id[] = "DINGUS CD-ROM ";
|
||||
static char cdrom_revision_id[] = "1.0 ";
|
||||
|
||||
uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
uint8_t alloc_len = cmd_ptr[4];
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "CD-ROM: more than 36 bytes requested in INQUIRY");
|
||||
}
|
||||
|
||||
data_ptr[0] = 5; // device type: CD-ROM
|
||||
data_ptr[1] = 0x80; // removable media
|
||||
data_ptr[2] = 2; // ANSI version: SCSI-2
|
||||
data_ptr[3] = 0x21; // ATAPI Version + response data format
|
||||
data_ptr[4] = 0x1F; // additional length
|
||||
data_ptr[5] = 0;
|
||||
data_ptr[6] = 0;
|
||||
data_ptr[7] = 0;
|
||||
std::memcpy(&data_ptr[8], cdrom_vendor_dingus_id, 8);
|
||||
std::memcpy(&data_ptr[16], cdrom_product_id, 16);
|
||||
std::memcpy(&data_ptr[32], cdrom_revision_id, 4);
|
||||
|
||||
return 36;
|
||||
}
|
||||
|
||||
uint32_t CdromDrive::mode_sense_ex(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
uint8_t *resp_ptr;
|
||||
|
||||
uint8_t page_code = cmd_ptr[2] & 0x3F;
|
||||
uint8_t alloc_len = READ_WORD_BE_U(&cmd_ptr[7]);
|
||||
|
||||
std::memset(data_ptr, 0, alloc_len);
|
||||
|
||||
data_ptr[0] = 0; // initial data size MSB
|
||||
data_ptr[1] = 6; // initial data size LSB
|
||||
data_ptr[2] = 1; // medium type: 120mm CD-ROM
|
||||
data_ptr[3] = 0; // device-specific parameter
|
||||
data_ptr[4] = 0;
|
||||
data_ptr[5] = 0;
|
||||
data_ptr[6] = 0; // block description length MSB
|
||||
data_ptr[7] = 0; // block description length LSB
|
||||
|
||||
resp_ptr = data_ptr + 8;
|
||||
|
||||
resp_ptr[0] = page_code;
|
||||
|
||||
switch (page_code) {
|
||||
case 0x01:
|
||||
resp_ptr[1] = 6; // data size
|
||||
std::memset(&resp_ptr[2], 0, 6);
|
||||
data_ptr[1] += 8; // adjust overall length
|
||||
break;
|
||||
case 0x2A:
|
||||
resp_ptr[1] = 18; // page data length
|
||||
std::memset(&resp_ptr[2], 0, 18);
|
||||
resp_ptr[2] = 0x03; // supports reading CD-R and CD-E
|
||||
resp_ptr[3] = 0x00; // doesn't support writing to CD-R and CD-E
|
||||
resp_ptr[6] = (1 << 5) | (1 << 3) | (1 << 0); // tray type + eject + lock support
|
||||
WRITE_WORD_BE_A(&resp_ptr[ 8], 706); // report 4x speed
|
||||
WRITE_WORD_BE_A(&resp_ptr[10], 2); // supports audio on/off only
|
||||
WRITE_WORD_BE_A(&resp_ptr[12], 512); // 512Kb cache
|
||||
WRITE_WORD_BE_A(&resp_ptr[14], 706); // report current speed (4x)
|
||||
data_ptr[1] += 20; // adjust overall length
|
||||
break;
|
||||
default:
|
||||
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return data_ptr[1] + 2; // return total response length
|
||||
}
|
||||
|
||||
uint32_t CdromDrive::request_sense(uint8_t *data_ptr, uint8_t sense_key,
|
||||
uint8_t asc, uint8_t ascq) {
|
||||
std::memset(data_ptr, 0, 18);
|
||||
|
||||
data_ptr[ 0] = 0x80 | 0x70; // valid + current error
|
||||
data_ptr[ 2] = sense_key;
|
||||
data_ptr[ 7] = 10; // additional sense length
|
||||
data_ptr[12] = asc;
|
||||
data_ptr[13] = ascq;
|
||||
|
||||
return 18;
|
||||
}
|
||||
|
||||
uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
|
||||
WRITE_DWORD_BE_A(data_ptr, this->size_blocks);
|
||||
WRITE_DWORD_BE_A(&data_ptr[4], this->block_size);
|
||||
return 8;
|
||||
}
|
||||
|
||||
AddrMsf CdromDrive::lba_to_msf(const int lba) {
|
||||
return {lba / 4500, /*.min*/ (lba / 75) % 60, /*.sec*/ lba % 75 /*.frm*/};
|
||||
}
|
||||
|
||||
uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
int tot_tracks, data_len;
|
||||
uint8_t start_track, session_num;
|
||||
uint8_t* out_ptr;
|
||||
uint16_t alloc_len = READ_WORD_BE_U(&cmd_ptr[7]);
|
||||
bool is_msf = !!(cmd_ptr[1] & 2);
|
||||
|
||||
// ATAPI specific handling of the format field
|
||||
uint8_t format = cmd_ptr[2] & 7;
|
||||
if (!format) {
|
||||
format = cmd_ptr[9] >> 6;
|
||||
}
|
||||
|
||||
if (!alloc_len)
|
||||
return 0;
|
||||
|
||||
switch(format) {
|
||||
case 0: // Formatted TOC
|
||||
start_track = cmd_ptr[6];
|
||||
if (!start_track) { // special case: track zero (lead-in) as starting track
|
||||
// return all tracks starting with track 1 plus lead-out
|
||||
start_track = 1;
|
||||
tot_tracks = this->num_tracks + 1;
|
||||
} else if (start_track == LEAD_OUT_TRK_NUM) {
|
||||
start_track = this->num_tracks + 1;
|
||||
tot_tracks = 1;
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "CDROM: invalid starting track %d in READ_TOC", start_track);
|
||||
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_ptr = data_ptr;
|
||||
data_len = (tot_tracks * 8) + 4;
|
||||
|
||||
// write TOC data header
|
||||
WRITE_WORD_BE_A(out_ptr, data_len - 2);
|
||||
out_ptr[2] = 1; // 1st track number
|
||||
out_ptr[3] = this->num_tracks; // last track number
|
||||
out_ptr += 4;
|
||||
|
||||
for (int tx = 0; tx < tot_tracks; tx++) {
|
||||
if ((out_ptr - data_ptr + 8) > alloc_len)
|
||||
break; // exit the loop if the output buffer length is exhausted
|
||||
|
||||
TrackDescriptor& td = this->tracks[start_track + tx - 1];
|
||||
|
||||
*out_ptr++ = 0; // reserved
|
||||
*out_ptr++ = td.adr_ctrl;
|
||||
*out_ptr++ = td.trk_num;
|
||||
*out_ptr++ = 0; // reserved
|
||||
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(td.start_lba + 150);
|
||||
*out_ptr++ = 0; // reserved
|
||||
*out_ptr++ = msf.min;
|
||||
*out_ptr++ = msf.sec;
|
||||
*out_ptr++ = msf.frm;
|
||||
} else {
|
||||
WRITE_DWORD_BE_A(out_ptr, td.start_lba);
|
||||
out_ptr += 4;
|
||||
}
|
||||
}
|
||||
return data_len;
|
||||
case 1: // Multi-session info
|
||||
std::memset(data_ptr, 0, 12);
|
||||
data_ptr[1] = 10; // TOC data length
|
||||
data_ptr[2] = 1; // first session number
|
||||
data_ptr[3] = 1; // last session number
|
||||
data_ptr[5] = this->tracks[0].adr_ctrl;
|
||||
data_ptr[6] = 1;
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(this->tracks[0].start_lba + 150);
|
||||
data_ptr[ 8] = 0; // reserved
|
||||
data_ptr[ 9] = msf.min;
|
||||
data_ptr[10] = msf.sec;
|
||||
data_ptr[11] = msf.frm;
|
||||
}
|
||||
return 12;
|
||||
case 2: // Raw TOC
|
||||
session_num = cmd_ptr[6];
|
||||
if (!session_num)
|
||||
session_num = 1;
|
||||
if (session_num > 1) {
|
||||
LOG_F(ERROR, "CDROM: invalid session number %d", session_num);
|
||||
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
|
||||
return 0;
|
||||
}
|
||||
std::memset(data_ptr, 0, 48);
|
||||
out_ptr = data_ptr;
|
||||
// prepare data header
|
||||
out_ptr[1] = 46; // TOC data length
|
||||
out_ptr[2] = 1; // first session number
|
||||
out_ptr[3] = 1; // last session number
|
||||
out_ptr += 4;
|
||||
// descriptor #1 -> first track
|
||||
out_ptr[0] = session_num;
|
||||
out_ptr[1] = this->tracks[0].adr_ctrl;
|
||||
out_ptr[3] = 0xA0; // point -> first track
|
||||
out_ptr[8] = 1; // first track number
|
||||
out_ptr += 11;
|
||||
// descriptor #2 -> last track
|
||||
out_ptr[0] = session_num;
|
||||
out_ptr[1] = this->tracks[0].adr_ctrl;
|
||||
out_ptr[3] = 0xA1; // point -> last track
|
||||
out_ptr[8] = 1; // last track number
|
||||
out_ptr += 11;
|
||||
// descriptor #3 -> lead-out
|
||||
out_ptr[0] = session_num;
|
||||
out_ptr[1] = this->tracks[0].adr_ctrl;
|
||||
out_ptr[3] = 0xA2; // point -> lead-out
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(this->tracks[1].start_lba + 150);
|
||||
out_ptr[ 7] = 0; // reserved
|
||||
out_ptr[ 8] = msf.min;
|
||||
out_ptr[ 9] = msf.sec;
|
||||
out_ptr[10] = msf.frm;
|
||||
} else {
|
||||
WRITE_DWORD_BE_U(&out_ptr[7], this->tracks[1].start_lba);
|
||||
}
|
||||
out_ptr += 11;
|
||||
// descriptor #4 -> data track
|
||||
out_ptr[0] = session_num;
|
||||
out_ptr[1] = this->tracks[0].adr_ctrl;
|
||||
out_ptr[3] = 1; // point -> data track
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(this->tracks[0].start_lba + 150);
|
||||
out_ptr[ 7] = 0; // reserved
|
||||
out_ptr[ 8] = msf.min;
|
||||
out_ptr[ 9] = msf.sec;
|
||||
out_ptr[10] = msf.frm;
|
||||
}
|
||||
return 48;
|
||||
default:
|
||||
LOG_F(ERROR, "CDROM: unsupported format in READ_TOC");
|
||||
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 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 Virtual CD-ROM drive definitions. */
|
||||
|
||||
#ifndef CD_ROM_DRIVE_H
|
||||
#define CD_ROM_DRIVE_H
|
||||
|
||||
#include <devices/storage/blockstoragedevice.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
|
||||
/* Original CD-ROM addressing mode expressed
|
||||
in minutes, seconds and frames */
|
||||
typedef struct {
|
||||
int min;
|
||||
int sec;
|
||||
int frm;
|
||||
} AddrMsf;
|
||||
|
||||
/* Descriptor for CD-ROM tracks in TOC */
|
||||
typedef struct {
|
||||
uint8_t trk_num;
|
||||
uint8_t adr_ctrl;
|
||||
uint32_t start_lba;
|
||||
} TrackDescriptor;
|
||||
|
||||
#define CDROM_MAX_TRACKS 100
|
||||
#define LEAD_OUT_TRK_NUM 0xAA
|
||||
|
||||
class CdromDrive : public BlockStorageDevice {
|
||||
public:
|
||||
CdromDrive();
|
||||
virtual ~CdromDrive() = default;
|
||||
|
||||
void set_error_callback(std::function<void(uint8_t, uint8_t)>&& err_cb) {
|
||||
this->set_error = std::move(err_cb);
|
||||
}
|
||||
|
||||
bool medium_present() { return this->is_ready; }
|
||||
|
||||
void insert_image(std::string filename);
|
||||
|
||||
uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
|
||||
uint32_t mode_sense_ex(uint8_t *cmd_ptr, uint8_t *data_ptr);
|
||||
uint32_t request_sense(uint8_t *data_ptr, uint8_t sense_key, uint8_t asc,
|
||||
uint8_t ascq);
|
||||
uint32_t report_capacity(uint8_t *data_ptr);
|
||||
uint32_t read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr);
|
||||
|
||||
AddrMsf lba_to_msf(const int lba);
|
||||
|
||||
protected:
|
||||
std::function<void(uint8_t, uint8_t)> set_error;
|
||||
|
||||
TrackDescriptor tracks[CDROM_MAX_TRACKS];
|
||||
int num_tracks;
|
||||
};
|
||||
|
||||
#endif // CD_ROM_DRIVE_H
|
||||
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/video/atimach64defs.h>
|
||||
#include <devices/video/atimach64gx.h>
|
||||
@@ -307,17 +306,8 @@ void AtiMach64Gx::enable_crtc_internal()
|
||||
ABORT_F("%s: unsupported pixel depth %d", this->name.c_str(), this->pixel_depth);
|
||||
}
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
this->stop_refresh_task();
|
||||
this->start_refresh_task();
|
||||
|
||||
this->crtc_on = true;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -107,9 +106,11 @@ ATIRage::ATIRage(uint16_t dev_id)
|
||||
switch (dev_id) {
|
||||
case ATI_RAGE_GT_DEV_ID:
|
||||
asic_id = 0x9A; // GT-B2U3 fabricated by UMC
|
||||
this->cmd_fifo_size = 48;
|
||||
break;
|
||||
case ATI_RAGE_PRO_DEV_ID:
|
||||
asic_id = 0x5C; // R3B/D/P-A4 fabricated by UMC
|
||||
this->cmd_fifo_size = 128;
|
||||
break;
|
||||
default:
|
||||
asic_id = 0xDD;
|
||||
@@ -153,7 +154,7 @@ void ATIRage::notify_bar_change(int bar_num)
|
||||
if (this->aperture_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
this->aperture_base = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
APERTURE_SIZE - this->vram_size, this);
|
||||
LOG_F(INFO, "ATIRage: aperture address set to 0x%08X", this->aperture_base);
|
||||
}
|
||||
break;
|
||||
@@ -245,6 +246,9 @@ uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_GUI_STAT:
|
||||
result = this->cmd_fifo_size << 16; // HACK: tell the guest the command FIFO is empty
|
||||
break;
|
||||
default:
|
||||
result = this->regs[reg_offset >> 2];
|
||||
}
|
||||
@@ -567,17 +571,8 @@ void ATIRage::crtc_update() {
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
this->stop_refresh_task();
|
||||
this->start_refresh_task();
|
||||
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,8 @@ private:
|
||||
uint32_t regs[512] = {}; // internal registers
|
||||
uint8_t plls[64] = {}; // internal PLL registers
|
||||
|
||||
uint8_t cmd_fifo_size = 0;
|
||||
|
||||
// Video RAM variables
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
uint32_t vram_size;
|
||||
|
||||
@@ -31,7 +31,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Kudos to joevt#3510 for his precious technical help and HW hacking.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
@@ -293,18 +292,10 @@ void ControlVideo::enable_display()
|
||||
/ (new_height + vert_blank);
|
||||
LOG_F(INFO, "Control: refresh rate set to %f Hz", this->refresh_rate);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
this->stop_refresh_task();
|
||||
|
||||
// set up periodic timer for display updates
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
this->start_refresh_task();
|
||||
|
||||
this->blank_on = false;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -75,6 +75,7 @@ DisplayID::DisplayID()
|
||||
this->last_sda = 1;
|
||||
this->last_scl = 1;
|
||||
this->data_ptr = 0;
|
||||
this->data_pos = 0;
|
||||
}
|
||||
|
||||
DisplayID::DisplayID(uint8_t std_code, uint8_t ext_code)
|
||||
@@ -181,7 +182,8 @@ uint8_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
|
||||
if (this->dev_addr & 1) {
|
||||
this->next_state = I2CState::DATA;
|
||||
this->data_ptr = this->edid;
|
||||
this->byte = *(this->data_ptr++);
|
||||
this->data_pos = 0;
|
||||
this->byte = this->data_ptr[this->data_pos++];
|
||||
} else {
|
||||
this->next_state = I2CState::REG_ADDR;
|
||||
}
|
||||
@@ -200,7 +202,10 @@ uint8_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)
|
||||
if (dev_addr & 1) {
|
||||
if (!sda) {
|
||||
/* load next data byte */
|
||||
this->byte = *(this->data_ptr++);
|
||||
if (data_pos < 128)
|
||||
this->byte = this->data_ptr[this->data_pos++];
|
||||
else
|
||||
this->byte = 0;
|
||||
} else {
|
||||
LOG_F(ERROR, "DDC-I2C: Oops! NACK received");
|
||||
}
|
||||
|
||||
+11
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -72,15 +72,16 @@ private:
|
||||
uint8_t ext_sense_code;
|
||||
|
||||
/* DDC I2C variables. */
|
||||
uint8_t next_state;
|
||||
uint8_t prev_state;
|
||||
uint8_t last_sda;
|
||||
uint8_t last_scl;
|
||||
int bit_count; /* number of bits processed so far */
|
||||
uint8_t byte; /* byte value being currently transferred */
|
||||
uint8_t dev_addr; /* current device address */
|
||||
uint8_t reg_addr; /* current register address */
|
||||
uint8_t* data_ptr; /* ptr to data byte to be transferred next */
|
||||
uint8_t next_state;
|
||||
uint8_t prev_state;
|
||||
uint8_t last_sda;
|
||||
uint8_t last_scl;
|
||||
uint8_t byte; // byte value being currently transferred
|
||||
uint8_t dev_addr; // current device address
|
||||
uint8_t reg_addr; // current register address
|
||||
uint8_t* data_ptr; // ptr to data byte to be transferred next
|
||||
int bit_count; // number of bits processed so far
|
||||
int data_pos; // current position in the data buffer
|
||||
|
||||
/*
|
||||
uint8_t edid[128] = {
|
||||
|
||||
@@ -21,7 +21,6 @@ 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>
|
||||
@@ -203,27 +202,24 @@ void PdmOnboardVideo::enable_video_internal()
|
||||
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, nullptr);
|
||||
// set CRTC parameters
|
||||
MapDmaResult res = mmu_map_dma_mem(fb_base_phys, PDM_FB_SIZE_MAX, false);
|
||||
this->fb_ptr = res.host_va;
|
||||
this->active_width = new_width;
|
||||
this->active_height = new_height;
|
||||
this->hori_blank = hori_blank;
|
||||
this->vert_blank = vert_blank;
|
||||
this->hori_total = new_width + hori_blank;
|
||||
this->vert_total = new_height + vert_blank;
|
||||
|
||||
this->set_depth_internal(new_width);
|
||||
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
this->stop_refresh_task();
|
||||
|
||||
// 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);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
this->refresh_rate = (double)(this->pixel_clock) / hori_total / vert_total;
|
||||
LOG_F(INFO, "PDM-Video: refresh rate set to %f Hz", this->refresh_rate);
|
||||
this->start_refresh_task();
|
||||
|
||||
LOG_F(9, "PDM-Video: video enabled");
|
||||
this->crtc_on = true;
|
||||
@@ -231,6 +227,7 @@ void PdmOnboardVideo::enable_video_internal()
|
||||
|
||||
void PdmOnboardVideo::disable_video_internal()
|
||||
{
|
||||
this->stop_refresh_task();
|
||||
this->blank_on = true;
|
||||
this->blank_display();
|
||||
this->blanking = 0x80;
|
||||
@@ -240,7 +237,7 @@ void PdmOnboardVideo::disable_video_internal()
|
||||
|
||||
/** 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.
|
||||
It requres a non-standard conversion routine implemented below.
|
||||
*/
|
||||
void PdmOnboardVideo::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
{
|
||||
|
||||
@@ -61,6 +61,11 @@ public:
|
||||
void set_clut_index(uint8_t index);
|
||||
void set_clut_color(uint8_t color);
|
||||
|
||||
void init_interrupts(InterruptCtrl *int_ctrl, uint32_t vbl_irq_id) {
|
||||
this->int_ctrl = int_ctrl;
|
||||
this->irq_id = vbl_irq_id;
|
||||
};
|
||||
|
||||
protected:
|
||||
void set_depth_internal(int pitch);
|
||||
void enable_video_internal();
|
||||
|
||||
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Video Conroller base class implementation. */
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
@@ -32,13 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
VideoCtrlBase::VideoCtrlBase(int width, int height)
|
||||
{
|
||||
EventManager::get_instance()->register_handler(EventType::EVENT_WINDOW,
|
||||
[this](const BaseEvent& event) {
|
||||
const WindowEvent& wnd_event = static_cast<const WindowEvent&>(event);
|
||||
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
||||
wnd_event.window_id == this->disp_wnd_id)
|
||||
this->resizing = false;
|
||||
});
|
||||
EventManager::get_instance()->add_window_handler(this, &VideoCtrlBase::handle_events);
|
||||
|
||||
this->create_display_window(width, height);
|
||||
}
|
||||
@@ -62,6 +56,12 @@ VideoCtrlBase::~VideoCtrlBase()
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::handle_events(const WindowEvent& wnd_event) {
|
||||
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
||||
wnd_event.window_id == this->disp_wnd_id)
|
||||
this->resizing = false;
|
||||
}
|
||||
|
||||
void VideoCtrlBase::create_display_window(int width, int height)
|
||||
{
|
||||
if (!this->display_wnd) { // create display window
|
||||
@@ -150,6 +150,40 @@ void VideoCtrlBase::update_screen()
|
||||
SDL_RenderPresent(this->renderer);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::start_refresh_task() {
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
||||
this->refresh_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
// assert VBL interrupt
|
||||
if (this->int_ctrl)
|
||||
this->int_ctrl->ack_int(this->irq_id, 1);
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
uint64_t vbl_duration = static_cast<uint64_t>(1.0f / ((double)(this->pixel_clock) /
|
||||
hori_total / vert_blank) * NS_PER_SEC + 0.5);
|
||||
this->vbl_end_task_id = TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
refresh_interval + vbl_duration,
|
||||
[this]() {
|
||||
// deassert VBL interrupt
|
||||
if (this->int_ctrl)
|
||||
this->int_ctrl->ack_int(this->irq_id, 0);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::stop_refresh_task() {
|
||||
if (this->refresh_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->refresh_task_id);
|
||||
}
|
||||
if (this->vbl_end_task_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->vbl_end_task_id);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoCtrlBase::get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g,
|
||||
uint8_t& b, uint8_t& a)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef VIDEO_CTRL_H
|
||||
#define VIDEO_CTRL_H
|
||||
|
||||
#include <core/hostevents.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <SDL.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -34,10 +36,14 @@ public:
|
||||
VideoCtrlBase(int width = 640, int height = 480);
|
||||
~VideoCtrlBase();
|
||||
|
||||
void handle_events(const WindowEvent& wnd_event);
|
||||
void create_display_window(int width, int height);
|
||||
void blank_display();
|
||||
void update_screen(void);
|
||||
|
||||
void start_refresh_task();
|
||||
void stop_refresh_task();
|
||||
|
||||
void get_palette_colors(uint8_t index, uint8_t& r, uint8_t& g, uint8_t& b,
|
||||
uint8_t& a);
|
||||
void set_palette_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
||||
@@ -61,6 +67,8 @@ protected:
|
||||
int active_height; // height of the visible display area
|
||||
int hori_total = 0;
|
||||
int vert_total = 0;
|
||||
int hori_blank = 0;
|
||||
int vert_blank = 0;
|
||||
int pixel_depth;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
@@ -71,6 +79,11 @@ protected:
|
||||
uint8_t* fb_ptr;
|
||||
int fb_pitch;
|
||||
uint32_t refresh_task_id = 0;
|
||||
uint32_t vbl_end_task_id = 0;
|
||||
|
||||
// interrupt suff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/devices"
|
||||
|
||||
@@ -73,7 +73,7 @@ HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
|
||||
if (found) {
|
||||
return this->get_comp_by_name(comp_name);
|
||||
} else {
|
||||
LOG_F(WARNING, "No component of type %lu was found!", type);
|
||||
LOG_F(WARNING, "No component of type %llu was found!", type);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/platinum.h>
|
||||
#include <loguru.hpp>
|
||||
@@ -61,9 +60,6 @@ int initialize_catalyst(std::string& id)
|
||||
// allocate and map physical RAM
|
||||
platinum_obj->map_phys_ram();
|
||||
|
||||
// add single SCSI bus
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
// init virtual CPU and request MPC601
|
||||
ppc_cpu_init(platinum_obj, PPC_VER::MPC601, 7833600ULL);
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ static const map<string, string> PropHelp = {
|
||||
{"fdd_wr_prot", "toggles floppy disk's write protection"},
|
||||
{"hdd_img", "specifies path to hard disk image"},
|
||||
{"hdd_wr_prot", "toggles hard disk's write protection"},
|
||||
{"cdr_config", "CD-ROM device path in [bus]:[device#] format"},
|
||||
{"cdr_img", "specifies path to CD-ROM image"},
|
||||
{"mon_id", "specifies which monitor to emulate"},
|
||||
{"pci_A1", "insert a PCI device into A1 slot"},
|
||||
|
||||
@@ -28,7 +28,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
@@ -126,8 +125,6 @@ int initialize_gossamer(std::string& id)
|
||||
grackle_obj->pci_register_device(
|
||||
DEV_FUN(0x12,0), dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT")));
|
||||
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
// add Athens clock generator device and register it with the I2C host
|
||||
gMachineObj->add_device("Athens", std::unique_ptr<AthensClocks>(new AthensClocks(0x28)));
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
@@ -163,10 +160,12 @@ static const PropMap gossamer_settings = {
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
{"cdr_config",
|
||||
new StrProperty("Ide1:0")},
|
||||
};
|
||||
|
||||
static vector<string> pmg3_devices = {
|
||||
"Grackle", "ScreamerSnd", "Heathrow", "AtiRageGT"
|
||||
"Grackle", "ScreamerSnd", "Heathrow", "AtiRageGT", "AtapiCdrom"
|
||||
};
|
||||
|
||||
static const MachineDescription pmg3dt_descriptor = {
|
||||
|
||||
@@ -82,9 +82,8 @@ int initialize_pdm(std::string& id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add internal SCSI bus
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
auto scsi_bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
// get internal SCSI bus object
|
||||
auto scsi_bus = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("Scsi0"));
|
||||
|
||||
std::string hd_image_path = GET_STR_PROP("hdd_img");
|
||||
if (!hd_image_path.empty()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -144,3 +144,21 @@ void BinProperty::set_string(string val)
|
||||
LOG_F(ERROR, "Invalid BinProperty value %s!", val.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void parse_device_path(string dev_path, string& bus_id, uint32_t& dev_num) {
|
||||
bus_id = "";
|
||||
dev_num = -1;
|
||||
|
||||
size_t delimiter_pos = dev_path.find(":");
|
||||
if (delimiter_pos == string::npos)
|
||||
ABORT_F("Invalid device path %s", dev_path.c_str());
|
||||
|
||||
bus_id = dev_path.substr(0, delimiter_pos);
|
||||
|
||||
try {
|
||||
dev_num = (uint32_t)strtoul(dev_path.substr(delimiter_pos+1).c_str(), 0, 0);
|
||||
} catch (string bad_string) {
|
||||
ABORT_F("Invalid device number %s in device path %s", bad_string.c_str(),
|
||||
dev_path.c_str());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -189,6 +189,8 @@ private:
|
||||
int bin_val;
|
||||
};
|
||||
|
||||
void parse_device_path(string dev_path, string& bus_id, uint32_t& dev_num);
|
||||
|
||||
/** Special map type for specifying machine presets. */
|
||||
typedef map<string, BasicProperty*> PropMap;
|
||||
|
||||
@@ -205,4 +207,4 @@ extern map<string, unique_ptr<BasicProperty>> gMachineSettings;
|
||||
#define GET_BIN_PROP(name) \
|
||||
dynamic_cast<BinProperty*>(gMachineSettings.at(name).get())->get_val()
|
||||
|
||||
#endif /* MACHINE_PROPERTIES_H */
|
||||
#endif // MACHINE_PROPERTIES_H
|
||||
@@ -23,7 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/hammerhead.h>
|
||||
#include <loguru.hpp>
|
||||
@@ -68,9 +67,6 @@ int initialize_tnt(std::string& id)
|
||||
// allocate and map physical RAM
|
||||
memctrl_obj->map_phys_ram();
|
||||
|
||||
// add single SCSI bus
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
// init virtual CPU and request MPC601
|
||||
ppc_cpu_init(memctrl_obj, PPC_VER::MPC601, 7833600ULL);
|
||||
|
||||
|
||||
@@ -94,18 +94,20 @@ static const PropMap yosemite_settings = {
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
{"cdr_config",
|
||||
new StrProperty("Ide0:0")},
|
||||
};
|
||||
|
||||
static vector<string> pmg3nw_devices = {
|
||||
"Grackle", "Dec21154", "BurgundySnd", "Heathrow"
|
||||
static vector<string> yosemite_devices = {
|
||||
"Grackle", "Dec21154", "BurgundySnd", "Heathrow", "AtapiCdrom"
|
||||
};
|
||||
|
||||
static const MachineDescription pmg3nw_descriptor = {
|
||||
static const MachineDescription yosemite_descriptor = {
|
||||
.name = "pmg3dt",
|
||||
.description = "Power Macintosh G3 Blue and White",
|
||||
.devices = pmg3nw_devices,
|
||||
.devices = yosemite_devices,
|
||||
.settings = yosemite_settings,
|
||||
.init_func = &initialize_yosemite
|
||||
};
|
||||
|
||||
REGISTER_MACHINE(pmg3nw, pmg3nw_descriptor);
|
||||
REGISTER_MACHINE(pmg3nw, yosemite_descriptor);
|
||||
@@ -70,16 +70,8 @@ static string appDescription = string(
|
||||
);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
/*
|
||||
Execution Type:
|
||||
0 = Realtime (Interpreter)
|
||||
1 = Realtime (Debugger)
|
||||
2 = Recompiler (to-do)
|
||||
|
||||
The rest will be decided later
|
||||
*/
|
||||
|
||||
uint32_t execution_mode = 0;
|
||||
uint32_t execution_mode = interpreter;
|
||||
|
||||
CLI::App app(appDescription);
|
||||
app.allow_windows_style_options(); /* we want Windows-style options */
|
||||
@@ -206,10 +198,10 @@ int main(int argc, char** argv) {
|
||||
});
|
||||
|
||||
switch (execution_mode) {
|
||||
case 0:
|
||||
case interpreter:
|
||||
ppc_exec();
|
||||
break;
|
||||
case 1:
|
||||
case debugger:
|
||||
enter_debugger();
|
||||
break;
|
||||
default:
|
||||
|
||||
+77
-58
@@ -1,65 +1,84 @@
|
||||
The BMac is an Ethernet controller featured in G3 and early G4 Macs. As described by a Linux contributor, this controller "appears to have some parts in common with the Sun "Happy Meal" (HME) controller".
|
||||
## Description
|
||||
|
||||
The max frame size is 0x5EE bytes.
|
||||
BMac aka BigMac is an Ethernet media access controller cell integrated in the
|
||||
Heathrow and Paddington I/O controllers.
|
||||
According to a former Apple employee, BMac has been licensed from Sun.
|
||||
It's therefore not surprising that it has a lot in common with the Sun
|
||||
"Happy Meal" (HME) controller.
|
||||
|
||||
It resides on 0xF3011000, with Writing DMA on 0xF3008200 and Reading DMA on 0xF3008300.
|
||||
### BMac based Ethernet HW
|
||||
|
||||
There are three BMac based HW configurations:
|
||||
|
||||
* BMac in a Heathrow I/O + LXT907 PHY used in Power Macintosh G3 (Old World)
|
||||
* BMac+ in a Paddington I/O + LXT970 aka ST10040 PHY in Power Macintosh Blue & White (New World)
|
||||
* BMac+ in a Paddington I/O + DP83843 PHY in a Bronze Keyboard PowerBook G3
|
||||
|
||||
## Documentation
|
||||
|
||||
No official documentation has surfaced so far. Fortunately, the official source
|
||||
code as well as the STP2002 datasheet provide enough information on the BMac device.
|
||||
|
||||
* Apple source code: https://github.com/apple-oss-distributions/AppleBMacEthernet
|
||||
* STP2002 datasheet: https://people.freebsd.org/~wpaul/STP2002QFP-UG.pdf
|
||||
|
||||
## Register Map
|
||||
|
||||
| Register Name | Offset |
|
||||
|:-------------:|:------:|
|
||||
| XIFC | 0x000 |
|
||||
| TXFIFOCSR | 0x100 |
|
||||
| TXTH | 0x110 |
|
||||
| RXFIFOCSR | 0x120 |
|
||||
BMac registers are located at offset 0x11000 starting from the I/O controller base address.
|
||||
|
||||
| Register Name | Offset | Description |
|
||||
|:-------------:|:------:|:---------------------------------------------------:|
|
||||
| XIFC | 0x000 | Transceiver interface configuration register |
|
||||
| TXFIFOCSR | 0x100 | Transceiver FIFO control & status register |
|
||||
| TXTH | 0x110 | Transceiver FIFO treshold |
|
||||
| RXFIFOCSR | 0x120 | Receiver FIFO control & status register |
|
||||
| MEMADD | 0x130 |
|
||||
| XCVRIF | 0x160 |
|
||||
| CHIPID | 0x170 |
|
||||
| MIFCSR | 0x180 |
|
||||
| SROMCSR | 0x190 |
|
||||
| TXPNTR | 0x1A0 |
|
||||
| RXPNTR | 0x1B0 |
|
||||
| STATUS | 0x200 |
|
||||
| INTDISABLE | 0x210 |
|
||||
| TXRST | 0x420 |
|
||||
| TXCFG | 0x430 |
|
||||
| IPG1 | 0x440 |
|
||||
| IPG2 | 0x450 |
|
||||
| ALIMIT | 0x460 |
|
||||
| SLOT | 0x470 |
|
||||
| PALEN | 0x480 |
|
||||
| PAPAT | 0x490 |
|
||||
| TXSFD | 0x4A0 |
|
||||
| JAM | 0x4B0 |
|
||||
| TXMAX | 0x4C0 |
|
||||
| TXMIN | 0x4D0 |
|
||||
| PAREG | 0x4E0 |
|
||||
| DCNT | 0x4F0 |
|
||||
| NCCNT | 0x500 |
|
||||
| NTCNT | 0x510 |
|
||||
| EXCNT | 0x520 |
|
||||
| LTCNT | 0x530 |
|
||||
| RSEED | 0x540 |
|
||||
| TXSM | 0x550 |
|
||||
| RXRST | 0x620 |
|
||||
| RXRST | 0x620 |
|
||||
| RXCFG | 0x630 |
|
||||
| RXMAX | 0x640 |
|
||||
| RXMIN | 0x650 |
|
||||
| MADD2 | 0x660 |
|
||||
| MADD1 | 0x670 |
|
||||
| MADD0 | 0x680 |
|
||||
| FRCNT | 0x690 |
|
||||
| LECNT | 0x6A0 |
|
||||
| AECNT | 0x6B0 |
|
||||
| FECNT | 0x6C0 |
|
||||
| RXSM | 0x6D0 |
|
||||
| RXCV | 0x6E0 |
|
||||
| HASH3 | 0x700 |
|
||||
| HASH2 | 0x710 |
|
||||
| HASH1 | 0x720 |
|
||||
| HASH0 | 0x730 |
|
||||
| AFR2 | 0x740 |
|
||||
| AFR1 | 0x750 |
|
||||
| AFR0 | 0x760 |
|
||||
| AFCR | 0x770 |
|
||||
| CHIPID | 0x170 | Chip aka Ethernet cell identification register |
|
||||
| MIFCSR | 0x180 | Media interface control & status register |
|
||||
| SROMCSR | 0x190 | Serial EEPROM control & status register |
|
||||
| TXPNTR | 0x1A0 | Transceiver pointer |
|
||||
| RXPNTR | 0x1B0 | Receiver pointer |
|
||||
| STATUS | 0x200 | Global status register |
|
||||
| INTDISABLE | 0x210 | Global interrupt disable register |
|
||||
| TXRST | 0x420 | Transceiver software reset |
|
||||
| TXCFG | 0x430 | Transceiver configuration register |
|
||||
| IPG1 | 0x440 | Interpacket gap 1 register |
|
||||
| IPG2 | 0x450 | Interpacket gap 2 register |
|
||||
| ALIMIT | 0x460 | Transceiver attempt limit register |
|
||||
| SLOT | 0x470 | Transceiver slot time register |
|
||||
| PALEN | 0x480 | Transceiver preamble length register |
|
||||
| PAPAT | 0x490 | Transceiver preamble pattern register |
|
||||
| TXSFD | 0x4A0 | Transceiver start of frame delimiter (SFD) register |
|
||||
| JAM | 0x4B0 | Transceiver jam size register |
|
||||
| TXMAX | 0x4C0 | Transceiver maximum frame size register |
|
||||
| TXMIN | 0x4D0 | Transceiver minimum frame size register |
|
||||
| PAREG | 0x4E0 | Transceiver peak attempts register |
|
||||
| DCNT | 0x4F0 | Defer timer (counter ?) |
|
||||
| NCCNT | 0x500 | Normal collision counter |
|
||||
| NTCNT | 0x510 | Network collision counter |
|
||||
| EXCNT | 0x520 | Excessive collision counter |
|
||||
| LTCNT | 0x530 | Late collision counter |
|
||||
| RSEED | 0x540 | Transceiver random number seed register |
|
||||
| TXSM | 0x550 | Transceiver state machine register |
|
||||
| RXRST | 0x620 | Receiver software reset register |
|
||||
| RXCFG | 0x630 | Receiver configuration register |
|
||||
| RXMAX | 0x640 | Receiver maximum frame size register |
|
||||
| RXMIN | 0x650 | Receiver minimum frame size register |
|
||||
| MADD2 | 0x660 | Receiver MAC address 2 register |
|
||||
| MADD1 | 0x670 | Receiver MAC address 1 register |
|
||||
| MADD0 | 0x680 | Receiver MAC address 0 register |
|
||||
| FRCNT | 0x690 | Receiver frame counter register |
|
||||
| LECNT | 0x6A0 | Receiver length error counter register |
|
||||
| AECNT | 0x6B0 | Receiver alignment error counter register |
|
||||
| FECNT | 0x6C0 | Receiver frame check sum error counter register |
|
||||
| RXSM | 0x6D0 | Receiver state machine register |
|
||||
| RXCV | 0x6E0 | Receiver code violation register |
|
||||
| HASH3 | 0x700 | Receiver hash table 3 register |
|
||||
| HASH2 | 0x710 | Receiver hash table 2 register |
|
||||
| HASH1 | 0x720 | Receiver hash table 1 register |
|
||||
| HASH0 | 0x730 | Receiver hash table 0 register |
|
||||
| AFR2 | 0x740 | Receiver address filter 2 register |
|
||||
| AFR1 | 0x750 | Receiver address filter 1 register |
|
||||
| AFR0 | 0x760 | Receiver address filter 0 register |
|
||||
| AFCR | 0x770 | Receiver address filter control register |
|
||||
Reference in new issue
Block a user