/**
 * @file syscall.c
 * @brief Kernel syscall handler
 * 
 */

#include "syscall.h"
#include "offset.h"
#include "debug.h"


/**
 * @brief Syscall is called from the exception handler.
 *
 * The context of the calling thread is stored on the stack and remains
 * accessible via kernel_stack_context pointer from the thread structure
 * and appropriate offset as defined in "offset.h".
 *
 * The SYSCALL instruction produces an exception of type syscall. This is
 * the only way to enter kernel from userspace (e.i. this exception is not
 * a result of error condition). The SYSCALL opcode allows to specify the
 * syscall number, which can be then used for decoding syscall parameters
 * and dispatching of the syscal. The EPC register which is also stored in
 * the context allows the handler to do so. Special care must be taken for
 * exceptions that occurred in branch delay slot.
 *
 * Before returning, the routine has to increase the return address to
 * point at the next instruction beyond EPC. This may be a non-trivial
 * problem if the syscall instruction was in the branch delay slot. To
 * simplify the handler, one may make such behavior illegal.
 * 
 */
void
syscall (void)
{
	/*
	 * The syscall handler is for others to write. For now, just
	 * dump the registers and halt the machine.
	 */
	___reg_view ();
	___halt ();
}
