Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
8 changed files with 32 additions and 171 deletions
Showing only changes of commit d6fae8055b - Show all commits

View File

@ -155,13 +155,6 @@ namespace JabyEngine {
__syscall_function_cast(Table_A, void(*)())();
}
static __always_inline void SetDefaultExceptionJmpBuf() {
register uint32_t FuncID asm("t1") = 0x18;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
__syscall_function_cast(Table_B, void(*)())();
}
static __always_inline void* memcpy(void *dst, const void *src, size_t len) {
register uint32_t FuncID asm("t1") = 0x2A;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
@ -176,8 +169,7 @@ namespace JabyEngine {
return __syscall_function_cast(Table_B, ThreadHandle(*)(void(*)(), uint32_t*, uint32_t*))(thread_func, stack_ptr, gp);
}
// No return??????
static __always_inline void ChangeThread(ThreadHandle handle) {
static __always_inline void [[noreturn]] ChangeThread(ThreadHandle handle) {
register uint32_t FuncID asm("t1") = 0x10;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
@ -219,6 +211,13 @@ namespace JabyEngine {
__syscall_function_cast(Table_B, void(*)())();
}
static __always_inline void SetDefaultExitFromException() {
register uint32_t FuncID asm("t1") = 0x18;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));
__syscall_function_cast(Table_B, void(*)())();
}
static __always_inline int SysEnqIntRP(Priority prio, InterruptCallback* interElm) {
register uint32_t FuncID asm("t1") = 0x02;
__asm__ volatile("" : "=r"(FuncID) : "r"(FuncID));

View File

@ -21,7 +21,6 @@ namespace JabyEngine {
extern State current_state;
extern uint8_t irq_bit_pending;
extern uint8_t last_cmd;
struct Command {
static void wait_completed() {
@ -35,7 +34,6 @@ namespace JabyEngine {
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
irq_bit_pending = bit::set(irq_bit_pending, cmd.complete_irq);
last_cmd = cmd.id;
CD_IO::PortIndex0::change_to();
((CD_IO::PortIndex0::ParameterFifo.write(CD_IO::ParameterFifo{args})),...);
CD_IO::PortIndex0::CommandFifo.write(CD_IO::CommandFifo{cmd.id});
@ -48,54 +46,6 @@ namespace JabyEngine {
}
};
/*struct NewCommand {
struct Internal {
static void wait_completed(CD_IO::Interrupt::Type irq) {
static const auto get_next_irq = []() -> CD_IO::Interrupt::Type {
CD_IO::Interrupt::Type cur_irq = CD_IO::Interrupt::None;
do {
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
} while(cur_irq == CD_IO::Interrupt::None);
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
// ^ Stabilize interrupt
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
return cur_irq;
};
CD_IO::PortIndex1::change_to();
while(get_next_irq() != irq);
CD_IO::PortIndex0::change_to();
}
template<typename...ARGS>
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
CD_IO::PortIndex0::change_to();
((CD_IO::PortIndex0::ParameterFifo.write(CD_IO::ParameterFifo{args})),...);
CD_IO::PortIndex0::CommandFifo.write(CD_IO::CommandFifo{cmd.id});
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
}
};
// Requires Index 0
template<typename...ARGS>
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(cmd, args...);
}
// Requires Index 0
template<typename...ARGS>
static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) {
Interrupt::disable_irq(Interrupt::CDROM);
Internal::send(cmd, args...);
Internal::wait_completed(cmd.complete_irq);
Interrupt::enable_irq(Interrupt::CDROM);
}
};*/
namespace IRQ {
void process(uint32_t irq);
void read_sector_to0(uint32_t* dst, size_t bytes);

View File

@ -5,16 +5,11 @@
namespace JabyEngine {
namespace Callback {
namespace internal {
static void execute_callback(Thread::Handle thread_handle, uint32_t parm, uint8_t irq_bit_pending, uint8_t irq, uint8_t last_cmd) {
static void execute_callback(Thread::Handle thread_handle, uint32_t parm) {
if(CurrentThread::is_me(MainThread::Handle)) {
CurrentThread::replace_with(thread_handle);
CurrentThread::force_a0(parm);
}
else {
//printf("%i +> %i +> %i\n", irq_bit_pending, irq, last_cmd);
}
//printf("C\n");
SysCall::ReturnFromException();
}
@ -32,7 +27,7 @@ namespace JabyEngine {
void routine();
static void [[deprecated("Currently not in use")]] execute() {
execute_callback(VSync::thread_handle, 0, 0, 0, 0);
execute_callback(VSync::thread_handle, 0);
}
}
@ -43,8 +38,8 @@ namespace JabyEngine {
extern uint32_t stack[StackSize];
void routine(uint32_t irq);
static void execute(uint32_t irq, uint8_t irq_bit_pending, uint8_t irq2, uint8_t last_cmd) {
execute_callback(CD::thread_handle, irq, irq_bit_pending, irq2, last_cmd);
static void execute(uint32_t irq) {
execute_callback(CD::thread_handle, irq);
}
static uint32_t resume() {

View File

@ -48,7 +48,7 @@ namespace JabyEngine {
setting.get_loc_functional = !CD::get_loc().is_zero();
CD::enable_CDXA(double_speed); //< Activates PortIndex0
set_channel(channel);//printf("!!0-%X %X %X\n", setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
set_channel(channel);
CD::Command::send(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::Command::send(CD_IO::Command::ReadS);
}
@ -75,7 +75,7 @@ namespace JabyEngine {
void pop_play() {
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0
set_channel(setting.channel);//printf("!!1-%X %X %X\n", setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
set_channel(setting.channel);
CD::Command::send_wait_response(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::Command::send(CD_IO::Command::ReadS);
}

View File

@ -34,26 +34,22 @@ namespace JabyEngine {
// TODO: Verify this on real HW
CD_IO::Interrupt::enable_extended(CD_IO::PortIndex1::InterruptEnable);
/*const auto event = SysCall::OpenEvent(0xF0000003, 0x1000, 0x1000, ::JabyEngine::CD::internal::blubb);
printf(">>> 0x%p\n", event);
SysCall::EnableEvent(event);*/
Interrupt::enable_irq(Interrupt::CDROM);
Interrupt::ack_irq(Interrupt::CDROM);
SysCall::ExitCriticalSection();
// TODO: Do we need this at all?!
__debug_boot_color_at(::JabyEngine::GPU::Color24::Red(), DebugX, DebugY, DebugScale);
CD_IO::PortIndex0::change_to();
printf("@%i\n", __LINE__);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale);
Command::send(CD_IO::Command::GetStat);printf("@%i\n", __LINE__);
Command::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale);
Command::send(CD_IO::Command::GetStat);printf("@%i\n", __LINE__);
Command::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Yellow(), DebugX, DebugY, DebugScale);
Command::send(CD_IO::Command::Init);printf("@%i\n", __LINE__);
Command::send(CD_IO::Command::Init);
Command::send(CD_IO::Command::Demute);printf("@%i\n", __LINE__);
Command::send(CD_IO::Command::Demute);
}
}
}

View File

@ -40,17 +40,21 @@ namespace JabyEngine {
}
namespace boot {
namespace Start {
namespace Start {
// Thanks to Nicolas Noble!
static void enable_vanilla_bios() {
SysCall::FlushCache();
SysCall::DequeueCdIntr();
SysCall::SetDefaultExitFromException();
}
static void setup() {
static constexpr auto DebugX = 1;
static constexpr auto DebugY = 0;
static constexpr auto DebugScale = 1.0;
SysCall::FlushCache();
SysCall::DequeueCdIntr();
SysCall::SetDefaultExceptionJmpBuf();
BIOS::identify();
enable_vanilla_bios();
Callbacks::setup();
__debug_boot_color_at(::JabyEngine::GPU::Color24::Grey(), DebugX, DebugY, DebugScale);

View File

@ -43,14 +43,12 @@ namespace JabyEngine {
State current_state = State::Ready;
uint8_t irq_bit_pending = CD_IO::Interrupt::None;
uint8_t last_cmd = 0;
auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc cmd) {
const auto loc = BCDTimeStamp::from(lba);
//printf("!!2-%X %X %X\n", loc.min, loc.sec, loc.sector);
Command::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
Command::send(cmd);
return loc;
@ -91,7 +89,6 @@ namespace JabyEngine {
}
void resume_at0(const BCDTimeStamp& cd_time) {
//printf("!!3-%X %X %X\n", cd_time.min, cd_time.sec, cd_time.sector);
Command::send(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector);
}
@ -99,9 +96,7 @@ namespace JabyEngine {
static SysCall::InterruptVerifierResult verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) {
//printf("A\n");
Interrupt::ack_irq(Interrupt::CDROM);
//printf("B\n");
return SysCall::InterruptVerifierResult::ExecuteHandler;
}
@ -117,11 +112,6 @@ namespace JabyEngine {
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex1::change_to();
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
/*CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag);
zero = 0;
zero = 1;
zero = 2;
zero = 3;*/
irq_bit_pending = bit::clear(irq_bit_pending, cur_irq);
@ -132,11 +122,10 @@ namespace JabyEngine {
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status);
Callback::internal::CD::execute(cur_irq, irq_bit_pending, cur_irq, last_cmd);
Callback::internal::CD::execute(cur_irq);
}
void process(uint32_t irq) {
//printf("%i -> %i -> %i\n", irq_bit_pending, irq, last_cmd);
if(current_state != State::XAMode) {
switch(irq) {
case CD_IO::Interrupt::DataReady: {
@ -146,9 +135,6 @@ namespace JabyEngine {
//Now obtain sector
read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes);
/*const auto time = get_locL();
printf("%X %X %X\n", time.min, time.sec, time.sector);*/
if(cur_file.done_processing()) {
current_state = State::Done;
Command::send(CD_IO::Command::Pause);
@ -178,81 +164,12 @@ namespace JabyEngine {
}
}
}
uint32_t entered = 0;
void blubb() {
entered = 1;
printf("A\n");
Interrupt::ack_irq(Interrupt::CDROM);
const auto old_status = CD_IO::IndexStatus.read();
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex1::change_to();
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::Interrupt::reset_parameter_fifo(CD_IO::PortIndex1::InterruptFlag);
zero = 0;
zero = 1;
zero = 2;
zero = 3;
irq_bit_pending = bit::clear(irq_bit_pending, cur_irq);
CD_IO::PortIndex0::change_to();
if(cur_irq == CD_IO::Interrupt::DataReady) {
CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data());
}
if(cur_irq == CD_IO::Interrupt::Acknowledge) {
CD_IO::PortIndex0::ResponseFifo.read();
}
if(current_state != State::XAMode) {
switch(cur_irq) {
case CD_IO::Interrupt::DataReady: {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
IRQ::read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes);
const auto time = get_locL();
printf("%X %X %X\n", time.min, time.sec, time.sector);
if(cur_file.done_processing()) {
current_state = State::Done;
Command::send(CD_IO::Command::Pause);
}
}
else {
current_state = State::BufferFull;
Command::send(CD_IO::Command::Pause);
}
} break;
case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time
IRQ::resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
Command::send(CD_IO::Command::Play);
} break;
case CD_IO::Interrupt::DiskError: {
current_state = State::Error;
} break;
}
}
else {
current_state = CDXA::interrupt_handler(cur_irq);
}
}
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator) {
cur_file.set_from(file_info);
sector_allocator = buffer_allocator;
Command::send(CD_IO::Command::SetMode, DataSectorMode);
enable_CD();
send_read_n0(cur_file.cur_lba);
}

View File

@ -88,7 +88,7 @@ namespace JabyEngine {
void query_controller() {
static constexpr auto TypeIDX = 1;
//SysCall::EnterCriticalSection();
SysCall::EnterCriticalSection();
Periphery::connect_to(cur_controller_port);
for(uint32_t id = 0; id < Periphery::DeviceCount; id++) {
auto &cur_controller = controller[cur_controller_port][id];
@ -130,7 +130,7 @@ namespace JabyEngine {
if(Configuration::Periphery::include_portB()) {
cur_controller_port ^= 0x1;
}
//SysCall::ExitCriticalSection();
SysCall::ExitCriticalSection();
}
}
}