From owner-svn-src-all@freebsd.org Thu Nov 14 16:46:29 2019 Return-Path: Delivered-To: svn-src-all@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 180E41AD742; Thu, 14 Nov 2019 16:46:29 +0000 (UTC) (envelope-from ian@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) server-signature RSA-PSS (4096 bits) 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 47DS6r646Bz4dCM; Thu, 14 Nov 2019 16:46:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id AAF253407; Thu, 14 Nov 2019 16:46:28 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xAEGkSCS064198; Thu, 14 Nov 2019 16:46:28 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAEGkSSw064195; Thu, 14 Nov 2019 16:46:28 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201911141646.xAEGkSSw064195@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Thu, 14 Nov 2019 16:46:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354709 - in head/sys/arm: arm conf X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in head/sys/arm: arm conf X-SVN-Commit-Revision: 354709 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Nov 2019 16:46:29 -0000 Author: ian Date: Thu Nov 14 16:46:27 2019 New Revision: 354709 URL: https://svnweb.freebsd.org/changeset/base/354709 Log: Rewrite arm/stack_machdep.c for EABI; add stack(9) support to arm kernels. The old stack_machdep.c code was written for the APCS ABI (aka "oldabi"). When we switched to ARM EABI (back in freebsd 10) this file never got updated, and apparently nobody noticed that until now. The new implementation uses the same stack unwinder code used by the arm implemenation of the db_trace stuff. Modified: head/sys/arm/arm/stack_machdep.c head/sys/arm/conf/std.armv6 head/sys/arm/conf/std.armv7 Modified: head/sys/arm/arm/stack_machdep.c ============================================================================== --- head/sys/arm/arm/stack_machdep.c Thu Nov 14 16:28:02 2019 (r354708) +++ head/sys/arm/arm/stack_machdep.c Thu Nov 14 16:46:27 2019 (r354709) @@ -1,8 +1,7 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2005 Antoine Brodin - * All rights reserved. + * Copyright (c) 2019 Ian Lepore * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -29,63 +28,64 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include #include #include - -#include #include #include -/* - * This code makes assumptions about the stack layout. These are correct - * when using APCS (the old ABI), but are no longer true with AAPCS and the - * ARM EABI. There is also an issue with clang and llvm when building for - * APCS where it lays out the stack incorrectly. Because of this we disable - * this when building for ARM EABI or when building with clang. - */ +static void +stack_capture(struct stack *st, struct unwind_state *state) +{ -extern vm_offset_t kernel_vm_end; + stack_zero(st); + while (unwind_stack_one(state, 1) == 0) { + if (stack_put(st, state->registers[PC]) == -1) + break; + } +} -static void -stack_capture(struct stack *st, u_int32_t *frame) +void +stack_save(struct stack *st) { + struct unwind_state state; + uint32_t sp; + + /* Read the stack pointer */ + __asm __volatile("mov %0, sp" : "=&r" (sp)); + + state.registers[FP] = (uint32_t)__builtin_frame_address(0); + state.registers[SP] = sp; + state.registers[LR] = (uint32_t)__builtin_return_address(0); + state.registers[PC] = (uint32_t)stack_save; + + stack_capture(st, &state); } void stack_save_td(struct stack *st, struct thread *td) { - u_int32_t *frame; + struct unwind_state state; - if (TD_IS_SWAPPED(td)) - panic("stack_save_td: swapped"); - if (TD_IS_RUNNING(td)) - panic("stack_save_td: running"); + KASSERT(!TD_IS_SWAPPED(td), ("stack_save_td: swapped")); + KASSERT(!TD_IS_RUNNING(td), ("stack_save_td: running")); - /* - * This register, the frame pointer, is incorrect for the ARM EABI - * as it doesn't have a frame pointer, however it's value is not used - * when building for EABI. - */ - frame = (u_int32_t *)td->td_pcb->pcb_regs.sf_r11; - stack_zero(st); - stack_capture(st, frame); + state.registers[FP] = td->td_pcb->pcb_regs.sf_r11; + state.registers[SP] = td->td_pcb->pcb_regs.sf_sp; + state.registers[LR] = td->td_pcb->pcb_regs.sf_lr; + state.registers[PC] = td->td_pcb->pcb_regs.sf_pc; + + stack_capture(st, &state); } int stack_save_td_running(struct stack *st, struct thread *td) { + if (td == curthread) { + stack_save(st); + return (0); + } return (EOPNOTSUPP); -} - -void -stack_save(struct stack *st) -{ - u_int32_t *frame; - - frame = (u_int32_t *)__builtin_frame_address(0); - stack_zero(st); - stack_capture(st, frame); } Modified: head/sys/arm/conf/std.armv6 ============================================================================== --- head/sys/arm/conf/std.armv6 Thu Nov 14 16:28:02 2019 (r354708) +++ head/sys/arm/conf/std.armv6 Thu Nov 14 16:46:27 2019 (r354709) @@ -34,6 +34,7 @@ options GEOM_LABEL # Provides labelization options COMPAT_43 # Compatible with BSD 4.3 [KEEP THIS!] options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options KTRACE # ktrace(1) support +options STACK # stack(9) support options SYSVSHM # SYSV-style shared memory options SYSVMSG # SYSV-style message queues options SYSVSEM # SYSV-style semaphores Modified: head/sys/arm/conf/std.armv7 ============================================================================== --- head/sys/arm/conf/std.armv7 Thu Nov 14 16:28:02 2019 (r354708) +++ head/sys/arm/conf/std.armv7 Thu Nov 14 16:46:27 2019 (r354709) @@ -34,6 +34,7 @@ options GEOM_LABEL # Provides labelization options COMPAT_43 # Compatible with BSD 4.3 [KEEP THIS!] options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options KTRACE # ktrace(1) support +options STACK # stack(9) support options SYSVSHM # SYSV-style shared memory options SYSVMSG # SYSV-style message queues options SYSVSEM # SYSV-style semaphores