sched: properly implement blocking for read
This is a milestone update, as userspace applications are now able to properly read from TTY devices, be blocked while waiting, and write the output back. Userspace development will move much faster now that these kinks have been worked out. This version will be tagged as vbos v0.01 Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
52ba70f4b7
commit
b753afd4fb
9 changed files with 74 additions and 54 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#define __ASM__
|
||||
#include <dev/serial.h>
|
||||
#include <lib/errno.h>
|
||||
|
||||
.macro save_context
|
||||
pushq %rax
|
||||
|
|
@ -202,25 +203,14 @@ gate_syscall:
|
|||
movq %r10, %rcx
|
||||
save_context
|
||||
save_iretq_frame
|
||||
pushq %rax
|
||||
movq 0(%rax), %rdi
|
||||
movq 40(%rax), %rsi
|
||||
movq 32(%rax), %rdx
|
||||
movq 24(%rax), %rcx
|
||||
movq 16(%rax), %r8
|
||||
movq 56(%rax), %r9
|
||||
sti
|
||||
|
||||
call syscall
|
||||
popq %rdi
|
||||
movq %rax, 0(%rdi)
|
||||
call schedule
|
||||
|
||||
.global syscall_block
|
||||
syscall_block:
|
||||
cli
|
||||
save_context
|
||||
save_iretq_frame
|
||||
call schedule
|
||||
|
||||
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
|
||||
|
|
|
|||
|
|
@ -146,8 +146,9 @@ void schedule()
|
|||
spinlock_release(&proc->lock);
|
||||
}
|
||||
|
||||
size_t num_procs = proc_tree->num_nodes;
|
||||
size_t counter = 0;
|
||||
size_t limit = 1000000;
|
||||
size_t limit = num_procs * 2;
|
||||
while (counter++ < limit) {
|
||||
/* next process */
|
||||
proc = proc_next(proc);
|
||||
|
|
@ -158,6 +159,7 @@ void schedule()
|
|||
/* fallthrough */
|
||||
case PROC_STOPPED:
|
||||
proc->state = PROC_RUNNING;
|
||||
proc_set_current(proc->pid);
|
||||
spinlock_release(&proc->lock);
|
||||
_return_to_user(&proc->regs, proc->cr3);
|
||||
|
||||
|
|
@ -169,6 +171,7 @@ void schedule()
|
|||
}
|
||||
}
|
||||
|
||||
proc_set_current(0);
|
||||
sti();
|
||||
yield();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include "lib/errno.h"
|
||||
#include <kernel/lock.h>
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/proc.h>
|
||||
|
|
@ -15,14 +16,19 @@ typedef void *(*syscall_t)(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t
|
|||
syscall_t syscall_table[SYSCALL_MAX];
|
||||
slab_t *fd_slab;
|
||||
|
||||
uint64_t syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5)
|
||||
void syscall(uint64_t syscall_no, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5)
|
||||
{
|
||||
syscall_t syscall = (void *)syscall_table[syscall_no];
|
||||
|
||||
if (syscall == NULL)
|
||||
return -ENOSYS;
|
||||
sys_set_return(proc_find(getpid()), ENOSYS);
|
||||
|
||||
return (uint64_t)syscall(arg1, arg2, arg3, arg4, arg5);
|
||||
ssize_t ret = (ssize_t)syscall(arg1, arg2, arg3, arg4, arg5);
|
||||
|
||||
if (ret >= 0)
|
||||
sys_set_return(proc_find(getpid()), ret);
|
||||
|
||||
schedule();
|
||||
}
|
||||
|
||||
void sys_set_return(struct proc *proc, uint64_t ret)
|
||||
|
|
@ -62,7 +68,7 @@ ssize_t sys_read(int fd, void *buf, size_t count)
|
|||
if (file_type == VFS_VNO_CHARDEV && ret == -EAGAIN) {
|
||||
struct char_device *dev = vfs_file_dev(file);
|
||||
proc_block(proc, dev, buf, true, count);
|
||||
schedule();
|
||||
return -ESYSCALLBLK;
|
||||
}
|
||||
|
||||
proc->state = PROC_RUNNING;
|
||||
|
|
|
|||
Loading…
Reference in a new issue