aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/init.c6
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/drivers/fb.c45
-rw-r--r--kernel/features/fs.c46
-rw-r--r--kernel/features/proc.c9
-rw-r--r--kernel/features/syscall.c5
-rw-r--r--kernel/inc/boot.h1
-rw-r--r--kernel/inc/fb.h10
-rw-r--r--kernel/inc/fs.h4
-rw-r--r--kernel/main.c8
-rw-r--r--libc/inc/ioctl.h11
-rw-r--r--libc/inc/sys.h2
12 files changed, 123 insertions, 25 deletions
diff --git a/apps/init.c b/apps/init.c
index 9e57078..6503022 100644
--- a/apps/init.c
+++ b/apps/init.c
@@ -8,13 +8,11 @@
int main(int argc, char **argv)
{
- log("Loaded!\n");
+ log("%s loaded\n", argv[0]);
while (1) {
};
- (void)argc;
- log("%s loaded\n", argv[0]);
- int wm = exec("/bin/wm", "wm", argv[1], NULL);
+ int wm = exec("/bin/wm", "wm", NULL);
int test = exec("/bin/window", "test", NULL);
return wm + test;
diff --git a/kernel/Makefile b/kernel/Makefile
index 2db201b..e9ade73 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -8,6 +8,7 @@ COBJS = main.o \
drivers/mouse.o \
drivers/pci.o \
drivers/ide.o \
+ drivers/fb.o \
drivers/timer.o \
drivers/rtl8139.o \
features/mm.o \
diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c
new file mode 100644
index 0000000..a1a7729
--- /dev/null
+++ b/kernel/drivers/fb.c
@@ -0,0 +1,45 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#include <def.h>
+#include <fb.h>
+#include <fs.h>
+#include <ioctl.h>
+#include <mem.h>
+#include <str.h>
+#include <sys.h>
+
+static u32 dev_id = 0;
+static struct vid_info *info = NULL;
+
+static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev)
+{
+ UNUSED(arg2);
+ UNUSED(arg3);
+ UNUSED(dev);
+
+ switch (request) {
+ case IO_FB_GET:
+ memcpy(arg1, info->vbe, 256);
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+static u8 fb_ready(void)
+{
+ return 1;
+}
+
+void fb_install(struct vid_info *boot)
+{
+ info = boot;
+
+ struct device *dev = zalloc(sizeof(*dev));
+ dev->name = strdup("fb");
+ dev->type = DEV_CHAR;
+ dev->ioctl = fb_ioctl;
+ dev->ready = fb_ready;
+ device_add(dev);
+ dev_id = dev->id;
+}
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 687d7ad..4d19dde 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -131,7 +131,8 @@ s32 vfs_read(const char *path, void *buf, u32 offset, u32 count)
path++;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs && m->dev->vfs->read && m->dev->vfs->perm);
+ if (!(m && m->dev && m->dev->vfs && m->dev->vfs->read && m->dev->vfs->perm))
+ return -1;
u32 len = strlen(m->path);
if (len > 1)
@@ -156,7 +157,8 @@ s32 vfs_write(const char *path, void *buf, u32 offset, u32 count)
path++;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs && m->dev->vfs->write && m->dev->vfs->perm);
+ if (!(m && m->dev && m->dev->vfs && m->dev->vfs->write && m->dev->vfs->perm))
+ return -1;
u32 len = strlen(m->path);
if (len > 1)
@@ -168,6 +170,25 @@ s32 vfs_write(const char *path, void *buf, u32 offset, u32 count)
return m->dev->vfs->write(path, buf, offset, count, m->dev);
}
+s32 vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3)
+{
+ while (*path == ' ')
+ path++;
+
+ struct mount_info *m = vfs_find_mount_info(path);
+ if (!(m && m->dev && m->dev->vfs && m->dev->vfs->ioctl && m->dev->vfs->perm))
+ return -1;
+
+ u32 len = strlen(m->path);
+ if (len > 1)
+ path += len;
+
+ if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super())
+ return -1;
+
+ return m->dev->vfs->ioctl(path, request, arg1, arg2, arg3, m->dev);
+}
+
s32 vfs_stat(const char *path, struct stat *buf)
{
while (*path == ' ')
@@ -177,12 +198,16 @@ s32 vfs_stat(const char *path, struct stat *buf)
return -1;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs && m->dev->vfs->stat);
+ if (!(m && m->dev && m->dev->vfs && m->dev->vfs->stat && m->dev->vfs->perm))
+ return -1;
u32 len = strlen(m->path);
if (len > 1)
path += len;
+ if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super())
+ return -1;
+
return m->dev->vfs->stat(path, buf, m->dev);
}
@@ -192,7 +217,8 @@ s32 vfs_wait(const char *path, u32 func_ptr)
path++;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs);
+ if (!(m && m->dev && m->dev->vfs))
+ return -1;
// Default wait
if (!m->dev->vfs->wait) {
@@ -280,10 +306,19 @@ static s32 devfs_read(const char *path, void *buf, u32 offset, u32 count, struct
{
struct device *target = device_get_by_name(path + 1);
if (!target || !target->read)
- return 0;
+ return -1;
return target->read(buf, offset, count, dev);
}
+static s32 devfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3,
+ struct device *dev)
+{
+ struct device *target = device_get_by_name(path + 1);
+ if (!target || !target->ioctl)
+ return -1;
+ return target->ioctl(request, arg1, arg2, arg3, dev);
+}
+
static u8 devfs_perm(const char *path, enum vfs_perm perm, struct device *dev)
{
(void)path;
@@ -309,6 +344,7 @@ void device_install(void)
struct vfs *vfs = zalloc(sizeof(*vfs));
vfs->type = VFS_DEVFS;
vfs->read = devfs_read;
+ vfs->ioctl = devfs_ioctl;
vfs->perm = devfs_perm;
vfs->ready = devfs_ready;
struct device *dev = zalloc(sizeof(*dev));
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index db2291c..38d88f8 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -479,15 +479,6 @@ void proc_init(void)
_eip = ((struct proc *)new->data)->regs.eip;
_esp = ((struct proc *)new->data)->regs.useresp;
- /* u32 argc = 2; */
- /* char **argv = malloc(sizeof(*argv) * (argc + 1)); */
- /* argv[0] = strdup("init"); */
- /* argv[1] = (char *)boot_passed->vbe; */
- /* argv[2] = NULL; */
-
- /* ((u32 *)_esp)[0] = argc; // First argument (argc) */
- /* ((u32 *)_esp)[-1] = (u32)argv; // Second argument (argv) */
-
printf("Jumping to userspace!\n");
memory_switch_dir(((struct proc *)new->data)->page_dir);
proc_jump_userspace();
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index b3e69e0..bac1738 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -52,6 +52,11 @@ static void syscall_handler(struct regs *r)
r->eax = (u32)vfs_write((char *)r->ebx, (void *)r->ecx, r->edx, r->esi);
break;
}
+ case SYS_IOCTL: {
+ r->eax = (u32)vfs_ioctl((char *)r->ebx, r->ecx, (void *)r->edx, (void *)r->esi,
+ (void *)r->edi);
+ break;
+ }
case SYS_POLL: {
s32 ret = vfs_poll((const char **)r->ebx);
if (ret == PROC_MAX_WAIT_IDS + 1)
diff --git a/kernel/inc/boot.h b/kernel/inc/boot.h
index 052a56f..7f085cd 100644
--- a/kernel/inc/boot.h
+++ b/kernel/inc/boot.h
@@ -6,7 +6,6 @@
#include <def.h>
-extern struct vid_info *boot_passed;
struct vid_info {
u32 mode;
u32 *vbe;
diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h
new file mode 100644
index 0000000..3e7b08f
--- /dev/null
+++ b/kernel/inc/fb.h
@@ -0,0 +1,10 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef FB
+#define FB
+
+#include <boot.h>
+
+void fb_install(struct vid_info *boot);
+
+#endif
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index 33b1afb..cd97b99 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -20,6 +20,7 @@ struct device {
void *data;
s32 (*read)(void *buf, u32 offset, u32 count, struct device *dev);
s32 (*write)(void *buf, u32 offset, u32 count, struct device *dev);
+ s32 (*ioctl)(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev);
u8 (*ready)(void);
};
@@ -40,6 +41,8 @@ struct vfs {
void *data;
s32 (*read)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
s32 (*write)(const char *path, void *buf, u32 offset, u32 count, struct device *dev);
+ s32 (*ioctl)(const char *path, u32 request, void *arg1, void *arg2, void *arg3,
+ struct device *dev);
s32 (*stat)(const char *path, struct stat *buf, struct device *dev);
s32 (*wait)(const char *path, u32 func_ptr, struct device *dev);
u8 (*perm)(const char *path, enum vfs_perm perm, struct device *dev);
@@ -60,6 +63,7 @@ struct device *vfs_find_dev(const char *path);
s32 vfs_read(const char *path, void *buf, u32 offset, u32 count);
s32 vfs_write(const char *path, void *buf, u32 offset, u32 count);
+s32 vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3);
s32 vfs_stat(const char *path, struct stat *buf);
s32 vfs_wait(const char *path, u32 func_ptr);
s32 vfs_poll(const char **files);
diff --git a/kernel/main.c b/kernel/main.c
index 8247672..118fe11 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -2,6 +2,7 @@
#include <boot.h>
#include <cpu.h>
+#include <fb.h>
#include <fs.h>
#include <ide.h>
#include <interrupts.h>
@@ -17,10 +18,6 @@
#include <syscall.h>
#include <timer.h>
-#include <print.h>
-
-struct vid_info *boot_passed;
-
void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info); // Decl
void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info)
{
@@ -35,8 +32,6 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info)
memory_install(mem_info);
- boot_passed = vid_info;
-
cpu_enable_features();
cpu_print();
srand(rdseed());
@@ -50,6 +45,7 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info)
timer_install();
keyboard_install();
mouse_install();
+ fb_install(vid_info);
/* net_install(); */
// Enable drivers
diff --git a/libc/inc/ioctl.h b/libc/inc/ioctl.h
new file mode 100644
index 0000000..c3eec56
--- /dev/null
+++ b/libc/inc/ioctl.h
@@ -0,0 +1,11 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef IOCTL
+#define IOCTL
+
+// FB interface
+#define IO_FB_GET 0
+
+int ioctl_is_awesome; // GCC is not
+
+#endif
diff --git a/libc/inc/sys.h b/libc/inc/sys.h
index 5858579..c20eabc 100644
--- a/libc/inc/sys.h
+++ b/libc/inc/sys.h
@@ -16,6 +16,7 @@ enum sys {
SYS_STAT, // Get file information
SYS_READ, // Read file
SYS_WRITE, // Write to file
+ SYS_IOCTL, // Interact with a file/device
SYS_POLL, // Wait for multiple files
SYS_EXEC, // Execute path
SYS_EXIT, // Exit current process // TODO: Free all memory of process
@@ -70,6 +71,7 @@ int sysv(enum sys num, ...);
(s32) sys4(SYS_READ, (int)(path), (int)(buf), (int)(offset), (int)(count))
#define write(path, buf, offset, count) \
(s32) sys4(SYS_WRITE, (int)(path), (int)(buf), (int)(offset), (int)(count))
+#define ioctl(path, ...) (s32) sysv(SYS_IOCTL, (int)(path), ##__VA_ARGS__)
#define stat(path, stat) (s32) sys2(SYS_STAT, (int)(path), (int)(stat))
#define poll(files) (s32) sys1(SYS_POLL, (int)(files))
#define exec(path, ...) (s32) sysv(SYS_EXEC, (int)(path), ##__VA_ARGS__)