Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syscalls #212

Open
antoyo opened this issue Aug 9, 2018 · 4 comments
Open

Syscalls #212

antoyo opened this issue Aug 9, 2018 · 4 comments

Comments

@antoyo
Copy link

antoyo commented Aug 9, 2018

Hi.
Could you please add a way to do system calls in the language?
That would be useful when you want to do low-level stuff without using C.
Thanks.

@githwxi
Copy link
Owner

githwxi commented Aug 17, 2018

Could you propose a way to do it?

@jrfondren
Copy link

you could start with the syscall() library call, to get all the functionality with some overhead

and then use inline ASM (in inline C) on a per-architecture basis to drop the overhead.

I would expect that one of the libc-lite libraries already does this, though.

@antoyo
Copy link
Author

antoyo commented Mar 30, 2019

For instance, of x86_64, the code would look like:

%{^
long syscall1(long value) {
    long result;
    __asm__("mov %1, %%rax;"
         "syscall"
         : "=r"(result)
         :"r"(value)
         :"%rax", "%rdi");
    return result;
}

long syscall2(long value1, long value2) {
    long result;
    __asm__("mov %1, %%rax;"
         "mov %2, %%rdi;"
         "syscall"
         : "=r"(result)
         :"r"(value1), "r"(value2)
         :"%rax", "%rdi");
    return result;
}
%}

extern fn syscall1(value: lint): lint =
    "ext#"

extern fn syscall2(value1: lint, value2: lint): lint =
    "ext#"

(or perhaps using variadics)

@bbarker
Copy link
Contributor

bbarker commented Mar 30, 2019

cc @master-q - seems like may be of interest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants