aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2021-01-10 13:19:50 +0100
committerMarvin Borner2021-01-10 13:19:50 +0100
commit3619c820f8ff5918cf122a031bde6305d32f6528 (patch)
tree2eb38cc5bfd51529a5e5c603ee9801569307ff17 /kernel
parentff9c7766edded74f4d522484c828b1bdc7dfa96d (diff)
Started procfs
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/fs.c8
-rw-r--r--kernel/features/proc.c38
-rw-r--r--kernel/inc/proc.h3
3 files changed, 43 insertions, 6 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 14e6a9c..ab2e236 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -185,14 +185,12 @@ void device_install(void)
{
devices = list_new();
- struct vfs *vfs;
- struct device *dev;
-
- vfs = malloc(sizeof(*vfs));
+ struct vfs *vfs = malloc(sizeof(*vfs));
vfs->type = VFS_DEVFS;
vfs->read = devfs_read;
- dev = malloc(sizeof(*dev));
+ struct device *dev = malloc(sizeof(*dev));
dev->name = "dev";
+ dev->type = DEV_CHAR;
dev->vfs = vfs;
device_add(dev);
vfs_mount(dev, "/dev/");
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index 93e97f1..499be81 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -3,6 +3,7 @@
#include <assert.h>
#include <boot.h>
#include <cpu.h>
+#include <fs.h>
#include <interrupts.h>
#include <list.h>
#include <load.h>
@@ -129,6 +130,7 @@ struct proc *proc_make(void)
{
struct proc *proc = malloc(sizeof(*proc));
proc->pid = current_pid++;
+ proc->messages = list_new();
proc->state = PROC_RUNNING;
if (current)
@@ -137,6 +139,31 @@ struct proc *proc_make(void)
return proc;
}
+u32 procfs_read(const char *path, void *buf, u32 offset, u32 count, struct device *dev)
+{
+ while (*path == '/')
+ path++;
+
+ int pid = 0;
+ while (path[0] >= '0' && path[0] <= '9') {
+ pid = pid * 10 + (path[0] - '0');
+ path++;
+ }
+
+ if (pid) {
+ struct proc *p = proc_from_pid(pid);
+ if (!p)
+ return 0;
+
+ if (!memcmp(path, "/status", 8)) {
+ printf("STATUS!\n");
+ }
+ }
+
+ printf("%s - off: %d, cnt: %d, buf: %x, dev %x\n", path, offset, count, buf, dev);
+ return count;
+}
+
extern void proc_jump_userspace(void);
u32 _esp, _eip;
@@ -149,6 +176,17 @@ void proc_init(void)
scheduler_enable();
proc_list = list_new();
+ // Procfs
+ struct vfs *vfs = malloc(sizeof(*vfs));
+ vfs->type = VFS_PROCFS;
+ vfs->read = procfs_read;
+ struct device *dev = malloc(sizeof(*dev));
+ dev->name = "proc";
+ dev->type = DEV_CHAR;
+ dev->vfs = vfs;
+ device_add(dev);
+ vfs_mount(dev, "/proc/");
+
kernel_proc = proc_make();
struct node *new = list_add(proc_list, proc_make());
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index c8fb3e2..7a479be 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -8,7 +8,7 @@
#include <list.h>
#include <sys.h>
-#define PROC_QUANTUM 100 // Milliseconds or something // TODO
+#define PROC_QUANTUM 42 // Milliseconds or something // TODO
#define EFLAGS_ALWAYS 0x2 // Always one
#define EFLAGS_INTERRUPTS 0x200 // Enable interrupts
@@ -24,6 +24,7 @@ struct proc {
struct regs regs;
struct regs regs_backup;
enum proc_state state;
+ struct list *messages;
};
struct proc *kernel_proc;