Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Sparc register context support |
| 3 | * |
| 4 | * Copyright (C) 2000 Ulrich Weigand |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #ifdef __sparc__ |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <errno.h> |
| 27 | #include <sys/types.h> |
| 28 | #ifdef HAVE_SYS_REG_H |
Patrik Stridvall | 7a4e599 | 2000-12-01 23:53:46 +0000 | [diff] [blame] | 29 | # include <sys/reg.h> |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 30 | #endif |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 31 | #include <stdarg.h> |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 32 | #include <unistd.h> |
Patrik Stridvall | 7a4e599 | 2000-12-01 23:53:46 +0000 | [diff] [blame] | 33 | #ifdef HAVE_SYS_PTRACE_H |
| 34 | # include <sys/ptrace.h> |
| 35 | #endif |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 36 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 37 | #include "windef.h" |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 38 | |
Alexandre Julliard | cf27a7f | 2003-02-14 20:27:09 +0000 | [diff] [blame] | 39 | #include "file.h" |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 40 | #include "thread.h" |
| 41 | #include "request.h" |
| 42 | |
| 43 | |
| 44 | #if defined(__sun) || defined(__sun__) |
| 45 | |
| 46 | /* retrieve a thread context */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 47 | static void get_thread_context_ptrace( struct thread *thread, unsigned int flags, CONTEXT *context ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 48 | { |
Alexandre Julliard | baf0a06 | 2003-03-11 01:48:53 +0000 | [diff] [blame] | 49 | int pid = get_ptrace_pid(thread); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 50 | if (flags & CONTEXT_FULL) |
| 51 | { |
| 52 | struct regs regs; |
| 53 | if (ptrace( PTRACE_GETREGS, pid, 0, (int) ®s ) == -1) goto error; |
| 54 | if (flags & CONTEXT_INTEGER) |
| 55 | { |
| 56 | context->g0 = 0; |
| 57 | context->g1 = regs.r_g1; |
| 58 | context->g2 = regs.r_g2; |
| 59 | context->g3 = regs.r_g3; |
| 60 | context->g4 = regs.r_g4; |
| 61 | context->g5 = regs.r_g5; |
| 62 | context->g6 = regs.r_g6; |
| 63 | context->g7 = regs.r_g7; |
| 64 | |
| 65 | context->o0 = regs.r_o0; |
| 66 | context->o1 = regs.r_o1; |
| 67 | context->o2 = regs.r_o2; |
| 68 | context->o3 = regs.r_o3; |
| 69 | context->o4 = regs.r_o4; |
| 70 | context->o5 = regs.r_o5; |
| 71 | context->o6 = regs.r_o6; |
| 72 | context->o7 = regs.r_o7; |
| 73 | |
| 74 | /* FIXME: local and in registers */ |
| 75 | } |
| 76 | if (flags & CONTEXT_CONTROL) |
| 77 | { |
| 78 | context->psr = regs.r_psr; |
| 79 | context->pc = regs.r_pc; |
| 80 | context->npc = regs.r_npc; |
| 81 | context->y = regs.r_y; |
| 82 | context->wim = 0; /* FIXME */ |
| 83 | context->tbr = 0; /* FIXME */ |
| 84 | } |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 85 | context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 86 | } |
| 87 | if (flags & CONTEXT_FLOATING_POINT) |
| 88 | { |
| 89 | /* FIXME */ |
| 90 | } |
| 91 | return; |
| 92 | error: |
| 93 | file_set_error(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /* set a thread context */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 98 | static void set_thread_context_ptrace( struct thread *thread, unsigned int flags, const CONTEXT *context ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 99 | { |
| 100 | /* FIXME */ |
| 101 | } |
| 102 | |
| 103 | #else /* __sun__ */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 104 | #error You must implement get/set_thread_context_ptrace for your platform |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 105 | #endif /* __sun__ */ |
| 106 | |
| 107 | |
| 108 | /* copy a context structure according to the flags */ |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 109 | static void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 110 | { |
| 111 | if (flags & CONTEXT_CONTROL) |
| 112 | { |
| 113 | to->psr = from->psr; |
| 114 | to->pc = from->pc; |
| 115 | to->npc = from->npc; |
| 116 | to->y = from->y; |
| 117 | to->wim = from->wim; |
| 118 | to->tbr = from->tbr; |
| 119 | } |
| 120 | if (flags & CONTEXT_INTEGER) |
| 121 | { |
| 122 | to->g0 = from->g0; |
| 123 | to->g1 = from->g1; |
| 124 | to->g2 = from->g2; |
| 125 | to->g3 = from->g3; |
| 126 | to->g4 = from->g4; |
| 127 | to->g5 = from->g5; |
| 128 | to->g6 = from->g6; |
| 129 | to->g7 = from->g7; |
| 130 | to->o0 = from->o0; |
| 131 | to->o1 = from->o1; |
| 132 | to->o2 = from->o2; |
| 133 | to->o3 = from->o3; |
| 134 | to->o4 = from->o4; |
| 135 | to->o5 = from->o5; |
| 136 | to->o6 = from->o6; |
| 137 | to->o7 = from->o7; |
| 138 | to->l0 = from->l0; |
| 139 | to->l1 = from->l1; |
| 140 | to->l2 = from->l2; |
| 141 | to->l3 = from->l3; |
| 142 | to->l4 = from->l4; |
| 143 | to->l5 = from->l5; |
| 144 | to->l6 = from->l6; |
| 145 | to->l7 = from->l7; |
| 146 | to->i0 = from->i0; |
| 147 | to->i1 = from->i1; |
| 148 | to->i2 = from->i2; |
| 149 | to->i3 = from->i3; |
| 150 | to->i4 = from->i4; |
| 151 | to->i5 = from->i5; |
| 152 | to->i6 = from->i6; |
| 153 | to->i7 = from->i7; |
| 154 | } |
| 155 | if (flags & CONTEXT_FLOATING_POINT) |
| 156 | { |
| 157 | /* FIXME */ |
| 158 | } |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 159 | context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 162 | /* retrieve the current instruction pointer of a context */ |
| 163 | void *get_context_ip( const CONTEXT *context ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 164 | { |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 165 | return (void *)context->pc; |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 168 | /* retrieve the thread context */ |
| 169 | void get_thread_context( struct thread *thread, CONTEXT *context, unsigned int flags ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 170 | { |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 171 | context->ContextFlags |= CONTEXT_SPARC; |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 172 | flags &= ~CONTEXT_SPARC; /* get rid of CPU id */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 173 | |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 174 | if (thread->context) /* thread is inside an exception event or suspended */ |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 175 | { |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 176 | copy_context( context, thread->context, flags ); |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 177 | } |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 178 | else if (flags && suspend_for_ptrace( thread )) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 179 | { |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 180 | get_thread_context_ptrace( thread, flags, context ); |
| 181 | resume_after_ptrace( thread ); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 185 | /* set the thread context */ |
| 186 | void set_thread_context( struct thread *thread, const CONTEXT *context, unsigned int flags ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 187 | { |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 188 | flags &= ~CONTEXT_SPARC; /* get rid of CPU id */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 189 | |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 190 | if (thread->context) /* thread is inside an exception event or suspended */ |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 191 | { |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 192 | copy_context( thread->context, context, flags ); |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 193 | } |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 194 | else if (flags && suspend_for_ptrace( thread )) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 195 | { |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 196 | set_thread_context_ptrace( thread, flags, context ); |
| 197 | resume_after_ptrace( thread ); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | #endif /* __sparc__ */ |