sortix-mirror/sortix/syscall.cpp

102 lines
2.4 KiB
C++
Raw Normal View History

2011-08-05 12:25:00 +00:00
/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with Sortix. If not, see <http://www.gnu.org/licenses/>.
syscall.h
Handles system calls from userspace safely.
******************************************************************************/
#include "platform.h"
#include "syscall.h"
#include "scheduler.h"
#include "interrupt.h"
2011-08-05 12:25:00 +00:00
#include "log.h"
#include "panic.h"
#include "vga.h"
#include "keyboard.h"
2011-08-21 22:25:28 +00:00
#include "sound.h"
2011-08-27 18:57:39 +00:00
#include "process.h"
2011-08-27 21:26:11 +00:00
#include "initrd.h"
2011-08-05 12:25:00 +00:00
namespace Sortix
{
namespace Syscall
{
void SysStdOutPrint(CPU::InterruptRegisters* R)
{
#ifdef PLATFORM_X86
// TODO: Validate our input pointer is legal for the current thread/process!
R->eax = (uint32_t) Log::Print((const char*) R->ebx);
#else
#warning "This syscall is not supported on this arch"
while(true);
#endif
}
2011-08-27 21:26:11 +00:00
const size_t NumSyscalls = 12;
2011-08-05 12:25:00 +00:00
const Syscall Syscalls[NumSyscalls] =
{
&Scheduler::SysCreateThread,
&Scheduler::SysExitThread,
&Scheduler::SysSleep,
&Scheduler::SysUSleep,
&SysStdOutPrint,
&VGA::SysCreateFrame,
&VGA::SysChangeFrame,
&VGA::SysDeleteFrame,
&Keyboard::SysReceieveKeystroke,
2011-08-21 22:25:28 +00:00
&Sound::SysSetFrequency,
2011-08-27 18:57:39 +00:00
&SysExecute,
2011-08-27 21:26:11 +00:00
&InitRD::SysPrintPathFiles,
2011-08-05 12:25:00 +00:00
};
void Init()
{
Interrupt::RegisterHandler(0x80, &OnCall);
2011-08-05 12:25:00 +00:00
}
void OnCall(CPU::InterruptRegisters* registers)
{
#ifdef PLATFORM_X86
size_t callId = registers->eax;
// Make sure the requested syscall exists.
if ( callId >= NumSyscalls ) { return; }
#ifdef USING_OLD_SYSCALL
Syscalls[registers->eax](registers);
#else
Thread* thread = CurrentThread();
thread->BeginSyscall(registers);
Syscalls[registers->eax](thread);
thread->OnSysReturn();
#endif
#else
#warning "System calls are not available on this platform"
while(true);
#endif
}
}
}