about summary refs log tree commit diff stats
path: root/kernel.soso/framebuffer.c
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-09-14 01:42:29 -0700
committerKartik Agaram <vc@akkartik.com>2019-09-14 01:45:55 -0700
commit46bb1d3157f9ad575c83a4bfa1e32b0d21bc8546 (patch)
tree28918f653d7cf970d33d5592047ef663289aca40 /kernel.soso/framebuffer.c
parentded2b24ce28f4a9df75ce40117f0f06f09574369 (diff)
downloadmu-46bb1d3157f9ad575c83a4bfa1e32b0d21bc8546.tar.gz
5650 - support a second OS: soso
https://github.com/ozkl/soso

+ Much smaller than Linux; builds instantly
+ Supports graphics
- No network support
- Doesn't work on a cloud server (yet?)
Diffstat (limited to 'kernel.soso/framebuffer.c')
-rw-r--r--kernel.soso/framebuffer.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/kernel.soso/framebuffer.c b/kernel.soso/framebuffer.c
new file mode 100644
index 00000000..04783705
--- /dev/null
+++ b/kernel.soso/framebuffer.c
@@ -0,0 +1,108 @@
+#include "devfs.h"
+#include "device.h"
+#include "common.h"
+#include "gfx.h"
+#include "framebuffer.h"
+#include "vmm.h"
+#include "process.h"
+
+static BOOL fb_open(File *file, uint32 flags);
+static int32 fb_read(File *file, uint32 size, uint8 *buffer);
+static int32 fb_write(File *file, uint32 size, uint8 *buffer);
+static int32 fb_ioctl(File *node, int32 request, void * argp);
+static void* fb_mmap(File* file, uint32 size, uint32 offset, uint32 flags);
+static BOOL fb_munmap(File* file, void* address, uint32 size);
+
+static uint8* gFrameBufferPhysical = 0;
+static uint8* gFrameBufferVirtual = 0;
+
+void initializeFrameBuffer(uint8* p_address, uint8* v_address)
+{
+    gFrameBufferPhysical = p_address;
+    gFrameBufferVirtual = v_address;
+
+    Device device;
+    memset((uint8*)&device, 0, sizeof(Device));
+    strcpy(device.name, "fb0");
+    device.deviceType = FT_CharacterDevice;
+    device.open = fb_open;
+    device.read = fb_read;
+    device.write = fb_write;
+    device.ioctl = fb_ioctl;
+    device.mmap = fb_mmap;
+    device.munmap = fb_munmap;
+
+    registerDevice(&device);
+}
+
+static BOOL fb_open(File *file, uint32 flags)
+{
+    return TRUE;
+}
+
+static int32 fb_read(File *file, uint32 size, uint8 *buffer)
+{
+    if (size == 0)
+    {
+        return 0;
+    }
+
+    return -1;
+}
+
+static int32 fb_write(File *file, uint32 size, uint8 *buffer)
+{
+    if (size == 0)
+    {
+        return 0;
+    }
+
+    int32 requestedSize = size;
+
+    int32 length = Gfx_GetWidth() * Gfx_GetHeight() * 4;
+
+    int32 availableSize = length - file->offset;
+
+    if (availableSize <= 0)
+    {
+        return -1;
+    }
+
+    int32 targetSize = MIN(requestedSize, availableSize);
+
+    memcpy(gFrameBufferVirtual + file->offset, buffer, targetSize);
+
+    file->offset += targetSize;
+
+    return targetSize;
+}
+
+static int32 fb_ioctl(File *node, int32 request, void * argp)
+{
+    int32 result = -1;
+
+    switch (request)
+    {
+    case FB_GET_WIDTH:
+        result = Gfx_GetWidth();
+        break;
+    case FB_GET_HEIGHT:
+        result = Gfx_GetHeight();
+        break;
+    case FB_GET_BITSPERPIXEL:
+        result = 32;
+        break;
+    }
+
+    return result;
+}
+
+static void* fb_mmap(File* file, uint32 size, uint32 offset, uint32 flags)
+{
+    return mapMemory(file->thread->owner, size, (uint32)(gFrameBufferPhysical + offset), NULL);
+}
+
+static BOOL fb_munmap(File* file, void* address, uint32 size)
+{
+    return unmapMemory(file->thread->owner, size, (uint32)address);
+}