2018-10-16 11:01:38 +02:00
|
|
|
#include "i386.h"
|
2018-11-01 13:15:46 +01:00
|
|
|
#include "Process.h"
|
2018-10-16 11:01:38 +02:00
|
|
|
#include "Syscall.h"
|
2018-10-23 15:19:02 +02:00
|
|
|
#include "Console.h"
|
2018-11-07 22:15:02 +01:00
|
|
|
#include "Scheduler.h"
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-31 00:23:46 +01:00
|
|
|
extern "C" void syscall_entry(RegisterDump&);
|
2018-10-16 11:01:38 +02:00
|
|
|
extern "C" void syscall_ISR();
|
|
|
|
extern volatile RegisterDump* syscallRegDump;
|
|
|
|
|
2018-11-09 12:20:44 +01:00
|
|
|
asm(
|
2018-10-16 11:01:38 +02:00
|
|
|
".globl syscall_ISR \n"
|
|
|
|
"syscall_ISR:\n"
|
|
|
|
" pusha\n"
|
|
|
|
" pushw %ds\n"
|
|
|
|
" pushw %es\n"
|
|
|
|
" pushw %fs\n"
|
|
|
|
" pushw %gs\n"
|
|
|
|
" pushw %ss\n"
|
|
|
|
" pushw %ss\n"
|
|
|
|
" pushw %ss\n"
|
|
|
|
" pushw %ss\n"
|
2018-10-23 10:12:50 +02:00
|
|
|
" pushw %ss\n"
|
2018-10-16 11:01:38 +02:00
|
|
|
" popw %ds\n"
|
|
|
|
" popw %es\n"
|
|
|
|
" popw %fs\n"
|
|
|
|
" popw %gs\n"
|
2018-10-31 00:23:46 +01:00
|
|
|
" mov %esp, %eax\n"
|
2018-10-16 11:01:38 +02:00
|
|
|
" call syscall_entry\n"
|
|
|
|
" popw %gs\n"
|
2018-10-23 10:12:50 +02:00
|
|
|
" popw %gs\n"
|
2018-10-16 11:01:38 +02:00
|
|
|
" popw %fs\n"
|
|
|
|
" popw %es\n"
|
|
|
|
" popw %ds\n"
|
|
|
|
" popa\n"
|
|
|
|
" iret\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
namespace Syscall {
|
|
|
|
|
|
|
|
void initialize()
|
|
|
|
{
|
|
|
|
registerUserCallableInterruptHandler(0x80, syscall_ISR);
|
|
|
|
kprintf("syscall: int 0x80 handler installed\n");
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:41:58 +01:00
|
|
|
static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
2018-10-29 21:54:11 +01:00
|
|
|
ASSERT_INTERRUPTS_ENABLED();
|
2018-10-16 11:01:38 +02:00
|
|
|
switch (function) {
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_yield:
|
2018-11-07 22:15:02 +01:00
|
|
|
Scheduler::yield();
|
2018-10-16 11:01:38 +02:00
|
|
|
break;
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_putch:
|
2018-10-23 15:19:02 +02:00
|
|
|
Console::the().putChar(arg1 & 0xff);
|
2018-10-16 11:01:38 +02:00
|
|
|
break;
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_sleep:
|
2018-11-07 21:19:47 +01:00
|
|
|
return current->sys$sleep((unsigned)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_gettimeofday:
|
2018-10-25 17:29:49 +02:00
|
|
|
return current->sys$gettimeofday((timeval*)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_get_dir_entries:
|
2018-10-24 12:43:52 +02:00
|
|
|
return current->sys$get_dir_entries((int)arg1, (void*)arg2, (size_t)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_lstat:
|
2018-10-27 00:29:31 +02:00
|
|
|
return current->sys$lstat((const char*)arg1, (Unix::stat*)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_stat:
|
2018-10-31 10:14:56 +01:00
|
|
|
return current->sys$stat((const char*)arg1, (Unix::stat*)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getcwd:
|
2018-10-24 14:28:22 +02:00
|
|
|
return current->sys$getcwd((char*)arg1, (size_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_open:
|
2018-10-29 21:54:11 +01:00
|
|
|
return current->sys$open((const char*)arg1, (int)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_write:
|
2018-10-30 15:33:37 +01:00
|
|
|
return current->sys$write((int)arg1, (const void*)arg2, (size_t)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_close:
|
2018-10-23 10:12:50 +02:00
|
|
|
//kprintf("syscall: close(%d)\n", arg1);
|
2018-10-16 11:01:38 +02:00
|
|
|
return current->sys$close((int)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_read:
|
2018-10-23 10:12:50 +02:00
|
|
|
//kprintf("syscall: read(%d, %p, %u)\n", arg1, arg2, arg3);
|
2018-10-16 11:01:38 +02:00
|
|
|
return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_lseek:
|
2018-10-31 17:50:43 +01:00
|
|
|
return current->sys$lseek((int)arg1, (off_t)arg2, (int)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_kill:
|
2018-10-16 11:01:38 +02:00
|
|
|
return current->sys$kill((pid_t)arg1, (int)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getuid:
|
2018-10-16 11:01:38 +02:00
|
|
|
return current->sys$getuid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getgid:
|
2018-10-22 13:55:11 +02:00
|
|
|
return current->sys$getgid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getpid:
|
2018-10-22 13:55:11 +02:00
|
|
|
return current->sys$getpid();
|
2018-11-06 13:33:06 +01:00
|
|
|
case Syscall::SC_getppid:
|
|
|
|
return current->sys$getppid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_waitpid:
|
2018-10-27 01:24:22 +02:00
|
|
|
return current->sys$waitpid((pid_t)arg1, (int*)arg2, (int)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_mmap:
|
2018-11-08 11:37:01 +01:00
|
|
|
return (dword)current->sys$mmap((const SC_mmap_params*)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_munmap:
|
2018-10-24 09:48:24 +02:00
|
|
|
return current->sys$munmap((void*)arg1, (size_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_gethostname:
|
2018-10-26 09:54:29 +02:00
|
|
|
return current->sys$gethostname((char*)arg1, (size_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_exit:
|
2018-10-23 15:19:02 +02:00
|
|
|
cli();
|
2018-10-22 11:43:55 +02:00
|
|
|
current->sys$exit((int)arg1);
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return 0;
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_get_arguments:
|
2018-10-26 11:16:56 +02:00
|
|
|
return current->sys$get_arguments((int*)arg1, (char***)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_get_environment:
|
2018-10-31 17:50:43 +01:00
|
|
|
return current->sys$get_environment((char***)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_chdir:
|
2018-10-26 14:24:11 +02:00
|
|
|
return current->sys$chdir((const char*)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_uname:
|
2018-10-26 14:56:21 +02:00
|
|
|
return current->sys$uname((utsname*)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_set_mmap_name:
|
2018-10-28 09:57:22 +01:00
|
|
|
return current->sys$set_mmap_name((void*)arg1, (size_t)arg2, (const char*)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_readlink:
|
2018-10-28 14:11:51 +01:00
|
|
|
return current->sys$readlink((const char*)arg1, (char*)arg2, (size_t)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_ttyname_r:
|
2018-10-30 22:03:02 +01:00
|
|
|
return current->sys$ttyname_r((int)arg1, (char*)arg2, (size_t)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_setsid:
|
2018-11-02 12:56:51 +01:00
|
|
|
return current->sys$setsid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getsid:
|
2018-11-02 12:56:51 +01:00
|
|
|
return current->sys$getsid((pid_t)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_setpgid:
|
2018-11-02 12:56:51 +01:00
|
|
|
return current->sys$setpgid((pid_t)arg1, (pid_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getpgid:
|
2018-11-02 12:56:51 +01:00
|
|
|
return current->sys$getpgid((pid_t)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getpgrp:
|
2018-11-02 12:56:51 +01:00
|
|
|
return current->sys$getpgrp();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_tcgetpgrp:
|
2018-11-02 13:14:25 +01:00
|
|
|
return current->sys$tcgetpgrp((int)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_tcsetpgrp:
|
2018-11-02 13:14:25 +01:00
|
|
|
return current->sys$tcsetpgrp((int)arg1, (pid_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_fork:
|
2018-11-02 20:41:58 +01:00
|
|
|
return current->sys$fork(regs);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_execve:
|
2018-11-03 01:49:40 +01:00
|
|
|
return current->sys$execve((const char*)arg1, (const char**)arg2, (const char**)arg3);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_geteuid:
|
2018-11-05 15:04:19 +01:00
|
|
|
return current->sys$geteuid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getegid:
|
2018-11-05 15:04:19 +01:00
|
|
|
return current->sys$getegid();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_signal:
|
2018-11-05 18:16:00 +01:00
|
|
|
return (dword)current->sys$signal((int)arg1, (Unix::sighandler_t)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_isatty:
|
2018-11-05 18:16:00 +01:00
|
|
|
return current->sys$isatty((int)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_getdtablesize:
|
2018-11-05 19:01:22 +01:00
|
|
|
return current->sys$getdtablesize();
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_dup:
|
2018-11-05 19:01:22 +01:00
|
|
|
return current->sys$dup((int)arg1);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_dup2:
|
2018-11-05 19:01:22 +01:00
|
|
|
return current->sys$dup2((int)arg1, (int)arg2);
|
2018-11-06 13:23:22 +01:00
|
|
|
case Syscall::SC_sigaction:
|
2018-11-06 10:46:40 +01:00
|
|
|
return current->sys$sigaction((int)arg1, (const Unix::sigaction*)arg2, (Unix::sigaction*)arg3);
|
2018-11-06 13:40:23 +01:00
|
|
|
case Syscall::SC_umask:
|
|
|
|
return current->sys$umask((mode_t)arg1);
|
2018-11-07 01:38:51 +01:00
|
|
|
case Syscall::SC_getgroups:
|
|
|
|
return current->sys$getgroups((int)arg1, (gid_t*)arg2);
|
|
|
|
case Syscall::SC_setgroups:
|
|
|
|
return current->sys$setgroups((size_t)arg1, (const gid_t*)arg2);
|
2018-11-07 21:19:47 +01:00
|
|
|
case Syscall::SC_sigreturn:
|
|
|
|
current->sys$sigreturn();
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return 0;
|
2018-10-16 11:01:38 +02:00
|
|
|
default:
|
2018-10-30 23:01:48 +01:00
|
|
|
kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3);
|
2018-10-16 11:01:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-31 00:23:46 +01:00
|
|
|
void syscall_entry(RegisterDump& regs)
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
|
|
|
DWORD function = regs.eax;
|
|
|
|
DWORD arg1 = regs.edx;
|
|
|
|
DWORD arg2 = regs.ecx;
|
|
|
|
DWORD arg3 = regs.ebx;
|
2018-11-02 20:41:58 +01:00
|
|
|
regs.eax = Syscall::handle(regs, function, arg1, arg2, arg3);
|
2018-10-16 11:01:38 +02:00
|
|
|
}
|
2018-11-02 20:41:58 +01:00
|
|
|
|