1 /* GNU/Linux/MIPS specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995-2020 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
;
59 /* The singleton target ops object. */
61 static mips_target the_mips_target
;
63 /* Defined in auto-generated file mips-linux.c. */
64 void init_registers_mips_linux (void);
65 extern const struct target_desc
*tdesc_mips_linux
;
67 /* Defined in auto-generated file mips-dsp-linux.c. */
68 void init_registers_mips_dsp_linux (void);
69 extern const struct target_desc
*tdesc_mips_dsp_linux
;
71 /* Defined in auto-generated file mips64-linux.c. */
72 void init_registers_mips64_linux (void);
73 extern const struct target_desc
*tdesc_mips64_linux
;
75 /* Defined in auto-generated file mips64-dsp-linux.c. */
76 void init_registers_mips64_dsp_linux (void);
77 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
80 #define tdesc_mips_linux tdesc_mips64_linux
81 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
84 #ifndef PTRACE_GET_THREAD_AREA
85 #define PTRACE_GET_THREAD_AREA 25
92 #define mips_num_regs 73
93 #define mips_dsp_num_regs 80
95 #include <asm/ptrace.h>
99 #define DSP_CONTROL 77
104 unsigned char buf
[8];
106 /* Deliberately signed, for proper sign extension. */
111 /* Return the ptrace ``address'' of register REGNO. */
113 #define mips_base_regs \
114 -1, 1, 2, 3, 4, 5, 6, 7, \
115 8, 9, 10, 11, 12, 13, 14, 15, \
116 16, 17, 18, 19, 20, 21, 22, 23, \
117 24, 25, 26, 27, 28, 29, 30, 31, \
119 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
121 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
122 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
123 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
124 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
125 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
126 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
127 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
128 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
131 #define mips_dsp_regs \
132 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
133 DSP_BASE + 4, DSP_BASE + 5, \
136 static int mips_regmap
[mips_num_regs
] = {
141 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
147 /* DSP registers are not in any regset and can only be accessed
150 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
151 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
154 static int have_dsp
= -1;
156 /* Try peeking at an arbitrarily chosen DSP register and pick the available
157 user register set accordingly. */
159 static const struct target_desc
*
160 mips_read_description (void)
164 int pid
= lwpid_of (current_thread
);
167 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
177 perror_with_name ("ptrace");
182 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
186 mips_target::low_arch_setup ()
188 current_process ()->tdesc
= mips_read_description ();
191 /* Per-process arch-specific data we want to keep. */
193 struct arch_process_info
195 /* -1 if the kernel and/or CPU do not support watch registers.
196 1 if watch_readback is valid and we can read style, num_valid
198 0 if we need to read the watch_readback. */
200 int watch_readback_valid
;
202 /* Cached watch register read values. */
204 struct pt_watch_regs watch_readback
;
206 /* Current watchpoint requests for this process. */
208 struct mips_watchpoint
*current_watches
;
210 /* The current set of watch register values for writing the
213 struct pt_watch_regs watch_mirror
;
216 /* Per-thread arch-specific data we want to keep. */
220 /* Non-zero if our copy differs from what's recorded in the thread. */
221 int watch_registers_changed
;
224 /* From mips-linux-nat.c. */
226 /* Pseudo registers can not be read. ptrace does not provide a way to
227 read (or set) PS_REGNUM, and there's no point in reading or setting
228 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
229 or FCRIR via ptrace(). */
232 mips_target::low_cannot_fetch_register (int regno
)
234 const struct target_desc
*tdesc
;
236 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
239 tdesc
= current_process ()->tdesc
;
241 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
242 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
245 if (find_regno (tdesc
, "r0") == regno
)
252 mips_target::low_cannot_store_register (int regno
)
254 const struct target_desc
*tdesc
;
256 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
259 tdesc
= current_process ()->tdesc
;
261 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
262 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
265 if (find_regno (tdesc
, "r0") == regno
)
268 if (find_regno (tdesc
, "cause") == regno
)
271 if (find_regno (tdesc
, "badvaddr") == regno
)
274 if (find_regno (tdesc
, "fir") == regno
)
281 mips_target::low_fetch_register (regcache
*regcache
, int regno
)
283 const struct target_desc
*tdesc
= current_process ()->tdesc
;
285 if (find_regno (tdesc
, "r0") == regno
)
287 supply_register_zeroed (regcache
, regno
);
295 mips_target::low_supports_breakpoints ()
301 mips_target::low_get_pc (regcache
*regcache
)
303 union mips_register pc
;
304 collect_register_by_name (regcache
, "pc", pc
.buf
);
305 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
309 mips_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
311 union mips_register newpc
;
312 if (register_size (regcache
->tdesc
, 0) == 4)
317 supply_register_by_name (regcache
, "pc", newpc
.buf
);
320 /* Correct in either endianness. */
321 static const unsigned int mips_breakpoint
= 0x0005000d;
322 #define mips_breakpoint_len 4
324 /* Implementation of target ops method "sw_breakpoint_from_kind". */
327 mips_target::sw_breakpoint_from_kind (int kind
, int *size
)
329 *size
= mips_breakpoint_len
;
330 return (const gdb_byte
*) &mips_breakpoint
;
334 mips_target::low_breakpoint_at (CORE_ADDR where
)
338 read_memory (where
, (unsigned char *) &insn
, 4);
339 if (insn
== mips_breakpoint
)
342 /* If necessary, recognize more trap instructions here. GDB only uses the
347 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
350 update_watch_registers_callback (thread_info
*thread
)
352 struct lwp_info
*lwp
= get_thread_lwp (thread
);
354 /* The actual update is done later just before resuming the lwp,
355 we just mark that the registers need updating. */
356 lwp
->arch_private
->watch_registers_changed
= 1;
358 /* If the lwp isn't stopped, force it to momentarily pause, so
359 we can update its watch registers. */
361 linux_stop_lwp (lwp
);
364 /* This is the implementation of linux_target_ops method
367 static struct arch_process_info
*
368 mips_linux_new_process (void)
370 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
375 /* This is the implementation of linux_target_ops method
379 mips_linux_delete_process (struct arch_process_info
*info
)
384 /* This is the implementation of linux_target_ops method new_thread.
385 Mark the watch registers as changed, so the threads' copies will
389 mips_linux_new_thread (struct lwp_info
*lwp
)
391 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
393 info
->watch_registers_changed
= 1;
395 lwp
->arch_private
= info
;
398 /* Function to call when a thread is being deleted. */
401 mips_linux_delete_thread (struct arch_lwp_info
*arch_lwp
)
406 /* Create a new mips_watchpoint and add it to the list. */
409 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
410 enum target_hw_bp_type watch_type
)
412 struct mips_watchpoint
*new_watch
;
413 struct mips_watchpoint
**pw
;
415 new_watch
= XNEW (struct mips_watchpoint
);
416 new_watch
->addr
= addr
;
417 new_watch
->len
= len
;
418 new_watch
->type
= watch_type
;
419 new_watch
->next
= NULL
;
421 pw
= &priv
->current_watches
;
427 /* Hook to call when a new fork is attached. */
430 mips_linux_new_fork (struct process_info
*parent
,
431 struct process_info
*child
)
433 struct arch_process_info
*parent_private
;
434 struct arch_process_info
*child_private
;
435 struct mips_watchpoint
*wp
;
437 /* These are allocated by linux_add_process. */
438 gdb_assert (parent
->priv
!= NULL
439 && parent
->priv
->arch_private
!= NULL
);
440 gdb_assert (child
->priv
!= NULL
441 && child
->priv
->arch_private
!= NULL
);
443 /* Linux kernel before 2.6.33 commit
444 72f674d203cd230426437cdcf7dd6f681dad8b0d
445 will inherit hardware debug registers from parent
446 on fork/vfork/clone. Newer Linux kernels create such tasks with
447 zeroed debug registers.
449 GDB core assumes the child inherits the watchpoints/hw
450 breakpoints of the parent, and will remove them all from the
451 forked off process. Copy the debug registers mirrors into the
452 new process so that all breakpoints and watchpoints can be
453 removed together. The debug registers mirror will become zeroed
454 in the end before detaching the forked off process, thus making
455 this compatible with older Linux kernels too. */
457 parent_private
= parent
->priv
->arch_private
;
458 child_private
= child
->priv
->arch_private
;
460 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
461 child_private
->watch_readback
= parent_private
->watch_readback
;
463 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
464 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
466 child_private
->watch_mirror
= parent_private
->watch_mirror
;
468 /* This is the implementation of linux_target_ops method
469 prepare_to_resume. If the watch regs have changed, update the
473 mips_linux_prepare_to_resume (struct lwp_info
*lwp
)
475 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
476 struct process_info
*proc
= find_process_pid (ptid
.pid ());
477 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
479 if (lwp
->arch_private
->watch_registers_changed
)
481 /* Only update the watch registers if we have set or unset a
482 watchpoint already. */
483 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
485 /* Write the mirrored watch register values. */
486 int tid
= ptid
.lwp ();
488 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
489 &priv
->watch_mirror
, NULL
))
490 perror_with_name ("Couldn't write watch register");
493 lwp
->arch_private
->watch_registers_changed
= 0;
498 mips_target::supports_z_point_type (char z_type
)
502 case Z_PACKET_WRITE_WP
:
503 case Z_PACKET_READ_WP
:
504 case Z_PACKET_ACCESS_WP
:
511 /* This is the implementation of linux_target_ops method
515 mips_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
516 int len
, struct raw_breakpoint
*bp
)
518 struct process_info
*proc
= current_process ();
519 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
520 struct pt_watch_regs regs
;
522 enum target_hw_bp_type watch_type
;
525 lwpid
= lwpid_of (current_thread
);
526 if (!mips_linux_read_watch_registers (lwpid
,
527 &priv
->watch_readback
,
528 &priv
->watch_readback_valid
,
535 regs
= priv
->watch_readback
;
536 /* Add the current watches. */
537 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
539 /* Now try to add the new watch. */
540 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
541 irw
= mips_linux_watch_type_to_irw (watch_type
);
542 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
545 /* It fit. Stick it on the end of the list. */
546 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
548 priv
->watch_mirror
= regs
;
550 /* Only update the threads of this process. */
551 for_each_thread (proc
->pid
, update_watch_registers_callback
);
556 /* This is the implementation of linux_target_ops method
560 mips_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
561 int len
, struct raw_breakpoint
*bp
)
563 struct process_info
*proc
= current_process ();
564 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
567 enum target_hw_bp_type watch_type
;
569 struct mips_watchpoint
**pw
;
570 struct mips_watchpoint
*w
;
572 /* Search for a known watch that matches. Then unlink and free it. */
573 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
575 pw
= &priv
->current_watches
;
578 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
589 return -1; /* We don't know about it, fail doing nothing. */
591 /* At this point watch_readback is known to be valid because we
592 could not have added the watch without reading it. */
593 gdb_assert (priv
->watch_readback_valid
== 1);
595 priv
->watch_mirror
= priv
->watch_readback
;
596 mips_linux_watch_populate_regs (priv
->current_watches
,
597 &priv
->watch_mirror
);
599 /* Only update the threads of this process. */
600 for_each_thread (proc
->pid
, update_watch_registers_callback
);
605 /* This is the implementation of linux_target_ops method
606 stopped_by_watchpoint. The watchhi R and W bits indicate
607 the watch register triggered. */
610 mips_stopped_by_watchpoint (void)
612 struct process_info
*proc
= current_process ();
613 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
616 long lwpid
= lwpid_of (current_thread
);
618 if (!mips_linux_read_watch_registers (lwpid
,
619 &priv
->watch_readback
,
620 &priv
->watch_readback_valid
,
624 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
626 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
627 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
634 /* This is the implementation of linux_target_ops method
635 stopped_data_address. */
638 mips_stopped_data_address (void)
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 /* On MIPS we don't know the low order 3 bits of the data address.
647 GDB does not support remote targets that can't report the
648 watchpoint address. So, make our best guess; return the starting
649 address of a watchpoint request which overlaps the one that
652 if (!mips_linux_read_watch_registers (lwpid
,
653 &priv
->watch_readback
,
654 &priv
->watch_readback_valid
,
658 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
660 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
661 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
664 CORE_ADDR t_low
, t_hi
;
666 struct mips_watchpoint
*watch
;
668 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
669 t_irw
= t_low
& IRW_MASK
;
670 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
672 t_low
&= ~(CORE_ADDR
)t_hi
;
674 for (watch
= priv
->current_watches
;
678 CORE_ADDR addr
= watch
->addr
;
679 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
681 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
683 /* Different type. */
686 /* Check for overlap of even a single byte. */
687 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
692 /* Shouldn't happen. */
696 /* Fetch the thread-local storage pointer for libthread_db. */
699 ps_get_thread_area (struct ps_prochandle
*ph
,
700 lwpid_t lwpid
, int idx
, void **base
)
702 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
705 /* IDX is the bias from the thread pointer to the beginning of the
706 thread descriptor. It has to be subtracted due to implementation
707 quirks in libthread_db. */
708 *base
= (void *) ((char *)*base
- idx
);
714 mips_collect_register (struct regcache
*regcache
,
715 int use_64bit
, int regno
, union mips_register
*reg
)
717 union mips_register tmp_reg
;
721 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
726 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
727 reg
->reg64
= tmp_reg
.reg32
;
732 mips_supply_register (struct regcache
*regcache
,
733 int use_64bit
, int regno
, const union mips_register
*reg
)
737 /* For big-endian 32-bit targets, ignore the high four bytes of each
739 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
742 supply_register (regcache
, regno
, reg
->buf
+ offset
);
745 #ifdef HAVE_PTRACE_GETREGS
748 mips_collect_register_32bit (struct regcache
*regcache
,
749 int use_64bit
, int regno
, unsigned char *buf
)
751 union mips_register tmp_reg
;
754 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
755 reg32
= tmp_reg
.reg64
;
756 memcpy (buf
, ®32
, 4);
760 mips_supply_register_32bit (struct regcache
*regcache
,
761 int use_64bit
, int regno
, const unsigned char *buf
)
763 union mips_register tmp_reg
;
766 memcpy (®32
, buf
, 4);
767 tmp_reg
.reg64
= reg32
;
768 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
772 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
774 union mips_register
*regset
= (union mips_register
*) buf
;
776 const struct target_desc
*tdesc
= regcache
->tdesc
;
778 use_64bit
= (register_size (tdesc
, 0) == 8);
780 for (i
= 1; i
< 32; i
++)
781 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
783 mips_collect_register (regcache
, use_64bit
,
784 find_regno (tdesc
, "lo"), regset
+ 32);
785 mips_collect_register (regcache
, use_64bit
,
786 find_regno (tdesc
, "hi"), regset
+ 33);
787 mips_collect_register (regcache
, use_64bit
,
788 find_regno (tdesc
, "pc"), regset
+ 34);
789 mips_collect_register (regcache
, use_64bit
,
790 find_regno (tdesc
, "badvaddr"), regset
+ 35);
791 mips_collect_register (regcache
, use_64bit
,
792 find_regno (tdesc
, "status"), regset
+ 36);
793 mips_collect_register (regcache
, use_64bit
,
794 find_regno (tdesc
, "cause"), regset
+ 37);
796 mips_collect_register (regcache
, use_64bit
,
797 find_regno (tdesc
, "restart"), regset
+ 0);
801 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
803 const union mips_register
*regset
= (const union mips_register
*) buf
;
806 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
808 supply_register_by_name_zeroed (regcache
, "r0");
810 for (i
= 1; i
< 32; i
++)
811 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
813 mips_supply_register (regcache
, use_64bit
,
814 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
815 mips_supply_register (regcache
, use_64bit
,
816 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
817 mips_supply_register (regcache
, use_64bit
,
818 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
819 mips_supply_register (regcache
, use_64bit
,
820 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
821 mips_supply_register (regcache
, use_64bit
,
822 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
823 mips_supply_register (regcache
, use_64bit
,
824 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
826 mips_supply_register (regcache
, use_64bit
,
827 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
831 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
833 union mips_register
*regset
= (union mips_register
*) buf
;
834 int i
, use_64bit
, first_fp
, big_endian
;
836 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
837 first_fp
= find_regno (regcache
->tdesc
, "f0");
838 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
840 /* See GDB for a discussion of this peculiar layout. */
841 for (i
= 0; i
< 32; i
++)
843 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
845 collect_register (regcache
, first_fp
+ i
,
846 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
848 mips_collect_register_32bit (regcache
, use_64bit
,
849 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
850 mips_collect_register_32bit (regcache
, use_64bit
,
851 find_regno (regcache
->tdesc
, "fir"),
856 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
858 const union mips_register
*regset
= (const union mips_register
*) buf
;
859 int i
, use_64bit
, first_fp
, big_endian
;
861 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
862 first_fp
= find_regno (regcache
->tdesc
, "f0");
863 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
865 /* See GDB for a discussion of this peculiar layout. */
866 for (i
= 0; i
< 32; i
++)
868 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
870 supply_register (regcache
, first_fp
+ i
,
871 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
873 mips_supply_register_32bit (regcache
, use_64bit
,
874 find_regno (regcache
->tdesc
, "fcsr"),
876 mips_supply_register_32bit (regcache
, use_64bit
,
877 find_regno (regcache
->tdesc
, "fir"),
880 #endif /* HAVE_PTRACE_GETREGS */
882 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
885 mips_collect_ptrace_register (struct regcache
*regcache
,
886 int regno
, char *buf
)
888 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
890 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
892 union mips_register reg
;
894 mips_collect_register (regcache
, 0, regno
, ®
);
895 memcpy (buf
, ®
, sizeof (reg
));
898 collect_register (regcache
, regno
, buf
);
901 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
904 mips_supply_ptrace_register (struct regcache
*regcache
,
905 int regno
, const char *buf
)
907 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
909 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
911 union mips_register reg
;
913 memcpy (®
, buf
, sizeof (reg
));
914 mips_supply_register (regcache
, 0, regno
, ®
);
917 supply_register (regcache
, regno
, buf
);
920 static struct regset_info mips_regsets
[] = {
921 #ifdef HAVE_PTRACE_GETREGS
922 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
923 mips_fill_gregset
, mips_store_gregset
},
924 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
925 mips_fill_fpregset
, mips_store_fpregset
},
926 #endif /* HAVE_PTRACE_GETREGS */
930 static struct regsets_info mips_regsets_info
=
932 mips_regsets
, /* regsets */
934 NULL
, /* disabled_regsets */
937 static struct usrregs_info mips_dsp_usrregs_info
=
943 static struct usrregs_info mips_usrregs_info
=
949 static struct regs_info dsp_regs_info
=
951 mips_dsp_regset_bitmap
,
952 &mips_dsp_usrregs_info
,
956 static struct regs_info myregs_info
=
958 NULL
, /* regset_bitmap */
964 mips_target::get_regs_info ()
967 return &dsp_regs_info
;
972 struct linux_target_ops the_low_target
= {
975 mips_stopped_by_watchpoint
,
976 mips_stopped_data_address
,
977 mips_collect_ptrace_register
,
978 mips_supply_ptrace_register
,
979 NULL
, /* siginfo_fixup */
980 mips_linux_new_process
,
981 mips_linux_delete_process
,
982 mips_linux_new_thread
,
983 mips_linux_delete_thread
,
985 mips_linux_prepare_to_resume
988 /* The linux target ops object. */
990 linux_process_target
*the_linux_target
= &the_mips_target
;
993 initialize_low_arch (void)
995 /* Initialize the Linux target descriptions. */
996 init_registers_mips_linux ();
997 init_registers_mips_dsp_linux ();
998 init_registers_mips64_linux ();
999 init_registers_mips64_dsp_linux ();
1001 initialize_regsets_info (&mips_regsets_info
);