forked from RPCSX/rpcsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'RPCSX:master' into devel
- Loading branch information
Showing
11 changed files
with
284 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,78 @@ | ||
#include "io-device.hpp" | ||
#include "orbis/KernelAllocator.hpp" | ||
#include "orbis/error/ErrorCode.hpp" | ||
#include "orbis/file.hpp" | ||
#include "orbis/uio.hpp" | ||
#include "orbis/utils/Logs.hpp" | ||
#include <span> | ||
#include <unistd.h> | ||
|
||
struct ConsoleFile : orbis::File {}; | ||
struct ConsoleDevice : IoDevice { | ||
int inputFd; | ||
int outputFd; | ||
|
||
ConsoleDevice(int inputFd, int outputFd) | ||
: inputFd(inputFd), outputFd(outputFd) {} | ||
|
||
orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path, | ||
std::uint32_t flags, std::uint32_t mode, | ||
orbis::Thread *thread) override; | ||
}; | ||
|
||
static orbis::ErrorCode console_ioctl(orbis::File *file, std::uint64_t request, | ||
void *argp, orbis::Thread *thread) { | ||
void *argp, orbis::Thread *thread) { | ||
|
||
ORBIS_LOG_FATAL("Unhandled console ioctl", request); | ||
return {}; | ||
} | ||
|
||
static orbis::ErrorCode console_read(orbis::File *file, orbis::Uio *uio, | ||
orbis::Thread *thread) { | ||
auto dev = dynamic_cast<ConsoleDevice *>(file->device.get()); | ||
|
||
for (auto vec : std::span(uio->iov, uio->iovcnt)) { | ||
auto result = ::read(dev->inputFd, vec.base, vec.len); | ||
|
||
if (result < 0) { | ||
return orbis::ErrorCode::IO; | ||
} | ||
|
||
uio->offset += result; | ||
break; | ||
} | ||
return {}; | ||
} | ||
|
||
static orbis::ErrorCode console_write(orbis::File *file, orbis::Uio *uio, | ||
orbis::Thread *thread) { | ||
auto dev = dynamic_cast<ConsoleDevice *>(file->device.get()); | ||
|
||
for (auto vec : std::span(uio->iov, uio->iovcnt)) { | ||
::write(dev->outputFd, vec.base, vec.len); | ||
} | ||
uio->resid = 0; | ||
return {}; | ||
} | ||
|
||
static const orbis::FileOps fileOps = { | ||
.ioctl = console_ioctl, | ||
.read = console_read, | ||
.write = console_write, | ||
}; | ||
|
||
struct ConsoleDevice : IoDevice { | ||
orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path, | ||
std::uint32_t flags, std::uint32_t mode, | ||
orbis::Thread *thread) override { | ||
auto newFile = orbis::knew<ConsoleFile>(); | ||
newFile->ops = &fileOps; | ||
newFile->device = this; | ||
orbis::ErrorCode ConsoleDevice::open(orbis::Ref<orbis::File> *file, | ||
const char *path, std::uint32_t flags, | ||
std::uint32_t mode, | ||
orbis::Thread *thread) { | ||
auto newFile = orbis::knew<ConsoleFile>(); | ||
newFile->ops = &fileOps; | ||
newFile->device = this; | ||
|
||
*file = newFile; | ||
return {}; | ||
} | ||
}; | ||
*file = newFile; | ||
return {}; | ||
} | ||
|
||
IoDevice *createConsoleCharacterDevice() { return orbis::knew<ConsoleDevice>(); } | ||
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd) { | ||
return orbis::knew<ConsoleDevice>(inputFd, outputFd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "io-device.hpp" | ||
#include "orbis/KernelAllocator.hpp" | ||
#include "orbis/error/ErrorCode.hpp" | ||
#include "orbis/file.hpp" | ||
#include "orbis/thread/Thread.hpp" | ||
#include "orbis/uio.hpp" | ||
#include "orbis/utils/Logs.hpp" | ||
#include <span> | ||
|
||
struct HddFile : orbis::File {}; | ||
|
||
static orbis::ErrorCode hdd_ioctl(orbis::File *fs, std::uint64_t request, | ||
void *argp, orbis::Thread *thread) { | ||
|
||
if (request == 0x40046480) { // DIOCGSECTORSIZE | ||
return orbis::uwrite(orbis::ptr<orbis::uint>(argp), 0x1000u); | ||
} | ||
|
||
ORBIS_LOG_FATAL("Unhandled hdd ioctl", request); | ||
thread->where(); | ||
return {}; | ||
} | ||
|
||
static orbis::ErrorCode hdd_read(orbis::File *file, orbis::Uio *uio, | ||
orbis::Thread *thread) { | ||
auto dev = file->device.get(); | ||
|
||
ORBIS_LOG_ERROR(__FUNCTION__, uio->offset); | ||
for (auto vec : std::span(uio->iov, uio->iovcnt)) { | ||
std::memset(vec.base, 0, vec.len); | ||
|
||
// HACK: dummy UFS header | ||
if (uio->offset == 0x10000) { | ||
*(uint32_t *)((char *)vec.base + 0x55c) = 0x19540119; | ||
*(uint64_t *)((char *)vec.base + 0x3e8) = 0x1000; | ||
*(uint8_t *)((char *)vec.base + 0xd3) = 1; | ||
*(uint8_t *)((char *)vec.base + 0xd1) = 1; | ||
} | ||
uio->offset += vec.len; | ||
} | ||
return {}; | ||
} | ||
|
||
|
||
static orbis::ErrorCode hdd_stat(orbis::File *fs, orbis::Stat *sb, | ||
orbis::Thread *thread) { | ||
// TODO | ||
return {}; | ||
} | ||
|
||
static const orbis::FileOps fsOps = { | ||
.ioctl = hdd_ioctl, | ||
.read = hdd_read, | ||
.stat = hdd_stat, | ||
}; | ||
|
||
struct HddDevice : IoDevice { | ||
orbis::ErrorCode open(orbis::Ref<orbis::File> *fs, const char *path, | ||
std::uint32_t flags, std::uint32_t mode, | ||
orbis::Thread *thread) override { | ||
auto newFile = orbis::knew<HddFile>(); | ||
newFile->ops = &fsOps; | ||
newFile->device = this; | ||
|
||
*fs = newFile; | ||
return {}; | ||
} | ||
}; | ||
|
||
IoDevice *createHddCharacterDevice() { return orbis::knew<HddDevice>(); } |
Oops, something went wrong.