From patchwork Mon Jun 22 00:44:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1314027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49qrKs2lCrz9sRh for ; Mon, 22 Jun 2020 10:45:21 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=OgxetIvv; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49qrKr5ZvNzDqbc for ; Mon, 22 Jun 2020 10:45:20 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49qrKg2p6WzDqbW for ; Mon, 22 Jun 2020 10:45:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=OgxetIvv; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 49qrKf62z8z9sRh; Mon, 22 Jun 2020 10:45:10 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1592786711; bh=kPZk4xv+cGxAHpRpyBeD5AZ0hcyz92w56eZqExbnZRA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgxetIvv/L50l4t+OAaMc5HD6eaIENg0Y2X6fzqSm42fftfXhwGSS8rBEQbm2dmUA VNYT7qNgCTAIsOPvvzM9u1OnDECmgxZ5AVXPsvOcCM0KyeC7orWfOxK2456q0xFtj8 TJgeDMM1KI6iEyDKgGuVQtzYtAJoCuGRLu0Q5lBqqF3/q5TRY2/TbCCSzcg99S+QJt frU0MVIraHHV6zZbzBbJczsqHFPS1nz2nQhrDfdHybomTKeUYyC2ER+I+ZjGiSFEyk JdW84W770iEDK73OrT+LE/bflQE8Ss0sL4wQVeomtskHqV/HStt11zwR/RwUcgJdJ+ EOBKPWK2jZ4CQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Mon, 22 Jun 2020 10:44:53 +1000 Message-Id: <20200622004501.12889-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200622004501.12889-1-amitay@ozlabs.org> References: <20200622004501.12889-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 1/9] libpdbg: Make thread procedures consistent X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" All thread procedures should use struct thread as the first argument instead of struct pdbg_target. Signed-off-by: Amitay Isaacs --- libpdbg/chip.c | 79 ++++++++++++++++++++++++++++++++---------------- libpdbg/chip.h | 5 ++- libpdbg/hwunit.h | 6 ++-- libpdbg/p8chip.c | 13 +++----- libpdbg/p9chip.c | 8 ++--- src/pdbgproxy.c | 2 +- 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/libpdbg/chip.c b/libpdbg/chip.c index 86e91bd..f9f184b 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -274,18 +274,14 @@ int thread_sreset_all(void) * data. Note that only registers r0 and r1 are saved and restored so * opcode sequences must preserve other registers. */ -int ram_instructions(struct pdbg_target *thread_target, uint64_t *opcodes, +int ram_instructions(struct thread *thread, uint64_t *opcodes, uint64_t *results, int len, unsigned int lpar) { uint64_t opcode = 0, r0 = 0, r1 = 0, scratch = 0; int i; int exception = 0; - struct thread *thread; bool did_setup = false; - assert(!strcmp(thread_target->class, "thread")); - thread = target_to_thread(thread_target); - if (!thread->ram_is_setup) { CHECK_ERR(thread->ram_setup(thread)); did_setup = true; @@ -339,31 +335,40 @@ int ram_instructions(struct pdbg_target *thread_target, uint64_t *opcodes, /* * Get gpr value. Chip must be stopped. */ -int thread_getgpr(struct pdbg_target *thread, int gpr, uint64_t *value) +int thread_getgpr(struct pdbg_target *target, int gpr, uint64_t *value) { + struct thread *thread; uint64_t opcodes[] = {mtspr(277, gpr)}; uint64_t results[] = {0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); *value = results[0]; return 0; } -int thread_putgpr(struct pdbg_target *thread, int gpr, uint64_t value) +int thread_putgpr(struct pdbg_target *target, int gpr, uint64_t value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(gpr, 277)}; uint64_t results[] = {value}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); return 0; } -int thread_getnia(struct pdbg_target *thread, uint64_t *value) +int thread_getnia(struct pdbg_target *target, uint64_t *value) { + struct thread *thread; uint64_t opcodes[] = {mfnia(0), mtspr(277, 0)}; uint64_t results[] = {0, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); *value = results[1]; return 0; @@ -376,8 +381,9 @@ int thread_getnia(struct pdbg_target *thread, uint64_t *value) * This is a hack and should be made much cleaner once we have target * specific putspr commands. */ -int thread_putnia(struct pdbg_target *thread, uint64_t value) +int thread_putnia(struct pdbg_target *target, uint64_t value) { + struct thread *thread; uint64_t opcodes[] = { mfspr(1, 8), /* mflr r1 */ mfspr(0, 277), /* value -> r0 */ mtspr(8, 0), /* mtlr r0 */ @@ -385,42 +391,53 @@ int thread_putnia(struct pdbg_target *thread, uint64_t value) mtspr(8, 1), }; /* mtlr r1 */ uint64_t results[] = {0, value, 0, 0, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); return 0; } -int thread_getspr(struct pdbg_target *thread, int spr, uint64_t *value) +int thread_getspr(struct pdbg_target *target, int spr, uint64_t *value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(0, spr), mtspr(277, 0)}; uint64_t results[] = {0, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); *value = results[1]; return 0; } -int thread_putspr(struct pdbg_target *thread, int spr, uint64_t value) +int thread_putspr(struct pdbg_target *target, int spr, uint64_t value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(0, 277), mtspr(spr, 0)}; uint64_t results[] = {value, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); return 0; } -int thread_getmsr(struct pdbg_target *thread, uint64_t *value) +int thread_getmsr(struct pdbg_target *target, uint64_t *value) { + struct thread *thread; uint64_t opcodes[] = {mfmsr(0), mtspr(277, 0)}; uint64_t results[] = {0, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); *value = results[1]; return 0; } -int thread_getcr(struct pdbg_target *thread, uint32_t *value) +int thread_getcr(struct pdbg_target *target, uint32_t *value) { - + struct thread *thread; uint64_t opcodes[] = {mfocrf(0, 0), mtspr(277, 0), mfocrf(0, 1), mtspr(277, 0), mfocrf(0, 2), mtspr(277, 0), mfocrf(0, 3), mtspr(277, 0), mfocrf(0, 4), mtspr(277, 0), mfocrf(0, 5), mtspr(277, 0), @@ -429,6 +446,8 @@ int thread_getcr(struct pdbg_target *thread, uint32_t *value) uint32_t cr_field, cr = 0; int i; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); for (i = 1; i < 16; i += 2) { cr_field = results[i]; @@ -440,58 +459,66 @@ int thread_getcr(struct pdbg_target *thread, uint32_t *value) return 0; } -int thread_putcr(struct pdbg_target *thread, uint32_t value) +int thread_putcr(struct pdbg_target *target, uint32_t value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(0, 277), mtocrf(0, 0), mtocrf(1, 0), mtocrf(2, 0), mtocrf(3, 0), mtocrf(4, 0), mtocrf(5, 0), mtocrf(6, 0), mtocrf(7, 0)}; uint64_t results[] = {value}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); return 0; } -int thread_putmsr(struct pdbg_target *thread, uint64_t value) +int thread_putmsr(struct pdbg_target *target, uint64_t value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(0, 277), mtmsr(0)}; uint64_t results[] = {value, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); return 0; } -int thread_getmem(struct pdbg_target *thread, uint64_t addr, uint64_t *value) +int thread_getmem(struct pdbg_target *target, uint64_t addr, uint64_t *value) { + struct thread *thread; uint64_t opcodes[] = {mfspr(0, 277), mfspr(1, 277), ld(0, 0, 1), mtspr(277, 0)}; uint64_t results[] = {0xdeaddeaddeaddead, addr, 0, 0}; + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); *value = results[3]; return 0; } -int thread_getxer(struct pdbg_target *thread_target, uint64_t *value) +int thread_getxer(struct pdbg_target *target, uint64_t *value) { - struct thread *thread; - assert(!strcmp(thread_target->class, "thread")); - thread = target_to_thread(thread_target); + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); - CHECK_ERR(thread->ram_getxer(thread_target, value)); + CHECK_ERR(thread->ram_getxer(thread, value)); return 0; } -int thread_putxer(struct pdbg_target *thread_target, uint64_t value) +int thread_putxer(struct pdbg_target *target, uint64_t value) { struct thread *thread; - assert(!strcmp(thread_target->class, "thread")); - thread = target_to_thread(thread_target); + assert(pdbg_target_is_class(target, "thread")); + thread = target_to_thread(target); - CHECK_ERR(thread->ram_putxer(thread_target, value)); + CHECK_ERR(thread->ram_putxer(thread, value)); return 0; } diff --git a/libpdbg/chip.h b/libpdbg/chip.h index 52f3486..b3342b8 100644 --- a/libpdbg/chip.h +++ b/libpdbg/chip.h @@ -16,9 +16,12 @@ #ifndef __LIBPDBG_CHIP_H #define __LIBPDBG_CHIP_H +#include "libpdbg.h" +#include "hwunit.h" + uint64_t mfspr(uint64_t reg, uint64_t spr) __attribute__ ((visibility("hidden"))); uint64_t mtspr(uint64_t spr, uint64_t reg) __attribute__ ((visibility("hidden"))); -int ram_instructions(struct pdbg_target *thread_target, uint64_t *opcodes, +int ram_instructions(struct thread *thread, uint64_t *opcodes, uint64_t *results, int len, unsigned int lpar) __attribute__ ((visibility("hidden"))); #endif diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index e3a8426..7fe83a6 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -140,9 +140,9 @@ struct thread { int (*ram_setup)(struct thread *); int (*ram_instruction)(struct thread *, uint64_t opcode, uint64_t *scratch); int (*ram_destroy)(struct thread *); - int (*ram_getxer)(struct pdbg_target *, uint64_t *value); - int (*ram_putxer)(struct pdbg_target *, uint64_t value); - int (*enable_attn)(struct pdbg_target *); + int (*ram_getxer)(struct thread *, uint64_t *value); + int (*ram_putxer)(struct thread *, uint64_t value); + int (*enable_attn)(struct thread *); }; #define target_to_thread(x) container_of(x, struct thread, target) diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c index 484d77c..4a2061a 100644 --- a/libpdbg/p8chip.c +++ b/libpdbg/p8chip.c @@ -477,7 +477,7 @@ static int p8_ram_destroy(struct thread *thread) return 0; } -static int p8_ram_getxer(struct pdbg_target *thread, uint64_t *value) +static int p8_ram_getxer(struct thread *thread, uint64_t *value) { uint64_t opcodes[] = {mfxerf(0, 0), mtspr(277, 0), mfxerf(0, 1), mtspr(277, 0), mfxerf(0, 2), mtspr(277, 0), @@ -496,7 +496,7 @@ static int p8_ram_getxer(struct pdbg_target *thread, uint64_t *value) return 0; } -static int p8_ram_putxer(struct pdbg_target *thread, uint64_t value) +static int p8_ram_putxer(struct thread *thread, uint64_t value) { uint64_t fields[] = {value, value, value, value, 0}; uint64_t opcodes[] = {mfspr(0, 277), mtxerf(0, 0), mtxerf(0, 1), mtxerf(0, 2), mtxerf(0, 3)}; @@ -618,17 +618,12 @@ static int p8_put_hid0(struct pdbg_target *chip, uint64_t value) return 0; } -static int p8_enable_attn(struct pdbg_target *target) +static int p8_enable_attn(struct thread *thread) { struct pdbg_target *core; uint64_t hid0; - core = pdbg_target_parent("core", target); - if (core == NULL) - { - PR_ERROR("CORE NOT FOUND\n"); - return 1; - } + core = pdbg_target_require_parent("core", &thread->target); /* Need to enable the attn instruction in HID0 */ if (p8_get_hid0(core, &hid0)) { diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c index 6222dc3..811bca6 100644 --- a/libpdbg/p9chip.c +++ b/libpdbg/p9chip.c @@ -404,16 +404,16 @@ static int p9_ram_destroy(struct thread *thread) return 0; } -static int p9_ram_getxer(struct pdbg_target *thread, uint64_t *value) +static int p9_ram_getxer(struct thread *thread, uint64_t *value) { - CHECK_ERR(thread_getspr(thread, 1, value)); + CHECK_ERR(thread_getspr(&thread->target, 1, value)); return 0; } -static int p9_ram_putxer(struct pdbg_target *thread, uint64_t value) +static int p9_ram_putxer(struct thread *thread, uint64_t value) { - CHECK_ERR(thread_putspr(thread, 1, value)); + CHECK_ERR(thread_putspr(&thread->target, 1, value)); return 0; diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c index ee99cfb..bb7c7b3 100644 --- a/src/pdbgproxy.c +++ b/src/pdbgproxy.c @@ -285,7 +285,7 @@ static void put_mem(uint64_t *stack, void *priv) data = attn_opcode; /* Need to enable the attn instruction in HID0 */ - if (thread->enable_attn(thread_target)) + if (thread->enable_attn(thread)) goto out; } else stack[2] = __builtin_bswap64(stack[2]) >> 32;