feature (kernel): Implemented syscall architecture

This commit is contained in:
antifallobst 2023-02-17 15:18:12 +01:00
parent e92c45394a
commit 84e4c1c51c
4 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,36 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* NoxOS 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.
*
* NoxOS 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 this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef NOX_SYSCALL_H
#define NOX_SYSCALL_H
#include "platform/cpu.h"
typedef enum {
SYSCALLS_MISC = 0x00,
SYSCALLS_FILE = 0x01,
SYSCALLS_PROC = 0x02,
SYSCALLS_KERNEL = 0xFF,
}syscall_group_E;
typedef enum {
SYSCALL_KERNEL_START_SCHEDULER = 0xFF00
} syscall_E;
extern void syscall_perform(syscall_E id);
cpu_state_T* syscall_handle(cpu_state_T* state);
#endif //NOX_SYSCALL_H

View File

@ -17,6 +17,7 @@
#include "platform/cpu.h" #include "platform/cpu.h"
#include "platform/gdt.h" #include "platform/gdt.h"
#include "platform/exceptions.h" #include "platform/exceptions.h"
#include "platform/syscall.h"
#include "mm/page_frame.h" #include "mm/page_frame.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/io.h" #include "utils/io.h"
@ -231,7 +232,7 @@ cpu_state_T* irq_handle(cpu_state_T* state, pic_irq_E irq) {
switch (irq) { switch (irq) {
case IRQ_PIT: { case IRQ_PIT: {
log(LOG_DEBUG, "PIT -> Tick"); // log(LOG_DEBUG, "PIT -> Tick");
break; break;
} }
default: { default: {
@ -253,6 +254,10 @@ cpu_state_T* interrupts_handle(cpu_state_T* state) {
return irq_handle(state, state->interrupt_id - IRQ_MASTER_OFFSET); return irq_handle(state, state->interrupt_id - IRQ_MASTER_OFFSET);
} }
if (state->interrupt_id == 0x80) {
return syscall_handle(state);
}
log(LOG_WARNING, "Unhandled interrupt: 0x%xb", state->interrupt_id); log(LOG_WARNING, "Unhandled interrupt: 0x%xb", state->interrupt_id);
return state; return state;

View File

@ -0,0 +1,45 @@
/* Copyright (C) Antifallobst <antifallobst@systemausfall.org>
*
* NoxOS 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.
*
* NoxOS 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 this program.
* If not, see <https://www.gnu.org/licenses/>.
*/
#include "platform/syscall.h"
#include "utils/logger.h"
#include "proc/scheduler.h"
cpu_state_T* syscall_handle(cpu_state_T* state) {
cpu_state_T* return_state = state;
syscall_group_E group_id = (state->rax & 0xFF00) >> 8;
if (group_id == SYSCALLS_KERNEL &&
scheduler_is_initialized() &&
scheduler_get_current_process() != PROC_KERNEL)
{
log(LOG_WARNING, "non kernel process[%d:%d] tried to perform a kernel syscall (permission denied)", scheduler_get_current_process(), scheduler_get_current_thread());
return return_state;
}
switch (state->rax) {
case SYSCALL_KERNEL_START_SCHEDULER: {
scheduler_start(state);
break;
}
default: {
log(LOG_WARNING, "Unhandled syscall: 0x%xw RAX[0x%x]", state->rax, state->rax);
break;
}
}
return return_state;
}

View File

@ -0,0 +1,5 @@
syscall_perform:
mov rax, rdi
int 0x80
ret
GLOBAL syscall_perform