Use <sys/syscall.h> instead of <libmaxsi/syscall.h>.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-22 00:44:41 +02:00
parent a1ed9144bc
commit 86107a467c
38 changed files with 372 additions and 489 deletions

View File

@ -22,14 +22,10 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL1_VOID(sys_exit, SYSCALL_EXIT, int);
} // namespace Maxsi
using namespace Maxsi;
extern "C" void _exit(int status)
{

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int);
extern "C" int access(const char* pathname, int mode)
{
return SysAccess(pathname, mode);
}
} // namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1(int, SysChDir, SYSCALL_CHDIR, const char*);
@ -33,5 +31,3 @@ extern "C" int chdir(const char* path)
{
return SysChDir(path);
}
} // namespace Maxsi

View File

@ -22,18 +22,13 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <errno.h>
namespace Maxsi {
// TODO: Implement this in the kernel.
extern "C" int chmod(const char* path, mode_t mode)
{
errno = ENOSYS;
return -1;
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL1(int, SysClose, SYSCALL_CLOSE, int);
extern "C" int close(int fd)
{
return SysClose(fd);
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL1(int, SysDup, SYSCALL_DUP, int);
extern "C" int dup(int fd)
{
return SysDup(fd);
}
} // namespace Maxsi

View File

@ -26,7 +26,6 @@
#include <libmaxsi/platform.h>
#include <libmaxsi/error.h>
#ifndef SORTIX_KERNEL
#include <libmaxsi/syscall.h>
#include <stdio.h>
#endif

View File

@ -22,18 +22,13 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <errno.h>
namespace Maxsi {
// TODO: Implement this in the kernel.
extern "C" int fchmod(int fd, mode_t mode)
{
errno = ENOSYS;
return -1;
}
} // namespace Maxsi

View File

@ -22,17 +22,17 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <fcntl.h>
namespace Maxsi {
#include <stdarg.h>
DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long);
extern "C" int fcntl(int fd, int cmd, unsigned long arg)
extern "C" int fcntl(int fd, int cmd, ...)
{
va_list ap;
va_start(ap, cmd);
unsigned long arg = va_arg(ap, unsigned long);
va_end(ap);
return SysFCntl(fd, cmd, arg);
}
} // namespace Maxsi

View File

@ -22,11 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/stat.h>
namespace Maxsi {
#include <sys/syscall.h>
DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*);
@ -34,5 +31,3 @@ extern "C" int fstat(int fd, struct stat* st)
{
return SysFStat(fd, st);
}
} // namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t);
@ -33,5 +31,3 @@ extern "C" int ftruncate(int fd, off_t length)
{
return SysFTruncate(fd, length);
}
} // namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL2(char*, SysGetCWD, SYSCALL_GETCWD, char*, size_t);
@ -33,5 +31,3 @@ extern "C" char* getcwd(char* buf, size_t size)
{
return SysGetCWD(buf, size);
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <sys/termmode.h>
namespace Maxsi {
DEFN_SYSCALL2(int, sys_gettermmode, SYSCALL_GETTERMMODE, int, unsigned*);
extern "C" int gettermmode(int fd, unsigned* mode)
{
return sys_gettermmode(fd, mode);
}
} // namespace Maxsi

View File

@ -1,311 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
syscall.h
Assembly stubs for declaring system calls in libmaxsi.
*******************************************************************************/
#ifdef SORTIX_KERNEL
#warning ===
#warning Sortix does not support syscalls from within the kernel, building this part of LibMaxsi should not be needed, and should not be used in kernel mode
#warning ===
#else
#ifndef LIBMAXSI_SYSCALL_H
#define LIBMAXSI_SYSCALL_H
#include <sortix/syscallnum.h>
#include <errno.h>
namespace Maxsi
{
#define DECL_SYSCALL0(type,fn) type fn();
#define DECL_SYSCALL1(type,fn,p1) type fn(p1);
#define DECL_SYSCALL2(type,fn,p1,p2) type fn(p1,p2);
#define DECL_SYSCALL3(type,fn,p1,p2,p3) type fn(p1,p2,p3);
#define DECL_SYSCALL4(type,fn,p1,p2,p3,p4) type fn(p1,p2,p3,p4);
#define DECL_SYSCALL5(type,fn,p1,p2,p3,p4,p5) type fn(p1,p2,p3,p4,p5);
#ifdef PLATFORM_X86
#define DEFN_SYSCALL0(type, fn, num) \
inline type fn() \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL1(type, fn, num, P1) \
inline type fn(P1 p1) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL2(type, fn, num, P1, P2) \
inline type fn(P1 p1, P2 p2) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \
inline type fn(P1 p1, P2 p2, P3 p3) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \
inline type fn(P1 p1, P2 p2, P3 p3, P4 p4) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \
inline type fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4), "S" ((size_t)p5)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
inline void fn() \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
inline void fn(P1 p1) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
inline void fn(P1 p1, P2 p2) \
{ \
size_t a; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
inline void fn(P1 p1, P2 p2, P3 p3) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4), "S" ((size_t)p5)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#else
// TODO: Make these inline - though that requires a move advanced inline
// assembly stub to force parameters into the right registers.
#define DEFN_SYSCALL0(type, fn, num) \
type fn() \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL1(type, fn, num, P1) \
type fn(P1) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL2(type, fn, num, P1, P2) \
type fn(P1, P2) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \
type fn(P1, P2, P3) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \
type fn(P1, P2, P3, P4) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \
type fn(P1, P2, P3, P4, P5) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
void fn() \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
void fn(P1) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
void fn(P1, P2) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
void fn(P1, P2, P3) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
void fn(P1, P2, P3, P4) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
void fn(P1, P2, P3, P4, P5) \
{ \
size_t a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#endif
}
#endif
#endif

View File

@ -0,0 +1,313 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of LibMaxsi.
LibMaxsi is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
sys/syscall.h
Functions and macros for declaring system call stubs.
*******************************************************************************/
#if defined(SORTIX_KERNEL)
#error This part of libc should not be built in kernel mode
#endif
#ifndef _SYS_SYSCALL_H
#define _SYS_SYSCALL_H 1
#include <features.h>
#include <sortix/syscallnum.h>
#include <errno.h> /* Should not be exposed here; use an eventual __errno.h. */
__BEGIN_DECLS
#define DECL_SYSCALL0(type,fn) type fn();
#define DECL_SYSCALL1(type,fn,p1) type fn(p1);
#define DECL_SYSCALL2(type,fn,p1,p2) type fn(p1,p2);
#define DECL_SYSCALL3(type,fn,p1,p2,p3) type fn(p1,p2,p3);
#define DECL_SYSCALL4(type,fn,p1,p2,p3,p4) type fn(p1,p2,p3,p4);
#define DECL_SYSCALL5(type,fn,p1,p2,p3,p4,p5) type fn(p1,p2,p3,p4,p5);
// System call functions for i386. (IA-32)
#if defined(__i386__)
#define DEFN_SYSCALL0(type, fn, num) \
inline type fn() \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL1(type, fn, num, P1) \
inline type fn(P1 p1) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL2(type, fn, num, P1, P2) \
inline type fn(P1 p1, P2 p2) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \
inline type fn(P1 p1, P2 p2, P3 p3) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \
inline type fn(P1 p1, P2 p2, P3 p3, P4 p4) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \
inline type fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4), "S" ((unsigned long)p5)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
inline void fn() \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
inline void fn(P1 p1) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
inline void fn(P1 p1, P2 p2) \
{ \
unsigned long a; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
inline void fn(P1 p1, P2 p2, P3 p3) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
inline void fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4), "S" ((unsigned long)p5)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
// System call functions for x86_64. (amd64)
#elif defined(__x86_64__)
// TODO: Make these inline - though that requires a move advanced inline
// assembly stub to force parameters into the right registers.
#define DEFN_SYSCALL0(type, fn, num) \
type fn() \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL1(type, fn, num, P1) \
type fn(P1) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL2(type, fn, num, P1, P2) \
type fn(P1, P2) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \
type fn(P1, P2, P3) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \
type fn(P1, P2, P3, P4) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \
type fn(P1, P2, P3, P4, P5) \
{ \
type a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
return a; \
}
#define DEFN_SYSCALL0_VOID(fn, num) \
void fn() \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL1_VOID(fn, num, P1) \
void fn(P1) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \
void fn(P1, P2) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \
void fn(P1, P2, P3) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \
void fn(P1, P2, P3, P4) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \
void fn(P1, P2, P3, P4, P5) \
{ \
unsigned long a; \
int reterrno; \
asm volatile("int $0x80" : "=a" (a) : "0" (num)); \
asm volatile("movl %%edx, %0" : "=r"(reterrno)); \
if ( reterrno ) { errno = reterrno; } \
}
// Unknown platform with no implementation available.
#else
#error System call interface is not declared for host system.
#endif
__END_DECLS
#endif

View File

@ -28,6 +28,7 @@
#define _TERMIOS_H 1
#include <features.h>
#include <stddef.h>
#include <sortix/termios.h>
__BEGIN_DECLS

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL1(int, sys_isatty, SYSCALL_ISATTY, int);
extern "C" int isatty(int fd)
{
return sys_isatty(fd);
}
} // namespace Maxsi

View File

@ -22,11 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/kernelinfo.h>
namespace Maxsi {
#include <sys/syscall.h>
DEFN_SYSCALL3(ssize_t, SysKernelInfo, SYSCALL_KERNELINFO, const char*, char*, size_t);
@ -34,6 +31,3 @@ extern "C" ssize_t kernelinfo(const char* req, char* resp, size_t resplen)
{
return SysKernelInfo(req, resp, resplen);
}
} // namespace Maxsi

View File

@ -22,12 +22,9 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL3_VOID(SysSeek, SYSCALL_SEEK, int, off_t*, int);
extern "C" off_t lseek(int fd, off_t offset, int whence)
@ -35,5 +32,3 @@ extern "C" off_t lseek(int fd, off_t offset, int whence)
SysSeek(fd, &offset, whence);
return offset;
}
} // namespace Maxsi

View File

@ -26,7 +26,7 @@
#include <libmaxsi/memory.h>
#include <libmaxsi/error.h>
#ifndef SORTIX_KERNEL
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#endif
namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/stat.h>
#include <sys/syscall.h>
DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t);
@ -33,5 +31,3 @@ extern "C" int mkdir(const char* pathname, mode_t mode)
{
return SysMkDir(pathname, mode);
}
} // namespace Maxsi

View File

@ -22,17 +22,21 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <fcntl.h>
namespace Maxsi {
#include <stdarg.h>
DEFN_SYSCALL3(int, SysOpen, SYSCALL_OPEN, const char*, int, mode_t);
extern "C" int open(const char* path, int flags, mode_t mode)
extern "C" int open(const char* path, int flags, ...)
{
int mode = 0;
if ( flags & O_CREAT )
{
va_list ap;
va_start(ap, flags);
mode = va_arg(ap, mode_t);
va_end(ap);
}
return SysOpen(path, flags, mode);
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL1(int, SysPipe, SYSCALL_PIPE, int*);
extern "C" int pipe(int pipefd[2])
{
return SysPipe(pipefd);
}
} // namespace Maxsi

View File

@ -24,8 +24,8 @@
#define _WANT_ENVIRON
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/process.h>
#include <sys/syscall.h>
#include <stdio.h>
#include <stdarg.h>
#include <dirent.h>

View File

@ -22,13 +22,10 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <errno.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL3(ssize_t, SysRead, SYSCALL_READ, int, void*, size_t);
extern "C" ssize_t read(int fd, void* buf, size_t count)
@ -44,5 +41,3 @@ extern "C" ssize_t pread(int, void*, size_t, off_t)
errno = ENOSYS;
return -1;
}
} // namespace Maxsi

View File

@ -22,11 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/readdirents.h>
namespace Maxsi {
#include <sys/syscall.h>
DEFN_SYSCALL3(int, SysReadDirEnts, SYSCALL_READDIRENTS, int, struct sortix_dirent*, size_t);
@ -34,5 +31,3 @@ extern "C" int readdirents(int fd, struct sortix_dirent* dirent, size_t size)
{
return SysReadDirEnts(fd, dirent, size);
}
} // namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*);
@ -33,5 +31,3 @@ extern "C" int rmdir(const char* pathname)
{
return SysRmDir(pathname);
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <sys/termmode.h>
namespace Maxsi {
DEFN_SYSCALL2(int, sys_settermmode, SYSCALL_SETTERMMODE, int, unsigned);
extern "C" int settermmode(int fd, unsigned mode)
{
return sys_settermmode(fd, mode);
}
} // namespace Maxsi

View File

@ -24,8 +24,8 @@
#include <libmaxsi/platform.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/process.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

View File

@ -24,8 +24,8 @@
******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <libmaxsi/sortix-sound.h>
#include <sys/syscall.h>
namespace System
{

View File

@ -22,11 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/stat.h>
namespace Maxsi {
#include <sys/syscall.h>
DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*);
@ -40,5 +37,3 @@ extern "C" int lstat(const char* path, struct stat* st)
{
return SysStat(path, st);
}
} // namespace Maxsi

View File

@ -24,7 +24,7 @@
#include <libmaxsi/platform.h>
#include <sys/types.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <libmaxsi/thread.h>
#ifdef SORTIX_KERNEL

View File

@ -24,7 +24,7 @@
#include <libmaxsi/platform.h>
#include <libmaxsi/memory.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <errno.h>
#include <sys/time.h>
#include <time.h>

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t);
@ -33,5 +31,3 @@ extern "C" int truncate(const char* pathname, off_t length)
{
return SysTruncate(pathname, length);
}
} // namespace Maxsi

View File

@ -22,18 +22,13 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <errno.h>
namespace Maxsi {
// TODO: Implement this in the kernel.
extern "C" mode_t umask(mode_t mask)
{
return 0;
}
} // namespace Maxsi

View File

@ -22,10 +22,8 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
namespace Maxsi {
#include <sys/syscall.h>
#include <unistd.h>
DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*);
@ -33,5 +31,3 @@ extern "C" int unlink(const char* pathname)
{
return SysUnlink(pathname);
}
} // namespace Maxsi

View File

@ -22,17 +22,12 @@
******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <termios.h>
namespace Maxsi {
DEFN_SYSCALL2(int, SysTCGetWinSize, SYSCALL_TCGETWINSIZE, int, struct winsize*);
extern "C" int tcgetwinsize(int fd, struct winsize* ws)
{
return SysTCGetWinSize(fd, ws);
}
} // namespace Maxsi

View File

@ -22,13 +22,10 @@
*******************************************************************************/
#include <libmaxsi/platform.h>
#include <libmaxsi/syscall.h>
#include <sys/syscall.h>
#include <errno.h>
#include <unistd.h>
namespace Maxsi {
DEFN_SYSCALL3(ssize_t, SysWrite, SYSCALL_WRITE, int, const void*, size_t);
extern "C" ssize_t write(int fd, const void* buf, size_t count)
@ -44,5 +41,3 @@ extern "C" ssize_t pwrite(int, const void*, size_t, off_t)
errno = ENOSYS;
return -1;
}
} // namespace Maxsi