[kernel] Clean up syscall code
This is a minor refactor including: - Removing old commented-out syscall_dispatch function - Removing IA32_EFER syscall-enable flag setting (this is done by the bootloader now) - Moving much logging from inside process/thread syscalls to the 'task' log area, allowing for turning the 'syscall' area down to info by default.
This commit is contained in:
@@ -8,7 +8,7 @@ LOG(task, info);
|
||||
LOG(sched, info);
|
||||
LOG(loader, debug);
|
||||
LOG(boot, debug);
|
||||
LOG(syscall,debug);
|
||||
LOG(syscall,info);
|
||||
LOG(vmem, debug);
|
||||
LOG(objs, debug);
|
||||
LOG(timer, debug);
|
||||
|
||||
@@ -13,10 +13,6 @@ extern "C" {
|
||||
void syscall_handler_prelude();
|
||||
}
|
||||
|
||||
namespace syscalls {
|
||||
|
||||
} // namespace syscalls
|
||||
|
||||
uintptr_t syscall_registry[static_cast<unsigned>(syscall::MAX)];
|
||||
const char * syscall_names[static_cast<unsigned>(syscall::MAX)];
|
||||
|
||||
@@ -44,86 +40,9 @@ syscall_invalid(uint64_t call)
|
||||
_halt();
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
syscall_dispatch(cpu_state *regs)
|
||||
{
|
||||
console *cons = console::get();
|
||||
syscall call = static_cast<syscall>(regs->rax);
|
||||
|
||||
auto &s = scheduler::get();
|
||||
auto *p = s.current();
|
||||
|
||||
switch (call) {
|
||||
case syscall::noop:
|
||||
break;
|
||||
|
||||
case syscall::debug:
|
||||
cons->set_color(11);
|
||||
cons->printf("\nProcess %d: Received DEBUG syscall\n", p->pid);
|
||||
cons->set_color();
|
||||
print_regs(*regs);
|
||||
cons->printf("\n Syscall enters: %8d\n", __counter_syscall_enter);
|
||||
cons->printf(" Syscall sysret: %8d\n", __counter_syscall_sysret);
|
||||
break;
|
||||
|
||||
case syscall::send:
|
||||
{
|
||||
pid_t target = regs->rdi;
|
||||
uintptr_t data = regs->rsi;
|
||||
|
||||
cons->set_color(11);
|
||||
cons->printf("\nProcess %d: Received SEND syscall, target %d, data %016lx\n", p->pid, target, data);
|
||||
cons->set_color();
|
||||
|
||||
if (p->wait_on_send(target))
|
||||
s.schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
case syscall::receive:
|
||||
{
|
||||
pid_t source = regs->rdi;
|
||||
uintptr_t data = regs->rsi;
|
||||
|
||||
cons->set_color(11);
|
||||
cons->printf("\nProcess %d: Received RECEIVE syscall, source %d, dat %016lx\n", p->pid, source, data);
|
||||
cons->set_color();
|
||||
|
||||
if (p->wait_on_receive(source))
|
||||
s.schedule();
|
||||
}
|
||||
break;
|
||||
|
||||
case syscall::fork:
|
||||
{
|
||||
cons->set_color(11);
|
||||
cons->printf("\nProcess %d: Received FORK syscall\n", p->pid);
|
||||
cons->set_color();
|
||||
|
||||
pid_t pid = p->fork(regs);
|
||||
cons->printf("\n fork returning %d\n", pid);
|
||||
regs->rax = pid;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
cons->set_color(9);
|
||||
cons->printf("\nReceived unknown syscall: %02x\n", call);
|
||||
cons->set_color();
|
||||
_halt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
syscall_enable()
|
||||
{
|
||||
// IA32_EFER - set bit 0, syscall enable
|
||||
uint64_t efer = rdmsr(msr::ia32_efer);
|
||||
wrmsr(msr::ia32_efer, efer|1);
|
||||
|
||||
// IA32_STAR - high 32 bits contain k+u CS
|
||||
// Kernel CS: GDT[1] ring 0 bits[47:32]
|
||||
// User CS: GDT[3] ring 3 bits[63:48]
|
||||
|
||||
@@ -7,7 +7,7 @@ struct cpu_state;
|
||||
|
||||
enum class syscall : uint64_t
|
||||
{
|
||||
#define SYSCALL(id, name, result, ...) name = id,
|
||||
#define SYSCALL(id, name, ...) name = id,
|
||||
#include "syscalls.inc"
|
||||
#undef SYSCALL
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ j6_status_t
|
||||
process_create(j6_handle_t *handle)
|
||||
{
|
||||
process *child = construct_handle<process>(handle);
|
||||
log::debug(logs::syscall, "Process %llx created", child->koid());
|
||||
log::debug(logs::task, "Process %llx created", child->koid());
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ process_kill(j6_handle_t handle)
|
||||
process *c = get_handle<process>(handle);
|
||||
if (!c) return j6_err_invalid_arg;
|
||||
|
||||
log::debug(logs::syscall, "Process %llx killed by process %llx", c->koid(), p.koid());
|
||||
log::debug(logs::task, "Process %llx killed by process %llx", c->koid(), p.koid());
|
||||
c->exit(-1u);
|
||||
|
||||
return j6_status_ok;
|
||||
@@ -48,11 +48,11 @@ j6_status_t
|
||||
process_exit(int32_t status)
|
||||
{
|
||||
process &p = process::current();
|
||||
log::debug(logs::syscall, "Process %llx exiting with code %d", p.koid(), status);
|
||||
log::debug(logs::task, "Process %llx exiting with code %d", p.koid(), status);
|
||||
|
||||
p.exit(status);
|
||||
|
||||
log::error(logs::syscall, "returned to exit syscall");
|
||||
log::error(logs::task, "returned to exit syscall");
|
||||
return j6_err_unexpected;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ thread_create(void *rip, j6_handle_t *handle)
|
||||
child->clear_state(thread::state::loading);
|
||||
child->set_state(thread::state::ready);
|
||||
|
||||
log::debug(logs::syscall, "Thread %llx spawned new thread %llx, handle %d",
|
||||
log::debug(logs::task, "Thread %llx spawned new thread %llx, handle %d",
|
||||
parent.koid(), child->koid(), *handle);
|
||||
|
||||
return j6_status_ok;
|
||||
@@ -29,10 +29,10 @@ j6_status_t
|
||||
thread_exit(int32_t status)
|
||||
{
|
||||
thread &th = thread::current();
|
||||
log::debug(logs::syscall, "Thread %llx exiting with code %d", th.koid(), status);
|
||||
log::debug(logs::task, "Thread %llx exiting with code %d", th.koid(), status);
|
||||
th.exit(status);
|
||||
|
||||
log::error(logs::syscall, "returned to exit syscall");
|
||||
log::error(logs::task, "returned to exit syscall");
|
||||
return j6_err_unexpected;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ j6_status_t
|
||||
thread_sleep(uint64_t til)
|
||||
{
|
||||
thread &th = thread::current();
|
||||
log::debug(logs::syscall, "Thread %llx sleeping until %llu", th.koid(), til);
|
||||
log::debug(logs::task, "Thread %llx sleeping until %llu", th.koid(), til);
|
||||
|
||||
th.wait_on_time(til);
|
||||
return j6_status_ok;
|
||||
|
||||
Reference in New Issue
Block a user