summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/init/main.c5
-rw-r--r--src/kernel/fd.c27
-rw-r--r--src/kernel/fd.h1
-rw-r--r--src/kernel/proc.c2
-rw-r--r--src/shared/magic.h3
5 files changed, 38 insertions, 0 deletions
diff --git a/src/init/main.c b/src/init/main.c
index 0c5f034..7c1c882 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -1,4 +1,5 @@
#include <kernel/syscalls.h>
+#include <shared/magic.h>
#include <stdint.h>
// takes a cstring and copies it right before a page boundary
@@ -24,6 +25,10 @@ int main() {
multipageify("/some/where/file"),
sizeof("/some/where/file") - 1);
+ _syscall_fd_write(FD_STDOUT, "fd test ", 8);
+ _syscall_fd_close(FD_STDOUT);
+ _syscall_fd_write(FD_STDOUT, "fd test ", 8); // should fail
+
_syscall_exit("bye from init! ",
sizeof("bye from init! ") - 1);
}
diff --git a/src/kernel/fd.c b/src/kernel/fd.c
index 7d448eb..e99fb7d 100644
--- a/src/kernel/fd.c
+++ b/src/kernel/fd.c
@@ -1,12 +1,39 @@
#include <kernel/fd.h>
+#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+static int fdop_special_tty(enum fdop fdop, struct fd *fd, void *ptr, size_t len);
+
int fdop_dispatch(enum fdop fdop, struct fd *fd, void *ptr, size_t len) {
switch(fd->type) {
case FD_EMPTY:
return -1;
+ case FD_SPECIAL_TTY:
+ return fdop_special_tty(fdop, fd, ptr, len);
default:
panic();
}
}
+
+static int fdop_special_tty(enum fdop fdop, struct fd *fd, void *ptr, size_t len) {
+ switch(fdop) {
+ case FDOP_READ:
+ return -1; // input not implemented yet
+
+ case FDOP_WRITE: {
+ struct virt_iter iter;
+ virt_iter_new(&iter, (void*)ptr, len,
+ process_current->pages, true, false);
+ while (virt_iter_next(&iter))
+ tty_write(iter.frag, iter.frag_len);
+ return iter.prior;
+ }
+
+ case FDOP_CLOSE:
+ fd->type = FD_EMPTY;
+ return 0;
+
+ default: panic();
+ }
+}
diff --git a/src/kernel/fd.h b/src/kernel/fd.h
index 7f7cbdd..6950b9b 100644
--- a/src/kernel/fd.h
+++ b/src/kernel/fd.h
@@ -7,6 +7,7 @@ typedef int fd_t; // TODO duplicated in syscalls.h
enum fd_type {
FD_EMPTY,
+ FD_SPECIAL_TTY,
};
struct fd {
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 4c278e6..15e1ef9 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -3,6 +3,7 @@
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/util.h>
+#include <shared/magic.h>
#include <stdint.h>
struct process *process_first;
@@ -23,6 +24,7 @@ struct process *process_seed() {
for (int i = 0; i < FD_MAX; i++)
proc->fds[i].type = FD_EMPTY;
+ proc->fds[FD_STDOUT].type = FD_SPECIAL_TTY;
// map the stack to the last page in memory
pagedir_map(proc->pages, (void*)~PAGE_MASK, page_alloc(1), true, true);
diff --git a/src/shared/magic.h b/src/shared/magic.h
new file mode 100644
index 0000000..cf126d7
--- /dev/null
+++ b/src/shared/magic.h
@@ -0,0 +1,3 @@
+#pragma once
+
+#define FD_STDOUT 0