Skip to content

Commit

Permalink
System calls reorganized into the relevant source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
pykello committed Aug 19, 2014
1 parent f81b46a commit fc6a5bb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
4 changes: 4 additions & 0 deletions include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions include/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions kernel/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
37 changes: 0 additions & 37 deletions kernel/ksyscall.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#include <console.h>
#include <klib.h>
#include <ksyscall.h>
#include <lib/string.h>
#include <lib/syscall.h>
#include <monitor.h>
#include <proc.h>
#include <system.h>

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,
Expand All @@ -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();
}
1 change: 1 addition & 0 deletions kernel/proc/build.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PROC_DIR = kernel/proc

OBJS += $(PROC_DIR)/proc.o
OBJS += $(PROC_DIR)/syscall_exit.o
22 changes: 22 additions & 0 deletions kernel/proc/syscall_exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <ksyscall.h>
#include <proc.h>
#include <monitor.h>
#include <system.h>
#include <vm.h>

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;
}

0 comments on commit fc6a5bb

Please sign in to comment.