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
;
55 /* The singleton target ops object. */
57 static mips_target the_mips_target
;
59 /* Defined in auto-generated file mips-linux.c. */
60 void init_registers_mips_linux (void);
61 extern const struct target_desc
*tdesc_mips_linux
;
63 /* Defined in auto-generated file mips-dsp-linux.c. */
64 void init_registers_mips_dsp_linux (void);
65 extern const struct target_desc
*tdesc_mips_dsp_linux
;
67 /* Defined in auto-generated file mips64-linux.c. */
68 void init_registers_mips64_linux (void);
69 extern const struct target_desc
*tdesc_mips64_linux
;
71 /* Defined in auto-generated file mips64-dsp-linux.c. */
72 void init_registers_mips64_dsp_linux (void);
73 extern const struct target_desc
*tdesc_mips64_dsp_linux
;
76 #define tdesc_mips_linux tdesc_mips64_linux
77 #define tdesc_mips_dsp_linux tdesc_mips64_dsp_linux
80 #ifndef PTRACE_GET_THREAD_AREA
81 #define PTRACE_GET_THREAD_AREA 25
88 #define mips_num_regs 73
89 #define mips_dsp_num_regs 80
91 #include <asm/ptrace.h>
95 #define DSP_CONTROL 77
100 unsigned char buf
[8];
102 /* Deliberately signed, for proper sign extension. */
107 /* Return the ptrace ``address'' of register REGNO. */
109 #define mips_base_regs \
110 -1, 1, 2, 3, 4, 5, 6, 7, \
111 8, 9, 10, 11, 12, 13, 14, 15, \
112 16, 17, 18, 19, 20, 21, 22, 23, \
113 24, 25, 26, 27, 28, 29, 30, 31, \
115 -1, MMLO, MMHI, BADVADDR, CAUSE, PC, \
117 FPR_BASE, FPR_BASE + 1, FPR_BASE + 2, FPR_BASE + 3, \
118 FPR_BASE + 4, FPR_BASE + 5, FPR_BASE + 6, FPR_BASE + 7, \
119 FPR_BASE + 8, FPR_BASE + 9, FPR_BASE + 10, FPR_BASE + 11, \
120 FPR_BASE + 12, FPR_BASE + 13, FPR_BASE + 14, FPR_BASE + 15, \
121 FPR_BASE + 16, FPR_BASE + 17, FPR_BASE + 18, FPR_BASE + 19, \
122 FPR_BASE + 20, FPR_BASE + 21, FPR_BASE + 22, FPR_BASE + 23, \
123 FPR_BASE + 24, FPR_BASE + 25, FPR_BASE + 26, FPR_BASE + 27, \
124 FPR_BASE + 28, FPR_BASE + 29, FPR_BASE + 30, FPR_BASE + 31, \
127 #define mips_dsp_regs \
128 DSP_BASE, DSP_BASE + 1, DSP_BASE + 2, DSP_BASE + 3, \
129 DSP_BASE + 4, DSP_BASE + 5, \
132 static int mips_regmap
[mips_num_regs
] = {
137 static int mips_dsp_regmap
[mips_dsp_num_regs
] = {
143 /* DSP registers are not in any regset and can only be accessed
146 static unsigned char mips_dsp_regset_bitmap
[(mips_dsp_num_regs
+ 7) / 8] = {
147 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x80
150 static int have_dsp
= -1;
152 /* Try peeking at an arbitrarily chosen DSP register and pick the available
153 user register set accordingly. */
155 static const struct target_desc
*
156 mips_read_description (void)
160 int pid
= lwpid_of (current_thread
);
163 ptrace (PTRACE_PEEKUSER
, pid
, DSP_CONTROL
, 0);
173 perror_with_name ("ptrace");
178 return have_dsp
? tdesc_mips_dsp_linux
: tdesc_mips_linux
;
182 mips_target::low_arch_setup ()
184 current_process ()->tdesc
= mips_read_description ();
187 /* Per-process arch-specific data we want to keep. */
189 struct arch_process_info
191 /* -1 if the kernel and/or CPU do not support watch registers.
192 1 if watch_readback is valid and we can read style, num_valid
194 0 if we need to read the watch_readback. */
196 int watch_readback_valid
;
198 /* Cached watch register read values. */
200 struct pt_watch_regs watch_readback
;
202 /* Current watchpoint requests for this process. */
204 struct mips_watchpoint
*current_watches
;
206 /* The current set of watch register values for writing the
209 struct pt_watch_regs watch_mirror
;
212 /* Per-thread arch-specific data we want to keep. */
216 /* Non-zero if our copy differs from what's recorded in the thread. */
217 int watch_registers_changed
;
220 /* From mips-linux-nat.c. */
222 /* Pseudo registers can not be read. ptrace does not provide a way to
223 read (or set) PS_REGNUM, and there's no point in reading or setting
224 ZERO_REGNUM, it's always 0. We also can not set BADVADDR, CAUSE,
225 or FCRIR via ptrace(). */
228 mips_target::low_cannot_fetch_register (int regno
)
230 const struct target_desc
*tdesc
;
232 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
235 tdesc
= current_process ()->tdesc
;
237 /* On n32 we can't access 64-bit registers via PTRACE_PEEKUSR. */
238 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
241 if (find_regno (tdesc
, "r0") == regno
)
248 mips_target::low_cannot_store_register (int regno
)
250 const struct target_desc
*tdesc
;
252 if (get_regs_info ()->usrregs
->regmap
[regno
] == -1)
255 tdesc
= current_process ()->tdesc
;
257 /* On n32 we can't access 64-bit registers via PTRACE_POKEUSR. */
258 if (register_size (tdesc
, regno
) > sizeof (PTRACE_XFER_TYPE
))
261 if (find_regno (tdesc
, "r0") == regno
)
264 if (find_regno (tdesc
, "cause") == regno
)
267 if (find_regno (tdesc
, "badvaddr") == regno
)
270 if (find_regno (tdesc
, "fir") == regno
)
277 mips_target::low_fetch_register (regcache
*regcache
, int regno
)
279 const struct target_desc
*tdesc
= current_process ()->tdesc
;
281 if (find_regno (tdesc
, "r0") == regno
)
283 supply_register_zeroed (regcache
, regno
);
291 mips_target::low_supports_breakpoints ()
297 mips_target::low_get_pc (regcache
*regcache
)
299 union mips_register pc
;
300 collect_register_by_name (regcache
, "pc", pc
.buf
);
301 return register_size (regcache
->tdesc
, 0) == 4 ? pc
.reg32
: pc
.reg64
;
305 mips_target::low_set_pc (regcache
*regcache
, CORE_ADDR pc
)
307 union mips_register newpc
;
308 if (register_size (regcache
->tdesc
, 0) == 4)
313 supply_register_by_name (regcache
, "pc", newpc
.buf
);
316 /* Correct in either endianness. */
317 static const unsigned int mips_breakpoint
= 0x0005000d;
318 #define mips_breakpoint_len 4
320 /* Implementation of target ops method "sw_breakpoint_from_kind". */
323 mips_target::sw_breakpoint_from_kind (int kind
, int *size
)
325 *size
= mips_breakpoint_len
;
326 return (const gdb_byte
*) &mips_breakpoint
;
330 mips_breakpoint_at (CORE_ADDR where
)
334 the_target
->read_memory (where
, (unsigned char *) &insn
, 4);
335 if (insn
== mips_breakpoint
)
338 /* If necessary, recognize more trap instructions here. GDB only uses the
343 /* Mark the watch registers of lwp, represented by ENTRY, as changed. */
346 update_watch_registers_callback (thread_info
*thread
)
348 struct lwp_info
*lwp
= get_thread_lwp (thread
);
350 /* The actual update is done later just before resuming the lwp,
351 we just mark that the registers need updating. */
352 lwp
->arch_private
->watch_registers_changed
= 1;
354 /* If the lwp isn't stopped, force it to momentarily pause, so
355 we can update its watch registers. */
357 linux_stop_lwp (lwp
);
360 /* This is the implementation of linux_target_ops method
363 static struct arch_process_info
*
364 mips_linux_new_process (void)
366 struct arch_process_info
*info
= XCNEW (struct arch_process_info
);
371 /* This is the implementation of linux_target_ops method
375 mips_linux_delete_process (struct arch_process_info
*info
)
380 /* This is the implementation of linux_target_ops method new_thread.
381 Mark the watch registers as changed, so the threads' copies will
385 mips_linux_new_thread (struct lwp_info
*lwp
)
387 struct arch_lwp_info
*info
= XCNEW (struct arch_lwp_info
);
389 info
->watch_registers_changed
= 1;
391 lwp
->arch_private
= info
;
394 /* Function to call when a thread is being deleted. */
397 mips_linux_delete_thread (struct arch_lwp_info
*arch_lwp
)
402 /* Create a new mips_watchpoint and add it to the list. */
405 mips_add_watchpoint (struct arch_process_info
*priv
, CORE_ADDR addr
, int len
,
406 enum target_hw_bp_type watch_type
)
408 struct mips_watchpoint
*new_watch
;
409 struct mips_watchpoint
**pw
;
411 new_watch
= XNEW (struct mips_watchpoint
);
412 new_watch
->addr
= addr
;
413 new_watch
->len
= len
;
414 new_watch
->type
= watch_type
;
415 new_watch
->next
= NULL
;
417 pw
= &priv
->current_watches
;
423 /* Hook to call when a new fork is attached. */
426 mips_linux_new_fork (struct process_info
*parent
,
427 struct process_info
*child
)
429 struct arch_process_info
*parent_private
;
430 struct arch_process_info
*child_private
;
431 struct mips_watchpoint
*wp
;
433 /* These are allocated by linux_add_process. */
434 gdb_assert (parent
->priv
!= NULL
435 && parent
->priv
->arch_private
!= NULL
);
436 gdb_assert (child
->priv
!= NULL
437 && child
->priv
->arch_private
!= NULL
);
439 /* Linux kernel before 2.6.33 commit
440 72f674d203cd230426437cdcf7dd6f681dad8b0d
441 will inherit hardware debug registers from parent
442 on fork/vfork/clone. Newer Linux kernels create such tasks with
443 zeroed debug registers.
445 GDB core assumes the child inherits the watchpoints/hw
446 breakpoints of the parent, and will remove them all from the
447 forked off process. Copy the debug registers mirrors into the
448 new process so that all breakpoints and watchpoints can be
449 removed together. The debug registers mirror will become zeroed
450 in the end before detaching the forked off process, thus making
451 this compatible with older Linux kernels too. */
453 parent_private
= parent
->priv
->arch_private
;
454 child_private
= child
->priv
->arch_private
;
456 child_private
->watch_readback_valid
= parent_private
->watch_readback_valid
;
457 child_private
->watch_readback
= parent_private
->watch_readback
;
459 for (wp
= parent_private
->current_watches
; wp
!= NULL
; wp
= wp
->next
)
460 mips_add_watchpoint (child_private
, wp
->addr
, wp
->len
, wp
->type
);
462 child_private
->watch_mirror
= parent_private
->watch_mirror
;
464 /* This is the implementation of linux_target_ops method
465 prepare_to_resume. If the watch regs have changed, update the
469 mips_linux_prepare_to_resume (struct lwp_info
*lwp
)
471 ptid_t ptid
= ptid_of (get_lwp_thread (lwp
));
472 struct process_info
*proc
= find_process_pid (ptid
.pid ());
473 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
475 if (lwp
->arch_private
->watch_registers_changed
)
477 /* Only update the watch registers if we have set or unset a
478 watchpoint already. */
479 if (mips_linux_watch_get_num_valid (&priv
->watch_mirror
) > 0)
481 /* Write the mirrored watch register values. */
482 int tid
= ptid
.lwp ();
484 if (-1 == ptrace (PTRACE_SET_WATCH_REGS
, tid
,
485 &priv
->watch_mirror
, NULL
))
486 perror_with_name ("Couldn't write watch register");
489 lwp
->arch_private
->watch_registers_changed
= 0;
494 mips_supports_z_point_type (char z_type
)
498 case Z_PACKET_WRITE_WP
:
499 case Z_PACKET_READ_WP
:
500 case Z_PACKET_ACCESS_WP
:
507 /* This is the implementation of linux_target_ops method
511 mips_insert_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
512 int len
, struct raw_breakpoint
*bp
)
514 struct process_info
*proc
= current_process ();
515 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
516 struct pt_watch_regs regs
;
518 enum target_hw_bp_type watch_type
;
521 lwpid
= lwpid_of (current_thread
);
522 if (!mips_linux_read_watch_registers (lwpid
,
523 &priv
->watch_readback
,
524 &priv
->watch_readback_valid
,
531 regs
= priv
->watch_readback
;
532 /* Add the current watches. */
533 mips_linux_watch_populate_regs (priv
->current_watches
, ®s
);
535 /* Now try to add the new watch. */
536 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
537 irw
= mips_linux_watch_type_to_irw (watch_type
);
538 if (!mips_linux_watch_try_one_watch (®s
, addr
, len
, irw
))
541 /* It fit. Stick it on the end of the list. */
542 mips_add_watchpoint (priv
, addr
, len
, watch_type
);
544 priv
->watch_mirror
= regs
;
546 /* Only update the threads of this process. */
547 for_each_thread (proc
->pid
, update_watch_registers_callback
);
552 /* This is the implementation of linux_target_ops method
556 mips_remove_point (enum raw_bkpt_type type
, CORE_ADDR addr
,
557 int len
, struct raw_breakpoint
*bp
)
559 struct process_info
*proc
= current_process ();
560 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
563 enum target_hw_bp_type watch_type
;
565 struct mips_watchpoint
**pw
;
566 struct mips_watchpoint
*w
;
568 /* Search for a known watch that matches. Then unlink and free it. */
569 watch_type
= raw_bkpt_type_to_target_hw_bp_type (type
);
571 pw
= &priv
->current_watches
;
574 if (w
->addr
== addr
&& w
->len
== len
&& w
->type
== watch_type
)
585 return -1; /* We don't know about it, fail doing nothing. */
587 /* At this point watch_readback is known to be valid because we
588 could not have added the watch without reading it. */
589 gdb_assert (priv
->watch_readback_valid
== 1);
591 priv
->watch_mirror
= priv
->watch_readback
;
592 mips_linux_watch_populate_regs (priv
->current_watches
,
593 &priv
->watch_mirror
);
595 /* Only update the threads of this process. */
596 for_each_thread (proc
->pid
, update_watch_registers_callback
);
601 /* This is the implementation of linux_target_ops method
602 stopped_by_watchpoint. The watchhi R and W bits indicate
603 the watch register triggered. */
606 mips_stopped_by_watchpoint (void)
608 struct process_info
*proc
= current_process ();
609 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
612 long lwpid
= lwpid_of (current_thread
);
614 if (!mips_linux_read_watch_registers (lwpid
,
615 &priv
->watch_readback
,
616 &priv
->watch_readback_valid
,
620 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
622 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
623 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
630 /* This is the implementation of linux_target_ops method
631 stopped_data_address. */
634 mips_stopped_data_address (void)
636 struct process_info
*proc
= current_process ();
637 struct arch_process_info
*priv
= proc
->priv
->arch_private
;
640 long lwpid
= lwpid_of (current_thread
);
642 /* On MIPS we don't know the low order 3 bits of the data address.
643 GDB does not support remote targets that can't report the
644 watchpoint address. So, make our best guess; return the starting
645 address of a watchpoint request which overlaps the one that
648 if (!mips_linux_read_watch_registers (lwpid
,
649 &priv
->watch_readback
,
650 &priv
->watch_readback_valid
,
654 num_valid
= mips_linux_watch_get_num_valid (&priv
->watch_readback
);
656 for (n
= 0; n
< MAX_DEBUG_REGISTER
&& n
< num_valid
; n
++)
657 if (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
660 CORE_ADDR t_low
, t_hi
;
662 struct mips_watchpoint
*watch
;
664 t_low
= mips_linux_watch_get_watchlo (&priv
->watch_readback
, n
);
665 t_irw
= t_low
& IRW_MASK
;
666 t_hi
= (mips_linux_watch_get_watchhi (&priv
->watch_readback
, n
)
668 t_low
&= ~(CORE_ADDR
)t_hi
;
670 for (watch
= priv
->current_watches
;
674 CORE_ADDR addr
= watch
->addr
;
675 CORE_ADDR last_byte
= addr
+ watch
->len
- 1;
677 if ((t_irw
& mips_linux_watch_type_to_irw (watch
->type
)) == 0)
679 /* Different type. */
682 /* Check for overlap of even a single byte. */
683 if (last_byte
>= t_low
&& addr
<= t_low
+ t_hi
)
688 /* Shouldn't happen. */
692 /* Fetch the thread-local storage pointer for libthread_db. */
695 ps_get_thread_area (struct ps_prochandle
*ph
,
696 lwpid_t lwpid
, int idx
, void **base
)
698 if (ptrace (PTRACE_GET_THREAD_AREA
, lwpid
, NULL
, base
) != 0)
701 /* IDX is the bias from the thread pointer to the beginning of the
702 thread descriptor. It has to be subtracted due to implementation
703 quirks in libthread_db. */
704 *base
= (void *) ((char *)*base
- idx
);
710 mips_collect_register (struct regcache
*regcache
,
711 int use_64bit
, int regno
, union mips_register
*reg
)
713 union mips_register tmp_reg
;
717 collect_register (regcache
, regno
, &tmp_reg
.reg64
);
722 collect_register (regcache
, regno
, &tmp_reg
.reg32
);
723 reg
->reg64
= tmp_reg
.reg32
;
728 mips_supply_register (struct regcache
*regcache
,
729 int use_64bit
, int regno
, const union mips_register
*reg
)
733 /* For big-endian 32-bit targets, ignore the high four bytes of each
735 if (__BYTE_ORDER
== __BIG_ENDIAN
&& !use_64bit
)
738 supply_register (regcache
, regno
, reg
->buf
+ offset
);
741 #ifdef HAVE_PTRACE_GETREGS
744 mips_collect_register_32bit (struct regcache
*regcache
,
745 int use_64bit
, int regno
, unsigned char *buf
)
747 union mips_register tmp_reg
;
750 mips_collect_register (regcache
, use_64bit
, regno
, &tmp_reg
);
751 reg32
= tmp_reg
.reg64
;
752 memcpy (buf
, ®32
, 4);
756 mips_supply_register_32bit (struct regcache
*regcache
,
757 int use_64bit
, int regno
, const unsigned char *buf
)
759 union mips_register tmp_reg
;
762 memcpy (®32
, buf
, 4);
763 tmp_reg
.reg64
= reg32
;
764 mips_supply_register (regcache
, use_64bit
, regno
, &tmp_reg
);
768 mips_fill_gregset (struct regcache
*regcache
, void *buf
)
770 union mips_register
*regset
= (union mips_register
*) buf
;
772 const struct target_desc
*tdesc
= regcache
->tdesc
;
774 use_64bit
= (register_size (tdesc
, 0) == 8);
776 for (i
= 1; i
< 32; i
++)
777 mips_collect_register (regcache
, use_64bit
, i
, regset
+ i
);
779 mips_collect_register (regcache
, use_64bit
,
780 find_regno (tdesc
, "lo"), regset
+ 32);
781 mips_collect_register (regcache
, use_64bit
,
782 find_regno (tdesc
, "hi"), regset
+ 33);
783 mips_collect_register (regcache
, use_64bit
,
784 find_regno (tdesc
, "pc"), regset
+ 34);
785 mips_collect_register (regcache
, use_64bit
,
786 find_regno (tdesc
, "badvaddr"), regset
+ 35);
787 mips_collect_register (regcache
, use_64bit
,
788 find_regno (tdesc
, "status"), regset
+ 36);
789 mips_collect_register (regcache
, use_64bit
,
790 find_regno (tdesc
, "cause"), regset
+ 37);
792 mips_collect_register (regcache
, use_64bit
,
793 find_regno (tdesc
, "restart"), regset
+ 0);
797 mips_store_gregset (struct regcache
*regcache
, const void *buf
)
799 const union mips_register
*regset
= (const union mips_register
*) buf
;
802 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
804 supply_register_by_name_zeroed (regcache
, "r0");
806 for (i
= 1; i
< 32; i
++)
807 mips_supply_register (regcache
, use_64bit
, i
, regset
+ i
);
809 mips_supply_register (regcache
, use_64bit
,
810 find_regno (regcache
->tdesc
, "lo"), regset
+ 32);
811 mips_supply_register (regcache
, use_64bit
,
812 find_regno (regcache
->tdesc
, "hi"), regset
+ 33);
813 mips_supply_register (regcache
, use_64bit
,
814 find_regno (regcache
->tdesc
, "pc"), regset
+ 34);
815 mips_supply_register (regcache
, use_64bit
,
816 find_regno (regcache
->tdesc
, "badvaddr"), regset
+ 35);
817 mips_supply_register (regcache
, use_64bit
,
818 find_regno (regcache
->tdesc
, "status"), regset
+ 36);
819 mips_supply_register (regcache
, use_64bit
,
820 find_regno (regcache
->tdesc
, "cause"), regset
+ 37);
822 mips_supply_register (regcache
, use_64bit
,
823 find_regno (regcache
->tdesc
, "restart"), regset
+ 0);
827 mips_fill_fpregset (struct regcache
*regcache
, void *buf
)
829 union mips_register
*regset
= (union mips_register
*) buf
;
830 int i
, use_64bit
, first_fp
, big_endian
;
832 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
833 first_fp
= find_regno (regcache
->tdesc
, "f0");
834 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
836 /* See GDB for a discussion of this peculiar layout. */
837 for (i
= 0; i
< 32; i
++)
839 collect_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
841 collect_register (regcache
, first_fp
+ i
,
842 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
844 mips_collect_register_32bit (regcache
, use_64bit
,
845 find_regno (regcache
->tdesc
, "fcsr"), regset
[32].buf
);
846 mips_collect_register_32bit (regcache
, use_64bit
,
847 find_regno (regcache
->tdesc
, "fir"),
852 mips_store_fpregset (struct regcache
*regcache
, const void *buf
)
854 const union mips_register
*regset
= (const union mips_register
*) buf
;
855 int i
, use_64bit
, first_fp
, big_endian
;
857 use_64bit
= (register_size (regcache
->tdesc
, 0) == 8);
858 first_fp
= find_regno (regcache
->tdesc
, "f0");
859 big_endian
= (__BYTE_ORDER
== __BIG_ENDIAN
);
861 /* See GDB for a discussion of this peculiar layout. */
862 for (i
= 0; i
< 32; i
++)
864 supply_register (regcache
, first_fp
+ i
, regset
[i
].buf
);
866 supply_register (regcache
, first_fp
+ i
,
867 regset
[i
& ~1].buf
+ 4 * (big_endian
!= (i
& 1)));
869 mips_supply_register_32bit (regcache
, use_64bit
,
870 find_regno (regcache
->tdesc
, "fcsr"),
872 mips_supply_register_32bit (regcache
, use_64bit
,
873 find_regno (regcache
->tdesc
, "fir"),
876 #endif /* HAVE_PTRACE_GETREGS */
878 /* Take care of 32-bit registers with 64-bit ptrace, POKEUSER side. */
881 mips_collect_ptrace_register (struct regcache
*regcache
,
882 int regno
, char *buf
)
884 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
886 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
888 union mips_register reg
;
890 mips_collect_register (regcache
, 0, regno
, ®
);
891 memcpy (buf
, ®
, sizeof (reg
));
894 collect_register (regcache
, regno
, buf
);
897 /* Take care of 32-bit registers with 64-bit ptrace, PEEKUSER side. */
900 mips_supply_ptrace_register (struct regcache
*regcache
,
901 int regno
, const char *buf
)
903 int use_64bit
= sizeof (PTRACE_XFER_TYPE
) == 8;
905 if (use_64bit
&& register_size (regcache
->tdesc
, regno
) == 4)
907 union mips_register reg
;
909 memcpy (®
, buf
, sizeof (reg
));
910 mips_supply_register (regcache
, 0, regno
, ®
);
913 supply_register (regcache
, regno
, buf
);
916 static struct regset_info mips_regsets
[] = {
917 #ifdef HAVE_PTRACE_GETREGS
918 { PTRACE_GETREGS
, PTRACE_SETREGS
, 0, 38 * 8, GENERAL_REGS
,
919 mips_fill_gregset
, mips_store_gregset
},
920 { PTRACE_GETFPREGS
, PTRACE_SETFPREGS
, 0, 33 * 8, FP_REGS
,
921 mips_fill_fpregset
, mips_store_fpregset
},
922 #endif /* HAVE_PTRACE_GETREGS */
926 static struct regsets_info mips_regsets_info
=
928 mips_regsets
, /* regsets */
930 NULL
, /* disabled_regsets */
933 static struct usrregs_info mips_dsp_usrregs_info
=
939 static struct usrregs_info mips_usrregs_info
=
945 static struct regs_info dsp_regs_info
=
947 mips_dsp_regset_bitmap
,
948 &mips_dsp_usrregs_info
,
952 static struct regs_info myregs_info
=
954 NULL
, /* regset_bitmap */
960 mips_target::get_regs_info ()
963 return &dsp_regs_info
;
968 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
);