2018-10-16 09:01:38 +00:00
|
|
|
#include "i386.h"
|
|
|
|
#include "Task.h"
|
|
|
|
#include "Syscall.h"
|
2018-10-23 13:19:02 +00:00
|
|
|
#include "Console.h"
|
2018-10-23 21:32:53 +00:00
|
|
|
#include <AK/Lock.h>
|
2018-10-16 09:01:38 +00:00
|
|
|
|
|
|
|
extern "C" void syscall_entry();
|
|
|
|
extern "C" void syscall_ISR();
|
|
|
|
extern volatile RegisterDump* syscallRegDump;
|
|
|
|
|
|
|
|
asm(
|
|
|
|
".globl syscall_ISR \n"
|
|
|
|
".globl syscallRegDump \n"
|
|
|
|
"syscallRegDump: \n"
|
|
|
|
".long 0\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 08:12:50 +00:00
|
|
|
" pushw %ss\n"
|
2018-10-16 09:01:38 +00:00
|
|
|
" popw %ds\n"
|
|
|
|
" popw %es\n"
|
|
|
|
" popw %fs\n"
|
|
|
|
" popw %gs\n"
|
|
|
|
" mov %esp, syscallRegDump\n"
|
|
|
|
" call syscall_entry\n"
|
|
|
|
" popw %gs\n"
|
2018-10-23 08:12:50 +00:00
|
|
|
" popw %gs\n"
|
2018-10-16 09:01:38 +00:00
|
|
|
" popw %fs\n"
|
|
|
|
" popw %es\n"
|
|
|
|
" popw %ds\n"
|
|
|
|
" popa\n"
|
|
|
|
" iret\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
namespace Syscall {
|
|
|
|
|
2018-10-23 13:19:02 +00:00
|
|
|
static SpinLock* s_lock;
|
|
|
|
|
2018-10-16 09:01:38 +00:00
|
|
|
void initialize()
|
|
|
|
{
|
2018-10-23 13:19:02 +00:00
|
|
|
s_lock = new SpinLock;
|
2018-10-16 09:01:38 +00:00
|
|
|
registerUserCallableInterruptHandler(0x80, syscall_ISR);
|
|
|
|
kprintf("syscall: int 0x80 handler installed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
|
|
|
{
|
2018-10-23 13:19:02 +00:00
|
|
|
Locker locker(*s_lock);
|
2018-10-16 09:01:38 +00:00
|
|
|
switch (function) {
|
|
|
|
case Syscall::Yield:
|
|
|
|
yield();
|
|
|
|
break;
|
2018-10-22 09:53:30 +00:00
|
|
|
case Syscall::PutCharacter:
|
2018-10-23 13:19:02 +00:00
|
|
|
Console::the().putChar(arg1 & 0xff);
|
2018-10-16 09:01:38 +00:00
|
|
|
break;
|
|
|
|
case Syscall::Sleep:
|
2018-10-25 15:29:49 +00:00
|
|
|
return current->sys$sleep(arg1);
|
|
|
|
case Syscall::PosixGettimeofday:
|
|
|
|
return current->sys$gettimeofday((timeval*)arg1);
|
2018-10-23 08:12:50 +00:00
|
|
|
case Syscall::Spawn:
|
2018-10-26 09:16:56 +00:00
|
|
|
return current->sys$spawn((const char*)arg1, (const char**)arg2);
|
2018-10-24 10:43:52 +00:00
|
|
|
case Syscall::GetDirEntries:
|
|
|
|
return current->sys$get_dir_entries((int)arg1, (void*)arg2, (size_t)arg3);
|
2018-10-24 11:19:36 +00:00
|
|
|
case Syscall::PosixLstat:
|
2018-10-26 22:29:31 +00:00
|
|
|
return current->sys$lstat((const char*)arg1, (Unix::stat*)arg2);
|
2018-10-24 12:28:22 +00:00
|
|
|
case Syscall::PosixGetcwd:
|
|
|
|
return current->sys$getcwd((char*)arg1, (size_t)arg2);
|
2018-10-16 09:01:38 +00:00
|
|
|
case Syscall::PosixOpen:
|
2018-10-23 08:12:50 +00:00
|
|
|
//kprintf("syscall: open('%s', %u)\n", arg1, arg2);
|
2018-10-16 09:01:38 +00:00
|
|
|
return current->sys$open((const char*)arg1, (size_t)arg2);
|
|
|
|
case Syscall::PosixClose:
|
2018-10-23 08:12:50 +00:00
|
|
|
//kprintf("syscall: close(%d)\n", arg1);
|
2018-10-16 09:01:38 +00:00
|
|
|
return current->sys$close((int)arg1);
|
|
|
|
case Syscall::PosixRead:
|
2018-10-23 08:12:50 +00:00
|
|
|
//kprintf("syscall: read(%d, %p, %u)\n", arg1, arg2, arg3);
|
2018-10-16 09:01:38 +00:00
|
|
|
return current->sys$read((int)arg1, (void*)arg2, (size_t)arg3);
|
|
|
|
case Syscall::PosixSeek:
|
|
|
|
// FIXME: This has the wrong signature, should be like lseek()
|
2018-10-23 13:19:02 +00:00
|
|
|
kprintf("syscall: seek(%d, %d)\n", arg1, arg2);
|
|
|
|
return current->sys$seek((int)arg1, (int)arg2);
|
2018-10-16 09:01:38 +00:00
|
|
|
case Syscall::PosixKill:
|
|
|
|
kprintf("syscall: kill(%d, %d)\n", arg1, arg2);
|
|
|
|
return current->sys$kill((pid_t)arg1, (int)arg2);
|
|
|
|
case Syscall::PosixGetuid:
|
|
|
|
return current->sys$getuid();
|
2018-10-22 11:55:11 +00:00
|
|
|
case Syscall::PosixGetgid:
|
|
|
|
return current->sys$getgid();
|
|
|
|
case Syscall::PosixGetpid:
|
|
|
|
return current->sys$getpid();
|
2018-10-23 22:20:34 +00:00
|
|
|
case Syscall::PosixWaitpid:
|
2018-10-26 23:24:22 +00:00
|
|
|
return current->sys$waitpid((pid_t)arg1, (int*)arg2, (int)arg3);
|
2018-10-24 07:48:24 +00:00
|
|
|
case Syscall::PosixMmap:
|
|
|
|
return (dword)current->sys$mmap((void*)arg1, (size_t)arg2);
|
|
|
|
case Syscall::PosixMunmap:
|
|
|
|
return current->sys$munmap((void*)arg1, (size_t)arg2);
|
2018-10-26 07:54:29 +00:00
|
|
|
case Syscall::PosixGethostname:
|
|
|
|
return current->sys$gethostname((char*)arg1, (size_t)arg2);
|
2018-10-22 09:43:55 +00:00
|
|
|
case Syscall::PosixExit:
|
2018-10-23 13:19:02 +00:00
|
|
|
cli();
|
|
|
|
locker.unlock();
|
2018-10-22 09:43:55 +00:00
|
|
|
current->sys$exit((int)arg1);
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
return 0;
|
2018-10-26 09:16:56 +00:00
|
|
|
case Syscall::GetArguments:
|
|
|
|
return current->sys$get_arguments((int*)arg1, (char***)arg2);
|
2018-10-26 12:24:11 +00:00
|
|
|
case Syscall::PosixChdir:
|
|
|
|
return current->sys$chdir((const char*)arg1);
|
2018-10-26 12:56:21 +00:00
|
|
|
case Syscall::PosixUname:
|
|
|
|
return current->sys$uname((utsname*)arg1);
|
2018-10-28 08:57:22 +00:00
|
|
|
case Syscall::SetMmapName:
|
|
|
|
return current->sys$set_mmap_name((void*)arg1, (size_t)arg2, (const char*)arg3);
|
2018-10-28 13:11:51 +00:00
|
|
|
case Syscall::PosixReadlink:
|
|
|
|
return current->sys$readlink((const char*)arg1, (char*)arg2, (size_t)arg3);
|
2018-10-16 09:01:38 +00:00
|
|
|
default:
|
|
|
|
kprintf("int0x80: Unknown function %x requested {%x, %x, %x}\n", function, arg1, arg2, arg3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void syscall_entry()
|
|
|
|
{
|
|
|
|
auto& regs = *syscallRegDump;
|
|
|
|
DWORD function = regs.eax;
|
|
|
|
DWORD arg1 = regs.edx;
|
|
|
|
DWORD arg2 = regs.ecx;
|
|
|
|
DWORD arg3 = regs.ebx;
|
|
|
|
regs.eax = Syscall::handle(function, arg1, arg2, arg3);
|
|
|
|
}
|