diff options
author | Marvin Borner | 2020-05-02 15:44:11 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-02 15:44:11 +0200 |
commit | aa8a8811818331cf511681327e3ba95e456f0d33 (patch) | |
tree | 852c314dae76e756863f94639ff45eff72834d5d /src/kernel/syscall/actions | |
parent | 2a0e810a473dea57fd1cd53ea424b61269c029ba (diff) |
Added many syscalls to get better POSIX compliance
Diffstat (limited to 'src/kernel/syscall/actions')
-rw-r--r-- | src/kernel/syscall/actions/sys_exit.c | 8 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_fork.c | 19 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_get_pid.c | 7 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_pointers.c | 20 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_putch.c | 9 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_read.c | 22 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_scancode.c | 11 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_write.c | 22 |
8 files changed, 78 insertions, 40 deletions
diff --git a/src/kernel/syscall/actions/sys_exit.c b/src/kernel/syscall/actions/sys_exit.c new file mode 100644 index 0000000..e2761fd --- /dev/null +++ b/src/kernel/syscall/actions/sys_exit.c @@ -0,0 +1,8 @@ +#include <stdint.h> +#include <kernel/tasks/process.h> + +uint32_t sys_exit(uint32_t code) +{ + current_proc->state = PROC_ASLEEP; + return code; +}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_fork.c b/src/kernel/syscall/actions/sys_fork.c new file mode 100644 index 0000000..af64ff9 --- /dev/null +++ b/src/kernel/syscall/actions/sys_fork.c @@ -0,0 +1,19 @@ +#include <stdint.h> +#include <kernel/interrupts/interrupts.h> +#include <kernel/memory/paging.h> +#include <kernel/tasks/process.h> +#include <kernel/lib/lib.h> + +uint32_t sys_fork(struct regs *r) +{ + struct page_directory *dir = paging_copy_user_directory(current_proc->cr3); + struct process *proc = process_make_new(); + proc->cr3 = dir; + memcpy(&proc->registers, r, sizeof(struct regs)); + proc->registers.eax = proc->pid; + proc->pid = current_proc->pid; + + process_spawn(proc); + + return 0; +}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_get_pid.c b/src/kernel/syscall/actions/sys_get_pid.c new file mode 100644 index 0000000..7631230 --- /dev/null +++ b/src/kernel/syscall/actions/sys_get_pid.c @@ -0,0 +1,7 @@ +#include <stdint.h> +#include <kernel/tasks/process.h> + +uint32_t sys_get_pid() +{ + return current_proc->pid; +}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_pointers.c b/src/kernel/syscall/actions/sys_pointers.c deleted file mode 100644 index 1a9a5cf..0000000 --- a/src/kernel/syscall/actions/sys_pointers.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdint.h> -#include <kernel/graphics/vesa.h> -#include <kernel/fs/load.h> -#include <kernel/memory/alloc.h> -#include <kernel/memory/paging.h> -#include <kernel/tasks/process.h> - -struct pointers { - struct vbe_mode_info *current_mode_info; - struct font *font; -}; - -uint32_t sys_pointers() -{ - struct pointers *pointers = umalloc(sizeof(struct vbe_mode_info) + sizeof(struct font)); - pointers->current_mode_info = current_mode_info; - pointers->font = font; - - return pointers; -}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_putch.c b/src/kernel/syscall/actions/sys_putch.c deleted file mode 100644 index beaa4a2..0000000 --- a/src/kernel/syscall/actions/sys_putch.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdint.h> -#include <kernel/lib/stdio.h> -#include <kernel/lib/string.h> - -uint32_t sys_putch(char ch) -{ - putch(ch); - return 0; -}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_read.c b/src/kernel/syscall/actions/sys_read.c new file mode 100644 index 0000000..a954f56 --- /dev/null +++ b/src/kernel/syscall/actions/sys_read.c @@ -0,0 +1,22 @@ +#include <stdint.h> +#include <kernel/fs/vfs.h> +#include <kernel/fs/ext2.h> +#include <kernel/lib/stdlib.h> +#include <kernel/memory/alloc.h> + +uint32_t sys_read(char *path, uint32_t offset, uint32_t count, char *buf) +{ + struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node)); + strcpy(node->name, path); + ext2_root->open(node); + if (node->inode != 0) { + uint32_t size = ((struct ext2_file *)node->impl)->inode.size; + ext2_root->read(node, 0, size, buf); + buf[size - 1] = '\0'; + ext2_root->close(node); + return size; + } else { + ext2_root->close(node); + return -1; + } +}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_scancode.c b/src/kernel/syscall/actions/sys_scancode.c deleted file mode 100644 index 612326a..0000000 --- a/src/kernel/syscall/actions/sys_scancode.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdint.h> -#include <kernel/input/input.h> -#include <kernel/io/io.h> - -uint32_t sys_scancode() -{ - sti(); - uint32_t key = wait_scancode(); - cli(); - return key; -}
\ No newline at end of file diff --git a/src/kernel/syscall/actions/sys_write.c b/src/kernel/syscall/actions/sys_write.c new file mode 100644 index 0000000..d79ef37 --- /dev/null +++ b/src/kernel/syscall/actions/sys_write.c @@ -0,0 +1,22 @@ +#include <stdint.h> +#include <kernel/fs/vfs.h> +#include <kernel/fs/ext2.h> +#include <kernel/lib/stdlib.h> +#include <kernel/memory/alloc.h> + +uint32_t sys_write(char *path, uint32_t offset, uint32_t count, char *buf) +{ + struct fs_node *node = (struct fs_node *)umalloc(sizeof(struct fs_node)); + strcpy(node->name, path); + ext2_root->open(node); + if (node->inode != 0) { + uint32_t size = ((struct ext2_file *)node->impl)->inode.size; + ext2_root->write(node, 0, size, buf); + buf[size - 1] = '\0'; + ext2_root->close(node); + return size; + } else { + ext2_root->close(node); + return -1; + } +}
\ No newline at end of file |