Compare commits

..

No commits in common. "fd8a0175d9912b8798f76613796369d94a0b4d6b" and "0ea9974512adb8cf58974646b0421669e2c6f96f" have entirely different histories.

11 changed files with 6 additions and 106 deletions

View File

@ -1,17 +1,4 @@
section .text
global _start
_start:
mov rax, 1
mov rdi, message
int 42h
mov rax, 1
mov rdi, message2
int 42h
mov rax, 0
int 42h
section .rodata
message:
db "Hello!", 0xa, 0
message2:
db "I am an app", 0xa, 0

View File

@ -15,9 +15,6 @@ set(SOURCES
src/thread/Spinlock.cpp
src/thread/Thread.cpp
src/thread/Scheduler.cpp
src/sys/Syscall.cpp
src/sys/exit.cpp
src/sys/console_print.cpp
src/InitRD.cpp
src/ELF.cpp
)

View File

@ -188,4 +188,4 @@ ISR_ERROR 21 ; control-protection exception (#CP)
; ISR 22-31 reserved
IRQ 32, 0 ; timer interrupt
IRQ 33, 0 ; keyboard interrupt
ISR 66 ; system call
ISR 66 ; user exit

View File

@ -4,7 +4,6 @@
#include "arch/x86_64/CPU.h"
#include "arch/x86_64/IO.h"
#include "memory/MemoryManager.h"
#include "sys/Syscall.h"
#include "thread/Scheduler.h"
#include <cpuid.h>
#include <luna/CString.h>
@ -108,10 +107,11 @@ extern "C" void arch_interrupt_entry(Registers* regs)
scancode_queue.try_push(scancode);
pic_eoi(regs);
}
else if (regs->isr == 66) // System call
else if (regs->isr == 66) // Exit!!
{
SyscallArgs args = { regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8, regs->r9 };
regs->rax = (u64)invoke_syscall(regs, args, regs->rax);
kdbgln("exiting from user task!!");
Scheduler::current()->state = ThreadState::Dying;
kernel_yield();
}
else
{

View File

@ -347,23 +347,6 @@ namespace MemoryManager
return false;
}
// FIXME: Replace this with some kind of strdup_from_user() function.
bool validate_userspace_string(u64 address)
{
if (!validate_readable_page(address)) return false;
while (*(char*)address != 0)
{
address++;
if (address % ARCH_PAGE_SIZE)
{
if (!validate_readable_page(address)) return false;
}
}
return true;
}
usize free()
{
return free_mem;

View File

@ -20,8 +20,6 @@ namespace MemoryManager
bool validate_readable_page(u64 address);
bool validate_writable_page(u64 address);
bool validate_userspace_string(u64 address);
Result<void> map_frames_at(u64 virt, u64 phys, usize count, int flags);
Result<u64> alloc_at(u64 virt, usize count, int flags);

View File

@ -1,18 +0,0 @@
#include "sys/Syscall.h"
#include <luna/SystemError.h>
syscall_func_t syscalls[] = {
#undef __enumerate
#define __enumerate(name) sys_##name,
enumerate_syscalls(__enumerate)
#undef __enumerate
};
i64 invoke_syscall(Registers* regs, SyscallArgs args, u64 syscall)
{
if (syscall >= Syscalls::__count) { return -ENOSYS; }
auto rc = syscalls[syscall](regs, args);
if (rc.has_error()) return -rc.error();
return (i64)rc.value();
}

View File

@ -1,16 +0,0 @@
#pragma once
#include "arch/CPU.h"
#include <luna/Result.h>
#include <luna/Syscall.h>
typedef u64 SyscallArgs[6];
typedef Result<u64> (*syscall_func_t)(Registers*, SyscallArgs);
// Invoked by the architecture-dependent system call entry point.
i64 invoke_syscall(Registers*, SyscallArgs, u64 syscall);
#undef __enumerate
#define __enumerate(name) extern Result<u64> sys_##name(Registers*, SyscallArgs);
enumerate_syscalls(__enumerate)
#undef __enumerate

View File

@ -1,12 +0,0 @@
#include "memory/MemoryManager.h"
#include "sys/Syscall.h"
#include "video/TextConsole.h"
Result<u64> sys_console_print(Registers*, SyscallArgs args)
{
if (!MemoryManager::validate_userspace_string(args[0])) return err(EFAULT);
TextConsole::print((char*)args[0]);
return { 0 };
}

View File

@ -1,7 +0,0 @@
#include "sys/Syscall.h"
#include "thread/Scheduler.h"
Result<u64> sys_exit(Registers*, SyscallArgs)
{
kernel_exit();
}

View File

@ -1,12 +0,0 @@
#pragma once
#define enumerate_syscalls(_e) _e(exit) _e(console_print)
enum Syscalls
{
#undef __enumerate
#define __enumerate(name) SYS_##name,
enumerate_syscalls(__enumerate)
#undef __enumerate
__count
};