mescc: Mes C Library: x86_64: Introduce __sys_call and friends.

This prepares for x86_64 syscall-internal.

* lib/linux/x86_64-mes-gcc/syscall.c (__sys_call, __sys_call1,
__sys_call2, __sys_call3, __sys_call4): New functions, copied from ...
(_sys_call, _sys_call1, _sys_call2, _sys_call3, _sys_call4): ... these.
Use them, handle errno only.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2020-08-30 12:11:51 +02:00
parent 1c128c7a9f
commit e16d1e469a
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
2 changed files with 141 additions and 63 deletions

View file

@ -21,16 +21,9 @@
#include <errno.h> #include <errno.h>
#include <linux/x86_64/syscall.h> #include <linux/x86_64/syscall.h>
// HMM, merge this with x86-mes-gcc/mes.c, doing something like
// #define R0 eax
// #define R1 ebx
//
// #define R0 rax
// #define R1 rdi
// *INDENT-OFF* // *INDENT-OFF*
long long
_sys_call (long sys_call) __sys_call (long sys_call)
{ {
long r; long r;
asm ( asm (
@ -41,18 +34,11 @@ _sys_call (long sys_call)
: "rm" (sys_call) : "rm" (sys_call)
: "rax" : "rax"
); );
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r; return r;
} }
long long
_sys_call1 (long sys_call, long one) __sys_call1 (long sys_call, long one)
{ {
long r; long r;
asm ( asm (
@ -64,18 +50,11 @@ _sys_call1 (long sys_call, long one)
: "rm" (sys_call), "rm" (one) : "rm" (sys_call), "rm" (one)
: "rax", "rdi" : "rax", "rdi"
); );
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r; return r;
} }
long long
_sys_call2 (long sys_call, long one, long two) __sys_call2 (long sys_call, long one, long two)
{ {
long r; long r;
asm ( asm (
@ -88,18 +67,11 @@ _sys_call2 (long sys_call, long one, long two)
: "rm" (sys_call), "rm" (one), "rm" (two) : "rm" (sys_call), "rm" (one), "rm" (two)
: "rax", "rdi", "rsi" : "rax", "rdi", "rsi"
); );
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r; return r;
} }
long long
_sys_call3 (long sys_call, long one, long two, long three) __sys_call3 (long sys_call, long one, long two, long three)
{ {
long r; long r;
asm ( asm (
@ -113,18 +85,11 @@ _sys_call3 (long sys_call, long one, long two, long three)
: "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three) : "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three)
: "rax", "rdi", "rsi", "rdx" : "rax", "rdi", "rsi", "rdx"
); );
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r; return r;
} }
long long
_sys_call4 (long sys_call, long one, long two, long three, long four) __sys_call4 (long sys_call, long one, long two, long three, long four)
{ {
long r; long r;
asm ( asm (
@ -141,6 +106,70 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
: "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four) : "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four)
: "rax", "rdi", "rsi", "rdx", "r10" : "rax", "rdi", "rsi", "rdx", "r10"
); );
return r;
}
// *INDENT-ON*
long
_sys_call (long sys_call)
{
long r = __sys_call (sys_call);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call1 (long sys_call, long one)
{
long r = __sys_call1 (sys_call, one);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call2 (long sys_call, long one, long two)
{
long r = __sys_call2 (sys_call, one, two);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call3 (long sys_call, long one, long two, long three)
{
long r = __sys_call3 (sys_call, one, two, three);
if (r < 0)
{
errno = -r;
r = -1;
}
else
errno = 0;
return r;
}
long
_sys_call4 (long sys_call, long one, long two, long three, long four)
{
long r = __sys_call4 (sys_call, one, two, three, four);
if (r < 0) if (r < 0)
{ {
errno = -r; errno = -r;

View file

@ -1,6 +1,6 @@
/* -*-comment-start: "//";comment-end:""-*- /* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software * GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> * Copyright © 2016,2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* *
* This file is part of GNU Mes. * This file is part of GNU Mes.
* *
@ -22,16 +22,75 @@
#include <linux/x86_64/syscall.h> #include <linux/x86_64/syscall.h>
long long
//__sys_call (long one, long two, long three, long four) __sys_call (long sys_call)
__sys_call (long sys_call, long one, long two, long three, long four)
{ {
#if 1 // !MES_CCAMD64 #if 0 // !MES_CCAMD64
// asm ("mov____0x8(%rbp),%rdi !0x10"); asm ("mov____0x8(%rbp),%rdi !0x10");
// asm ("mov____0x8(%rbp),%rsi !0x18"); #else
// asm ("mov____0x8(%rbp),%rdx !0x20"); asm ("mov____0x8(%rbp),%rax !0x10");
// asm ("mov____0x8(%rbp),%rdx !0x28"); #endif
// asm ("mov____0x8(%rbp),%r10 !0x30");
asm ("syscall");
}
long
__sys_call1 (long sys_call, long one)
{
#if 0 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
#else
asm ("mov____0x8(%rbp),%rax !0x10");
asm ("mov____0x8(%rbp),%rdi !0x18");
#endif
asm ("syscall");
}
long
__sys_call2 (long sys_call, long one, long two)
{
#if 0 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
asm ("mov____0x8(%rbp),%rdx !0x20");
#else
asm ("mov____0x8(%rbp),%rax !0x10");
asm ("mov____0x8(%rbp),%rdi !0x18");
asm ("mov____0x8(%rbp),%rsi !0x20");
#endif
asm ("syscall");
}
long
__sys_call3 (long sys_call, long one, long two, long three)
{
#if 0 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
asm ("mov____0x8(%rbp),%rdx !0x20");
asm ("mov____0x8(%rbp),%rdx !0x28");
#else
asm ("mov____0x8(%rbp),%rax !0x10");
asm ("mov____0x8(%rbp),%rdi !0x18");
asm ("mov____0x8(%rbp),%rsi !0x20");
asm ("mov____0x8(%rbp),%rdx !0x28");
#endif
asm ("syscall");
}
long
__sys_call4 (long sys_call, long one, long two, long three, long four)
{
#if 0 // !MES_CCAMD64
asm ("mov____0x8(%rbp),%rdi !0x10");
asm ("mov____0x8(%rbp),%rsi !0x18");
asm ("mov____0x8(%rbp),%rdx !0x20");
asm ("mov____0x8(%rbp),%rdx !0x28");
asm ("mov____0x8(%rbp),%r10 !0x30");
#else
asm ("mov____0x8(%rbp),%rax !0x10"); asm ("mov____0x8(%rbp),%rax !0x10");
asm ("mov____0x8(%rbp),%rdi !0x18"); asm ("mov____0x8(%rbp),%rdi !0x18");
asm ("mov____0x8(%rbp),%rsi !0x20"); asm ("mov____0x8(%rbp),%rsi !0x20");
@ -45,8 +104,6 @@ __sys_call (long sys_call, long one, long two, long three, long four)
long long
_sys_call (long sys_call) _sys_call (long sys_call)
{ {
// long rax = sys_call;
// long r = __sys_call ();
long r = __sys_call (sys_call); long r = __sys_call (sys_call);
if (r < 0) if (r < 0)
{ {
@ -61,9 +118,7 @@ _sys_call (long sys_call)
long long
_sys_call1 (long sys_call, long one) _sys_call1 (long sys_call, long one)
{ {
// long rax = sys_call; long r = __sys_call1 (sys_call, one);
// long r = __sys_call (one);
long r = __sys_call (sys_call, one);
if (r < 0) if (r < 0)
{ {
errno = -r; errno = -r;
@ -77,9 +132,7 @@ _sys_call1 (long sys_call, long one)
long long
_sys_call2 (long sys_call, long one, long two) _sys_call2 (long sys_call, long one, long two)
{ {
// long rax = sys_call; long r = __sys_call2 (sys_call, one, two);
// long r = __sys_call (one, two);
long r = __sys_call (sys_call, one, two);
if (r < 0) if (r < 0)
{ {
errno = -r; errno = -r;
@ -93,9 +146,7 @@ _sys_call2 (long sys_call, long one, long two)
long long
_sys_call3 (long sys_call, long one, long two, long three) _sys_call3 (long sys_call, long one, long two, long three)
{ {
// long rax = sys_call; long r = __sys_call3 (sys_call, one, two, three);
// long r = __sys_call (one, two, three);
long r = __sys_call (sys_call, one, two, three);
if (r < 0) if (r < 0)
{ {
errno = -r; errno = -r;
@ -109,9 +160,7 @@ _sys_call3 (long sys_call, long one, long two, long three)
long long
_sys_call4 (long sys_call, long one, long two, long three, long four) _sys_call4 (long sys_call, long one, long two, long three, long four)
{ {
// long rax = sys_call; long r = __sys_call4 (sys_call, one, two, three, four);
// long r = __sys_call (one, two, three, four);
long r = __sys_call (sys_call, one, two, three, four);
if (r < 0) if (r < 0)
{ {
errno = -r; errno = -r;