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
36 void low_arch_setup () override
;
39 /* The singleton target ops object. */
41 static mips_target the_mips_target
;
43 /* Defined in auto-generated file mips-linux.c. */
44 void init_registers_mips_linux (void);
45 extern const struct target_desc
*tdesc_mips_linux
;
47 /* Defined in auto-generated file mips-dsp-linux.c. */
48 void init_registers_mips_dsp_linux (void);
49 extern const struct target_desc
*tdesc_mips_dsp_linux
;
51 /* Defined in auto-generated file mips64-linux.c. */
52 void init_registers_mips64_linux (void);
53 extern const struct target_desc
*tdesc_mips64_linux
;
55 /* Defined in auto-generated file mips64-dsp-linux.c. */
56 void init_registers_mips64_dsp_linux (void);
57 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
60 #define tdesc_mips_linux tdesc_mips64_linux
61 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
64 #ifndef PTRACE_GET_THREAD_AREA
65 #define PTRACE_GET_THREAD_AREA 25
72 #define mips_num_regs 73
73 #define mips_dsp_num_regs 80
75 #include <asm/ptrace.h>
79 #define DSP_CONTROL 77
86 /* Deliberately signed, for proper sign extension. */
91 /* Return the ptrace ``address'' of register REGNO. */
93 #define mips_base_regs \
94 -1, 1, 2, 3, 4, 5, 6, 7, \
95 8, 9, 10, 11, 12, 13, 14, 15, \
96 16, 17, 18, 19, 20, 21, 22, 23, \
97 24, 25, 26, 27, 28, 29, 30, 31, \
99 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
101 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
102 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
103 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
104 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
105 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
106 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
107 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
108 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
111 #define mips_dsp_regs \
112 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
113 DSP_BASE + 4, DSP_BASE + 5, \
116 static int mips_regmap
[mips_num_regs
] = {
121 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
127 /* DSP registers are not in any regset and can only be accessed
130 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
131 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
134 static int have_dsp
= -1;
136 /* Try peeking at an arbitrarily chosen DSP register and pick the available
137 user register set accordingly. */
139 static const struct target_desc
*
140 mips_read_description (void)
144 int pid
= lwpid_of (current_thread
);
147 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
157 perror_with_name ("ptrace");
162 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
166 mips_target::low_arch_setup ()
168 current_process ()->tdesc
= mips_read_description ();
171 static struct usrregs_info
*
172 get_usrregs_info (void)
174 const struct regs_info
*regs_info
= the_low_target
.regs_info ();
176 return regs_info
->usrregs
;
179 /* Per-process arch-specific data we want to keep. */
181 struct arch_process_info
183 /* -1 if the kernel and/or CPU do not support watch registers.
184 1 if watch_readback is valid and we can read style, num_valid
186 0 if we need to read the watch_readback. */
188 int watch_readback_valid
;
190 /* Cached watch register read values. */
192 struct pt_watch_regs watch_readback
;
194 /* Current watchpoint requests for this process. */
196 struct mips_watchpoint
*current_watches
;
198 /* The current set of watch register values for writing the
201 struct pt_watch_regs watch_mirror
;
204 /* Per-thread arch-specific data we want to keep. */
208 /* Non-zero if our copy differs from what's recorded in the thread. */
209 int watch_registers_changed
;
212 /* From mips-linux-nat.c. */
214 /* Pseudo registers can not be read. ptrace does not provide a way to
215 read (or set) PS_REGNUM, and there's no point in reading or setting
216 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
217 or FCRIR via ptrace(). */
220 mips_cannot_fetch_register (int regno
)
222 const struct target_desc
*tdesc
;
224 if (get_usrregs_info ()->regmap
[regno
] == -1)
227 tdesc
= current_process ()->tdesc
;
229 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
230 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
233 if (find_regno (tdesc
, "r0") == regno
)
240 mips_cannot_store_register (int regno
)
242 const struct target_desc
*tdesc
;
244 if (get_usrregs_info ()->regmap
[regno
] == -1)
247 tdesc
= current_process ()->tdesc
;
249 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
250 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
253 if (find_regno (tdesc
, "r0") == regno
)
256 if (find_regno (tdesc
, "cause") == regno
)
259 if (find_regno (tdesc
, "badvaddr") == regno
)
262 if (find_regno (tdesc
, "fir") == regno
)
269 mips_fetch_register (struct regcache
*regcache
, int regno
)
271 const struct target_desc
*tdesc
= current_process ()->tdesc
;
273 if (find_regno (tdesc
, "r0") == regno
)
275 supply_register_zeroed (regcache
, regno
);
283 mips_get_pc (struct regcache
*regcache
)
285 union mips_register pc
;
286 collect_register_by_name (regcache
, "pc", pc
.buf
);
287 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
291 mips_set_pc (struct regcache
*regcache
, CORE_ADDR pc
)
293 union mips_register newpc
;
294 if (register_size (regcache
->tdesc
, 0) == 4)
299 supply_register_by_name (regcache
, "pc", newpc
.buf
);
302 /* Correct in either endianness. */
303 static const unsigned int mips_breakpoint
= 0x0005000d;
304 #define mips_breakpoint_len 4
306 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
308 static const gdb_byte
*
309 mips_sw_breakpoint_from_kind (int kind
, int *size
)
311 *size
= mips_breakpoint_len
;
312 return (const gdb_byte
*) &mips_breakpoint
;
316 mips_breakpoint_at (CORE_ADDR where
)
320 the_target
->read_memory (where
, (unsigned char *) &insn
, 4);
321 if (insn
== mips_breakpoint
)
324 /* If necessary, recognize more trap instructions here. GDB only uses the
329 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
332 update_watch_registers_callback (thread_info
*thread
)
334 struct lwp_info
*lwp
= get_thread_lwp (thread
);
336 /* The actual update is done later just before resuming the lwp,
337 we just mark that the registers need updating. */
338 lwp
->arch_private
->watch_registers_changed
= 1;
340 /* If the lwp isn't stopped, force it to momentarily pause, so
341 we can update its watch registers. */
343 linux_stop_lwp (lwp
);
346 /* This is the implementation of linux_target_ops method
349 static struct arch_process_info
*
350 mips_linux_new_process (void)
352 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
357 /* This is the implementation of linux_target_ops method
361 mips_linux_delete_process (struct arch_process_info
*info
)
366 /* This is the implementation of linux_target_ops method new_thread.
367 Mark the watch registers as changed, so the threads' copies will
371 mips_linux_new_thread (struct lwp_info
*lwp
)
373 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
375 info
->watch_registers_changed
= 1;
377 lwp
->arch_private
= info
;
380 /* Function to call when a thread is being deleted. */
383 mips_linux_delete_thread (struct arch_lwp_info
*arch_lwp
)
388 /* Create a new mips_watchpoint and add it to the list. */
391 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
392 enum target_hw_bp_type watch_type
)
394 struct mips_watchpoint
*new_watch
;
395 struct mips_watchpoint
**pw
;
397 new_watch
= XNEW (struct mips_watchpoint
);
398 new_watch
->addr
= addr
;
399 new_watch
->len
= len
;
400 new_watch
->type
= watch_type
;
401 new_watch
->next
= NULL
;
403 pw
= &priv
->current_watches
;
409 /* Hook to call when a new fork is attached. */
412 mips_linux_new_fork (struct process_info
*parent
,
413 struct process_info
*child
)
415 struct arch_process_info
*parent_private
;
416 struct arch_process_info
*child_private
;
417 struct mips_watchpoint
*wp
;
419 /* These are allocated by linux_add_process. */
420 gdb_assert (parent
->priv
!= NULL
421 && parent
->priv
->arch_private
!= NULL
);
422 gdb_assert (child
->priv
!= NULL
423 && child
->priv
->arch_private
!= NULL
);
425 /* Linux kernel before 2.6.33 commit
426 72f674d203cd230426437cdcf7dd6f681dad8b0d
427 will inherit hardware debug registers from parent
428 on fork/vfork/clone. Newer Linux kernels create such tasks with
429 zeroed debug registers.
431 GDB core assumes the child inherits the watchpoints/hw
432 breakpoints of the parent, and will remove them all from the
433 forked off process. Copy the debug registers mirrors into the
434 new process so that all breakpoints and watchpoints can be
435 removed together. The debug registers mirror will become zeroed
436 in the end before detaching the forked off process, thus making
437 this compatible with older Linux kernels too. */
439 parent_private
= parent
->priv
->arch_private
;
440 child_private
= child
->priv
->arch_private
;
442 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
443 child_private
->watch_readback
= parent_private
->watch_readback
;
445 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
446 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
448 child_private
->watch_mirror
= parent_private
->watch_mirror
;
450 /* This is the implementation of linux_target_ops method
451 prepare_to_resume. If the watch regs have changed, update the
455 mips_linux_prepare_to_resume (struct lwp_info
*lwp
)
457 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
458 struct process_info
*proc
= find_process_pid (ptid
.pid ());
459 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
461 if (lwp
->arch_private
->watch_registers_changed
)
463 /* Only update the watch registers if we have set or unset a
464 watchpoint already. */
465 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
467 /* Write the mirrored watch register values. */
468 int tid
= ptid
.lwp ();
470 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
471 &priv
->watch_mirror
, NULL
))
472 perror_with_name ("Couldn't write watch register");
475 lwp
->arch_private
->watch_registers_changed
= 0;
480 mips_supports_z_point_type (char z_type
)
484 case Z_PACKET_WRITE_WP
:
485 case Z_PACKET_READ_WP
:
486 case Z_PACKET_ACCESS_WP
:
493 /* This is the implementation of linux_target_ops method
497 mips_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
498 int len
, struct raw_breakpoint
*bp
)
500 struct process_info
*proc
= current_process ();
501 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
502 struct pt_watch_regs regs
;
504 enum target_hw_bp_type watch_type
;
507 lwpid
= lwpid_of (current_thread
);
508 if (!mips_linux_read_watch_registers (lwpid
,
509 &priv
->watch_readback
,
510 &priv
->watch_readback_valid
,
517 regs
= priv
->watch_readback
;
518 /* Add the current watches. */
519 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
521 /* Now try to add the new watch. */
522 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
523 irw
= mips_linux_watch_type_to_irw (watch_type
);
524 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
527 /* It fit. Stick it on the end of the list. */
528 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
530 priv
->watch_mirror
= regs
;
532 /* Only update the threads of this process. */
533 for_each_thread (proc
->pid
, update_watch_registers_callback
);
538 /* This is the implementation of linux_target_ops method
542 mips_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
543 int len
, struct raw_breakpoint
*bp
)
545 struct process_info
*proc
= current_process ();
546 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
549 enum target_hw_bp_type watch_type
;
551 struct mips_watchpoint
**pw
;
552 struct mips_watchpoint
*w
;
554 /* Search for a known watch that matches. Then unlink and free it. */
555 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
557 pw
= &priv
->current_watches
;
560 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
571 return -1; /* We don't know about it, fail doing nothing. */
573 /* At this point watch_readback is known to be valid because we
574 could not have added the watch without reading it. */
575 gdb_assert (priv
->watch_readback_valid
== 1);
577 priv
->watch_mirror
= priv
->watch_readback
;
578 mips_linux_watch_populate_regs (priv
->current_watches
,
579 &priv
->watch_mirror
);
581 /* Only update the threads of this process. */
582 for_each_thread (proc
->pid
, update_watch_registers_callback
);
587 /* This is the implementation of linux_target_ops method
588 stopped_by_watchpoint. The watchhi R and W bits indicate
589 the watch register triggered. */
592 mips_stopped_by_watchpoint (void)
594 struct process_info
*proc
= current_process ();
595 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
598 long lwpid
= lwpid_of (current_thread
);
600 if (!mips_linux_read_watch_registers (lwpid
,
601 &priv
->watch_readback
,
602 &priv
->watch_readback_valid
,
606 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
608 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
609 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
616 /* This is the implementation of linux_target_ops method
617 stopped_data_address. */
620 mips_stopped_data_address (void)
622 struct process_info
*proc
= current_process ();
623 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
626 long lwpid
= lwpid_of (current_thread
);
628 /* On MIPS we don't know the low order 3 bits of the data address.
629 GDB does not support remote targets that can't report the
630 watchpoint address. So, make our best guess; return the starting
631 address of a watchpoint request which overlaps the one that
634 if (!mips_linux_read_watch_registers (lwpid
,
635 &priv
->watch_readback
,
636 &priv
->watch_readback_valid
,
640 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
642 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
643 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
646 CORE_ADDR t_low
, t_hi
;
648 struct mips_watchpoint
*watch
;
650 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
651 t_irw
= t_low
& IRW_MASK
;
652 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
654 t_low
&= ~(CORE_ADDR
)t_hi
;
656 for (watch
= priv
->current_watches
;
660 CORE_ADDR addr
= watch
->addr
;
661 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
663 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
665 /* Different type. */
668 /* Check for overlap of even a single byte. */
669 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
674 /* Shouldn't happen. */
678 /* Fetch the thread-local storage pointer for libthread_db. */
681 ps_get_thread_area (struct ps_prochandle
*ph
,
682 lwpid_t lwpid
, int idx
, void **base
)
684 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
687 /* IDX is the bias from the thread pointer to the beginning of the
688 thread descriptor. It has to be subtracted due to implementation
689 quirks in libthread_db. */
690 *base
= (void *) ((char *)*base
- idx
);
696 mips_collect_register (struct regcache
*regcache
,
697 int use_64bit
, int regno
, union mips_register
*reg
)
699 union mips_register tmp_reg
;
703 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
708 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
709 reg
->reg64
= tmp_reg
.reg32
;
714 mips_supply_register (struct regcache
*regcache
,
715 int use_64bit
, int regno
, const union mips_register
*reg
)
719 /* For big-endian 32-bit targets, ignore the high four bytes of each
721 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
724 supply_register (regcache
, regno
, reg
->buf
+ offset
);
727 #ifdef HAVE_PTRACE_GETREGS
730 mips_collect_register_32bit (struct regcache
*regcache
,
731 int use_64bit
, int regno
, unsigned char *buf
)
733 union mips_register tmp_reg
;
736 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
737 reg32
= tmp_reg
.reg64
;
738 memcpy (buf
, ®32
, 4);
742 mips_supply_register_32bit (struct regcache
*regcache
,
743 int use_64bit
, int regno
, const unsigned char *buf
)
745 union mips_register tmp_reg
;
748 memcpy (®32
, buf
, 4);
749 tmp_reg
.reg64
= reg32
;
750 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
754 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
756 union mips_register
*regset
= (union mips_register
*) buf
;
758 const struct target_desc
*tdesc
= regcache
->tdesc
;
760 use_64bit
= (register_size (tdesc
, 0) == 8);
762 for (i
= 1; i
< 32; i
++)
763 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
765 mips_collect_register (regcache
, use_64bit
,
766 find_regno (tdesc
, "lo"), regset
+ 32);
767 mips_collect_register (regcache
, use_64bit
,
768 find_regno (tdesc
, "hi"), regset
+ 33);
769 mips_collect_register (regcache
, use_64bit
,
770 find_regno (tdesc
, "pc"), regset
+ 34);
771 mips_collect_register (regcache
, use_64bit
,
772 find_regno (tdesc
, "badvaddr"), regset
+ 35);
773 mips_collect_register (regcache
, use_64bit
,
774 find_regno (tdesc
, "status"), regset
+ 36);
775 mips_collect_register (regcache
, use_64bit
,
776 find_regno (tdesc
, "cause"), regset
+ 37);
778 mips_collect_register (regcache
, use_64bit
,
779 find_regno (tdesc
, "restart"), regset
+ 0);
783 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
785 const union mips_register
*regset
= (const union mips_register
*) buf
;
788 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
790 supply_register_by_name_zeroed (regcache
, "r0");
792 for (i
= 1; i
< 32; i
++)
793 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
795 mips_supply_register (regcache
, use_64bit
,
796 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
797 mips_supply_register (regcache
, use_64bit
,
798 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
799 mips_supply_register (regcache
, use_64bit
,
800 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
801 mips_supply_register (regcache
, use_64bit
,
802 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
803 mips_supply_register (regcache
, use_64bit
,
804 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
805 mips_supply_register (regcache
, use_64bit
,
806 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
808 mips_supply_register (regcache
, use_64bit
,
809 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
813 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
815 union mips_register
*regset
= (union mips_register
*) buf
;
816 int i
, use_64bit
, first_fp
, big_endian
;
818 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
819 first_fp
= find_regno (regcache
->tdesc
, "f0");
820 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
822 /* See GDB for a discussion of this peculiar layout. */
823 for (i
= 0; i
< 32; i
++)
825 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
827 collect_register (regcache
, first_fp
+ i
,
828 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
830 mips_collect_register_32bit (regcache
, use_64bit
,
831 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
832 mips_collect_register_32bit (regcache
, use_64bit
,
833 find_regno (regcache
->tdesc
, "fir"),
838 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
840 const union mips_register
*regset
= (const union mips_register
*) buf
;
841 int i
, use_64bit
, first_fp
, big_endian
;
843 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
844 first_fp
= find_regno (regcache
->tdesc
, "f0");
845 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
847 /* See GDB for a discussion of this peculiar layout. */
848 for (i
= 0; i
< 32; i
++)
850 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
852 supply_register (regcache
, first_fp
+ i
,
853 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
855 mips_supply_register_32bit (regcache
, use_64bit
,
856 find_regno (regcache
->tdesc
, "fcsr"),
858 mips_supply_register_32bit (regcache
, use_64bit
,
859 find_regno (regcache
->tdesc
, "fir"),
862 #endif /* HAVE_PTRACE_GETREGS */
864 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
867 mips_collect_ptrace_register (struct regcache
*regcache
,
868 int regno
, char *buf
)
870 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
872 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
874 union mips_register reg
;
876 mips_collect_register (regcache
, 0, regno
, ®
);
877 memcpy (buf
, ®
, sizeof (reg
));
880 collect_register (regcache
, regno
, buf
);
883 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
886 mips_supply_ptrace_register (struct regcache
*regcache
,
887 int regno
, const char *buf
)
889 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
891 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
893 union mips_register reg
;
895 memcpy (®
, buf
, sizeof (reg
));
896 mips_supply_register (regcache
, 0, regno
, ®
);
899 supply_register (regcache
, regno
, buf
);
902 static struct regset_info mips_regsets
[] = {
903 #ifdef HAVE_PTRACE_GETREGS
904 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
905 mips_fill_gregset
, mips_store_gregset
},
906 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
907 mips_fill_fpregset
, mips_store_fpregset
},
908 #endif /* HAVE_PTRACE_GETREGS */
912 static struct regsets_info mips_regsets_info
=
914 mips_regsets
, /* regsets */
916 NULL
, /* disabled_regsets */
919 static struct usrregs_info mips_dsp_usrregs_info
=
925 static struct usrregs_info mips_usrregs_info
=
931 static struct regs_info dsp_regs_info
=
933 mips_dsp_regset_bitmap
,
934 &mips_dsp_usrregs_info
,
938 static struct regs_info regs_info
=
940 NULL
, /* regset_bitmap */
945 static const struct regs_info
*
946 mips_regs_info (void)
949 return &dsp_regs_info
;
954 struct linux_target_ops the_low_target
= {
956 mips_cannot_fetch_register
,
957 mips_cannot_store_register
,
961 NULL
, /* breakpoint_kind_from_pc */
962 mips_sw_breakpoint_from_kind
,
963 NULL
, /* get_next_pcs */
966 mips_supports_z_point_type
,
969 mips_stopped_by_watchpoint
,
970 mips_stopped_data_address
,
971 mips_collect_ptrace_register
,
972 mips_supply_ptrace_register
,
973 NULL
, /* siginfo_fixup */
974 mips_linux_new_process
,
975 mips_linux_delete_process
,
976 mips_linux_new_thread
,
977 mips_linux_delete_thread
,
979 mips_linux_prepare_to_resume
982 /* The linux target ops object. */
984 linux_process_target
*the_linux_target
= &the_mips_target
;
987 initialize_low_arch (void)
989 /* Initialize the Linux target descriptions. */
990 init_registers_mips_linux ();
991 init_registers_mips_dsp_linux ();
992 init_registers_mips64_linux ();
993 init_registers_mips64_dsp_linux ();
995 initialize_regsets_info (&mips_regsets_info
);