From patchwork Sat Jun 14 21:08:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: maddy X-Patchwork-Id: 359810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BD1C81400EA for ; Sun, 15 Jun 2014 07:44:39 +1000 (EST) Received: from localhost ([::1]:36843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wvvkb-0007Ep-PS for incoming@patchwork.ozlabs.org; Sat, 14 Jun 2014 17:44:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvvC0-0005rC-4x for qemu-devel@nongnu.org; Sat, 14 Jun 2014 17:09:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WvvBo-0005lL-VK for qemu-devel@nongnu.org; Sat, 14 Jun 2014 17:08:52 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:43110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvvBo-0005jP-8d for qemu-devel@nongnu.org; Sat, 14 Jun 2014 17:08:40 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 15 Jun 2014 07:08:34 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 15 Jun 2014 07:08:33 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id B59DA2CE8047; Sun, 15 Jun 2014 07:08:32 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5EKkQuQ10617110; Sun, 15 Jun 2014 06:46:27 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5EL8VER014557; Sun, 15 Jun 2014 07:08:31 +1000 Received: from SrihariMadhavan.ibm.com ([9.80.70.144]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5EL8Tt6014532; Sun, 15 Jun 2014 07:08:30 +1000 From: Madhavan Srinivasan To: agraf@suse.de, paulus@samba.org Date: Sun, 15 Jun 2014 02:38:27 +0530 Message-Id: <1402780107-28864-1-git-send-email-maddy@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14061421-6102-0000-0000-000005C69362 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 X-Mailman-Approved-At: Sat, 14 Jun 2014 17:44:15 -0400 Cc: Madhavan Srinivasan , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] qemu/target-ppc: software breakpoint support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds software breakpoint support for ppc. Patch allows to insert and remove sw breakpoints using Qemu gdbserver on ppc. Patch use "abs" instruction as sw breakpoint instruction. This instruction with primary opcode 31 and extended opcode 360 has been dropped from PowerISA (in v2.01) and will generate an Emulation assistance interrupt in hypervisor when executed. KVM also has to be updated with this to make use of sw breakpoint. Signed-off-by: Madhavan Srinivasan --- target-ppc/kvm.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 9974b10..fa4b4ec 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -1201,6 +1201,17 @@ static int kvmppc_handle_dcr_write(CPUPPCState *env, uint32_t dcrn, uint32_t dat return 0; } +static int kvmppc_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *arch_info) +{ + int ret = -1; + + if (kvm_find_sw_breakpoint(cs, arch_info->address)) { + ret = EXCP_DEBUG; + } + + return ret; +} + int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) { PowerPCCPU *cpu = POWERPC_CPU(cs); @@ -1240,7 +1251,10 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) watchdog_perform_action(); ret = 0; break; - + case KVM_EXIT_DEBUG: + DPRINTF("handle debug exit pc = 0x%lx\n", run->debug.arch.address); + ret = kvmppc_handle_debug(cs, &run->debug.arch); + break; default: fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason); ret = -1; @@ -1901,14 +1915,29 @@ void kvm_arch_init_irq_routing(KVMState *s) { } +static const uint8_t dbg_int[] = { 0x7c, 0x00, 0x02, 0xd0}; int kvm_arch_insert_sw_breakpoint(CPUState *cpu, struct kvm_sw_breakpoint *bp) { - return -EINVAL; + if( cpu_memory_rw_debug(cpu, bp->pc, (uint8_t *)&bp->saved_insn, sizeof(dbg_int), 0) || + cpu_memory_rw_debug(cpu, bp->pc, (uint8_t *)dbg_int, sizeof(dbg_int), 1) ){ + return -EINVAL; + } + return 0; } int kvm_arch_remove_sw_breakpoint(CPUState *cpu, struct kvm_sw_breakpoint *bp) { - return -EINVAL; + uint8_t tmp[4]; + + if (cpu_memory_rw_debug(cpu, bp->pc, tmp, sizeof(dbg_int), 0)) { + return -EINVAL; + } else if (memcmp(tmp, dbg_int, sizeof(dbg_int))) { + return -EINVAL; + } else if (cpu_memory_rw_debug(cpu, bp->pc, (uint8_t *)&bp->saved_insn, sizeof(dbg_int), 1)) { + return -EINVAL; + } + + return 0; } int kvm_arch_insert_hw_breakpoint(target_ulong addr, target_ulong len, int type) @@ -1927,6 +1956,9 @@ void kvm_arch_remove_all_hw_breakpoints(void) void kvm_arch_update_guest_debug(CPUState *cpu, struct kvm_guest_debug *dbg) { + if (kvm_sw_breakpoints_active(cpu)) { + dbg->control |= KVM_GUESTDBG_USE_SW_BP; + } } struct kvm_get_htab_buf {