Fix syscalls

This commit is contained in:
Mark
2019-10-13 18:25:22 +03:00
parent 2f3aee2d46
commit 3dfa5a54f4
4 changed files with 75 additions and 11 deletions
+2 -1
View File
@@ -25,7 +25,8 @@ OBJS+=$(O)/sys/amd64/hw/rs232.o \
$(O)/sys/amd64/mm/phys.o \
$(O)/sys/amd64/mm/vmalloc.o \
$(O)/sys/amd64/mm/pool.o \
$(O)/sys/amd64/syscall_s.o
$(O)/sys/amd64/syscall_s.o \
$(O)/sys/amd64/syscall.o
kernel_OBJS=$(O)/sys/amd64/entry.o \
$(OBJS)
+26 -2
View File
@@ -19,10 +19,23 @@ static char t_stack3[IDLE_STACK * AMD64_MAX_SMP] = {0};
static struct thread t_idle[AMD64_MAX_SMP] = {0};
void func0(uintptr_t id, int state) {
uintptr_t a0 = 0, a1 = 0;
uint16_t attr = (id + 0x2) << 8;
uint16_t letter = '0' + id;
*((uint16_t *) MM_VIRTUALIZE(0xB8000) + 80 * 0 + id) = state * attr | letter;
{
register uintptr_t rsp asm ("rsp");
a0 = rsp;
}
asm volatile ("syscall");
{
register uintptr_t rsp asm ("rsp");
a1 = rsp;
}
if (a0 != a1) {
while (1);
}
}
void idle_func(uintptr_t id) {
@@ -31,7 +44,6 @@ void idle_func(uintptr_t id) {
uintptr_t a0 = 0, a1 = 0;
*((uint16_t *) MM_VIRTUALIZE(0xB8000) + 80 * 1 + id) = (id + 'A') | ((id + 0x9) << 8);
{
register uintptr_t rsp asm ("rsp");
a0 = rsp;
@@ -48,7 +60,19 @@ void idle_func(uintptr_t id) {
while (1) {
func0(id, state);
asm volatile ("syscall");
{
register uintptr_t rsp asm ("rsp");
a0 = rsp;
}
asm volatile ("syscall");
{
register uintptr_t rsp asm ("rsp");
a1 = rsp;
}
if (a0 != a1) {
while (1);
}
state = !state;
for (size_t i = 0; i < 10000000; ++i);
}
+6
View File
@@ -0,0 +1,6 @@
#include "sys/types.h"
#include "sys/debug.h"
int amd64_syscall(uintptr_t rdi, uintptr_t rsi, uintptr_t rdx, uintptr_t rcx, uintptr_t r10, uintptr_t rax) {
return 0;
}
+41 -8
View File
@@ -55,21 +55,54 @@ amd64_syscall_entry:
movq get_cpu(0x08), %rsp
movq (%rsp), %rsp
pushq %rax
movq get_cpu(0x20), %rax
pushq %rax
pushq %rcx
movq get_cpu(0x20), %rcx
pushq %rcx
pushq %r11
movq $100000000, %rax
// Safe for interrupts now
sti
1:
decq %rax
jnz 1b
// Userspace:
// %rdi %rsi %rdx %rcx %8 %r9
// Syscall:
// %rdi %rsi %rdx %r10 %r8 %r9
// %rax
// Now it's done like
// %rdi -> %rdi
// %rsi -> %rsi
// %rdx -> %rdx
// %r10 -> %rcx
// %r8 -> %r8
// %rax -> %r9
// FIXME: use %rax properly and
// have a table of system calls
movq %r10, %rcx
movq %rax, %r9
call amd64_syscall
// Disable interrupts
cli
popq %r11
popq %rdi
popq %rax
popq %rcx
// We could've been interrupted by irq0, which could've
// scheduled a new task, which could've rewritten the TSS/RSP0
// with weird values, so just fix that up
movq %rsp, %rdx
movq get_cpu(0x08), %rsi
movq %rdx, (%rsi)
movq get_cpu(0x18), %rsi
addq $(25 * 8), %rdx
movq %rdx, 4(%rsi)
movq %rdi, %rsp
swapgs
sysretq
_fmt0:
.string "rsp = %p\n"