2023-06-23 02:28:14 +02:00
|
|
|
#include "io-device.hpp"
|
2023-07-04 18:19:17 +02:00
|
|
|
#include "orbis/KernelAllocator.hpp"
|
2023-07-12 14:12:34 +02:00
|
|
|
#include "orbis/utils/Logs.hpp"
|
2023-06-23 02:28:14 +02:00
|
|
|
#include "vm.hpp"
|
|
|
|
|
|
2023-07-29 18:53:34 +02:00
|
|
|
struct HmdMmapDevice : public IoDevice {
|
|
|
|
|
orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path,
|
2023-07-29 21:46:28 +02:00
|
|
|
std::uint32_t flags, std::uint32_t mode,
|
|
|
|
|
orbis::Thread *thread) override;
|
2023-07-29 18:53:34 +02:00
|
|
|
};
|
|
|
|
|
struct HmdMmapFile : public orbis::File {};
|
2023-06-23 02:28:14 +02:00
|
|
|
|
2023-07-29 18:53:34 +02:00
|
|
|
static orbis::ErrorCode hmd_mmap_ioctl(orbis::File *file, std::uint64_t request,
|
|
|
|
|
void *argp, orbis::Thread *thread) {
|
2023-07-12 14:12:34 +02:00
|
|
|
ORBIS_LOG_FATAL("Unhandled hmd_mmap ioctl", request);
|
2023-07-29 18:53:34 +02:00
|
|
|
|
|
|
|
|
// 0x800c4802
|
|
|
|
|
return {};
|
2023-06-23 02:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-29 18:53:34 +02:00
|
|
|
static orbis::ErrorCode hmd_mmap_mmap(orbis::File *file, void **address,
|
|
|
|
|
std::uint64_t size, std::int32_t prot,
|
|
|
|
|
std::int32_t flags, std::int64_t offset,
|
|
|
|
|
orbis::Thread *thread) {
|
|
|
|
|
ORBIS_LOG_FATAL("hmd_mmap mmap", address, size, offset);
|
|
|
|
|
auto result = rx::vm::map(*address, size, prot, flags);
|
|
|
|
|
|
|
|
|
|
if (result == (void *)-1) {
|
|
|
|
|
return orbis::ErrorCode::INVAL; // TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*address = result;
|
|
|
|
|
return {};
|
2023-06-23 02:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-29 18:53:34 +02:00
|
|
|
static const orbis::FileOps ops = {
|
|
|
|
|
.ioctl = hmd_mmap_ioctl,
|
|
|
|
|
.mmap = hmd_mmap_mmap,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
orbis::ErrorCode HmdMmapDevice::open(orbis::Ref<orbis::File> *file,
|
|
|
|
|
const char *path, std::uint32_t flags,
|
2023-07-29 21:46:28 +02:00
|
|
|
std::uint32_t mode,
|
|
|
|
|
orbis::Thread *thread) {
|
2023-07-29 18:53:34 +02:00
|
|
|
auto newFile = orbis::knew<HmdMmapFile>();
|
|
|
|
|
newFile->device = this;
|
|
|
|
|
newFile->ops = &ops;
|
|
|
|
|
*file = newFile;
|
|
|
|
|
return {};
|
2023-06-23 02:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IoDevice *createHmdMmapCharacterDevice() {
|
2023-07-29 18:53:34 +02:00
|
|
|
return orbis::knew<HmdMmapDevice>();
|
2023-06-23 02:28:14 +02:00
|
|
|
}
|