Skip to content

Commit

Permalink
Merge branch 'RPCSX:master' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
qurious-pixel authored Nov 2, 2023
2 parents e579418 + 3cb4bae commit 0e219a6
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 125 deletions.
8 changes: 2 additions & 6 deletions orbis-kernel/src/sys/sys_descrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ orbis::SysResult orbis::sys_getdtablesize(Thread *thread) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_dup2(Thread *thread, uint from, uint to) {
if (to == 1 || to == 2) { // HACK: ignore setup /dev/console to stdout/stderr
return {};
}

std::lock_guard lock(thread->tproc->fileDescriptors.mutex);

auto file = thread->tproc->fileDescriptors.get(from);

if (file == nullptr) {
return ErrorCode::BADF;
}

thread->tproc->fileDescriptors.close(to);
thread->tproc->fileDescriptors.insert(to, file);
return {};
Expand Down
8 changes: 8 additions & 0 deletions orbis-kernel/src/sys/sys_sce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ orbis::SysResult orbis::sys_mtypeprotect(Thread *thread /* TODO */) {
orbis::SysResult orbis::sys_regmgr_call(Thread *thread, uint32_t op,
uint32_t id, ptr<void> result,
ptr<void> value, uint64_t type) {
ORBIS_LOG_ERROR(__FUNCTION__, op, id, type);
thread->where();

if (op == 2) {
if (id == 0x2010000) {
return uwrite((ptr<uint>)value, 0u);
}
}
if (op == 25) {
struct nonsys_int {
union {
Expand Down
7 changes: 4 additions & 3 deletions orbis-kernel/src/sys/sys_sysctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ orbis::SysResult orbis::sys___sysctl(Thread *thread, ptr<sint> name,
size_t newlen) {
enum sysctl_ctl { unspec, kern, vm, vfs, net, debug, hw, machdep, user };

// machdep.tsc_freq

enum sysctl_kern {
usrstack = 33,
kern_14 = 14,
Expand Down Expand Up @@ -154,11 +152,14 @@ orbis::SysResult orbis::sys___sysctl(Thread *thread, ptr<sint> name,

auto result = uread(thread->tproc->appInfo, (ptr<AppInfo>)new_);
if (result == ErrorCode{}) {
auto appInfo = thread->tproc->appInfo;
auto &appInfo = thread->tproc->appInfo;
ORBIS_LOG_ERROR("set AppInfo", appInfo.appId, appInfo.unk0,
appInfo.unk1, appInfo.appType, appInfo.titleId,
appInfo.unk2, appInfo.unk3, appInfo.unk5, appInfo.unk6,
appInfo.unk7, appInfo.unk8);

// HACK
appInfo.unk4 = orbis::slong(0x80000000'00000000);
}

return result;
Expand Down
1 change: 1 addition & 0 deletions rpcsx-os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_executable(rpcsx-os
iodev/camera.cpp
iodev/cd.cpp
iodev/console.cpp
iodev/hdd.cpp
iodev/dce.cpp
iodev/dipsw.cpp
iodev/dmem.cpp
Expand Down
3 changes: 2 additions & 1 deletion rpcsx-os/io-devices.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ IoDevice *createRngCharacterDevice();
IoDevice *createAjmCharacterDevice();
IoDevice *createIccConfigurationCharacterDevice();
IoDevice *createNpdrmCharacterDevice();
IoDevice *createConsoleCharacterDevice();
IoDevice *createConsoleCharacterDevice(int inputFd, int outputFd);
IoDevice *createSblSrvCharacterDevice();
IoDevice *createShmDevice();
IoDevice *createBlockPoolDevice();
Expand All @@ -29,3 +29,4 @@ IoDevice *createBtCharacterDevice();
IoDevice *createXptCharacterDevice();
IoDevice *createCdCharacterDevice();
IoDevice *createMetaDbgCharacterDevice();
IoDevice *createHddCharacterDevice();
72 changes: 59 additions & 13 deletions rpcsx-os/iodev/console.cpp
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);
}
70 changes: 70 additions & 0 deletions rpcsx-os/iodev/hdd.cpp
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>(); }
Loading

0 comments on commit 0e219a6

Please sign in to comment.