From fc6a5bbbbdb527804987445c691c164adb9be094 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Tue, 19 Aug 2014 22:56:48 +0300 Subject: [PATCH] System calls reorganized into the relevant source files. --- include/console.h | 4 ++++ include/proc.h | 3 +++ kernel/console.c | 11 +++++++++++ kernel/ksyscall.c | 37 ------------------------------------- kernel/proc/build.mk | 1 + kernel/proc/syscall_exit.c | 22 ++++++++++++++++++++++ 6 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 kernel/proc/syscall_exit.c diff --git a/include/console.h b/include/console.h index 54be02f..5cad942 100644 --- a/include/console.h +++ b/include/console.h @@ -54,4 +54,8 @@ void uart_transmit(char c); bool uart_can_receive(void); int uart_receive(void); +/* system calls */ +int syscall_putch(int c); +int syscall_getch(void); + #endif diff --git a/include/proc.h b/include/proc.h index ceb920a..700af0e 100644 --- a/include/proc.h +++ b/include/proc.h @@ -88,4 +88,7 @@ void proc_shrink_memory(struct Process *proc, int page_count); bool proc_load(struct Process *proc, char **proc_image, int page_count); void proc_start(struct Process *proc); +/* system calls */ +int syscall_exit(int arg1); + #endif diff --git a/kernel/console.c b/kernel/console.c index 8f98ea2..67de82f 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -54,6 +54,12 @@ void kputch(int c) } } +int syscall_putch(int c) +{ + kputch(c); + return 0; +} + /* * kgetch reads the next available character from receive_buffer. If the buffer * is empty, this function returns 0. @@ -80,6 +86,11 @@ int kgetch(void) return keycode; } +int syscall_getch(void) +{ + return kgetch(); +} + /* * uart_interrupt_handler reads a character from the uart0 serial port, and * puts it into receive_buffer. If the buffer is full, the character is ignored. diff --git a/kernel/ksyscall.c b/kernel/ksyscall.c index 7da6e49..52d517f 100644 --- a/kernel/ksyscall.c +++ b/kernel/ksyscall.c @@ -1,15 +1,6 @@ #include -#include -#include -#include #include -#include #include -#include - -static int syscall_exit(int arg1); -static int syscall_putch(int arg1); -static int syscall_getch(void); static int (*const syscall_handler[])() = { [SYSCALL_EXIT] = syscall_exit, @@ -22,31 +13,3 @@ int handle_syscall(enum SystemCallCode code, int arg1, int arg2, int arg3) { return syscall_handler[code](arg1, arg2, arg3); } - -static int syscall_exit(int arg1) -{ - (void) arg1; - if (current_process == NULL) - return -1; - - set_translation_table_base((uint32_t) V2P(kernel_vm)); - proc_free(current_process); - current_process = NULL; - - __asm__ volatile("ldr sp, =kernel_stack_start"); - enable_interrupts(); - monitor(); - - return 0; -} - -static int syscall_putch(int arg1) -{ - kputch(arg1); - return 0; -} - -static int syscall_getch(void) -{ - return kgetch(); -} diff --git a/kernel/proc/build.mk b/kernel/proc/build.mk index 7cae69e..c8cb46d 100644 --- a/kernel/proc/build.mk +++ b/kernel/proc/build.mk @@ -1,3 +1,4 @@ PROC_DIR = kernel/proc OBJS += $(PROC_DIR)/proc.o +OBJS += $(PROC_DIR)/syscall_exit.o diff --git a/kernel/proc/syscall_exit.c b/kernel/proc/syscall_exit.c new file mode 100644 index 0000000..caf180d --- /dev/null +++ b/kernel/proc/syscall_exit.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +int syscall_exit(int arg1) +{ + (void) arg1; + if (current_process == NULL) + return -1; + + set_translation_table_base((uint32_t) V2P(kernel_vm)); + proc_free(current_process); + current_process = NULL; + + __asm__ volatile("ldr sp, =kernel_stack_start"); + enable_interrupts(); + monitor(); + + return 0; +} \ No newline at end of file