1 /* GNU/Linux/MIPS specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995-2021 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "linux-low.h"
22 #include "nat/gdb_ptrace.h"
25 #include "nat/mips-linux-watch.h"
26 #include "gdb_proc_service.h"
28 /* Linux target op definitions for the MIPS architecture. */
30 class mips_target
: public linux_process_target
34 const regs_info
*get_regs_info () override
;
36 const gdb_byte
*sw_breakpoint_from_kind (int kind
, int *size
) override
;
38 bool supports_z_point_type (char z_type
) override
;
42 void low_arch_setup () override
;
44 bool low_cannot_fetch_register (int regno
) override
;
46 bool low_cannot_store_register (int regno
) override
;
48 bool low_fetch_register (regcache
*regcache
, int regno
) override
;
50 bool low_supports_breakpoints () override
;
52 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
54 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
56 bool low_breakpoint_at (CORE_ADDR pc
) override
;
58 int low_insert_point (raw_bkpt_type type
, CORE_ADDR addr
,
59 int size
, raw_breakpoint
*bp
) override
;
61 int low_remove_point (raw_bkpt_type type
, CORE_ADDR addr
,
62 int size
, raw_breakpoint
*bp
) override
;
64 bool low_stopped_by_watchpoint () override
;
66 CORE_ADDR
low_stopped_data_address () override
;
68 void low_collect_ptrace_register (regcache
*regcache
, int regno
,
71 void low_supply_ptrace_register (regcache
*regcache
, int regno
,
72 const char *buf
) override
;
74 arch_process_info
*low_new_process () override
;
76 void low_delete_process (arch_process_info
*info
) override
;
78 void low_new_thread (lwp_info
*) override
;
80 void low_delete_thread (arch_lwp_info
*) override
;
82 void low_new_fork (process_info
*parent
, process_info
*child
) override
;
84 void low_prepare_to_resume (lwp_info
*lwp
) override
;
87 /* The singleton target ops object. */
89 static mips_target the_mips_target
;
91 /* Defined in auto-generated file mips-linux.c. */
92 void init_registers_mips_linux (void);
93 extern const struct target_desc
*tdesc_mips_linux
;
95 /* Defined in auto-generated file mips-dsp-linux.c. */
96 void init_registers_mips_dsp_linux (void);
97 extern const struct target_desc
*tdesc_mips_dsp_linux
;
99 /* Defined in auto-generated file mips64-linux.c. */
100 void init_registers_mips64_linux (void);
101 extern const struct target_desc
*tdesc_mips64_linux
;
103 /* Defined in auto-generated file mips64-dsp-linux.c. */
104 void init_registers_mips64_dsp_linux (void);
105 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
108 #define tdesc_mips_linux tdesc_mips64_linux
109 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
112 #ifndef PTRACE_GET_THREAD_AREA
113 #define PTRACE_GET_THREAD_AREA 25
116 #ifdef HAVE_SYS_REG_H
120 #define mips_num_regs 73
121 #define mips_dsp_num_regs 80
123 #include <asm/ptrace.h>
127 #define DSP_CONTROL 77
132 unsigned char buf
[8];
134 /* Deliberately signed, for proper sign extension. */
139 /* Return the ptrace ``address'' of register REGNO. */
141 #define mips_base_regs \
142 -1, 1, 2, 3, 4, 5, 6, 7, \
143 8, 9, 10, 11, 12, 13, 14, 15, \
144 16, 17, 18, 19, 20, 21, 22, 23, \
145 24, 25, 26, 27, 28, 29, 30, 31, \
147 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
149 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
150 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
151 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
152 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
153 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
154 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
155 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
156 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
159 #define mips_dsp_regs \
160 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
161 DSP_BASE + 4, DSP_BASE + 5, \
164 static int mips_regmap
[mips_num_regs
] = {
169 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
175 /* DSP registers are not in any regset and can only be accessed
178 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
179 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
182 static int have_dsp
= -1;
184 /* Try peeking at an arbitrarily chosen DSP register and pick the available
185 user register set accordingly. */
187 static const struct target_desc
*
188 mips_read_description (void)
192 int pid
= lwpid_of (current_thread
);
195 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
205 perror_with_name ("ptrace");
210 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
214 mips_target::low_arch_setup ()
216 current_process ()->tdesc
= mips_read_description ();
219 /* Per-process arch-specific data we want to keep. */
221 struct arch_process_info
223 /* -1 if the kernel and/or CPU do not support watch registers.
224 1 if watch_readback is valid and we can read style, num_valid
226 0 if we need to read the watch_readback. */
228 int watch_readback_valid
;
230 /* Cached watch register read values. */
232 struct pt_watch_regs watch_readback
;
234 /* Current watchpoint requests for this process. */
236 struct mips_watchpoint
*current_watches
;
238 /* The current set of watch register values for writing the
241 struct pt_watch_regs watch_mirror
;
244 /* Per-thread arch-specific data we want to keep. */
248 /* Non-zero if our copy differs from what's recorded in the thread. */
249 int watch_registers_changed
;
252 /* From mips-linux-nat.c. */
254 /* Pseudo registers can not be read. ptrace does not provide a way to
255 read (or set) PS_REGNUM, and there's no point in reading or setting
256 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
257 or FCRIR via ptrace(). */
260 mips_target::low_cannot_fetch_register (int regno
)
262 const struct target_desc
*tdesc
;
264 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
267 tdesc
= current_process ()->tdesc
;
269 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
270 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
273 if (find_regno (tdesc
, "r0") == regno
)
280 mips_target::low_cannot_store_register (int regno
)
282 const struct target_desc
*tdesc
;
284 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
287 tdesc
= current_process ()->tdesc
;
289 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
290 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
293 if (find_regno (tdesc
, "r0") == regno
)
296 if (find_regno (tdesc
, "cause") == regno
)
299 if (find_regno (tdesc
, "badvaddr") == regno
)
302 if (find_regno (tdesc
, "fir") == regno
)
309 mips_target::low_fetch_register (regcache
*regcache
, int regno
)
311 const struct target_desc
*tdesc
= current_process ()->tdesc
;
313 if (find_regno (tdesc
, "r0") == regno
)
315 supply_register_zeroed (regcache
, regno
);
323 mips_target::low_supports_breakpoints ()
329 mips_target::low_get_pc (regcache
*regcache
)
331 union mips_register pc
;
332 collect_register_by_name (regcache
, "pc", pc
.buf
);
333 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
337 mips_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
339 union mips_register newpc
;
340 if (register_size (regcache
->tdesc
, 0) == 4)
345 supply_register_by_name (regcache
, "pc", newpc
.buf
);
348 /* Correct in either endianness. */
349 static const unsigned int mips_breakpoint
= 0x0005000d;
350 #define mips_breakpoint_len 4
352 /* Implementation of target ops method "sw_breakpoint_from_kind". */
355 mips_target::sw_breakpoint_from_kind (int kind
, int *size
)
357 *size
= mips_breakpoint_len
;
358 return (const gdb_byte
*) &mips_breakpoint
;
362 mips_target::low_breakpoint_at (CORE_ADDR where
)
366 read_memory (where
, (unsigned char *) &insn
, 4);
367 if (insn
== mips_breakpoint
)
370 /* If necessary, recognize more trap instructions here. GDB only uses the
375 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
378 update_watch_registers_callback (thread_info
*thread
)
380 struct lwp_info
*lwp
= get_thread_lwp (thread
);
382 /* The actual update is done later just before resuming the lwp,
383 we just mark that the registers need updating. */
384 lwp
->arch_private
->watch_registers_changed
= 1;
386 /* If the lwp isn't stopped, force it to momentarily pause, so
387 we can update its watch registers. */
389 linux_stop_lwp (lwp
);
392 /* This is the implementation of linux target ops method
396 mips_target::low_new_process ()
398 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
403 /* This is the implementation of linux target ops method
404 low_delete_process. */
407 mips_target::low_delete_process (arch_process_info
*info
)
412 /* This is the implementation of linux target ops method low_new_thread.
413 Mark the watch registers as changed, so the threads' copies will
417 mips_target::low_new_thread (lwp_info
*lwp
)
419 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
421 info
->watch_registers_changed
= 1;
423 lwp
->arch_private
= info
;
426 /* Function to call when a thread is being deleted. */
429 mips_target::low_delete_thread (arch_lwp_info
*arch_lwp
)
434 /* Create a new mips_watchpoint and add it to the list. */
437 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
438 enum target_hw_bp_type watch_type
)
440 struct mips_watchpoint
*new_watch
;
441 struct mips_watchpoint
**pw
;
443 new_watch
= XNEW (struct mips_watchpoint
);
444 new_watch
->addr
= addr
;
445 new_watch
->len
= len
;
446 new_watch
->type
= watch_type
;
447 new_watch
->next
= NULL
;
449 pw
= &priv
->current_watches
;
455 /* Hook to call when a new fork is attached. */
458 mips_target::low_new_fork (process_info
*parent
,
461 struct arch_process_info
*parent_private
;
462 struct arch_process_info
*child_private
;
463 struct mips_watchpoint
*wp
;
465 /* These are allocated by linux_add_process. */
466 gdb_assert (parent
->priv
!= NULL
467 && parent
->priv
->arch_private
!= NULL
);
468 gdb_assert (child
->priv
!= NULL
469 && child
->priv
->arch_private
!= NULL
);
471 /* Linux kernel before 2.6.33 commit
472 72f674d203cd230426437cdcf7dd6f681dad8b0d
473 will inherit hardware debug registers from parent
474 on fork/vfork/clone. Newer Linux kernels create such tasks with
475 zeroed debug registers.
477 GDB core assumes the child inherits the watchpoints/hw
478 breakpoints of the parent, and will remove them all from the
479 forked off process. Copy the debug registers mirrors into the
480 new process so that all breakpoints and watchpoints can be
481 removed together. The debug registers mirror will become zeroed
482 in the end before detaching the forked off process, thus making
483 this compatible with older Linux kernels too. */
485 parent_private
= parent
->priv
->arch_private
;
486 child_private
= child
->priv
->arch_private
;
488 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
489 child_private
->watch_readback
= parent_private
->watch_readback
;
491 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
492 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
494 child_private
->watch_mirror
= parent_private
->watch_mirror
;
496 /* This is the implementation of linux target ops method
497 low_prepare_to_resume. If the watch regs have changed, update the
501 mips_target::low_prepare_to_resume (lwp_info
*lwp
)
503 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
504 struct process_info
*proc
= find_process_pid (ptid
.pid ());
505 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
507 if (lwp
->arch_private
->watch_registers_changed
)
509 /* Only update the watch registers if we have set or unset a
510 watchpoint already. */
511 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
513 /* Write the mirrored watch register values. */
514 int tid
= ptid
.lwp ();
516 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
517 &priv
->watch_mirror
, NULL
))
518 perror_with_name ("Couldn't write watch register");
521 lwp
->arch_private
->watch_registers_changed
= 0;
526 mips_target::supports_z_point_type (char z_type
)
530 case Z_PACKET_WRITE_WP
:
531 case Z_PACKET_READ_WP
:
532 case Z_PACKET_ACCESS_WP
:
539 /* This is the implementation of linux target ops method
543 mips_target::low_insert_point (raw_bkpt_type type
, CORE_ADDR addr
,
544 int len
, raw_breakpoint
*bp
)
546 struct process_info
*proc
= current_process ();
547 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
548 struct pt_watch_regs regs
;
550 enum target_hw_bp_type watch_type
;
553 lwpid
= lwpid_of (current_thread
);
554 if (!mips_linux_read_watch_registers (lwpid
,
555 &priv
->watch_readback
,
556 &priv
->watch_readback_valid
,
563 regs
= priv
->watch_readback
;
564 /* Add the current watches. */
565 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
567 /* Now try to add the new watch. */
568 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
569 irw
= mips_linux_watch_type_to_irw (watch_type
);
570 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
573 /* It fit. Stick it on the end of the list. */
574 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
576 priv
->watch_mirror
= regs
;
578 /* Only update the threads of this process. */
579 for_each_thread (proc
->pid
, update_watch_registers_callback
);
584 /* This is the implementation of linux target ops method
588 mips_target::low_remove_point (raw_bkpt_type type
, CORE_ADDR addr
,
589 int len
, raw_breakpoint
*bp
)
591 struct process_info
*proc
= current_process ();
592 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
595 enum target_hw_bp_type watch_type
;
597 struct mips_watchpoint
**pw
;
598 struct mips_watchpoint
*w
;
600 /* Search for a known watch that matches. Then unlink and free it. */
601 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
603 pw
= &priv
->current_watches
;
606 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
617 return -1; /* We don't know about it, fail doing nothing. */
619 /* At this point watch_readback is known to be valid because we
620 could not have added the watch without reading it. */
621 gdb_assert (priv
->watch_readback_valid
== 1);
623 priv
->watch_mirror
= priv
->watch_readback
;
624 mips_linux_watch_populate_regs (priv
->current_watches
,
625 &priv
->watch_mirror
);
627 /* Only update the threads of this process. */
628 for_each_thread (proc
->pid
, update_watch_registers_callback
);
633 /* This is the implementation of linux target ops method
634 low_stopped_by_watchpoint. The watchhi R and W bits indicate
635 the watch register triggered. */
638 mips_target::low_stopped_by_watchpoint ()
640 struct process_info
*proc
= current_process ();
641 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
644 long lwpid
= lwpid_of (current_thread
);
646 if (!mips_linux_read_watch_registers (lwpid
,
647 &priv
->watch_readback
,
648 &priv
->watch_readback_valid
,
652 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
654 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
655 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
662 /* This is the implementation of linux target ops method
663 low_stopped_data_address. */
666 mips_target::low_stopped_data_address ()
668 struct process_info
*proc
= current_process ();
669 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
672 long lwpid
= lwpid_of (current_thread
);
674 /* On MIPS we don't know the low order 3 bits of the data address.
675 GDB does not support remote targets that can't report the
676 watchpoint address. So, make our best guess; return the starting
677 address of a watchpoint request which overlaps the one that
680 if (!mips_linux_read_watch_registers (lwpid
,
681 &priv
->watch_readback
,
682 &priv
->watch_readback_valid
,
686 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
688 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
689 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
692 CORE_ADDR t_low
, t_hi
;
694 struct mips_watchpoint
*watch
;
696 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
697 t_irw
= t_low
& IRW_MASK
;
698 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
700 t_low
&= ~(CORE_ADDR
)t_hi
;
702 for (watch
= priv
->current_watches
;
706 CORE_ADDR addr
= watch
->addr
;
707 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
709 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
711 /* Different type. */
714 /* Check for overlap of even a single byte. */
715 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
720 /* Shouldn't happen. */
724 /* Fetch the thread-local storage pointer for libthread_db. */
727 ps_get_thread_area (struct ps_prochandle
*ph
,
728 lwpid_t lwpid
, int idx
, void **base
)
730 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
733 /* IDX is the bias from the thread pointer to the beginning of the
734 thread descriptor. It has to be subtracted due to implementation
735 quirks in libthread_db. */
736 *base
= (void *) ((char *)*base
- idx
);
742 mips_collect_register (struct regcache
*regcache
,
743 int use_64bit
, int regno
, union mips_register
*reg
)
745 union mips_register tmp_reg
;
749 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
754 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
755 reg
->reg64
= tmp_reg
.reg32
;
760 mips_supply_register (struct regcache
*regcache
,
761 int use_64bit
, int regno
, const union mips_register
*reg
)
765 /* For big-endian 32-bit targets, ignore the high four bytes of each
767 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
770 supply_register (regcache
, regno
, reg
->buf
+ offset
);
773 #ifdef HAVE_PTRACE_GETREGS
776 mips_collect_register_32bit (struct regcache
*regcache
,
777 int use_64bit
, int regno
, unsigned char *buf
)
779 union mips_register tmp_reg
;
782 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
783 reg32
= tmp_reg
.reg64
;
784 memcpy (buf
, ®32
, 4);
788 mips_supply_register_32bit (struct regcache
*regcache
,
789 int use_64bit
, int regno
, const unsigned char *buf
)
791 union mips_register tmp_reg
;
794 memcpy (®32
, buf
, 4);
795 tmp_reg
.reg64
= reg32
;
796 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
800 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
802 union mips_register
*regset
= (union mips_register
*) buf
;
804 const struct target_desc
*tdesc
= regcache
->tdesc
;
806 use_64bit
= (register_size (tdesc
, 0) == 8);
808 for (i
= 1; i
< 32; i
++)
809 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
811 mips_collect_register (regcache
, use_64bit
,
812 find_regno (tdesc
, "lo"), regset
+ 32);
813 mips_collect_register (regcache
, use_64bit
,
814 find_regno (tdesc
, "hi"), regset
+ 33);
815 mips_collect_register (regcache
, use_64bit
,
816 find_regno (tdesc
, "pc"), regset
+ 34);
817 mips_collect_register (regcache
, use_64bit
,
818 find_regno (tdesc
, "badvaddr"), regset
+ 35);
819 mips_collect_register (regcache
, use_64bit
,
820 find_regno (tdesc
, "status"), regset
+ 36);
821 mips_collect_register (regcache
, use_64bit
,
822 find_regno (tdesc
, "cause"), regset
+ 37);
824 mips_collect_register (regcache
, use_64bit
,
825 find_regno (tdesc
, "restart"), regset
+ 0);
829 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
831 const union mips_register
*regset
= (const union mips_register
*) buf
;
834 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
836 supply_register_by_name_zeroed (regcache
, "r0");
838 for (i
= 1; i
< 32; i
++)
839 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
841 mips_supply_register (regcache
, use_64bit
,
842 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
843 mips_supply_register (regcache
, use_64bit
,
844 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
845 mips_supply_register (regcache
, use_64bit
,
846 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
847 mips_supply_register (regcache
, use_64bit
,
848 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
849 mips_supply_register (regcache
, use_64bit
,
850 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
851 mips_supply_register (regcache
, use_64bit
,
852 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
854 mips_supply_register (regcache
, use_64bit
,
855 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
859 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
861 union mips_register
*regset
= (union mips_register
*) buf
;
862 int i
, use_64bit
, first_fp
, big_endian
;
864 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
865 first_fp
= find_regno (regcache
->tdesc
, "f0");
866 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
868 /* See GDB for a discussion of this peculiar layout. */
869 for (i
= 0; i
< 32; i
++)
871 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
873 collect_register (regcache
, first_fp
+ i
,
874 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
876 mips_collect_register_32bit (regcache
, use_64bit
,
877 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
878 mips_collect_register_32bit (regcache
, use_64bit
,
879 find_regno (regcache
->tdesc
, "fir"),
884 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
886 const union mips_register
*regset
= (const union mips_register
*) buf
;
887 int i
, use_64bit
, first_fp
, big_endian
;
889 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
890 first_fp
= find_regno (regcache
->tdesc
, "f0");
891 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
893 /* See GDB for a discussion of this peculiar layout. */
894 for (i
= 0; i
< 32; i
++)
896 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
898 supply_register (regcache
, first_fp
+ i
,
899 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
901 mips_supply_register_32bit (regcache
, use_64bit
,
902 find_regno (regcache
->tdesc
, "fcsr"),
904 mips_supply_register_32bit (regcache
, use_64bit
,
905 find_regno (regcache
->tdesc
, "fir"),
908 #endif /* HAVE_PTRACE_GETREGS */
910 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
913 mips_target::low_collect_ptrace_register (regcache
*regcache
, int regno
,
916 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
918 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
920 union mips_register reg
;
922 mips_collect_register (regcache
, 0, regno
, ®
);
923 memcpy (buf
, ®
, sizeof (reg
));
926 collect_register (regcache
, regno
, buf
);
929 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
932 mips_target::low_supply_ptrace_register (regcache
*regcache
, int regno
,
935 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
937 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
939 union mips_register reg
;
941 memcpy (®
, buf
, sizeof (reg
));
942 mips_supply_register (regcache
, 0, regno
, ®
);
945 supply_register (regcache
, regno
, buf
);
948 static struct regset_info mips_regsets
[] = {
949 #ifdef HAVE_PTRACE_GETREGS
950 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
951 mips_fill_gregset
, mips_store_gregset
},
952 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
953 mips_fill_fpregset
, mips_store_fpregset
},
954 #endif /* HAVE_PTRACE_GETREGS */
958 static struct regsets_info mips_regsets_info
=
960 mips_regsets
, /* regsets */
962 NULL
, /* disabled_regsets */
965 static struct usrregs_info mips_dsp_usrregs_info
=
971 static struct usrregs_info mips_usrregs_info
=
977 static struct regs_info dsp_regs_info
=
979 mips_dsp_regset_bitmap
,
980 &mips_dsp_usrregs_info
,
984 static struct regs_info myregs_info
=
986 NULL
, /* regset_bitmap */
992 mips_target::get_regs_info ()
995 return &dsp_regs_info
;
1000 /* The linux target ops object. */
1002 linux_process_target
*the_linux_target
= &the_mips_target
;
1005 initialize_low_arch (void)
1007 /* Initialize the Linux target descriptions. */
1008 init_registers_mips_linux ();
1009 init_registers_mips_dsp_linux ();
1010 init_registers_mips64_linux ();
1011 init_registers_mips64_dsp_linux ();
1013 initialize_regsets_info (&mips_regsets_info
);