From f885a8d76c96ec94e2f7a4c4fadd57dfe384a8ac Mon Sep 17 00:00:00 2001 From: Adrien Grassein Date: Thu, 18 Jan 2024 11:54:15 +0100 Subject: [PATCH] target/aarch64: Cleanup on exit Restore target configuration on exit so that OpenOCD get correct values when restarting. Change-Id: I8cbba1fdae1d3c4a580197b7a97691443780ed06 Signed-off-by: Adrien Grassein Signed-off-by: Adrien Charruel Reviewed-on: https://review.openocd.org/c/openocd/+/8654 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/aarch64.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/target/aarch64.c b/src/target/aarch64.c index 609965ba5..ce7808e3a 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -2857,6 +2857,14 @@ static void aarch64_deinit_target(struct target *target) struct aarch64_common *aarch64 = target_to_aarch64(target); struct armv8_common *armv8 = &aarch64->armv8_common; struct arm_dpm *dpm = &armv8->dpm; + uint64_t address; + + if (target->state == TARGET_HALTED) { + // Restore the previous state of the target (gp registers, MMU, caches, etc) + int retval = aarch64_restore_one(target, true, &address, false, false); + if (retval != ERROR_OK) + LOG_TARGET_ERROR(target, "Failed to restore target state"); + } if (armv8->debug_ap) dap_put_ap(armv8->debug_ap); -- 2.49.0