2011-09-23 12:00:45 +04:00
|
|
|
#ifndef CR_SYSCALL_H_
|
|
|
|
#define CR_SYSCALL_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "compiler.h"
|
2011-10-19 13:09:01 +04:00
|
|
|
#include "syscall-codes.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long syscall0(int nr)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long syscall1(int nr, unsigned long arg0)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long syscall2(int nr, unsigned long arg0, unsigned long arg1)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0), "S" (arg1)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long syscall3(int nr, unsigned long arg0, unsigned long arg1,
|
2011-10-24 22:16:14 +04:00
|
|
|
unsigned long arg2)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0), "S" (arg1), "d" (arg2)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long syscall4(int nr, unsigned long arg0, unsigned long arg1,
|
2011-10-24 22:16:14 +04:00
|
|
|
unsigned long arg2, unsigned long arg3)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
register unsigned long r10 asm("r10") = r10;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
r10 = arg3;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0), "S" (arg1), "d" (arg2)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static long always_inline syscall5(int nr, unsigned long arg0, unsigned long arg1,
|
2011-10-24 22:16:14 +04:00
|
|
|
unsigned long arg2, unsigned long arg3,
|
|
|
|
unsigned long arg4)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
register unsigned long r10 asm("r10") = r10;
|
|
|
|
register unsigned long r8 asm("r8") = r8;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
r10 = arg3;
|
|
|
|
r8 = arg4;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0), "S" (arg1), "d" (arg2)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static long always_inline syscall6(int nr, unsigned long arg0, unsigned long arg1,
|
2011-10-24 22:16:14 +04:00
|
|
|
unsigned long arg2, unsigned long arg3,
|
|
|
|
unsigned long arg4, unsigned long arg5)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
register unsigned long r10 asm("r10") = r10;
|
|
|
|
register unsigned long r8 asm("r8") = r8;
|
|
|
|
register unsigned long r9 asm("r9") = r9;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
r10 = arg3;
|
|
|
|
r8 = arg4;
|
|
|
|
r9 = arg5;
|
|
|
|
asm volatile("syscall"
|
|
|
|
: "=a" (ret)
|
|
|
|
: "a" (nr), "D" (arg0), "S" (arg1), "d" (arg2)
|
|
|
|
: "memory");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline unsigned long sys_pause(void)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall0(__NR_pause);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline unsigned long sys_mmap(void *addr, unsigned long len, unsigned long prot,
|
2011-10-24 22:16:14 +04:00
|
|
|
unsigned long flags, unsigned long fd, unsigned long offset)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall6(__NR_mmap, (unsigned long)addr,
|
|
|
|
len, prot, flags, fd, offset);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline unsigned long sys_munmap(void *addr,unsigned long len)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall2(__NR_munmap, (unsigned long)addr, len);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_open(const char *filename, unsigned long flags, unsigned long mode)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_open, (unsigned long)filename, flags, mode);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_close(int fd)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall1(__NR_close, fd);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_write(unsigned long fd, const void *buf, unsigned long count)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_write, fd, (unsigned long)buf, count);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_mincore(unsigned long addr, unsigned long size, void *vec)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_mincore, addr, size, (unsigned long)vec);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_lseek(unsigned long fd, unsigned long offset, unsigned long origin)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_lseek, fd, offset, origin);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_mprotect(unsigned long start, unsigned long len, unsigned long prot)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_mprotect, start, len, prot);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_nanosleep(struct timespec *req, struct timespec *rem)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall2(__NR_nanosleep, (unsigned long)req, (unsigned long)rem);
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_read(unsigned long fd, void *buf, unsigned long count)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
|
|
|
return syscall3(__NR_read, fd, (unsigned long)buf, count);
|
|
|
|
}
|
|
|
|
|
2011-10-26 10:58:10 +04:00
|
|
|
static always_inline long sys_exit(unsigned long error_code)
|
|
|
|
{
|
|
|
|
return syscall1(__NR_exit, error_code);
|
|
|
|
}
|
|
|
|
|
2011-10-24 17:17:39 +04:00
|
|
|
/*
|
|
|
|
* Note this call expects a signal frame on stack
|
|
|
|
* (regs->sp) so be very carefull here!
|
|
|
|
*/
|
2011-10-24 22:18:13 +04:00
|
|
|
static always_inline long sys_rt_sigreturn(void)
|
2011-10-24 17:17:39 +04:00
|
|
|
{
|
|
|
|
return syscall0(__NR_rt_sigreturn);
|
|
|
|
}
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
#else /* CONFIG_X86_64 */
|
|
|
|
# error x86-32 bit mode not yet implemented
|
|
|
|
#endif /* CONFIG_X86_64 */
|
|
|
|
|
|
|
|
#endif /* CR_SYSCALL_H_ */
|