@samitouri / QOSamiQemu / commits / 2497a8a6e1

target/mips: Replace ldtul_p() -> ldn_p()

Prefer ldn_p(target_long_bits/8) over target-specific ldtul_p(). Use deposit64() in gdb_write_register(), allowing to remove 'target_ulong' type uses. Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260219191955.83815-27-philmd@linaro.org>

Philippe Mathieu-Daudé committed Mar 25, 2025 at 11:44 UTC 2497a8a6e175d04cf790aae3702805d9702fcea4
1 file changed +8 -6
target/mips/gdbstub.c
+8 -6
@@ -18,6 +18,7 @@
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20 #include "qemu/osdep.h"
21 +#include "qemu/bitops.h"
22 #include "cpu.h"
23 #include "internal.h"
24 #include "gdbstub/helpers.h"
@@ -77,14 +78,15 @@ int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
78
79 int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
80 {
81 + const unsigned regsz = target_long_bits() / 8;
82 CPUMIPSState *env = cpu_env(cs);
81 - target_ulong tmp;
83 + uint64_t tmp;
84
83 - tmp = ldtul_p(mem_buf);
85 + tmp = ldn_p(mem_buf, regsz);
86
87 if (n < 32) {
88 env->active_tc.gpr[n] = tmp;
87 - return sizeof(target_ulong);
89 + return regsz;
90 }
91 if (env->CP0_Config1 & (1 << CP0C1_FP) && n >= 38 && n < 72) {
92 switch (n) {
@@ -104,7 +106,7 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
106 }
107 break;
108 }
107 - return sizeof(target_ulong);
109 + return regsz;
110 }
111 switch (n) {
112 case 32:
@@ -127,7 +129,7 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
129 #endif
130 break;
131 case 37:
130 - env->active_tc.PC = tmp & ~(target_ulong)1;
132 + env->active_tc.PC = deposit64(tmp, 63, 1, 0);
133 if (tmp & 1) {
134 env->hflags |= MIPS_HFLAG_M16;
135 } else {
@@ -144,5 +146,5 @@ int mips_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
146 break;
147 }
148
147 - return sizeof(target_ulong);
149 + return regsz;
150 }