aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2021-01-20 23:22:32 +0100
committerMarvin Borner2021-01-20 23:22:32 +0100
commit64ccbef99bdadc816e8c756ca8b5ae9a148a47fd (patch)
treedc53211d20a6b711b5076cbb46119c42f77caae6 /kernel
parent1ca3f322c81544ba769a0cd44fbd4bf03a8f875d (diff)
Added proc wait struct with function
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/fs.c1
-rw-r--r--kernel/features/proc.c15
-rw-r--r--kernel/features/syscall.c5
-rw-r--r--kernel/inc/proc.h8
4 files changed, 21 insertions, 8 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 48e736a..9918983 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -1,6 +1,7 @@
// MIT License, Copyright (c) 2020 Marvin Borner
#include <assert.h>
+#include <cpu.h>
#include <def.h>
#include <fs.h>
#include <ide.h>
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index af6a307..9af1ce4 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -125,21 +125,26 @@ void proc_exit(struct proc *proc, int status)
hlt();
}
-void proc_yield(struct regs *r)
+void proc_clear_quantum()
{
quantum = 0;
+}
+
+void proc_yield(struct regs *r)
+{
+ proc_clear_quantum();
scheduler(r);
}
void proc_enable_waiting(u32 dev_id)
{
- printf("ENABLING %d\n", dev_id);
struct node *iterator = proc_list->head;
while (iterator) {
struct proc *p = iterator->data;
- printf("\t-> %s: %d\n", p->name, p->waits_for);
- if (p && p->waits_for && p->waits_for == dev_id) {
- //printf("WAKING %s\n", p->name);
+ struct proc_wait *w = &p->wait;
+ if (p && w && w->id == dev_id) {
+ struct regs *r = &p->regs;
+ r->eax = (u32)w->func((char *)r->ebx, (void *)r->ecx, r->edx, r->esi);
p->state = PROC_RUNNING;
}
iterator = iterator->next;
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 59965a5..d980317 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -42,8 +42,9 @@ void syscall_handler(struct regs *r)
} else {
struct proc *p = proc_current();
p->state = PROC_SLEEPING;
- p->waits_for = vfs_find_dev((char *)r->ebx)->id;
- scheduler(r);
+ p->wait.id = vfs_find_dev((char *)r->ebx)->id;
+ p->wait.func = vfs_read;
+ proc_yield(r);
sti();
while (1)
hlt();
diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h
index 75978e9..30af5b1 100644
--- a/kernel/inc/proc.h
+++ b/kernel/inc/proc.h
@@ -19,13 +19,18 @@
enum proc_state { PROC_RUNNING, PROC_SLEEPING };
+struct proc_wait {
+ u32 id; // dev_id
+ u32 (*func)();
+};
+
struct proc {
u32 pid;
char name[32];
struct regs regs;
struct regs regs_backup;
+ struct proc_wait wait; // dev_id
enum proc_state state;
- u32 waits_for; // dev_id
struct stack *messages;
};
@@ -36,6 +41,7 @@ struct proc *proc_current(void);
struct proc *proc_from_pid(u32 pid);
void proc_exit(struct proc *proc, int status);
void proc_yield(struct regs *r);
+void proc_clear_quantum();
void proc_enable_waiting(u32 dev_id);
struct proc *proc_make(void);