Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 1 | #ifndef __SPARC_PTRACE_H |
| 2 | #define __SPARC_PTRACE_H |
| 3 | |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 4 | #if defined(__sparc__) && defined(__arch64__) |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 5 | /* 64 bit sparc */ |
| 6 | #include <asm/pstate.h> |
| 7 | |
| 8 | /* This struct defines the way the registers are stored on the |
| 9 | * stack during a system call and basically all traps. |
| 10 | */ |
| 11 | |
| 12 | /* This magic value must have the low 9 bits clear, |
| 13 | * as that is where we encode the %tt value, see below. |
| 14 | */ |
| 15 | #define PT_REGS_MAGIC 0x57ac6c00 |
| 16 | |
| 17 | #ifndef __ASSEMBLY__ |
| 18 | |
| 19 | #include <linux/types.h> |
| 20 | |
| 21 | struct pt_regs { |
| 22 | unsigned long u_regs[16]; /* globals and ins */ |
| 23 | unsigned long tstate; |
| 24 | unsigned long tpc; |
| 25 | unsigned long tnpc; |
| 26 | unsigned int y; |
| 27 | |
| 28 | /* We encode a magic number, PT_REGS_MAGIC, along |
| 29 | * with the %tt (trap type) register value at trap |
| 30 | * entry time. The magic number allows us to identify |
| 31 | * accurately a trap stack frame in the stack |
| 32 | * unwinder, and the %tt value allows us to test |
| 33 | * things like "in a system call" etc. for an arbitray |
| 34 | * process. |
| 35 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 36 | * The PT_REGS_MAGIC is chosen such that it can be |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 37 | * loaded completely using just a sethi instruction. |
| 38 | */ |
| 39 | unsigned int magic; |
| 40 | }; |
| 41 | |
| 42 | struct pt_regs32 { |
| 43 | unsigned int psr; |
| 44 | unsigned int pc; |
| 45 | unsigned int npc; |
| 46 | unsigned int y; |
| 47 | unsigned int u_regs[16]; /* globals and ins */ |
| 48 | }; |
| 49 | |
| 50 | /* A V9 register window */ |
| 51 | struct reg_window { |
| 52 | unsigned long locals[8]; |
| 53 | unsigned long ins[8]; |
| 54 | }; |
| 55 | |
| 56 | /* A 32-bit register window. */ |
| 57 | struct reg_window32 { |
| 58 | unsigned int locals[8]; |
| 59 | unsigned int ins[8]; |
| 60 | }; |
| 61 | |
| 62 | /* A V9 Sparc stack frame */ |
| 63 | struct sparc_stackf { |
| 64 | unsigned long locals[8]; |
| 65 | unsigned long ins[6]; |
| 66 | struct sparc_stackf *fp; |
| 67 | unsigned long callers_pc; |
| 68 | char *structptr; |
| 69 | unsigned long xargs[6]; |
| 70 | unsigned long xxargs[1]; |
| 71 | }; |
| 72 | |
| 73 | /* A 32-bit Sparc stack frame */ |
| 74 | struct sparc_stackf32 { |
| 75 | unsigned int locals[8]; |
| 76 | unsigned int ins[6]; |
| 77 | unsigned int fp; |
| 78 | unsigned int callers_pc; |
| 79 | unsigned int structptr; |
| 80 | unsigned int xargs[6]; |
| 81 | unsigned int xxargs[1]; |
| 82 | }; |
| 83 | |
| 84 | struct sparc_trapf { |
| 85 | unsigned long locals[8]; |
| 86 | unsigned long ins[8]; |
| 87 | unsigned long _unused; |
| 88 | struct pt_regs *regs; |
| 89 | }; |
| 90 | #endif /* (!__ASSEMBLY__) */ |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 91 | #else |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 92 | /* 32 bit sparc */ |
| 93 | |
| 94 | #include <asm/psr.h> |
| 95 | |
| 96 | /* This struct defines the way the registers are stored on the |
| 97 | * stack during a system call and basically all traps. |
| 98 | */ |
| 99 | #ifndef __ASSEMBLY__ |
| 100 | |
| 101 | struct pt_regs { |
| 102 | unsigned long psr; |
| 103 | unsigned long pc; |
| 104 | unsigned long npc; |
| 105 | unsigned long y; |
| 106 | unsigned long u_regs[16]; /* globals and ins */ |
| 107 | }; |
| 108 | |
| 109 | /* A 32-bit register window. */ |
| 110 | struct reg_window32 { |
| 111 | unsigned long locals[8]; |
| 112 | unsigned long ins[8]; |
| 113 | }; |
| 114 | |
| 115 | /* A Sparc stack frame */ |
| 116 | struct sparc_stackf { |
| 117 | unsigned long locals[8]; |
| 118 | unsigned long ins[6]; |
| 119 | struct sparc_stackf *fp; |
| 120 | unsigned long callers_pc; |
| 121 | char *structptr; |
| 122 | unsigned long xargs[6]; |
| 123 | unsigned long xxargs[1]; |
| 124 | }; |
| 125 | #endif /* (!__ASSEMBLY__) */ |
| 126 | |
| 127 | #endif /* (defined(__sparc__) && defined(__arch64__))*/ |
| 128 | |
| 129 | #ifndef __ASSEMBLY__ |
| 130 | |
| 131 | #define TRACEREG_SZ sizeof(struct pt_regs) |
| 132 | #define STACKFRAME_SZ sizeof(struct sparc_stackf) |
| 133 | |
| 134 | #define TRACEREG32_SZ sizeof(struct pt_regs32) |
| 135 | #define STACKFRAME32_SZ sizeof(struct sparc_stackf32) |
| 136 | |
| 137 | #endif /* (!__ASSEMBLY__) */ |
| 138 | |
| 139 | #define UREG_G0 0 |
| 140 | #define UREG_G1 1 |
| 141 | #define UREG_G2 2 |
| 142 | #define UREG_G3 3 |
| 143 | #define UREG_G4 4 |
| 144 | #define UREG_G5 5 |
| 145 | #define UREG_G6 6 |
| 146 | #define UREG_G7 7 |
| 147 | #define UREG_I0 8 |
| 148 | #define UREG_I1 9 |
| 149 | #define UREG_I2 10 |
| 150 | #define UREG_I3 11 |
| 151 | #define UREG_I4 12 |
| 152 | #define UREG_I5 13 |
| 153 | #define UREG_I6 14 |
| 154 | #define UREG_I7 15 |
| 155 | #define UREG_FP UREG_I6 |
| 156 | #define UREG_RETPC UREG_I7 |
| 157 | |
| 158 | #if defined(__sparc__) && defined(__arch64__) |
| 159 | /* 64 bit sparc */ |
| 160 | |
| 161 | #ifndef __ASSEMBLY__ |
| 162 | |
| 163 | #ifdef __KERNEL__ |
| 164 | |
| 165 | #include <linux/threads.h> |
| 166 | #include <asm/system.h> |
| 167 | |
| 168 | static inline int pt_regs_trap_type(struct pt_regs *regs) |
| 169 | { |
| 170 | return regs->magic & 0x1ff; |
| 171 | } |
| 172 | |
| 173 | static inline bool pt_regs_is_syscall(struct pt_regs *regs) |
| 174 | { |
| 175 | return (regs->tstate & TSTATE_SYSCALL); |
| 176 | } |
| 177 | |
| 178 | static inline bool pt_regs_clear_syscall(struct pt_regs *regs) |
| 179 | { |
| 180 | return (regs->tstate &= ~TSTATE_SYSCALL); |
| 181 | } |
| 182 | |
| 183 | #define arch_ptrace_stop_needed(exit_code, info) \ |
| 184 | ({ flush_user_windows(); \ |
| 185 | get_thread_wsaved() != 0; \ |
| 186 | }) |
| 187 | |
| 188 | #define arch_ptrace_stop(exit_code, info) \ |
| 189 | synchronize_user_stack() |
| 190 | |
| 191 | struct global_reg_snapshot { |
| 192 | unsigned long tstate; |
| 193 | unsigned long tpc; |
| 194 | unsigned long tnpc; |
| 195 | unsigned long o7; |
| 196 | unsigned long i7; |
| 197 | unsigned long rpc; |
| 198 | struct thread_info *thread; |
| 199 | unsigned long pad1; |
| 200 | }; |
| 201 | extern struct global_reg_snapshot global_reg_snapshot[NR_CPUS]; |
| 202 | |
| 203 | #define force_successful_syscall_return() \ |
| 204 | do { current_thread_info()->syscall_noerror = 1; \ |
| 205 | } while (0) |
| 206 | #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) |
| 207 | #define instruction_pointer(regs) ((regs)->tpc) |
Jason Wessel | 33d8881 | 2011-07-19 15:43:16 -0500 | [diff] [blame^] | 208 | #define instruction_pointer_set(regs, val) ((regs)->tpc = (val)) |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 209 | #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) |
| 210 | #define regs_return_value(regs) ((regs)->u_regs[UREG_I0]) |
| 211 | #ifdef CONFIG_SMP |
| 212 | extern unsigned long profile_pc(struct pt_regs *); |
| 213 | #else |
| 214 | #define profile_pc(regs) instruction_pointer(regs) |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 215 | #endif |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 216 | extern void show_regs(struct pt_regs *); |
| 217 | #endif /* (__KERNEL__) */ |
| 218 | |
| 219 | #else /* __ASSEMBLY__ */ |
| 220 | /* For assembly code. */ |
| 221 | #define TRACEREG_SZ 0xa0 |
| 222 | #define STACKFRAME_SZ 0xc0 |
| 223 | |
| 224 | #define TRACEREG32_SZ 0x50 |
| 225 | #define STACKFRAME32_SZ 0x60 |
| 226 | #endif /* __ASSEMBLY__ */ |
| 227 | |
| 228 | #else /* (defined(__sparc__) && defined(__arch64__)) */ |
| 229 | |
| 230 | /* 32 bit sparc */ |
| 231 | |
| 232 | #ifndef __ASSEMBLY__ |
| 233 | |
| 234 | #ifdef __KERNEL__ |
| 235 | |
| 236 | #include <asm/system.h> |
| 237 | |
| 238 | static inline bool pt_regs_is_syscall(struct pt_regs *regs) |
| 239 | { |
| 240 | return (regs->psr & PSR_SYSCALL); |
| 241 | } |
| 242 | |
| 243 | static inline bool pt_regs_clear_syscall(struct pt_regs *regs) |
| 244 | { |
| 245 | return (regs->psr &= ~PSR_SYSCALL); |
| 246 | } |
| 247 | |
| 248 | #define arch_ptrace_stop_needed(exit_code, info) \ |
| 249 | ({ flush_user_windows(); \ |
| 250 | current_thread_info()->w_saved != 0; \ |
| 251 | }) |
| 252 | |
| 253 | #define arch_ptrace_stop(exit_code, info) \ |
| 254 | synchronize_user_stack() |
| 255 | |
| 256 | #define user_mode(regs) (!((regs)->psr & PSR_PS)) |
| 257 | #define instruction_pointer(regs) ((regs)->pc) |
| 258 | #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) |
| 259 | unsigned long profile_pc(struct pt_regs *); |
| 260 | extern void show_regs(struct pt_regs *); |
| 261 | #endif /* (__KERNEL__) */ |
| 262 | |
| 263 | #else /* (!__ASSEMBLY__) */ |
| 264 | /* For assembly code. */ |
| 265 | #define TRACEREG_SZ 0x50 |
| 266 | #define STACKFRAME_SZ 0x60 |
| 267 | #endif /* (!__ASSEMBLY__) */ |
| 268 | |
| 269 | #endif /* (defined(__sparc__) && defined(__arch64__)) */ |
| 270 | |
| 271 | #ifdef __KERNEL__ |
| 272 | #define STACK_BIAS 2047 |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 273 | #endif |
Sam Ravnborg | f3ec38d | 2009-01-02 19:42:12 -0800 | [diff] [blame] | 274 | |
| 275 | /* These are for pt_regs. */ |
| 276 | #define PT_V9_G0 0x00 |
| 277 | #define PT_V9_G1 0x08 |
| 278 | #define PT_V9_G2 0x10 |
| 279 | #define PT_V9_G3 0x18 |
| 280 | #define PT_V9_G4 0x20 |
| 281 | #define PT_V9_G5 0x28 |
| 282 | #define PT_V9_G6 0x30 |
| 283 | #define PT_V9_G7 0x38 |
| 284 | #define PT_V9_I0 0x40 |
| 285 | #define PT_V9_I1 0x48 |
| 286 | #define PT_V9_I2 0x50 |
| 287 | #define PT_V9_I3 0x58 |
| 288 | #define PT_V9_I4 0x60 |
| 289 | #define PT_V9_I5 0x68 |
| 290 | #define PT_V9_I6 0x70 |
| 291 | #define PT_V9_FP PT_V9_I6 |
| 292 | #define PT_V9_I7 0x78 |
| 293 | #define PT_V9_TSTATE 0x80 |
| 294 | #define PT_V9_TPC 0x88 |
| 295 | #define PT_V9_TNPC 0x90 |
| 296 | #define PT_V9_Y 0x98 |
| 297 | #define PT_V9_MAGIC 0x9c |
| 298 | #define PT_TSTATE PT_V9_TSTATE |
| 299 | #define PT_TPC PT_V9_TPC |
| 300 | #define PT_TNPC PT_V9_TNPC |
| 301 | |
| 302 | /* These for pt_regs32. */ |
| 303 | #define PT_PSR 0x0 |
| 304 | #define PT_PC 0x4 |
| 305 | #define PT_NPC 0x8 |
| 306 | #define PT_Y 0xc |
| 307 | #define PT_G0 0x10 |
| 308 | #define PT_WIM PT_G0 |
| 309 | #define PT_G1 0x14 |
| 310 | #define PT_G2 0x18 |
| 311 | #define PT_G3 0x1c |
| 312 | #define PT_G4 0x20 |
| 313 | #define PT_G5 0x24 |
| 314 | #define PT_G6 0x28 |
| 315 | #define PT_G7 0x2c |
| 316 | #define PT_I0 0x30 |
| 317 | #define PT_I1 0x34 |
| 318 | #define PT_I2 0x38 |
| 319 | #define PT_I3 0x3c |
| 320 | #define PT_I4 0x40 |
| 321 | #define PT_I5 0x44 |
| 322 | #define PT_I6 0x48 |
| 323 | #define PT_FP PT_I6 |
| 324 | #define PT_I7 0x4c |
| 325 | |
| 326 | /* Reg_window offsets */ |
| 327 | #define RW_V9_L0 0x00 |
| 328 | #define RW_V9_L1 0x08 |
| 329 | #define RW_V9_L2 0x10 |
| 330 | #define RW_V9_L3 0x18 |
| 331 | #define RW_V9_L4 0x20 |
| 332 | #define RW_V9_L5 0x28 |
| 333 | #define RW_V9_L6 0x30 |
| 334 | #define RW_V9_L7 0x38 |
| 335 | #define RW_V9_I0 0x40 |
| 336 | #define RW_V9_I1 0x48 |
| 337 | #define RW_V9_I2 0x50 |
| 338 | #define RW_V9_I3 0x58 |
| 339 | #define RW_V9_I4 0x60 |
| 340 | #define RW_V9_I5 0x68 |
| 341 | #define RW_V9_I6 0x70 |
| 342 | #define RW_V9_I7 0x78 |
| 343 | |
| 344 | #define RW_L0 0x00 |
| 345 | #define RW_L1 0x04 |
| 346 | #define RW_L2 0x08 |
| 347 | #define RW_L3 0x0c |
| 348 | #define RW_L4 0x10 |
| 349 | #define RW_L5 0x14 |
| 350 | #define RW_L6 0x18 |
| 351 | #define RW_L7 0x1c |
| 352 | #define RW_I0 0x20 |
| 353 | #define RW_I1 0x24 |
| 354 | #define RW_I2 0x28 |
| 355 | #define RW_I3 0x2c |
| 356 | #define RW_I4 0x30 |
| 357 | #define RW_I5 0x34 |
| 358 | #define RW_I6 0x38 |
| 359 | #define RW_I7 0x3c |
| 360 | |
| 361 | /* Stack_frame offsets */ |
| 362 | #define SF_V9_L0 0x00 |
| 363 | #define SF_V9_L1 0x08 |
| 364 | #define SF_V9_L2 0x10 |
| 365 | #define SF_V9_L3 0x18 |
| 366 | #define SF_V9_L4 0x20 |
| 367 | #define SF_V9_L5 0x28 |
| 368 | #define SF_V9_L6 0x30 |
| 369 | #define SF_V9_L7 0x38 |
| 370 | #define SF_V9_I0 0x40 |
| 371 | #define SF_V9_I1 0x48 |
| 372 | #define SF_V9_I2 0x50 |
| 373 | #define SF_V9_I3 0x58 |
| 374 | #define SF_V9_I4 0x60 |
| 375 | #define SF_V9_I5 0x68 |
| 376 | #define SF_V9_FP 0x70 |
| 377 | #define SF_V9_PC 0x78 |
| 378 | #define SF_V9_RETP 0x80 |
| 379 | #define SF_V9_XARG0 0x88 |
| 380 | #define SF_V9_XARG1 0x90 |
| 381 | #define SF_V9_XARG2 0x98 |
| 382 | #define SF_V9_XARG3 0xa0 |
| 383 | #define SF_V9_XARG4 0xa8 |
| 384 | #define SF_V9_XARG5 0xb0 |
| 385 | #define SF_V9_XXARG 0xb8 |
| 386 | |
| 387 | #define SF_L0 0x00 |
| 388 | #define SF_L1 0x04 |
| 389 | #define SF_L2 0x08 |
| 390 | #define SF_L3 0x0c |
| 391 | #define SF_L4 0x10 |
| 392 | #define SF_L5 0x14 |
| 393 | #define SF_L6 0x18 |
| 394 | #define SF_L7 0x1c |
| 395 | #define SF_I0 0x20 |
| 396 | #define SF_I1 0x24 |
| 397 | #define SF_I2 0x28 |
| 398 | #define SF_I3 0x2c |
| 399 | #define SF_I4 0x30 |
| 400 | #define SF_I5 0x34 |
| 401 | #define SF_FP 0x38 |
| 402 | #define SF_PC 0x3c |
| 403 | #define SF_RETP 0x40 |
| 404 | #define SF_XARG0 0x44 |
| 405 | #define SF_XARG1 0x48 |
| 406 | #define SF_XARG2 0x4c |
| 407 | #define SF_XARG3 0x50 |
| 408 | #define SF_XARG4 0x54 |
| 409 | #define SF_XARG5 0x58 |
| 410 | #define SF_XXARG 0x5c |
| 411 | |
| 412 | #ifdef __KERNEL__ |
| 413 | |
| 414 | /* global_reg_snapshot offsets */ |
| 415 | #define GR_SNAP_TSTATE 0x00 |
| 416 | #define GR_SNAP_TPC 0x08 |
| 417 | #define GR_SNAP_TNPC 0x10 |
| 418 | #define GR_SNAP_O7 0x18 |
| 419 | #define GR_SNAP_I7 0x20 |
| 420 | #define GR_SNAP_RPC 0x28 |
| 421 | #define GR_SNAP_THREAD 0x30 |
| 422 | #define GR_SNAP_PAD1 0x38 |
| 423 | |
| 424 | #endif /* __KERNEL__ */ |
| 425 | |
| 426 | /* Stuff for the ptrace system call */ |
| 427 | #define PTRACE_SPARC_DETACH 11 |
| 428 | #define PTRACE_GETREGS 12 |
| 429 | #define PTRACE_SETREGS 13 |
| 430 | #define PTRACE_GETFPREGS 14 |
| 431 | #define PTRACE_SETFPREGS 15 |
| 432 | #define PTRACE_READDATA 16 |
| 433 | #define PTRACE_WRITEDATA 17 |
| 434 | #define PTRACE_READTEXT 18 |
| 435 | #define PTRACE_WRITETEXT 19 |
| 436 | #define PTRACE_GETFPAREGS 20 |
| 437 | #define PTRACE_SETFPAREGS 21 |
| 438 | |
| 439 | /* There are for debugging 64-bit processes, either from a 32 or 64 bit |
| 440 | * parent. Thus their complements are for debugging 32-bit processes only. |
| 441 | */ |
| 442 | |
| 443 | #define PTRACE_GETREGS64 22 |
| 444 | #define PTRACE_SETREGS64 23 |
| 445 | /* PTRACE_SYSCALL is 24 */ |
| 446 | #define PTRACE_GETFPREGS64 25 |
| 447 | #define PTRACE_SETFPREGS64 26 |
| 448 | |
| 449 | #endif /* !(__SPARC_PTRACE_H) */ |