Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2003 PathScale, Inc. |
Jeff Dike | 42fda66 | 2007-10-16 01:26:50 -0700 | [diff] [blame] | 3 | * Copyright (C) 2003 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the GPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef __SYSDEP_X86_64_PTRACE_H |
| 9 | #define __SYSDEP_X86_64_PTRACE_H |
| 10 | |
Al Viro | 4de1c5f | 2011-08-18 20:01:19 +0100 | [diff] [blame] | 11 | #include <generated/user_constants.h> |
Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 12 | #include "sysdep/faultinfo.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #define MAX_REG_OFFSET (UM_FRAME_SIZE) |
| 15 | #define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long)) |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #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 Dike | a8b4fc4 | 2006-09-27 01:50:35 -0700 | [diff] [blame] | 46 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #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 Viro | adcfb98 | 2011-08-18 20:03:59 +0100 | [diff] [blame^] | 72 | #define IP_RESTART_SYSCALL(ip) ((ip) -= 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r)) |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #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 Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 83 | struct uml_pt_regs { |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 84 | unsigned long gp[MAX_REG_NR]; |
Ingo van Lil | fbfe9c8 | 2011-09-14 16:21:23 -0700 | [diff] [blame] | 85 | unsigned long fp[HOST_FP_SIZE]; |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 86 | struct faultinfo faultinfo; |
| 87 | long syscall; |
| 88 | int is_user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #define EMPTY_UML_PT_REGS { } |
| 92 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 93 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 119 | #define UPT_IP(r) REGS_IP((r)->gp) |
| 120 | #define UPT_SP(r) REGS_SP((r)->gp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 122 | #define UPT_EFLAGS(r) REGS_EFLAGS((r)->gp) |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 123 | #define UPT_SYSCALL_NR(r) ((r)->syscall) |
Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 124 | #define UPT_SYSCALL_RET(r) UPT_RAX(r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | extern int user_context(unsigned long sp); |
| 127 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 128 | #define UPT_IS_USER(r) ((r)->is_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 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 | |
| 137 | struct syscall_args { |
| 138 | unsigned long args[6]; |
| 139 | }; |
| 140 | |
| 141 | #define SYSCALL_ARGS(r) ((struct syscall_args) \ |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 142 | { .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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #define UPT_SET_SYSCALL_RETURN(r, res) \ |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 150 | REGS_SET_SYSCALL_RETURN((r)->regs, (res)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 152 | #define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->gp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 154 | #define UPT_FAULTINFO(r) (&(r)->faultinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Jeff Dike | a5f6096c | 2007-10-16 01:27:15 -0700 | [diff] [blame] | 156 | static inline void arch_init_registers(int pid) |
| 157 | { |
| 158 | } |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | #endif |