Skip to contentSkip to conversation

qemu/target-ppc: software breakpoint support

PATCH In review Madhavan Srinivasan 2 participants 3 messages Jun 14, 2014 – Jun 17, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu/target-ppc: software breakpoint support

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.

---
 target-ppc/kvm.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
target-ppc/kvm.c +35 -3
index 9974b10..fa4b4ec 100644
@@ -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 {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 15 lines

-----Original Message-----
From: [email protected] [mailto:qemu-ppc- [email protected]] On Behalf Of Madhavan Srinivasan
Sent: Sunday, June 15, 2014 2:38 AM
To: [email protected]; [email protected]
Cc: Madhavan Srinivasan; [email protected]; [email protected]
Subject: [Qemu-ppc] [PATCH] qemu/target-ppc: software breakpoint support

This patch adds software breakpoint support for ppc. Patch allows to insert and remove sw breakpoints using Qemu gdbserver on ppc.

Quoted 5 lines

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.

There are already a patch "ppc debug: Add debug stub support" in review which implements software breakpoint
In addition this patch also implements h/w breakpoints/watchpoints for BOOKE. But I actually do not know how h/w breakpoints works on BOOK3S and you can help me figuring out what can be shared between booke and book3s.

Quoted 44 lines
---
 target-ppc/kvm.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
target-ppc/kvm.c +0 -0
index 9974b10..fa4b4ec 100644
@@ -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)

target-ppc/kvm.c +14 -1
+{
+	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;

target-ppc/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1918

Quoted 4 lines
target-ppc/kvm.c +1 -0
@@ -1901,14 +1915,29 @@ void kvm_arch_init_irq_routing(KVMState *s)
 {
 }
 
+static const uint8_t dbg_int[] = { 0x7c, 0x00, 0x02, 0xd0};

This should not be hardcoded but we should get this from KVM. Please refer to patch "ppc debug: Add debug stub support" to know how to get debug instruction.

Thanks
-Bharat

Quoted 44 lines
target-ppc/kvm.c +1 -1
 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) ||

target-ppc/kvm.c +1 -0
+	    cpu_memory_rw_debug(cpu, bp->pc, (uint8_t *)dbg_int, sizeof(dbg_int),

1) ){

target-ppc/kvm.c +10 -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)) {

target-ppc/kvm.c +4 -0
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 int kvm_arch_insert_hw_breakpoint(target_ulong addr, target_ulong len, int

type)

target-ppc/kvm.c +3 -1
@@ -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 {
--

1.8.3.1

#2 lore raw
Quoted 15 lines · On Monday 16 June 2014 03:22 PM, [email protected] wrote:
Quoted 15 lines

-----Original Message-----
From: [email protected] [mailto:qemu-ppc- [email protected]] On Behalf Of Madhavan Srinivasan
Sent: Sunday, June 15, 2014 2:38 AM
To: [email protected]; [email protected]
Cc: Madhavan Srinivasan; [email protected]; [email protected]
Subject: [Qemu-ppc] [PATCH] qemu/target-ppc: software breakpoint support

This patch adds software breakpoint support for ppc. Patch allows to insert and remove sw breakpoints using Qemu gdbserver on ppc.

Quoted 7 lines
Quoted 5 lines

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.

There are already a patch "ppc debug: Add debug stub support" in review which implements software breakpoint

My bad. Should have checked for it. Will look at the patchset posted.

Quoted 2 lines

In addition this patch also implements h/w breakpoints/watchpoints for BOOKE. But I actually do not know how h/w breakpoints works on BOOK3S and you can help me figuring out what can be shared between booke and book3s.

Sure will update you on this soon.

Quoted 47 lines
Quoted 47 lines
---
 target-ppc/kvm.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
target-ppc/kvm.c +0 -0
index 9974b10..fa4b4ec 100644
@@ -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)

target-ppc/kvm.c +14 -1
+{
+	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;
target-ppc/kvm.c +0 -0
@@ -1901,14 +1915,29 @@ void kvm_arch_init_irq_routing(KVMState *s)
 {
 }
 
Quoted 4 lines

target-ppc/kvm.c void kvm_arch_init_irq_routing(KVMState *s) · line 1918

Quoted 1 line
target-ppc/kvm.c +1 -0
+static const uint8_t dbg_int[] = { 0x7c, 0x00, 0x02, 0xd0};

This should not be hardcoded but we should get this from KVM. Please refer to patch "ppc debug: Add debug stub support" to know how to get debug instruction.

Sure Will do

Quoted 3 lines

Thanks
-Bharat

Thanks for review.
Regards
Maddy

Quoted 45 lines
Quoted 44 lines
target-ppc/kvm.c +1 -1
 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) ||

target-ppc/kvm.c +1 -0
+	    cpu_memory_rw_debug(cpu, bp->pc, (uint8_t *)dbg_int, sizeof(dbg_int),

1) ){

target-ppc/kvm.c +10 -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)) {

target-ppc/kvm.c +4 -0
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 int kvm_arch_insert_hw_breakpoint(target_ulong addr, target_ulong len, int

type)

target-ppc/kvm.c +3 -1
@@ -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 {
--

1.8.3.1