1 /* Ravenscar x86-64 target support.
3 Copyright (C) 2020-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "amd64-tdep.h"
26 #include "ravenscar-thread.h"
27 #include "amd64-ravenscar-thread.h"
29 struct amd64_ravenscar_ops
: public ravenscar_arch_ops
31 void fetch_registers (struct regcache
*regcache
, int regnum
) override
;
32 void store_registers (struct regcache
*regcache
, int regnum
) override
;
36 /* Return the offset of the register in the context buffer. */
37 int register_offset (struct gdbarch
*arch
, int regnum
);
40 /* x86-64 Ravenscar stores registers as:
42 type Context_Buffer is record
55 static const int register_layout
[] =
69 amd64_ravenscar_ops::register_offset (struct gdbarch
*arch
, int regnum
)
71 for (int i
= 0; i
< ARRAY_SIZE (register_layout
); ++i
)
72 if (register_layout
[i
] == regnum
)
78 /* Supply register REGNUM, which has been saved at REGISTER_ADDR, to
82 supply_register_at_address (struct regcache
*regcache
, int regnum
,
83 CORE_ADDR register_addr
)
85 struct gdbarch
*gdbarch
= regcache
->arch ();
86 int buf_size
= register_size (gdbarch
, regnum
);
89 buf
= (gdb_byte
*) alloca (buf_size
);
90 read_memory (register_addr
, buf
, buf_size
);
91 regcache
->raw_supply (regnum
, buf
);
95 amd64_ravenscar_ops::fetch_registers (struct regcache
*regcache
, int regnum
)
97 struct gdbarch
*gdbarch
= regcache
->arch ();
98 const int num_regs
= gdbarch_num_regs (gdbarch
);
100 CORE_ADDR current_address
;
101 CORE_ADDR thread_descriptor_address
;
103 /* The tid is the thread_id field, which is a pointer to the thread. */
104 thread_descriptor_address
= (CORE_ADDR
) inferior_ptid
.tid ();
106 /* Read registers. */
107 for (current_regnum
= 0; current_regnum
< num_regs
; current_regnum
++)
109 int offset
= register_offset (gdbarch
, current_regnum
);
113 current_address
= thread_descriptor_address
+ offset
;
114 supply_register_at_address (regcache
, current_regnum
,
121 amd64_ravenscar_ops::store_registers (struct regcache
*regcache
, int regnum
)
123 struct gdbarch
*gdbarch
= regcache
->arch ();
124 int buf_size
= register_size (gdbarch
, regnum
);
125 gdb_byte buf
[buf_size
];
126 CORE_ADDR register_address
;
128 int offset
= register_offset (gdbarch
, regnum
);
131 register_address
= inferior_ptid
.tid () + offset
;
133 regcache
->raw_collect (regnum
, buf
);
134 write_memory (register_address
,
140 /* The ravenscar_arch_ops vector for AMD64 targets. */
142 static struct amd64_ravenscar_ops amd64_ravenscar_ops
;
144 /* Register amd64_ravenscar_ops in GDBARCH. */
147 register_amd64_ravenscar_ops (struct gdbarch
*gdbarch
)
149 set_gdbarch_ravenscar_ops (gdbarch
, &amd64_ravenscar_ops
);