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.
nexos
Member
Posts: 1081 Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos
Post
by nexos » Sun Jul 12, 2020 1:02 pm
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
Posts: 1081 Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos
Post
by nexos » Sun Jul 12, 2020 1:13 pm
I found the problem (perhaps maybe I should have debugged before posting
) 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
Posts: 5885 Joined: Mon Mar 25, 2013 7:01 pm
Post
by Octocontrabass » Sun Jul 12, 2020 1:17 pm
Couldn't you replace the inline assembly with something like this?
nexos
Member
Posts: 1081 Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos
Post
by nexos » Sun Jul 12, 2020 1:18 pm
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