Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
| 6 | #ifndef __SYSDEP_I386_PTRACE_H |
| 7 | #define __SYSDEP_I386_PTRACE_H |
| 8 | |
| 9 | #include "uml-config.h" |
| 10 | #include "user_constants.h" |
Jeff Dike | 36ca119 | 2005-06-13 15:52:10 -0700 | [diff] [blame] | 11 | #include "sysdep/faultinfo.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #define MAX_REG_NR (UM_FRAME_SIZE / sizeof(unsigned long)) |
| 14 | #define MAX_REG_OFFSET (UM_FRAME_SIZE) |
| 15 | |
Paolo 'Blaisorblade' Giarrusso | 972410b | 2006-03-31 02:30:21 -0800 | [diff] [blame] | 16 | static inline void update_debugregs(int seq) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /* syscall emulation path in ptrace */ |
| 19 | |
| 20 | #ifndef PTRACE_SYSEMU |
| 21 | #define PTRACE_SYSEMU 31 |
| 22 | #endif |
| 23 | |
| 24 | void set_using_sysemu(int value); |
| 25 | int get_using_sysemu(void); |
| 26 | extern int sysemu_supported; |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "skas_ptregs.h" |
| 29 | |
| 30 | #define REGS_IP(r) ((r)[HOST_IP]) |
| 31 | #define REGS_SP(r) ((r)[HOST_SP]) |
| 32 | #define REGS_EFLAGS(r) ((r)[HOST_EFLAGS]) |
| 33 | #define REGS_EAX(r) ((r)[HOST_EAX]) |
| 34 | #define REGS_EBX(r) ((r)[HOST_EBX]) |
| 35 | #define REGS_ECX(r) ((r)[HOST_ECX]) |
| 36 | #define REGS_EDX(r) ((r)[HOST_EDX]) |
| 37 | #define REGS_ESI(r) ((r)[HOST_ESI]) |
| 38 | #define REGS_EDI(r) ((r)[HOST_EDI]) |
| 39 | #define REGS_EBP(r) ((r)[HOST_EBP]) |
| 40 | #define REGS_CS(r) ((r)[HOST_CS]) |
| 41 | #define REGS_SS(r) ((r)[HOST_SS]) |
| 42 | #define REGS_DS(r) ((r)[HOST_DS]) |
| 43 | #define REGS_ES(r) ((r)[HOST_ES]) |
| 44 | #define REGS_FS(r) ((r)[HOST_FS]) |
| 45 | #define REGS_GS(r) ((r)[HOST_GS]) |
| 46 | |
| 47 | #define REGS_SET_SYSCALL_RETURN(r, res) REGS_EAX(r) = (res) |
| 48 | |
| 49 | #define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r)) |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #ifndef PTRACE_SYSEMU_SINGLESTEP |
| 52 | #define PTRACE_SYSEMU_SINGLESTEP 32 |
| 53 | #endif |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | union uml_pt_regs { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | struct skas_regs { |
Jeff Dike | e46962f | 2006-12-06 20:34:54 -0800 | [diff] [blame] | 57 | unsigned long regs[MAX_REG_NR]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | unsigned long fp[HOST_FP_SIZE]; |
| 59 | unsigned long xfp[HOST_XFP_SIZE]; |
Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 60 | struct faultinfo faultinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | long syscall; |
| 62 | int is_user; |
| 63 | } skas; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | #define EMPTY_UML_PT_REGS { } |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #define UPT_SC(r) ((r)->tt.sc) |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 69 | #define UPT_IP(r) REGS_IP((r)->skas.regs) |
| 70 | #define UPT_SP(r) REGS_SP((r)->skas.regs) |
| 71 | #define UPT_EFLAGS(r) REGS_EFLAGS((r)->skas.regs) |
| 72 | #define UPT_EAX(r) REGS_EAX((r)->skas.regs) |
| 73 | #define UPT_EBX(r) REGS_EBX((r)->skas.regs) |
| 74 | #define UPT_ECX(r) REGS_ECX((r)->skas.regs) |
| 75 | #define UPT_EDX(r) REGS_EDX((r)->skas.regs) |
| 76 | #define UPT_ESI(r) REGS_ESI((r)->skas.regs) |
| 77 | #define UPT_EDI(r) REGS_EDI((r)->skas.regs) |
| 78 | #define UPT_EBP(r) REGS_EBP((r)->skas.regs) |
| 79 | #define UPT_ORIG_EAX(r) ((r)->skas.syscall) |
| 80 | #define UPT_CS(r) REGS_CS((r)->skas.regs) |
| 81 | #define UPT_SS(r) REGS_SS((r)->skas.regs) |
| 82 | #define UPT_DS(r) REGS_DS((r)->skas.regs) |
| 83 | #define UPT_ES(r) REGS_ES((r)->skas.regs) |
| 84 | #define UPT_FS(r) REGS_FS((r)->skas.regs) |
| 85 | #define UPT_GS(r) REGS_GS((r)->skas.regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | #define UPT_SYSCALL_ARG1(r) UPT_EBX(r) |
| 88 | #define UPT_SYSCALL_ARG2(r) UPT_ECX(r) |
| 89 | #define UPT_SYSCALL_ARG3(r) UPT_EDX(r) |
| 90 | #define UPT_SYSCALL_ARG4(r) UPT_ESI(r) |
| 91 | #define UPT_SYSCALL_ARG5(r) UPT_EDI(r) |
| 92 | #define UPT_SYSCALL_ARG6(r) UPT_EBP(r) |
| 93 | |
| 94 | extern int user_context(unsigned long sp); |
| 95 | |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 96 | #define UPT_IS_USER(r) ((r)->skas.is_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | struct syscall_args { |
| 99 | unsigned long args[6]; |
| 100 | }; |
| 101 | |
| 102 | #define SYSCALL_ARGS(r) ((struct syscall_args) \ |
| 103 | { .args = { UPT_SYSCALL_ARG1(r), \ |
| 104 | UPT_SYSCALL_ARG2(r), \ |
| 105 | UPT_SYSCALL_ARG3(r), \ |
| 106 | UPT_SYSCALL_ARG4(r), \ |
| 107 | UPT_SYSCALL_ARG5(r), \ |
| 108 | UPT_SYSCALL_ARG6(r) } } ) |
| 109 | |
| 110 | #define UPT_REG(regs, reg) \ |
| 111 | ({ unsigned long val; \ |
| 112 | switch(reg){ \ |
| 113 | case EIP: val = UPT_IP(regs); break; \ |
| 114 | case UESP: val = UPT_SP(regs); break; \ |
| 115 | case EAX: val = UPT_EAX(regs); break; \ |
| 116 | case EBX: val = UPT_EBX(regs); break; \ |
| 117 | case ECX: val = UPT_ECX(regs); break; \ |
| 118 | case EDX: val = UPT_EDX(regs); break; \ |
| 119 | case ESI: val = UPT_ESI(regs); break; \ |
| 120 | case EDI: val = UPT_EDI(regs); break; \ |
| 121 | case EBP: val = UPT_EBP(regs); break; \ |
| 122 | case ORIG_EAX: val = UPT_ORIG_EAX(regs); break; \ |
| 123 | case CS: val = UPT_CS(regs); break; \ |
| 124 | case SS: val = UPT_SS(regs); break; \ |
| 125 | case DS: val = UPT_DS(regs); break; \ |
| 126 | case ES: val = UPT_ES(regs); break; \ |
| 127 | case FS: val = UPT_FS(regs); break; \ |
| 128 | case GS: val = UPT_GS(regs); break; \ |
| 129 | case EFL: val = UPT_EFLAGS(regs); break; \ |
| 130 | default : \ |
| 131 | panic("Bad register in UPT_REG : %d\n", reg); \ |
| 132 | val = -1; \ |
| 133 | } \ |
| 134 | val; \ |
| 135 | }) |
| 136 | |
| 137 | |
| 138 | #define UPT_SET(regs, reg, val) \ |
| 139 | do { \ |
| 140 | switch(reg){ \ |
| 141 | case EIP: UPT_IP(regs) = val; break; \ |
| 142 | case UESP: UPT_SP(regs) = val; break; \ |
| 143 | case EAX: UPT_EAX(regs) = val; break; \ |
| 144 | case EBX: UPT_EBX(regs) = val; break; \ |
| 145 | case ECX: UPT_ECX(regs) = val; break; \ |
| 146 | case EDX: UPT_EDX(regs) = val; break; \ |
| 147 | case ESI: UPT_ESI(regs) = val; break; \ |
| 148 | case EDI: UPT_EDI(regs) = val; break; \ |
| 149 | case EBP: UPT_EBP(regs) = val; break; \ |
| 150 | case ORIG_EAX: UPT_ORIG_EAX(regs) = val; break; \ |
| 151 | case CS: UPT_CS(regs) = val; break; \ |
| 152 | case SS: UPT_SS(regs) = val; break; \ |
| 153 | case DS: UPT_DS(regs) = val; break; \ |
| 154 | case ES: UPT_ES(regs) = val; break; \ |
| 155 | case FS: UPT_FS(regs) = val; break; \ |
| 156 | case GS: UPT_GS(regs) = val; break; \ |
| 157 | case EFL: UPT_EFLAGS(regs) = val; break; \ |
| 158 | default : \ |
| 159 | panic("Bad register in UPT_SET : %d\n", reg); \ |
| 160 | break; \ |
| 161 | } \ |
| 162 | } while (0) |
| 163 | |
| 164 | #define UPT_SET_SYSCALL_RETURN(r, res) \ |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 165 | REGS_SET_SYSCALL_RETURN((r)->skas.regs, (res)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 167 | #define UPT_RESTART_SYSCALL(r) REGS_RESTART_SYSCALL((r)->skas.regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | #define UPT_ORIG_SYSCALL(r) UPT_EAX(r) |
| 170 | #define UPT_SYSCALL_NR(r) UPT_ORIG_EAX(r) |
| 171 | #define UPT_SYSCALL_RET(r) UPT_EAX(r) |
| 172 | |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame^] | 173 | #define UPT_FAULTINFO(r) (&(r)->skas.faultinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | #endif |