sched: fix page faulting on process switching
This is the first version of the kernel with fully isolated threads for user and kernel tasks, where process 0 is only used for scheduling and interrupt handling. User process have a "buddy" kernel process that handles its tasks in the kernel. This system allows for easy blocking of threads without much need for thought. Just `sswtch` in an infinite read loop, and your userspace process will be blocked. Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
72827c1e00
commit
f92e88597d
8 changed files with 125 additions and 30 deletions
19
dev/serial.c
19
dev/serial.c
|
|
@ -60,14 +60,19 @@ inline void serial_putchar(char c)
|
|||
outb(COM1, c);
|
||||
}
|
||||
|
||||
void serial_trap()
|
||||
void serial_read_line()
|
||||
{
|
||||
while ((inb(COM1 | 5) & 0x01) == 0)
|
||||
;
|
||||
if ((inb(COM1 | 5) & 0x01) == 0)
|
||||
return;
|
||||
|
||||
char c = inb(COM1);
|
||||
|
||||
ringbuf_write(tty0->data, &c, 1);
|
||||
}
|
||||
|
||||
void serial_trap()
|
||||
{
|
||||
serial_read_line();
|
||||
lapic_eoi();
|
||||
}
|
||||
|
||||
|
|
@ -77,14 +82,12 @@ ssize_t serial_read(char *buf)
|
|||
|
||||
char c;
|
||||
|
||||
serial_read_line();
|
||||
|
||||
struct proc *proc = proc_find(getpid());
|
||||
|
||||
serial_trap();
|
||||
|
||||
while ((ret = ringbuf_read(tty0->data, &c, 1)) == 0) {
|
||||
_save_context();
|
||||
sti();
|
||||
yield();
|
||||
sswtch();
|
||||
}
|
||||
|
||||
copy_to_user(proc, buf, &c, 1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue