aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/include/shared/sysdep-x86_64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/include/shared/sysdep-x86_64')
-rw-r--r--arch/um/include/shared/sysdep-x86_64/archsetjmp.h24
-rw-r--r--arch/um/include/shared/sysdep-x86_64/barrier.h7
-rw-r--r--arch/um/include/shared/sysdep-x86_64/checksum.h144
-rw-r--r--arch/um/include/shared/sysdep-x86_64/faultinfo.h29
-rw-r--r--arch/um/include/shared/sysdep-x86_64/kernel-offsets.h23
-rw-r--r--arch/um/include/shared/sysdep-x86_64/ptrace.h240
-rw-r--r--arch/um/include/shared/sysdep-x86_64/ptrace_user.h77
-rw-r--r--arch/um/include/shared/sysdep-x86_64/sc.h45
-rw-r--r--arch/um/include/shared/sysdep-x86_64/sigcontext.h27
-rw-r--r--arch/um/include/shared/sysdep-x86_64/skas_ptrace.h22
-rw-r--r--arch/um/include/shared/sysdep-x86_64/stub.h108
-rw-r--r--arch/um/include/shared/sysdep-x86_64/syscalls.h33
-rw-r--r--arch/um/include/shared/sysdep-x86_64/tls.h29
13 files changed, 808 insertions, 0 deletions
diff --git a/arch/um/include/shared/sysdep-x86_64/archsetjmp.h b/arch/um/include/shared/sysdep-x86_64/archsetjmp.h
new file mode 100644
index 00000000000..2af8f12ca16
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/archsetjmp.h
@@ -0,0 +1,24 @@
1/*
2 * arch/um/include/sysdep-x86_64/archsetjmp.h
3 */
4
5#ifndef _KLIBC_ARCHSETJMP_H
6#define _KLIBC_ARCHSETJMP_H
7
8struct __jmp_buf {
9 unsigned long __rbx;
10 unsigned long __rsp;
11 unsigned long __rbp;
12 unsigned long __r12;
13 unsigned long __r13;
14 unsigned long __r14;
15 unsigned long __r15;
16 unsigned long __rip;
17};
18
19typedef struct __jmp_buf jmp_buf[1];
20
21#define JB_IP __rip
22#define JB_SP __rsp
23
24#endif /* _SETJMP_H */
diff --git a/arch/um/include/shared/sysdep-x86_64/barrier.h b/arch/um/include/shared/sysdep-x86_64/barrier.h
new file mode 100644
index 00000000000..7b610befdc8
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/barrier.h
@@ -0,0 +1,7 @@
1#ifndef __SYSDEP_X86_64_BARRIER_H
2#define __SYSDEP_X86_64_BARRIER_H
3
4/* Copied from include/asm-x86_64 for use by userspace. */
5#define mb() asm volatile("mfence":::"memory")
6
7#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/checksum.h b/arch/um/include/shared/sysdep-x86_64/checksum.h
new file mode 100644
index 00000000000..a5be9031ea8
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/checksum.h
@@ -0,0 +1,144 @@
1/*
2 * Licensed under the GPL
3 */
4
5#ifndef __UM_SYSDEP_CHECKSUM_H
6#define __UM_SYSDEP_CHECKSUM_H
7
8#include "linux/string.h"
9#include "linux/in6.h"
10#include "asm/uaccess.h"
11
12extern __wsum csum_partial(const void *buff, int len, __wsum sum);
13
14/*
15 * Note: when you get a NULL pointer exception here this means someone
16 * passed in an incorrect kernel address to one of these functions.
17 *
18 * If you use these functions directly please don't forget the
19 * access_ok().
20 */
21
22static __inline__
23__wsum csum_partial_copy_nocheck(const void *src, void *dst,
24 int len, __wsum sum)
25{
26 memcpy(dst, src, len);
27 return(csum_partial(dst, len, sum));
28}
29
30static __inline__
31__wsum csum_partial_copy_from_user(const void __user *src,
32 void *dst, int len, __wsum sum,
33 int *err_ptr)
34{
35 if (copy_from_user(dst, src, len)) {
36 *err_ptr = -EFAULT;
37 return (__force __wsum)-1;
38 }
39 return csum_partial(dst, len, sum);
40}
41
42/**
43 * csum_fold - Fold and invert a 32bit checksum.
44 * sum: 32bit unfolded sum
45 *
46 * Fold a 32bit running checksum to 16bit and invert it. This is usually
47 * the last step before putting a checksum into a packet.
48 * Make sure not to mix with 64bit checksums.
49 */
50static inline __sum16 csum_fold(__wsum sum)
51{
52 __asm__(
53 " addl %1,%0\n"
54 " adcl $0xffff,%0"
55 : "=r" (sum)
56 : "r" ((__force u32)sum << 16),
57 "0" ((__force u32)sum & 0xffff0000)
58 );
59 return (__force __sum16)(~(__force u32)sum >> 16);
60}
61
62/**
63 * csum_tcpup_nofold - Compute an IPv4 pseudo header checksum.
64 * @saddr: source address
65 * @daddr: destination address
66 * @len: length of packet
67 * @proto: ip protocol of packet
68 * @sum: initial sum to be added in (32bit unfolded)
69 *
70 * Returns the pseudo header checksum the input data. Result is
71 * 32bit unfolded.
72 */
73static inline __wsum
74csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
75 unsigned short proto, __wsum sum)
76{
77 asm(" addl %1, %0\n"
78 " adcl %2, %0\n"
79 " adcl %3, %0\n"
80 " adcl $0, %0\n"
81 : "=r" (sum)
82 : "g" (daddr), "g" (saddr), "g" ((len + proto) << 8), "0" (sum));
83 return sum;
84}
85
86/*
87 * computes the checksum of the TCP/UDP pseudo-header
88 * returns a 16-bit checksum, already complemented
89 */
90static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
91 unsigned short len,
92 unsigned short proto,
93 __wsum sum)
94{
95 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
96}
97
98/**
99 * ip_fast_csum - Compute the IPv4 header checksum efficiently.
100 * iph: ipv4 header
101 * ihl: length of header / 4
102 */
103static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
104{
105 unsigned int sum;
106
107 asm( " movl (%1), %0\n"
108 " subl $4, %2\n"
109 " jbe 2f\n"
110 " addl 4(%1), %0\n"
111 " adcl 8(%1), %0\n"
112 " adcl 12(%1), %0\n"
113 "1: adcl 16(%1), %0\n"
114 " lea 4(%1), %1\n"
115 " decl %2\n"
116 " jne 1b\n"
117 " adcl $0, %0\n"
118 " movl %0, %2\n"
119 " shrl $16, %0\n"
120 " addw %w2, %w0\n"
121 " adcl $0, %0\n"
122 " notl %0\n"
123 "2:"
124 /* Since the input registers which are loaded with iph and ipl
125 are modified, we must also specify them as outputs, or gcc
126 will assume they contain their original values. */
127 : "=r" (sum), "=r" (iph), "=r" (ihl)
128 : "1" (iph), "2" (ihl)
129 : "memory");
130 return (__force __sum16)sum;
131}
132
133static inline unsigned add32_with_carry(unsigned a, unsigned b)
134{
135 asm("addl %2,%0\n\t"
136 "adcl $0,%0"
137 : "=r" (a)
138 : "0" (a), "r" (b));
139 return a;
140}
141
142extern __sum16 ip_compute_csum(const void *buff, int len);
143
144#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/faultinfo.h b/arch/um/include/shared/sysdep-x86_64/faultinfo.h
new file mode 100644
index 00000000000..cb917b0d566
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/faultinfo.h
@@ -0,0 +1,29 @@
1/*
2 * Copyright (C) 2004 Fujitsu Siemens Computers GmbH
3 * Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
4 * Licensed under the GPL
5 */
6
7#ifndef __FAULTINFO_X86_64_H
8#define __FAULTINFO_X86_64_H
9
10/* this structure contains the full arch-specific faultinfo
11 * from the traps.
12 * On i386, ptrace_faultinfo unfortunately doesn't provide
13 * all the info, since trap_no is missing.
14 * All common elements are defined at the same position in
15 * both structures, thus making it easy to copy the
16 * contents without knowledge about the structure elements.
17 */
18struct faultinfo {
19 int error_code; /* in ptrace_faultinfo misleadingly called is_write */
20 unsigned long cr2; /* in ptrace_faultinfo called addr */
21 int trap_no; /* missing in ptrace_faultinfo */
22};
23
24#define FAULT_WRITE(fi) ((fi).error_code & 2)
25#define FAULT_ADDRESS(fi) ((fi).cr2)
26
27#define PTRACE_FULL_FAULTINFO 1
28
29#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h b/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h
new file mode 100644
index 00000000000..a307237b796
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/kernel-offsets.h
@@ -0,0 +1,23 @@
1#include <linux/stddef.h>
2#include <linux/sched.h>
3#include <linux/time.h>
4#include <linux/elf.h>
5#include <linux/crypto.h>
6#include <asm/page.h>
7#include <asm/mman.h>
8
9#define DEFINE(sym, val) \
10 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
11
12#define DEFINE_STR1(x) #x
13#define DEFINE_STR(sym, val) asm volatile("\n->" #sym " " DEFINE_STR1(val) " " #val: : )
14
15#define BLANK() asm volatile("\n->" : : )
16
17#define OFFSET(sym, str, mem) \
18 DEFINE(sym, offsetof(struct str, mem));
19
20void foo(void)
21{
22#include <common-offsets.h>
23}
diff --git a/arch/um/include/shared/sysdep-x86_64/ptrace.h b/arch/um/include/shared/sysdep-x86_64/ptrace.h
new file mode 100644
index 00000000000..9ea44d111f3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/ptrace.h
@@ -0,0 +1,240 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 *
5 * Licensed under the GPL
6 */
7
8#ifndef __SYSDEP_X86_64_PTRACE_H
9#define __SYSDEP_X86_64_PTRACE_H
10
11#include "uml-config.h"
12#include "user_constants.h"
13#include "sysdep/faultinfo.h"
14
15#define MAX_REG_OFFSET (UM_FRAME_SIZE)
16#define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long))
17
18#include "skas_ptregs.h"
19
20#define REGS_IP(r) ((r)[HOST_IP])
21#define REGS_SP(r) ((r)[HOST_SP])
22
23#define REGS_RBX(r) ((r)[HOST_RBX])
24#define REGS_RCX(r) ((r)[HOST_RCX])
25#define REGS_RDX(r) ((r)[HOST_RDX])
26#define REGS_RSI(r) ((r)[HOST_RSI])
27#define REGS_RDI(r) ((r)[HOST_RDI])
28#define REGS_RBP(r) ((r)[HOST_RBP])
29#define REGS_RAX(r) ((r)[HOST_RAX])
30#define REGS_R8(r) ((r)[HOST_R8])
31#define REGS_R9(r) ((r)[HOST_R9])
32#define REGS_R10(r) ((r)[HOST_R10])
33#define REGS_R11(r) ((r)[HOST_R11])
34#define REGS_R12(r) ((r)[HOST_R12])
35#define REGS_R13(r) ((r)[HOST_R13])
36#define REGS_R14(r) ((r)[HOST_R14])
37#define REGS_R15(r) ((r)[HOST_R15])
38#define REGS_CS(r) ((r)[HOST_CS])
39#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
40#define REGS_SS(r) ((r)[HOST_SS])
41
42#define HOST_FS_BASE 21
43#define HOST_GS_BASE 22
44#define HOST_DS 23
45#define HOST_ES 24
46#define HOST_FS 25
47#define HOST_GS 26
48
49/* Also defined in asm/ptrace-x86_64.h, but not in libc headers. So, these
50 * are already defined for kernel code, but not for userspace code.
51 */
52#ifndef FS_BASE
53/* These aren't defined in ptrace.h, but exist in struct user_regs_struct,
54 * which is what x86_64 ptrace actually uses.
55 */
56#define FS_BASE (HOST_FS_BASE * sizeof(long))
57#define GS_BASE (HOST_GS_BASE * sizeof(long))
58#define DS (HOST_DS * sizeof(long))
59#define ES (HOST_ES * sizeof(long))
60#define FS (HOST_FS * sizeof(long))
61#define GS (HOST_GS * sizeof(long))
62#endif
63
64#define REGS_FS_BASE(r) ((r)[HOST_FS_BASE])
65#define REGS_GS_BASE(r) ((r)[HOST_GS_BASE])
66#define REGS_DS(r) ((r)[HOST_DS])
67#define REGS_ES(r) ((r)[HOST_ES])
68#define REGS_FS(r) ((r)[HOST_FS])
69#define REGS_GS(r) ((r)[HOST_GS])
70
71#define REGS_ORIG_RAX(r) ((r)[HOST_ORIG_RAX])
72
73#define REGS_SET_SYSCALL_RETURN(r, res) REGS_RAX(r) = (res)
74
75#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
76
77#define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)
78
79#define REGS_FAULT_ADDR(r) ((r)->fault_addr)
80
81#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
82
83#define REGS_TRAP(r) ((r)->trap_type)
84
85#define REGS_ERR(r) ((r)->fault_type)
86
87struct uml_pt_regs {
88 unsigned long gp[MAX_REG_NR];
89 struct faultinfo faultinfo;
90 long syscall;
91 int is_user;
92};
93
94#define EMPTY_UML_PT_REGS { }
95
96#define UPT_RBX(r) REGS_RBX((r)->gp)
97#define UPT_RCX(r) REGS_RCX((r)->gp)
98#define UPT_RDX(r) REGS_RDX((r)->gp)
99#define UPT_RSI(r) REGS_RSI((r)->gp)
100#define UPT_RDI(r) REGS_RDI((r)->gp)
101#define UPT_RBP(r) REGS_RBP((r)->gp)
102#define UPT_RAX(r) REGS_RAX((r)->gp)
103#define UPT_R8(r) REGS_R8((r)->gp)
104#define UPT_R9(r) REGS_R9((r)->gp)
105#define UPT_R10(r) REGS_R10((r)->gp)
106#define UPT_R11(r) REGS_R11((r)->gp)
107#define UPT_R12(r) REGS_R12((r)->gp)
108#define UPT_R13(r) REGS_R13((r)->gp)
109#define UPT_R14(r) REGS_R14((r)->gp)
110#define UPT_R15(r) REGS_R15((r)->gp)
111#define UPT_CS(r) REGS_CS((r)->gp)
112#define UPT_FS_BASE(r) REGS_FS_BASE((r)->gp)
113#define UPT_FS(r) REGS_FS((r)->gp)
114#define UPT_GS_BASE(r) REGS_GS_BASE((r)->gp)
115#define UPT_GS(r) REGS_GS((r)->gp)
116#define UPT_DS(r) REGS_DS((r)->gp)
117#define UPT_ES(r) REGS_ES((r)->gp)
118#define UPT_CS(r) REGS_CS((r)->gp)
119#define UPT_SS(r) REGS_SS((r)->gp)
120#define UPT_ORIG_RAX(r) REGS_ORIG_RAX((r)->gp)
121
122#define UPT_IP(r) REGS_IP((r)->gp)
123#define UPT_SP(r) REGS_SP((r)->gp)
124
125#define UPT_EFLAGS(r) REGS_EFLAGS((r)->gp)
126#define UPT_SYSCALL_NR(r) ((r)->syscall)
127#define UPT_SYSCALL_RET(r) UPT_RAX(r)
128
129extern int user_context(unsigned long sp);
130
131#define UPT_IS_USER(r) ((r)->is_user)
132
133#define UPT_SYSCALL_ARG1(r) UPT_RDI(r)
134#define UPT_SYSCALL_ARG2(r) UPT_RSI(r)
135#define UPT_SYSCALL_ARG3(r) UPT_RDX(r)
136#define UPT_SYSCALL_ARG4(r) UPT_R10(r)
137#define UPT_SYSCALL_ARG5(r) UPT_R8(r)
138#define UPT_SYSCALL_ARG6(r) UPT_R9(r)
139
140struct syscall_args {
141 unsigned long args[6];
142};
143
144#define SYSCALL_ARGS(r) ((struct syscall_args) \
145 { .args = { UPT_SYSCALL_ARG1(r), \
146 UPT_SYSCALL_ARG2(r), \
147 UPT_SYSCALL_ARG3(r), \
148 UPT_SYSCALL_ARG4(r), \
149 UPT_SYSCALL_ARG5(r), \
150 UPT_SYSCALL_ARG6(r) } } )
151
152#define UPT_REG(regs, reg) \
153 ({ unsigned long val; \
154 switch(reg){ \
155 case R8: val = UPT_R8(regs); break; \
156 case R9: val = UPT_R9(regs); break; \
157 case R10: val = UPT_R10(regs); break; \
158 case R11: val = UPT_R11(regs); break; \
159 case R12: val = UPT_R12(regs); break; \
160 case R13: val = UPT_R13(regs); break; \
161 case R14: val = UPT_R14(regs); break; \
162 case R15: val = UPT_R15(regs); break; \
163 case RIP: val = UPT_IP(regs); break; \
164 case RSP: val = UPT_SP(regs); break; \
165 case RAX: val = UPT_RAX(regs); break; \
166 case RBX: val = UPT_RBX(regs); break; \
167 case RCX: val = UPT_RCX(regs); break; \
168 case RDX: val = UPT_RDX(regs); break; \
169 case RSI: val = UPT_RSI(regs); break; \
170 case RDI: val = UPT_RDI(regs); break; \
171 case RBP: val = UPT_RBP(regs); break; \
172 case ORIG_RAX: val = UPT_ORIG_RAX(regs); break; \
173 case CS: val = UPT_CS(regs); break; \
174 case SS: val = UPT_SS(regs); break; \
175 case FS_BASE: val = UPT_FS_BASE(regs); break; \
176 case GS_BASE: val = UPT_GS_BASE(regs); break; \
177 case DS: val = UPT_DS(regs); break; \
178 case ES: val = UPT_ES(regs); break; \
179 case FS : val = UPT_FS (regs); break; \
180 case GS: val = UPT_GS(regs); break; \
181 case EFLAGS: val = UPT_EFLAGS(regs); break; \
182 default : \
183 panic("Bad register in UPT_REG : %d\n", reg); \
184 val = -1; \
185 } \
186 val; \
187 })
188
189
190#define UPT_SET(regs, reg, val) \
191 ({ unsigned long __upt_val = val; \
192 switch(reg){ \
193 case R8: UPT_R8(regs) = __upt_val; break; \
194 case R9: UPT_R9(regs) = __upt_val; break; \
195 case R10: UPT_R10(regs) = __upt_val; break; \
196 case R11: UPT_R11(regs) = __upt_val; break; \
197 case R12: UPT_R12(regs) = __upt_val; break; \
198 case R13: UPT_R13(regs) = __upt_val; break; \
199 case R14: UPT_R14(regs) = __upt_val; break; \
200 case R15: UPT_R15(regs) = __upt_val; break; \
201 case RIP: UPT_IP(regs) = __upt_val; break; \
202 case RSP: UPT_SP(regs) = __upt_val; break; \
203 case RAX: UPT_RAX(regs) = __upt_val; break; \
204 case RBX: UPT_RBX(regs) = __upt_val; break; \
205 case RCX: UPT_RCX(regs) = __upt_val; break; \
206 case RDX: UPT_RDX(regs) = __upt_val; break; \
207 case RSI: UPT_RSI(regs) = __upt_val; break; \
208 case RDI: UPT_RDI(regs) = __upt_val; break; \
209 case RBP: UPT_RBP(regs) = __upt_val; break; \
210 case ORIG_RAX: UPT_ORIG_RAX(regs) = __upt_val; break; \
211 case CS: UPT_CS(regs) = __upt_val; break; \
212 case SS: UPT_SS(regs) = __upt_val; break; \
213 case FS_BASE: UPT_FS_BASE(regs) = __upt_val; break; \
214 case GS_BASE: UPT_GS_BASE(regs) = __upt_val; break; \
215 case DS: UPT_DS(regs) = __upt_val; break; \
216 case ES: UPT_ES(regs) = __upt_val; break; \
217 case FS: UPT_FS(regs) = __upt_val; break; \
218 case GS: UPT_GS(regs) = __upt_val; break; \
219 case EFLAGS: UPT_EFLAGS(regs) = __upt_val; break; \
220 default : \
221 panic("Bad register in UPT_SET : %d\n", reg); \
222 break; \
223 } \
224 __upt_val; \
225 })
226
227#define UPT_SET_SYSCALL_RETURN(r, res) \
228 REGS_SET_SYSCALL_RETURN((r)->regs, (res))
229
230#define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->gp)
231
232#define UPT_SEGV_IS_FIXABLE(r) REGS_SEGV_IS_FIXABLE(&r->skas)
233
234#define UPT_FAULTINFO(r) (&(r)->faultinfo)
235
236static inline void arch_init_registers(int pid)
237{
238}
239
240#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/ptrace_user.h b/arch/um/include/shared/sysdep-x86_64/ptrace_user.h
new file mode 100644
index 00000000000..4dbccdb58f4
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/ptrace_user.h
@@ -0,0 +1,77 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_PTRACE_USER_H__
8#define __SYSDEP_X86_64_PTRACE_USER_H__
9
10#define __FRAME_OFFSETS
11#include <sys/ptrace.h>
12#include <linux/ptrace.h>
13#include <asm/ptrace.h>
14#undef __FRAME_OFFSETS
15#include "user_constants.h"
16
17#define PT_INDEX(off) ((off) / sizeof(unsigned long))
18
19#define PT_SYSCALL_NR(regs) ((regs)[PT_INDEX(ORIG_RAX)])
20#define PT_SYSCALL_NR_OFFSET (ORIG_RAX)
21
22#define PT_SYSCALL_ARG1(regs) (((unsigned long *) (regs))[PT_INDEX(RDI)])
23#define PT_SYSCALL_ARG1_OFFSET (RDI)
24
25#define PT_SYSCALL_ARG2(regs) (((unsigned long *) (regs))[PT_INDEX(RSI)])
26#define PT_SYSCALL_ARG2_OFFSET (RSI)
27
28#define PT_SYSCALL_ARG3(regs) (((unsigned long *) (regs))[PT_INDEX(RDX)])
29#define PT_SYSCALL_ARG3_OFFSET (RDX)
30
31#define PT_SYSCALL_ARG4(regs) (((unsigned long *) (regs))[PT_INDEX(RCX)])
32#define PT_SYSCALL_ARG4_OFFSET (RCX)
33
34#define PT_SYSCALL_ARG5(regs) (((unsigned long *) (regs))[PT_INDEX(R8)])
35#define PT_SYSCALL_ARG5_OFFSET (R8)
36
37#define PT_SYSCALL_ARG6(regs) (((unsigned long *) (regs))[PT_INDEX(R9)])
38#define PT_SYSCALL_ARG6_OFFSET (R9)
39
40#define PT_SYSCALL_RET_OFFSET (RAX)
41
42#define PT_IP_OFFSET (RIP)
43#define PT_IP(regs) ((regs)[PT_INDEX(RIP)])
44
45#define PT_SP_OFFSET (RSP)
46#define PT_SP(regs) ((regs)[PT_INDEX(RSP)])
47
48#define PT_ORIG_RAX_OFFSET (ORIG_RAX)
49#define PT_ORIG_RAX(regs) ((regs)[PT_INDEX(ORIG_RAX)])
50
51/*
52 * x86_64 FC3 doesn't define this in /usr/include/linux/ptrace.h even though
53 * it's defined in the kernel's include/linux/ptrace.h. Additionally, use the
54 * 2.4 name and value for 2.4 host compatibility.
55 */
56#ifndef PTRACE_OLDSETOPTIONS
57#define PTRACE_OLDSETOPTIONS 21
58#endif
59
60/*
61 * These are before the system call, so the system call number is RAX
62 * rather than ORIG_RAX, and arg4 is R10 rather than RCX
63 */
64#define REGS_SYSCALL_NR PT_INDEX(RAX)
65#define REGS_SYSCALL_ARG1 PT_INDEX(RDI)
66#define REGS_SYSCALL_ARG2 PT_INDEX(RSI)
67#define REGS_SYSCALL_ARG3 PT_INDEX(RDX)
68#define REGS_SYSCALL_ARG4 PT_INDEX(R10)
69#define REGS_SYSCALL_ARG5 PT_INDEX(R8)
70#define REGS_SYSCALL_ARG6 PT_INDEX(R9)
71
72#define REGS_IP_INDEX PT_INDEX(RIP)
73#define REGS_SP_INDEX PT_INDEX(RSP)
74
75#define FP_SIZE (HOST_FP_SIZE)
76
77#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/sc.h b/arch/um/include/shared/sysdep-x86_64/sc.h
new file mode 100644
index 00000000000..8aee45b0743
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/sc.h
@@ -0,0 +1,45 @@
1#ifndef __SYSDEP_X86_64_SC_H
2#define __SYSDEP_X86_64_SC_H
3
4/* Copyright (C) 2003 - 2004 PathScale, Inc
5 * Released under the GPL
6 */
7
8#include <user_constants.h>
9
10#define SC_OFFSET(sc, field) \
11 *((unsigned long *) &(((char *) (sc))[HOST_##field]))
12
13#define SC_RBX(sc) SC_OFFSET(sc, SC_RBX)
14#define SC_RCX(sc) SC_OFFSET(sc, SC_RCX)
15#define SC_RDX(sc) SC_OFFSET(sc, SC_RDX)
16#define SC_RSI(sc) SC_OFFSET(sc, SC_RSI)
17#define SC_RDI(sc) SC_OFFSET(sc, SC_RDI)
18#define SC_RBP(sc) SC_OFFSET(sc, SC_RBP)
19#define SC_RAX(sc) SC_OFFSET(sc, SC_RAX)
20#define SC_R8(sc) SC_OFFSET(sc, SC_R8)
21#define SC_R9(sc) SC_OFFSET(sc, SC_R9)
22#define SC_R10(sc) SC_OFFSET(sc, SC_R10)
23#define SC_R11(sc) SC_OFFSET(sc, SC_R11)
24#define SC_R12(sc) SC_OFFSET(sc, SC_R12)
25#define SC_R13(sc) SC_OFFSET(sc, SC_R13)
26#define SC_R14(sc) SC_OFFSET(sc, SC_R14)
27#define SC_R15(sc) SC_OFFSET(sc, SC_R15)
28#define SC_IP(sc) SC_OFFSET(sc, SC_IP)
29#define SC_SP(sc) SC_OFFSET(sc, SC_SP)
30#define SC_CR2(sc) SC_OFFSET(sc, SC_CR2)
31#define SC_ERR(sc) SC_OFFSET(sc, SC_ERR)
32#define SC_TRAPNO(sc) SC_OFFSET(sc, SC_TRAPNO)
33#define SC_CS(sc) SC_OFFSET(sc, SC_CS)
34#define SC_FS(sc) SC_OFFSET(sc, SC_FS)
35#define SC_GS(sc) SC_OFFSET(sc, SC_GS)
36#define SC_EFLAGS(sc) SC_OFFSET(sc, SC_EFLAGS)
37#define SC_SIGMASK(sc) SC_OFFSET(sc, SC_SIGMASK)
38#define SC_SS(sc) SC_OFFSET(sc, SC_SS)
39#if 0
40#define SC_ORIG_RAX(sc) SC_OFFSET(sc, SC_ORIG_RAX)
41#define SC_DS(sc) SC_OFFSET(sc, SC_DS)
42#define SC_ES(sc) SC_OFFSET(sc, SC_ES)
43#endif
44
45#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/sigcontext.h b/arch/um/include/shared/sysdep-x86_64/sigcontext.h
new file mode 100644
index 00000000000..0155133b145
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/sigcontext.h
@@ -0,0 +1,27 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_SIGCONTEXT_H
8#define __SYSDEP_X86_64_SIGCONTEXT_H
9
10#include <sysdep/sc.h>
11
12#define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
13
14#define GET_FAULTINFO_FROM_SC(fi, sc) \
15 { \
16 (fi).cr2 = SC_CR2(sc); \
17 (fi).error_code = SC_ERR(sc); \
18 (fi).trap_no = SC_TRAPNO(sc); \
19 }
20
21/* This is Page Fault */
22#define SEGV_IS_FIXABLE(fi) ((fi)->trap_no == 14)
23
24/* No broken SKAS API, which doesn't pass trap_no, here. */
25#define SEGV_MAYBE_FIXABLE(fi) 0
26
27#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h b/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h
new file mode 100644
index 00000000000..95db4be786e
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/skas_ptrace.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_X86_64_SKAS_PTRACE_H
7#define __SYSDEP_X86_64_SKAS_PTRACE_H
8
9struct ptrace_faultinfo {
10 int is_write;
11 unsigned long addr;
12};
13
14struct ptrace_ldt {
15 int func;
16 void *ptr;
17 unsigned long bytecount;
18};
19
20#define PTRACE_LDT 54
21
22#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/stub.h b/arch/um/include/shared/sysdep-x86_64/stub.h
new file mode 100644
index 00000000000..655f9c2de3a
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/stub.h
@@ -0,0 +1,108 @@
1/*
2 * Copyright (C) 2004 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __SYSDEP_STUB_H
7#define __SYSDEP_STUB_H
8
9#include <sys/mman.h>
10#include <asm/unistd.h>
11#include <sysdep/ptrace_user.h>
12#include "as-layout.h"
13#include "stub-data.h"
14#include "kern_constants.h"
15#include "uml-config.h"
16
17extern void stub_segv_handler(int sig);
18extern void stub_clone_handler(void);
19
20#define STUB_SYSCALL_RET PT_INDEX(RAX)
21#define STUB_MMAP_NR __NR_mmap
22#define MMAP_OFFSET(o) (o)
23
24#define __syscall_clobber "r11","rcx","memory"
25#define __syscall "syscall"
26
27static inline long stub_syscall0(long syscall)
28{
29 long ret;
30
31 __asm__ volatile (__syscall
32 : "=a" (ret)
33 : "0" (syscall) : __syscall_clobber );
34
35 return ret;
36}
37
38static inline long stub_syscall2(long syscall, long arg1, long arg2)
39{
40 long ret;
41
42 __asm__ volatile (__syscall
43 : "=a" (ret)
44 : "0" (syscall), "D" (arg1), "S" (arg2) : __syscall_clobber );
45
46 return ret;
47}
48
49static inline long stub_syscall3(long syscall, long arg1, long arg2, long arg3)
50{
51 long ret;
52
53 __asm__ volatile (__syscall
54 : "=a" (ret)
55 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3)
56 : __syscall_clobber );
57
58 return ret;
59}
60
61static inline long stub_syscall4(long syscall, long arg1, long arg2, long arg3,
62 long arg4)
63{
64 long ret;
65
66 __asm__ volatile ("movq %5,%%r10 ; " __syscall
67 : "=a" (ret)
68 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
69 "g" (arg4)
70 : __syscall_clobber, "r10" );
71
72 return ret;
73}
74
75static inline long stub_syscall5(long syscall, long arg1, long arg2, long arg3,
76 long arg4, long arg5)
77{
78 long ret;
79
80 __asm__ volatile ("movq %5,%%r10 ; movq %6,%%r8 ; " __syscall
81 : "=a" (ret)
82 : "0" (syscall), "D" (arg1), "S" (arg2), "d" (arg3),
83 "g" (arg4), "g" (arg5)
84 : __syscall_clobber, "r10", "r8" );
85
86 return ret;
87}
88
89static inline void trap_myself(void)
90{
91 __asm("int3");
92}
93
94static inline void remap_stack(long fd, unsigned long offset)
95{
96 __asm__ volatile ("movq %4,%%r10 ; movq %5,%%r8 ; "
97 "movq %6, %%r9; " __syscall "; movq %7, %%rbx ; "
98 "movq %%rax, (%%rbx)":
99 : "a" (STUB_MMAP_NR), "D" (STUB_DATA),
100 "S" (UM_KERN_PAGE_SIZE),
101 "d" (PROT_READ | PROT_WRITE),
102 "g" (MAP_FIXED | MAP_SHARED), "g" (fd),
103 "g" (offset),
104 "i" (&((struct stub_data *) STUB_DATA)->err)
105 : __syscall_clobber, "r10", "r8", "r9" );
106}
107
108#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/syscalls.h b/arch/um/include/shared/sysdep-x86_64/syscalls.h
new file mode 100644
index 00000000000..7cfb0b08565
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/syscalls.h
@@ -0,0 +1,33 @@
1/*
2 * Copyright 2003 PathScale, Inc.
3 *
4 * Licensed under the GPL
5 */
6
7#ifndef __SYSDEP_X86_64_SYSCALLS_H__
8#define __SYSDEP_X86_64_SYSCALLS_H__
9
10#include <linux/msg.h>
11#include <linux/shm.h>
12#include <kern_constants.h>
13
14typedef long syscall_handler_t(void);
15
16extern syscall_handler_t *sys_call_table[];
17
18#define EXECUTE_SYSCALL(syscall, regs) \
19 (((long (*)(long, long, long, long, long, long)) \
20 (*sys_call_table[syscall]))(UPT_SYSCALL_ARG1(&regs->regs), \
21 UPT_SYSCALL_ARG2(&regs->regs), \
22 UPT_SYSCALL_ARG3(&regs->regs), \
23 UPT_SYSCALL_ARG4(&regs->regs), \
24 UPT_SYSCALL_ARG5(&regs->regs), \
25 UPT_SYSCALL_ARG6(&regs->regs)))
26
27extern long old_mmap(unsigned long addr, unsigned long len,
28 unsigned long prot, unsigned long flags,
29 unsigned long fd, unsigned long pgoff);
30extern syscall_handler_t sys_modify_ldt;
31extern syscall_handler_t sys_arch_prctl;
32
33#endif
diff --git a/arch/um/include/shared/sysdep-x86_64/tls.h b/arch/um/include/shared/sysdep-x86_64/tls.h
new file mode 100644
index 00000000000..35f19f25bd3
--- /dev/null
+++ b/arch/um/include/shared/sysdep-x86_64/tls.h
@@ -0,0 +1,29 @@
1#ifndef _SYSDEP_TLS_H
2#define _SYSDEP_TLS_H
3
4# ifndef __KERNEL__
5
6/* Change name to avoid conflicts with the original one from <asm/ldt.h>, which
7 * may be named user_desc (but in 2.4 and in header matching its API was named
8 * modify_ldt_ldt_s). */
9
10typedef struct um_dup_user_desc {
11 unsigned int entry_number;
12 unsigned int base_addr;
13 unsigned int limit;
14 unsigned int seg_32bit:1;
15 unsigned int contents:2;
16 unsigned int read_exec_only:1;
17 unsigned int limit_in_pages:1;
18 unsigned int seg_not_present:1;
19 unsigned int useable:1;
20 unsigned int lm:1;
21} user_desc_t;
22
23# else /* __KERNEL__ */
24
25# include <asm/ldt.h>
26typedef struct user_desc user_desc_t;
27
28# endif /* __KERNEL__ */
29#endif /* _SYSDEP_TLS_H */