The Pedigree Project  0.1
x64/syscall-stubs.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef SERVICE
21 #error syscall-stubs.h requires SERVICE to be defined
22 #endif
23 #ifndef SERVICE_ERROR
24 #error syscall-stubs.h requires SERVICE_ERROR to be defined
25 #endif
26 #ifndef SERVICE_INIT
27 #error syscall-stubs.h requires SERVICE_INIT to be defined
28 #endif
29 
30 static long
31 syscall6(long function, long p1, long p2, long p3, long p4, long p5, long p6)
32 {
33  long eax = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
34  long ret;
35  long err;
36  register long p5_r __asm__("r8") = p5;
37  register long p6_r __asm__("r9") = p6;
38 
39  SERVICE_INIT;
40 
41  __asm__ __volatile__("syscall"
42  : "=a"(ret), "=b"(err)
43  : "0"(eax), "1"(p1), "d"(p2), "S"(p3), "D"(p4),
44  "r"(p5_r), "r"(p6_r)
45  : "rcx", "r11", "memory");
46 
47  if (err)
48  {
49  SERVICE_ERROR = err;
50  }
51  return ret;
52 }
53 
54 static long syscall6_err(
55  long function, long p1, long p2, long p3, long p4, long p5, long p6,
56  long *err)
57 {
58  long eax = ((SERVICE & 0xFFFF) << 16) | (function & 0xFFFF);
59  long ret;
60  register long p5_r __asm__("r8") = p5;
61  register long p6_r __asm__("r9") = p6;
62 
63  *err = 0;
64  __asm__ __volatile__("syscall"
65  : "=a"(ret), "=b"(*err)
66  : "0"(eax), "1"(p1), "d"(p2), "S"(p3), "D"(p4),
67  "r"(p5_r), "r"(p6_r)
68  : "rcx", "r11", "memory");
69 
70  return ret;
71 }
72 
73 static long syscall0(long function)
74 {
75  return syscall6(function, 0, 0, 0, 0, 0, 0);
76 }
77 
78 static long syscall1(long function, long p1)
79 {
80  return syscall6(function, p1, 0, 0, 0, 0, 0);
81 }
82 
83 static long syscall2(long function, long p1, long p2)
84 {
85  return syscall6(function, p1, p2, 0, 0, 0, 0);
86 }
87 
88 static long syscall3(long function, long p1, long p2, long p3)
89 {
90  return syscall6(function, p1, p2, p3, 0, 0, 0);
91 }
92 
93 static long syscall4(long function, long p1, long p2, long p3, long p4)
94 {
95  return syscall6(function, p1, p2, p3, p4, 0, 0);
96 }
97 
98 static long syscall5(long function, long p1, long p2, long p3, long p4, long p5)
99 {
100  return syscall6(function, p1, p2, p3, p4, p5, 0);
101 }