kernel: add a temporary syscall dispatch system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#ifndef MANGO_X86_64_INIT_H_
|
||||
#define MANGO_X86_64_INIT_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef MANGO_USER_PMAP_H_
|
||||
#define MANGO_USER_PMAP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uintptr_t ml_pmap_t;
|
||||
typedef uint64_t ml_pfn_t;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mango/machine/irq.h>
|
||||
#include <mango/panic.h>
|
||||
#include <mango/sched.h>
|
||||
#include <mango/syscall.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MAX_ISR_HANDLERS 16
|
||||
@@ -151,6 +152,8 @@ int idt_init(struct idt_ptr *ptr)
|
||||
init_global_idt();
|
||||
}
|
||||
|
||||
set_syscall_gate((uintptr_t)syscall_gate);
|
||||
|
||||
ptr->i_limit = sizeof(idt) - 1;
|
||||
ptr->i_base = (uintptr_t)&idt;
|
||||
|
||||
@@ -203,7 +206,7 @@ void irq_dispatch(struct ml_cpu_context *regs)
|
||||
void syscall_dispatch(struct ml_cpu_context *regs)
|
||||
{
|
||||
unsigned int sysid = regs->rax;
|
||||
virt_addr_t syscall_impl = 0; // TODO
|
||||
virt_addr_t syscall_impl = syscall_get_func(sysid);
|
||||
|
||||
if (syscall_impl == 0) {
|
||||
regs->rax = KERN_UNSUPPORTED;
|
||||
|
||||
20
include/mango/syscall.h
Normal file
20
include/mango/syscall.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef MANGO_SYSCALL_H_
|
||||
#define MANGO_SYSCALL_H_
|
||||
|
||||
#include <mango/handle.h>
|
||||
#include <mango/status.h>
|
||||
#include <mango/vm.h>
|
||||
|
||||
#define SYS_EXIT 1
|
||||
#define SYS_VM_OBJECT_CREATE 2
|
||||
|
||||
extern kern_status_t sys_exit(int status);
|
||||
extern kern_status_t sys_vm_object_create(
|
||||
const char *name,
|
||||
size_t len,
|
||||
enum vm_prot prot,
|
||||
kern_handle_t *out_handle);
|
||||
|
||||
extern virt_addr_t syscall_get_func(unsigned int sysid);
|
||||
|
||||
#endif
|
||||
40
kernel/syscall.c
Normal file
40
kernel/syscall.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <mango/machine/cpu.h>
|
||||
#include <mango/printk.h>
|
||||
#include <mango/syscall.h>
|
||||
|
||||
kern_status_t sys_exit(int status)
|
||||
{
|
||||
printk("sys_exit(%d)", status);
|
||||
while (1) {
|
||||
ml_cpu_pause();
|
||||
}
|
||||
return KERN_UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
kern_status_t sys_vm_object_create(
|
||||
const char *name,
|
||||
size_t len,
|
||||
enum vm_prot prot,
|
||||
kern_handle_t *out_handle)
|
||||
{
|
||||
printk("sys_vm_object_create()");
|
||||
return KERN_UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
#define SYSCALL_TABLE_ENTRY(id, p) [SYS_##id] = (virt_addr_t)(sys_##p)
|
||||
|
||||
static const virt_addr_t syscall_table[] = {
|
||||
SYSCALL_TABLE_ENTRY(EXIT, exit),
|
||||
SYSCALL_TABLE_ENTRY(VM_OBJECT_CREATE, vm_object_create),
|
||||
};
|
||||
static const size_t syscall_table_count
|
||||
= sizeof syscall_table / sizeof syscall_table[0];
|
||||
|
||||
virt_addr_t syscall_get_func(unsigned int sysid)
|
||||
{
|
||||
if (sysid >= syscall_table_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return syscall_table[sysid];
|
||||
}
|
||||
Reference in New Issue
Block a user