64 bit System API

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

64 bit System API

Post 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
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: 64 bit System API

Post 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!
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: 64 bit System API

Post by Octocontrabass »

Couldn't you replace the inline assembly with something like this?

Code: Select all

return syscalls[r->rax](r);
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: 64 bit System API

Post by nexos »

Yes, I could! Thanks for the tip.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply