| OLD | NEW |
| 1 /* Ravenscar SPARC target support. | 1 /* Ravenscar SPARC target support. |
| 2 | 2 |
| 3 Copyright 2004, 2010-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2004-2013 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
| 9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 17 You should have received a copy of the GNU General Public License |
| 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 |
| 20 #include "defs.h" | 20 #include "defs.h" |
| 21 #include "gdbcore.h" | 21 #include "gdbcore.h" |
| 22 #include "regcache.h" | 22 #include "regcache.h" |
| 23 #include "sparc-tdep.h" | 23 #include "sparc-tdep.h" |
| 24 #include "inferior.h" | 24 #include "inferior.h" |
| 25 #include "ravenscar-thread.h" | 25 #include "ravenscar-thread.h" |
| 26 #include "sparc-ravenscar-thread.h" |
| 26 | 27 |
| 27 static struct ravenscar_arch_ops ravenscar_sparc_ops; | 28 static void sparc_ravenscar_fetch_registers (struct regcache *regcache, |
| 28 | |
| 29 static void ravenscar_sparc_fetch_registers (struct regcache *regcache, | |
| 30 int regnum); | 29 int regnum); |
| 31 static void ravenscar_sparc_store_registers (struct regcache *regcache, | 30 static void sparc_ravenscar_store_registers (struct regcache *regcache, |
| 32 int regnum); | 31 int regnum); |
| 33 static void ravenscar_sparc_prepare_to_store (struct regcache *regcache); | 32 static void sparc_ravenscar_prepare_to_store (struct regcache *regcache); |
| 34 | 33 |
| 35 /* Register offsets from a referenced address (exempli gratia the | 34 /* Register offsets from a referenced address (exempli gratia the |
| 36 Thread_Descriptor). The referenced address depends on the register | 35 Thread_Descriptor). The referenced address depends on the register |
| 37 number. The Thread_Descriptor layout and the stack layout are documented | 36 number. The Thread_Descriptor layout and the stack layout are documented |
| 38 in the GNAT sources, in sparc-bb.h. */ | 37 in the GNAT sources, in sparc-bb.h. */ |
| 39 | 38 |
| 40 static const int sparc_register_offsets[] = | 39 static const int sparc_register_offsets[] = |
| 41 { | 40 { |
| 42 /* G0 - G7 */ | 41 /* G0 - G7 */ |
| 43 -1, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C, | 42 -1, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 58 | 57 |
| 59 /* supply register REGNUM, which has been saved on REGISTER_ADDR, to the | 58 /* supply register REGNUM, which has been saved on REGISTER_ADDR, to the |
| 60 regcache. */ | 59 regcache. */ |
| 61 | 60 |
| 62 static void | 61 static void |
| 63 supply_register_at_address (struct regcache *regcache, int regnum, | 62 supply_register_at_address (struct regcache *regcache, int regnum, |
| 64 CORE_ADDR register_addr) | 63 CORE_ADDR register_addr) |
| 65 { | 64 { |
| 66 struct gdbarch *gdbarch = get_regcache_arch (regcache); | 65 struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 67 int buf_size = register_size (gdbarch, regnum); | 66 int buf_size = register_size (gdbarch, regnum); |
| 68 char *buf; | 67 gdb_byte *buf; |
| 69 | 68 |
| 70 buf = (char *) alloca (buf_size); | 69 buf = alloca (buf_size); |
| 71 read_memory (register_addr, buf, buf_size); | 70 read_memory (register_addr, buf, buf_size); |
| 72 regcache_raw_supply (regcache, regnum, buf); | 71 regcache_raw_supply (regcache, regnum, buf); |
| 73 } | 72 } |
| 74 | 73 |
| 75 /* Return true if, for a non-running thread, REGNUM has been saved on the | 74 /* Return true if, for a non-running thread, REGNUM has been saved on the |
| 76 stack. */ | 75 stack. */ |
| 77 | 76 |
| 78 static int | 77 static int |
| 79 register_on_stack_p (int regnum) | 78 register_on_stack_p (int regnum) |
| 80 { | 79 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 || (regnum == SPARC32_WIM_REGNUM) | 94 || (regnum == SPARC32_WIM_REGNUM) |
| 96 || (regnum == SPARC32_FSR_REGNUM) | 95 || (regnum == SPARC32_FSR_REGNUM) |
| 97 || (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F0_REGNUM + 31) | 96 || (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F0_REGNUM + 31) |
| 98 || (regnum == SPARC32_PC_REGNUM); | 97 || (regnum == SPARC32_PC_REGNUM); |
| 99 } | 98 } |
| 100 | 99 |
| 101 /* to_fetch_registers when inferior_ptid is different from the running | 100 /* to_fetch_registers when inferior_ptid is different from the running |
| 102 thread. */ | 101 thread. */ |
| 103 | 102 |
| 104 static void | 103 static void |
| 105 ravenscar_sparc_fetch_registers (struct regcache *regcache, int regnum) | 104 sparc_ravenscar_fetch_registers (struct regcache *regcache, int regnum) |
| 106 { | 105 { |
| 107 struct gdbarch *gdbarch = get_regcache_arch (regcache); | 106 struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 108 const int sp_regnum = gdbarch_sp_regnum (gdbarch); | 107 const int sp_regnum = gdbarch_sp_regnum (gdbarch); |
| 109 const int num_regs = gdbarch_num_regs (gdbarch); | 108 const int num_regs = gdbarch_num_regs (gdbarch); |
| 110 int current_regnum; | 109 int current_regnum; |
| 111 CORE_ADDR current_address; | 110 CORE_ADDR current_address; |
| 112 CORE_ADDR thread_descriptor_address; | 111 CORE_ADDR thread_descriptor_address; |
| 113 ULONGEST stack_address; | 112 ULONGEST stack_address; |
| 114 | 113 |
| 114 /* The tid is the thread_id field, which is a pointer to the thread. */ |
| 115 thread_descriptor_address = (CORE_ADDR) ptid_get_tid (inferior_ptid); | 115 thread_descriptor_address = (CORE_ADDR) ptid_get_tid (inferior_ptid); |
| 116 |
| 117 /* Read the saved SP in the context buffer. */ |
| 116 current_address = thread_descriptor_address | 118 current_address = thread_descriptor_address |
| 117 + sparc_register_offsets [sp_regnum]; | 119 + sparc_register_offsets [sp_regnum]; |
| 118 supply_register_at_address (regcache, sp_regnum, current_address); | 120 supply_register_at_address (regcache, sp_regnum, current_address); |
| 119 regcache_cooked_read_unsigned (regcache, sp_regnum, &stack_address); | 121 regcache_cooked_read_unsigned (regcache, sp_regnum, &stack_address); |
| 120 | 122 |
| 123 /* Read registers. */ |
| 121 for (current_regnum = 0; current_regnum < num_regs; current_regnum ++) | 124 for (current_regnum = 0; current_regnum < num_regs; current_regnum ++) |
| 122 { | 125 { |
| 123 if (register_in_thread_descriptor_p (current_regnum)) | 126 if (register_in_thread_descriptor_p (current_regnum)) |
| 124 { | 127 { |
| 125 current_address = thread_descriptor_address | 128 current_address = thread_descriptor_address |
| 126 + sparc_register_offsets [current_regnum]; | 129 + sparc_register_offsets [current_regnum]; |
| 127 supply_register_at_address (regcache, current_regnum, | 130 supply_register_at_address (regcache, current_regnum, |
| 128 current_address); | 131 current_address); |
| 129 } | 132 } |
| 130 else if (register_on_stack_p (current_regnum)) | 133 else if (register_on_stack_p (current_regnum)) |
| 131 { | 134 { |
| 132 current_address = stack_address | 135 current_address = stack_address |
| 133 + sparc_register_offsets [current_regnum]; | 136 + sparc_register_offsets [current_regnum]; |
| 134 supply_register_at_address (regcache, current_regnum, | 137 supply_register_at_address (regcache, current_regnum, |
| 135 current_address); | 138 current_address); |
| 136 } | 139 } |
| 137 } | 140 } |
| 138 } | 141 } |
| 139 | 142 |
| 140 /* to_prepare_to_store when inferior_ptid is different from the running | 143 /* to_prepare_to_store when inferior_ptid is different from the running |
| 141 thread. */ | 144 thread. */ |
| 142 | 145 |
| 143 static void | 146 static void |
| 144 ravenscar_sparc_prepare_to_store (struct regcache *regcache) | 147 sparc_ravenscar_prepare_to_store (struct regcache *regcache) |
| 145 { | 148 { |
| 146 /* Nothing to do. */ | 149 /* Nothing to do. */ |
| 147 } | 150 } |
| 148 | 151 |
| 149 /* to_store_registers when inferior_ptid is different from the running | 152 /* to_store_registers when inferior_ptid is different from the running |
| 150 thread. */ | 153 thread. */ |
| 151 | 154 |
| 152 static void | 155 static void |
| 153 ravenscar_sparc_store_registers (struct regcache *regcache, int regnum) | 156 sparc_ravenscar_store_registers (struct regcache *regcache, int regnum) |
| 154 { | 157 { |
| 155 struct gdbarch *gdbarch = get_regcache_arch (regcache); | 158 struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 156 int buf_size = register_size (gdbarch, regnum); | 159 int buf_size = register_size (gdbarch, regnum); |
| 157 char buf [buf_size]; | 160 gdb_byte buf[buf_size]; |
| 158 ULONGEST register_address; | 161 ULONGEST register_address; |
| 159 | 162 |
| 160 if (register_in_thread_descriptor_p (regnum)) | 163 if (register_in_thread_descriptor_p (regnum)) |
| 161 register_address = | 164 register_address = |
| 162 ptid_get_tid (inferior_ptid) + sparc_register_offsets [regnum]; | 165 ptid_get_tid (inferior_ptid) + sparc_register_offsets [regnum]; |
| 163 else if (register_on_stack_p (regnum)) | 166 else if (register_on_stack_p (regnum)) |
| 164 { | 167 { |
| 165 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, | 168 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, |
| 166 ®ister_address); | 169 ®ister_address); |
| 167 register_address += sparc_register_offsets [regnum]; | 170 register_address += sparc_register_offsets [regnum]; |
| 168 } | 171 } |
| 169 else | 172 else |
| 170 return; | 173 return; |
| 171 | 174 |
| 172 regcache_raw_collect (regcache, regnum, buf); | 175 regcache_raw_collect (regcache, regnum, buf); |
| 173 write_memory (register_address, | 176 write_memory (register_address, |
| 174 buf, | 177 buf, |
| 175 buf_size); | 178 buf_size); |
| 176 } | 179 } |
| 177 | 180 |
| 178 /* Provide a prototype to silence -Wmissing-prototypes. */ | 181 static struct ravenscar_arch_ops sparc_ravenscar_ops = |
| 179 extern void _initialize_ravenscar_sparc (void); | 182 { |
| 183 sparc_ravenscar_fetch_registers, |
| 184 sparc_ravenscar_store_registers, |
| 185 sparc_ravenscar_prepare_to_store |
| 186 }; |
| 187 |
| 188 /* Register ravenscar_arch_ops in GDBARCH. */ |
| 180 | 189 |
| 181 void | 190 void |
| 182 _initialize_ravenscar_sparc (void) | 191 register_sparc_ravenscar_ops (struct gdbarch *gdbarch) |
| 183 { | 192 { |
| 184 ravenscar_sparc_ops.to_fetch_registers = ravenscar_sparc_fetch_registers; | 193 set_gdbarch_ravenscar_ops (gdbarch, &sparc_ravenscar_ops); |
| 185 ravenscar_sparc_ops.to_store_registers = ravenscar_sparc_store_registers; | |
| 186 ravenscar_sparc_ops.to_prepare_to_store = ravenscar_sparc_prepare_to_store; | |
| 187 ravenscar_register_arch_ops (&ravenscar_sparc_ops); | |
| 188 } | 194 } |
| OLD | NEW |