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
;
40 void low_arch_setup () override
;
42 bool low_cannot_fetch_register (int regno
) override
;
44 bool low_cannot_store_register (int regno
) override
;
46 bool low_fetch_register (regcache
*regcache
, int regno
) override
;
48 bool low_supports_breakpoints () override
;
50 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
52 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
54 bool low_breakpoint_at (CORE_ADDR pc
) override
;
57 /* The singleton target ops object. */
59 static mips_target the_mips_target
;
61 /* Defined in auto-generated file mips-linux.c. */
62 void init_registers_mips_linux (void);
63 extern const struct target_desc
*tdesc_mips_linux
;
65 /* Defined in auto-generated file mips-dsp-linux.c. */
66 void init_registers_mips_dsp_linux (void);
67 extern const struct target_desc
*tdesc_mips_dsp_linux
;
69 /* Defined in auto-generated file mips64-linux.c. */
70 void init_registers_mips64_linux (void);
71 extern const struct target_desc
*tdesc_mips64_linux
;
73 /* Defined in auto-generated file mips64-dsp-linux.c. */
74 void init_registers_mips64_dsp_linux (void);
75 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
78 #define tdesc_mips_linux tdesc_mips64_linux
79 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
82 #ifndef PTRACE_GET_THREAD_AREA
83 #define PTRACE_GET_THREAD_AREA 25
90 #define mips_num_regs 73
91 #define mips_dsp_num_regs 80
93 #include <asm/ptrace.h>
97 #define DSP_CONTROL 77
102 unsigned char buf
[8];
104 /* Deliberately signed, for proper sign extension. */
109 /* Return the ptrace ``address'' of register REGNO. */
111 #define mips_base_regs \
112 -1, 1, 2, 3, 4, 5, 6, 7, \
113 8, 9, 10, 11, 12, 13, 14, 15, \
114 16, 17, 18, 19, 20, 21, 22, 23, \
115 24, 25, 26, 27, 28, 29, 30, 31, \
117 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
119 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
120 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
121 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
122 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
123 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
124 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
125 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
126 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
129 #define mips_dsp_regs \
130 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
131 DSP_BASE + 4, DSP_BASE + 5, \
134 static int mips_regmap
[mips_num_regs
] = {
139 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
145 /* DSP registers are not in any regset and can only be accessed
148 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
149 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
152 static int have_dsp
= -1;
154 /* Try peeking at an arbitrarily chosen DSP register and pick the available
155 user register set accordingly. */
157 static const struct target_desc
*
158 mips_read_description (void)
162 int pid
= lwpid_of (current_thread
);
165 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
175 perror_with_name ("ptrace");
180 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
184 mips_target::low_arch_setup ()
186 current_process ()->tdesc
= mips_read_description ();
189 /* Per-process arch-specific data we want to keep. */
191 struct arch_process_info
193 /* -1 if the kernel and/or CPU do not support watch registers.
194 1 if watch_readback is valid and we can read style, num_valid
196 0 if we need to read the watch_readback. */
198 int watch_readback_valid
;
200 /* Cached watch register read values. */
202 struct pt_watch_regs watch_readback
;
204 /* Current watchpoint requests for this process. */
206 struct mips_watchpoint
*current_watches
;
208 /* The current set of watch register values for writing the
211 struct pt_watch_regs watch_mirror
;
214 /* Per-thread arch-specific data we want to keep. */
218 /* Non-zero if our copy differs from what's recorded in the thread. */
219 int watch_registers_changed
;
222 /* From mips-linux-nat.c. */
224 /* Pseudo registers can not be read. ptrace does not provide a way to
225 read (or set) PS_REGNUM, and there's no point in reading or setting
226 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
227 or FCRIR via ptrace(). */
230 mips_target::low_cannot_fetch_register (int regno
)
232 const struct target_desc
*tdesc
;
234 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
237 tdesc
= current_process ()->tdesc
;
239 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
240 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
243 if (find_regno (tdesc
, "r0") == regno
)
250 mips_target::low_cannot_store_register (int regno
)
252 const struct target_desc
*tdesc
;
254 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
257 tdesc
= current_process ()->tdesc
;
259 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
260 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
263 if (find_regno (tdesc
, "r0") == regno
)
266 if (find_regno (tdesc
, "cause") == regno
)
269 if (find_regno (tdesc
, "badvaddr") == regno
)
272 if (find_regno (tdesc
, "fir") == regno
)
279 mips_target::low_fetch_register (regcache
*regcache
, int regno
)
281 const struct target_desc
*tdesc
= current_process ()->tdesc
;
283 if (find_regno (tdesc
, "r0") == regno
)
285 supply_register_zeroed (regcache
, regno
);
293 mips_target::low_supports_breakpoints ()
299 mips_target::low_get_pc (regcache
*regcache
)
301 union mips_register pc
;
302 collect_register_by_name (regcache
, "pc", pc
.buf
);
303 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
307 mips_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
309 union mips_register newpc
;
310 if (register_size (regcache
->tdesc
, 0) == 4)
315 supply_register_by_name (regcache
, "pc", newpc
.buf
);
318 /* Correct in either endianness. */
319 static const unsigned int mips_breakpoint
= 0x0005000d;
320 #define mips_breakpoint_len 4
322 /* Implementation of target ops method "sw_breakpoint_from_kind". */
325 mips_target::sw_breakpoint_from_kind (int kind
, int *size
)
327 *size
= mips_breakpoint_len
;
328 return (const gdb_byte
*) &mips_breakpoint
;
332 mips_target::low_breakpoint_at (CORE_ADDR where
)
336 read_memory (where
, (unsigned char *) &insn
, 4);
337 if (insn
== mips_breakpoint
)
340 /* If necessary, recognize more trap instructions here. GDB only uses the
345 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
348 update_watch_registers_callback (thread_info
*thread
)
350 struct lwp_info
*lwp
= get_thread_lwp (thread
);
352 /* The actual update is done later just before resuming the lwp,
353 we just mark that the registers need updating. */
354 lwp
->arch_private
->watch_registers_changed
= 1;
356 /* If the lwp isn't stopped, force it to momentarily pause, so
357 we can update its watch registers. */
359 linux_stop_lwp (lwp
);
362 /* This is the implementation of linux_target_ops method
365 static struct arch_process_info
*
366 mips_linux_new_process (void)
368 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
373 /* This is the implementation of linux_target_ops method
377 mips_linux_delete_process (struct arch_process_info
*info
)
382 /* This is the implementation of linux_target_ops method new_thread.
383 Mark the watch registers as changed, so the threads' copies will
387 mips_linux_new_thread (struct lwp_info
*lwp
)
389 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
391 info
->watch_registers_changed
= 1;
393 lwp
->arch_private
= info
;
396 /* Function to call when a thread is being deleted. */
399 mips_linux_delete_thread (struct arch_lwp_info
*arch_lwp
)
404 /* Create a new mips_watchpoint and add it to the list. */
407 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
408 enum target_hw_bp_type watch_type
)
410 struct mips_watchpoint
*new_watch
;
411 struct mips_watchpoint
**pw
;
413 new_watch
= XNEW (struct mips_watchpoint
);
414 new_watch
->addr
= addr
;
415 new_watch
->len
= len
;
416 new_watch
->type
= watch_type
;
417 new_watch
->next
= NULL
;
419 pw
= &priv
->current_watches
;
425 /* Hook to call when a new fork is attached. */
428 mips_linux_new_fork (struct process_info
*parent
,
429 struct process_info
*child
)
431 struct arch_process_info
*parent_private
;
432 struct arch_process_info
*child_private
;
433 struct mips_watchpoint
*wp
;
435 /* These are allocated by linux_add_process. */
436 gdb_assert (parent
->priv
!= NULL
437 && parent
->priv
->arch_private
!= NULL
);
438 gdb_assert (child
->priv
!= NULL
439 && child
->priv
->arch_private
!= NULL
);
441 /* Linux kernel before 2.6.33 commit
442 72f674d203cd230426437cdcf7dd6f681dad8b0d
443 will inherit hardware debug registers from parent
444 on fork/vfork/clone. Newer Linux kernels create such tasks with
445 zeroed debug registers.
447 GDB core assumes the child inherits the watchpoints/hw
448 breakpoints of the parent, and will remove them all from the
449 forked off process. Copy the debug registers mirrors into the
450 new process so that all breakpoints and watchpoints can be
451 removed together. The debug registers mirror will become zeroed
452 in the end before detaching the forked off process, thus making
453 this compatible with older Linux kernels too. */
455 parent_private
= parent
->priv
->arch_private
;
456 child_private
= child
->priv
->arch_private
;
458 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
459 child_private
->watch_readback
= parent_private
->watch_readback
;
461 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
462 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
464 child_private
->watch_mirror
= parent_private
->watch_mirror
;
466 /* This is the implementation of linux_target_ops method
467 prepare_to_resume. If the watch regs have changed, update the
471 mips_linux_prepare_to_resume (struct lwp_info
*lwp
)
473 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
474 struct process_info
*proc
= find_process_pid (ptid
.pid ());
475 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
477 if (lwp
->arch_private
->watch_registers_changed
)
479 /* Only update the watch registers if we have set or unset a
480 watchpoint already. */
481 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
483 /* Write the mirrored watch register values. */
484 int tid
= ptid
.lwp ();
486 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
487 &priv
->watch_mirror
, NULL
))
488 perror_with_name ("Couldn't write watch register");
491 lwp
->arch_private
->watch_registers_changed
= 0;
496 mips_supports_z_point_type (char z_type
)
500 case Z_PACKET_WRITE_WP
:
501 case Z_PACKET_READ_WP
:
502 case Z_PACKET_ACCESS_WP
:
509 /* This is the implementation of linux_target_ops method
513 mips_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
514 int len
, struct raw_breakpoint
*bp
)
516 struct process_info
*proc
= current_process ();
517 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
518 struct pt_watch_regs regs
;
520 enum target_hw_bp_type watch_type
;
523 lwpid
= lwpid_of (current_thread
);
524 if (!mips_linux_read_watch_registers (lwpid
,
525 &priv
->watch_readback
,
526 &priv
->watch_readback_valid
,
533 regs
= priv
->watch_readback
;
534 /* Add the current watches. */
535 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
537 /* Now try to add the new watch. */
538 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
539 irw
= mips_linux_watch_type_to_irw (watch_type
);
540 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
543 /* It fit. Stick it on the end of the list. */
544 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
546 priv
->watch_mirror
= regs
;
548 /* Only update the threads of this process. */
549 for_each_thread (proc
->pid
, update_watch_registers_callback
);
554 /* This is the implementation of linux_target_ops method
558 mips_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
559 int len
, struct raw_breakpoint
*bp
)
561 struct process_info
*proc
= current_process ();
562 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
565 enum target_hw_bp_type watch_type
;
567 struct mips_watchpoint
**pw
;
568 struct mips_watchpoint
*w
;
570 /* Search for a known watch that matches. Then unlink and free it. */
571 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
573 pw
= &priv
->current_watches
;
576 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
587 return -1; /* We don't know about it, fail doing nothing. */
589 /* At this point watch_readback is known to be valid because we
590 could not have added the watch without reading it. */
591 gdb_assert (priv
->watch_readback_valid
== 1);
593 priv
->watch_mirror
= priv
->watch_readback
;
594 mips_linux_watch_populate_regs (priv
->current_watches
,
595 &priv
->watch_mirror
);
597 /* Only update the threads of this process. */
598 for_each_thread (proc
->pid
, update_watch_registers_callback
);
603 /* This is the implementation of linux_target_ops method
604 stopped_by_watchpoint. The watchhi R and W bits indicate
605 the watch register triggered. */
608 mips_stopped_by_watchpoint (void)
610 struct process_info
*proc
= current_process ();
611 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
614 long lwpid
= lwpid_of (current_thread
);
616 if (!mips_linux_read_watch_registers (lwpid
,
617 &priv
->watch_readback
,
618 &priv
->watch_readback_valid
,
622 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
624 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
625 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
632 /* This is the implementation of linux_target_ops method
633 stopped_data_address. */
636 mips_stopped_data_address (void)
638 struct process_info
*proc
= current_process ();
639 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
642 long lwpid
= lwpid_of (current_thread
);
644 /* On MIPS we don't know the low order 3 bits of the data address.
645 GDB does not support remote targets that can't report the
646 watchpoint address. So, make our best guess; return the starting
647 address of a watchpoint request which overlaps the one that
650 if (!mips_linux_read_watch_registers (lwpid
,
651 &priv
->watch_readback
,
652 &priv
->watch_readback_valid
,
656 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
658 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
659 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
662 CORE_ADDR t_low
, t_hi
;
664 struct mips_watchpoint
*watch
;
666 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
667 t_irw
= t_low
& IRW_MASK
;
668 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
670 t_low
&= ~(CORE_ADDR
)t_hi
;
672 for (watch
= priv
->current_watches
;
676 CORE_ADDR addr
= watch
->addr
;
677 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
679 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
681 /* Different type. */
684 /* Check for overlap of even a single byte. */
685 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
690 /* Shouldn't happen. */
694 /* Fetch the thread-local storage pointer for libthread_db. */
697 ps_get_thread_area (struct ps_prochandle
*ph
,
698 lwpid_t lwpid
, int idx
, void **base
)
700 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
703 /* IDX is the bias from the thread pointer to the beginning of the
704 thread descriptor. It has to be subtracted due to implementation
705 quirks in libthread_db. */
706 *base
= (void *) ((char *)*base
- idx
);
712 mips_collect_register (struct regcache
*regcache
,
713 int use_64bit
, int regno
, union mips_register
*reg
)
715 union mips_register tmp_reg
;
719 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
724 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
725 reg
->reg64
= tmp_reg
.reg32
;
730 mips_supply_register (struct regcache
*regcache
,
731 int use_64bit
, int regno
, const union mips_register
*reg
)
735 /* For big-endian 32-bit targets, ignore the high four bytes of each
737 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
740 supply_register (regcache
, regno
, reg
->buf
+ offset
);
743 #ifdef HAVE_PTRACE_GETREGS
746 mips_collect_register_32bit (struct regcache
*regcache
,
747 int use_64bit
, int regno
, unsigned char *buf
)
749 union mips_register tmp_reg
;
752 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
753 reg32
= tmp_reg
.reg64
;
754 memcpy (buf
, ®32
, 4);
758 mips_supply_register_32bit (struct regcache
*regcache
,
759 int use_64bit
, int regno
, const unsigned char *buf
)
761 union mips_register tmp_reg
;
764 memcpy (®32
, buf
, 4);
765 tmp_reg
.reg64
= reg32
;
766 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
770 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
772 union mips_register
*regset
= (union mips_register
*) buf
;
774 const struct target_desc
*tdesc
= regcache
->tdesc
;
776 use_64bit
= (register_size (tdesc
, 0) == 8);
778 for (i
= 1; i
< 32; i
++)
779 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
781 mips_collect_register (regcache
, use_64bit
,
782 find_regno (tdesc
, "lo"), regset
+ 32);
783 mips_collect_register (regcache
, use_64bit
,
784 find_regno (tdesc
, "hi"), regset
+ 33);
785 mips_collect_register (regcache
, use_64bit
,
786 find_regno (tdesc
, "pc"), regset
+ 34);
787 mips_collect_register (regcache
, use_64bit
,
788 find_regno (tdesc
, "badvaddr"), regset
+ 35);
789 mips_collect_register (regcache
, use_64bit
,
790 find_regno (tdesc
, "status"), regset
+ 36);
791 mips_collect_register (regcache
, use_64bit
,
792 find_regno (tdesc
, "cause"), regset
+ 37);
794 mips_collect_register (regcache
, use_64bit
,
795 find_regno (tdesc
, "restart"), regset
+ 0);
799 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
801 const union mips_register
*regset
= (const union mips_register
*) buf
;
804 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
806 supply_register_by_name_zeroed (regcache
, "r0");
808 for (i
= 1; i
< 32; i
++)
809 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
811 mips_supply_register (regcache
, use_64bit
,
812 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
813 mips_supply_register (regcache
, use_64bit
,
814 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
815 mips_supply_register (regcache
, use_64bit
,
816 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
817 mips_supply_register (regcache
, use_64bit
,
818 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
819 mips_supply_register (regcache
, use_64bit
,
820 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
821 mips_supply_register (regcache
, use_64bit
,
822 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
824 mips_supply_register (regcache
, use_64bit
,
825 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
829 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
831 union mips_register
*regset
= (union mips_register
*) buf
;
832 int i
, use_64bit
, first_fp
, big_endian
;
834 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
835 first_fp
= find_regno (regcache
->tdesc
, "f0");
836 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
838 /* See GDB for a discussion of this peculiar layout. */
839 for (i
= 0; i
< 32; i
++)
841 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
843 collect_register (regcache
, first_fp
+ i
,
844 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
846 mips_collect_register_32bit (regcache
, use_64bit
,
847 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
848 mips_collect_register_32bit (regcache
, use_64bit
,
849 find_regno (regcache
->tdesc
, "fir"),
854 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
856 const union mips_register
*regset
= (const union mips_register
*) buf
;
857 int i
, use_64bit
, first_fp
, big_endian
;
859 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
860 first_fp
= find_regno (regcache
->tdesc
, "f0");
861 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
863 /* See GDB for a discussion of this peculiar layout. */
864 for (i
= 0; i
< 32; i
++)
866 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
868 supply_register (regcache
, first_fp
+ i
,
869 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
871 mips_supply_register_32bit (regcache
, use_64bit
,
872 find_regno (regcache
->tdesc
, "fcsr"),
874 mips_supply_register_32bit (regcache
, use_64bit
,
875 find_regno (regcache
->tdesc
, "fir"),
878 #endif /* HAVE_PTRACE_GETREGS */
880 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
883 mips_collect_ptrace_register (struct regcache
*regcache
,
884 int regno
, char *buf
)
886 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
888 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
890 union mips_register reg
;
892 mips_collect_register (regcache
, 0, regno
, ®
);
893 memcpy (buf
, ®
, sizeof (reg
));
896 collect_register (regcache
, regno
, buf
);
899 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
902 mips_supply_ptrace_register (struct regcache
*regcache
,
903 int regno
, const char *buf
)
905 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
907 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
909 union mips_register reg
;
911 memcpy (®
, buf
, sizeof (reg
));
912 mips_supply_register (regcache
, 0, regno
, ®
);
915 supply_register (regcache
, regno
, buf
);
918 static struct regset_info mips_regsets
[] = {
919 #ifdef HAVE_PTRACE_GETREGS
920 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
921 mips_fill_gregset
, mips_store_gregset
},
922 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
923 mips_fill_fpregset
, mips_store_fpregset
},
924 #endif /* HAVE_PTRACE_GETREGS */
928 static struct regsets_info mips_regsets_info
=
930 mips_regsets
, /* regsets */
932 NULL
, /* disabled_regsets */
935 static struct usrregs_info mips_dsp_usrregs_info
=
941 static struct usrregs_info mips_usrregs_info
=
947 static struct regs_info dsp_regs_info
=
949 mips_dsp_regset_bitmap
,
950 &mips_dsp_usrregs_info
,
954 static struct regs_info myregs_info
=
956 NULL
, /* regset_bitmap */
962 mips_target::get_regs_info ()
965 return &dsp_regs_info
;
970 struct linux_target_ops the_low_target
= {
971 mips_supports_z_point_type
,
974 mips_stopped_by_watchpoint
,
975 mips_stopped_data_address
,
976 mips_collect_ptrace_register
,
977 mips_supply_ptrace_register
,
978 NULL
, /* siginfo_fixup */
979 mips_linux_new_process
,
980 mips_linux_delete_process
,
981 mips_linux_new_thread
,
982 mips_linux_delete_thread
,
984 mips_linux_prepare_to_resume
987 /* The linux target ops object. */
989 linux_process_target
*the_linux_target
= &the_mips_target
;
992 initialize_low_arch (void)
994 /* Initialize the Linux target descriptions. */
995 init_registers_mips_linux ();
996 init_registers_mips_dsp_linux ();
997 init_registers_mips64_linux ();
998 init_registers_mips64_dsp_linux ();
1000 initialize_regsets_info (&mips_regsets_info
);