x86: Move x86-specific linker options to elf_linker_x86_params
[deliverable/binutils-gdb.git] / gdb / amd64-obsd-nat.c
CommitLineData
e2879ccb
MK
1/* Native-dependent code for OpenBSD/amd64.
2
42a4f53d 3 Copyright (C) 2003-2019 Free Software Foundation, Inc.
e2879ccb
MK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
e2879ccb
MK
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e2879ccb
MK
19
20#include "defs.h"
21
d55e5aa6 22/* Local non-gdb includes. */
f6ac5f3d 23#include "amd64-bsd-nat.h"
e2879ccb 24#include "amd64-nat.h"
d55e5aa6
TT
25#include "amd64-tdep.h"
26#include "gdbcore.h"
874a80af 27#include "obsd-nat.h"
d55e5aa6
TT
28#include "regcache.h"
29#include "target.h"
e2879ccb
MK
30
31/* Mapping between the general-purpose registers in OpenBSD/amd64
32 `struct reg' format and GDB's register cache layout for
33 OpenBSD/i386.
34
35 Note that most (if not all) OpenBSD/amd64 registers are 64-bit,
36 while the OpenBSD/i386 registers are all 32-bit, but since we're
37 little-endian we get away with that. */
38
39/* From <machine/reg.h>. */
40static int amd64obsd32_r_reg_offset[] =
41{
42 14 * 8, /* %eax */
43 3 * 8, /* %ecx */
44 2 * 8, /* %edx */
45 13 * 8, /* %ebx */
46 15 * 8, /* %esp */
47 12 * 8, /* %ebp */
48 1 * 8, /* %esi */
49 0 * 8, /* %edi */
50 16 * 8, /* %eip */
51 17 * 8, /* %eflags */
52 18 * 8, /* %cs */
53 19 * 8, /* %ss */
54 20 * 8, /* %ds */
55 21 * 8, /* %es */
56 22 * 8, /* %fs */
57 23 * 8 /* %gs */
58};
59\f
60
492cf391
MK
61/* Support for debugging kernel virtual memory images. */
62
63#include <sys/types.h>
64#include <machine/frame.h>
65#include <machine/pcb.h>
66
67#include "bsd-kvm.h"
68
69static int
70amd64obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
71{
72 struct switchframe sf;
73 int regnum;
74
75 /* The following is true for OpenBSD 3.5:
76
77 The pcb contains the stack pointer at the point of the context
78 switch in cpu_switch(). At that point we have a stack frame as
79 described by `struct switchframe', which for OpenBSD 3.5 has the
80 following layout:
81
82 interrupt level
83 %r15
84 %r14
85 %r13
86 %r12
87 %rbp
88 %rbx
89 return address
90
91 Together with %rsp in the pcb, this accounts for all callee-saved
92 registers specified by the psABI. From this information we
93 reconstruct the register state as it would look when we just
94 returned from cpu_switch().
95
96 For core dumps the pcb is saved by savectx(). In that case the
97 stack frame only contains the return address, and there is no way
98 to recover the other registers. */
99
100 /* The stack pointer shouldn't be zero. */
101 if (pcb->pcb_rsp == 0)
102 return 0;
103
104 /* Read the stack frame, and check its validity. */
d7a30af7 105 read_memory (pcb->pcb_rsp, (gdb_byte *) &sf, sizeof sf);
492cf391
MK
106 if (sf.sf_rbp == pcb->pcb_rbp)
107 {
108 /* Yes, we have a frame that matches cpu_switch(). */
109 pcb->pcb_rsp += sizeof (struct switchframe);
73e1c03f
SM
110 regcache->raw_supply (12, &sf.sf_r12);
111 regcache->raw_supply (13, &sf.sf_r13);
112 regcache->raw_supply (14, &sf.sf_r14);
113 regcache->raw_supply (15, &sf.sf_r15);
114 regcache->raw_supply (AMD64_RBX_REGNUM, &sf.sf_rbx);
115 regcache->raw_supply (AMD64_RIP_REGNUM, &sf.sf_rip);
492cf391
MK
116 }
117 else
118 {
119 /* No, the pcb must have been last updated by savectx(). */
120 pcb->pcb_rsp += 8;
73e1c03f 121 regcache->raw_supply (AMD64_RIP_REGNUM, &sf);
492cf391
MK
122 }
123
73e1c03f
SM
124 regcache->raw_supply (AMD64_RSP_REGNUM, &pcb->pcb_rsp);
125 regcache->raw_supply (AMD64_RBP_REGNUM, &pcb->pcb_rbp);
492cf391
MK
126
127 return 1;
128}
e2879ccb 129
f6ac5f3d
PA
130static amd64_bsd_nat_target<obsd_nat_target> the_amd64_obsd_nat_target;
131
e2879ccb
MK
132void
133_initialize_amd64obsd_nat (void)
134{
135 amd64_native_gregset32_reg_offset = amd64obsd32_r_reg_offset;
136 amd64_native_gregset32_num_regs = ARRAY_SIZE (amd64obsd32_r_reg_offset);
137 amd64_native_gregset64_reg_offset = amd64obsd_r_reg_offset;
492cf391 138
d9f719f1 139 add_inf_child_target (&the_amd64_obsd_nat_target);
6a5c78a3 140
492cf391
MK
141 /* Support debugging kernel virtual memory images. */
142 bsd_kvm_add_target (amd64obsd_supply_pcb);
e2879ccb 143}
This page took 1.62509 seconds and 4 git commands to generate.