From patchwork Fri Dec 20 12:04:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182245 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp437377ilf; Fri, 20 Dec 2019 04:07:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyt/M4WtUZre5qgy5N4zumtTNXN1tGSMf2ZOj86+j4e3Wq8ssSErsc1qI1cKi5R83m/0ZUt X-Received: by 2002:a05:620a:817:: with SMTP id s23mr13163632qks.391.1576843672790; Fri, 20 Dec 2019 04:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843672; cv=none; d=google.com; s=arc-20160816; b=tBAAL6uMb3k2R2oJzIgGduMGmpRn7QVF4NAM4xrUQgKrf7tgdQUHoWYJOrM0BhTL3d 5gj9zS8ANArurSPY1jMIDczQPFERabRGuHF5IOO15AkeSstjDjcl7G3W4b0+Zy/IWqE2 Jf7zBs97qdspcoWja0GBj9KfjK+sW4GQtbrRwhnDno1WuNBViA40Xtwpg920MWmPsD8s lLuolpA/pSD0DM+bVH58OpzkDiaKfr7DWXgrHoJwrgrmiK4ZeRARw3bEs2JYb/1vzpW6 CIWUzeXXKRBlvMXJbaqFo32AdLfHrntgoQjoa/fV4XVZ0Jx/9Rvk4HfCk/lp+wfsqL2V G0pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=EvncXr65wY8Yn/VEebWv31Jr8VPL+HsPbo8SEsDtLUlVfgV97oKEd5Nt9MmHunQz+n qt9gMCfXLlbjfJvSpnEwJN7+SEcDM5Xo0HGbayfJK1LINOfD+14yZ0kEY3DvuoFOFeoU goFYXF1Jrf3KvWLAagH8oF973CUv2DcMHAJSvaaNi8LMEAL8QgbNKne55/w4d2vjmG4j 9UTHoairrh6NEdgGZ45pJ4Ki76a5YDa4Wi1wrfLSmYpqrMaUudOo7n96lNsanL/ow94+ gYeO2/9kkjIHpfeHJCtCB1f/c+A2PVOCWYgunSCMjHyp5PxRycrCEVJObbKg3/EM69kw 89Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LbCMyns6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x25si4990644qki.196.2019.12.20.04.07.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LbCMyns6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH4R-0008BL-S2 for patch@linaro.org; Fri, 20 Dec 2019 07:07:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51739) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1S-0004Ye-3F for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1P-0007HQ-RR for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:45 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1P-0007AL-DM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:43 -0500 Received: by mail-wm1-x341.google.com with SMTP id t14so8960418wmi.5 for ; Fri, 20 Dec 2019 04:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=LbCMyns60IYsl2fr34xczYIcdxEpgga2aL+YUPYbIJan0EKbOwPWT9hzJlUbcl+d9f AwZ6eJvNmbG63CJYFUYGIRVbOUTUwNF9SgzjEsg9QwFPzPAmzx/+D/B3TXdIZnDqkxBW Axd6pRuAnxWmJTl0gGBE9cMggpiQWSzBuamL+aWrkkJvDNRRU/Fxg39aDj/OER0nybnA 9GLDP99RipYiAhzg3WlDnfckxlzqrt+Fb39iGTm3z1haFYr7ecP4Krmj+TZEixzBFVQE k3sEWBmuYcDYK3U4f9Yq+1gRRZ/PBl/6mOPlYHcqh+e1Z7FbwCRQELvFVuPMv52N3YTe Fqzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OtFgNihQmjwXIczGB6RrVvTGCHXdssZoK9FktuuxCfA=; b=BvGxsma8af2VvHBVcUobJ0p9Ii8FAYPCbaJUwPWRKnoI8mLwlDUP4t0sFcvFGHH6et simYIknbDw08vaG/EAubfwJbrAhb3uCBTQ4s3SCqdudMDQTbLaPTMC12JTzfG0K/p7ce Ub+Ua4pWniEH7NRzJiCBmQeN2IyEixiL9nSV8A8freXg/4K4RnNTLNNgRvuq+PNqeuK1 O7nVPHIDmIB9kyBNUcu4czgDewEJYeqcOTa9dTWKEEOZ2YBMxI43z/XFM3GXq9B0YTro EqP+YbK7IFKiPDvk/ewnNDoYjIAiOhyP3kSWkf2rkFa2AnerEEvqKwYryr07mRZInNFn /jaQ== X-Gm-Message-State: APjAAAVPMgbl8gMb45JzLY2zhSuKdc2ya/wtd2npPVBTySPOxu5lAjnY ZH0FDCurqqM2cWbSDTlKrWPMvQ== X-Received: by 2002:a1c:3dc3:: with SMTP id k186mr15459707wma.95.1576843481218; Fri, 20 Dec 2019 04:04:41 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x10sm9420713wrv.60.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:39 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E6BEA1FF8C; Fri, 20 Dec 2019 12:04:38 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 01/21] gdbstub: make GDBState static and have common init function Date: Fri, 20 Dec 2019 12:04:18 +0000 Message-Id: <20191220120438.16114-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of allocating make this entirely static. We shall reduce the size of the structure in later commits and dynamically allocate parts of it. We introduce an init and reset helper function to keep all the manipulation in one place. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde --- v2 - made entirely static, dropped dh/rth r-b tags due to changes --- gdbstub.c | 168 ++++++++++++++++++++++++++---------------------------- 1 file changed, 81 insertions(+), 87 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 4cf8af365e2..36b1d7a9408 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -342,6 +342,7 @@ enum RSState { RS_CHKSUM2, }; typedef struct GDBState { + bool init; /* have we been initialised? */ CPUState *c_cpu; /* current CPU for step/continue ops */ CPUState *g_cpu; /* current CPU for other ops */ CPUState *query_cpu; /* for q{f|s}ThreadInfo */ @@ -372,7 +373,23 @@ typedef struct GDBState { */ static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; -static GDBState *gdbserver_state; +static GDBState gdbserver_state; + +static void init_gdbserver_state(void) +{ + g_assert(!gdbserver_state.init); + memset(&gdbserver_state, 0, sizeof(GDBState)); + gdbserver_state.init = true; +} + +#ifndef CONFIG_USER_ONLY +static void reset_gdbserver_state(void) +{ + g_free(gdbserver_state.processes); + gdbserver_state.processes = NULL; + gdbserver_state.process_num = 0; +} +#endif bool gdb_has_xml; @@ -425,8 +442,8 @@ int use_gdb_syscalls(void) /* -semihosting-config target=auto */ /* On the first call check if gdb is connected and remember. */ if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { - gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED - : GDB_SYS_DISABLED); + gdb_syscall_mode = gdbserver_state.init ? + GDB_SYS_ENABLED : GDB_SYS_DISABLED; } return gdb_syscall_mode == GDB_SYS_ENABLED; } @@ -984,7 +1001,7 @@ static int gdb_breakpoint_insert(int type, target_ulong addr, target_ulong len) int err = 0; if (kvm_enabled()) { - return kvm_insert_breakpoint(gdbserver_state->c_cpu, addr, len, type); + return kvm_insert_breakpoint(gdbserver_state.c_cpu, addr, len, type); } switch (type) { @@ -1021,7 +1038,7 @@ static int gdb_breakpoint_remove(int type, target_ulong addr, target_ulong len) int err = 0; if (kvm_enabled()) { - return kvm_remove_breakpoint(gdbserver_state->c_cpu, addr, len, type); + return kvm_remove_breakpoint(gdbserver_state.c_cpu, addr, len, type); } switch (type) { @@ -1074,7 +1091,7 @@ static void gdb_breakpoint_remove_all(void) CPUState *cpu; if (kvm_enabled()) { - kvm_remove_all_breakpoints(gdbserver_state->c_cpu); + kvm_remove_all_breakpoints(gdbserver_state.c_cpu); return; } @@ -2601,7 +2618,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) void gdb_set_stop_cpu(CPUState *cpu) { - GDBProcess *p = gdb_get_cpu_process(gdbserver_state, cpu); + GDBProcess *p = gdb_get_cpu_process(&gdbserver_state, cpu); if (!p->attached) { /* @@ -2611,14 +2628,14 @@ void gdb_set_stop_cpu(CPUState *cpu) return; } - gdbserver_state->c_cpu = cpu; - gdbserver_state->g_cpu = cpu; + gdbserver_state.c_cpu = cpu; + gdbserver_state.g_cpu = cpu; } #ifndef CONFIG_USER_ONLY static void gdb_vm_state_change(void *opaque, int running, RunState state) { - GDBState *s = gdbserver_state; + GDBState *s = &gdbserver_state; CPUState *cpu = s->c_cpu; char buf[256]; char thread_id[16]; @@ -2722,17 +2739,16 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) char *p_end; target_ulong addr; uint64_t i64; - GDBState *s; - s = gdbserver_state; - if (!s) + if (!gdbserver_state.init) return; - s->current_syscall_cb = cb; + + gdbserver_state.current_syscall_cb = cb; #ifndef CONFIG_USER_ONLY vm_stop(RUN_STATE_DEBUG); #endif - p = s->syscall_buf; - p_end = &s->syscall_buf[sizeof(s->syscall_buf)]; + p = &gdbserver_state.syscall_buf[0]; + p_end = &gdbserver_state.syscall_buf[sizeof(gdbserver_state.syscall_buf)]; *(p++) = 'F'; while (*fmt) { if (*fmt == '%') { @@ -2765,14 +2781,14 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } *p = 0; #ifdef CONFIG_USER_ONLY - put_packet(s, s->syscall_buf); + put_packet(&gdbserver_state, gdbserver_state.syscall_buf); /* Return control to gdb for it to process the syscall request. * Since the protocol requires that gdb hands control back to us * using a "here are the results" F packet, we don't need to check * gdb_handlesig's return value (which is the signal to deliver if * execution was resumed via a continue packet). */ - gdb_handlesig(s->c_cpu, 0); + gdb_handlesig(gdbserver_state.c_cpu, 0); #else /* In this case wait to send the syscall packet until notification that the CPU has stopped. This must be done because if the packet is sent @@ -2780,7 +2796,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) is still in the running state, which can cause packets to be dropped and state transition 'T' packets to be sent while the syscall is still being processed. */ - qemu_cpu_kick(s->c_cpu); + qemu_cpu_kick(gdbserver_state.c_cpu); #endif } @@ -2941,15 +2957,13 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) /* Tell the remote gdb that the process has exited. */ void gdb_exit(CPUArchState *env, int code) { - GDBState *s; char buf[4]; - s = gdbserver_state; - if (!s) { + if (!gdbserver_state.init) { return; } #ifdef CONFIG_USER_ONLY - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } #endif @@ -2957,10 +2971,10 @@ void gdb_exit(CPUArchState *env, int code) trace_gdbstub_op_exiting((uint8_t)code); snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); #ifndef CONFIG_USER_ONLY - qemu_chr_fe_deinit(&s->chr, true); + qemu_chr_fe_deinit(&gdbserver_state.chr, true); #endif } @@ -2993,12 +3007,10 @@ static void create_default_process(GDBState *s) int gdb_handlesig(CPUState *cpu, int sig) { - GDBState *s; char buf[256]; int n; - s = gdbserver_state; - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return sig; } @@ -3008,58 +3020,55 @@ gdb_handlesig(CPUState *cpu, int sig) if (sig != 0) { snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); } /* put_packet() might have detected that the peer terminated the connection. */ - if (s->fd < 0) { + if (gdbserver_state.fd < 0) { return sig; } sig = 0; - s->state = RS_IDLE; - s->running_state = 0; - while (s->running_state == 0) { - n = read(s->fd, buf, 256); + gdbserver_state.state = RS_IDLE; + gdbserver_state.running_state = 0; + while (gdbserver_state.running_state == 0) { + n = read(gdbserver_state.fd, buf, 256); if (n > 0) { int i; for (i = 0; i < n; i++) { - gdb_read_byte(s, buf[i]); + gdb_read_byte(&gdbserver_state, buf[i]); } } else { /* XXX: Connection closed. Should probably wait for another connection before continuing. */ if (n == 0) { - close(s->fd); + close(gdbserver_state.fd); } - s->fd = -1; + gdbserver_state.fd = -1; return sig; } } - sig = s->signal; - s->signal = 0; + sig = gdbserver_state.signal; + gdbserver_state.signal = 0; return sig; } /* Tell the remote gdb that the process has exited due to SIG. */ void gdb_signalled(CPUArchState *env, int sig) { - GDBState *s; char buf[4]; - s = gdbserver_state; - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); - put_packet(s, buf); + put_packet(&gdbserver_state, buf); } static bool gdb_accept(void) { - GDBState *s; struct sockaddr_in sockaddr; socklen_t len; int fd; @@ -3083,15 +3092,13 @@ static bool gdb_accept(void) return false; } - s = g_malloc0(sizeof(GDBState)); - create_default_process(s); - s->processes[0].attached = true; - s->c_cpu = gdb_first_attached_cpu(s); - s->g_cpu = s->c_cpu; - s->fd = fd; + init_gdbserver_state(); + create_default_process(&gdbserver_state); + gdbserver_state.processes[0].attached = true; + gdbserver_state.c_cpu = gdb_first_attached_cpu(&gdbserver_state); + gdbserver_state.g_cpu = gdbserver_state.c_cpu; + gdbserver_state.fd = fd; gdb_has_xml = false; - - gdbserver_state = s; return true; } @@ -3144,13 +3151,11 @@ int gdbserver_start(int port) /* Disable gdb stub for child processes. */ void gdbserver_fork(CPUState *cpu) { - GDBState *s = gdbserver_state; - - if (gdbserver_fd < 0 || s->fd < 0) { + if (gdbserver_fd < 0 || gdbserver_state.fd < 0) { return; } - close(s->fd); - s->fd = -1; + close(gdbserver_state.fd); + gdbserver_state.fd = -1; cpu_breakpoint_remove_all(cpu, BP_GDB); cpu_watchpoint_remove_all(cpu, BP_GDB); } @@ -3167,7 +3172,7 @@ static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) int i; for (i = 0; i < size; i++) { - gdb_read_byte(gdbserver_state, buf[i]); + gdb_read_byte(&gdbserver_state, buf[i]); } } @@ -3210,13 +3215,13 @@ static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) const char *p = (const char *)buf; int max_sz; - max_sz = (sizeof(gdbserver_state->last_packet) - 2) / 2; + max_sz = (sizeof(gdbserver_state.last_packet) - 2) / 2; for (;;) { if (len <= max_sz) { - gdb_monitor_output(gdbserver_state, p, len); + gdb_monitor_output(&gdbserver_state, p, len); break; } - gdb_monitor_output(gdbserver_state, p, max_sz); + gdb_monitor_output(&gdbserver_state, p, max_sz); p += max_sz; len -= max_sz; } @@ -3308,18 +3313,10 @@ static void create_processes(GDBState *s) create_default_process(s); } -static void cleanup_processes(GDBState *s) -{ - g_free(s->processes); - s->process_num = 0; - s->processes = NULL; -} - int gdbserver_start(const char *device) { trace_gdbstub_op_start(device); - GDBState *s; char gdbstub_device_name[128]; Chardev *chr = NULL; Chardev *mon_chr; @@ -3357,10 +3354,8 @@ int gdbserver_start(const char *device) return -1; } - s = gdbserver_state; - if (!s) { - s = g_malloc0(sizeof(GDBState)); - gdbserver_state = s; + if (!gdbserver_state.init) { + init_gdbserver_state(); qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL); @@ -3369,31 +3364,30 @@ int gdbserver_start(const char *device) NULL, NULL, &error_abort); monitor_init_hmp(mon_chr, false); } else { - qemu_chr_fe_deinit(&s->chr, true); - mon_chr = s->mon_chr; - cleanup_processes(s); - memset(s, 0, sizeof(GDBState)); - s->mon_chr = mon_chr; + qemu_chr_fe_deinit(&gdbserver_state.chr, true); + mon_chr = gdbserver_state.mon_chr; + reset_gdbserver_state(); } - create_processes(s); + create_processes(&gdbserver_state); if (chr) { - qemu_chr_fe_init(&s->chr, chr, &error_abort); - qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive, - gdb_chr_event, NULL, s, NULL, true); + qemu_chr_fe_init(&gdbserver_state.chr, chr, &error_abort); + qemu_chr_fe_set_handlers(&gdbserver_state.chr, gdb_chr_can_receive, + gdb_chr_receive, gdb_chr_event, + NULL, &gdbserver_state, NULL, true); } - s->state = chr ? RS_IDLE : RS_INACTIVE; - s->mon_chr = mon_chr; - s->current_syscall_cb = NULL; + gdbserver_state.state = chr ? RS_IDLE : RS_INACTIVE; + gdbserver_state.mon_chr = mon_chr; + gdbserver_state.current_syscall_cb = NULL; return 0; } void gdbserver_cleanup(void) { - if (gdbserver_state) { - put_packet(gdbserver_state, "W00"); + if (gdbserver_state.init) { + put_packet(&gdbserver_state, "W00"); } } From patchwork Fri Dec 20 12:04:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182249 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp442700ilf; Fri, 20 Dec 2019 04:12:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwh9biit/xz43dWz8101VXOgrhA+QEr1YS30SPh1gmnFR7KrIw2yUSI6u2vpw6F+NdA3Ip9 X-Received: by 2002:ac8:4257:: with SMTP id r23mr11195588qtm.126.1576843933702; Fri, 20 Dec 2019 04:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843933; cv=none; d=google.com; s=arc-20160816; b=HI/HZbRSELkiPJk1sISeh3tVy3827Xuot+x7BQYaSIasDKkNa6br+vqNYF7uUmIriC B95+d5uf4ESnYdFvw3PmoT2j17sUPbJdtEd864VHDQfttEbs4Qbc4kb6ODUdSNIXYqzG tqej+RMLm9h4C/ghXZc780fLGbnqaYbqkhKZdPpEEuQuw2bimsR7WchEGrMipw4JGssM NT6MSCQMQHJKgKiSYKwWhz0bF5niza+T3GuEjldS1IxD9SJ2AdRKBU8ArpRKjNrlIzNr 87km3BWmZn+Q79RBU1AL4iR2pS2rrx6v0sX8qjg4g+/4sNQsgaAkOJRpSIz9IdjuOmFT NIvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=rtXyTIryChja7GHZgwjU3Ymea0EY02+NZM6fOzaZL2OMTyZHfzeVfUg0m9c6Ew+j/h U9YlC+JSrMgtlASBOkTKXnQ98u57ihP41V1TquMTxRb7/ybCcF6wvWmdSuWpo9muaPxZ Cnc39WOY5d45f06o9xGt3BusL8NFBzlPIuGtXqXXKKbkZjqzFUmBZ6LoIlQOm2ZJiS0Y KsIsVrgNhiKRvDl9jDO1PKHhDPcS0dQoUFZYdjvJR89M87gfseliTGMFFfrnqVa/DXyt HanaUtQy2fXwW7XlxMZmPd0ev1Qnji3Z3lFs660RUEQPjmn6LAtMgcm6RDnINpg47CzB 9Khw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="AhiWv/y8"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l15si5056124qkk.284.2019.12.20.04.12.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:12:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="AhiWv/y8"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH8f-0005c2-0I for patch@linaro.org; Fri, 20 Dec 2019 07:12:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52562) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1X-0004gt-Vb for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1S-0007Rc-Fd for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:40703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1R-0007NV-W1 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:46 -0500 Received: by mail-wr1-x443.google.com with SMTP id c14so9162041wrn.7 for ; Fri, 20 Dec 2019 04:04:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=AhiWv/y8M5rAIJik9jWX2Lllb/CNWYmNQfClwDtmC8PqIzNqOM1dOHuYWIbZ4OZAu0 yi8xkq1EB+Gj64INiuYJ6cJOqfjTZyT9mARy3Qn0XtqRUBcrjv+reB+WDwjW/tHxnj73 pqywfbIQd9eqcw3AShEU6v05AEoktinVbu10CHrdFAdgl6jCUSP2BSd6cR+wNxb3vyTf gBqjJUQODPYZta2VIn1lBEsYgYQGeI0n6Wxe+oEwK/Mjlh1ASJjkh3vI5gw57GVMVyQq I85cG103BczYpoZ3kF/8APG8vo7aDCQjAjc4pzkEpLrOMl+6FhFg3PW/XmSqC04rtFLO 1AfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dQOlXAoJ3FKmzm2CRRD+Ds4XAjn4cv/b/o6pTKLN+vI=; b=ZZc7iQ7t/4e1vbqo2WzkD4PolKTSMPETb2fW/uMsee42u1285WoKHVDsN/kCescKV8 SqO5f99r+e+Wwt2zXI7wv7bza7nWhlrlbzUuWjRtaHij3tZ4qHIne+nGnpx/GFjXzUYn bBv+gZDGiKnsPWfBxHBSbQ629wf5pZszLqGttRy2oCrk4UaDTSYqf0EMDEEJUf9WkmYx D12SPByJ3EcfmhifpBHuIdwx84PMQIgCX6XMsghLU3PWQK+nxYACY+XlWxcqTvd5IU3U SbV9LNCQ/zKRndJeEDEEh6ijAN2b1rfWVkmaekWnbvs1SDWCZFXX2thpE2fU9hXAnJSv d5IQ== X-Gm-Message-State: APjAAAUHfasmU4Yo860zF7Jyv+duI0YIJiiPZMcVhfvFcYBszyKcofDS BB690Q95TZqwsP8YdX3+0FInUfjvoQ4= X-Received: by 2002:adf:dfc2:: with SMTP id q2mr14366564wrn.251.1576843483694; Fri, 20 Dec 2019 04:04:43 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a14sm10011883wrx.81.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:39 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0EFC41FF8F; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 02/21] gdbstub: stop passing GDBState * around and use global Date: Fri, 20 Dec 2019 12:04:19 +0000 Message-Id: <20191220120438.16114-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - remove final *s paramters from function calls v4 - a few fixups for coding style --- gdbstub.c | 561 +++++++++++++++++++++++++++--------------------------- 1 file changed, 278 insertions(+), 283 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 36b1d7a9408..85ef7d37e08 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -397,21 +397,21 @@ bool gdb_has_xml; /* XXX: This is not thread safe. Do we care? */ static int gdbserver_fd = -1; -static int get_char(GDBState *s) +static int get_char(void) { uint8_t ch; int ret; for(;;) { - ret = qemu_recv(s->fd, &ch, 1, 0); + ret = qemu_recv(gdbserver_state.fd, &ch, 1, 0); if (ret < 0) { if (errno == ECONNRESET) - s->fd = -1; + gdbserver_state.fd = -1; if (errno != EINTR) return -1; } else if (ret == 0) { - close(s->fd); - s->fd = -1; + close(gdbserver_state.fd); + gdbserver_state.fd = -1; return -1; } else { break; @@ -449,11 +449,11 @@ int use_gdb_syscalls(void) } /* Resume execution. */ -static inline void gdb_continue(GDBState *s) +static inline void gdb_continue(void) { #ifdef CONFIG_USER_ONLY - s->running_state = 1; + gdbserver_state.running_state = 1; trace_gdbstub_op_continue(); #else if (!runstate_needs_reset()) { @@ -467,7 +467,7 @@ static inline void gdb_continue(GDBState *s) * Resume execution, per CPU actions. For user-mode emulation it's * equivalent to gdb_continue. */ -static int gdb_continue_partial(GDBState *s, char *newstates) +static int gdb_continue_partial(char *newstates) { CPUState *cpu; int res = 0; @@ -482,7 +482,7 @@ static int gdb_continue_partial(GDBState *s, char *newstates) cpu_single_step(cpu, sstep_flags); } } - s->running_state = 1; + gdbserver_state.running_state = 1; #else int flag = 0; @@ -520,13 +520,13 @@ static int gdb_continue_partial(GDBState *s, char *newstates) return res; } -static void put_buffer(GDBState *s, const uint8_t *buf, int len) +static void put_buffer(const uint8_t *buf, int len) { #ifdef CONFIG_USER_ONLY int ret; while (len > 0) { - ret = send(s->fd, buf, len, 0); + ret = send(gdbserver_state.fd, buf, len, 0); if (ret < 0) { if (errno != EINTR) return; @@ -538,7 +538,7 @@ static void put_buffer(GDBState *s, const uint8_t *buf, int len) #else /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(&s->chr, buf, len); + qemu_chr_fe_write_all(&gdbserver_state.chr, buf, len); #endif } @@ -620,17 +620,18 @@ static void hexdump(const char *buf, int len, } /* return -1 if error, 0 if OK */ -static int put_packet_binary(GDBState *s, const char *buf, int len, bool dump) +static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; uint8_t *p; + uint8_t *ps = &gdbserver_state.last_packet[0]; if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPLY)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } for(;;) { - p = s->last_packet; + p = ps; *(p++) = '$'; memcpy(p, buf, len); p += len; @@ -642,11 +643,11 @@ static int put_packet_binary(GDBState *s, const char *buf, int len, bool dump) *(p++) = tohex((csum >> 4) & 0xf); *(p++) = tohex((csum) & 0xf); - s->last_packet_len = p - s->last_packet; - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + gdbserver_state.last_packet_len = p - ps; + put_buffer(ps, gdbserver_state.last_packet_len); #ifdef CONFIG_USER_ONLY - i = get_char(s); + i = get_char(); if (i < 0) return -1; if (i == '+') @@ -659,11 +660,11 @@ static int put_packet_binary(GDBState *s, const char *buf, int len, bool dump) } /* return -1 if error, 0 if OK */ -static int put_packet(GDBState *s, const char *buf) +static int put_packet(const char *buf) { trace_gdbstub_io_reply(buf); - return put_packet_binary(s, buf, strlen(buf), false); + return put_packet_binary(buf, strlen(buf), false); } /* Encode data using the encoding for 'x' packets. */ @@ -687,37 +688,38 @@ static int memtox(char *buf, const char *mem, int len) return p - buf; } -static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu) +static uint32_t gdb_get_cpu_pid(CPUState *cpu) { /* TODO: In user mode, we should use the task state PID */ if (cpu->cluster_index == UNASSIGNED_CLUSTER_INDEX) { /* Return the default process' PID */ - return s->processes[s->process_num - 1].pid; + int index = gdbserver_state.process_num - 1; + return gdbserver_state.processes[index].pid; } return cpu->cluster_index + 1; } -static GDBProcess *gdb_get_process(const GDBState *s, uint32_t pid) +static GDBProcess *gdb_get_process(uint32_t pid) { int i; if (!pid) { /* 0 means any process, we take the first one */ - return &s->processes[0]; + return &gdbserver_state.processes[0]; } - for (i = 0; i < s->process_num; i++) { - if (s->processes[i].pid == pid) { - return &s->processes[i]; + for (i = 0; i < gdbserver_state.process_num; i++) { + if (gdbserver_state.processes[i].pid == pid) { + return &gdbserver_state.processes[i]; } } return NULL; } -static GDBProcess *gdb_get_cpu_process(const GDBState *s, CPUState *cpu) +static GDBProcess *gdb_get_cpu_process(CPUState *cpu) { - return gdb_get_process(s, gdb_get_cpu_pid(s, cpu)); + return gdb_get_process(gdb_get_cpu_pid(cpu)); } static CPUState *find_cpu(uint32_t thread_id) @@ -733,13 +735,12 @@ static CPUState *find_cpu(uint32_t thread_id) return NULL; } -static CPUState *get_first_cpu_in_process(const GDBState *s, - GDBProcess *process) +static CPUState *get_first_cpu_in_process(GDBProcess *process) { CPUState *cpu; CPU_FOREACH(cpu) { - if (gdb_get_cpu_pid(s, cpu) == process->pid) { + if (gdb_get_cpu_pid(cpu) == process->pid) { return cpu; } } @@ -747,13 +748,13 @@ static CPUState *get_first_cpu_in_process(const GDBState *s, return NULL; } -static CPUState *gdb_next_cpu_in_process(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_cpu_in_process(CPUState *cpu) { - uint32_t pid = gdb_get_cpu_pid(s, cpu); + uint32_t pid = gdb_get_cpu_pid(cpu); cpu = CPU_NEXT(cpu); while (cpu) { - if (gdb_get_cpu_pid(s, cpu) == pid) { + if (gdb_get_cpu_pid(cpu) == pid) { break; } @@ -764,12 +765,12 @@ static CPUState *gdb_next_cpu_in_process(const GDBState *s, CPUState *cpu) } /* Return the cpu following @cpu, while ignoring unattached processes. */ -static CPUState *gdb_next_attached_cpu(const GDBState *s, CPUState *cpu) +static CPUState *gdb_next_attached_cpu(CPUState *cpu) { cpu = CPU_NEXT(cpu); while (cpu) { - if (gdb_get_cpu_process(s, cpu)->attached) { + if (gdb_get_cpu_process(cpu)->attached) { break; } @@ -780,29 +781,29 @@ static CPUState *gdb_next_attached_cpu(const GDBState *s, CPUState *cpu) } /* Return the first attached cpu */ -static CPUState *gdb_first_attached_cpu(const GDBState *s) +static CPUState *gdb_first_attached_cpu(void) { CPUState *cpu = first_cpu; - GDBProcess *process = gdb_get_cpu_process(s, cpu); + GDBProcess *process = gdb_get_cpu_process(cpu); if (!process->attached) { - return gdb_next_attached_cpu(s, cpu); + return gdb_next_attached_cpu(cpu); } return cpu; } -static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) +static CPUState *gdb_get_cpu(uint32_t pid, uint32_t tid) { GDBProcess *process; CPUState *cpu; if (!pid && !tid) { /* 0 means any process/thread, we take the first attached one */ - return gdb_first_attached_cpu(s); + return gdb_first_attached_cpu(); } else if (pid && !tid) { /* any thread in a specific process */ - process = gdb_get_process(s, pid); + process = gdb_get_process(pid); if (process == NULL) { return NULL; @@ -812,7 +813,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) return NULL; } - return get_first_cpu_in_process(s, process); + return get_first_cpu_in_process(process); } else { /* a specific thread */ cpu = find_cpu(tid); @@ -821,7 +822,7 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) return NULL; } - process = gdb_get_cpu_process(s, cpu); + process = gdb_get_cpu_process(cpu); if (pid && process->pid != pid) { return NULL; @@ -835,13 +836,13 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) } } -static const char *get_feature_xml(const GDBState *s, const char *p, - const char **newp, GDBProcess *process) +static const char *get_feature_xml(const char *p, const char **newp, + GDBProcess *process) { size_t len; int i; const char *name; - CPUState *cpu = get_first_cpu_in_process(s, process); + CPUState *cpu = get_first_cpu_in_process(process); CPUClass *cc = CPU_GET_CLASS(cpu); len = 0; @@ -1076,13 +1077,13 @@ static inline void gdb_cpu_breakpoint_remove_all(CPUState *cpu) #endif } -static void gdb_process_breakpoint_remove_all(const GDBState *s, GDBProcess *p) +static void gdb_process_breakpoint_remove_all(GDBProcess *p) { - CPUState *cpu = get_first_cpu_in_process(s, p); + CPUState *cpu = get_first_cpu_in_process(p); while (cpu) { gdb_cpu_breakpoint_remove_all(cpu); - cpu = gdb_next_cpu_in_process(s, cpu); + cpu = gdb_next_cpu_in_process(cpu); } } @@ -1100,20 +1101,19 @@ static void gdb_breakpoint_remove_all(void) } } -static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) +static void gdb_set_cpu_pc(target_ulong pc) { - CPUState *cpu = s->c_cpu; + CPUState *cpu = gdbserver_state.c_cpu; cpu_synchronize_state(cpu); cpu_set_pc(cpu, pc); } -static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, - char *buf, size_t buf_size) +static char *gdb_fmt_thread_id(CPUState *cpu, char *buf, size_t buf_size) { - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { snprintf(buf, buf_size, "p%02x.%02x", - gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu)); + gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); } else { snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); } @@ -1180,7 +1180,7 @@ static GDBThreadIdKind read_thread_id(const char *buf, const char **end_buf, * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if there is * a format error, 0 on success. */ -static int gdb_handle_vcont(GDBState *s, const char *p) +static int gdb_handle_vcont(const char *p) { int res, signal = 0; char cur_action; @@ -1255,36 +1255,36 @@ static int gdb_handle_vcont(GDBState *s, const char *p) goto out; case GDB_ALL_PROCESSES: - cpu = gdb_first_attached_cpu(s); + cpu = gdb_first_attached_cpu(); while (cpu) { if (newstates[cpu->cpu_index] == 1) { newstates[cpu->cpu_index] = cur_action; } - cpu = gdb_next_attached_cpu(s, cpu); + cpu = gdb_next_attached_cpu(cpu); } break; case GDB_ALL_THREADS: - process = gdb_get_process(s, pid); + process = gdb_get_process(pid); if (!process->attached) { res = -EINVAL; goto out; } - cpu = get_first_cpu_in_process(s, process); + cpu = get_first_cpu_in_process(process); while (cpu) { if (newstates[cpu->cpu_index] == 1) { newstates[cpu->cpu_index] = cur_action; } - cpu = gdb_next_cpu_in_process(s, cpu); + cpu = gdb_next_cpu_in_process(cpu); } break; case GDB_ONE_THREAD: - cpu = gdb_get_cpu(s, pid, tid); + cpu = gdb_get_cpu(pid, tid); /* invalid CPU/thread specified */ if (!cpu) { @@ -1299,8 +1299,8 @@ static int gdb_handle_vcont(GDBState *s, const char *p) break; } } - s->signal = signal; - gdb_continue_partial(s, newstates); + gdbserver_state.signal = signal; + gdb_continue_partial(newstates); out: g_free(newstates); @@ -1409,7 +1409,6 @@ static int cmd_parse_params(const char *data, const char *schema, } typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH]; @@ -1453,7 +1452,7 @@ static inline int startswith(const char *string, const char *pattern) return !strncmp(string, pattern, strlen(pattern)); } -static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, +static int process_string_cmd(void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { int i, schema_len, max_num_params = 0; @@ -1490,7 +1489,6 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, return -1; } - gdb_ctx.s = s; cmd->handler(&gdb_ctx, user_ctx); return 0; } @@ -1498,8 +1496,7 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, return -1; } -static void run_cmd_parser(GDBState *s, const char *data, - const GdbCmdParseEntry *cmd) +static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) { if (!data) { return; @@ -1507,44 +1504,43 @@ static void run_cmd_parser(GDBState *s, const char *data, /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ - if (process_string_cmd(s, NULL, data, cmd, 1)) { - put_packet(s, ""); + if (process_string_cmd(NULL, data, cmd, 1)) { + put_packet(""); } } static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) { GDBProcess *process; - GDBState *s = gdb_ctx->s; uint32_t pid = 1; - if (s->multiprocess) { + if (gdbserver_state.multiprocess) { if (!gdb_ctx->num_params) { - put_packet(s, "E22"); + put_packet("E22"); return; } pid = gdb_ctx->params[0].val_ul; } - process = gdb_get_process(s, pid); - gdb_process_breakpoint_remove_all(s, process); + process = gdb_get_process(pid); + gdb_process_breakpoint_remove_all(process); process->attached = false; - if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { - s->c_cpu = gdb_first_attached_cpu(s); + if (pid == gdb_get_cpu_pid(gdbserver_state.c_cpu)) { + gdbserver_state.c_cpu = gdb_first_attached_cpu(); } - if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { - s->g_cpu = gdb_first_attached_cpu(s); + if (pid == gdb_get_cpu_pid(gdbserver_state.g_cpu)) { + gdbserver_state.g_cpu = gdb_first_attached_cpu(); } - if (!s->c_cpu) { + if (!gdbserver_state.c_cpu) { /* No more process attached */ gdb_syscall_mode = GDB_SYS_DISABLED; - gdb_continue(s); + gdb_continue(); } - put_packet(s, "OK"); + put_packet("OK"); } static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1552,33 +1548,33 @@ static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) CPUState *cpu; if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } if (gdb_ctx->params[0].thread_id.kind == GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } - cpu = gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu = gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } static void handle_continue(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, gdb_ctx->params[0].val_ull); + gdb_set_cpu_pc(gdb_ctx->params[0].val_ull); } - gdb_ctx->s->signal = 0; - gdb_continue(gdb_ctx->s); + gdbserver_state.signal = 0; + gdb_continue(); } static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1593,11 +1589,11 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) signal = gdb_ctx->params[0].val_ul; } - gdb_ctx->s->signal = gdb_signal_to_target(signal); - if (gdb_ctx->s->signal == -1) { - gdb_ctx->s->signal = 0; + gdbserver_state.signal = gdb_signal_to_target(signal); + if (gdbserver_state.signal == -1) { + gdbserver_state.signal = 0; } - gdb_continue(gdb_ctx->s); + gdb_continue(); } static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1605,24 +1601,24 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) CPUState *cpu; if (gdb_ctx->num_params != 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } if (gdb_ctx->params[1].thread_id.kind == GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } if (gdb_ctx->params[1].thread_id.kind != GDB_ONE_THREAD) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } - cpu = gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[1].thread_id.pid, + cpu = gdb_get_cpu(gdb_ctx->params[1].thread_id.pid, gdb_ctx->params[1].thread_id.tid); if (!cpu) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } @@ -1632,15 +1628,15 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) */ switch (gdb_ctx->params[0].opcode) { case 'c': - gdb_ctx->s->c_cpu = cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.c_cpu = cpu; + put_packet("OK"); break; case 'g': - gdb_ctx->s->g_cpu = cpu; - put_packet(gdb_ctx->s, "OK"); + gdbserver_state.g_cpu = cpu; + put_packet("OK"); break; default: - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); break; } } @@ -1650,7 +1646,7 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) int res; if (gdb_ctx->num_params != 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } @@ -1658,14 +1654,14 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >= 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res == -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1673,7 +1669,7 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) int res; if (gdb_ctx->num_params != 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } @@ -1681,14 +1677,14 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_ctx->params[1].val_ull, gdb_ctx->params[2].val_ull); if (res >= 0) { - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); return; } else if (res == -ENOSYS) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } /* @@ -1707,20 +1703,20 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) int reg_size; if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } if (gdb_ctx->num_params != 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } reg_size = strlen(gdb_ctx->params[1].data) / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size); - gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + gdb_write_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1728,73 +1724,73 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) int reg_size; if (!gdb_has_xml) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } - reg_size = gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + reg_size = gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0].val_ull); if (!reg_size) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params != 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } /* hextomem() reads 2*len bytes */ if (gdb_ctx->params[1].val_ull > strlen(gdb_ctx->params[2].data) / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } hextomem(gdb_ctx->mem_buf, gdb_ctx->params[2].data, gdb_ctx->params[1].val_ull); - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_ull, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, true)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params != 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } /* memtohex() doubles the required space */ if (gdb_ctx->params[1].val_ull > MAX_PACKET_LENGTH / 2) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } - if (target_memory_rw_debug(gdb_ctx->s->g_cpu, gdb_ctx->params[0].val_ull, + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull, false)) { - put_packet(gdb_ctx->s, "E14"); + put_packet("E14"); return; } memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1807,37 +1803,37 @@ static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); registers = gdb_ctx->mem_buf; len = strlen(gdb_ctx->params[0].data) / 2; hextomem(registers, gdb_ctx->params[0].data, len); - for (addr = 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs && len > 0; + for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len > 0; addr++) { - reg_size = gdb_write_register(gdb_ctx->s->g_cpu, registers, addr); + reg_size = gdb_write_register(gdbserver_state.g_cpu, registers, addr); len -= reg_size; registers += reg_size; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) { target_ulong addr, len; - cpu_synchronize_state(gdb_ctx->s->g_cpu); + cpu_synchronize_state(gdbserver_state.g_cpu); len = 0; - for (addr = 0; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs; addr++) { - len += gdb_read_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf + len, + for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++) { + len += gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf + len, addr); } memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) { - if (gdb_ctx->num_params >= 1 && gdb_ctx->s->current_syscall_cb) { + if (gdb_ctx->num_params >= 1 && gdbserver_state.current_syscall_cb) { target_ulong ret, err; ret = (target_ulong)gdb_ctx->params[0].val_ull; @@ -1846,31 +1842,31 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) } else { err = 0; } - gdb_ctx->s->current_syscall_cb(gdb_ctx->s->c_cpu, ret, err); - gdb_ctx->s->current_syscall_cb = NULL; + gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err); + gdbserver_state.current_syscall_cb = NULL; } if (gdb_ctx->num_params >= 3 && gdb_ctx->params[2].opcode == (uint8_t)'C') { - put_packet(gdb_ctx->s, "T02"); + put_packet("T02"); return; } - gdb_continue(gdb_ctx->s); + gdb_continue(); } static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) { if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->s, (target_ulong)gdb_ctx->params[0].val_ull); + gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull); } - cpu_single_step(gdb_ctx->s->c_cpu, sstep_flags); - gdb_continue(gdb_ctx->s); + cpu_single_step(gdbserver_state.c_cpu, sstep_flags); + gdb_continue(); } static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, "vCont;c;C;s;S"); + put_packet("vCont;c;C;s;S"); } static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1881,11 +1877,11 @@ static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - res = gdb_handle_vcont(gdb_ctx->s, gdb_ctx->params[0].data); + res = gdb_handle_vcont(gdb_ctx->params[0].data); if ((res == -EINVAL) || (res == -ERANGE)) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); } else if (res) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } @@ -1900,31 +1896,31 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) goto cleanup; } - process = gdb_get_process(gdb_ctx->s, gdb_ctx->params[0].val_ul); + process = gdb_get_process(gdb_ctx->params[0].val_ul); if (!process) { goto cleanup; } - cpu = get_first_cpu_in_process(gdb_ctx->s, process); + cpu = get_first_cpu_in_process(process); if (!cpu) { goto cleanup; } process->attached = true; - gdb_ctx->s->g_cpu = cpu; - gdb_ctx->s->c_cpu = cpu; + gdbserver_state.g_cpu = cpu; + gdbserver_state.c_cpu = cpu; - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); cleanup: - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) { /* Kill the target */ - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); error_report("QEMU: Terminated via GDBstub"); exit(0); } @@ -1961,10 +1957,10 @@ static void handle_v_commands(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } @@ -1973,7 +1969,7 @@ static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user_ctx) snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1983,13 +1979,13 @@ static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) } sstep_flags = gdb_ctx->params[0].val_ul; - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%x", sstep_flags); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2003,33 +1999,32 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) * the first thread of the current process (gdb returns the * first thread). */ - process = gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cpu = get_first_cpu_in_process(gdb_ctx->s, process); - gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + process = gdb_get_cpu_process(gdbserver_state.g_cpu); + cpu = get_first_cpu_in_process(process); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "QC%s", thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { char thread_id[16]; - if (!gdb_ctx->s->query_cpu) { - put_packet(gdb_ctx->s, "l"); + if (!gdbserver_state.query_cpu) { + put_packet("l"); return; } - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->query_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.query_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "m%s", thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); - gdb_ctx->s->query_cpu = - gdb_next_attached_cpu(gdb_ctx->s, gdb_ctx->s->query_cpu); + put_packet(gdb_ctx->str_buf); + gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu); } static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { - gdb_ctx->s->query_cpu = gdb_first_attached_cpu(gdb_ctx->s); + gdbserver_state.query_cpu = gdb_first_attached_cpu(); handle_query_threads(gdb_ctx, user_ctx); } @@ -2040,11 +2035,11 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) if (!gdb_ctx->num_params || gdb_ctx->params[0].thread_id.kind == GDB_READ_THREAD_ERR) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } - cpu = gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[0].thread_id.pid, + cpu = gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, gdb_ctx->params[0].thread_id.tid); if (!cpu) { return; @@ -2052,7 +2047,7 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) cpu_synchronize_state(cpu); - if (gdb_ctx->s->multiprocess && (gdb_ctx->s->process_num > 1)) { + if (gdbserver_state.multiprocess && (gdbserver_state.process_num > 1)) { /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc = object_get_class(OBJECT(cpu)); const char *cpu_model = object_class_get_name(oc); @@ -2069,7 +2064,7 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) } trace_gdbstub_op_extra_info((char *)gdb_ctx->mem_buf); memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } #ifdef CONFIG_USER_ONLY @@ -2077,14 +2072,14 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) { TaskState *ts; - ts = gdb_ctx->s->c_cpu->opaque; + ts = gdbserver_state.c_cpu->opaque; snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx ";Bss=" TARGET_ABI_FMT_lx, ts->info->code_offset, ts->info->data_offset, ts->info->data_offset); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2092,21 +2087,21 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) int len; if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } len = strlen(gdb_ctx->params[0].data); if (len % 2) { - put_packet(gdb_ctx->s, "E01"); + put_packet("E01"); return; } len = len / 2; hextomem(gdb_ctx->mem_buf, gdb_ctx->params[0].data, len); gdb_ctx->mem_buf[len++] = 0; - qemu_chr_be_write(gdb_ctx->s->mon_chr, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->s, "OK"); + qemu_chr_be_write(gdbserver_state.mon_chr, gdb_ctx->mem_buf, len); + put_packet("OK"); } #endif @@ -2125,11 +2120,11 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) if (gdb_ctx->num_params && strstr(gdb_ctx->params[0].data, "multiprocess+")) { - gdb_ctx->s->multiprocess = true; + gdbserver_state.multiprocess = true; } pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";multiprocess+"); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2141,22 +2136,22 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) const char *p; if (gdb_ctx->num_params < 3) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } - process = gdb_get_cpu_process(gdb_ctx->s, gdb_ctx->s->g_cpu); - cc = CPU_GET_CLASS(gdb_ctx->s->g_cpu); + process = gdb_get_cpu_process(gdbserver_state.g_cpu); + cc = CPU_GET_CLASS(gdbserver_state.g_cpu); if (!cc->gdb_core_xml_file) { - put_packet(gdb_ctx->s, ""); + put_packet(""); return; } gdb_has_xml = true; p = gdb_ctx->params[0].data; - xml = get_feature_xml(gdb_ctx->s, p, &p, process); + xml = get_feature_xml(p, &p, process); if (!xml) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } @@ -2164,7 +2159,7 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) len = gdb_ctx->params[2].val_ul; total_len = strlen(xml); if (addr > total_len) { - put_packet(gdb_ctx->s, "E00"); + put_packet("E00"); return; } @@ -2180,12 +2175,12 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) len = memtox(gdb_ctx->str_buf + 1, xml + addr, total_len - addr); } - put_packet_binary(gdb_ctx->s, gdb_ctx->str_buf, len + 1, true); + put_packet_binary(gdb_ctx->str_buf, len + 1, true); } static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) { - put_packet(gdb_ctx->s, GDB_ATTACHED); + put_packet(GDB_ATTACHED); } static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2194,7 +2189,7 @@ static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx) #ifndef CONFIG_USER_ONLY pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";PhyMemMode"); #endif - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } #ifndef CONFIG_USER_ONLY @@ -2202,13 +2197,13 @@ static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) { snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d", phy_memory_mode); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); } static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) { if (!gdb_ctx->num_params) { - put_packet(gdb_ctx->s, "E22"); + put_packet("E22"); return; } @@ -2217,7 +2212,7 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) } else { phy_memory_mode = 1; } - put_packet(gdb_ctx->s, "OK"); + put_packet("OK"); } #endif @@ -2333,16 +2328,16 @@ static void handle_gen_query(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } @@ -2352,16 +2347,16 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } - if (process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, gdb_ctx->params[0].data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { - put_packet(gdb_ctx->s, ""); + put_packet(""); } } @@ -2369,11 +2364,11 @@ static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) { char thread_id[16]; - gdb_fmt_thread_id(gdb_ctx->s, gdb_ctx->s->c_cpu, thread_id, + gdb_fmt_thread_id(gdbserver_state.c_cpu, thread_id, sizeof(thread_id)); snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, thread_id); - put_packet(gdb_ctx->s, gdb_ctx->str_buf); + put_packet(gdb_ctx->str_buf); /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -2382,7 +2377,7 @@ static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_breakpoint_remove_all(); } -static int gdb_handle_packet(GDBState *s, const char *line_buf) +static int gdb_handle_packet(const char *line_buf) { const GdbCmdParseEntry *cmd_parser = NULL; @@ -2390,7 +2385,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) switch (line_buf[0]) { case '!': - put_packet(s, "OK"); + put_packet("OK"); break; case '?': { @@ -2605,12 +2600,12 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) break; default: /* put empty packet */ - put_packet(s, ""); + put_packet(""); break; } if (cmd_parser) { - run_cmd_parser(s, line_buf, cmd_parser); + run_cmd_parser(line_buf, cmd_parser); } return RS_IDLE; @@ -2618,7 +2613,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) void gdb_set_stop_cpu(CPUState *cpu) { - GDBProcess *p = gdb_get_cpu_process(&gdbserver_state, cpu); + GDBProcess *p = gdb_get_cpu_process(cpu); if (!p->attached) { /* @@ -2635,19 +2630,18 @@ void gdb_set_stop_cpu(CPUState *cpu) #ifndef CONFIG_USER_ONLY static void gdb_vm_state_change(void *opaque, int running, RunState state) { - GDBState *s = &gdbserver_state; - CPUState *cpu = s->c_cpu; + CPUState *cpu = gdbserver_state.c_cpu; char buf[256]; char thread_id[16]; const char *type; int ret; - if (running || s->state == RS_INACTIVE) { + if (running || gdbserver_state.state == RS_INACTIVE) { return; } /* Is there a GDB syscall waiting to be sent? */ - if (s->current_syscall_cb) { - put_packet(s, s->syscall_buf); + if (gdbserver_state.current_syscall_cb) { + put_packet(gdbserver_state.syscall_buf); return; } @@ -2656,7 +2650,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) return; } - gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id)); + gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); switch (state) { case RUN_STATE_DEBUG: @@ -2721,7 +2715,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); send_packet: - put_packet(s, buf); + put_packet(buf); /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -2740,8 +2734,9 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) target_ulong addr; uint64_t i64; - if (!gdbserver_state.init) + if (!gdbserver_state.init) { return; + } gdbserver_state.current_syscall_cb = cb; #ifndef CONFIG_USER_ONLY @@ -2781,7 +2776,7 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } *p = 0; #ifdef CONFIG_USER_ONLY - put_packet(&gdbserver_state, gdbserver_state.syscall_buf); + put_packet(gdbserver_state.syscall_buf); /* Return control to gdb for it to process the syscall request. * Since the protocol requires that gdb hands control back to us * using a "here are the results" F packet, we don't need to check @@ -2809,17 +2804,17 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) va_end(va); } -static void gdb_read_byte(GDBState *s, uint8_t ch) +static void gdb_read_byte(uint8_t ch) { uint8_t reply; #ifndef CONFIG_USER_ONLY - if (s->last_packet_len) { + if (gdbserver_state.last_packet_len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch == '-') { trace_gdbstub_err_got_nack(); - put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_state.last_packet_len); } else if (ch == '+') { trace_gdbstub_io_got_ack(); } else { @@ -2827,7 +2822,7 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } if (ch == '+' || ch == '$') - s->last_packet_len = 0; + gdbserver_state.last_packet_len = 0; if (ch != '$') return; } @@ -2838,13 +2833,13 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) } else #endif { - switch(s->state) { + switch(gdbserver_state.state) { case RS_IDLE: if (ch == '$') { /* start of command packet */ - s->line_buf_index = 0; - s->line_sum = 0; - s->state = RS_GETLINE; + gdbserver_state.line_buf_index = 0; + gdbserver_state.line_sum = 0; + gdbserver_state.state = RS_GETLINE; } else { trace_gdbstub_err_garbage(ch); } @@ -2852,37 +2847,37 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) case RS_GETLINE: if (ch == '}') { /* start escape sequence */ - s->state = RS_GETLINE_ESC; - s->line_sum += ch; + gdbserver_state.state = RS_GETLINE_ESC; + gdbserver_state.line_sum += ch; } else if (ch == '*') { /* start run length encoding sequence */ - s->state = RS_GETLINE_RLE; - s->line_sum += ch; + gdbserver_state.state = RS_GETLINE_RLE; + gdbserver_state.line_sum += ch; } else if (ch == '#') { /* end of command, start of checksum*/ - s->state = RS_CHKSUM1; - } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { + gdbserver_state.state = RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >= sizeof(gdbserver_state.line_buf) - 1) { trace_gdbstub_err_overrun(); - s->state = RS_IDLE; + gdbserver_state.state = RS_IDLE; } else { /* unescaped command character */ - s->line_buf[s->line_buf_index++] = ch; - s->line_sum += ch; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++] = ch; + gdbserver_state.line_sum += ch; } break; case RS_GETLINE_ESC: if (ch == '#') { /* unexpected end of command in escape sequence */ - s->state = RS_CHKSUM1; - } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { + gdbserver_state.state = RS_CHKSUM1; + } else if (gdbserver_state.line_buf_index >= sizeof(gdbserver_state.line_buf) - 1) { /* command buffer overrun */ trace_gdbstub_err_overrun(); - s->state = RS_IDLE; + gdbserver_state.state = RS_IDLE; } else { /* parse escaped character and leave escape state */ - s->line_buf[s->line_buf_index++] = ch ^ 0x20; - s->line_sum += ch; - s->state = RS_GETLINE; + gdbserver_state.line_buf[gdbserver_state.line_buf_index++] = ch ^ 0x20; + gdbserver_state.line_sum += ch; + gdbserver_state.state = RS_GETLINE; } break; case RS_GETLINE_RLE: @@ -2893,25 +2888,25 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) if (ch < ' ' || ch == '#' || ch == '$' || ch > 126) { /* invalid RLE count encoding */ trace_gdbstub_err_invalid_repeat(ch); - s->state = RS_GETLINE; + gdbserver_state.state = RS_GETLINE; } else { /* decode repeat length */ int repeat = ch - ' ' + 3; - if (s->line_buf_index + repeat >= sizeof(s->line_buf) - 1) { + if (gdbserver_state.line_buf_index + repeat >= sizeof(gdbserver_state.line_buf) - 1) { /* that many repeats would overrun the command buffer */ trace_gdbstub_err_overrun(); - s->state = RS_IDLE; - } else if (s->line_buf_index < 1) { + gdbserver_state.state = RS_IDLE; + } else if (gdbserver_state.line_buf_index < 1) { /* got a repeat but we have nothing to repeat */ trace_gdbstub_err_invalid_rle(); - s->state = RS_GETLINE; + gdbserver_state.state = RS_GETLINE; } else { /* repeat the last character */ - memset(s->line_buf + s->line_buf_index, - s->line_buf[s->line_buf_index - 1], repeat); - s->line_buf_index += repeat; - s->line_sum += ch; - s->state = RS_GETLINE; + memset(gdbserver_state.line_buf + gdbserver_state.line_buf_index, + gdbserver_state.line_buf[gdbserver_state.line_buf_index - 1], repeat); + gdbserver_state.line_buf_index += repeat; + gdbserver_state.line_sum += ch; + gdbserver_state.state = RS_GETLINE; } } break; @@ -2919,33 +2914,33 @@ static void gdb_read_byte(GDBState *s, uint8_t ch) /* get high hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state = RS_GETLINE; + gdbserver_state.state = RS_GETLINE; break; } - s->line_buf[s->line_buf_index] = '\0'; - s->line_csum = fromhex(ch) << 4; - s->state = RS_CHKSUM2; + gdbserver_state.line_buf[gdbserver_state.line_buf_index] = '\0'; + gdbserver_state.line_csum = fromhex(ch) << 4; + gdbserver_state.state = RS_CHKSUM2; break; case RS_CHKSUM2: /* get low hex digit of checksum */ if (!isxdigit(ch)) { trace_gdbstub_err_checksum_invalid(ch); - s->state = RS_GETLINE; + gdbserver_state.state = RS_GETLINE; break; } - s->line_csum |= fromhex(ch); + gdbserver_state.line_csum |= fromhex(ch); - if (s->line_csum != (s->line_sum & 0xff)) { - trace_gdbstub_err_checksum_incorrect(s->line_sum, s->line_csum); + if (gdbserver_state.line_csum != (gdbserver_state.line_sum & 0xff)) { + trace_gdbstub_err_checksum_incorrect(gdbserver_state.line_sum, gdbserver_state.line_csum); /* send NAK reply */ reply = '-'; - put_buffer(s, &reply, 1); - s->state = RS_IDLE; + put_buffer(&reply, 1); + gdbserver_state.state = RS_IDLE; } else { /* send ACK reply */ reply = '+'; - put_buffer(s, &reply, 1); - s->state = gdb_handle_packet(s, s->line_buf); + put_buffer(&reply, 1); + gdbserver_state.state = gdb_handle_packet(gdbserver_state.line_buf); } break; default: @@ -2971,7 +2966,7 @@ void gdb_exit(CPUArchState *env, int code) trace_gdbstub_op_exiting((uint8_t)code); snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code); - put_packet(&gdbserver_state, buf); + put_packet(buf); #ifndef CONFIG_USER_ONLY qemu_chr_fe_deinit(&gdbserver_state.chr, true); @@ -2988,7 +2983,7 @@ static void create_default_process(GDBState *s) GDBProcess *process; int max_pid = 0; - if (s->process_num) { + if (gdbserver_state.process_num) { max_pid = s->processes[s->process_num - 1].pid; } @@ -3020,7 +3015,7 @@ gdb_handlesig(CPUState *cpu, int sig) if (sig != 0) { snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } /* put_packet() might have detected that the peer terminated the connection. */ @@ -3037,7 +3032,7 @@ gdb_handlesig(CPUState *cpu, int sig) int i; for (i = 0; i < n; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } else { /* XXX: Connection closed. Should probably wait for another @@ -3064,7 +3059,7 @@ void gdb_signalled(CPUArchState *env, int sig) } snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb(sig)); - put_packet(&gdbserver_state, buf); + put_packet(buf); } static bool gdb_accept(void) @@ -3095,7 +3090,7 @@ static bool gdb_accept(void) init_gdbserver_state(); create_default_process(&gdbserver_state); gdbserver_state.processes[0].attached = true; - gdbserver_state.c_cpu = gdb_first_attached_cpu(&gdbserver_state); + gdbserver_state.c_cpu = gdb_first_attached_cpu(); gdbserver_state.g_cpu = gdbserver_state.c_cpu; gdbserver_state.fd = fd; gdb_has_xml = false; @@ -3172,7 +3167,7 @@ static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) int i; for (i = 0; i < size; i++) { - gdb_read_byte(&gdbserver_state, buf[i]); + gdb_read_byte(buf[i]); } } @@ -3188,7 +3183,7 @@ static void gdb_chr_event(void *opaque, int event) s->processes[i].attached = !i; } - s->c_cpu = gdb_first_attached_cpu(s); + s->c_cpu = gdb_first_attached_cpu(); s->g_cpu = s->c_cpu; vm_stop(RUN_STATE_PAUSED); @@ -3199,7 +3194,7 @@ static void gdb_chr_event(void *opaque, int event) } } -static void gdb_monitor_output(GDBState *s, const char *msg, int len) +static void gdb_monitor_output(const char *msg, int len) { char buf[MAX_PACKET_LENGTH]; @@ -3207,7 +3202,7 @@ static void gdb_monitor_output(GDBState *s, const char *msg, int len) if (len > (MAX_PACKET_LENGTH/2) - 1) len = (MAX_PACKET_LENGTH/2) - 1; memtohex(buf + 1, (uint8_t *)msg, len); - put_packet(s, buf); + put_packet(buf); } static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) @@ -3218,10 +3213,10 @@ static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) max_sz = (sizeof(gdbserver_state.last_packet) - 2) / 2; for (;;) { if (len <= max_sz) { - gdb_monitor_output(&gdbserver_state, p, len); + gdb_monitor_output(p, len); break; } - gdb_monitor_output(&gdbserver_state, p, max_sz); + gdb_monitor_output(p, max_sz); p += max_sz; len -= max_sz; } @@ -3305,9 +3300,9 @@ static void create_processes(GDBState *s) { object_child_foreach(object_get_root(), find_cpu_clusters, s); - if (s->processes) { + if (gdbserver_state.processes) { /* Sort by PID */ - qsort(s->processes, s->process_num, sizeof(s->processes[0]), pid_order); + qsort(gdbserver_state.processes, gdbserver_state.process_num, sizeof(gdbserver_state.processes[0]), pid_order); } create_default_process(s); @@ -3387,7 +3382,7 @@ int gdbserver_start(const char *device) void gdbserver_cleanup(void) { if (gdbserver_state.init) { - put_packet(&gdbserver_state, "W00"); + put_packet("W00"); } } From patchwork Fri Dec 20 12:04:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182244 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp434011ilf; Fri, 20 Dec 2019 04:05:23 -0800 (PST) X-Google-Smtp-Source: APXvYqy+uw/6VgdE5XTxm+NNt7zRjQu7vyHzd4cWx8MTwxLHZETUS3PusAN/qBkmGhRqcbnFXcZb X-Received: by 2002:ad4:4511:: with SMTP id k17mr11467762qvu.135.1576843522964; Fri, 20 Dec 2019 04:05:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843522; cv=none; d=google.com; s=arc-20160816; b=sBZUDgohWjVwIK9ExU6oAnUk/8SbWWff60ZLpORXlCr8hMwf8glSwMfEMLfsHHhle8 cfQI9CWX9epVV9l326tt6BaJ6r0xtWqZFfEBYWZh0ftDAx7b10/KNDuZ2ODJBqd1+1MX ZJPhEiUBKW0OOTlh+M/U9wGPOOnOoqUDRjm/283FWdGpGW+aapVXiswyp/cv8fR3MLeZ aTr4F8QnhL9sXDIYn8WjBE7QAuEGrtfgAhnXym9cOB3ORCohq9G5zD6Ade0kvvBwITI9 U7yJtkc+C335Ex4mX+m+F9Lwut0tkzoOX06PsdUhL/7qg0k5HMgE0lf3kOpM7vPz6pKs 7PIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=MJOYXxTVLX53H7uYRIw9rYoUQgaz2ynGUUiMSuMBAbBC/Osf8l88+bwzbtN/zaOvJb LN7/h0yQX1jJ9rDxbSSQfDjy80sGUH/ZU1dXrtCPHYEgHgQTNC721LgII2+zH6OBxwK5 TviOdK7Dy+b+TL8CYxOleJDQJChIIJOdseWQHOLvLbkbhnAOc87y4efWoK1l6Z9OUu+f W98ZnN3dTEvVw5TZ9THMj9/Kzj++AxsuPGU42HvYP1IpOjg2DJ6YBonUrg1GF2CVDEDR O3/ikKKRvsHE2MVNzSXcuLZxrnAlCFh/pPiark73c+fmdhi+B2Qg89ywPvFtsSp0t5g2 QjLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=q7TmYNKW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h28si5141326qkl.158.2019.12.20.04.05.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:05:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=q7TmYNKW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH21-0004jm-V7 for patch@linaro.org; Fri, 20 Dec 2019 07:05:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1V-0004eJ-V0 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1T-0007VF-DJ for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:35139) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1S-0007Qn-ST for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:47 -0500 Received: by mail-wm1-x341.google.com with SMTP id p17so8999928wmb.0 for ; Fri, 20 Dec 2019 04:04:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=q7TmYNKWU5PtbBxYlqGHX6d0UF1Sh7xr+8MrmolwyK49r9W619SkSTzjX7n7pza6Qn rc6dlJRvCwuv7vZZKgoQjqwdk9GDmcCDGMyqMaPUlXHMjIHD1eO6xCeZ/5GzVnWqBWFR R67PHSNxpCl538ZmulzmByvFlfEArdGpp1Kv0F+k3AYeXKGBaBp54Z7gtliSW9kodAfW Xhi3iYVX2bJJDQ9S6BmfDyC87Y+T7AL2yIFdGIZ3c6TjAz4EAaJ0X30RNFtuok7EaIS1 IDK28rwAlmGhVhbac7W20dKldP5bll3A1ivN3LVQRWAyPoV2Yk9BpqRXiCNPkRj/9/DD LjvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RRppQbj+sXywUjOQA2w87Jf3PtvabL0PQyQmHfRcQXo=; b=tioB8MUbcpD+Dd0nYCqa85faHbvoLHpKgS2hxZc6799C1Fuq1A545kbACUjMGEjUYB Y658zcNYiIbCRS99gI/zccsyvzR8udOydJq6obOK5oNZBx1PRvtaGc5k9q3ksLX5H0km x42p1A75fy7Mb30QJ30Mn62nKdbHmHXqw4/yMu3KDFzxwW38XN2J0TXqOUdOevYyk/8r j8DQQ6QSLowWnR7JLGprZxF+r3QfVHaIfo9G+uzInD9YLFaWnJyCzF/bPmb9CKie2XGE SyOel7z126Pi10UnePgcOTHdDNaLcukqsRBNoYnjHBkJeLxZoHpzYlFTZgcO3aEUx38x FhEw== X-Gm-Message-State: APjAAAUaTBiglyE4tpj4a9cnJBuTDiO15fLxSOb+Dp3VkyTivMRwOVxZ It4lTtOulbdaScqx6nnY23+LrA== X-Received: by 2002:a1c:20d3:: with SMTP id g202mr16307905wmg.169.1576843485550; Fri, 20 Dec 2019 04:04:45 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f127sm8140798wma.4.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:41 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 28A871FF90; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 03/21] gdbstub: move str_buf to GDBState and use GString Date: Fri, 20 Dec 2019 12:04:20 +0000 Message-Id: <20191220120438.16114-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rather than having a static buffer replace str_buf with a GString which we know can grow on demand. Convert the internal functions to take a GString instead of a char * and length. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde Tested-by: Damien Hedde --- v2 - fix conflict from status gdbserver_state - add put_strbuf helper v3 - remove double ;; --- gdbstub.c | 195 +++++++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 105 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 85ef7d37e08..80d99c209ff 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -366,6 +366,7 @@ typedef struct GDBState { int process_num; char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; + GString *str_buf; } GDBState; /* By default use no IRQs and no timers while single stepping so as to @@ -380,6 +381,7 @@ static void init_gdbserver_state(void) g_assert(!gdbserver_state.init); memset(&gdbserver_state, 0, sizeof(GDBState)); gdbserver_state.init = true; + gdbserver_state.str_buf = g_string_new(NULL); } #ifndef CONFIG_USER_ONLY @@ -563,17 +565,15 @@ static inline int tohex(int v) } /* writes 2*len+1 bytes in buf */ -static void memtohex(char *buf, const uint8_t *mem, int len) +static void memtohex(GString *buf, const uint8_t *mem, int len) { int i, c; - char *q; - q = buf; for(i = 0; i < len; i++) { c = mem[i]; - *q++ = tohex(c >> 4); - *q++ = tohex(c & 0xf); + g_string_append_c(buf, tohex(c >> 4)); + g_string_append_c(buf, tohex(c & 0xf)); } - *q = '\0'; + g_string_append_c(buf, '\0'); } static void hextomem(uint8_t *mem, const char *buf, int len) @@ -667,25 +667,28 @@ static int put_packet(const char *buf) return put_packet_binary(buf, strlen(buf), false); } +static void put_strbuf(void) +{ + put_packet(gdbserver_state.str_buf->str); +} + /* Encode data using the encoding for 'x' packets. */ -static int memtox(char *buf, const char *mem, int len) +static void memtox(GString *buf, const char *mem, int len) { - char *p = buf; char c; while (len--) { c = *(mem++); switch (c) { case '#': case '$': case '*': case '}': - *(p++) = '}'; - *(p++) = c ^ 0x20; + g_string_append_c(buf, '}'); + g_string_append_c(buf, c ^ 0x20); break; default: - *(p++) = c; + g_string_append_c(buf, c); break; } } - return p - buf; } static uint32_t gdb_get_cpu_pid(CPUState *cpu) @@ -1109,16 +1112,14 @@ static void gdb_set_cpu_pc(target_ulong pc) cpu_set_pc(cpu, pc); } -static char *gdb_fmt_thread_id(CPUState *cpu, char *buf, size_t buf_size) +static void gdb_append_thread_id(CPUState *cpu, GString *buf) { if (gdbserver_state.multiprocess) { - snprintf(buf, buf_size, "p%02x.%02x", - gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); + g_string_append_printf(buf, "p%02x.%02x", + gdb_get_cpu_pid(cpu), cpu_gdb_index(cpu)); } else { - snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); + g_string_append_printf(buf, "%02x", cpu_gdb_index(cpu)); } - - return buf; } typedef enum GDBThreadIdKind { @@ -1412,7 +1413,6 @@ typedef struct GdbCmdContext { GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH]; - char str_buf[MAX_PACKET_LENGTH + 1]; } GdbCmdContext; typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); @@ -1502,6 +1502,8 @@ static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) return; } + g_string_set_size(gdbserver_state.str_buf, 0); + /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ if (process_string_cmd(NULL, data, cmd, 1)) { @@ -1740,8 +1742,8 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, reg_size); + put_strbuf(); } static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1789,8 +1791,8 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull); + put_strbuf(); } static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1827,8 +1829,8 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) addr); } - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->str_buf); + memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, len); + put_strbuf(); } static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1889,9 +1891,8 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) { GDBProcess *process; CPUState *cpu; - char thread_id[16]; - pstrcpy(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "E22"); + g_string_assign(gdbserver_state.str_buf, "E22"); if (!gdb_ctx->num_params) { goto cleanup; } @@ -1910,11 +1911,11 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) gdbserver_state.g_cpu = cpu; gdbserver_state.c_cpu = cpu; - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", - GDB_SIGNAL_TRAP, thread_id); + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); cleanup: - put_packet(gdb_ctx->str_buf); + put_strbuf(); } static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1966,10 +1967,9 @@ static void handle_v_commands(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", SSTEP_ENABLE, - SSTEP_NOIRQ, SSTEP_NOTIMER); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", + SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); + put_strbuf(); } static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -1984,15 +1984,14 @@ static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "0x%x", sstep_flags); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "0x%x", sstep_flags); + put_strbuf(); } static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) { CPUState *cpu; GDBProcess *process; - char thread_id[16]; /* * "Current thread" remains vague in the spec, so always return @@ -2001,24 +2000,21 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) */ process = gdb_get_cpu_process(gdbserver_state.g_cpu); cpu = get_first_cpu_in_process(process); - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "QC%s", thread_id); - put_packet(gdb_ctx->str_buf); + g_string_assign(gdbserver_state.str_buf, "QC"); + gdb_append_thread_id(cpu, gdbserver_state.str_buf); + put_strbuf(); } static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) { - char thread_id[16]; - if (!gdbserver_state.query_cpu) { put_packet("l"); return; } - gdb_fmt_thread_id(gdbserver_state.query_cpu, thread_id, - sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "m%s", thread_id); - put_packet(gdb_ctx->str_buf); + g_string_assign(gdbserver_state.str_buf, "m"); + gdb_append_thread_id(gdbserver_state.query_cpu, gdbserver_state.str_buf); + put_strbuf(); gdbserver_state.query_cpu = gdb_next_attached_cpu(gdbserver_state.query_cpu); } @@ -2030,8 +2026,8 @@ static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) { + g_autoptr(GString) rs = g_string_new(NULL); CPUState *cpu; - int len; if (!gdb_ctx->num_params || gdb_ctx->params[0].thread_id.kind == GDB_READ_THREAD_ERR) { @@ -2051,20 +2047,17 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc = object_get_class(OBJECT(cpu)); const char *cpu_model = object_class_get_name(oc); - char *cpu_name = object_get_canonical_path_component(OBJECT(cpu)); - len = snprintf((char *)gdb_ctx->mem_buf, sizeof(gdb_ctx->str_buf) / 2, - "%s %s [%s]", cpu_model, cpu_name, - cpu->halted ? "halted " : "running"); - g_free(cpu_name); + g_autofree char *cpu_name; + cpu_name = object_get_canonical_path_component(OBJECT(cpu)); + g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name, + cpu->halted ? "halted " : "running"); } else { - /* memtohex() doubles the required space */ - len = snprintf((char *)gdb_ctx->mem_buf, sizeof(gdb_ctx->str_buf) / 2, - "CPU#%d [%s]", cpu->cpu_index, + g_string_printf(rs, "CPU#%d [%s]", cpu->cpu_index, cpu->halted ? "halted " : "running"); } - trace_gdbstub_op_extra_info((char *)gdb_ctx->mem_buf); - memtohex(gdb_ctx->str_buf, gdb_ctx->mem_buf, len); - put_packet(gdb_ctx->str_buf); + trace_gdbstub_op_extra_info(rs->str); + memtohex(gdbserver_state.str_buf, (uint8_t *)rs->str, rs->len); + put_strbuf(); } #ifdef CONFIG_USER_ONLY @@ -2073,13 +2066,14 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) TaskState *ts; ts = gdbserver_state.c_cpu->opaque; - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx - ";Bss=" TARGET_ABI_FMT_lx, - ts->info->code_offset, - ts->info->data_offset, - ts->info->data_offset); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, + "Text=" TARGET_ABI_FMT_lx + ";Data=" TARGET_ABI_FMT_lx + ";Bss=" TARGET_ABI_FMT_lx, + ts->info->code_offset, + ts->info->data_offset, + ts->info->data_offset); + put_strbuf(); } #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2110,12 +2104,10 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) { CPUClass *cc; - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "PacketSize=%x", - MAX_PACKET_LENGTH); + g_string_printf(gdbserver_state.str_buf, "PacketSize=%x", MAX_PACKET_LENGTH); cc = CPU_GET_CLASS(first_cpu); if (cc->gdb_core_xml_file) { - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), - ";qXfer:features:read+"); + g_string_append(gdbserver_state.str_buf, ";qXfer:features:read+"); } if (gdb_ctx->num_params && @@ -2123,8 +2115,8 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) gdbserver_state.multiprocess = true; } - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";multiprocess+"); - put_packet(gdb_ctx->str_buf); + g_string_append(gdbserver_state.str_buf, ";multiprocess+"); + put_strbuf(); } static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2168,14 +2160,15 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) } if (len < total_len - addr) { - gdb_ctx->str_buf[0] = 'm'; - len = memtox(gdb_ctx->str_buf + 1, xml + addr, len); + g_string_assign(gdbserver_state.str_buf, "m"); + memtox(gdbserver_state.str_buf, xml + addr, len); } else { - gdb_ctx->str_buf[0] = 'l'; - len = memtox(gdb_ctx->str_buf + 1, xml + addr, total_len - addr); + g_string_assign(gdbserver_state.str_buf, "l"); + memtox(gdbserver_state.str_buf, xml + addr, total_len - addr); } - put_packet_binary(gdb_ctx->str_buf, len + 1, true); + put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); } static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2185,19 +2178,19 @@ static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "sstepbits;sstep"); + g_string_printf(gdbserver_state.str_buf, "sstepbits;sstep"); #ifndef CONFIG_USER_ONLY - pstrcat(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), ";PhyMemMode"); + g_string_append(gdbserver_state.str_buf, ";PhyMemMode"); #endif - put_packet(gdb_ctx->str_buf); + put_strbuf(); } #ifndef CONFIG_USER_ONLY static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) { - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "%d", phy_memory_mode); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); + put_strbuf(); } static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) @@ -2362,13 +2355,10 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx) static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) { - char thread_id[16]; - - gdb_fmt_thread_id(gdbserver_state.c_cpu, thread_id, - sizeof(thread_id)); - snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", - GDB_SIGNAL_TRAP, thread_id); - put_packet(gdb_ctx->str_buf); + g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TRAP); + gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); + g_string_append_c(gdbserver_state.str_buf, ';'); + put_strbuf(); /* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state @@ -2631,8 +2621,8 @@ void gdb_set_stop_cpu(CPUState *cpu) static void gdb_vm_state_change(void *opaque, int running, RunState state) { CPUState *cpu = gdbserver_state.c_cpu; - char buf[256]; - char thread_id[16]; + g_autoptr(GString) buf = g_string_new(NULL); + g_autoptr(GString) tid = g_string_new(NULL); const char *type; int ret; @@ -2650,7 +2640,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) return; } - gdb_fmt_thread_id(cpu, thread_id, sizeof(thread_id)); + gdb_append_thread_id(cpu, tid); switch (state) { case RUN_STATE_DEBUG: @@ -2668,10 +2658,9 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) } trace_gdbstub_hit_watchpoint(type, cpu_gdb_index(cpu), (target_ulong)cpu->watchpoint_hit->vaddr); - snprintf(buf, sizeof(buf), - "T%02xthread:%s;%swatch:" TARGET_FMT_lx ";", - GDB_SIGNAL_TRAP, thread_id, type, - (target_ulong)cpu->watchpoint_hit->vaddr); + g_string_printf(buf, "T%02xthread:%s;%swatch:" TARGET_FMT_lx ";", + GDB_SIGNAL_TRAP, tid->str, type, + (target_ulong)cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit = NULL; goto send_packet; } else { @@ -2712,10 +2701,10 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) break; } gdb_set_stop_cpu(cpu); - snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); + g_string_printf(buf, "T%02xthread:%s;", ret, tid->str); send_packet: - put_packet(buf); + put_packet(buf->str); /* disable single step if it was enabled */ cpu_single_step(cpu, 0); @@ -3196,13 +3185,9 @@ static void gdb_chr_event(void *opaque, int event) static void gdb_monitor_output(const char *msg, int len) { - char buf[MAX_PACKET_LENGTH]; - - buf[0] = 'O'; - if (len > (MAX_PACKET_LENGTH/2) - 1) - len = (MAX_PACKET_LENGTH/2) - 1; - memtohex(buf + 1, (uint8_t *)msg, len); - put_packet(buf); + g_autoptr(GString) buf = g_string_new("O"); + memtohex(buf, (uint8_t *)msg, len); + put_packet(buf->str); } static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) From patchwork Fri Dec 20 12:04:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182248 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp440486ilf; Fri, 20 Dec 2019 04:10:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwf5pTUDNQqP2OAVj/XGIe+8xgl1/Fwza9PzoMsiBzk4iLrE8ik0bxTP122sbuWqqFwNvr2 X-Received: by 2002:a05:620a:166a:: with SMTP id d10mr12970346qko.37.1576843820237; Fri, 20 Dec 2019 04:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843820; cv=none; d=google.com; s=arc-20160816; b=0A/2gsCx09j3D101zjuB7A4KB5H/lsskyBDCtQkVIQKVbguJmPtALMgBQ8LzFk4oDh K9AJWHnI2z8HuVyO9vkUCAlIibuq9w0cmu4L+belBhSPBaLeuoGK5a1/u2d4bdViWuO5 L8sNG2k+LkQHajl8FZhMn2AZcbXX6Y41HewBWgnme2hix72X/AyDt4xu+Im6Kp/OE7Np 728ViGS4lcDWsdbycHjdw/cc6DPmf+WNA6oiwhEKNXmM54gEN+JGEDMqiOBtJgp/xttY +df/0MDCrsMapjQ4XYCsJvFWyUF3tIj1dGhPxJeB2CS9IW8EVeBQADnNtSlt6blJGY9L U/1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=XqVeiujiqXTUPYshKIU4y32G3h8T86t5TTlI5i/1A9yc2cHlh8VwtiogWTtXThRj/j 4tcCGWvDW3k7TwaF7VaoQrOfB6ercan+9f9MpXcIfTOnD8JxUXrGzRIZwwEqytqW+sHz IPwLykSsnERnLLnhZWbLVSlBSKhXRlyhVnZV7ocRpkOVNyge6dhuqyceYh/h/wsLueqD mGUSm4HEhE15tVPVDs8LRlcYIY9RyhMwYQvYQz9mYeVU6Sn0GnYsqLyge7DFe6ptYqxJ 2GKsOg63NiaavSGYok8eavWJLUrxWL7S++tixfvm6vm+wt3n5yMp7zKxNA4UkTDDlorm cBPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UGdI7+HZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g20si4848860qkm.184.2019.12.20.04.10.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:10:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UGdI7+HZ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH6p-0002gJ-B0 for patch@linaro.org; Fri, 20 Dec 2019 07:10:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1Y-0004gw-1D for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1W-0007fw-1a for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:36430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1V-0007ak-FF for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: by mail-wm1-x344.google.com with SMTP id p17so8990524wma.1 for ; Fri, 20 Dec 2019 04:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=UGdI7+HZhPUey0/nxd9li+tSmYYOvpsFqXiegs2Ajtxn22KbYgx4qIgI6tgHjfgv6o bHUPldO21h6X3LfUDZsdKmuXS8KS5fKVtUkQtJYsEeIxZtOoJ+mxyDexX6eGnrw676DL IRCT+a85SxMC1ovNXUlZ9dm2nbDP6qpnxGlOIlPemgZegV6bpX/5MKrTRgYCqtLqUpsl RnD9WV/px5dQjDlYwxEK+2/j7+QtBBALzrM7bOPfAWwTEFvIZ2XSlFLApbqwxCeameBr gYp6I9DJ07y46Ntyz+VuQl1nP7KXv3s6e3u56v+hN6N0xyjAY60cgpiuaUXNajzuZPFa beew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zc6kvGdtDLz2ojH8CUPfJdv2oY/VOoynhGQP1OaS620=; b=e6c3EJfZ1wjLBJ6uZoGdjLl9gGPrYagn9J+Uoc7S3+h26Tb7Qo0SNY0G6jeMkerSVK I9VQoQjYsuG0aAO6ZMKYLzORCzJL3kPRNaAGh/IKfK8Kd3SRiA3l2c+mOC4cef9qYRLv XG7WXxp8eWK1uudA6LADDPYqa7v9EtpSzoJDhREhKL4dKFS7dFi8AuB4agk808yJAKIt 1yhHIE38obQoHm1Xg32TKqS9vUF5xyeb0wI4iMyBSmmQMt336yBis/aec8x3PwXEHV+C wEg4JtB7ORT8TgyvoM0vknDCfgfuGtVFyN1YNtyXcfQ6yEODz9XZK/A1FqpuLLGIIeB5 cbfA== X-Gm-Message-State: APjAAAWI8KGOmeeD2H06XjrtP5dfHvaE3zlaEMdPMII3t2yVmiVoTzuT Fy72ZX7t+0q88RPp00i6g+PQ5TyT1Cg= X-Received: by 2002:a7b:c346:: with SMTP id l6mr3426414wmj.100.1576843488144; Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b67sm10038051wmc.38.2019.12.20.04.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:42 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3F9AB1FF91; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 04/21] gdbstub: move mem_buf to GDBState and use GByteArray Date: Fri, 20 Dec 2019 12:04:21 +0000 Message-Id: <20191220120438.16114-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is in preparation for further re-factoring of the register API with the rest of the code. Theoretically the read register function could overwrite the MAX_PACKET_LENGTH buffer although currently all registers are well within the size range. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Damien Hedde Tested-by: Damien Hedde --- v4 - don't set_set to len on rcmd (it's zeroed before we get here) v3 - fixed up email on Damien's tags --- gdbstub.c | 56 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 80d99c209ff..736e3cc1052 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -367,6 +367,7 @@ typedef struct GDBState { char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; GString *str_buf; + GByteArray *mem_buf; } GDBState; /* By default use no IRQs and no timers while single stepping so as to @@ -382,6 +383,7 @@ static void init_gdbserver_state(void) memset(&gdbserver_state, 0, sizeof(GDBState)); gdbserver_state.init = true; gdbserver_state.str_buf = g_string_new(NULL); + gdbserver_state.mem_buf = g_byte_array_sized_new(MAX_PACKET_LENGTH); } #ifndef CONFIG_USER_ONLY @@ -576,12 +578,13 @@ static void memtohex(GString *buf, const uint8_t *mem, int len) g_string_append_c(buf, '\0'); } -static void hextomem(uint8_t *mem, const char *buf, int len) +static void hextomem(GByteArray *mem, const char *buf, int len) { int i; for(i = 0; i < len; i++) { - mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]); + guint8 byte = fromhex(buf[0]) << 4 | fromhex(buf[1]); + g_byte_array_append(mem, &byte, 1); buf += 2; } } @@ -1412,7 +1415,6 @@ static int cmd_parse_params(const char *data, const char *schema, typedef struct GdbCmdContext { GdbCmdVariant *params; int num_params; - uint8_t mem_buf[MAX_PACKET_LENGTH]; } GdbCmdContext; typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); @@ -1503,6 +1505,7 @@ static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) } g_string_set_size(gdbserver_state.str_buf, 0); + g_byte_array_set_size(gdbserver_state.mem_buf, 0); /* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ @@ -1715,8 +1718,8 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) } reg_size = strlen(gdb_ctx->params[1].data) / 2; - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size); - gdb_write_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[1].data, reg_size); + gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->data, gdb_ctx->params[0].val_ull); put_packet("OK"); } @@ -1735,14 +1738,17 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - reg_size = gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf, + reg_size = gdb_read_register(gdbserver_state.g_cpu, + gdbserver_state.mem_buf->data, gdb_ctx->params[0].val_ull); if (!reg_size) { put_packet("E14"); return; + } else { + g_byte_array_set_size(gdbserver_state.mem_buf, reg_size); } - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, reg_size); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, reg_size); put_strbuf(); } @@ -1759,11 +1765,11 @@ static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) return; } - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[2].data, + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[2].data, gdb_ctx->params[1].val_ull); if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1].val_ull, true)) { + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, true)) { put_packet("E14"); return; } @@ -1784,14 +1790,17 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) return; } + g_byte_array_set_size(gdbserver_state.mem_buf, gdb_ctx->params[1].val_ull); + if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].val_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1].val_ull, false)) { + gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len, false)) { put_packet("E14"); return; } - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1].val_ull); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len); put_strbuf(); } @@ -1806,9 +1815,9 @@ static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) } cpu_synchronize_state(gdbserver_state.g_cpu); - registers = gdb_ctx->mem_buf; len = strlen(gdb_ctx->params[0].data) / 2; - hextomem(registers, gdb_ctx->params[0].data, len); + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + registers = gdbserver_state.mem_buf->data; for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len > 0; addr++) { reg_size = gdb_write_register(gdbserver_state.g_cpu, registers, addr); @@ -1825,11 +1834,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) cpu_synchronize_state(gdbserver_state.g_cpu); len = 0; for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++) { - len += gdb_read_register(gdbserver_state.g_cpu, gdb_ctx->mem_buf + len, + len += gdb_read_register(gdbserver_state.g_cpu, + gdbserver_state.mem_buf->data + len, addr); } + /* FIXME: This is after the fact sizing */ + g_byte_array_set_size(gdbserver_state.mem_buf, len); - memtohex(gdbserver_state.str_buf, gdb_ctx->mem_buf, len); + memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, len); put_strbuf(); } @@ -2078,6 +2090,7 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) #else static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) { + const guint8 zero = 0; int len; if (!gdb_ctx->num_params) { @@ -2091,12 +2104,13 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) return; } + g_assert(gdbserver_state.mem_buf->len == 0); len = len / 2; - hextomem(gdb_ctx->mem_buf, gdb_ctx->params[0].data, len); - gdb_ctx->mem_buf[len++] = 0; - qemu_chr_be_write(gdbserver_state.mon_chr, gdb_ctx->mem_buf, len); + hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); + qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf->len); put_packet("OK"); - } #endif From patchwork Fri Dec 20 12:04:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182253 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp447857ilf; Fri, 20 Dec 2019 04:16:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwH/xPxEUpTKuwVdhnrKyA7Hf4dmSn2qls4VDMSn8kLUjfHqCeiIvOVnDzdsbO2eCC1trOp X-Received: by 2002:a05:6830:1e30:: with SMTP id t16mr14882370otr.220.1576844200301; Fri, 20 Dec 2019 04:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844200; cv=none; d=google.com; s=arc-20160816; b=A9AFiZWiR4R8aN9zCjaVhMSgU5f0P3d4uJFisksIuNkoOtbGPktdmWXJENkMvTLBf5 K1oNx7Tf/Ap7rUrKnfAOHXD7i88l5r4wJq4pioVafkYgu8v3+1zq7BsYraK9mK9N1yXf AQroanWs1E8cnnp6IE2XTaXkRm6K6Iyq33qwhl24Lvbhios5n3LfTzR/2/puKH4HVtCd lHp6vd8nchVNMz5A9XpDqBStt160j8YOWbgx3yYSM5K3NjcgAZ5PV+xeukHW83T2vNeS MwBl9cNaj3kx82wiI1O2QTPA4qKF8bhQhQVIj2fN1dv7RoDtAl2iWS5ra4+RzoRfvfbr IKDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=jaHh0YRHy5umd0FbligxcibYe7XqbnjEYZcRlXU2h/TMPDEn8A7BYiHhPNH6yRWPe+ EMtGJioJNgqCf7ozMCWcvLUfzECfbfeDEu1sWKrsituN2IGnkVPcKdl61n7HZFPrF6LP NMNJFOOOpIx3iBZPDvAzeSdW516DA/cr14sXPRoxqiEis0wxFGifOg154lSJLgCFl/L7 OXOo8u7Oe5cL2YhDXYMZ76X3ULLxqsaBkyVE0NHrDZKZo9U6RF4lb0ZBoYs5tsOjTiPQ GYpN0ZQAe1ObzWm8DWy11/8giWnXnN4jfnXIdWeDVZZ+XdHlUKkHv4m36B5lUOaGfvXU Z0Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=irOjJcd5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c2si4885900otn.311.2019.12.20.04.16.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=irOjJcd5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHCv-0003Hu-SI for patch@linaro.org; Fri, 20 Dec 2019 07:16:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52346) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1V-0004eB-UH for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1U-0007ZT-Ey for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:49 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:37078) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1U-0007UX-28 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:48 -0500 Received: by mail-wr1-x442.google.com with SMTP id w15so9212200wru.4 for ; Fri, 20 Dec 2019 04:04:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=irOjJcd5Hps147k7K/cpd9lmlTA7CoOSFEYeMIn3AxcVDzfW/1bPFDx7d1OyfT9u0j 08aW6EQExY29yRo7vbR8MqtFEScD9Jm7yu7bq6l2uN7lEfrVaNQmAv1HsTAYgByEnp0d x7VcJoGuW2RKtf2RVKxUlBLmzxL/hQ+VurnkW+IQcoI4R58hRpMX+LHxfbmhGIceJyOB pRU06rLCKUl0wBQyAJraU1pDP4tZq3LYPl6q54TvIJ914Ik3ABTp+N4JQJpy/IJCox9D EmNdJFZ8EMy8W2V7rJpjy8bBL5cy0Vz4x7CAAiBWn/lEvmbScYag7nUWlc6SF0SzuWYr 2YjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KcowZQvidWsL6K9vNr5PA0mK1ZdxCgzSQNRXFm9TCF8=; b=JCDEShW6mHNHKZvS2lonAbiKedIO3hLJ7fBLtptxJlLkiMWlqA3nIgba6OeUMInM4d sG2joAMYu3Qf7zKAVV7FwsHeOcySbN1ri7FMVYIeTOECwHuYFNbc+tfV+J/0rmdhXJNt uADEc17BJP2kz4CFuGmRksF3hoagSKV6kdnLmbU+4/uXtCRpQp8Zp1AKxzue4KMbmE0+ YxLo5FwaajDUDzUOgCikn4m0WZLQlf/BIb+1ngb7g+eSbGXIb/uygDZk57KNBjPfaifj r28foXqQO3oCANFzjrs4vv3mRPw1rn4Vg0r/2rdccfM10MwYG3Gf/Cw8FaYJQUB0nflB BA2A== X-Gm-Message-State: APjAAAXmFkdSdgVWxmIsM32M2rq1khjtqJwF03vHmQDT3IWsT5m2F3ND fbTR3ELqSVXdaQrL2L9ywwg6hIpvSaI= X-Received: by 2002:adf:f78d:: with SMTP id q13mr15035764wrp.365.1576843486808; Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u22sm9804594wru.30.2019.12.20.04.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5367F1FF92; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 05/21] gdbstub: add helper for 128 bit registers Date: Fri, 20 Dec 2019 12:04:22 +0000 Message-Id: <20191220120438.16114-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Richard Henderson , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- v2 - take care of endianess of the whole 128 bit word --- include/exec/gdbstub.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- 2.20.1 diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 08363969c14..59e366ba3af 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -102,6 +102,19 @@ static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val) return 8; } +static inline int gdb_get_reg128(uint8_t *mem_buf, uint64_t val_hi, + uint64_t val_lo) +{ +#ifdef TARGET_WORDS_BIGENDIAN + stq_p(mem_buf, val_hi); + stq_p(mem_buf + 8, val_lo); +#else + stq_p(mem_buf, val_lo); + stq_p(mem_buf + 8, val_hi); +#endif + return 16; +} + #if TARGET_LONG_BITS == 64 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val) #define ldtul_p(addr) ldq_p(addr) From patchwork Fri Dec 20 12:04:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182254 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp450635ilf; Fri, 20 Dec 2019 04:18:59 -0800 (PST) X-Google-Smtp-Source: APXvYqyggJIA63bxMrYmEk77CGgoaU6mcU/qFttaFNpEXTjq0zRpa70+shEunV4MJBC6WX6WpNIY X-Received: by 2002:a9d:674f:: with SMTP id w15mr15014580otm.243.1576844339177; Fri, 20 Dec 2019 04:18:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844339; cv=none; d=google.com; s=arc-20160816; b=kHvKuChWETDDKFVFy6JMLd1Xsh3HeQmi4FuXbG9sazJicIx8kuEW0+G7CFtA7ixYZu M6FFbi//9soFEpC8a4CD+X5g0FynBem8tJ16mqJarlna9n1mdQRcqPwK9Nya9vWYc4kc OcbdNkT/H1D38k9cCDSEuoTNFltyzkTscNFrESXfJACJKnZ2XoNvJ0kuTFhP7tgrmxVh n/6dnpfbifReL5+zw1fB12+QwC+A3174j4BFxi+vEBgNk0ihpCkFuFc9aJY/UogRinoX gbYrdB5mBglaxjlAL0Zxbt4vY/E+u4HeVkWy0R/0EChJYYD/g2p/IA+PQYpd6Ie/q6hv +m+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=YL1gsGnQGeeOMnwQN+Wi4PpXctddz55JQnPBtXvFyKahlBOd6BPW51zADg1QukBQB2 P5yKP2VrbOCXrt1XY6nE1rgnJ4D0CtUdedmQ4PZBYTWUbFimT2CaGinmcTYQa9pSA4Wo bsqSpmgKDfnATxg1ERM/Pgg64EWjTwbHen6ZQrfaYkJuHR1Cw33+sRUQeVG25h7eF9AQ nDV2jjWfAb4SePZQ77A3tsJuQUmsOZO8rboa0iwTSBWyCfpfJ2IE/xuoRF7ci/n85Rpo e1MtOwQ9W5InNJQjazuJoNezoTB/stwLuV2EIcsuWkz8TTy5nP9lhRsLYiK0L3vAQIUC mExA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LuPL37ZA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v202si4532925oie.79.2019.12.20.04.18.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:18:59 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LuPL37ZA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHFC-0006Io-8M for patch@linaro.org; Fri, 20 Dec 2019 07:18:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52860) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1a-0004k6-G9 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1Z-0007nz-2H for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:51606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1Y-0007k4-Hg for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:52 -0500 Received: by mail-wm1-x342.google.com with SMTP id d73so8695432wmd.1 for ; Fri, 20 Dec 2019 04:04:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=LuPL37ZAkEEmEi+yqJ9WADzmqnLZrz+RJ1ojuwkeqTFWjZWglfHrlUo+yK37mRjyZ0 uHIir3/Jqn78UzcjUndn5Dw4i4rDuovNnUx/XgHE6FGoCZEqX3Arh6JLtcbTr5tmFQG5 SKAj2i6eGnLxfltMBbkJF4Vnboz5XMFC5EyBKkorUm016VRyd2n5d1Z+Kx9HSGZjoJId WolhnPylDDM/imY+lIo2y/AAJKdfo+TwTDgKBEFZy4rEFNEpXDwRjmq+zrnaZSMMvag0 lP14JfWmS/CWyFwt0nZwkPI9vPzT81ub4r78E2S7+TR0TIkqU4gK+JzJlf65b2kZXCE6 Qsrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yP04C6ThOAXjLefYFBP1Rp4bmt2cBEv6NwVmKqtKkDw=; b=hR+iXuwuK/gQQe5lleWcy+Vcfp+NbSNk6fE93K7MJquOOdgVCzPyIWEAayw/zgNqqY DkWAPO2uC78V/+PxEu75IS/XAzx1Q/SbRQsN+2pZ6OKF2Su0b89HIm4Qi1w7VsqVUE2t rYrtydCHDj01LJ0Anlgp38dp59OCvhIAijsTAUqYzhlxX2bMKwsJWBoposZSMkOw221k vsIIalmZuHvOFcBF/DhnbLvqZMnQGfNGiH5TGdMoqatfKIM5yeQ5NjpL7RVxwt2SHMDi 7e+pq3iKdHbRmDSeK9D8CNAeYpFRxraNJ8lvZo21Dk+vIR41y6wCs2zldwF5OIW6RRNh 0LhQ== X-Gm-Message-State: APjAAAXzI6afax/JQvPq0YFmRf5ffBJXrp7wdLJQ6nvj86k34cWb7YHN oT2qpXc3qNpTwW2sBeDGKo3VNpLakjk= X-Received: by 2002:a1c:e108:: with SMTP id y8mr15629231wmg.147.1576843491069; Fri, 20 Dec 2019 04:04:51 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m7sm9462105wrr.40.2019.12.20.04.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6B5541FF93; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 06/21] target/arm: use gdb_get_reg helpers Date: Fri, 20 Dec 2019 12:04:23 +0000 Message-Id: <20191220120438.16114-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is cleaner than poking memory directly and will make later clean-ups easier. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- v2 - make sure we pass hi/lo correctly as quads are stored in LE order --- target/arm/helper.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index 5074b5f69ca..6f3b6ca7d3f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -105,21 +105,17 @@ static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) { switch (reg) { case 0 ... 31: - /* 128 bit FP register */ - { - uint64_t *q = aa64_vfp_qreg(env, reg); - stq_le_p(buf, q[0]); - stq_le_p(buf + 8, q[1]); - return 16; - } + { + /* 128 bit FP register - quads are in LE order */ + uint64_t *q = aa64_vfp_qreg(env, reg); + return gdb_get_reg128(buf, q[1], q[0]); + } case 32: /* FPSR */ - stl_p(buf, vfp_get_fpsr(env)); - return 4; + return gdb_get_reg32(buf, vfp_get_fpsr(env)); case 33: /* FPCR */ - stl_p(buf, vfp_get_fpcr(env)); - return 4; + return gdb_get_reg32(buf,vfp_get_fpcr(env)); default: return 0; } From patchwork Fri Dec 20 12:04:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182246 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp440011ilf; Fri, 20 Dec 2019 04:09:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwFGqjJODq/q53hkWMLeZGsvaTpv64rtGl9LEn5NLujb+93kocW9E8oSnjGo1l8fm6NlVgq X-Received: by 2002:aca:4587:: with SMTP id s129mr3367564oia.124.1576843798170; Fri, 20 Dec 2019 04:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576843798; cv=none; d=google.com; s=arc-20160816; b=HsiJXaxtbhjyNtA9XhlynI95Vi6z/8q629jZWcqORrtVYroIq4dAyOAv7fLj7+fEzx u0WzJt+Yyjg1lVH/xKeuuJBYDJ1oQFk8KbbpIkvuxPe227Fny+oyelwJXmEON/0mIzp9 sOHiDS9EkmU6cYzybH0w77nWuxOhxCv2hV8ytZOz5jQLWHRAqlmZWlxKpU+X864SjpCC xhAqv8EKdLNu7AXOOoBtKGq3GzmeYOXSj1MdchsNuyyP+edjdJaK73N+MV6mYQ4k0X0Z BaR668Iet+IFAm0DP673Q+J6jAOTb7aEzBxd4yuGE9yr4CTgTGt0hVFGEbZ28IebuKls /Naw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=BEtjdaAv4DBXuKl4eEmSiZT3DGVyI+bl3J3HWcJ0jKi6frF/5JlZ4d4pF4gAmiu+dI gnVLdKuqRNTo8/1MTUVgzDZyrKGhF8/yrbx9GgxMh+V5N2XxQl3LCkWfBFQ/7q0qPRUE jaovrcKg/BSp4Hu0eTH34xcW2K5H9I7o0uwvRMMA8XsjbRsbrX4MQNuWG6adGW9bvWLs RctihwOxZVCNjcZW1LiCKT5vr/kxUDIebSoQcMZ76fcwaVPmDBeKOdDGYeMibQfIziHJ lJd7G2t7UvRELCVxetW9HD76L1OiT2bkbhHc4h/QqzRXbsc4TZ/2Q1CyovRV0wKO5euN x7Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Rl7Mtd+w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o187si4717031oig.107.2019.12.20.04.09.58 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:09:58 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Rl7Mtd+w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH6T-0002jf-5N for patch@linaro.org; Fri, 20 Dec 2019 07:09:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53166) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1c-0004ms-Eu for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1b-0007wr-8t for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:56 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1a-0007sC-QU for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:54 -0500 Received: by mail-wr1-x441.google.com with SMTP id q6so9153864wro.9 for ; Fri, 20 Dec 2019 04:04:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=Rl7Mtd+wYfO2sBYfYEwqUKijA39big+VB1gytaYA6V223uSnjIWRdhlnwGBl05XELM 8zDC72ZTf7xpCVG2BCGDO6vn9NBoepPAsMzU2X/PAE8hZfFR6+FQf3XKS4Usae/B4XNr oB4Y23OV/6G8SpDEDTlMiOxLzeHD8RWQrRQhUUHGSipZItC8IzezEcehAuLxKcFX6sjt +GGDbr5CaRyRyRGwRMMvBbGph3NE8EYxPBrMShKkNYIeFtbIeSC2VKdH0qwbaI2zjFYf KslAxqlsuFJcchaEhVPaywhjTNoyUSSZMbn4ppPMkVg/xCb76M7KsHPfpIvI8zoue8SL cFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bqp2vY6ZYjqYdoh+7hv2voXM8FmNpL/WqUxsGE1oBh8=; b=Ob2kKkBQlFvnrrBzwIeifC12yKIe0IqG0CF6iY+P+U8UsTKf9dCzOBM86Wpz7aQXBt Xi0/t/tOYpPF4z5GJfnmnQ20KJ7yCB0tUdAnDITE9VCiBqok2t6sfXZ/vc3NmQN8HYM5 pQUvCm14E7+y8ti8cdDa1o4hODtWLlGsbpsv4NE8gM/Q5uu6nqo2N0OHhCrWkfMLEO6l u3G8RQGAutIhayQpTyA3bVUErVHruFTDJw58NuvsGV4UJCO5uLnsQHrLSFX+6PsB590p moTTObkxNZLkBfEgFSvqmOM/MWqFwMjf4INdP3kAPP5X2nwyh/yU5ed6yQNKEhizYF0F ULeA== X-Gm-Message-State: APjAAAWzHf7IdFpk4ttnDW+xipF9Ge/Y+4OQk9BgG1DamY2NJ+dezAYE P0h3hwW0MjeRSM6UFDlPAnC7hQ== X-Received: by 2002:a5d:4481:: with SMTP id j1mr15500657wrq.348.1576843493629; Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t1sm9542565wma.43.2019.12.20.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 80C9C1FF96; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 07/21] target/m68k: use gdb_get_reg helpers Date: Fri, 20 Dec 2019 12:04:24 +0000 Message-Id: <20191220120438.16114-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, Richard Henderson , Laurent Vivier , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is cleaner than poking memory directly and will make later clean-ups easier. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Laurent Vivier --- v3 - fix mem_buf references - fix mem_buf + len cases --- target/m68k/helper.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) -- 2.20.1 diff --git a/target/m68k/helper.c b/target/m68k/helper.c index ae766a6cb0b..2573ee7a535 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -72,19 +72,15 @@ static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) { if (n < 8) { float_status s; - stfq_p(mem_buf, floatx80_to_float64(env->fregs[n].d, &s)); - return 8; + return gdb_get_reg64(mem_buf, floatx80_to_float64(env->fregs[n].d, &s)); } switch (n) { case 8: /* fpcontrol */ - stl_be_p(mem_buf, env->fpcr); - return 4; + return gdb_get_reg32(mem_buf, env->fpcr); case 9: /* fpstatus */ - stl_be_p(mem_buf, env->fpsr); - return 4; + return gdb_get_reg32(mem_buf, env->fpsr); case 10: /* fpiar, not implemented */ - memset(mem_buf, 0, 4); - return 4; + return gdb_get_reg32(mem_buf, 0); } return 0; } @@ -112,21 +108,18 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) static int m68k_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) { if (n < 8) { - stw_be_p(mem_buf, env->fregs[n].l.upper); - memset(mem_buf + 2, 0, 2); - stq_be_p(mem_buf + 4, env->fregs[n].l.lower); - return 12; + int len = gdb_get_reg16(mem_buf, env->fregs[n].l.upper); + len += gdb_get_reg16(mem_buf + len, 0); + len += gdb_get_reg64(mem_buf + len, env->fregs[n].l.lower); + return len; } switch (n) { case 8: /* fpcontrol */ - stl_be_p(mem_buf, env->fpcr); - return 4; + return gdb_get_reg32(mem_buf, env->fpcr); case 9: /* fpstatus */ - stl_be_p(mem_buf, env->fpsr); - return 4; + return gdb_get_reg32(mem_buf, env->fpsr); case 10: /* fpiar, not implemented */ - memset(mem_buf, 0, 4); - return 4; + return gdb_get_reg32(mem_buf, 0); } return 0; } From patchwork Fri Dec 20 12:04:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182256 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp453471ilf; Fri, 20 Dec 2019 04:21:29 -0800 (PST) X-Google-Smtp-Source: APXvYqy3/fCBJE2CPjLK1pPo+yKmWI5adnqIkW3iTL1Z0DLTCzQkx+3QSV3BMWlkVmj7KZuiqPL5 X-Received: by 2002:a9d:7ccc:: with SMTP id r12mr15391990otn.22.1576844489502; Fri, 20 Dec 2019 04:21:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844489; cv=none; d=google.com; s=arc-20160816; b=AS6uU9ZlPu0R9fSX2HJOrBflEEUTslaBDaKOqB2xItcNcSVZSf1CCe9dSaqux04xGk xDv9RjQgZKxgQ6WV9DcfAFXkNXKJha1m7MtAmYvETF8bw/Z4ugBM6ptC9WME6+Zcd6hY CYpBsWieVo6AHAVf5e4diSENrZStWrbKhiQaALB8rwx5qPzM3t9g8AGYWm6LHPhF/G96 pEDCtxxZ1IoNdwKIe3VJxejYDNcuwOw1Q0cRa2yZmiel10fwnSU+x2wHPXBMT6B51E4y xcxSZky2W/1+GZ3eMXp2YxDQR4RplT7IP2V8zU5Ce9ovDC8rNr9u8O8wumIrM3ahWlJ9 jbig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=L1iSkJZDn3Olif7ZmOzPkgY8V2HAg4vrPXLquhm6NR+zTHN78Yu2IcMLtkJdCKyOj0 m42YrRLRme1dMhyV7vNMd2paxWJ0gK0CbvSDutKVAIB3Xfn1WtR8reA8qq30Psmhpn2T RqU2Tqj35gdwxr3obiTvZwoB+oJtjJcAnJZTJsQwiycmuJ7m3G/Vg34ziHF8fGjYcAGn 03JZmu8rnUSiZay1QC9Mldyi37lfUlVF13t/AUcjqj0eZ2p7BoUfxIAieC/TCg0XHvZs WGKxvPbR7HJf8Gnz/sOjfKB5+Wu4QZBl2qsS18olEB2JuCklLUK5Yp1ISSCFmezXgDMU hbRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LFMRgoeW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v4si5001753oth.3.2019.12.20.04.21.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:21:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LFMRgoeW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHHc-0001EA-CZ for patch@linaro.org; Fri, 20 Dec 2019 07:21:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54303) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1s-00052B-R8 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1l-0008Jz-7j for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:38617) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1k-0008Fl-28 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:04 -0500 Received: by mail-wm1-x344.google.com with SMTP id u2so8971468wmc.3 for ; Fri, 20 Dec 2019 04:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=LFMRgoeWys+pvnbQppS+YEGIwEHjaSatO55vdZpNde/OjlaBnTP/yOn7Lf90yFFmHb Ee8iiOHVFuLLg3SvVLG/Q/BMzXaURmiyjaBBSNPVN+jATv0rYZ1VWZ/4HQkkmOFhW+jY xpmqbeXEQ+DMrVNW2AyE4B88/Iu25U7bSNypIJld6YIWeNqJX+PFUbsRMsNZf6HfOn6z u05hAns0bVKuXY4eBk8tJHFrCNncPElZm/xRUnRqQUJOFgs7vdLJLVm2rOSC7YG51/Dj NJp0g4cnVVyi2yKV8ce8sNmW56+WWH9AQh3d9aDqKd1SLyYbPc+muTPFQ56gg74Ih41K h8vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Gl3w5dXDGfherWie7OLbv8FKPkn1YuYJp7v+pvZORo=; b=QgpwawOJwVa1MTZnH6ZrrqOH80f3luNpxlUmxj+NlVC45vCS0zb+Qxpdj31Xj/1psV idErh6KpJL83gVRbBcKFSxLQrnwse43FMrEk/8W2fPUzr/z7dpEEGoMf6hEr28BI3e+n K+rXEqN5CGBThPjLLR4GVzjPdFFN2cFctCRfyBhpRcr5CnSaUorp3CK9HZto87kutyqu pxZ8C2DMH6m/6Q+0NBAjipaKRXq+mFO2egJITBQVMq3KlY8MUvG3bBNF2xbT4h1Zql8T gZyXTjsTHfXtPvlbLyipVtWTSXjclBf84GHwuewRGiE/cSYtB4VjwrLj1HD8dZ/ZnpnV 2Rgg== X-Gm-Message-State: APjAAAVKBlxEvnKplJEFnTe9vZh0WMsxvMf3vrdBJm7ozNMGwqYu1iT2 heKppBxZR0RRRm9D0j8ezN9Bzg== X-Received: by 2002:a1c:7901:: with SMTP id l1mr15695925wme.67.1576843500868; Fri, 20 Dec 2019 04:05:00 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n10sm9391168wrt.14.2019.12.20.04.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DB0F01FF98; Fri, 20 Dec 2019 12:04:39 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 08/21] gdbstub: extend GByteArray to read register helpers Date: Fri, 20 Dec 2019 12:04:25 +0000 Message-Id: <20191220120438.16114-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Cornelia Huck , luis.machado@linaro.org, Sagar Karandikar , David Hildenbrand , Mark Cave-Ayland , Max Filippov , Alistair Francis , "Edgar E. Iglesias" , Marek Vasut , alan.hayward@arm.com, "open list:PowerPC TCG CPUs" , Aleksandar Rikalo , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Artyom Tarasenko , Eduardo Habkost , "open list:S390 general arch..." , "open list:ARM TCG CPUs" , Stafford Horne , =?utf-8?q?Alex_Benn=C3=A9e?= , David Gibson , damien.hedde@greensocs.com, "open list:RISC-V TCG CPUs" , Bastian Koppelmann , Chris Wulff , Laurent Vivier , Michael Walle , Palmer Dabbelt , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of passing a pointer to memory now just extend the GByteArray to all the read register helpers. They can then safely append their data through the normal way. We don't bother with this abstraction for write registers as we have already ensured the buffer being copied from is the correct size. Signed-off-by: Alex Bennée --- v4 - fix mem_buf calculation for ppc_maybe_bswap_register --- include/exec/gdbstub.h | 46 +++++++++++++++++----------- include/hw/core/cpu.h | 2 +- target/alpha/cpu.h | 2 +- target/arm/cpu.h | 4 +-- target/cris/cpu.h | 4 +-- target/hppa/cpu.h | 2 +- target/i386/cpu.h | 2 +- target/lm32/cpu.h | 2 +- target/m68k/cpu.h | 2 +- target/microblaze/cpu.h | 2 +- target/mips/internal.h | 2 +- target/openrisc/cpu.h | 2 +- target/ppc/cpu.h | 4 +-- target/riscv/cpu.h | 2 +- target/s390x/internal.h | 2 +- target/sh4/cpu.h | 2 +- target/sparc/cpu.h | 2 +- target/xtensa/cpu.h | 2 +- gdbstub.c | 20 ++++++------ hw/core/cpu.c | 2 +- target/alpha/gdbstub.c | 2 +- target/arm/gdbstub.c | 2 +- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 19 +++++------- target/cris/gdbstub.c | 4 +-- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/lm32/gdbstub.c | 2 +- target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 4 +-- target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/nios2/cpu.c | 2 +- target/openrisc/gdbstub.c | 2 +- target/ppc/gdbstub.c | 48 +++++++++++++++-------------- target/ppc/translate_init.inc.c | 54 ++++++++++++++++++--------------- target/riscv/gdbstub.c | 18 +++++------ target/s390x/gdbstub.c | 30 +++++++++--------- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/xtensa/gdbstub.c | 2 +- 41 files changed, 165 insertions(+), 148 deletions(-) -- 2.20.1 Reviewed-by: Damien Hedde diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 59e366ba3af..ef79e32708c 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -68,49 +68,59 @@ void gdb_signalled(CPUArchState *, int); void gdbserver_fork(CPUState *); #endif /* Get or set a register. Returns the size of the register. */ -typedef int (*gdb_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); +typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg); +typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); void gdb_register_coprocessor(CPUState *cpu, - gdb_reg_cb get_reg, gdb_reg_cb set_reg, + gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -/* The GDB remote protocol transfers values in target byte order. This means - * we can use the raw memory access routines to access the value buffer. - * Conveniently, these also handle the case where the buffer is mis-aligned. +/* + * The GDB remote protocol transfers values in target byte order. As + * the gdbstub may be batching up several register values we always + * append to the array. */ -static inline int gdb_get_reg8(uint8_t *mem_buf, uint8_t val) +static inline int gdb_get_reg8(GByteArray *buf, uint8_t val) { - stb_p(mem_buf, val); + g_byte_array_append(buf, &val, 1); return 1; } -static inline int gdb_get_reg16(uint8_t *mem_buf, uint16_t val) +static inline int gdb_get_reg16(GByteArray *buf, uint16_t val) { - stw_p(mem_buf, val); + uint16_t to_word = tswap16(val); + g_byte_array_append(buf, (uint8_t *) &to_word, 2); return 2; } -static inline int gdb_get_reg32(uint8_t *mem_buf, uint32_t val) +static inline int gdb_get_reg32(GByteArray *buf, uint32_t val) { - stl_p(mem_buf, val); + uint32_t to_long = tswap32(val); + g_byte_array_append(buf, (uint8_t *) &to_long, 4); return 4; } -static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val) +static inline int gdb_get_reg64(GByteArray *buf, uint64_t val) { - stq_p(mem_buf, val); + uint64_t to_quad = tswap64(val); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); return 8; } -static inline int gdb_get_reg128(uint8_t *mem_buf, uint64_t val_hi, +static inline int gdb_get_reg128(GByteArray *buf, uint64_t val_hi, uint64_t val_lo) { + uint64_t to_quad; #ifdef TARGET_WORDS_BIGENDIAN - stq_p(mem_buf, val_hi); - stq_p(mem_buf + 8, val_lo); + to_quad = tswap64(val_hi); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); + to_quad = tswap64(val_lo); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); #else - stq_p(mem_buf, val_lo); - stq_p(mem_buf + 8, val_hi); + to_quad = tswap64(val_lo); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); + to_quad = tswap64(val_hi); + g_byte_array_append(buf, (uint8_t *) &to_quad, 8); #endif return 16; } diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 77c6f052990..e85ec519add 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -195,7 +195,7 @@ typedef struct CPUClass { hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs); - int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg); + int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); void (*debug_excp_handler)(CPUState *cpu); diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h index a530249a5bf..faa09768424 100644 --- a/target/alpha/cpu.h +++ b/target/alpha/cpu.h @@ -282,7 +282,7 @@ void alpha_cpu_do_interrupt(CPUState *cpu); bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req); void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags); hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int alpha_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int alpha_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void alpha_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f70e9e0438..19b3ac32113 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -949,7 +949,7 @@ bool arm_cpu_exec_interrupt(CPUState *cpu, int int_req); hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); -int arm_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); /* Dynamically generates for gdb stub an XML description of the sysregs from @@ -969,7 +969,7 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); #ifdef TARGET_AARCH64 -int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int aarch64_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq); void aarch64_sve_change_el(CPUARMState *env, int old_el, diff --git a/target/cris/cpu.h b/target/cris/cpu.h index aba0a664744..333ee5b171a 100644 --- a/target/cris/cpu.h +++ b/target/cris/cpu.h @@ -194,8 +194,8 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags); hwaddr cris_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int crisv10_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); -int cris_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int crisv10_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); +int cris_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int cris_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); /* you can call this signal handler from your SIGBUS and SIGSEGV diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h index 6713d04f111..801a4fb1bae 100644 --- a/target/hppa/cpu.h +++ b/target/hppa/cpu.h @@ -321,7 +321,7 @@ void cpu_hppa_change_prot_id(CPUHPPAState *env); int cpu_hppa_signal_handler(int host_signum, void *pinfo, void *puc); hwaddr hppa_cpu_get_phys_page_debug(CPUState *cs, vaddr addr); -int hppa_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int hppa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int hppa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void hppa_cpu_do_interrupt(CPUState *cpu); bool hppa_cpu_exec_interrupt(CPUState *cpu, int int_req); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index af282936a78..63b0031c5bf 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1760,7 +1760,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags); hwaddr x86_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, MemTxAttrs *attrs); -int x86_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void x86_cpu_exec_enter(CPUState *cpu); diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h index 064c6b1267e..01d408eb55d 100644 --- a/target/lm32/cpu.h +++ b/target/lm32/cpu.h @@ -202,7 +202,7 @@ void lm32_cpu_do_interrupt(CPUState *cpu); bool lm32_cpu_exec_interrupt(CPUState *cs, int int_req); void lm32_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr lm32_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int lm32_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int lm32_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int lm32_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); typedef enum { diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index 20de3c379aa..cdb08c269f6 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -168,7 +168,7 @@ void m68k_cpu_do_interrupt(CPUState *cpu); bool m68k_cpu_exec_interrupt(CPUState *cpu, int int_req); void m68k_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr m68k_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int m68k_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int m68k_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int m68k_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void m68k_tcg_init(void); diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index 95773089aa3..987e4629b0a 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -313,7 +313,7 @@ void mb_cpu_do_interrupt(CPUState *cs); bool mb_cpu_exec_interrupt(CPUState *cs, int int_req); void mb_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr mb_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int mb_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void mb_tcg_init(void); diff --git a/target/mips/internal.h b/target/mips/internal.h index 3f435b5e631..c5ae86360f5 100644 --- a/target/mips/internal.h +++ b/target/mips/internal.h @@ -82,7 +82,7 @@ void mips_cpu_do_interrupt(CPUState *cpu); bool mips_cpu_exec_interrupt(CPUState *cpu, int int_req); void mips_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr mips_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int mips_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int mips_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int mips_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/openrisc/cpu.h b/target/openrisc/cpu.h index 0ad02eab794..d9484b802f3 100644 --- a/target/openrisc/cpu.h +++ b/target/openrisc/cpu.h @@ -320,7 +320,7 @@ void openrisc_cpu_do_interrupt(CPUState *cpu); bool openrisc_cpu_exec_interrupt(CPUState *cpu, int int_req); void openrisc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int openrisc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int openrisc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int openrisc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void openrisc_translate_init(void); bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr address, int size, diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 103bfe9dc27..41e009ae3c9 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1256,8 +1256,8 @@ bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req); void ppc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); void ppc_cpu_dump_statistics(CPUState *cpu, int flags); hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); -int ppc_cpu_gdb_read_register_apple(CPUState *cpu, uint8_t *buf, int reg); +int ppc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); +int ppc_cpu_gdb_read_register_apple(CPUState *cpu, GByteArray *buf, int reg); int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); int ppc_cpu_gdb_write_register_apple(CPUState *cpu, uint8_t *buf, int reg); #ifndef CONFIG_USER_ONLY diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e59343e13c0..fe0b8861021 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -243,7 +243,7 @@ extern const char * const riscv_excp_names[]; extern const char * const riscv_intr_names[]; void riscv_cpu_do_interrupt(CPUState *cpu); -int riscv_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); bool riscv_cpu_fp_enabled(CPURISCVState *env); diff --git a/target/s390x/internal.h b/target/s390x/internal.h index d37816104dd..8c95c734dbe 100644 --- a/target/s390x/internal.h +++ b/target/s390x/internal.h @@ -292,7 +292,7 @@ uint16_t float128_dcmask(CPUS390XState *env, float128 f1); /* gdbstub.c */ -int s390_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int s390_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int s390_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void s390_cpu_gdb_init(CPUState *cs); diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h index ecaa7a18a94..d7a1bffd600 100644 --- a/target/sh4/cpu.h +++ b/target/sh4/cpu.h @@ -208,7 +208,7 @@ void superh_cpu_do_interrupt(CPUState *cpu); bool superh_cpu_exec_interrupt(CPUState *cpu, int int_req); void superh_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr superh_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int superh_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int superh_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int superh_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h index ae97c7d9f79..b9369398f24 100644 --- a/target/sparc/cpu.h +++ b/target/sparc/cpu.h @@ -571,7 +571,7 @@ extern const VMStateDescription vmstate_sparc_cpu; void sparc_cpu_do_interrupt(CPUState *cpu); void sparc_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr sparc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); -int sparc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int sparc_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int sparc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index b363ffcf106..b20be1f5814 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -569,7 +569,7 @@ void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); void xtensa_count_regs(const XtensaConfig *config, unsigned *n_regs, unsigned *n_core_regs); -int xtensa_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); +int xtensa_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int xtensa_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type, diff --git a/gdbstub.c b/gdbstub.c index 736e3cc1052..287d0535b12 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -319,8 +319,8 @@ static int gdb_signal_to_target (int sig) typedef struct GDBRegisterState { int base_reg; int num_regs; - gdb_reg_cb get_reg; - gdb_reg_cb set_reg; + gdb_get_reg_cb get_reg; + gdb_set_reg_cb set_reg; const char *xml; struct GDBRegisterState *next; } GDBRegisterState; @@ -905,19 +905,19 @@ static const char *get_feature_xml(const char *p, const char **newp, return name ? xml_builtin[i][1] : NULL; } -static int gdb_read_register(CPUState *cpu, uint8_t *mem_buf, int reg) +static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc = CPU_GET_CLASS(cpu); CPUArchState *env = cpu->env_ptr; GDBRegisterState *r; if (reg < cc->gdb_num_core_regs) { - return cc->gdb_read_register(cpu, mem_buf, reg); + return cc->gdb_read_register(cpu, buf, reg); } for (r = cpu->gdb_regs; r; r = r->next) { if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { - return r->get_reg(env, mem_buf, reg - r->base_reg); + return r->get_reg(env, buf, reg - r->base_reg); } } return 0; @@ -948,7 +948,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) */ void gdb_register_coprocessor(CPUState *cpu, - gdb_reg_cb get_reg, gdb_reg_cb set_reg, + gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, int num_regs, const char *xml, int g_pos) { GDBRegisterState *s; @@ -1739,7 +1739,7 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) } reg_size = gdb_read_register(gdbserver_state.g_cpu, - gdbserver_state.mem_buf->data, + gdbserver_state.mem_buf, gdb_ctx->params[0].val_ull); if (!reg_size) { put_packet("E14"); @@ -1832,14 +1832,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) target_ulong addr, len; cpu_synchronize_state(gdbserver_state.g_cpu); + g_byte_array_set_size(gdbserver_state.mem_buf, 0); len = 0; for (addr = 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++) { len += gdb_read_register(gdbserver_state.g_cpu, - gdbserver_state.mem_buf->data + len, + gdbserver_state.mem_buf, addr); } - /* FIXME: This is after the fact sizing */ - g_byte_array_set_size(gdbserver_state.mem_buf, len); + g_assert(len == gdbserver_state.mem_buf->len); memtohex(gdbserver_state.str_buf, gdbserver_state.mem_buf->data, len); put_strbuf(); diff --git a/hw/core/cpu.c b/hw/core/cpu.c index db1a03c6bbb..9cd1a2a54fb 100644 --- a/hw/core/cpu.c +++ b/hw/core/cpu.c @@ -177,7 +177,7 @@ static int cpu_common_write_elf64_note(WriteCoreDumpFunction f, } -static int cpu_common_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg) +static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { return 0; } diff --git a/target/alpha/gdbstub.c b/target/alpha/gdbstub.c index 7f9cc092a9c..0cd76ddaa9e 100644 --- a/target/alpha/gdbstub.c +++ b/target/alpha/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int alpha_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { AlphaCPU *cpu = ALPHA_CPU(cs); CPUAlphaState *env = &cpu->env; diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 1239abd9842..4557775d245 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -32,7 +32,7 @@ typedef struct RegisterSysregXmlParam { We hack round this by giving the FPA regs zero size when talking to a newer gdb. */ -int arm_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int arm_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 665ebb3ef64..35d0b80c2de 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -20,7 +20,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int aarch64_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; diff --git a/target/arm/helper.c b/target/arm/helper.c index 6f3b6ca7d3f..36872627a5d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -47,30 +47,27 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, static void switch_mode(CPUARMState *env, int mode); -static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) +static int vfp_gdb_get_reg(CPUARMState *env, GByteArray *buf, int reg) { int nregs; /* VFP data registers are always little-endian. */ nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16; if (reg < nregs) { - stq_le_p(buf, *aa32_vfp_dreg(env, reg)); - return 8; + return gdb_get_reg64(buf, *aa32_vfp_dreg(env, reg)); } if (arm_feature(env, ARM_FEATURE_NEON)) { /* Aliases for Q regs. */ nregs += 16; if (reg < nregs) { uint64_t *q = aa32_vfp_qreg(env, reg - 32); - stq_le_p(buf, q[0]); - stq_le_p(buf + 8, q[1]); - return 16; + return gdb_get_reg128(buf, q[0], q[1]); } } switch (reg - nregs) { - case 0: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSID]); return 4; - case 1: stl_p(buf, vfp_get_fpscr(env)); return 4; - case 2: stl_p(buf, env->vfp.xregs[ARM_VFP_FPEXC]); return 4; + case 0: return gdb_get_reg32(buf, env->vfp.xregs[ARM_VFP_FPSID]); break; + case 1: return gdb_get_reg32(buf, vfp_get_fpscr(env)); break; + case 2: return gdb_get_reg32(buf, env->vfp.xregs[ARM_VFP_FPEXC]); break; } return 0; } @@ -101,7 +98,7 @@ static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg) return 0; } -static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) +static int aarch64_fpu_gdb_get_reg(CPUARMState *env, GByteArray *buf, int reg) { switch (reg) { case 0 ... 31: @@ -204,7 +201,7 @@ static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri, } } -static int arm_gdb_get_sysreg(CPUARMState *env, uint8_t *buf, int reg) +static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) { ARMCPU *cpu = env_archcpu(env); const ARMCPRegInfo *ri; diff --git a/target/cris/gdbstub.c b/target/cris/gdbstub.c index a3d76d2e8c2..b01b2aa0811 100644 --- a/target/cris/gdbstub.c +++ b/target/cris/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int crisv10_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int crisv10_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { CRISCPU *cpu = CRIS_CPU(cs); CPUCRISState *env = &cpu->env; @@ -53,7 +53,7 @@ int crisv10_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) return 0; } -int cris_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int cris_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { CRISCPU *cpu = CRIS_CPU(cs); CPUCRISState *env = &cpu->env; diff --git a/target/hppa/gdbstub.c b/target/hppa/gdbstub.c index 341888a9da0..a6428a2893f 100644 --- a/target/hppa/gdbstub.c +++ b/target/hppa/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int hppa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { HPPACPU *cpu = HPPA_CPU(cs); CPUHPPAState *env = &cpu->env; diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c index aef25b70f10..38324498f33 100644 --- a/target/i386/gdbstub.c +++ b/target/i386/gdbstub.c @@ -79,7 +79,7 @@ static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; #endif -int x86_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; diff --git a/target/lm32/gdbstub.c b/target/lm32/gdbstub.c index 82ede436e12..b6fe12e1d61 100644 --- a/target/lm32/gdbstub.c +++ b/target/lm32/gdbstub.c @@ -22,7 +22,7 @@ #include "exec/gdbstub.h" #include "hw/lm32/lm32_pic.h" -int lm32_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int lm32_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { LM32CPU *cpu = LM32_CPU(cs); CPULM32State *env = &cpu->env; diff --git a/target/m68k/gdbstub.c b/target/m68k/gdbstub.c index fdc96f57fff..eb2d030e148 100644 --- a/target/m68k/gdbstub.c +++ b/target/m68k/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int m68k_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int m68k_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; diff --git a/target/m68k/helper.c b/target/m68k/helper.c index 2573ee7a535..6f9099cd937 100644 --- a/target/m68k/helper.c +++ b/target/m68k/helper.c @@ -68,7 +68,7 @@ void m68k_cpu_list(void) g_slist_free(list); } -static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) +static int cf_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n) { if (n < 8) { float_status s; @@ -105,7 +105,7 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) return 0; } -static int m68k_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) +static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n) { if (n < 8) { int len = gdb_get_reg16(mem_buf, env->fregs[n].l.upper); diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c index 30677b6d1f4..f41ebf1f33b 100644 --- a/target/microblaze/gdbstub.c +++ b/target/microblaze/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int mb_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); CPUMBState *env = &cpu->env; diff --git a/target/mips/gdbstub.c b/target/mips/gdbstub.c index bbb25449391..98f56e660d2 100644 --- a/target/mips/gdbstub.c +++ b/target/mips/gdbstub.c @@ -22,7 +22,7 @@ #include "internal.h" #include "exec/gdbstub.h" -int mips_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int mips_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { MIPSCPU *cpu = MIPS_CPU(cs); CPUMIPSState *env = &cpu->env; diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index ca9c7a6df5d..17d868421ed 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -124,7 +124,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info) #endif } -static int nios2_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUClass *cc = CPU_GET_CLASS(cs); diff --git a/target/openrisc/gdbstub.c b/target/openrisc/gdbstub.c index 0fcdb79668c..095bf76c12c 100644 --- a/target/openrisc/gdbstub.c +++ b/target/openrisc/gdbstub.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -int openrisc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int openrisc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { OpenRISCCPU *cpu = OPENRISC_CPU(cs); CPUOpenRISCState *env = &cpu->env; diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c index 823759c92e7..eb362dd9aec 100644 --- a/target/ppc/gdbstub.c +++ b/target/ppc/gdbstub.c @@ -114,10 +114,11 @@ void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len) * the FP regs zero size when talking to a newer gdb. */ -int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_read_register(CPUState *cs, GByteArray *buf, int n) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; + uint8_t *mem_buf; int r = ppc_gdb_register_len(n); if (!r) { @@ -126,17 +127,17 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) if (n < 32) { /* gprs */ - gdb_get_regl(mem_buf, env->gpr[n]); + gdb_get_regl(buf, env->gpr[n]); } else if (n < 64) { /* fprs */ - stfq_p(mem_buf, *cpu_fpr_ptr(env, n - 32)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32)); } else { switch (n) { case 64: - gdb_get_regl(mem_buf, env->nip); + gdb_get_regl(buf, env->nip); break; case 65: - gdb_get_regl(mem_buf, env->msr); + gdb_get_regl(buf, env->msr); break; case 66: { @@ -145,31 +146,33 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) for (i = 0; i < 8; i++) { cr |= env->crf[i] << (32 - ((i + 1) * 4)); } - gdb_get_reg32(mem_buf, cr); + gdb_get_reg32(buf, cr); break; } case 67: - gdb_get_regl(mem_buf, env->lr); + gdb_get_regl(buf, env->lr); break; case 68: - gdb_get_regl(mem_buf, env->ctr); + gdb_get_regl(buf, env->ctr); break; case 69: - gdb_get_reg32(mem_buf, env->xer); + gdb_get_reg32(buf, env->xer); break; case 70: - gdb_get_reg32(mem_buf, env->fpscr); + gdb_get_reg32(buf, env->fpscr); break; } } + mem_buf = buf->data + buf->len - r; ppc_maybe_bswap_register(env, mem_buf, r); return r; } -int ppc_cpu_gdb_read_register_apple(CPUState *cs, uint8_t *mem_buf, int n) +int ppc_cpu_gdb_read_register_apple(CPUState *cs, GByteArray *buf, int n) { PowerPCCPU *cpu = POWERPC_CPU(cs); CPUPPCState *env = &cpu->env; + uint8_t *mem_buf; int r = ppc_gdb_register_len_apple(n); if (!r) { @@ -178,21 +181,21 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, uint8_t *mem_buf, int n) if (n < 32) { /* gprs */ - gdb_get_reg64(mem_buf, env->gpr[n]); + gdb_get_reg64(buf, env->gpr[n]); } else if (n < 64) { /* fprs */ - stfq_p(mem_buf, *cpu_fpr_ptr(env, n - 32)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n - 32)); } else if (n < 96) { /* Altivec */ - stq_p(mem_buf, n - 64); - stq_p(mem_buf + 8, 0); + gdb_get_reg64(buf, n - 64); + gdb_get_reg64(buf, 0); } else { switch (n) { case 64 + 32: - gdb_get_reg64(mem_buf, env->nip); + gdb_get_reg64(buf, env->nip); break; case 65 + 32: - gdb_get_reg64(mem_buf, env->msr); + gdb_get_reg64(buf, env->msr); break; case 66 + 32: { @@ -201,23 +204,24 @@ int ppc_cpu_gdb_read_register_apple(CPUState *cs, uint8_t *mem_buf, int n) for (i = 0; i < 8; i++) { cr |= env->crf[i] << (32 - ((i + 1) * 4)); } - gdb_get_reg32(mem_buf, cr); + gdb_get_reg32(buf, cr); break; } case 67 + 32: - gdb_get_reg64(mem_buf, env->lr); + gdb_get_reg64(buf, env->lr); break; case 68 + 32: - gdb_get_reg64(mem_buf, env->ctr); + gdb_get_reg64(buf, env->ctr); break; case 69 + 32: - gdb_get_reg32(mem_buf, env->xer); + gdb_get_reg32(buf, env->xer); break; case 70 + 32: - gdb_get_reg64(mem_buf, env->fpscr); + gdb_get_reg64(buf, env->fpscr); break; } } + mem_buf = buf->data + buf->len - r; ppc_maybe_bswap_register(env, mem_buf, r); return r; } diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index d33d65dff70..ca241d7f5e6 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -9845,7 +9845,7 @@ static int gdb_find_spr_idx(CPUPPCState *env, int n) return -1; } -static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_spr_reg(CPUPPCState *env, GByteArray *buf, int n) { int reg; int len; @@ -9856,8 +9856,8 @@ static int gdb_get_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) } len = TARGET_LONG_SIZE; - stn_p(mem_buf, len, env->spr[reg]); - ppc_maybe_bswap_register(env, mem_buf, len); + gdb_get_regl(buf, env->spr[reg]); + ppc_maybe_bswap_register(env, buf->data - len, len); return len; } @@ -9879,15 +9879,18 @@ static int gdb_set_spr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) } #endif -static int gdb_get_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_float_reg(CPUPPCState *env, GByteArray *buf, int n) { + uint8_t *mem_buf; if (n < 32) { - stfq_p(mem_buf, *cpu_fpr_ptr(env, n)); + gdb_get_reg64(buf, *cpu_fpr_ptr(env, n)); + mem_buf = buf->data - 8; ppc_maybe_bswap_register(env, mem_buf, 8); return 8; } if (n == 32) { - stl_p(mem_buf, env->fpscr); + gdb_get_reg32(buf, env->fpscr); + mem_buf = buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } @@ -9909,28 +9912,31 @@ static int gdb_set_float_reg(CPUPPCState *env, uint8_t *mem_buf, int n) return 0; } -static int gdb_get_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_avr_reg(CPUPPCState *env, GByteArray *buf, int n) { + uint8_t *mem_buf; + if (n < 32) { ppc_avr_t *avr = cpu_avr_ptr(env, n); if (!avr_need_swap(env)) { - stq_p(mem_buf, avr->u64[0]); - stq_p(mem_buf + 8, avr->u64[1]); + gdb_get_reg128(buf, avr->u64[0] , avr->u64[1]); } else { - stq_p(mem_buf, avr->u64[1]); - stq_p(mem_buf + 8, avr->u64[0]); + gdb_get_reg128(buf, avr->u64[1] , avr->u64[0]); } + mem_buf = buf->data - 16; ppc_maybe_bswap_register(env, mem_buf, 8); ppc_maybe_bswap_register(env, mem_buf + 8, 8); return 16; } if (n == 32) { - stl_p(mem_buf, helper_mfvscr(env)); + gdb_get_reg32(buf, helper_mfvscr(env)); + mem_buf = buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } if (n == 33) { - stl_p(mem_buf, (uint32_t)env->spr[SPR_VRSAVE]); + gdb_get_reg32(buf, (uint32_t)env->spr[SPR_VRSAVE]); + mem_buf = buf->data - 4; ppc_maybe_bswap_register(env, mem_buf, 4); return 4; } @@ -9965,25 +9971,25 @@ static int gdb_set_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n) return 0; } -static int gdb_get_spe_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_spe_reg(CPUPPCState *env, GByteArray *buf, int n) { if (n < 32) { #if defined(TARGET_PPC64) - stl_p(mem_buf, env->gpr[n] >> 32); - ppc_maybe_bswap_register(env, mem_buf, 4); + gdb_get_reg32(buf, env->gpr[n] >> 32); + ppc_maybe_bswap_register(env, buf->data - 4, 4); #else - stl_p(mem_buf, env->gprh[n]); + gdb_get_reg32(buf, env->gprh[n]); #endif return 4; } if (n == 32) { - stq_p(mem_buf, env->spe_acc); - ppc_maybe_bswap_register(env, mem_buf, 8); + gdb_get_reg64(buf, env->spe_acc); + ppc_maybe_bswap_register(env, buf->data - 8, 8); return 8; } if (n == 33) { - stl_p(mem_buf, env->spe_fscr); - ppc_maybe_bswap_register(env, mem_buf, 4); + gdb_get_reg32(buf, env->spe_fscr); + ppc_maybe_bswap_register(env, buf->data - 4, 4); return 4; } return 0; @@ -10018,11 +10024,11 @@ static int gdb_set_spe_reg(CPUPPCState *env, uint8_t *mem_buf, int n) return 0; } -static int gdb_get_vsx_reg(CPUPPCState *env, uint8_t *mem_buf, int n) +static int gdb_get_vsx_reg(CPUPPCState *env, GByteArray *buf, int n) { if (n < 32) { - stq_p(mem_buf, *cpu_vsrl_ptr(env, n)); - ppc_maybe_bswap_register(env, mem_buf, 8); + gdb_get_reg64(buf, *cpu_vsrl_ptr(env, n)); + ppc_maybe_bswap_register(env, buf->data - 8, 8); return 8; } return 0; diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 1a7947e0198..05442215a4b 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -269,7 +269,7 @@ static int csr_register_map[] = { CSR_MHCOUNTEREN, }; -int riscv_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; @@ -300,10 +300,10 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) return 0; } -static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) +static int riscv_gdb_get_fpu(CPURISCVState *env, GByteArray *buf, int n) { if (n < 32) { - return gdb_get_reg64(mem_buf, env->fpr[n]); + return gdb_get_reg64(buf, env->fpr[n]); /* there is hole between ft11 and fflags in fpu.xml */ } else if (n < 36 && n > 32) { target_ulong val = 0; @@ -316,7 +316,7 @@ static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) result = riscv_csrrw_debug(env, n - 33 + csr_register_map[8], &val, 0, 0); if (result == 0) { - return gdb_get_regl(mem_buf, val); + return gdb_get_regl(buf, val); } } return 0; @@ -345,7 +345,7 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) return 0; } -static int riscv_gdb_get_csr(CPURISCVState *env, uint8_t *mem_buf, int n) +static int riscv_gdb_get_csr(CPURISCVState *env, GByteArray *buf, int n) { if (n < ARRAY_SIZE(csr_register_map)) { target_ulong val = 0; @@ -353,7 +353,7 @@ static int riscv_gdb_get_csr(CPURISCVState *env, uint8_t *mem_buf, int n) result = riscv_csrrw_debug(env, csr_register_map[n], &val, 0, 0); if (result == 0) { - return gdb_get_regl(mem_buf, val); + return gdb_get_regl(buf, val); } } return 0; @@ -373,13 +373,13 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n) return 0; } -static int riscv_gdb_get_virtual(CPURISCVState *cs, uint8_t *mem_buf, int n) +static int riscv_gdb_get_virtual(CPURISCVState *cs, GByteArray *buf, int n) { if (n == 0) { #ifdef CONFIG_USER_ONLY - return gdb_get_regl(mem_buf, 0); + return gdb_get_regl(buf, 0); #else - return gdb_get_regl(mem_buf, cs->priv); + return gdb_get_regl(buf, cs->priv); #endif } return 0; diff --git a/target/s390x/gdbstub.c b/target/s390x/gdbstub.c index e24a49f4a91..d6fce5ff1e1 100644 --- a/target/s390x/gdbstub.c +++ b/target/s390x/gdbstub.c @@ -27,7 +27,7 @@ #include "sysemu/hw_accel.h" #include "sysemu/tcg.h" -int s390_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { S390CPU *cpu = S390_CPU(cs); CPUS390XState *env = &cpu->env; @@ -82,11 +82,11 @@ int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) /* total number of registers in s390-acr.xml */ #define S390_NUM_AC_REGS 16 -static int cpu_read_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_ac_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_A0_REGNUM ... S390_A15_REGNUM: - return gdb_get_reg32(mem_buf, env->aregs[n]); + return gdb_get_reg32(buf, env->aregs[n]); default: return 0; } @@ -111,13 +111,13 @@ static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) /* total number of registers in s390-fpr.xml */ #define S390_NUM_FP_REGS 17 -static int cpu_read_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_fp_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_FPC_REGNUM: - return gdb_get_reg32(mem_buf, env->fpc); + return gdb_get_reg32(buf, env->fpc); case S390_F0_REGNUM ... S390_F15_REGNUM: - return gdb_get_reg64(mem_buf, *get_freg(env, n - S390_F0_REGNUM)); + return gdb_get_reg64(buf, *get_freg(env, n - S390_F0_REGNUM)); default: return 0; } @@ -145,17 +145,17 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) /* total number of registers in s390-vx.xml */ #define S390_NUM_VREGS 32 -static int cpu_read_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_vreg(CPUS390XState *env, GByteArray *buf, int n) { int ret; switch (n) { case S390_V0L_REGNUM ... S390_V15L_REGNUM: - ret = gdb_get_reg64(mem_buf, env->vregs[n][1]); + ret = gdb_get_reg64(buf, env->vregs[n][1]); break; case S390_V16_REGNUM ... S390_V31_REGNUM: - ret = gdb_get_reg64(mem_buf, env->vregs[n][0]); - ret += gdb_get_reg64(mem_buf + 8, env->vregs[n][1]); + ret = gdb_get_reg64(buf, env->vregs[n][0]); + ret += gdb_get_reg64(buf, env->vregs[n][1]); break; default: ret = 0; @@ -186,11 +186,11 @@ static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) #define S390_NUM_C_REGS 16 #ifndef CONFIG_USER_ONLY -static int cpu_read_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_c_reg(CPUS390XState *env, GByteArray *buf, int n) { switch (n) { case S390_C0_REGNUM ... S390_C15_REGNUM: - return gdb_get_regl(mem_buf, env->cregs[n]); + return gdb_get_regl(buf, env->cregs[n]); default: return 0; } @@ -223,7 +223,7 @@ static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) /* total number of registers in s390-virt.xml */ #define S390_NUM_VIRT_REGS 8 -static int cpu_read_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_virt_reg(CPUS390XState *env, GByteArray *mem_buf, int n) { switch (n) { case S390_VIRT_CKC_REGNUM: @@ -296,9 +296,9 @@ static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) /* total number of registers in s390-gs.xml */ #define S390_NUM_GS_REGS 4 -static int cpu_read_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) +static int cpu_read_gs_reg(CPUS390XState *env, GByteArray *buf, int n) { - return gdb_get_regl(mem_buf, env->gscb[n]); + return gdb_get_regl(buf, env->gscb[n]); } static int cpu_write_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) diff --git a/target/sh4/gdbstub.c b/target/sh4/gdbstub.c index 44c1679e9db..49fc4a0cc69 100644 --- a/target/sh4/gdbstub.c +++ b/target/sh4/gdbstub.c @@ -24,7 +24,7 @@ /* Hint: Use "set architecture sh4" in GDB to see fpu registers */ /* FIXME: We should use XML for this. */ -int superh_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int superh_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { SuperHCPU *cpu = SUPERH_CPU(cs); CPUSH4State *env = &cpu->env; diff --git a/target/sparc/gdbstub.c b/target/sparc/gdbstub.c index 8be742b5a3d..78dc8dcc980 100644 --- a/target/sparc/gdbstub.c +++ b/target/sparc/gdbstub.c @@ -27,7 +27,7 @@ #define gdb_get_rega(buf, val) gdb_get_regl(buf, val) #endif -int sparc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int sparc_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { SPARCCPU *cpu = SPARC_CPU(cs); CPUSPARCState *env = &cpu->env; diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c index 54727881f38..0ee3feabe54 100644 --- a/target/xtensa/gdbstub.c +++ b/target/xtensa/gdbstub.c @@ -63,7 +63,7 @@ void xtensa_count_regs(const XtensaConfig *config, } } -int xtensa_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) +int xtensa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { XtensaCPU *cpu = XTENSA_CPU(cs); CPUXtensaState *env = &cpu->env; From patchwork Fri Dec 20 12:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182262 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp460925ilf; Fri, 20 Dec 2019 04:28:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxsA4TQVWrgwfARJrQMdp2QbIx6UmFZkT7d/P7OS3CDa7ccOCL1z31duWQ/bU/gN976ZqoZ X-Received: by 2002:ac8:704e:: with SMTP id y14mr11291561qtm.279.1576844880717; Fri, 20 Dec 2019 04:28:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844880; cv=none; d=google.com; s=arc-20160816; b=BUnkenSK+1Ed7fcmiZ0O/T+c4hDjp8xx3K892tcqRodXQNcOUxCCnHoIvS9Ci1zOtr E7/k61mnmIllGpS9fHDWmibZIuC6aP2niKoa6n52yfeuxWhmwVs5wM61jkwHGAvsqdog evNTACfOnZSYXxWUdrbHpFF83BnR/aHvLHsQkZuZ20KE44I3xAPJbjAVAeXKp7jqADcC v+150XM9mpOi9fl+CKYtwOZcuQKL7+to5mc3fr825ZnBI6gBHyYMMCpgkggYNZ2ZQeaY p1UqL9Fjj1v3n4MnPTKCVmkE4gzslOGr+AZ6Ggu7HKNWQsWHE4+8PZQbMhajFs94LZvj vwHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=uSoN3UMb6AaLnAvCuGLKr2zDRfmMIGX2Xip44JgQq3FiZK+GURJcvCJYFaYiFWp1AK 6G4NVoXeNzVyykPxvinfZhd86SUMlkPTnqzIFwYyWHgeKW8lqFwK4bIFx+l7xcD9GQUt utI1PKXqGV14dFW3BWtHa1EtHmFZIi5rJ3q06f6KM54JOIIqCmbnFUZejwO2b1dDKBCB irgjZdP9XRtQ3uZEprEowkdKJf+Iipd3p2bI6GnLYeaZ3Ak1dzNWrKRa3byj5rPIjUPv G48xur33XW36KcFEvLTvTrH0Qi/F19aaPxhFDIRfgvvpvQs/dsYxwzKqFluOUjbtZjO4 l2Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zf7pxHfw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q126si5266024qka.361.2019.12.20.04.28.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:28:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zf7pxHfw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHNw-00028E-78 for patch@linaro.org; Fri, 20 Dec 2019 07:28:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53709) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1k-0004rp-0y for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1e-000881-3N for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:03 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1d-00084q-OA for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:57 -0500 Received: by mail-wr1-x443.google.com with SMTP id t2so9205406wrr.1 for ; Fri, 20 Dec 2019 04:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=zf7pxHfwzEDlsgRvDI3Gpj1CcG5uUIUIUl+xMsUxnlOyJB36nmqqsRU13tXmumM6wE ermA5ztZ5EUFjEwiltk/zFWK3SlxhyX9NJsWvpHaE8oHnMt5cXPwt5jie6ltUhWb7nIN NE8ASZTwlhjYp94hG0KAiDQ5YFbGwqN8KzMUmh9z1U/0rkyZVVunc4wcXd+DMOxg97F1 u/Vi0PHP0FMuyTN7kpVMfztgcnollB369IYvxO+giX790Q/vYNln4EyPNbdnDXLnc7FR xsyHzvmM3OV5qSpFFTJQ0yzREZTUR5eTaOk2YiJecv5szmGQf3N3yJ+QyDRQNsFKwIgW KSCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=czanuspGcHlKRukvMkLTGjn1x611kvgV7PuFbsiK1Pk=; b=MkpkYyMS+kbaXYbOpRhGd6GsxNDOzdVPtwNilADR4D5taaEZWS5371pFIAY+bWlYTs BZpsfvZ98CpJUjz+wYlDiPPTFgAhgho3vIwtK/uFCzUuUxx35M8v2SzvclIk0JaIjODb j24u0W+6w3soeGY9wG5rXbnL9eX6kGpkrAXPsy89EdFzOlyc0y2OxnlxCnaY48lfL998 8PK7N7KeO/28kep5BU0LYOPiiBrHVGBQBPwifSHJpKJVJx61s3SztSAZS049g/47E3mm cQKC5czAzBeUModM1o1MyeAPu6hvtEyjwpRbwnBFnVMP4asJ+lfJTnALGE/eNQapaJSJ tPnA== X-Gm-Message-State: APjAAAVyAxbWtaxjGUQVwsuHEmSeHP7RFSNBqRdqs2DqCuGSri6LpxSu 9HSXRmenn4dyAlrNHdWshs7XEQ== X-Received: by 2002:a5d:690e:: with SMTP id t14mr14764377wru.65.1576843496579; Fri, 20 Dec 2019 04:04:56 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v22sm8994211wml.11.2019.12.20.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 00A051FF99; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 09/21] target/arm: prepare for multiple dynamic XMLs Date: Fri, 20 Dec 2019 12:04:26 +0000 Message-Id: <20191220120438.16114-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will want to generate similar dynamic XML for gdbstub support of SVE registers (the upstream doesn't use XML). To that end lightly rename a few things to make the distinction. Signed-off-by: Alex Bennée --- target/arm/cpu.h | 20 +++++++++++++------- target/arm/gdbstub.c | 30 +++++++++++++++--------------- target/arm/helper.c | 4 ++-- 3 files changed, 30 insertions(+), 24 deletions(-) -- 2.20.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 19b3ac32113..59d5dbae31f 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -128,14 +128,20 @@ enum { /** * DynamicGDBXMLInfo: * @desc: Contains the XML descriptions. - * @num_cpregs: Number of the Coprocessor registers seen by GDB. - * @cpregs_keys: Array that contains the corresponding Key of - * a given cpreg with the same order of the cpreg in the XML description. + * @num: Number of the registers in this XML seen by GDB. + * @data: A union with data specific to the set of registers + * @cpregs_keys: Array that contains the corresponding Key of + * a given cpreg with the same order of the cpreg + * in the XML description. */ typedef struct DynamicGDBXMLInfo { char *desc; - int num_cpregs; - uint32_t *cpregs_keys; + int num; + union { + struct { + uint32_t *keys; + } cpregs; + } data; } DynamicGDBXMLInfo; /* CPU state for each instance of a generic timer (in cp15 c14) */ @@ -748,7 +754,7 @@ struct ARMCPU { uint64_t *cpreg_vmstate_values; int32_t cpreg_vmstate_array_len; - DynamicGDBXMLInfo dyn_xml; + DynamicGDBXMLInfo dyn_sysreg_xml; /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; @@ -955,7 +961,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); /* Dynamically generates for gdb stub an XML description of the sysregs from * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_xml(CPUState *cpu); +int arm_gen_dynamic_sysreg_xml(CPUState *cpu); /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 4557775d245..1f68ab98c3b 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -106,15 +106,15 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) return 0; } -static void arm_gen_one_xml_reg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, - ARMCPRegInfo *ri, uint32_t ri_key, - int bitsize) +static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, + ARMCPRegInfo *ri, uint32_t ri_key, + int bitsize) { g_string_append_printf(s, "name); g_string_append_printf(s, " bitsize=\"%d\"", bitsize); g_string_append_printf(s, " group=\"cp_regs\"/>"); - dyn_xml->num_cpregs++; - dyn_xml->cpregs_keys[dyn_xml->num_cpregs - 1] = ri_key; + dyn_xml->data.cpregs.keys[dyn_xml->num] = ri_key; + dyn_xml->num++; } static void arm_register_sysreg_for_xml(gpointer key, gpointer value, @@ -126,12 +126,12 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value, GString *s = param->s; ARMCPU *cpu = ARM_CPU(param->cs); CPUARMState *env = &cpu->env; - DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_xml; + DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_sysreg_xml; if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) { if (arm_feature(env, ARM_FEATURE_AARCH64)) { if (ri->state == ARM_CP_STATE_AA64) { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); } } else { if (ri->state == ARM_CP_STATE_AA32) { @@ -140,30 +140,30 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value, return; } if (ri->type & ARM_CP_64BIT) { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); } else { - arm_gen_one_xml_reg_tag(s , dyn_xml, ri, ri_key, 32); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32); } } } } } -int arm_gen_dynamic_xml(CPUState *cs) +int arm_gen_dynamic_sysreg_xml(CPUState *cs) { ARMCPU *cpu = ARM_CPU(cs); GString *s = g_string_new(NULL); RegisterSysregXmlParam param = {cs, s}; - cpu->dyn_xml.num_cpregs = 0; - cpu->dyn_xml.cpregs_keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs)); + cpu->dyn_sysreg_xml.num = 0; + cpu->dyn_sysreg_xml.data.cpregs.keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs)); g_string_printf(s, ""); g_string_append_printf(s, ""); g_string_append_printf(s, ""); g_hash_table_foreach(cpu->cp_regs, arm_register_sysreg_for_xml, ¶m); g_string_append_printf(s, ""); - cpu->dyn_xml.desc = g_string_free(s, false); - return cpu->dyn_xml.num_cpregs; + cpu->dyn_sysreg_xml.desc = g_string_free(s, false); + return cpu->dyn_sysreg_xml.num; } const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) @@ -171,7 +171,7 @@ const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) ARMCPU *cpu = ARM_CPU(cs); if (strcmp(xmlname, "system-registers.xml") == 0) { - return cpu->dyn_xml.desc; + return cpu->dyn_sysreg_xml.desc; } return NULL; } diff --git a/target/arm/helper.c b/target/arm/helper.c index 36872627a5d..0a3bc53124e 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -207,7 +207,7 @@ static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) const ARMCPRegInfo *ri; uint32_t key; - key = cpu->dyn_xml.cpregs_keys[reg]; + key = cpu->dyn_sysreg_xml.data.cpregs.keys[reg]; ri = get_arm_cp_reginfo(cpu->cp_regs, key); if (ri) { if (cpreg_field_is_64bit(ri)) { @@ -7129,7 +7129,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) 19, "arm-vfp.xml", 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_xml(cs), + arm_gen_dynamic_sysreg_xml(cs), "system-registers.xml", 0); } From patchwork Fri Dec 20 12:04:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182250 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp444910ilf; Fri, 20 Dec 2019 04:14:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzJrPpw1/5vuZBcP/vUD9IwTSx6MnyfKMzYV3f2J0hstTyfC85N1fFTwZyvwyl/A4YIH5CG X-Received: by 2002:a9d:402:: with SMTP id 2mr4515933otc.357.1576844051402; Fri, 20 Dec 2019 04:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844051; cv=none; d=google.com; s=arc-20160816; b=yKIpq/HeU15xgMRbmkD/GazC4nPoxwGeha181rYnEDZoC29HQUca3558HjUpde3EZR ekTXFhAXPtrAHf77qjBtIEdeOCx8U4SAESGwQDFXTFASuti/stMBcSinMgeppgAPj0Xk 7XLRRYM/hbddmwLLA45OR55cVVaKC2lA/COHEtvXKNUI49dODrjctGbd3QeXPKuE3Vir S1IsUiuXmG8q19OyLdn6PpZWgX2Xq98VllXKuDOJi+4/na3pC4yZzmwHMXEGLuPRewcp HfdCSrHWsnX1sdbSYML+X56W/PY/k50ioPhSefnvYjL3mQHLIiwnoxlsq48akBdoN4yT k8lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=zbull54MV1trkO85rOVerDi2GrrFViTuy2VNhA0gFzUmPnB2Sk0GvG7sPTJbGqNeeH CDJSflPDtTXRLaWrzcNE8Z9jtn8VDy+/UeEVG6KjOVw5+SWkRFmOM0RGkUlqwzQBnfJs fu70Z/gc0EPWWkhDbmsHmlQXF5O3xN8rV/L/D4yrtHm8xC7ZNk0CQrZMLBx/clQroH1x ElZBwNtWH5Bexmi0oZNFMu94MVw3Ow2Rs2urj8zxnKkVpECLLOn0aO1+bq0FMNke+cCM gN1f01RuGNqIcXtfjZCeA9KCgeK2eQkDqbiwbctyOngqH2TmNfTcp5IClRsEmRXU/513 YvxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zEOXQ3yp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n85si4638960oig.191.2019.12.20.04.14.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:14:11 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zEOXQ3yp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAY-00085f-NI for patch@linaro.org; Fri, 20 Dec 2019 07:14:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53713) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1k-0004rq-0x for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1f-0008E2-JN for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:03 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1f-00089i-6k for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:04:59 -0500 Received: by mail-wr1-x442.google.com with SMTP id y17so9206945wrh.5 for ; Fri, 20 Dec 2019 04:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=zEOXQ3ypHQuLtrfxR0Q4lqmX6p8ZLE7D8i/NgyItrA85Sd5CnbuDRtnX/v6nyC1FNl 1ohtO6OhK3Q0MR40wRBO8MKy3joQ8oEDDPikRjMUnL98n8OQ6/2zHHUXJ4fmJdnglmm4 BozmDTsyik1HEiw8HwQCWTN686TTKefXkG0Y0aPHRRooslhCiygnDqpuoQQj9yXWxkaY BOZCO2XmC3KFLaeUh87M1qduz0TQozDEFGLJl6cmfSLmf77fZHq4q8K22pTbxr2T2ji5 tUEqqNaf6vRkiM/KJXPe/JbzcPmt6Hw3bTjdOaq/F0zcBMgopWD3+n3Jn8kHw1x3Q8W9 as3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frx1aURZvMjiv5Ib6mAusHFiIu8eDIVWmRgHjBz837s=; b=TVa5PeiCMmrrr5c6gmZihSalVN97zrTgfdVzvA5liVlQLAOdV/Z0fa9QyMo31DHveR TWyuZNEB1aJwO8o6aVNfnQlQbyKFdwdaC8zf9yzDF2cOtbmlNHeQAtzhzO/bEbLkmIeQ SDXKrfUEkyRiYkglROK55GnTFm1DWyiv+LE/vp2aqH/sSe4obLjHbKaDLKm1AvskyG21 /Ckygw4GqkvNQX0P90vGuIiNvd4PufFLbTtiw2J5XEi/txqX7l9+ggrJuY2Bp85AkFtR 1kA4r6S0KO3JZFu6A7SpJ4HQqmOiiVbdsvKjiU3MVF3dwC9R4YRmuEYogf8Pi0YM/xO0 ZbPg== X-Gm-Message-State: APjAAAWgSD/peroCD8iqrq8Jg1MiNlxqaZXhd9h/VBbr9NnOsJCMFI6d NyMlJaJ3hEMUMWQXYHCgal1E+g== X-Received: by 2002:a5d:4847:: with SMTP id n7mr14991390wrs.30.1576843498083; Fri, 20 Dec 2019 04:04:58 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u14sm9777423wrm.51.2019.12.20.04.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:48 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1760C1FF9A; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 10/21] target/arm: explicitly encode regnum in our XML Date: Fri, 20 Dec 2019 12:04:27 +0000 Message-Id: <20191220120438.16114-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is described as optional but I'm not convinced of the numbering when multiple target fragments are sent. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - post inc param->n in place so we don't get out count wrong --- target/arm/cpu.h | 2 +- target/arm/gdbstub.c | 17 +++++++++++------ target/arm/helper.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) -- 2.20.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 59d5dbae31f..40591b5dc70 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -961,7 +961,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); /* Dynamically generates for gdb stub an XML description of the sysregs from * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_sysreg_xml(CPUState *cpu); +int arm_gen_dynamic_sysreg_xml(CPUState *cpu, int base_reg); /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 1f68ab98c3b..69c35462a63 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -24,6 +24,7 @@ typedef struct RegisterSysregXmlParam { CPUState *cs; GString *s; + int n; } RegisterSysregXmlParam; /* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect @@ -108,10 +109,11 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, ARMCPRegInfo *ri, uint32_t ri_key, - int bitsize) + int bitsize, int regnum) { g_string_append_printf(s, "name); g_string_append_printf(s, " bitsize=\"%d\"", bitsize); + g_string_append_printf(s, " regnum=\"%d\"", regnum); g_string_append_printf(s, " group=\"cp_regs\"/>"); dyn_xml->data.cpregs.keys[dyn_xml->num] = ri_key; dyn_xml->num++; @@ -131,7 +133,8 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value, if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_NO_GDB))) { if (arm_feature(env, ARM_FEATURE_AARCH64)) { if (ri->state == ARM_CP_STATE_AA64) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, + param->n++); } } else { if (ri->state == ARM_CP_STATE_AA32) { @@ -140,20 +143,22 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value, return; } if (ri->type & ARM_CP_64BIT) { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 64, + param->n++); } else { - arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32); + arm_gen_one_xml_sysreg_tag(s , dyn_xml, ri, ri_key, 32, + param->n++); } } } } } -int arm_gen_dynamic_sysreg_xml(CPUState *cs) +int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) { ARMCPU *cpu = ARM_CPU(cs); GString *s = g_string_new(NULL); - RegisterSysregXmlParam param = {cs, s}; + RegisterSysregXmlParam param = {cs, s, base_reg}; cpu->dyn_sysreg_xml.num = 0; cpu->dyn_sysreg_xml.data.cpregs.keys = g_new(uint32_t, g_hash_table_size(cpu->cp_regs)); diff --git a/target/arm/helper.c b/target/arm/helper.c index 0a3bc53124e..488fdbf61a9 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -7129,7 +7129,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) 19, "arm-vfp.xml", 0); } gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, - arm_gen_dynamic_sysreg_xml(cs), + arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs), "system-registers.xml", 0); } From patchwork Fri Dec 20 12:04:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182255 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp451001ilf; Fri, 20 Dec 2019 04:19:20 -0800 (PST) X-Google-Smtp-Source: APXvYqxNyhBdzrN6MfrLEop41L8GgQV8VJ7yyNnGoibG8pam7nOAItVif13f4af9DeUUvVsUhekD X-Received: by 2002:a9d:222f:: with SMTP id o44mr2029123ota.51.1576844360424; Fri, 20 Dec 2019 04:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844360; cv=none; d=google.com; s=arc-20160816; b=QJiiGtl25QQya+gWOLtNDaJwtzv3bACEnyWWbej5wKaDVBF/k1GHX/ts+21ZTF2AUF g7US9ZlWFbhcP2dtD1PXFjDonPC00EmXDZPMDYF20Ig4lx2+Mv5Fd267DOL8eFWgb9e0 wMD6S7/uHbxPlIUITxOSpxHpt4N8GflSJafn9nSIsqDpTeW1riwo6vTSmoQuqKF84Hf5 XiTviIvsaxYJPgLD2tWHC5htbn2ChiXkbW4HWQDYCgqvQzQGz6x8hhwn/fZI7Q4PpufP UY226lxiB2WGROnQkTIfclg4zZPqcI4vVtE6/QNZhzdUUgwRkZZK3ezbnPf/xM2bh6TD xZow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=laI0MupuSfcCh/zikJNfllc/7oxUNym7x7hf/ylKElTG0Rjy9Wdp2MW0lEPQGFj2QQ BrEoaixBauvQEx69Uzb7kr3D2Ywjvj6IFNCZFS78vVZbXgfn8N/Fj3BfPmsT2bDoxfTJ VE+zNZjBczX+9R1dHPa3/1n1VMuRYD7IxLQJunw1qQhpuAsdG957aIjShGZGvj5kQWOy jms3QjF86vmrzMsZG5k45GFNLLpTGyI2Y+Qcu5AGaPXelmFz03Ej1cWvgnzCihuQXJ4k sVh5U8NDScWLbXax2DpJ84+0pfLrXnuN8HQQ/RaSwPoDJLXkrg7MaxJlKhIptSYjfPBK FYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KZafxjOH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o4si4817692oib.70.2019.12.20.04.19.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:19:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KZafxjOH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHFX-0006tQ-Ia for patch@linaro.org; Fri, 20 Dec 2019 07:19:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54443) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1y-000587-SF for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1q-0008SZ-5X for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:15 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:52406) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1o-0008Oj-O0 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:09 -0500 Received: by mail-wm1-x341.google.com with SMTP id p9so8694650wmc.2 for ; Fri, 20 Dec 2019 04:05:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=KZafxjOH1S30qEh72GnMUHe2Au3BKIRFNGoG+fusNFoSXd61bMzh2txwNDqIhUrWQ8 lsrFGNfq94RRztbZSLmBp1IZazWVx1xgFb4Nlu+kauZ+ZoCEoh6d2zZZOjzPf3q7sGH+ fupYZcO6tS99qPBjwTnrreimuBWw6KkOc4ym3r07qndFNjQxi9h2UMruWlaTDBeWXBL7 d5Wahcms/WP45ndLpzTUGYw9DXWohfk2QxMDaFzg2w7VMtCgvwHYZ7NkCNbFc/Sk5nvU LOMfb3qzVxp09VdCibz878qyKu36LPWOMQaBj9tr0luSw6I4m4xUGuo0h5KYP/enWVb/ F3Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YX/3QlJb96xuPlFrDu4WTqDveBFpdotwZIYVwV0XY7M=; b=AkBNO/DlnZBChzzVyYVoDLQOnVs2dHj+8/HzhXpfRNGxMoL9CFKBb8+9FcwliaNlYu HeqzF4O1zNIt+un/468R2GcJm8RQUhDoPEAsF+DT2Vafr/cejJmGnssOQwqOVoAjdheL ugnpSWjdiMhMSsxwubQK1e+J/7rECyatC5rStDIVTR2LsALu9GCCBiamZJvXwhRd4cbN lCK4OkpRh7Omkigb30i/wt4xaj15R3AVOIp9CmZSjToT+On5VE8CN1cw2c6bAgjqwXyx oxGdzfZSltKpZltWD66vT45gEkZYZUijnS0rR+RwFWTcodRtUnPeAm0wcps7Bc2zTz9u hu8g== X-Gm-Message-State: APjAAAWM7rbgDVEg7W/GQ/4vwt5sDpo6mbmoxnKHccqok2dGiLDYIPIq fN/t4WloUK7CUVidAKuSEZtwVA== X-Received: by 2002:a1c:7419:: with SMTP id p25mr15515137wmc.129.1576843507082; Fri, 20 Dec 2019 04:05:07 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x18sm9681364wrr.75.2019.12.20.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:51 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 2C4A81FF9B; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 11/21] target/arm: default SVE length to 64 bytes for linux-user Date: Fri, 20 Dec 2019 12:04:28 +0000 Message-Id: <20191220120438.16114-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The Linux kernel chooses the default of 64 bytes for SVE registers on the basis that it is the largest size on known hardware that won't grow the signal frame. We still honour the sve-max-vq property and userspace can expand the number of lanes by calling PR_SVE_SET_VL. This should not make any difference to SVE enabled software as the SVE is of course vector length agnostic. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - tweak zcr_el[1] instead --- target/arm/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index dd51adac059..2d2e786245b 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -199,9 +199,9 @@ static void arm_cpu_reset(CPUState *s) /* and to the SVE instructions */ env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 16, 2, 3); env->cp15.cptr_el[3] |= CPTR_EZ; - /* with maximum vector length */ + /* with reasonable vector length */ env->vfp.zcr_el[1] = cpu_isar_feature(aa64_sve, cpu) ? - cpu->sve_max_vq - 1 : 0; + MIN(cpu->sve_max_vq - 1, 3) : 0; env->vfp.zcr_el[2] = env->vfp.zcr_el[1]; env->vfp.zcr_el[3] = env->vfp.zcr_el[1]; /* From patchwork Fri Dec 20 12:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182259 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp457033ilf; Fri, 20 Dec 2019 04:24:32 -0800 (PST) X-Google-Smtp-Source: APXvYqx/gp4fVE/ImPPeKANM50Utref2Gln2uyfCNrdhbNjaG1m4qfZ8TDWh6px2gRlIBdSb31wx X-Received: by 2002:a05:620a:134d:: with SMTP id c13mr12618098qkl.322.1576844672852; Fri, 20 Dec 2019 04:24:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844672; cv=none; d=google.com; s=arc-20160816; b=U5xDsuK/CX6PbI8B+/o9sEgT1oGzhPCevhDAZ3LmwedNojjIIy6f4ux1YcpdTryaGj 6LgJBcs+YDoAvK0Ydtago7RCmzw6/htGGM7qFT41XeNZmhGnUDYZ4KTxmBuwiy/73G7m ceDv2qkIhcY6Y2iYAf3m2Imd5m/mIrgPaF4ucCwX25tctFult+og5a7e04Uqbfk2IVFc B6E1d/VQyjqs9iUHKHHqyNo5+fzYVbtC3JsJshqiBBAQJMGrA2dCaU7OW1AfBhpSN4ON 6pOMR8VlafR2sLo2yiVvVpy296uOGU/qaOlepLNtEf3qQYH0FyPBwLdOey2wkjzJihIc H/ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=lJrL/ZJ9B92oDfoV7Qauli1bDTEvUX2FU+/r7gO+jXiMjKpzGduZt/k1b4Kub4yrMh OokK3J176yLNmAiUGWOb7EbN5FgkENbwywh6AwGnF1hD7cg3jsW5gAKPvYogCBgtDppp z0Z3XymoTHKeywIPvpgZv0HfXMpXNGCabHYxhCAr+WR8Z7bOBKbz8v0EAzQoMUQQWP4w 9EtGIxxuA4q9BAdOMiWjomBGtaghwdYkyS0JPWA6QaUu1LU97YqhSS5WwKUsd2tByA5V SwEYLCX8Zgaw4/Cs7kgLO1F3bMkDlYoRcseVJeOMNtznJaW/rf8zbP27iJ051lRlw19L VI/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SMtfPsTr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f7si4613847qtq.320.2019.12.20.04.24.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:24:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SMtfPsTr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHKa-0006Gx-5n for patch@linaro.org; Fri, 20 Dec 2019 07:24:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54467) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1z-00058v-8S for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1u-00005q-Mo for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:18 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:55562) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1s-0008TU-DM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: by mail-wm1-x343.google.com with SMTP id q9so8693662wmj.5 for ; Fri, 20 Dec 2019 04:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=SMtfPsTri149jjIu+UJkvmetbIcnvlz9/IeVCHdGENCRiTHpdWtE/kSy0FPYebdvTc PDrpwOROaPUEz94UI9WSyvujhD0kxkTzhLT5ZjCzA5kkp7W+8xu9VW3Dw4dwHGekvzvz Hogtk/oHNAphBnalwXb6DPpCtv1q6vQJ0WLY/r2IG7cYh/m4Yu1nfmmAVbJd6Nyiyof9 8jMhX5MjH2sGXWymoTZLqZ5GlySwChV2xFT4frb9MZtu9KI/HxXmNA3H9hascAN1xdIX glXJ8xHG9z3q6vFxdYuwamyJp2uJJB1oBXRE88ai/bNt6BNEGUj1ct459UPFmvg7plfk mggw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0lj3FMjn35XuuJVdZtoKvCODlvGJ+nX8a+H04fPMgEc=; b=QlmeGzvUDARBAMoLQJ2I9gsW0JhbUBxehewEIGSQVf9HO3GNiE+QUs6G8vxl4KYGtY T87eRuyIxMU2T6IEJFdV0DErdHhOwzNYD5gtLpP5XMecD5BfU9R4AHO3lQ9UdEchJRbM kcfO7X10ZcenZY2Bj7DIL/6u8JY/IPe5YToSec70/sRzC6NoGYicZjbA7dQJgaT7UEx9 n5x/ODnQ/CyGIB6Wh8AYHBzI6Clzs5gzlqTOJW9wzXA0WubfO+OJPrtCF/zps9lxXXgr 8JUJRmfoJN2H9fpr1ZfONrjmFsh1MT9wLWr9h0FJqSXYxTSfe6rjYnCi/ja2TCIaeO6y Bo9w== X-Gm-Message-State: APjAAAUR8EexgXzq2MRwp+embZqYmnTPvConUkrbl+33xcTU9atK+Hxn eAh90igowirRwm0fjbr3x58hpw== X-Received: by 2002:a05:600c:409:: with SMTP id q9mr15852063wmb.19.1576843509874; Fri, 20 Dec 2019 04:05:09 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u24sm9396531wml.10.2019.12.20.04.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:51 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 44E8A1FF9C; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 12/21] target/arm: generate xml description of our SVE registers Date: Fri, 20 Dec 2019 12:04:29 +0000 Message-Id: <20191220120438.16114-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We also expose a the helpers to read/write the the registers. Signed-off-by: Alex Bennée --- v2 - instead of zNpM expose zN at sve_max_vq width - wrap union in union q(us), d(usf), s(usf), h(usf), b(us) v3 - add a vg pseudo register for current width - spacing fixes - use switch/case for whole group - drop fpsr_pos marker - remove unused variables v4 - const-ify vec_lanes - drop vg --- target/arm/cpu.h | 7 ++- target/arm/gdbstub.c | 129 +++++++++++++++++++++++++++++++++++++++++++ target/arm/helper.c | 113 ++++++++++++++++++++++++++++++++++++- 3 files changed, 244 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 40591b5dc70..33b96a0c066 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -755,6 +755,7 @@ struct ARMCPU { int32_t cpreg_vmstate_array_len; DynamicGDBXMLInfo dyn_sysreg_xml; + DynamicGDBXMLInfo dyn_svereg_xml; /* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS]; @@ -958,10 +959,12 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, int arm_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); -/* Dynamically generates for gdb stub an XML description of the sysregs from - * the cp_regs hashtable. Returns the registered sysregs number. +/* + * Helpers to dynamically generates XML descriptions of the sysregs + * and SVE registers. Returns the number of registers in each set. */ int arm_gen_dynamic_sysreg_xml(CPUState *cpu, int base_reg); +int arm_gen_dynamic_svereg_xml(CPUState *cpu, int base_reg); /* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index 69c35462a63..d9dc6b3fb41 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -171,12 +171,141 @@ int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) return cpu->dyn_sysreg_xml.num; } +struct TypeSize { + const char *gdb_type; + int size; + const char sz, suffix; +}; + +static const struct TypeSize vec_lanes[] = { + /* quads */ + { "uint128", 128, 'q', 'u' }, + { "int128", 128, 'q', 's' }, + /* 64 bit */ + { "uint64", 64, 'd', 'u' }, + { "int64", 64, 'd', 's' }, + { "ieee_double", 64, 'd', 'f' }, + /* 32 bit */ + { "uint32", 32, 's', 'u' }, + { "int32", 32, 's', 's' }, + { "ieee_single", 32, 's', 'f' }, + /* 16 bit */ + { "uint16", 16, 'h', 'u' }, + { "int16", 16, 'h', 's' }, + { "ieee_half", 16, 'h', 'f' }, + /* bytes */ + { "uint8", 8, 'b', 'u' }, + { "int8", 8, 'b', 's' }, +}; + + +int arm_gen_dynamic_svereg_xml(CPUState *cs, int base_reg) +{ + ARMCPU *cpu = ARM_CPU(cs); + GString *s = g_string_new(NULL); + DynamicGDBXMLInfo *info = &cpu->dyn_svereg_xml; + g_autoptr(GString) ts = g_string_new(""); + int i, bits, reg_width = (cpu->sve_max_vq * 128); + info->num = 0; + g_string_printf(s, ""); + g_string_append_printf(s, ""); + g_string_append_printf(s, ""); + + /* First define types and totals in a whole VL */ + for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { + int count = reg_width / vec_lanes[i].size; + g_string_printf(ts, "vq%d%c%c", count, + vec_lanes[i].sz, vec_lanes[i].suffix); + g_string_append_printf(s, + "", + ts->str, vec_lanes[i].gdb_type, count); + } + /* + * Now define a union for each size group containing unsigned and + * signed and potentially float versions of each size from 128 to + * 8 bits. + */ + for (bits = 128; bits >= 8; bits /= 2) { + int count = reg_width / bits; + g_string_append_printf(s, "", count); + for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { + if (vec_lanes[i].size == bits) { + g_string_append_printf(s, "", + vec_lanes[i].suffix, + count, + vec_lanes[i].sz, vec_lanes[i].suffix); + } + } + g_string_append(s, ""); + } + /* And now the final union of unions */ + g_string_append(s, ""); + for (bits = 128; bits >= 8; bits /= 2) { + int count = reg_width / bits; + for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { + if (vec_lanes[i].size == bits) { + g_string_append_printf(s, "", + vec_lanes[i].sz, count); + break; + } + } + } + g_string_append(s, ""); + + /* Then define each register in parts for each vq */ + for (i = 0; i < 32; i++) { + g_string_append_printf(s, + "", + i, reg_width, base_reg++); + info->num++; + } + /* fpscr & status registers */ + g_string_append_printf(s, "", base_reg++); + g_string_append_printf(s, "", base_reg++); + info->num += 2; + /* + * Predicate registers aren't so big they are worth splitting up + * but we do need to define a type to hold the array of quad + * references. + */ + g_string_append_printf(s, + "", + cpu->sve_max_vq); + for (i = 0; i < 16; i++) { + g_string_append_printf(s, + "", + i, cpu->sve_max_vq * 16, base_reg++); + info->num++; + } + g_string_append_printf(s, + "", + cpu->sve_max_vq * 16, base_reg++); + info->num += 1; + g_string_append_printf(s, ""); + cpu->dyn_svereg_xml.desc = g_string_free(s, false); + + return cpu->dyn_svereg_xml.num; +} + + const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) { ARMCPU *cpu = ARM_CPU(cs); if (strcmp(xmlname, "system-registers.xml") == 0) { return cpu->dyn_sysreg_xml.desc; + } else if (strcmp(xmlname, "sve-registers.xml") == 0) { + return cpu->dyn_svereg_xml.desc; } return NULL; } diff --git a/target/arm/helper.c b/target/arm/helper.c index 488fdbf61a9..857581feba4 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -201,6 +201,15 @@ static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri, } } +/** + * arm_get/set_gdb_*: get/set a gdb register + * @env: the CPU state + * @buf: a buffer to copy to/from + * @reg: register number (offset from start of group) + * + * We return the number of bytes copied + */ + static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg) { ARMCPU *cpu = env_archcpu(env); @@ -224,6 +233,90 @@ static int arm_gdb_set_sysreg(CPUARMState *env, uint8_t *buf, int reg) return 0; } +#ifdef TARGET_AARCH64 +static int arm_gdb_get_svereg(CPUARMState *env, GByteArray *buf, int reg) +{ + ARMCPU *cpu = env_archcpu(env); + + switch (reg) { + /* The first 32 registers are the zregs */ + case 0 ... 31: + { + int vq, len = 0; + for (vq = 0; vq < cpu->sve_max_vq; vq++) { + len += gdb_get_reg128(buf, + env->vfp.zregs[reg].d[vq * 2 + 1], + env->vfp.zregs[reg].d[vq * 2]); + } + return len; + } + case 32: + return gdb_get_reg32(buf, vfp_get_fpsr(env)); + case 33: + return gdb_get_reg32(buf, vfp_get_fpcr(env)); + /* then 16 predicates and the ffr */ + case 34 ... 50: + { + int preg = reg - 34; + int vq, len = 0; + for (vq = 0; vq < cpu->sve_max_vq; vq = vq + 4) { + len += gdb_get_reg64(buf, env->vfp.pregs[preg].p[vq / 4]); + } + return len; + } + default: + /* gdbstub asked for something out our range */ + qemu_log_mask(LOG_UNIMP, "%s: out of range register %d", __func__, reg); + break; + } + + return 0; +} + +static int arm_gdb_set_svereg(CPUARMState *env, uint8_t *buf, int reg) +{ + ARMCPU *cpu = env_archcpu(env); + + /* The first 32 registers are the zregs */ + switch (reg) { + /* The first 32 registers are the zregs */ + case 0 ... 31: + { + int vq, len = 0; + uint64_t *p = (uint64_t *) buf; + for (vq = 0; vq < cpu->sve_max_vq; vq++) { + env->vfp.zregs[reg].d[vq * 2 + 1] = *p++; + env->vfp.zregs[reg].d[vq * 2] = *p++; + len += 16; + } + return len; + } + case 32: + vfp_set_fpsr(env, *(uint32_t *)buf); + return 4; + case 33: + vfp_set_fpcr(env, *(uint32_t *)buf); + return 4; + case 34 ... 50: + { + int preg = reg - 34; + int vq, len = 0; + uint64_t *p = (uint64_t *) buf; + for (vq = 0; vq < cpu->sve_max_vq; vq = vq + 4) { + env->vfp.pregs[preg].p[vq / 4] = *p++; + len += 8; + } + return len; + } + default: + /* gdbstub asked for something out our range */ + break; + } + + return 0; +} +#endif /* TARGET_AARCH64 */ + static bool raw_accessors_invalid(const ARMCPRegInfo *ri) { /* Return true if the regdef would cause an assertion if you called @@ -7115,9 +7208,22 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) CPUARMState *env = &cpu->env; if (arm_feature(env, ARM_FEATURE_AARCH64)) { - gdb_register_coprocessor(cs, aarch64_fpu_gdb_get_reg, - aarch64_fpu_gdb_set_reg, - 34, "aarch64-fpu.xml", 0); + /* + * The lower part of each SVE register aliases to the FPU + * registers so we don't need to include both. + */ +#ifdef TARGET_AARCH64 + if (isar_feature_aa64_sve(&cpu->isar)) { + gdb_register_coprocessor(cs, arm_gdb_get_svereg, arm_gdb_set_svereg, + arm_gen_dynamic_svereg_xml(cs, cs->gdb_num_regs), + "sve-registers.xml", 0); + } else +#endif + { + gdb_register_coprocessor(cs, aarch64_fpu_gdb_get_reg, + aarch64_fpu_gdb_set_reg, + 34, "aarch64-fpu.xml", 0); + } } else if (arm_feature(env, ARM_FEATURE_NEON)) { gdb_register_coprocessor(cs, vfp_gdb_get_reg, vfp_gdb_set_reg, 51, "arm-neon.xml", 0); @@ -7131,6 +7237,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) gdb_register_coprocessor(cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs), "system-registers.xml", 0); + } /* Sort alphabetically by type name, except for "any". */ From patchwork Fri Dec 20 12:04:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182251 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp445707ilf; Fri, 20 Dec 2019 04:14:50 -0800 (PST) X-Google-Smtp-Source: APXvYqxew2gUMc+rNNXbGF6EaXx6KGXoA4zBWpn1OTOj/SR6LX5LsyWhFv5Y0J8uqVO4FRjwrd5L X-Received: by 2002:a9d:7ac9:: with SMTP id m9mr14139183otn.80.1576844089957; Fri, 20 Dec 2019 04:14:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844089; cv=none; d=google.com; s=arc-20160816; b=eR28eLMgdI+B/M8N+XWAHYX3b7Pp32if+K9Hxb9IiXr0UQv2vBR33ld7LtOnbP3cja 6rvJgW3Y5WkrkzL0Mu3m6GbwxPsXagQtxs74abcKazga+sVdHQzkRLnV6MTcUJfrJZl9 +/hrioQRUW4EgM+IBMRo9YBGemh09LfMIpRp1uniB/T4jR6qMYq6GSbi23fO5BJqbFWO Kc7BzouM6wS3GFBw6rFm9Lu08GoXdlJpG2hVg0wI0Ay0GcDAeYxupPweDcnKuqWBDJDV 3YP3fVEf4MeAsqiSiV+WaKaHK5cYXTYcpxOT1G4w6NZFsYLLde9+TwbUcf3Vnz/B5G7K Y/iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=togXYFWiDHjaH/A2MomM7jHh7BfryoDx4ee9h18JDy+nNJtVUF+7bvyTA1ONuJlmx2 Yf3eF+F8xcz1a66mzVljV6oeWQWW5jwJvCUiL8wkqKP5LSqqJB8dzf9vXkfd9ZKYo7jk PHAKFm8g5zpGc8UyEmBSoIEbhwcJY8nOBnok6C2JBg/dLyNnGozV2AArM9F3hXZJs6jk JACv3fVLWFfky4EWgvUB25zXTC3Z1cUwma+5xqml4oEvJK2fzJ+NRxGof9MRMdVSWnUa rQJUhDTzo7nutzZHw3UcoLOpkenGsG86nW5FHo0WpNgo7cnjfYKANkreLv1u8ZE4aoYn mcng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZjNjiRx8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i12si5200311otk.215.2019.12.20.04.14.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:14:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZjNjiRx8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHBA-0000nE-UU for patch@linaro.org; Fri, 20 Dec 2019 07:14:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36324) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAs-0000eI-41 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAq-0001Hi-Rc for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:55698) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAq-0001D4-DQ for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:28 -0500 Received: by mail-wm1-x342.google.com with SMTP id q9so8723044wmj.5 for ; Fri, 20 Dec 2019 04:14:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=ZjNjiRx8twV7r7+gDAfFetdXMlwhJqPIbx6ucz1bkg2WTBQ65zsfXdZ6bWzGg75osI RveYQ69dK0KRWzVlr3gAANejDTCO64FH6EL9b2yVg0r6cxKTVjJmKgalnVs/ItXs/ntF ZiVEUaxfhtoseX0kfUa/hRkvCcR850ZvKCguWrAhZVzC29VPnHB+5/+aRgH82mguyjlZ l7tTyKH0C6cpSl16+rcUKLr+yPYwZQXlNJ2j2gff//6IOWb+yDcTnM105NcBEpg8gxNW Xrst8kRSTF6jTMtz0VrZrKr2LG83544ls95VrKT5lihLI9ozgPGjgPR/9S0TFyHcgQVc NQ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mqhw4oMb9/NPBlcysMR2z8rn68YPooniQZ6sAVo6tJ0=; b=PeNL8FJUbIDxiZ8cnwsvwjygV8fT6pakWnCNNrAdnVJTqvzCwgmuzKOUkwAf/lfnE2 8DLahxGOU2VQqWGL96YxAvmoSwLM7ujWAiSOYwPvKBkeC4Cb5bNKpWEhAxHxT0bXSZN/ r2oLndpNA460N5TxCZExYPjfe0S/B6ui/HzLU/gk0oT53cUnbvhiWNUX1S6d1cXMcimX JqIBg44Z1jsL05Es4BlqWpzyBvYLQpQDzeL8BVBrZ5iWblUxgj0EjvXfPOU5or8dnDRn TaxWxBSLkaY+QX8IEo6ZfJwDZkoniOShWzM2bvBz6b4H+hJcowMWa8nKD6hyACnnbtVJ kc3g== X-Gm-Message-State: APjAAAUTvKpQS9mMGQuls4NP/dBiU3XasGFq0e+p0lglbkBrs3X/WmFE l78EVlufT1aYZtqX5eK/yspJqQ== X-Received: by 2002:a05:600c:54b:: with SMTP id k11mr15752965wmc.63.1576844067287; Fri, 20 Dec 2019 04:14:27 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o4sm9334239wrx.25.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 585F51FF9D; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 13/21] tests/tcg: add a configure compiler check for ARMv8.1 and SVE Date: Fri, 20 Dec 2019 12:04:30 +0000 Message-Id: <20191220120438.16114-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?utf-8?q?Alex_Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will need this for some tests later. The docker images already support it by default. Signed-off-by: Alex Bennée --- tests/tcg/configure.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.20.1 diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 210e68396f2..e0d1fbb182f 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -216,6 +216,20 @@ for target in $target_list; do echo "CROSS_CC_GUEST_STATIC=y" >> $config_target_mak fi echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak + + # Test for compiler features for optional tests. We only do this + # for cross compilers because ensuring the docker containers based + # compilers is a requirememt for adding a new test that needs a + # compiler feature. + case $target in + aarch64-*) + if do_compiler "$target_compiler" $target_compiler_cflags \ + -march=armv8.1-a+sve -o $TMPE $TMPC; then + echo "CROSS_CC_HAS_SVE=y" >> $config_target_mak + fi + ;; + esac + enabled_cross_compilers="$enabled_cross_compilers $target_compiler" got_cross_cc=yes break From patchwork Fri Dec 20 12:04:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182258 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp454720ilf; Fri, 20 Dec 2019 04:22:32 -0800 (PST) X-Google-Smtp-Source: APXvYqxWC89WOZD9R9yZ0ba/tmMf/XwquKOCmj6Ua8m+vs0L5GagHt8D7b1oSeWwf84PtFnDhm1Z X-Received: by 2002:ac8:3a02:: with SMTP id w2mr1445176qte.351.1576844552756; Fri, 20 Dec 2019 04:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844552; cv=none; d=google.com; s=arc-20160816; b=lXq6OlJhVR8SNpdo8PLOHdKyDzhXE3eXKtsC02IfyniBrjOTRMW40EvL7l2Rmsr0JE MWil829DG9hckT3gdbrNNkc5gHBcXedYxDoUYK+ZEHtKgrXTjwJa0ZrRlNFmwczuaozn UpvSwLbbJcZVi1TfsOgKE21WDPnTq96Jdih+jfI4iUInIZlXLM9NZuVIYl/SSaQ5EMmJ VQygLbuSAyGVQoEINrvVFojWOUlduy/7u5THu8mec6DyNB3fLPNZz3UcfnxCGQxziMz5 pGw526znrWxPO+Zx5BB8ID1biu40ToplNQaMUl+qg3YmJtmG7YkbB2yWPMgCoPL4fI5q 2/nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=i5gBQihY08E0tlQSMp5DZiJeaBVoceRzQCHum+7JMyKWuyBCmwVQrwHxijwCnKLfN6 Xl5FmjYAA1ctnxH3XAhCpUAbkz7XDeB5CkCZn/ykDyspJQjmRZ5S7TCo3FUIfIPVlJX5 rpcfgaXx0DNyjEXzN8jshs5oyfLF0FriaJszRXRMEo02yAYVEAg0u7nrAbAz+UGtGlmY qopyEb8z6Fm7398QO2OZbDjJnOaWMtsQ09/BGbz9m3yS5+0y3io1fIN+uiKxvnTQ9LIw DDz6xsmhONS2cImbLIbKAn12hfV8Dc69O/zZwbQMVhPOkHQdYn81wzdXjwsu3HWEw9cP z/rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=H7fqNRwd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 83si5362514qkj.334.2019.12.20.04.22.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:22:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=H7fqNRwd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHIe-0002qt-5N for patch@linaro.org; Fri, 20 Dec 2019 07:22:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36283) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAr-0000dv-VU for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAq-0001FF-9b for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAp-00019u-Uj for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:28 -0500 Received: by mail-wr1-x443.google.com with SMTP id z7so9163500wrl.13 for ; Fri, 20 Dec 2019 04:14:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=H7fqNRwdjB5hRPbOqjSzn3+92GkPWo2OL6At9HiFJ849JvF6TXaExMH38Jhn65KSh1 qoPED6b3NLZASeBJKKMcPoWXptmNZglhfPOaQxVR6gLA6Ao5So503ISzRoJZxqKm4PVX X1Qgk/bP5I2fSIFfCxTWiKGLvuYlkan7LYKxQDYCVj+hibAwZ6oThn5C9j5xoh9Wjvl0 3Y60fPxB28nL2F0HMdn1xQgKBOy1ofEXAuapr+thnXdzyMidic8Y125WGysvN1pAD57m PGNArncAjLnLlNYOD2qlV7DZcPbfZHvlNNQGfjXfAqHmBS/35mG2COdGwcLe3XzjFhP9 D1qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KRu49EbgGVQ7V2rxhXNHs855imxrN5MTwZSo9giC7oo=; b=J74Qu25/7jnSjsjQK0SLThR53zaEekvqv1Q6NjXmgMt+3sLVjeM/622eWWQ2ZrZgUv QIvK/17m9qoLLnqeSrugxU24Ot1xPGHSdBy06HuHEgg/GRrhxhEdzADprYP7v+tprFGE O2kpBXubVHVjjEAimpd9JZ/2VJXDebmxzH5zanNDwIMhcJDl4RdMh1SYHPa66juhfwld s19iJzypHqgwRuaz7AL7X0k6xA4cOOgTUDfHLcgXKIeDsHTJAEv6npwHEPtXNxI8KQ4b SgAx5AWUnzMxgPyEkVUD8XJwgs4qiJ53jNSsme2g/tE8bAaLyYxFFZBT6hlosIRt2tJH mbbA== X-Gm-Message-State: APjAAAVlDOGmmH/Mh03qwFpmq7Haj7SHgeVzzOnYkPU0LOV1ZZetbYpZ RmI0DoThcwu2/iDLk0weY6Mwsg== X-Received: by 2002:adf:93c5:: with SMTP id 63mr15130458wrp.236.1576844066353; Fri, 20 Dec 2019 04:14:26 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f207sm10901781wme.9.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6CBB11FF9E; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 14/21] target/arm: don't bother with id_aa64pfr0_read for USER_ONLY Date: Fri, 20 Dec 2019 12:04:31 +0000 Message-Id: <20191220120438.16114-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, Richard Henderson , "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Ben?= =?utf-8?q?n=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For system emulation we need to check the state of the GIC before we report the value. However this isn't relevant to exporting of the value to linux-user and indeed breaks the exported value as set by modify_arm_cp_regs. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - extend the ifdef and make type CONST with no accessfn --- target/arm/helper.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.20.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index 857581feba4..23de21f8820 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5912,6 +5912,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const ARMCPRegInfo *ri) return pfr1; } +#ifndef CONFIG_USER_ONLY static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) { ARMCPU *cpu = env_archcpu(env); @@ -5922,6 +5923,7 @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) } return pfr0; } +#endif /* Shared logic between LORID and the rest of the LOR* registers. * Secure state has already been delt with. @@ -6414,16 +6416,24 @@ void register_cp_regs_for_features(ARMCPU *cpu) * define new registers here. */ ARMCPRegInfo v8_idregs[] = { - /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't - * know the right value for the GIC field until after we - * define these regs. + /* + * ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST in system + * emulation because we don't know the right value for the + * GIC field until after we define these regs. */ { .name = "ID_AA64PFR0_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 0, - .access = PL1_R, .type = ARM_CP_NO_RAW, + .access = PL1_R, +#ifdef CONFIG_USER_ONLY + .type = ARM_CP_CONST, + .resetvalue = cpu->isar.id_aa64pfr0 +#else + .type = ARM_CP_NO_RAW, .accessfn = access_aa64_tid3, .readfn = id_aa64pfr0_read, - .writefn = arm_cp_write_ignore }, + .writefn = arm_cp_write_ignore +#endif + }, { .name = "ID_AA64PFR1_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 1, .access = PL1_R, .type = ARM_CP_CONST, From patchwork Fri Dec 20 12:04:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182257 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp454276ilf; Fri, 20 Dec 2019 04:22:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxcsJJg1VWKaKMs2mYnp4aMYH/2aG6bgJfRvyTMOGtd2BoWha7IbL7wUBlQRrYYoF2uc9PB X-Received: by 2002:a37:96c2:: with SMTP id y185mr13844131qkd.202.1576844529139; Fri, 20 Dec 2019 04:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844529; cv=none; d=google.com; s=arc-20160816; b=pDUF3g1M+kvYhx6qmBKUcK4Fmo/mplDdGJJbeRp3RVpNv3JHPQZNPSq6pt1UaVDDi7 7ozJdJC+n/YH7bvP4Pix6+hI2aAfypvDLDvzzSammG90IOd+RJ17POcxqWEUXc+hX+Fq WLZAkdL3km6KvA6gwM3BzheHtiHmNwO2bhblcq4mZJdekG5NP85diGZ4yOdbnzrv+/lo a8dtcaY1ihoACMD2woNFEgl0SbvpffX00TGaKTrLKieaFG3z0POsW8rCo/rGg7ORFwdo ymBjORcq04kE8JMLLl74MaVRx17t3mxAl90/hBbDWhDYopLuAWKoSYnKPljykJYA8PH3 IYZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=CgdL9GGDebgp93cc29KZCx+g9k1/lZVgKG4GYo6yJRLDRIPJEJF7a6E9SVBjmkxvWX B75t7UM67mvWTuVxAbur3yUf0BETkuSPpZ8iCZ+9znwMoqDmUJfAyxK0dP6edTqnABo3 tFxGFiaV+PoeL4FNLzWKwWZYfSYTrE4XkDKqpttN2QbB/agh4jyunYBtq8PpHtglhBmV qM4kkEtk16HgLRJK7h4cnaUMgogGjj0nkK739gZ6TAjuG0Cp3Rc9avWkmwp0NpICeyEa ppJ+vVjsW/H+cce3Ggy48ZwB/Y9mRQ30eXhFesbEsfsNhjIz7hWMI+3YUFq3CqH3dQQC PvUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xp2dTBBx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f8si5323423qkg.353.2019.12.20.04.22.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:22:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xp2dTBBx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHIG-0002QT-HZ for patch@linaro.org; Fri, 20 Dec 2019 07:22:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1y-000588-Q8 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1u-000061-Jv for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:16 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:40708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1s-0008Uc-HB for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:12 -0500 Received: by mail-wr1-x441.google.com with SMTP id c14so9163218wrn.7 for ; Fri, 20 Dec 2019 04:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=xp2dTBBxeYLwe+ePHeCjDEsBDmrLqff8Ct7NLrRv580181LOcouvQFzBCjPWpop+Al zix0jHpEbkh3zsxkGOdeldbrtHA1sjbSiCDcUG1N86lUm1k+gRgh8rXg2WwpgP48sNZB B4aSpnM7jzj0zoNHwAkWK32bJBwsVVk5ngpiSIMtZaZLGY++jRIYqsTXXmSwXsyQZSqX x4aP4psHYfCsSZW3V4+3HBkT3Sgxbff2/27GoOCA/dMUc+OOX8Oxlh8ddTvPGMEY7VHw 0LZCNvKhvLgvom3CARLrzILt3F2OL00jm7SvRj9zlyRNCRuLYfGfQQ07Z6EKwpnEBkba FnnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w/xx1ZZFQsqOfvn/N8QKFZGLl1ALeRRvJF9s6yRLgdQ=; b=f3wcqO/6asi84S5FJbS2zbeSGW2Lj047aziyD1NB1gy5yVMjtDQhVrtG8FE8DmitFy hhYWhG4D+D8oG7GgUSQ2RpCtAHQI7xWM+dQULpcVWDH3salVus66zSuiZGlx7779UlM9 PtRC8wKxOf9h94/d8Fz62GUMDM2uuMw6v+ovRg5BrRhUEAnzIikmGY+wGJ4LcH0Y0RgR 8CCN0yVTckpV+sc33p7aEJ6a0VNTyxL8izhOdlkVVr3LOoddqOAJcLQyzALWqYJU+Ncy EpMMB/dExzLbiyAHePlbtx0UH5QeM/vWBZAV/HRNQD+I84zkmnNMunQkKrmtJb1o0akO +oqw== X-Gm-Message-State: APjAAAXHfou0wMbNOAnBntx/bqbzgxRToee7G5uzEKRMjIxR+RcNOrE2 vbrwaUkJR0lBcjvHhYlpUU+4sQ== X-Received: by 2002:a05:6000:11c5:: with SMTP id i5mr14711263wrx.102.1576843511336; Fri, 20 Dec 2019 04:05:11 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s10sm9492391wrw.12.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 83A771FF9F; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 15/21] tests/tcg/aarch64: userspace system register test Date: Fri, 20 Dec 2019 12:04:32 +0000 Message-Id: <20191220120438.16114-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This tests a bunch of registers that the kernel allows userspace to read including the CPUID registers. We need a SVE aware compiler as we are testing the id_aa64zfr0_el1 register in the set. Signed-off-by: Alex Bennée Message-Id: <20190205190224.2198-7-alex.bennee@linaro.org> --- vgdbstub - don't build unless using docker or CROSS_CC_HAS_SVE --- tests/tcg/aarch64/sysregs.c | 172 ++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 6 ++ 2 files changed, 178 insertions(+) create mode 100644 tests/tcg/aarch64/sysregs.c -- 2.20.1 diff --git a/tests/tcg/aarch64/sysregs.c b/tests/tcg/aarch64/sysregs.c new file mode 100644 index 00000000000..40cf8d2877e --- /dev/null +++ b/tests/tcg/aarch64/sysregs.c @@ -0,0 +1,172 @@ +/* + * Check emulated system register access for linux-user mode. + * + * See: https://www.kernel.org/doc/Documentation/arm64/cpu-feature-registers.txt + * + * Copyright (c) 2019 Linaro + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_CPUID +#define HWCAP_CPUID (1 << 11) +#endif + +int failed_bit_count; + +/* Read and print system register `id' value */ +#define get_cpu_reg(id) ({ \ + unsigned long __val = 0xdeadbeef; \ + asm("mrs %0, "#id : "=r" (__val)); \ + printf("%-20s: 0x%016lx\n", #id, __val); \ + __val; \ + }) + +/* As above but also check no bits outside of `mask' are set*/ +#define get_cpu_reg_check_mask(id, mask) ({ \ + unsigned long __cval = get_cpu_reg(id); \ + unsigned long __extra = __cval & ~mask; \ + if (__extra) { \ + printf("%-20s: 0x%016lx\n", " !!extra bits!!", __extra); \ + failed_bit_count++; \ + } \ +}) + +/* As above but check RAZ */ +#define get_cpu_reg_check_zero(id) ({ \ + unsigned long __val = 0xdeadbeef; \ + asm("mrs %0, "#id : "=r" (__val)); \ + if (__val) { \ + printf("%-20s: 0x%016lx (not RAZ!)\n", #id, __val); \ + failed_bit_count++; \ + } \ +}) + +/* Chunk up mask into 63:48, 47:32, 31:16, 15:0 to ease counting */ +#define _m(a, b, c, d) (0x ## a ## b ## c ## d ##ULL) + +bool should_fail; +int should_fail_count; +int should_not_fail_count; +uintptr_t failed_pc[10]; + +void sigill_handler(int signo, siginfo_t *si, void *data) +{ + ucontext_t *uc = (ucontext_t *)data; + + if (should_fail) { + should_fail_count++; + } else { + uintptr_t pc = (uintptr_t) uc->uc_mcontext.pc; + failed_pc[should_not_fail_count++] = pc; + } + uc->uc_mcontext.pc += 4; +} + +int main(void) +{ + struct sigaction sa; + + /* Hook in a SIGILL handler */ + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = &sigill_handler; + sigemptyset(&sa.sa_mask); + + if (sigaction(SIGILL, &sa, 0) != 0) { + perror("sigaction"); + return 1; + } + + /* Counter values have been exposed since Linux 4.12 */ + printf("Checking Counter registers\n"); + + get_cpu_reg(ctr_el0); + get_cpu_reg(cntvct_el0); + get_cpu_reg(cntfrq_el0); + + /* HWCAP_CPUID indicates we can read feature registers, since Linux 4.11 */ + if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) { + printf("CPUID registers unavailable\n"); + return 1; + } else { + printf("Checking CPUID registers\n"); + } + + /* + * Some registers only expose some bits to user-space. Anything + * that is IMPDEF is exported as 0 to user-space. The _mask checks + * assert no extra bits are set. + * + * This check is *not* comprehensive as some fields are set to + * minimum valid fields - for the purposes of this check allowed + * to have non-zero values. + */ + get_cpu_reg_check_mask(id_aa64isar0_el1, _m(00ff,ffff,f0ff,fff0)); + get_cpu_reg_check_mask(id_aa64isar1_el1, _m(0000,00f0,ffff,ffff)); + /* TGran4 & TGran64 as pegged to -1 */ + get_cpu_reg_check_mask(id_aa64mmfr0_el1, _m(0000,0000,ff00,0000)); + get_cpu_reg_check_zero(id_aa64mmfr1_el1); + /* EL1/EL0 reported as AA64 only */ + get_cpu_reg_check_mask(id_aa64pfr0_el1, _m(000f,000f,00ff,0011)); + get_cpu_reg_check_mask(id_aa64pfr1_el1, _m(0000,0000,0000,00f0)); + /* all hidden, DebugVer fixed to 0x6 (ARMv8 debug architecture) */ + get_cpu_reg_check_mask(id_aa64dfr0_el1, _m(0000,0000,0000,0006)); + get_cpu_reg_check_zero(id_aa64dfr1_el1); + get_cpu_reg_check_zero(id_aa64zfr0_el1); + + get_cpu_reg_check_zero(id_aa64afr0_el1); + get_cpu_reg_check_zero(id_aa64afr1_el1); + + get_cpu_reg_check_mask(midr_el1, _m(0000,0000,ffff,ffff)); + /* mpidr sets bit 31, everything else hidden */ + get_cpu_reg_check_mask(mpidr_el1, _m(0000,0000,8000,0000)); + /* REVIDR is all IMPDEF so should be all zeros to user-space */ + get_cpu_reg_check_zero(revidr_el1); + + /* + * There are a block of more registers that are RAZ in the rest of + * the Op0=3, Op1=0, CRn=0, CRm=0,4,5,6,7 space. However for + * brevity we don't check stuff that is currently un-allocated + * here. Feel free to add them ;-) + */ + + printf("Remaining registers should fail\n"); + should_fail = true; + + /* Unexposed register access causes SIGILL */ + get_cpu_reg(id_mmfr0_el1); + get_cpu_reg(id_mmfr1_el1); + get_cpu_reg(id_mmfr2_el1); + get_cpu_reg(id_mmfr3_el1); + + get_cpu_reg(mvfr0_el1); + get_cpu_reg(mvfr1_el1); + + if (should_not_fail_count > 0) { + int i; + for (i = 0; i < should_not_fail_count; i++) { + uintptr_t pc = failed_pc[i]; + uint32_t insn = *(uint32_t *) pc; + printf("insn %#x @ %#lx unexpected FAIL\n", insn, pc); + } + return 1; + } + + if (failed_bit_count > 0) { + printf("Extra information leaked to user-space!\n"); + return 1; + } + + return should_fail_count == 6 ? 0 : 1; +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 96d2321045a..3f8783ada5c 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -32,4 +32,10 @@ run-plugin-semihosting-with-%: $(call strip-plugin,$<) 2> $<.err, \ "$< on $(TARGET_NAME) with $*") +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) +# System Registers Tests +AARCH64_TESTS += sysregs +sysregs: CFLAGS+=-march=armv8.1-a+sve +endif + TESTS += $(AARCH64_TESTS) From patchwork Fri Dec 20 12:04:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182263 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp462309ilf; Fri, 20 Dec 2019 04:29:20 -0800 (PST) X-Google-Smtp-Source: APXvYqydo/StV1jvKkNxbKOxxNuvXOo+Hxvg/OIS+gNZIz1R/sxwXNs3ssx5tBavHbtubMrBnKkT X-Received: by 2002:a05:6830:1704:: with SMTP id 4mr14389331otk.294.1576844960668; Fri, 20 Dec 2019 04:29:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844960; cv=none; d=google.com; s=arc-20160816; b=GNUpgYgd0nMcPdQW0J1F/Cb1jWnl/Oq12uOlnNAyBFGShYGg0q94tZQg/IK7hnGrlI 1tdO/OPTh3hkzq9d+ZRXYf6yEp1d8wA2pvBg/5rQA9JqpXZbFFVSX+WETbpasEcgSimJ RAiz8ogGWjxxH5hl/DTKBvonIYrFwvK0gYmoyBV4LM9MLkhRowUnr9dAJXIX5Ke5l7uv /3n2vwYvV+rrQT8kMTqrQK4NAQkuY7H4BMhVRQlz5MYfNHro3Mo+NuIqb4bIrXfwN+8J HMrmuj2FJkdTKBLPxzfhOVEzgUWXef4LPe4OV4v3Hy6UaT052/E7oHLhiyUp/MuAij3V fU5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=rF/YDONtT5fnHzFAoHK8ooJgzDdxBNGeZ5RF+C+qG2Gi+x0dOslhPB982e93yRJULH xvPfxYYWkuTucH0pBuHRnjBARzPoNPyu/7tnegC6GofRXBz+ji5dUOzcQj634vLspxVW 6jR8YBGnI3AdjANr8gsXOOjPPjWOEhquCUBRUfKGPIvyduIwjQ/qJS9Lt7Do6o/Sk99s iETRRlPeqb8UebbJMxIq3XTYAijkdMhi671eqciwGTbQ3989MYLOY3yOnt4/p5FAu6/L UGCiX/eK5Kbbwc/YUD/2W+HcMqdwmu6/x9NaPp8HRPxjEpIyaEPlaH03r9QvvP7MaENB MD4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PnGgh0R+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t12si4866389otm.224.2019.12.20.04.29.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:29:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PnGgh0R+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHPE-000301-1n for patch@linaro.org; Fri, 20 Dec 2019 07:29:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54392) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1v-00055K-Ax for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1r-0008UH-SW for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:14 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:34209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1q-0008Qy-1x for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:10 -0500 Received: by mail-wr1-x434.google.com with SMTP id t2so9206000wrr.1 for ; Fri, 20 Dec 2019 04:05:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=PnGgh0R+FuLJoLXgbUOqWoo88UXexq87sfNDL34DCTUZmg70y4egxTu3eHegGz20LV DdBYyM0xfslU5mbvOGCwgn7/Us1mj7ZodKEknlgvGeY9EH5/muHQ9d584zBBYpLozkT+ 03dTcXtXQvytcRaFRgad8ywVZzSoWz4MHdLbYRlvhJ9qJO2ilVc/divVDsG9qWUbc1nU xQdhTadQOHjXsDcdqm1R8YBQwPbGYTBMJoT1Boti1EJXjMDzll5iu0tRys5zm3SVaQhA yx2/zsP4BZzohxRkz/jNon4qKSYrv/nh+zhHQfvnZ9gcEiwaBpDRfC9iQTV5zvqobcDR PwPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fd9ZwTx/nGTAxWisTrByxsrJjTVOwFrJUX5QQ3jkZWE=; b=CSkdT2/0HkxwhJORyHOf7XxuqtCWf4KtaiKufSVPEqxE2uOd9XNLFAk24PoV/pgoSJ M3FSaWi/ku+5nva7r+1lFT/IBT24o3GA9DP2sbvF+tAAK61r4npFND8DNGVGaE5CSShS mYelVdsXmYC12dEaP78hLZcmsI5/qQdv8FMlDhXonJuCD6PEVByCT3laUpHoJ1bkjVVm A+w/mqIUF91OLUl2GBJp9QKeMOWJcBB769xsBcIyjRstgduVQShKTC4JhaXGg8aDeIuy v6R41apMBUwFmif0V6UT5UUhdtTeTiY1kmhk+rXzzou0W/1WliESB70R+fDzuTu7TZiy 4ffw== X-Gm-Message-State: APjAAAWPQjByVwaMlbgo5F0PthjUsebIGXmHG9D+UPi30s8bg0nnqaft haeuaDIg0G0eVkqrYMhVUmFBnQ== X-Received: by 2002:a5d:548e:: with SMTP id h14mr15983487wrv.380.1576843508480; Fri, 20 Dec 2019 04:05:08 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id k19sm9331183wmi.42.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9850E1FFA3; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 16/21] tests/guest-debug: add a simple test runner Date: Fri, 20 Dec 2019 12:04:33 +0000 Message-Id: <20191220120438.16114-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?utf-8?q?Alex_Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The test runners job is to start QEMU with guest debug enabled and then spawn a gdb process running a test script that exercises the functionality it wants to test. Signed-off-by: Alex Bennée --- tests/guest-debug/run-test.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 tests/guest-debug/run-test.py -- 2.20.1 diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py new file mode 100755 index 00000000000..8c49ee2f225 --- /dev/null +++ b/tests/guest-debug/run-test.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# Run a gdbstub test case +# +# Copyright (c) 2019 Linaro +# +# Author: Alex Bennée +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import argparse +import subprocess +import shutil +import shlex + +def get_args(): + parser = argparse.ArgumentParser(description="A gdbstub test runner") + parser.add_argument("--qemu", help="Qemu binary for test", + required=True) + parser.add_argument("--qargs", help="Qemu arguments for test") + parser.add_argument("--binary", help="Binary to debug", + required=True) + parser.add_argument("--test", help="GDB test script", + required=True) + parser.add_argument("--gdb", help="The gdb binary to use", default=None) + + return parser.parse_args() + +if __name__ == '__main__': + args = get_args() + + # Search for a gdb we can use + if not args.gdb: + args.gdb = shutil.which("gdb-multiarch") + if not args.gdb: + args.gdb = shutil.which("gdb") + if not args.gdb: + print("We need gdb to run the test") + exit(-1) + + # Launch QEMU with binary + if "system" in args.qemu: + cmd = "%s %s %s -s -S" % (args.qemu, args.qargs, args.binary) + else: + cmd = "%s %s -g 1234 %s" % (args.qemu, args.qargs, args.binary) + + inferior = subprocess.Popen(shlex.split(cmd)) + + # Now launch gdb with our test and collect the result + gdb_cmd = "%s %s -ex 'target remote localhost:1234' -x %s" % (args.gdb, args.binary, args.test) + + result = subprocess.call(gdb_cmd, shell=True); + + exit(result) From patchwork Fri Dec 20 12:04:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182252 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp447705ilf; Fri, 20 Dec 2019 04:16:31 -0800 (PST) X-Google-Smtp-Source: APXvYqx6hfmtgQH7Xdrl3PZdRFB6lcpSsFK94wa2k4ErzrFT7KhGnoIT9S7iHOhPynMtiDv4t/+/ X-Received: by 2002:a9d:ee2:: with SMTP id 89mr6242937otj.270.1576844190965; Fri, 20 Dec 2019 04:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844190; cv=none; d=google.com; s=arc-20160816; b=ltCuOwjiENsKkNcn9Mceg7Spmnrt7nD76O5japNBxSM/k9Hb9LR8k/LDYC1KksNXUi meWSl6VZLdyi50WVUaYwyxkcZiwN9v7kQ9FE3Zkugg37O0PdJY6ZPXt9SvtmXryTN2Np 5B8S7yYSkpS62i8cR9aS6LzTwm3hL3VkmsZl7E94hefeCwdwhMMlVJojLErtYuGHbS3y wHjtDy6en7ow+2G+Ybrnn7dDSpi2dSfWtw9Tqvk6ijCYgW8nXJv82bMaBSXVHypOfAnp uf7m4QEH4xgSRHb+5li5GO0qhoFuURajWdGmkqB4Dg3dt6vp9173nagHQuWKkejYhPpi Oq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=zSc89nwbeab9AMBz8lgIA/ThPCdtLywWy6uucZhGaKRAAWHBDSXbzYf3EyoKbP0AUf ZihGItv85G7uNSH84SaCXCKUIk5mCuThg3/pPd67vNtoFdT8FORnRPR8jKPyDWMG4Idj kJQu4OEix7ORZIZDD+tnvKDJnENvmLC57IjOmv42nrD+zPRR5iIFkC3Iq0rTLL5f0SX8 IG7DgtoqxmPfTp5XYQTEWFdO+B1tG9MPCkB/PYQd7dms2v83KB2npnvCnPLpv9CkmeLI 8IyUB+KleirHhWlpU8KXJDZdXcHBseoSTiIGkLaGa00ZjRW9/kXRvA9dEOEAmcgIfl3N +4vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A4H6UdB2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j24si2340037otn.110.2019.12.20.04.16.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:16:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A4H6UdB2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHCn-00039e-RZ for patch@linaro.org; Fri, 20 Dec 2019 07:16:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH1s-00051x-JR for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1o-0008Px-Iw for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:11 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:41086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1o-0008Mv-0o for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:08 -0500 Received: by mail-wr1-x431.google.com with SMTP id c9so9181934wrw.8 for ; Fri, 20 Dec 2019 04:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=A4H6UdB2S/92fnWU47nEN9m9Bh7bPxF+RJJFgzvQ4fOYUptOB8ZpYYtR+DmKDQm47l iCMacMxkIhA3qGQiS0J154sHigRiXYwQSI3IgjloX8DCq0ZxnL6Dquh6j2t+t7/vSlkC siLoqhVr1KUINloRsgyCwzzhkVq9ldeHXO/J86PFms6wsBcQ9Zj38QUTCkGgR3u64S4i vN7c+AG6ET+xD6ChpMJB2xhJQxHEs8A7xEfin/iNCt1ulKetW1KwoWAJWhwht9z++vAh wxReIq7I7KnF24EvL/S8/46wHa+pff5kumdlN1Y4b1yG8pTl4H8lEkZMfDqjzsz4bkAR hcZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0hbLzhNEhCkMRqzYtd3EEZ7EkJxE7ghYQ9NzTVxAhLY=; b=GxC8bHC++ShKF+KerpLBQcRQvmNkkrS7AIRaorNpqXB+e8kxE8DQZk7FWerE/k/LqP 3jGTgxefdUi/LjAMlmF4JzdDeGgLvQPlsyMP+wwGh/lhtVqXrfsXjNamibpe5dMquViq d8t9o/D6v94kCAkOqghqzqT2C1Vo9G2qGkbcvElMVu9LYaaq90jyNOcbuYXXupoM3b16 WV/HUAIKtJwV3Bdf4YVCxSPyuIpoxsoEFYJQTH4NvTk1gdzVFS8fxE6Slm9h/bQIevLY dDiwme/Njknbu/HQsbv5Vx9EeHV7qVRbTY8QpL2SaCt7ZpOt8CQY4B+pBj+RIee2K7cR og5g== X-Gm-Message-State: APjAAAWug4kwx70D1ZD5ltvEuH0a7JDyKJ8DmYUC8gcX57cx8s8n6LwG qZCoAd1s3lCto2gbZJRks1y2Cg== X-Received: by 2002:a5d:4651:: with SMTP id j17mr15576168wrs.237.1576843505701; Fri, 20 Dec 2019 04:05:05 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s128sm9713941wme.39.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AF5D61FFA5; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 17/21] tests/tcg/aarch64: add a gdbstub testcase for SVE registers Date: Fri, 20 Dec 2019 12:04:34 +0000 Message-Id: <20191220120438.16114-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We don't plumb this in yet as there are complications involved with binutils and cross-architectiure debugging but it is one step closer. Example: ./tests/guest-debug/run-test.py \ --qemu ./aarch64-linux-user/qemu-aarch64 \ --qargs "-cpu max" \ --bin ./tests/tcg/aarch64-linux-user/hello \ --test ~/lsrc/qemu.git/tests/tcg/aarch64/gdbstub/test-sve.py \ --gdb /home/alex/src/tools/binutils-gdb.git/install/bin/gdb Signed-off-by: Alex Bennée --- tests/.gitignore | 1 + tests/tcg/aarch64/gdbstub/test-sve.py | 75 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve.py -- 2.20.1 diff --git a/tests/.gitignore b/tests/.gitignore index f9c01708812..8cc428b58bb 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -10,6 +10,7 @@ qht-bench rcutorture test-* !test-*.c +!test-*.py !docker/test-* test-qapi-commands.[ch] include/test-qapi-commands-sub-module.[ch] diff --git a/tests/tcg/aarch64/gdbstub/test-sve.py b/tests/tcg/aarch64/gdbstub/test-sve.py new file mode 100644 index 00000000000..11bc96fc06d --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve.py @@ -0,0 +1,75 @@ +from __future__ import print_function +# +# Test the SVE registers are visable and changeable via gdbstub +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb + +MAGIC = 0xDEADBEEF + +failcount = 0 + +def report(cond, msg): + "Report success/fail of test" + if cond: + print ("PASS: %s" % (msg)) + else: + print ("FAIL: %s" % (msg)) + global failcount + failcount += 1 + +def run_test(): + "Run through the tests one by one" + + gdb.execute("info registers") + report(True, "info registers") + + gdb.execute("info registers vector") + report(True, "info registers vector") + + # Now all the zregs + frame = gdb.selected_frame() + for i in range(0, 32): + rname = "z%d" % (i) + zreg = frame.read_register(rname) + report(True, "Reading %s" % rname) + for j in range(0, 4): + cmd = "set $%s.q.u[%d] = 0x%x" % (rname, j, MAGIC) + gdb.execute(cmd) + report(True, "%s" % cmd) + for j in range(0, 4): + reg = "$%s.q.u[%d]" % (rname, j) + v = gdb.parse_and_eval(reg) + report(str(v.type) == "uint128_t", "size of %s" % (reg)) + for j in range(0, 8): + cmd = "set $%s.d.u[%d] = 0x%x" % (rname, j, MAGIC) + gdb.execute(cmd) + report(True, "%s" % cmd) + for j in range(0, 8): + reg = "$%s.d.u[%d]" % (rname, j) + v = gdb.parse_and_eval(reg) + report(str(v.type) == "uint64_t", "size of %s" % (reg)) + report(int(v) == MAGIC, "%s is 0x%x" % (reg, MAGIC)) + +# +# This runs as the script it sourced (via -x, via run-test.py) +# + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except: + print ("GDB Exception: %s" % (sys.exc_info()[0])) + failcount += 1 + +print("All tests complete: %d failures" % failcount) + +# Finally kill the inferior and exit gdb with a count of failures +gdb.execute("kill") +exit(failcount) From patchwork Fri Dec 20 12:04:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182264 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp462686ilf; Fri, 20 Dec 2019 04:29:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwM6b28cTFly+omJDn+cTMcw55WUYqH5zABaG2xCAli7s9/lMgChTQnD/115gr7p1aYwzRg X-Received: by 2002:a9d:74c8:: with SMTP id a8mr13978604otl.57.1576844981597; Fri, 20 Dec 2019 04:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844981; cv=none; d=google.com; s=arc-20160816; b=kY2pifyz/2DwdQiGBtuihOJ0jzfVYIsalFz+G2Z0MYi1gD1tmh4ekQHlhgFRZBXuxh GHYmtkO8gX1qjxPlbwTOk8pahAVExq/hcnRcYdA3j6r7xQs/UxWijfBvlPKrBHBmv9wn Z4d0b37uGy2Y0w2VZl5JXkRhEx4zUwRJmbr0FlbYNk/MbOTOLMZQ7Ic399ElvGIniAZx sblP06C/Nw06n4l1TBGlT1mhH2ggM2s4JFpqUaAwjh37IkiNlIUrKiNP6mz3YteuB/k8 if6sSKphXSxp6EqDuAVFiNyHEED0uh8ABDC8HMpAdve9OJFnmnNCur0Zvcl47sK+Cye1 Q+bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=D1xlxj4DFFvh57kqStqqq8x+WNm+Mvl8M4eAPbfBulvvNju7b/qj8PFFkXa0GGKLws ZhqeP7R4JPRNMjBg9xFST+yHEDDWX8Q8ss1d5ZNpEU6fvsIE4oFSu64gqbgdpCorfffc MKvabt9E0MdEKWNfFm+tIqc3M3u31wbmpsREIflOkZPV6YEOQ9hWIBCIifrndGz19xAx 1/85OFSW1+40ZJgq5Nh1BhxVnmEsFRboQNv3gDnRCHp0hOVKQ+M4zmsKUIFbOPnrtJJH A5yjzHEed48jEqpQnET1b8ZumkUgrsq710Tzpv0OVJlJzF/zEqQTfbgr265M0TGYBscN gXUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yI7t60Cn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s26si4997432otr.38.2019.12.20.04.29.41 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:29:41 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yI7t60Cn; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHPY-00039Y-Ua for patch@linaro.org; Fri, 20 Dec 2019 07:29:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiH20-0005Ay-Ow for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiH1y-00008E-Mj for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:20 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:40902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiH1u-00005D-HB for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:05:15 -0500 Received: by mail-wm1-x342.google.com with SMTP id t14so8962161wmi.5 for ; Fri, 20 Dec 2019 04:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=yI7t60CnVL6775T9HfpwZA3JM2Ww2nGwXk9wQf/Ypb7fNkwzX+m52h10d9jRRnXBya XtYqIFdAykWjmTzycIW/c/RiDs5I4DmrZ+PyF52wbASybJ9vnOMHRQjQLs0RZj2OgVcN qt0l/i6uUw+OrzikFCRkpFwXCvpdCPUvZKp8yAVYHhqSDU/Eqvtq4XLShjbUA0UspFz8 tCtsTKwC+StyPh9tBAWbPD7rTJF+r/vNl1aVVPk0cmyxytcHXPszDPLxEPsndED/mBgZ /ppdIn0RI2sipaptiB+REpow0ZZLIoHo8mhSLJyH3J34FFC2Zl/qt4Nfpp3dCgzI/eZC WsJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YCeE2L0TGRZ8+dNyp7Q4Gn+JUeo73/cxEQroPrtcLoY=; b=mSJpVtJ08RxJauewysP51eNxXYbiCVvuE4lDzfQHt/z1YYtvhm0bVBqif7oUV+n6L9 BreXSXSncnSTjY8JqKpBMwTGw5yIWz9+iBon2vQPiWQs0P72VjWoPt5nj3/NLRozBdtl wNOhog/ya2KtECAzm0weJA2JCL88A5jkdaynEH/c7u8SSxxt+5xyuUEEF7HD/QkPFgXe oSnViPc7gZM+uTLno3Eam0MlB9NfBkb1lZaNUSjWVYvOhM4JSEu/iF8HpOByJ0pR2eUY qbDAFtlb54gkcV/5f9yrRFnBT/j3Rv00xF07oNz5xoc2hDj3Qt0oRdYELyfiRMC4eAH1 ZiQA== X-Gm-Message-State: APjAAAUxCVUX8oBwCcpwXwMu60hclHIszkV1MNhgWsWD59eBbiRHayV5 OdzwAekTs9fQuS16J+9tCXV1sg== X-Received: by 2002:a7b:c183:: with SMTP id y3mr16211076wmi.0.1576843512480; Fri, 20 Dec 2019 04:05:12 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w19sm9049230wmc.22.2019.12.20.04.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:04:53 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C87411FFA6; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 18/21] tests/tcg/aarch64: add SVE iotcl test Date: Fri, 20 Dec 2019 12:04:35 +0000 Message-Id: <20191220120438.16114-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a fairly bare-bones test of setting the various vector sizes for SVE which will only fail if the PR_SVE_SET_VL can't reduce the user-space vector length by powers of 2. However we will also be able to use it in a future test which exercises the GDB stub. Signed-off-by: Alex Bennée --- v3 - use index to fill zreg - CROSS_CC_HAS_SVE --- tests/tcg/aarch64/sve-ioctls.c | 77 +++++++++++++++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 4 ++ 2 files changed, 81 insertions(+) create mode 100644 tests/tcg/aarch64/sve-ioctls.c -- 2.20.1 diff --git a/tests/tcg/aarch64/sve-ioctls.c b/tests/tcg/aarch64/sve-ioctls.c new file mode 100644 index 00000000000..d7bb64d53f9 --- /dev/null +++ b/tests/tcg/aarch64/sve-ioctls.c @@ -0,0 +1,77 @@ +/* + * SVE ioctls tests + * + * Test the SVE width setting ioctls work and provide a base for + * testing the gdbstub. + * + * Copyright (c) 2019 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_CPUID +#define HWCAP_CPUID (1 << 11) +#endif + +#define SVE_MAX_QUADS (2048 / 128) +#define BYTES_PER_QUAD (128 / 8) + +#define get_cpu_reg(id) ({ \ + unsigned long __val; \ + asm("mrs %0, "#id : "=r" (__val)); \ + __val; \ + }) + +static int do_sve_ioctl_test(void) +{ + int i, res, init_vq; + + res = prctl(PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) { + printf("FAILED to PR_SVE_GET_VL (%d)", res); + return -1; + } + init_vq = res & PR_SVE_VL_LEN_MASK; + + for (i = init_vq; i > 15; i /= 2) { + printf("Checking PR_SVE_SET_VL=%d\n", i); + res = prctl(PR_SVE_SET_VL, i, 0, 0, 0, 0); + if (res < 0) { + printf("FAILED to PR_SVE_SET_VL (%d)", res); + return -1; + } + asm("index z0.b, #0, #1\n" + ".global __sve_ld_done\n" + "__sve_ld_done:\n" + "mov z0.b, #0\n" + : /* no outputs kept */ + : /* no inputs */ + : "memory", "z0"); + } + printf("PASS\n"); + return 0; +} + +int main(int argc, char **argv) +{ + unsigned int sve_feature = (get_cpu_reg(ID_AA64PFR0_EL1) >> 32) & 0xf; + /* Exit early if we don't support SVE at all */ + if (sve_feature == 0x1) { + /* we also need to probe for the ioctl support */ + if (getauxval(AT_HWCAP) & HWCAP_SVE) { + return do_sve_ioctl_test(); + } else { + printf("SKIP: no HWCAP_SVE on this system\n"); + return 0; + } + } else { + printf("SKIP: no SVE on this system\n"); + return 0; + } +} diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target index 3f8783ada5c..209c79a1ddb 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -36,6 +36,10 @@ ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_SVE),) # System Registers Tests AARCH64_TESTS += sysregs sysregs: CFLAGS+=-march=armv8.1-a+sve + +# SVE ioctl test +AARCH64_TESTS += sve-ioctls +sve-ioctls: CFLAGS+=-march=armv8.1-a+sve endif TESTS += $(AARCH64_TESTS) From patchwork Fri Dec 20 12:04:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182265 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp467660ilf; Fri, 20 Dec 2019 04:33:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyP56saZvdBK0akUFqxxibDKprXXB+TjoUdoCt8HffcxrWXVhv/LN29HIMtfp8Q/5zg5f1B X-Received: by 2002:ac8:835:: with SMTP id u50mr11535103qth.15.1576845238042; Fri, 20 Dec 2019 04:33:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576845238; cv=none; d=google.com; s=arc-20160816; b=g5Ml22r7yPUwsVtd1ZpyEn0gIPDjS2By/Bsx+E1pKMjo0ouoKS2lSCuX/Bn7pYM/8/ YHuo4TwEkZlQUgAtNiRAvs84vzrA8GL6YagKojXxYrwMNefTIpiDkpsZnlbbz+CJi2tv IbmfAjeIQ6OGydTS7uCczAC5pwHU1EdkX8r4u4OYlAWEgXJOOsHQsUfUNup45jwICxMT YhEjdI6GqIpAtcglkC1+XoOmocgf7z4Yp3bwVo8Ce7NQpE1Kz3WKo9t2juczPAgCw4Mq IhSf4uwQrYl11ku8UAigUW+5ZkQKeoMegQo2upied6H0TUIItxqswcr1Kxly2bJkgCzq puxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=jycFXxXmPnZrm/rWKVVlXx4bFTcPleZEAXqBO3I/d08BwQBWSDSN86eL2UVRLyHXnk YmG9W1r7Oes5RYsThgDAGKYi34R3M4fwiAzGNAHAoR22BhAh1x3YX3BPTaV0E5M8gBgg Ksl9EnyJP1oUgIGgsb80Pmqhd/PVTPNvBtKYKkn75+/4v9LM7XaKnAUmRYTsemMLbtSe DyyEXDxmbwVtm8baftNkVwZ8I5y9HV4kkdC9dVYenkMBO7nykI64tW2abkqMqLFRcZGR qBbotyrmMFLnNeWd513gWnPl/ootvwWa0yIYsdSQ/Y9oCD/gaSLeBccPkNXz2U5SffXj xoxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Lp3dcu10; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w44si4615308qth.265.2019.12.20.04.33.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Lp3dcu10; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHTh-00081j-GC for patch@linaro.org; Fri, 20 Dec 2019 07:33:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAt-0000g6-8z for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAr-0001LX-Pt for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:36580) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAr-0001Gz-Dq for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:29 -0500 Received: by mail-wm1-x341.google.com with SMTP id p17so9020885wma.1 for ; Fri, 20 Dec 2019 04:14:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=Lp3dcu100TH5P0m6J/X71PizRAWRciZTSkHXfRhcpa3fQm7p8bAwdiBzCj32BLhj9N f8aj7+iV7C15MrAlH+gQxtnaOjMIDeHZxPlJyaWzYDjUgNUWfZgL+Gr0BFrwUEkAID9p G5ogaOSgyt07L9nCHNGrB3vsOM2aCB/r7AghorMR8EGvWgCRmSAVek4kjvMRTDozO+7x pbuw6bi6CqXKKTd8cnvXie6IJrSVducWBQYDYb5cbnKIOgy6a0V7G66+q+BA9A0/ERTd PNUQXqX1zC0vUhVaNZKzpLCSNgiJD8V4uGhwLyBhaRDKH0FkEE/sILFKY3Ebowk3LZK+ kREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r6DZWz56Ou8zN9swvxhZLHdPuxthEvVWZNmtroVIhWQ=; b=LKT2V9tC2cDwgY/HlUuOjdk/hCPHVApVTplAiyhG17lsZzAjovzwIqVT8WEeIGg4ir bWnFsmP2gvkOS5cPUAKRokIRx5DjrZ0W6+BwPB6GI7djv9V/NmCRPdksQuLRNyzp5WFS b6F5C5H+hsJNc6ThSjDmUiw1MDnbUSXUPzH+fKfIl/dgrGL1ykdwaLB3pnF5v3IFNhPK Sr7jeHOXDbSCXqDdZ7WMjZ4IB5mEmwOLiFP9vvKeKD5KvB3P67Zxnbt/FWhgOTrvx6wx f9SmlR+/7Po+NQ6CA01v5N5MxuhoaqZpr4IO+iPdm1Nha4CgUEiP/J6aoPOTB+iUDTjP X3LA== X-Gm-Message-State: APjAAAX/Tjmo7hzv1KZV+RerBVXHyVJRXx70BD1R7YMOp0qSopBfzHip Y3Sa8VdJKbRAN+0nYb/xWnYCmP/fcLA= X-Received: by 2002:a1c:a795:: with SMTP id q143mr15308301wme.52.1576844068237; Fri, 20 Dec 2019 04:14:28 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x10sm10077775wrp.58.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DE3101FFA9; Fri, 20 Dec 2019 12:04:40 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 19/21] tests/tcg/aarch64: add test-sve-ioctl guest-debug test Date: Fri, 20 Dec 2019 12:04:36 +0000 Message-Id: <20191220120438.16114-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, Peter Maydell , luis.machado@linaro.org, "open list:ARM TCG CPUs" , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This test exercises the gdbstub while runing the sve-iotcl test. I haven't plubmed it into make system as we need a way of verifying if gdb has the right support for SVE. Signed-off-by: Alex Bennée --- v4 - interrogate ZCR_EL1 directly as no longer have vg --- tests/tcg/aarch64/gdbstub/test-sve-ioctl.py | 71 +++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/tcg/aarch64/gdbstub/test-sve-ioctl.py -- 2.20.1 diff --git a/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py b/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py new file mode 100644 index 00000000000..6b6b6c83f2d --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-sve-ioctl.py @@ -0,0 +1,71 @@ +from __future__ import print_function +# +# Test the SVE ZReg reports the right amount of data. It uses the +# sve-ioctl test and examines the register data each time the +# __sve_ld_done breakpoint is hit. +# +# This is launched via tests/guest-debug/run-test.py +# + +import gdb + +initial_vlen = 0 +failcount = 0 + +def report(cond, msg): + "Report success/fail of test" + if cond: + print ("PASS: %s" % (msg)) + else: + print ("FAIL: %s" % (msg)) + global failcount + failcount += 1 + +class TestBreakpoint(gdb.Breakpoint): + def __init__(self, sym_name="__sve_ld_done"): + super(TestBreakpoint, self).__init__(sym_name) + # self.sym, ok = gdb.lookup_symbol(sym_name) + + def stop(self): + val_i = gdb.parse_and_eval('i') + global initial_vlen + for i in range(0, int(val_i)): + val_z = gdb.parse_and_eval("$z0.b.u[%d]" % i) + report(int(val_z) == i, "z0.b.u[%d] == %d" % (i, i)) + for i in range(i + 1, initial_vlen): + val_z = gdb.parse_and_eval("$z0.b.u[%d]" % i) + report(int(val_z) == 0, "z0.b.u[%d] == 0" % (i)) + + +def run_test(): + "Run through the tests one by one" + + print ("Setup breakpoint") + bp = TestBreakpoint() + + global initial_vlen + vg = gdb.parse_and_eval("$ZCR_EL1") + initial_vlen = int(vg) * 16 + + gdb.execute("c") + +# +# This runs as the script it sourced (via -x, via run-test.py) +# + +try: + # These are not very useful in scripts + gdb.execute("set pagination off") + gdb.execute("set confirm off") + + # Run the actual tests + run_test() +except: + print ("GDB Exception: %s" % (sys.exc_info()[0])) + failcount += 1 + import code + code.InteractiveConsole(locals=globals()).interact() + raise + +print("All tests complete: %d failures" % failcount) +exit(failcount) From patchwork Fri Dec 20 12:04:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182266 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp469809ilf; Fri, 20 Dec 2019 04:35:48 -0800 (PST) X-Google-Smtp-Source: APXvYqy8ucUwdR10DjWsk1Rfmcld/XzGno32biQ4SULttoJPYm0HmIf6OCrQ69sM275POWxEm2z7 X-Received: by 2002:aca:4ec5:: with SMTP id c188mr74676oib.1.1576845348693; Fri, 20 Dec 2019 04:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576845348; cv=none; d=google.com; s=arc-20160816; b=leH9SL9py96XktGmpYFLiiEYDfbNIfPTq4YedGHem6UBWwOHKh2kHEyhIKYvJioo6Q BXduiEh1IAj/HshfpJ40zWBhEMDMpsioSe47PQa3zxCFxpo/fz4VMMADVRf0RXoHz5Rb Xx2EF+BcYdnIEvX68OdFxmKHh72uMJYBF7GZv7cKyW3PqoIlFb/lAz8yjLJHoEgixeqa GoalUwSZxMZ3w0tWrabEW090yHc82ODUf3gpFy1Wk/uJO7WLzYKGpjayHLP2xTq+/XJq tgUBM9Qq4OtN8ZjTjznlKqi/5K2/uFSDG5nNs6NKxMN5HRG5GwSdLtvdesJeC+8npdeU D6IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=HYTs7VdnIgn/2DYwqX0gFyzRy+yVJG3yPznnADafXQvEoOUHhyXqKXAC4FEj/6Gx0z FZMDxqdNOKEkdnhSfVZwcgcX2k61smxyrBbFFqR6AKIMA00iGfIspnLonOfB/XMt61Ly 0mvsR+UY7jUMjDkCSGxEWyMICU4wz2rDmU7SymUiqBdOmfTeA3ChGU6amnIVN7YjSTEa /rUf/EWbXg711ZmQexPjDfe/igSg0pW7LAMIEWhYaWVB/rI6XQhjaeHJh7uI+UCV38gf lqUq64Ldv2y+QDxIpw4/KuhNap1C4BUnnCgzcUDsBIl1K1LA/j7iJvpKSttyslf02M+m Yjpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qA2Nbbnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x142si2364989oia.220.2019.12.20.04.35.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:35:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qA2Nbbnk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHVT-0001oq-TZ for patch@linaro.org; Fri, 20 Dec 2019 07:35:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36706) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAu-0000jj-RM for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAt-0001Q9-39 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:32 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34042) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAs-0001M9-Oa for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:30 -0500 Received: by mail-wm1-x343.google.com with SMTP id c127so1632092wme.1 for ; Fri, 20 Dec 2019 04:14:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=qA2Nbbnkf7t7LSKkmijtFigfij9EhBRtlf6+zLdSkH420XupqFUbMgVl9WcotKQEir fQYZXiwOwqXHl89D5VpT2YUiZK23e1DYjanfr7ZN4N2+JIOLltDI2tEx+Hel7HmfOakt ngHiiPj1zFQx5T8UFC9WvVXxphsrCHps0FzUznXpSsTf2DUPXut5jBeQQoZMB4i9ELGh rDLF6ELs8bZObKdDbNrU21jjHbV0Bkwjm2Vn36a1zANq2zbvk2xcbraG4XxL5GHhGZyQ Hv1ZiF3c2ReAx3O/Gbi9duUuFjpeaEFKa+ccTVpAPzWlM14mh7zUFzU3ak5iQEW7icOI kNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oMQw6t6tRzlw6HQPCH1hJECHMvald9wcRxGqG3qpIY0=; b=hXMRQuLQ3FOCB5cdbII9D2bV4o41R+MUwV/L7ZRWLapFUbNrrUkQpZHAsvYv5g+vcy 8buCAuNLLbx4Z6Ql/JlHKYJzcChiqOWMz+s2bZJYZh4ScnEDb7xSkMV4wNoet55GDnDZ oKgvgu/QiotzTqSsgoFuXKG7M+iOfdELz3nHjYgQJLukv8kmwM4Od4w3iwqal7b8Cgtn emk6DeQdePYYYnTcgtqJi8Uadgx2CsOt2KwhIKPMWPWgcyybWnezNgnd6NYUGC4M/QVG pJrFa+aZqCV5BPGA/XdNPz3Yv8O7f8lyEiNDHdi7ppop4Cu2s65Mqrsbaj3T2n8LQYHF b8Vw== X-Gm-Message-State: APjAAAW7tfzy1CtDDcVN1XRtbAvruNf8xvAlsE3uY3DrxDAC/4od7Bo7 I7ZLqQW9nVmfWhWsR7B4z/opaA== X-Received: by 2002:a7b:cd0a:: with SMTP id f10mr16703426wmj.56.1576844069376; Fri, 20 Dec 2019 04:14:29 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s10sm9517124wrw.12.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 00A021FFAA; Fri, 20 Dec 2019 12:04:41 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 20/21] gdbstub: change GDBState.last_packet to GByteArray Date: Fri, 20 Dec 2019 12:04:37 +0000 Message-Id: <20191220120438.16114-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , luis.machado@linaro.org, alan.hayward@arm.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Damien Hedde Remove the packet size upper limit by using a GByteArray instead of a statically allocated array for last_packet. Thus we can now send big packets. Also remove the last_packet_len field and use last_packet->len instead. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20191211160514.58373-2-damien.hedde@greensocs.com> Signed-off-by: Alex Bennée --- gdbstub.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 287d0535b12..49e760283db 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -351,8 +351,7 @@ typedef struct GDBState { int line_buf_index; int line_sum; /* running checksum */ int line_csum; /* checksum at the end of the packet */ - uint8_t last_packet[MAX_PACKET_LENGTH + 4]; - int last_packet_len; + GByteArray *last_packet; int signal; #ifdef CONFIG_USER_ONLY int fd; @@ -384,6 +383,7 @@ static void init_gdbserver_state(void) gdbserver_state.init = true; gdbserver_state.str_buf = g_string_new(NULL); gdbserver_state.mem_buf = g_byte_array_sized_new(MAX_PACKET_LENGTH); + gdbserver_state.last_packet = g_byte_array_sized_new(MAX_PACKET_LENGTH + 4); } #ifndef CONFIG_USER_ONLY @@ -626,28 +626,29 @@ static void hexdump(const char *buf, int len, static int put_packet_binary(const char *buf, int len, bool dump) { int csum, i; - uint8_t *p; - uint8_t *ps = &gdbserver_state.last_packet[0]; + uint8_t footer[3]; if (dump && trace_event_get_state_backends(TRACE_GDBSTUB_IO_BINARYREPLY)) { hexdump(buf, len, trace_gdbstub_io_binaryreply); } for(;;) { - p = ps; - *(p++) = '$'; - memcpy(p, buf, len); - p += len; + g_byte_array_set_size(gdbserver_state.last_packet, 0); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) "$", 1); + g_byte_array_append(gdbserver_state.last_packet, + (const uint8_t *) buf, len); csum = 0; for(i = 0; i < len; i++) { csum += buf[i]; } - *(p++) = '#'; - *(p++) = tohex((csum >> 4) & 0xf); - *(p++) = tohex((csum) & 0xf); + footer[0] = '#'; + footer[1] = tohex((csum >> 4) & 0xf); + footer[2] = tohex((csum) & 0xf); + g_byte_array_append(gdbserver_state.last_packet, footer, 3); - gdbserver_state.last_packet_len = p - ps; - put_buffer(ps, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); #ifdef CONFIG_USER_ONLY i = get_char(); @@ -2812,20 +2813,22 @@ static void gdb_read_byte(uint8_t ch) uint8_t reply; #ifndef CONFIG_USER_ONLY - if (gdbserver_state.last_packet_len) { + if (gdbserver_state.last_packet->len) { /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch == '-') { trace_gdbstub_err_got_nack(); - put_buffer((uint8_t *)gdbserver_state.last_packet, gdbserver_state.last_packet_len); + put_buffer(gdbserver_state.last_packet->data, + gdbserver_state.last_packet->len); } else if (ch == '+') { trace_gdbstub_io_got_ack(); } else { trace_gdbstub_io_got_unexpected(ch); } - if (ch == '+' || ch == '$') - gdbserver_state.last_packet_len = 0; + if (ch == '+' || ch == '$') { + g_byte_array_set_size(gdbserver_state.last_packet, 0); + } if (ch != '$') return; } @@ -3209,7 +3212,7 @@ static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) const char *p = (const char *)buf; int max_sz; - max_sz = (sizeof(gdbserver_state.last_packet) - 2) / 2; + max_sz = (MAX_PACKET_LENGTH / 2) + 1; for (;;) { if (len <= max_sz) { gdb_monitor_output(p, len); From patchwork Fri Dec 20 12:04:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 182261 Delivered-To: patch@linaro.org Received: by 2002:a92:1f98:0:0:0:0:0 with SMTP id f24csp459926ilf; Fri, 20 Dec 2019 04:27:00 -0800 (PST) X-Google-Smtp-Source: APXvYqyAajR94Ia3fF8CSKyKFVquehTcrk2KXB6UfLnplPkFlgn0ZjmDHfoIdFMJTuV8MvUIvyme X-Received: by 2002:a37:a68f:: with SMTP id p137mr13148108qke.328.1576844820774; Fri, 20 Dec 2019 04:27:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576844820; cv=none; d=google.com; s=arc-20160816; b=lI9v6YDEH9mxoiuIPO4rYszA6EFxwHPSWT3OCMHv1prhP1Z5Ibdv4PNuKKildF49qn eLSzJBLse1ynZ0WQ6N+BrlkPffchTeEtgA9B4v+Ui/nufbbWrav02FkIp4R6vJOnqz6b uCtmRrO2GdvZfkRy7v+JzQVR44T9rTdE7qgWboqP3t0FLdQrKY4s0umAaNyG1wKbwDGS XsClB5DLaN4JN50gz3fMKvpRw3fTTKhIjwLouEibgXKQ/NXpT7ThO07l8CVG0WY7h/Cl EmJTuuh4yCpkPG8azWOfcm7lSQJBnsmszv6/0IGoOhfMJOeFIhJHY31OQ8C4ufeSYPB3 ZBeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=p4EoOoFm66IFdxb9WhPODofp7NTeDL7arqJ1alLqhLf5huc05wGvK/K/JdkEEjaXhG afzfSs5UKG+5RRxAUji1P3ty0YhtnezrhiwaZKWLxIbGDjQoJLeB360Ps+kX0z+q9GPm BNHHDTmGUJtmC86sTHg6Qs+WwpYCN1jqVQDy0ufDRh4bZ4R8xZTeN080I61lppniU94j yYWCemqOV5+O+Vb5pKej2FfskpivPz5okpJDkDm+hVtyvwmwjMaAXNnc04m/Mlz9mVLL nvyhqGwkdthFL10MUXo8dIZ310x4Pw2eWSUO6VPL0jVmlWMUdkA0+rnP7IQArYaua/Ne SM8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uKxqL+Hz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u22si5293891qkm.81.2019.12.20.04.27.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 Dec 2019 04:27:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uKxqL+Hz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHMy-0000yP-AF for patch@linaro.org; Fri, 20 Dec 2019 07:27:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iiHAv-0000ku-A2 for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iiHAu-0001U2-2w for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:33 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:39508) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iiHAt-0001Q3-Od for qemu-devel@nongnu.org; Fri, 20 Dec 2019 07:14:31 -0500 Received: by mail-wr1-x443.google.com with SMTP id y11so9213129wrt.6 for ; Fri, 20 Dec 2019 04:14:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=uKxqL+Hzw4iaAyf2GQL3ih302+LPHD0BDKm0lOAWQE8yHtx4s7INbPSymA8JDx6sRY ET2+uPQ6b5llAglhMnBxJaLv7hWLR2jU4SpfIDU14BPPiP5jYv4UQIxPCR8hd2Cq0wLG cpPufAmiWJQdGs3zH2oF1wf6WRA7vxrqaVxWBYuw5nkSOt9D5Z4GGU+usgVNd2J1mJsu KnGg5matGM04D9YEJgjz7Hyovm1U+y/F8HEW+GVFK/7RMCEheIEx9zTMfhN8eyV5pQC2 yamKp9+uPDrrpklg1VMtp1QFxTYlZJwOMWzKqlX5NgUH1SoX/Pix4cixn/IzZ+bmy/y0 7c1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZYdZReL1NF4ccjo0j5hGGmu8VTV/596/vKb83rC+xjU=; b=pk6HkyTAdFnd+f5ddhMv+XFdqzGkQYXG/BUWfXHg99n+NW4qYll78CYDqnC3Rq3+Cf w0EsWMQp6btcGMaTJeQ3L7N/0XmHi/r9Lp2bfJF9hqtU6i235ssnuLaecS5u0VLGV5GO YxuvspyTmN2V4pVhoR776o9/nAXjS2q0hpIc0+M9YpaFBdFhGUO2KvloZGB1nS6ce4mB +U52WhENvLLG8AOOwVesaJ8n8aT011I2Zm3iPyZDE+SyI+oh/LsZwYJadc3D/BXl5Rcw 7lrmjHsfAAUwHMyxxsX5+O9Xwhm3mQrxwy3fHYXre66MWwXfpWTNDyTp7jUbO7JFQN/s +Npw== X-Gm-Message-State: APjAAAVb73Ze5jpYnxfw0QA6ywIjVAkQrBx0ljhEdyzYxsQMUxpgyIKk xaukQ6pyY06KUMX0LDviwgs40w== X-Received: by 2002:adf:f2c1:: with SMTP id d1mr14599626wrp.111.1576844070397; Fri, 20 Dec 2019 04:14:30 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q3sm9131236wmc.47.2019.12.20.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 04:14:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 155C61FFAB; Fri, 20 Dec 2019 12:04:41 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v4 21/21] gdbstub: do not split gdb_monitor_write payload Date: Fri, 20 Dec 2019 12:04:38 +0000 Message-Id: <20191220120438.16114-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220120438.16114-1-alex.bennee@linaro.org> References: <20191220120438.16114-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: damien.hedde@greensocs.com, luis.machado@linaro.org, =?utf-8?q?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , alan.hayward@arm.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Luc Michel Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Damien Hedde Since we can now send packets of arbitrary length: simplify gdb_monitor_write() and send the whole payload in one packet. Suggested-by: Luc Michel Signed-off-by: Damien Hedde Signed-off-by: Alex Bennée Message-Id: <20191211160514.58373-3-damien.hedde@greensocs.com> --- gdbstub.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 49e760283db..5d0cdb81e4f 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -3200,28 +3200,11 @@ static void gdb_chr_event(void *opaque, int event) } } -static void gdb_monitor_output(const char *msg, int len) -{ - g_autoptr(GString) buf = g_string_new("O"); - memtohex(buf, (uint8_t *)msg, len); - put_packet(buf->str); -} - static int gdb_monitor_write(Chardev *chr, const uint8_t *buf, int len) { - const char *p = (const char *)buf; - int max_sz; - - max_sz = (MAX_PACKET_LENGTH / 2) + 1; - for (;;) { - if (len <= max_sz) { - gdb_monitor_output(p, len); - break; - } - gdb_monitor_output(p, max_sz); - p += max_sz; - len -= max_sz; - } + g_autoptr(GString) hex_buf = g_string_new("O"); + memtohex(hex_buf, buf, len); + put_packet(hex_buf->str); return len; }