#include <stdint.h>
#include "syscall.h"
#include "errors.h"
#include "kprintf.h"
#include "sysdefs/syscall.h"
#include "ipcpipe.h"
#include "mman.h"
#include "sched.h"
#include "randcrypto.h"
#include "vfs.h"
#include "proc.h"
#include "fs.h"
#include "dev.h"
#include "time.h"
#include "ipcnetsock.h"

int32_t SYSCALL1(sys_debugprint, string) {
  char *p = (char *)string;
  kprintf("%s\n", p);
  return E_OK;
}

SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = {
  [SYS_DEBUGPRINT] = &sys_debugprint,

  [SYS_MMAN_MAP]   = &sys_mman_map,
  [SYS_MMAN_UNMAP] = &sys_mman_unmap,

  [SYS_SCHEDRELEASE] = &sys_schedrelease,

  [SYS_RAND]       = &sys_rand,

  [SYS_VFSMOUNT]   = &sys_vfsmount,
  [SYS_VFSUNMOUNT] = &sys_vfsunmount,

  [SYS_IPC_PIPEREAD]    = &sys_ipc_piperead,
  [SYS_IPC_PIPEWRITE]   = &sys_ipc_pipewrite,
  [SYS_IPC_PIPEMAKE]    = &sys_ipc_pipemake,
  [SYS_IPC_PIPEDELETE]  = &sys_ipc_pipedelete,
  [SYS_IPC_PIPECONNECT] = &sys_ipc_pipeconnect,

  [SYS_PROC_KILL]      = &sys_proc_kill,
  [SYS_PROC_SPAWN]     = &sys_proc_spawn,
  [SYS_PROC_POLLSTATE] = &sys_proc_pollstate,
  [SYS_PROC_GETPID]    = &sys_proc_getpid,
  [SYS_PROC_RUN]       = &sys_proc_run,
  [SYS_PROC_ARGLEN]    = &sys_proc_arglen,
  [SYS_PROC_ARGV]      = &sys_proc_argv,
  [SYS_PROC_LISTSIZE]  = &sys_proc_listsize,
  [SYS_PROC_STAT]      = &sys_proc_stat,

  [SYS_FS_OPENF]       = &sys_fs_openf,
  [SYS_FS_CLOSEF]      = &sys_fs_closef,
  [SYS_FS_READ]        = &sys_fs_read,
  [SYS_FS_WRITE]       = &sys_fs_write,
  [SYS_FS_STAT]        = &sys_fs_stat,
  [SYS_FS_FETCHDIRENT] = &sys_fs_fetchdirent,
  [SYS_FS_MKDIR]       = &sys_fs_mkdir,
  [SYS_FS_DELETE]      = &sys_fs_delete,

  [SYS_DEV_GETHANDLE] = &sys_dev_gethandle,
  [SYS_DEV_LISTSIZE]  = &sys_dev_listsize,
  [SYS_DEV_STAT]      = &sys_dev_stat,
  [SYS_DEV_CMD]       = &sys_dev_cmd,

  [SYS_TIME]    = &sys_time,

  [SYS_IPC_NETSOCKMAKE]     = &sys_ipc_netsockmake,
  [SYS_IPC_NETSOCKLISTEN]   = &sys_ipc_netsocklisten,
  [SYS_IPC_NETSOCKPOLLEV]   = &sys_ipc_netsockpollev,
};
