blob: 866fe7e473697563d48c4b5d20c44597e693c266 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2003 PathScale, Inc.
Jeff Dike42fda662007-10-16 01:26:50 -07003 * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Licensed under the GPL
6 */
7
8#ifndef __SYSDEP_X86_64_PTRACE_H
9#define __SYSDEP_X86_64_PTRACE_H
10
Al Viro4de1c5f2011-08-18 20:01:19 +010011#include <generated/user_constants.h>
Bodo Stroesserc5784552005-05-05 16:15:31 -070012#include "sysdep/faultinfo.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#define MAX_REG_OFFSET (UM_FRAME_SIZE)
15#define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long))
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define REGS_IP(r) ((r)[HOST_IP])
18#define REGS_SP(r) ((r)[HOST_SP])
19
20#define REGS_RBX(r) ((r)[HOST_RBX])
21#define REGS_RCX(r) ((r)[HOST_RCX])
22#define REGS_RDX(r) ((r)[HOST_RDX])
23#define REGS_RSI(r) ((r)[HOST_RSI])
24#define REGS_RDI(r) ((r)[HOST_RDI])
25#define REGS_RBP(r) ((r)[HOST_RBP])
26#define REGS_RAX(r) ((r)[HOST_RAX])
27#define REGS_R8(r) ((r)[HOST_R8])
28#define REGS_R9(r) ((r)[HOST_R9])
29#define REGS_R10(r) ((r)[HOST_R10])
30#define REGS_R11(r) ((r)[HOST_R11])
31#define REGS_R12(r) ((r)[HOST_R12])
32#define REGS_R13(r) ((r)[HOST_R13])
33#define REGS_R14(r) ((r)[HOST_R14])
34#define REGS_R15(r) ((r)[HOST_R15])
35#define REGS_CS(r) ((r)[HOST_CS])
36#define REGS_EFLAGS(r) ((r)[HOST_EFLAGS])
37#define REGS_SS(r) ((r)[HOST_SS])
38
39#define HOST_FS_BASE 21
40#define HOST_GS_BASE 22
41#define HOST_DS 23
42#define HOST_ES 24
43#define HOST_FS 25
44#define HOST_GS 26
45
Jeff Dikea8b4fc42006-09-27 01:50:35 -070046/* Also defined in asm/ptrace-x86_64.h, but not in libc headers. So, these
47 * are already defined for kernel code, but not for userspace code.
48 */
49#ifndef FS_BASE
50/* These aren't defined in ptrace.h, but exist in struct user_regs_struct,
51 * which is what x86_64 ptrace actually uses.
52 */
53#define FS_BASE (HOST_FS_BASE * sizeof(long))
54#define GS_BASE (HOST_GS_BASE * sizeof(long))
55#define DS (HOST_DS * sizeof(long))
56#define ES (HOST_ES * sizeof(long))
57#define FS (HOST_FS * sizeof(long))
58#define GS (HOST_GS * sizeof(long))
59#endif
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define REGS_FS_BASE(r) ((r)[HOST_FS_BASE])
62#define REGS_GS_BASE(r) ((r)[HOST_GS_BASE])
63#define REGS_DS(r) ((r)[HOST_DS])
64#define REGS_ES(r) ((r)[HOST_ES])
65#define REGS_FS(r) ((r)[HOST_FS])
66#define REGS_GS(r) ((r)[HOST_GS])
67
68#define REGS_ORIG_RAX(r) ((r)[HOST_ORIG_RAX])
69
70#define REGS_SET_SYSCALL_RETURN(r, res) REGS_RAX(r) = (res)
71
Al Viroadcfb982011-08-18 20:03:59 +010072#define IP_RESTART_SYSCALL(ip) ((ip) -= 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define REGS_FAULT_ADDR(r) ((r)->fault_addr)
76
77#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)
78
79#define REGS_TRAP(r) ((r)->trap_type)
80
81#define REGS_ERR(r) ((r)->fault_type)
82
Jeff Dike77bf4402007-10-16 01:26:58 -070083struct uml_pt_regs {
Jeff Dike18baddd2007-10-16 01:27:07 -070084 unsigned long gp[MAX_REG_NR];
Ingo van Lilfbfe9c82011-09-14 16:21:23 -070085 unsigned long fp[HOST_FP_SIZE];
Jeff Dike77bf4402007-10-16 01:26:58 -070086 struct faultinfo faultinfo;
87 long syscall;
88 int is_user;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
91#define EMPTY_UML_PT_REGS { }
92
Jeff Dike18baddd2007-10-16 01:27:07 -070093#define UPT_RBX(r) REGS_RBX((r)->gp)
94#define UPT_RCX(r) REGS_RCX((r)->gp)
95#define UPT_RDX(r) REGS_RDX((r)->gp)
96#define UPT_RSI(r) REGS_RSI((r)->gp)
97#define UPT_RDI(r) REGS_RDI((r)->gp)
98#define UPT_RBP(r) REGS_RBP((r)->gp)
99#define UPT_RAX(r) REGS_RAX((r)->gp)
100#define UPT_R8(r) REGS_R8((r)->gp)
101#define UPT_R9(r) REGS_R9((r)->gp)
102#define UPT_R10(r) REGS_R10((r)->gp)
103#define UPT_R11(r) REGS_R11((r)->gp)
104#define UPT_R12(r) REGS_R12((r)->gp)
105#define UPT_R13(r) REGS_R13((r)->gp)
106#define UPT_R14(r) REGS_R14((r)->gp)
107#define UPT_R15(r) REGS_R15((r)->gp)
108#define UPT_CS(r) REGS_CS((r)->gp)
109#define UPT_FS_BASE(r) REGS_FS_BASE((r)->gp)
110#define UPT_FS(r) REGS_FS((r)->gp)
111#define UPT_GS_BASE(r) REGS_GS_BASE((r)->gp)
112#define UPT_GS(r) REGS_GS((r)->gp)
113#define UPT_DS(r) REGS_DS((r)->gp)
114#define UPT_ES(r) REGS_ES((r)->gp)
115#define UPT_CS(r) REGS_CS((r)->gp)
116#define UPT_SS(r) REGS_SS((r)->gp)
117#define UPT_ORIG_RAX(r) REGS_ORIG_RAX((r)->gp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Jeff Dike18baddd2007-10-16 01:27:07 -0700119#define UPT_IP(r) REGS_IP((r)->gp)
120#define UPT_SP(r) REGS_SP((r)->gp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Jeff Dike18baddd2007-10-16 01:27:07 -0700122#define UPT_EFLAGS(r) REGS_EFLAGS((r)->gp)
Jeff Dike77bf4402007-10-16 01:26:58 -0700123#define UPT_SYSCALL_NR(r) ((r)->syscall)
Jeff Dikeba9950c2005-05-20 13:59:07 -0700124#define UPT_SYSCALL_RET(r) UPT_RAX(r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126extern int user_context(unsigned long sp);
127
Jeff Dike77bf4402007-10-16 01:26:58 -0700128#define UPT_IS_USER(r) ((r)->is_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130#define UPT_SYSCALL_ARG1(r) UPT_RDI(r)
131#define UPT_SYSCALL_ARG2(r) UPT_RSI(r)
132#define UPT_SYSCALL_ARG3(r) UPT_RDX(r)
133#define UPT_SYSCALL_ARG4(r) UPT_R10(r)
134#define UPT_SYSCALL_ARG5(r) UPT_R8(r)
135#define UPT_SYSCALL_ARG6(r) UPT_R9(r)
136
137struct syscall_args {
138 unsigned long args[6];
139};
140
141#define SYSCALL_ARGS(r) ((struct syscall_args) \
Jeff Dike8ca842c2007-10-16 01:27:08 -0700142 { .args = { UPT_SYSCALL_ARG1(r), \
143 UPT_SYSCALL_ARG2(r), \
144 UPT_SYSCALL_ARG3(r), \
145 UPT_SYSCALL_ARG4(r), \
146 UPT_SYSCALL_ARG5(r), \
147 UPT_SYSCALL_ARG6(r) } } )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define UPT_SET_SYSCALL_RETURN(r, res) \
Jeff Dike77bf4402007-10-16 01:26:58 -0700150 REGS_SET_SYSCALL_RETURN((r)->regs, (res))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Jeff Dike18baddd2007-10-16 01:27:07 -0700152#define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->gp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Jeff Dike77bf4402007-10-16 01:26:58 -0700154#define UPT_FAULTINFO(r) (&(r)->faultinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Jeff Dikea5f6096c2007-10-16 01:27:15 -0700156static inline void arch_init_registers(int pid)
157{
158}
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif