Hi,

Currently OpenOCD assumes that all targets read and save all registers
in context when stop, and restore them when resume. But for the target
I'm working on, the cost is too high to do that. My target has about
50 registers. Saving and restoring them needs much time. Usually GDB
and users are only interested in several registers. So I don't want
OpenOCD to save and restore all registers for my target. Instead, I
hope OpenOCD reads/writes registers only when necessary. To achieve
this, OpenOCD will invalidate all registers when target stops. If
OpenOCD is asked for a register value but it's invalid, it will then
read the register from the hardware and put them in the cache. When
resume the target, OpenOCD will write all dirty cached registers back
to hardware.

handle_reg_command already checks if the register is valid in the
cache and calls reg->type->get() to read the register if it's invalid.

This patch makes gdb_get_registers_packet and gdb_get_register_packet
do the same thing.

This patch should not affect existing targets.

Regards,
Jie
From 4fddaa909ac705a8bd5777a7121164f9aa1309b6 Mon Sep 17 00:00:00 2001
From: Jie Zhang <jie.zh...@analog.com>
Date: Tue, 3 May 2011 14:35:40 -0400
Subject: [PATCH] Get register value if it's invalid in cache.

---
 src/server/gdb_server.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 9c1d245..b29ee4f 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1064,6 +1064,8 @@ static int gdb_get_registers_packet(struct connection *connection,
 
 	for (i = 0; i < reg_list_size; i++)
 	{
+		if (!reg_list[i]->valid)
+			reg_list[i]->type->get(reg_list[i]);
 		gdb_str_to_target(target, reg_packet_p, reg_list[i]);
 		reg_packet_p += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
 	}
@@ -1168,6 +1170,9 @@ static int gdb_get_register_packet(struct connection *connection,
 		exit(-1);
 	}
 
+	if (!reg_list[reg_num]->valid)
+		reg_list[reg_num]->type->get(reg_list[reg_num]);
+
 	reg_packet = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2);
 
 	gdb_str_to_target(target, reg_packet, reg_list[reg_num]);
-- 
1.7.2.5

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to