summaryrefslogtreecommitdiff
path: root/src/third_party/unwind/dist/src/coredump/_UCD_access_reg_freebsd.c
blob: 930a1148e4f4424c94068308602f3718ac073698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* libunwind - a platform-independent unwind library

This file is part of libunwind.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */

#include "_UCD_lib.h"

#include "_UCD_internal.h"

int
_UCD_access_reg (unw_addr_space_t as,
                                unw_regnum_t regnum, unw_word_t *valp,
                                int write, void *arg)
{
  if (write)
    {
      Debug(0, "write is not supported\n");
      return -UNW_EINVAL;
    }

  struct UCD_info *ui = arg;

#if defined(UNW_TARGET_X86)
  switch (regnum) {
  case UNW_X86_EAX:
     *valp = ui->prstatus->pr_reg.r_eax;
     break;
  case UNW_X86_EDX:
     *valp = ui->prstatus->pr_reg.r_edx;
     break;
  case UNW_X86_ECX:
     *valp = ui->prstatus->pr_reg.r_ecx;
     break;
  case UNW_X86_EBX:
     *valp = ui->prstatus->pr_reg.r_ebx;
     break;
  case UNW_X86_ESI:
     *valp = ui->prstatus->pr_reg.r_esi;
     break;
  case UNW_X86_EDI:
     *valp = ui->prstatus->pr_reg.r_edi;
     break;
  case UNW_X86_EBP:
     *valp = ui->prstatus->pr_reg.r_ebp;
     break;
  case UNW_X86_ESP:
     *valp = ui->prstatus->pr_reg.r_esp;
     break;
  case UNW_X86_EIP:
     *valp = ui->prstatus->pr_reg.r_eip;
     break;
  case UNW_X86_EFLAGS:
     *valp = ui->prstatus->pr_reg.r_eflags;
     break;
  case UNW_X86_TRAPNO:
     *valp = ui->prstatus->pr_reg.r_trapno;
     break;
  default:
      Debug(0, "bad regnum:%d\n", regnum);
      return -UNW_EINVAL;
  }
#elif defined(UNW_TARGET_X86_64)
  switch (regnum) {
  case UNW_X86_64_RAX:
     *valp = ui->prstatus->pr_reg.r_rax;
     break;
  case UNW_X86_64_RDX:
     *valp = ui->prstatus->pr_reg.r_rdx;
     break;
  case UNW_X86_64_RCX:
     *valp = ui->prstatus->pr_reg.r_rcx;
     break;
  case UNW_X86_64_RBX:
     *valp = ui->prstatus->pr_reg.r_rbx;
     break;
  case UNW_X86_64_RSI:
     *valp = ui->prstatus->pr_reg.r_rsi;
     break;
  case UNW_X86_64_RDI:
     *valp = ui->prstatus->pr_reg.r_rdi;
     break;
  case UNW_X86_64_RBP:
     *valp = ui->prstatus->pr_reg.r_rbp;
     break;
  case UNW_X86_64_RSP:
     *valp = ui->prstatus->pr_reg.r_rsp;
     break;
  case UNW_X86_64_RIP:
     *valp = ui->prstatus->pr_reg.r_rip;
     break;
  default:
      Debug(0, "bad regnum:%d\n", regnum);
      return -UNW_EINVAL;
  }
#elif defined(UNW_TARGET_ARM)
  if (regnum >= UNW_ARM_R0 && regnum <= UNW_ARM_R12) {
     *valp = ui->prstatus->pr_reg.r[regnum];
  } else {
     switch (regnum) {
     case UNW_ARM_R13:
       *valp = ui->prstatus->pr_reg.r_sp;
       break;
     case UNW_ARM_R14:
       *valp = ui->prstatus->pr_reg.r_lr;
       break;
     case UNW_ARM_R15:
       *valp = ui->prstatus->pr_reg.r_pc;
       break;
     default:
       Debug(0, "bad regnum:%d\n", regnum);
       return -UNW_EINVAL;
     }
  }
#elif defined(UNW_TARGET_AARCH64)
  if (regnum >= UNW_AARCH64_X0 && regnum < UNW_AARCH64_X30) {
     *valp = ui->prstatus->pr_reg.x[regnum];
  } else {
     switch (regnum) {
     case UNW_AARCH64_SP:
       *valp = ui->prstatus->pr_reg.sp;
       break;
     case UNW_AARCH64_X30:
       *valp = ui->prstatus->pr_reg.lr;
       break;
     case UNW_AARCH64_PC:
       *valp = ui->prstatus->pr_reg.elr;
       break;
     default:
       Debug(0, "bad regnum:%d\n", regnum);
       return -UNW_EINVAL;
     }
  }

#else
#error Port me
#endif

  return 0;
}