kernel+init: Add a framebuffer special device file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-04-21 18:18:15 +02:00
parent 58dc23e4d9
commit 841fc25137
Signed by: apio
GPG Key ID: B8A7D06E42258954
8 changed files with 70 additions and 2 deletions

View File

@ -20,6 +20,7 @@ static void populate_devfs()
xmknod("/dev/console", 0666, 1, 0);
xmknod("/dev/null", 0666, 2, 0);
xmknod("/dev/zero", 0666, 2, 1);
xmknod("/dev/fb0", 0222, 3, 0);
}
int main()

View File

@ -43,6 +43,7 @@ set(SOURCES
src/fs/devices/NullDevice.cpp
src/fs/devices/ZeroDevice.cpp
src/fs/devices/ConsoleDevice.cpp
src/fs/devices/FramebufferDevice.cpp
src/InitRD.cpp
src/ELF.cpp
)

View File

@ -13,6 +13,11 @@ class Device
return err(ENOTTY);
}
virtual usize size() const
{
return 0;
}
virtual bool blocking() const = 0;
virtual ~Device() = default;

View File

@ -1,6 +1,7 @@
#include "fs/devices/DeviceRegistry.h"
#include "Log.h"
#include "fs/devices/ConsoleDevice.h"
#include "fs/devices/FramebufferDevice.h"
#include "fs/devices/NullDevice.h"
#include "fs/devices/ZeroDevice.h"
#include <luna/Vector.h>
@ -45,6 +46,7 @@ namespace DeviceRegistry
TRY(register_special_device(DeviceMajorTypes::Memory, 0, NullDevice::create));
TRY(register_special_device(DeviceMajorTypes::Memory, 1, ZeroDevice::create));
TRY(register_special_device(DeviceMajorTypes::Console, 0, ConsoleDevice::create));
TRY(register_special_device(DeviceMajorTypes::Framebuffer, 0, FramebufferDevice::create));
return {};
}

View File

@ -11,7 +11,8 @@ namespace DeviceRegistry
{
Null = 0,
Console = 1,
Memory = 2
Memory = 2,
Framebuffer = 3,
};
Result<SharedPtr<Device>> create_special_device(u32 major, u32 minor);

View File

@ -0,0 +1,37 @@
#include "fs/devices/FramebufferDevice.h"
#include "video/Framebuffer.h"
#include <luna/CString.h>
Result<SharedPtr<Device>> FramebufferDevice::create()
{
return (SharedPtr<Device>)TRY(make_shared<FramebufferDevice>());
}
Result<usize> FramebufferDevice::read(u8*, usize, usize) const
{
return 0;
}
Result<usize> FramebufferDevice::write(const u8* buf, usize offset, usize length)
{
if ((offset + length) > size()) length = size() - offset;
memcpy(Framebuffer::ptr() + offset, buf, length);
return length;
}
usize FramebufferDevice::size() const
{
return Framebuffer::size();
}
bool FramebufferDevice::blocking() const
{
return false;
}
Result<u64> FramebufferDevice::ioctl(int, void*)
{
return err(EINVAL);
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "fs/devices/DeviceRegistry.h"
class FramebufferDevice : public Device
{
public:
// Initializer for DeviceRegistry.
static Result<SharedPtr<Device>> create();
Result<usize> read(u8*, usize, usize) const override;
Result<usize> write(const u8*, usize, usize) override;
bool blocking() const override;
Result<u64> ioctl(int request, void* arg) override;
usize size() const override;
virtual ~FramebufferDevice() = default;
};

View File

@ -176,7 +176,7 @@ namespace TmpFS
usize size() const override
{
return 0;
return m_device->size();
}
mode_t mode() const override