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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 | |
Alexandre Julliard | 498742f | 2006-06-27 21:27:47 +0200 | [diff] [blame] | 43 | #if 0 /* no longer used */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 44 | |
| 45 | #if defined(__sun) || defined(__sun__) |
| 46 | |
| 47 | /* retrieve a thread context */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 48 | 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] | 49 | { |
Alexandre Julliard | baf0a06 | 2003-03-11 01:48:53 +0000 | [diff] [blame] | 50 | int pid = get_ptrace_pid(thread); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 51 | if (flags & CONTEXT_FULL) |
| 52 | { |
| 53 | struct regs regs; |
| 54 | if (ptrace( PTRACE_GETREGS, pid, 0, (int) ®s ) == -1) goto error; |
| 55 | if (flags & CONTEXT_INTEGER) |
| 56 | { |
| 57 | context->g0 = 0; |
| 58 | context->g1 = regs.r_g1; |
| 59 | context->g2 = regs.r_g2; |
| 60 | context->g3 = regs.r_g3; |
| 61 | context->g4 = regs.r_g4; |
| 62 | context->g5 = regs.r_g5; |
| 63 | context->g6 = regs.r_g6; |
| 64 | context->g7 = regs.r_g7; |
| 65 | |
| 66 | context->o0 = regs.r_o0; |
| 67 | context->o1 = regs.r_o1; |
| 68 | context->o2 = regs.r_o2; |
| 69 | context->o3 = regs.r_o3; |
| 70 | context->o4 = regs.r_o4; |
| 71 | context->o5 = regs.r_o5; |
| 72 | context->o6 = regs.r_o6; |
| 73 | context->o7 = regs.r_o7; |
| 74 | |
| 75 | /* FIXME: local and in registers */ |
| 76 | } |
| 77 | if (flags & CONTEXT_CONTROL) |
| 78 | { |
| 79 | context->psr = regs.r_psr; |
| 80 | context->pc = regs.r_pc; |
| 81 | context->npc = regs.r_npc; |
| 82 | context->y = regs.r_y; |
| 83 | context->wim = 0; /* FIXME */ |
| 84 | context->tbr = 0; /* FIXME */ |
| 85 | } |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 86 | context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 87 | } |
| 88 | if (flags & CONTEXT_FLOATING_POINT) |
| 89 | { |
| 90 | /* FIXME */ |
| 91 | } |
| 92 | return; |
| 93 | error: |
| 94 | file_set_error(); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /* set a thread context */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 99 | 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] | 100 | { |
| 101 | /* FIXME */ |
| 102 | } |
| 103 | |
| 104 | #else /* __sun__ */ |
Alexandre Julliard | 3f85e26 | 2005-11-02 14:12:13 +0000 | [diff] [blame] | 105 | #error You must implement get/set_thread_context_ptrace for your platform |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 106 | #endif /* __sun__ */ |
| 107 | |
Alexandre Julliard | 498742f | 2006-06-27 21:27:47 +0200 | [diff] [blame] | 108 | #endif /* 0 */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 109 | |
| 110 | /* copy a context structure according to the flags */ |
Alexandre Julliard | 86d4688 | 2006-06-23 13:16:14 +0200 | [diff] [blame] | 111 | void copy_context( CONTEXT *to, const CONTEXT *from, unsigned int flags ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 112 | { |
Alexandre Julliard | 86d4688 | 2006-06-23 13:16:14 +0200 | [diff] [blame] | 113 | flags &= ~CONTEXT_SPARC; /* get rid of CPU id */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 114 | if (flags & CONTEXT_CONTROL) |
| 115 | { |
| 116 | to->psr = from->psr; |
| 117 | to->pc = from->pc; |
| 118 | to->npc = from->npc; |
| 119 | to->y = from->y; |
| 120 | to->wim = from->wim; |
| 121 | to->tbr = from->tbr; |
| 122 | } |
| 123 | if (flags & CONTEXT_INTEGER) |
| 124 | { |
| 125 | to->g0 = from->g0; |
| 126 | to->g1 = from->g1; |
| 127 | to->g2 = from->g2; |
| 128 | to->g3 = from->g3; |
| 129 | to->g4 = from->g4; |
| 130 | to->g5 = from->g5; |
| 131 | to->g6 = from->g6; |
| 132 | to->g7 = from->g7; |
| 133 | to->o0 = from->o0; |
| 134 | to->o1 = from->o1; |
| 135 | to->o2 = from->o2; |
| 136 | to->o3 = from->o3; |
| 137 | to->o4 = from->o4; |
| 138 | to->o5 = from->o5; |
| 139 | to->o6 = from->o6; |
| 140 | to->o7 = from->o7; |
| 141 | to->l0 = from->l0; |
| 142 | to->l1 = from->l1; |
| 143 | to->l2 = from->l2; |
| 144 | to->l3 = from->l3; |
| 145 | to->l4 = from->l4; |
| 146 | to->l5 = from->l5; |
| 147 | to->l6 = from->l6; |
| 148 | to->l7 = from->l7; |
| 149 | to->i0 = from->i0; |
| 150 | to->i1 = from->i1; |
| 151 | to->i2 = from->i2; |
| 152 | to->i3 = from->i3; |
| 153 | to->i4 = from->i4; |
| 154 | to->i5 = from->i5; |
| 155 | to->i6 = from->i6; |
| 156 | to->i7 = from->i7; |
| 157 | } |
| 158 | if (flags & CONTEXT_FLOATING_POINT) |
| 159 | { |
| 160 | /* FIXME */ |
| 161 | } |
Alexandre Julliard | bd298b5 | 2005-12-21 20:06:42 +0100 | [diff] [blame] | 162 | context |= flags & (CONTEXT_CONTROL|CONTEXT_INTEGER); |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 165 | /* retrieve the current instruction pointer of a context */ |
| 166 | void *get_context_ip( const CONTEXT *context ) |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 167 | { |
Alexandre Julliard | 17de829 | 2006-04-19 19:45:39 +0200 | [diff] [blame] | 168 | return (void *)context->pc; |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Alexandre Julliard | 86d4688 | 2006-06-23 13:16:14 +0200 | [diff] [blame] | 171 | /* return the context flag that contains the CPU id */ |
| 172 | unsigned int get_context_cpu_flag(void) |
| 173 | { |
| 174 | return CONTEXT_SPARC; |
| 175 | } |
| 176 | |
| 177 | /* return only the context flags that correspond to system regs */ |
| 178 | /* (system regs are the ones we can't access on the client side) */ |
| 179 | unsigned int get_context_system_regs( unsigned int flags ) |
| 180 | { |
Alexandre Julliard | 498742f | 2006-06-27 21:27:47 +0200 | [diff] [blame] | 181 | return 0; /* FIXME: implement client-side handling */ |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | #endif /* __sparc__ */ |