Page 1 of 1

64 bit System API

Posted: Sun Jul 12, 2020 1:02 pm
by nexos
Hello,
I am working on a 64 bit system API dispatcher, but the function throws an invalid opcode when called. Here is the function

Code: Select all

VOID SchedApiDispatch(REGS* r)
{
    if(r->rax > MAXSYSCALL)
    {
        r->rax = 0;
        return;
    }
    VOID* location = syscalls[r->rax];
    QWORD ret = 0;
    asm volatile (" \
        mov %1, %%rdi; \
        mov %2, %%rsi; \
        mov %3, %%rdx; \
        mov %4, %%rcx; \
        mov %5, %%r8; \
        mov %6, %%r9; \
        call *%7; \
        add $48, %%esp; \
        " : "=a" (ret) : "r" (r->rdi), "r" (r->rsi), "r" (r->rdx), "r" (r->rcx), "r" (r->r8), "r" (r->r9), "r" (location));
   r->rax = ret;
}
I have read through the ABI as well.
Thanks for your help,
nexos

Re: 64 bit System API

Posted: Sun Jul 12, 2020 1:13 pm
by nexos
I found the problem (perhaps maybe I should have debugged before posting :shock: ) I needed to use the m rather then the r constraint for the function address. It works now!

Re: 64 bit System API

Posted: Sun Jul 12, 2020 1:17 pm
by Octocontrabass
Couldn't you replace the inline assembly with something like this?

Code: Select all

return syscalls[r->rax](r);

Re: 64 bit System API

Posted: Sun Jul 12, 2020 1:18 pm
by nexos
Yes, I could! Thanks for the tip.