Initial import
[external/libunwind.git] / src / coredump / _UCD_access_reg_freebsd.c
1 /* libunwind - a platform-independent unwind library
2
3 This file is part of libunwind.
4
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
23
24 #include "_UCD_lib.h"
25
26 #include "_UCD_internal.h"
27
28 int
29 _UCD_access_reg (unw_addr_space_t as,
30                                 unw_regnum_t regnum, unw_word_t *valp,
31                                 int write, void *arg)
32 {
33   if (write)
34     {
35       Debug(0, "write is not supported\n");
36       return -UNW_EINVAL;
37     }
38
39   struct UCD_info *ui = arg;
40
41 #if defined(UNW_TARGET_X86)
42   switch (regnum) {
43   case UNW_X86_EAX:
44      *valp = ui->prstatus->pr_reg.r_eax;
45      break;
46   case UNW_X86_EDX:
47      *valp = ui->prstatus->pr_reg.r_edx;
48      break;
49   case UNW_X86_ECX:
50      *valp = ui->prstatus->pr_reg.r_ecx;
51      break;
52   case UNW_X86_EBX:
53      *valp = ui->prstatus->pr_reg.r_ebx;
54      break;
55   case UNW_X86_ESI:
56      *valp = ui->prstatus->pr_reg.r_esi;
57      break;
58   case UNW_X86_EDI:
59      *valp = ui->prstatus->pr_reg.r_edi;
60      break;
61   case UNW_X86_EBP:
62      *valp = ui->prstatus->pr_reg.r_ebp;
63      break;
64   case UNW_X86_ESP:
65      *valp = ui->prstatus->pr_reg.r_esp;
66      break;
67   case UNW_X86_EIP:
68      *valp = ui->prstatus->pr_reg.r_eip;
69      break;
70   case UNW_X86_EFLAGS:
71      *valp = ui->prstatus->pr_reg.r_eflags;
72      break;
73   case UNW_X86_TRAPNO:
74      *valp = ui->prstatus->pr_reg.r_trapno;
75      break;
76   default:
77       Debug(0, "bad regnum:%d\n", regnum);
78       return -UNW_EINVAL;
79   };
80 #elif defined(UNW_TARGET_X86_64)
81   switch (regnum) {
82   case UNW_X86_64_RAX:
83      *valp = ui->prstatus->pr_reg.r_rax;
84      break;
85   case UNW_X86_64_RDX:
86      *valp = ui->prstatus->pr_reg.r_rdx;
87      break;
88   case UNW_X86_64_RCX:
89      *valp = ui->prstatus->pr_reg.r_rcx;
90      break;
91   case UNW_X86_64_RBX:
92      *valp = ui->prstatus->pr_reg.r_rbx;
93      break;
94   case UNW_X86_64_RSI:
95      *valp = ui->prstatus->pr_reg.r_rsi;
96      break;
97   case UNW_X86_64_RDI:
98      *valp = ui->prstatus->pr_reg.r_rdi;
99      break;
100   case UNW_X86_64_RBP:
101      *valp = ui->prstatus->pr_reg.r_rbp;
102      break;
103   case UNW_X86_64_RSP:
104      *valp = ui->prstatus->pr_reg.r_rsp;
105      break;
106   case UNW_X86_64_RIP:
107      *valp = ui->prstatus->pr_reg.r_rip;
108      break;
109   default:
110       Debug(0, "bad regnum:%d\n", regnum);
111       return -UNW_EINVAL;
112   };
113 #else
114 #error Port me
115 #endif
116
117   return 0;
118 }