diff --git a/etc/init b/etc/init index 539e434..2348774 100755 Binary files a/etc/init and b/etc/init differ diff --git a/etc/init.S b/etc/init.S index db1fdcd..aaa2e5f 100644 --- a/etc/init.S +++ b/etc/init.S @@ -1,10 +1,16 @@ .section .text .global _start _start: - movq $100, %rcx +0: + movq $1, %rdi + movq $2, %rsi + movq $3, %rdx + movq $4, %r10 + movq $5, %r8 + movq $6, %r9 + syscall + movq $10000000, %rcx 1: dec %rcx jnz 1b - // XXX: Syscall fucks up kstack? - //syscall - jmp _start + jmp 0b diff --git a/include/sys/amd64/hw/int_macros.inc b/include/sys/amd64/hw/int_macros.inc index 1b9c86d..80feeaa 100644 --- a/include/sys/amd64/hw/int_macros.inc +++ b/include/sys/amd64/hw/int_macros.inc @@ -41,11 +41,12 @@ popq %rax mov %rax, %ds popq %rax - //mov %rax, %es + mov %rax, %es popq %rax - //mov %rax, %fs popq %rax - //mov %rax, %gs + xor %rax, %rax + mov %rax, %fs + mov %rax, %gs // cr3 popq %rax diff --git a/sys/amd64/sys/syscall.c b/sys/amd64/sys/syscall.c index 194961a..4c9c251 100644 --- a/sys/amd64/sys/syscall.c +++ b/sys/amd64/sys/syscall.c @@ -2,4 +2,8 @@ #include "sys/debug.h" void amd64_syscall(uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5) { + switch (a0) { + default: + return; + } } diff --git a/sys/amd64/sys/syscall_s.S b/sys/amd64/sys/syscall_s.S index 9f25b29..6923d09 100644 --- a/sys/amd64/sys/syscall_s.S +++ b/sys/amd64/sys/syscall_s.S @@ -28,7 +28,7 @@ amd64_setup_syscall: movl $AMD64_MSR_LSTAR, %ecx wrmsr - movl $0x0, %eax + movl $0x0200, %eax movl $0x0, %edx movl $AMD64_MSR_SFMASK, %ecx wrmsr @@ -42,7 +42,6 @@ amd64_setup_syscall: retq amd64_syscall_entry: - cli // R11 = RFLAGS // RCX = userRIP // RSP = userRSP @@ -54,8 +53,8 @@ amd64_syscall_entry: // 1. Load kernRSP from amd64_thread_current->kstack_ptr, // userRSP is stored in %rax before being pushed movq %rsp, %rax - movq sched_current(%rip), %rsi - movq (%rsi), %rsp + movq sched_current(%rip), %rsp + movq (%rsp), %rsp // syscall handlers may mess up this in SysV amd64 ABI, store // these on stack @@ -63,6 +62,9 @@ amd64_syscall_entry: pushq %r11 pushq %rcx + // Move arguments + movq %r10, %rcx + call amd64_syscall popq %rcx diff --git a/sys/amd64/sys/thread.c b/sys/amd64/sys/thread.c index fb2b3e7..bce24ee 100644 --- a/sys/amd64/sys/thread.c +++ b/sys/amd64/sys/thread.c @@ -31,9 +31,11 @@ int thread_init(thread_t *t, panic("Failed to allocate thread kstack\n"); } } + t->kstack_base = kstack_base; t->kstack_size = kstack_size; t->kstack_ptr = t->kstack_base + t->kstack_size - sizeof(amd64_thread_context_t); + kdebug("KSTACK %p\n", t->kstack_ptr); // If we're not kernel, additionally set the ustack if (!(flags & THREAD_KERNEL)) { diff --git a/sys/sched.c b/sys/sched.c index cd1da36..874e97c 100644 --- a/sys/sched.c +++ b/sys/sched.c @@ -44,6 +44,7 @@ int sched(void) { if (to == from) { return -1; } + sched_current = to; return 0; }