1 /* GNU/Linux/MIPS specific low level interface, for the remote server for GDB.
2 Copyright (C) 1995-2024 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/>. */
19 #include "linux-low.h"
21 #include "nat/gdb_ptrace.h"
24 #include "nat/mips-linux-watch.h"
25 #include "gdb_proc_service.h"
27 /* Linux target op definitions for the MIPS architecture. */
29 class mips_target
: public linux_process_target
33 const regs_info
*get_regs_info () override
;
35 const gdb_byte
*sw_breakpoint_from_kind (int kind
, int *size
) override
;
37 bool supports_z_point_type (char z_type
) override
;
41 void low_arch_setup () override
;
43 bool low_cannot_fetch_register (int regno
) override
;
45 bool low_cannot_store_register (int regno
) override
;
47 bool low_fetch_register (regcache
*regcache
, int regno
) override
;
49 bool low_supports_breakpoints () override
;
51 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
53 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
55 bool low_breakpoint_at (CORE_ADDR pc
) override
;
57 int low_insert_point (raw_bkpt_type type
, CORE_ADDR addr
,
58 int size
, raw_breakpoint
*bp
) override
;
60 int low_remove_point (raw_bkpt_type type
, CORE_ADDR addr
,
61 int size
, raw_breakpoint
*bp
) override
;
63 bool low_stopped_by_watchpoint () override
;
65 CORE_ADDR
low_stopped_data_address () override
;
67 void low_collect_ptrace_register (regcache
*regcache
, int regno
,
70 void low_supply_ptrace_register (regcache
*regcache
, int regno
,
71 const char *buf
) override
;
73 arch_process_info
*low_new_process () override
;
75 void low_delete_process (arch_process_info
*info
) override
;
77 void low_new_thread (lwp_info
*) override
;
79 void low_delete_thread (arch_lwp_info
*) override
;
81 void low_new_fork (process_info
*parent
, process_info
*child
) override
;
83 void low_prepare_to_resume (lwp_info
*lwp
) override
;
86 /* The singleton target ops object. */
88 static mips_target the_mips_target
;
90 /* Defined in auto-generated file mips-linux.c. */
91 void init_registers_mips_linux (void);
92 extern const struct target_desc
*tdesc_mips_linux
;
94 /* Defined in auto-generated file mips-dsp-linux.c. */
95 void init_registers_mips_dsp_linux (void);
96 extern const struct target_desc
*tdesc_mips_dsp_linux
;
98 /* Defined in auto-generated file mips64-linux.c. */
99 void init_registers_mips64_linux (void);
100 extern const struct target_desc
*tdesc_mips64_linux
;
102 /* Defined in auto-generated file mips64-dsp-linux.c. */
103 void init_registers_mips64_dsp_linux (void);
104 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
107 #define tdesc_mips_linux tdesc_mips64_linux
108 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
111 #ifndef PTRACE_GET_THREAD_AREA
112 #define PTRACE_GET_THREAD_AREA 25
115 #ifdef HAVE_SYS_REG_H
119 #define mips_num_regs 73
120 #define mips_dsp_num_regs 80
122 #include <asm/ptrace.h>
126 #define DSP_CONTROL 77
131 unsigned char buf
[8];
133 /* Deliberately signed, for proper sign extension. */
138 /* Return the ptrace ``address'' of register REGNO. */
140 #define mips_base_regs \
141 -1, 1, 2, 3, 4, 5, 6, 7, \
142 8, 9, 10, 11, 12, 13, 14, 15, \
143 16, 17, 18, 19, 20, 21, 22, 23, \
144 24, 25, 26, 27, 28, 29, 30, 31, \
146 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
148 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
149 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
150 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
151 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
152 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
153 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
154 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
155 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
158 #define mips_dsp_regs \
159 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
160 DSP_BASE + 4, DSP_BASE + 5, \
163 static int mips_regmap
[mips_num_regs
] = {
168 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
174 /* DSP registers are not in any regset and can only be accessed
177 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
178 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
181 static int have_dsp
= -1;
183 /* Try peeking at an arbitrarily chosen DSP register and pick the available
184 user register set accordingly. */
186 static const struct target_desc
*
187 mips_read_description (void)
191 int pid
= lwpid_of (current_thread
);
194 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
204 perror_with_name ("ptrace");
209 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
213 mips_target::low_arch_setup ()
215 current_process ()->tdesc
= mips_read_description ();
218 /* Per-process arch-specific data we want to keep. */
220 struct arch_process_info
222 /* -1 if the kernel and/or CPU do not support watch registers.
223 1 if watch_readback is valid and we can read style, num_valid
225 0 if we need to read the watch_readback. */
227 int watch_readback_valid
;
229 /* Cached watch register read values. */
231 struct pt_watch_regs watch_readback
;
233 /* Current watchpoint requests for this process. */
235 struct mips_watchpoint
*current_watches
;
237 /* The current set of watch register values for writing the
240 struct pt_watch_regs watch_mirror
;
243 /* Per-thread arch-specific data we want to keep. */
247 /* Non-zero if our copy differs from what's recorded in the thread. */
248 int watch_registers_changed
;
251 /* From mips-linux-nat.c. */
253 /* Pseudo registers can not be read. ptrace does not provide a way to
254 read (or set) PS_REGNUM, and there's no point in reading or setting
255 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
256 or FCRIR via ptrace(). */
259 mips_target::low_cannot_fetch_register (int regno
)
261 const struct target_desc
*tdesc
;
263 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
266 tdesc
= current_process ()->tdesc
;
268 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
269 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
272 if (find_regno (tdesc
, "r0") == regno
)
279 mips_target::low_cannot_store_register (int regno
)
281 const struct target_desc
*tdesc
;
283 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
286 tdesc
= current_process ()->tdesc
;
288 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
289 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
292 if (find_regno (tdesc
, "r0") == regno
)
295 if (find_regno (tdesc
, "cause") == regno
)
298 if (find_regno (tdesc
, "badvaddr") == regno
)
301 if (find_regno (tdesc
, "fir") == regno
)
308 mips_target::low_fetch_register (regcache
*regcache
, int regno
)
310 const struct target_desc
*tdesc
= current_process ()->tdesc
;
312 if (find_regno (tdesc
, "r0") == regno
)
314 supply_register_zeroed (regcache
, regno
);
322 mips_target::low_supports_breakpoints ()
328 mips_target::low_get_pc (regcache
*regcache
)
330 union mips_register pc
;
331 collect_register_by_name (regcache
, "pc", pc
.buf
);
332 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
336 mips_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
338 union mips_register newpc
;
339 if (register_size (regcache
->tdesc
, 0) == 4)
344 supply_register_by_name (regcache
, "pc", newpc
.buf
);
347 /* Correct in either endianness. */
348 static const unsigned int mips_breakpoint
= 0x0005000d;
349 #define mips_breakpoint_len 4
351 /* Implementation of target ops method "sw_breakpoint_from_kind". */
354 mips_target::sw_breakpoint_from_kind (int kind
, int *size
)
356 *size
= mips_breakpoint_len
;
357 return (const gdb_byte
*) &mips_breakpoint
;
361 mips_target::low_breakpoint_at (CORE_ADDR where
)
365 read_memory (where
, (unsigned char *) &insn
, 4);
366 if (insn
== mips_breakpoint
)
369 /* If necessary, recognize more trap instructions here. GDB only uses the
374 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
377 update_watch_registers_callback (thread_info
*thread
)
379 struct lwp_info
*lwp
= get_thread_lwp (thread
);
381 /* The actual update is done later just before resuming the lwp,
382 we just mark that the registers need updating. */
383 lwp
->arch_private
->watch_registers_changed
= 1;
385 /* If the lwp isn't stopped, force it to momentarily pause, so
386 we can update its watch registers. */
388 linux_stop_lwp (lwp
);
391 /* This is the implementation of linux target ops method
395 mips_target::low_new_process ()
397 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
402 /* This is the implementation of linux target ops method
403 low_delete_process. */
406 mips_target::low_delete_process (arch_process_info
*info
)
411 /* This is the implementation of linux target ops method low_new_thread.
412 Mark the watch registers as changed, so the threads' copies will
416 mips_target::low_new_thread (lwp_info
*lwp
)
418 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
420 info
->watch_registers_changed
= 1;
422 lwp
->arch_private
= info
;
425 /* Function to call when a thread is being deleted. */
428 mips_target::low_delete_thread (arch_lwp_info
*arch_lwp
)
433 /* Create a new mips_watchpoint and add it to the list. */
436 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
437 enum target_hw_bp_type watch_type
)
439 struct mips_watchpoint
*new_watch
;
440 struct mips_watchpoint
**pw
;
442 new_watch
= XNEW (struct mips_watchpoint
);
443 new_watch
->addr
= addr
;
444 new_watch
->len
= len
;
445 new_watch
->type
= watch_type
;
446 new_watch
->next
= NULL
;
448 pw
= &priv
->current_watches
;
454 /* Hook to call when a new fork is attached. */
457 mips_target::low_new_fork (process_info
*parent
,
460 struct arch_process_info
*parent_private
;
461 struct arch_process_info
*child_private
;
462 struct mips_watchpoint
*wp
;
464 /* These are allocated by linux_add_process. */
465 gdb_assert (parent
->priv
!= NULL
466 && parent
->priv
->arch_private
!= NULL
);
467 gdb_assert (child
->priv
!= NULL
468 && child
->priv
->arch_private
!= NULL
);
470 /* Linux kernel before 2.6.33 commit
471 72f674d203cd230426437cdcf7dd6f681dad8b0d
472 will inherit hardware debug registers from parent
473 on fork/vfork/clone. Newer Linux kernels create such tasks with
474 zeroed debug registers.
476 GDB core assumes the child inherits the watchpoints/hw
477 breakpoints of the parent, and will remove them all from the
478 forked off process. Copy the debug registers mirrors into the
479 new process so that all breakpoints and watchpoints can be
480 removed together. The debug registers mirror will become zeroed
481 in the end before detaching the forked off process, thus making
482 this compatible with older Linux kernels too. */
484 parent_private
= parent
->priv
->arch_private
;
485 child_private
= child
->priv
->arch_private
;
487 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
488 child_private
->watch_readback
= parent_private
->watch_readback
;
490 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
491 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
493 child_private
->watch_mirror
= parent_private
->watch_mirror
;
495 /* This is the implementation of linux target ops method
496 low_prepare_to_resume. If the watch regs have changed, update the
500 mips_target::low_prepare_to_resume (lwp_info
*lwp
)
502 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
503 struct process_info
*proc
= find_process_pid (ptid
.pid ());
504 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
506 if (lwp
->arch_private
->watch_registers_changed
)
508 /* Only update the watch registers if we have set or unset a
509 watchpoint already. */
510 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
512 /* Write the mirrored watch register values. */
513 int tid
= ptid
.lwp ();
515 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
516 &priv
->watch_mirror
, NULL
))
517 perror_with_name ("Couldn't write watch register");
520 lwp
->arch_private
->watch_registers_changed
= 0;
525 mips_target::supports_z_point_type (char z_type
)
529 case Z_PACKET_WRITE_WP
:
530 case Z_PACKET_READ_WP
:
531 case Z_PACKET_ACCESS_WP
:
538 /* This is the implementation of linux target ops method
542 mips_target::low_insert_point (raw_bkpt_type type
, CORE_ADDR addr
,
543 int len
, raw_breakpoint
*bp
)
545 struct process_info
*proc
= current_process ();
546 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
547 struct pt_watch_regs regs
;
549 enum target_hw_bp_type watch_type
;
552 lwpid
= lwpid_of (current_thread
);
553 if (!mips_linux_read_watch_registers (lwpid
,
554 &priv
->watch_readback
,
555 &priv
->watch_readback_valid
,
562 regs
= priv
->watch_readback
;
563 /* Add the current watches. */
564 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
566 /* Now try to add the new watch. */
567 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
568 irw
= mips_linux_watch_type_to_irw (watch_type
);
569 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
572 /* It fit. Stick it on the end of the list. */
573 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
575 priv
->watch_mirror
= regs
;
577 /* Only update the threads of this process. */
578 for_each_thread (proc
->pid
, update_watch_registers_callback
);
583 /* This is the implementation of linux target ops method
587 mips_target::low_remove_point (raw_bkpt_type type
, CORE_ADDR addr
,
588 int len
, raw_breakpoint
*bp
)
590 struct process_info
*proc
= current_process ();
591 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
594 enum target_hw_bp_type watch_type
;
596 struct mips_watchpoint
**pw
;
597 struct mips_watchpoint
*w
;
599 /* Search for a known watch that matches. Then unlink and free it. */
600 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
602 pw
= &priv
->current_watches
;
605 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
616 return -1; /* We don't know about it, fail doing nothing. */
618 /* At this point watch_readback is known to be valid because we
619 could not have added the watch without reading it. */
620 gdb_assert (priv
->watch_readback_valid
== 1);
622 priv
->watch_mirror
= priv
->watch_readback
;
623 mips_linux_watch_populate_regs (priv
->current_watches
,
624 &priv
->watch_mirror
);
626 /* Only update the threads of this process. */
627 for_each_thread (proc
->pid
, update_watch_registers_callback
);
632 /* This is the implementation of linux target ops method
633 low_stopped_by_watchpoint. The watchhi R and W bits indicate
634 the watch register triggered. */
637 mips_target::low_stopped_by_watchpoint ()
639 struct process_info
*proc
= current_process ();
640 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
643 long lwpid
= lwpid_of (current_thread
);
645 if (!mips_linux_read_watch_registers (lwpid
,
646 &priv
->watch_readback
,
647 &priv
->watch_readback_valid
,
651 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
653 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
654 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
661 /* This is the implementation of linux target ops method
662 low_stopped_data_address. */
665 mips_target::low_stopped_data_address ()
667 struct process_info
*proc
= current_process ();
668 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
671 long lwpid
= lwpid_of (current_thread
);
673 /* On MIPS we don't know the low order 3 bits of the data address.
674 GDB does not support remote targets that can't report the
675 watchpoint address. So, make our best guess; return the starting
676 address of a watchpoint request which overlaps the one that
679 if (!mips_linux_read_watch_registers (lwpid
,
680 &priv
->watch_readback
,
681 &priv
->watch_readback_valid
,
685 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
687 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
688 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
691 CORE_ADDR t_low
, t_hi
;
693 struct mips_watchpoint
*watch
;
695 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
696 t_irw
= t_low
& IRW_MASK
;
697 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
699 t_low
&= ~(CORE_ADDR
)t_hi
;
701 for (watch
= priv
->current_watches
;
705 CORE_ADDR addr
= watch
->addr
;
706 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
708 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
710 /* Different type. */
713 /* Check for overlap of even a single byte. */
714 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
719 /* Shouldn't happen. */
723 /* Fetch the thread-local storage pointer for libthread_db. */
726 ps_get_thread_area (struct ps_prochandle
*ph
,
727 lwpid_t lwpid
, int idx
, void **base
)
729 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
732 /* IDX is the bias from the thread pointer to the beginning of the
733 thread descriptor. It has to be subtracted due to implementation
734 quirks in libthread_db. */
735 *base
= (void *) ((char *)*base
- idx
);
741 mips_collect_register (struct regcache
*regcache
,
742 int use_64bit
, int regno
, union mips_register
*reg
)
744 union mips_register tmp_reg
;
748 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
753 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
754 reg
->reg64
= tmp_reg
.reg32
;
759 mips_supply_register (struct regcache
*regcache
,
760 int use_64bit
, int regno
, const union mips_register
*reg
)
764 /* For big-endian 32-bit targets, ignore the high four bytes of each
766 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
769 supply_register (regcache
, regno
, reg
->buf
+ offset
);
772 #ifdef HAVE_PTRACE_GETREGS
775 mips_collect_register_32bit (struct regcache
*regcache
,
776 int use_64bit
, int regno
, unsigned char *buf
)
778 union mips_register tmp_reg
;
781 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
782 reg32
= tmp_reg
.reg64
;
783 memcpy (buf
, ®32
, 4);
787 mips_supply_register_32bit (struct regcache
*regcache
,
788 int use_64bit
, int regno
, const unsigned char *buf
)
790 union mips_register tmp_reg
;
793 memcpy (®32
, buf
, 4);
794 tmp_reg
.reg64
= reg32
;
795 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
799 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
801 union mips_register
*regset
= (union mips_register
*) buf
;
803 const struct target_desc
*tdesc
= regcache
->tdesc
;
805 use_64bit
= (register_size (tdesc
, 0) == 8);
807 for (i
= 1; i
< 32; i
++)
808 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
810 mips_collect_register (regcache
, use_64bit
,
811 find_regno (tdesc
, "lo"), regset
+ 32);
812 mips_collect_register (regcache
, use_64bit
,
813 find_regno (tdesc
, "hi"), regset
+ 33);
814 mips_collect_register (regcache
, use_64bit
,
815 find_regno (tdesc
, "pc"), regset
+ 34);
816 mips_collect_register (regcache
, use_64bit
,
817 find_regno (tdesc
, "badvaddr"), regset
+ 35);
818 mips_collect_register (regcache
, use_64bit
,
819 find_regno (tdesc
, "status"), regset
+ 36);
820 mips_collect_register (regcache
, use_64bit
,
821 find_regno (tdesc
, "cause"), regset
+ 37);
823 mips_collect_register (regcache
, use_64bit
,
824 find_regno (tdesc
, "restart"), regset
+ 0);
828 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
830 const union mips_register
*regset
= (const union mips_register
*) buf
;
833 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
835 supply_register_by_name_zeroed (regcache
, "r0");
837 for (i
= 1; i
< 32; i
++)
838 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
840 mips_supply_register (regcache
, use_64bit
,
841 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
842 mips_supply_register (regcache
, use_64bit
,
843 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
844 mips_supply_register (regcache
, use_64bit
,
845 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
846 mips_supply_register (regcache
, use_64bit
,
847 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
848 mips_supply_register (regcache
, use_64bit
,
849 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
850 mips_supply_register (regcache
, use_64bit
,
851 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
853 mips_supply_register (regcache
, use_64bit
,
854 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
858 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
860 union mips_register
*regset
= (union mips_register
*) buf
;
861 int i
, use_64bit
, first_fp
, big_endian
;
863 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
864 first_fp
= find_regno (regcache
->tdesc
, "f0");
865 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
867 /* See GDB for a discussion of this peculiar layout. */
868 for (i
= 0; i
< 32; i
++)
870 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
872 collect_register (regcache
, first_fp
+ i
,
873 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
875 mips_collect_register_32bit (regcache
, use_64bit
,
876 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
877 mips_collect_register_32bit (regcache
, use_64bit
,
878 find_regno (regcache
->tdesc
, "fir"),
883 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
885 const union mips_register
*regset
= (const union mips_register
*) buf
;
886 int i
, use_64bit
, first_fp
, big_endian
;
888 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
889 first_fp
= find_regno (regcache
->tdesc
, "f0");
890 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
892 /* See GDB for a discussion of this peculiar layout. */
893 for (i
= 0; i
< 32; i
++)
895 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
897 supply_register (regcache
, first_fp
+ i
,
898 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
900 mips_supply_register_32bit (regcache
, use_64bit
,
901 find_regno (regcache
->tdesc
, "fcsr"),
903 mips_supply_register_32bit (regcache
, use_64bit
,
904 find_regno (regcache
->tdesc
, "fir"),
907 #endif /* HAVE_PTRACE_GETREGS */
909 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
912 mips_target::low_collect_ptrace_register (regcache
*regcache
, int regno
,
915 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
917 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
919 union mips_register reg
;
921 mips_collect_register (regcache
, 0, regno
, ®
);
922 memcpy (buf
, ®
, sizeof (reg
));
925 collect_register (regcache
, regno
, buf
);
928 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
931 mips_target::low_supply_ptrace_register (regcache
*regcache
, int regno
,
934 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
936 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
938 union mips_register reg
;
940 memcpy (®
, buf
, sizeof (reg
));
941 mips_supply_register (regcache
, 0, regno
, ®
);
944 supply_register (regcache
, regno
, buf
);
947 static struct regset_info mips_regsets
[] = {
948 #ifdef HAVE_PTRACE_GETREGS
949 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
950 mips_fill_gregset
, mips_store_gregset
},
951 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
952 mips_fill_fpregset
, mips_store_fpregset
},
953 #endif /* HAVE_PTRACE_GETREGS */
957 static struct regsets_info mips_regsets_info
=
959 mips_regsets
, /* regsets */
961 NULL
, /* disabled_regsets */
964 static struct usrregs_info mips_dsp_usrregs_info
=
970 static struct usrregs_info mips_usrregs_info
=
976 static struct regs_info dsp_regs_info
=
978 mips_dsp_regset_bitmap
,
979 &mips_dsp_usrregs_info
,
983 static struct regs_info myregs_info
=
985 NULL
, /* regset_bitmap */
991 mips_target::get_regs_info ()
994 return &dsp_regs_info
;
999 /* The linux target ops object. */
1001 linux_process_target
*the_linux_target
= &the_mips_target
;
1004 initialize_low_arch (void)
1006 /* Initialize the Linux target descriptions. */
1007 init_registers_mips_linux ();
1008 init_registers_mips_dsp_linux ();
1009 init_registers_mips64_linux ();
1010 init_registers_mips64_dsp_linux ();
1012 initialize_regsets_info (&mips_regsets_info
);