From owner-dev-commits-src-main@freebsd.org Fri Jan 8 18:53:52 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D2A924D3153; Fri, 8 Jan 2021 18:53:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DCC1X5fxsz4plS; Fri, 8 Jan 2021 18:53:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B54FB23A; Fri, 8 Jan 2021 18:53:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 108Irqvv083382; Fri, 8 Jan 2021 18:53:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 108IrqgT083381; Fri, 8 Jan 2021 18:53:52 GMT (envelope-from git) Date: Fri, 8 Jan 2021 18:53:52 GMT Message-Id: <202101081853.108IrqgT083381@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 5f66d5a313bf - main - arm64: remove pcb_pc MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5f66d5a313bf2b2254de92b2915e48e5cf528893 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2021 18:53:52 -0000 The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=5f66d5a313bf2b2254de92b2915e48e5cf528893 commit 5f66d5a313bf2b2254de92b2915e48e5cf528893 Author: mhorne AuthorDate: 2020-12-21 16:16:09 +0000 Commit: Mitchell Horne CommitDate: 2021-01-08 18:53:44 +0000 arm64: remove pcb_pc The program counter field in the PCB is written in exactly one place, makectx(), upon entry to the debugger. For threads other than curthread, its value will be empty, or bogus. Rather than writing to this field in more places, it can be removed in favor of using the value in the link register. To make this clearer, pcb->pcb_x[30] is renamed to pcb->pcb_lr, similar to what already exists in struct trapframe. Also, prefer lr to x30 in assembly, as it better conveys intention. This improves PC_REGS() for kdb_thread != curthread. It is required for a functional gdb(4) stub, fixing the output of `info threads`, in particular. The space occupied by pcb_pc is retained, for compatibility with kgdb. Reviewed by: markj, jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27720 --- sys/arm64/arm64/db_trace.c | 2 +- sys/arm64/arm64/exception.S | 2 +- sys/arm64/arm64/genassym.c | 1 + sys/arm64/arm64/machdep.c | 6 +++--- sys/arm64/arm64/stack_machdep.c | 2 +- sys/arm64/arm64/swtch.S | 8 ++++---- sys/arm64/arm64/vm_machdep.c | 6 +++--- sys/arm64/include/db_machdep.h | 2 +- sys/arm64/include/pcb.h | 6 +++--- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sys/arm64/arm64/db_trace.c b/sys/arm64/arm64/db_trace.c index 42f63ffdf4be..1743d7765861 100644 --- a/sys/arm64/arm64/db_trace.c +++ b/sys/arm64/arm64/db_trace.c @@ -109,7 +109,7 @@ db_trace_thread(struct thread *thr, int count) frame.sp = (uintptr_t)ctx->pcb_sp; frame.fp = (uintptr_t)ctx->pcb_x[29]; - frame.pc = (uintptr_t)ctx->pcb_x[30]; + frame.pc = (uintptr_t)ctx->pcb_lr; db_stack_trace_cmd(thr, &frame); } else db_trace_self(); diff --git a/sys/arm64/arm64/exception.S b/sys/arm64/arm64/exception.S index 123f73b49734..bcb444ef2f55 100644 --- a/sys/arm64/arm64/exception.S +++ b/sys/arm64/arm64/exception.S @@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$"); sub sp, sp, #128 .endif sub sp, sp, #(TF_SIZE + 16) - stp x29, x30, [sp, #(TF_SIZE)] + stp x29, lr, [sp, #(TF_SIZE)] stp x28, x29, [sp, #(TF_X + 28 * 8)] stp x26, x27, [sp, #(TF_X + 26 * 8)] stp x24, x25, [sp, #(TF_X + 24 * 8)] diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c index c211d121c06e..1575a0158dec 100644 --- a/sys/arm64/arm64/genassym.c +++ b/sys/arm64/arm64/genassym.c @@ -60,6 +60,7 @@ ASSYM(PC_SSBD, offsetof(struct pcpu, pc_ssbd)); ASSYM(PCB_SIZE, roundup2(sizeof(struct pcb), STACKALIGNBYTES + 1)); ASSYM(PCB_SINGLE_STEP_SHIFT, PCB_SINGLE_STEP_SHIFT); ASSYM(PCB_REGS, offsetof(struct pcb, pcb_x)); +ASSYM(PCB_LR, offsetof(struct pcb, pcb_lr)); ASSYM(PCB_SP, offsetof(struct pcb, pcb_sp)); ASSYM(PCB_TPIDRRO, offsetof(struct pcb, pcb_tpidrro_el0)); ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault)); diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index 739257bed1db..90fc19d57415 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -732,11 +732,11 @@ makectx(struct trapframe *tf, struct pcb *pcb) { int i; - for (i = 0; i < PCB_LR; i++) + for (i = 0; i < nitems(pcb->pcb_x); i++) pcb->pcb_x[i] = tf->tf_x[i]; - pcb->pcb_x[PCB_LR] = tf->tf_lr; - pcb->pcb_pc = tf->tf_elr; + /* NB: pcb_lr is the PC, see PC_REGS() in db_machdep.h */ + pcb->pcb_lr = tf->tf_elr; pcb->pcb_sp = tf->tf_sp; } diff --git a/sys/arm64/arm64/stack_machdep.c b/sys/arm64/arm64/stack_machdep.c index 7ca64c9f3b2d..673da833afb4 100644 --- a/sys/arm64/arm64/stack_machdep.c +++ b/sys/arm64/arm64/stack_machdep.c @@ -71,7 +71,7 @@ stack_save_td(struct stack *st, struct thread *td) frame.sp = td->td_pcb->pcb_sp; frame.fp = td->td_pcb->pcb_x[29]; - frame.pc = td->td_pcb->pcb_x[30]; + frame.pc = td->td_pcb->pcb_lr; stack_capture(td, st, &frame); return (0); diff --git a/sys/arm64/arm64/swtch.S b/sys/arm64/arm64/swtch.S index 144cc0873f68..ee64f89502cc 100644 --- a/sys/arm64/arm64/swtch.S +++ b/sys/arm64/arm64/swtch.S @@ -101,7 +101,7 @@ ENTRY(cpu_throw) ldp x24, x25, [x4, #PCB_REGS + 24 * 8] ldp x26, x27, [x4, #PCB_REGS + 26 * 8] ldp x28, x29, [x4, #PCB_REGS + 28 * 8] - ldr x30, [x4, #PCB_REGS + 30 * 8] + ldr lr, [x4, #PCB_LR] ret END(cpu_throw) @@ -132,7 +132,7 @@ ENTRY(cpu_switch) stp x24, x25, [x4, #PCB_REGS + 24 * 8] stp x26, x27, [x4, #PCB_REGS + 26 * 8] stp x28, x29, [x4, #PCB_REGS + 28 * 8] - str x30, [x4, #PCB_REGS + 30 * 8] + str lr, [x4, #PCB_LR] /* And the old stack pointer */ mov x5, sp mrs x6, tpidrro_el0 @@ -198,7 +198,7 @@ ENTRY(cpu_switch) ldp x24, x25, [x4, #PCB_REGS + 24 * 8] ldp x26, x27, [x4, #PCB_REGS + 26 * 8] ldp x28, x29, [x4, #PCB_REGS + 28 * 8] - ldr x30, [x4, #PCB_REGS + 30 * 8] + ldr lr, [x4, #PCB_LR] str xzr, [x4, #PCB_REGS + 18 * 8] ret @@ -270,7 +270,7 @@ ENTRY(savectx) stp x24, x25, [x0, #PCB_REGS + 24 * 8] stp x26, x27, [x0, #PCB_REGS + 26 * 8] stp x28, x29, [x0, #PCB_REGS + 28 * 8] - str x30, [x0, #PCB_REGS + 30 * 8] + str lr, [x0, #PCB_LR] /* And the old stack pointer */ mov x5, sp mrs x6, tpidrro_el0 diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c index b4a3e596f9ef..6a84dc023562 100644 --- a/sys/arm64/arm64/vm_machdep.c +++ b/sys/arm64/arm64/vm_machdep.c @@ -102,7 +102,7 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags) /* Set the return value registers for fork() */ td2->td_pcb->pcb_x[8] = (uintptr_t)fork_return; td2->td_pcb->pcb_x[9] = (uintptr_t)td2; - td2->td_pcb->pcb_x[PCB_LR] = (uintptr_t)fork_trampoline; + td2->td_pcb->pcb_lr = (uintptr_t)fork_trampoline; td2->td_pcb->pcb_sp = (uintptr_t)td2->td_frame; td2->td_pcb->pcb_fpusaved = &td2->td_pcb->pcb_fpustate; td2->td_pcb->pcb_vfpcpu = UINT_MAX; @@ -173,7 +173,7 @@ cpu_copy_thread(struct thread *td, struct thread *td0) td->td_pcb->pcb_x[8] = (uintptr_t)fork_return; td->td_pcb->pcb_x[9] = (uintptr_t)td; - td->td_pcb->pcb_x[PCB_LR] = (uintptr_t)fork_trampoline; + td->td_pcb->pcb_lr = (uintptr_t)fork_trampoline; td->td_pcb->pcb_sp = (uintptr_t)td->td_frame; td->td_pcb->pcb_fpusaved = &td->td_pcb->pcb_fpustate; td->td_pcb->pcb_vfpcpu = UINT_MAX; @@ -265,7 +265,7 @@ cpu_fork_kthread_handler(struct thread *td, void (*func)(void *), void *arg) td->td_pcb->pcb_x[8] = (uintptr_t)func; td->td_pcb->pcb_x[9] = (uintptr_t)arg; - td->td_pcb->pcb_x[PCB_LR] = (uintptr_t)fork_trampoline; + td->td_pcb->pcb_lr = (uintptr_t)fork_trampoline; td->td_pcb->pcb_sp = (uintptr_t)td->td_frame; td->td_pcb->pcb_fpusaved = &td->td_pcb->pcb_fpustate; td->td_pcb->pcb_vfpcpu = UINT_MAX; diff --git a/sys/arm64/include/db_machdep.h b/sys/arm64/include/db_machdep.h index 45d548c750bc..f2fd2a57a9c3 100644 --- a/sys/arm64/include/db_machdep.h +++ b/sys/arm64/include/db_machdep.h @@ -43,7 +43,7 @@ typedef vm_offset_t db_addr_t; typedef long db_expr_t; -#define PC_REGS() ((db_addr_t)kdb_thrctx->pcb_pc) +#define PC_REGS() ((db_addr_t)kdb_thrctx->pcb_lr) #define BKPT_INST (0xd4200000) #define BKPT_SIZE (4) diff --git a/sys/arm64/include/pcb.h b/sys/arm64/include/pcb.h index 25c1a5a7aff4..012ed2c92741 100644 --- a/sys/arm64/include/pcb.h +++ b/sys/arm64/include/pcb.h @@ -36,10 +36,10 @@ struct trapframe; -#define PCB_LR 30 struct pcb { - uint64_t pcb_x[31]; - uint64_t pcb_pc; + uint64_t pcb_x[30]; + uint64_t pcb_lr; + uint64_t _reserved; /* Was pcb_pc */ /* These two need to be in order as we access them together */ uint64_t pcb_sp; uint64_t pcb_tpidr_el0;