Index: head/sys/arm/arm/stack_machdep.c =================================================================== --- head/sys/arm/arm/stack_machdep.c (revision 354708) +++ head/sys/arm/arm/stack_machdep.c (revision 354709) @@ -1,91 +1,91 @@ /*- - * 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 * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #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); } Index: head/sys/arm/conf/std.armv6 =================================================================== --- head/sys/arm/conf/std.armv6 (revision 354708) +++ head/sys/arm/conf/std.armv6 (revision 354709) @@ -1,86 +1,87 @@ # Standard kernel config items for all ARMv6 systems. # # $FreeBSD$ options HZ=1000 options ARM_L2_PIPT # Only L2 PIPT is supported options INTRNG # All arm systems use INTRNG these days options PREEMPTION # Enable kernel thread preemption options VIMAGE # Subsystem virtualization, e.g. VNET options INET # InterNETworking options INET6 # IPv6 communications protocols options TCP_HHOOK # hhook(9) framework for TCP device crypto # core crypto support options IPSEC_SUPPORT # Allow kldload of ipsec and tcpmd5 options SCTP # Stream Control Transmission Protocol options FFS # Berkeley Fast Filesystem options SOFTUPDATES # Enable FFS soft updates support options UFS_ACL # Support for access control lists options UFS_DIRHASH # Improve performance on big directories options UFS_GJOURNAL # Enable gjournal-based UFS journaling options QUOTA # Enable disk quotas for UFS options NFSCL # Network Filesystem Client options NFSLOCKD # Network Lock Manager options NFS_ROOT # NFS usable as /, requires NFSCL options MSDOSFS # MSDOS Filesystem options CD9660 # ISO 9660 Filesystem options PROCFS # Process filesystem (requires PSEUDOFS) options PSEUDOFS # Pseudo-filesystem framework options TMPFS # Efficient memory filesystem options GEOM_PART_GPT # GUID Partition Tables options GEOM_PART_BSD # BSD partition scheme options GEOM_PART_MBR # MBR partition scheme 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 options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) options CAPABILITY_MODE # Capsicum capability mode options CAPABILITIES # Capsicum capabilites options FREEBSD_BOOT_LOADER # Process metadata passed from loader(8) options VFP # Enable floating point hardware support options MAC # Support for Mandatory Access Control (MAC) options COMPAT_FREEBSD10 # Compatible with FreeBSD10 options COMPAT_FREEBSD11 # Compatible with FreeBSD11 options COMPAT_FREEBSD12 # Compatible with FreeBSD12 # DTrace support options KDTRACE_HOOKS # Kernel DTrace hooks options DDB_CTF # all architectures - kernel ELF linker loads CTF data makeoptions WITH_CTF=1 # Debugging support. Always need this: makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols options KDB # Enable kernel debugger support. options KDB_TRACE # Print a stack trace for a panic. # For full debugger support use (turn off in stable branch): options DDB # Support DDB #options DEADLKRES # Enable the deadlock resolver options INVARIANTS # Enable calls of extra sanity checking options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS options WITNESS # Enable checks to detect deadlocks and cycles options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed options MALLOC_DEBUG_MAXZONES=8 # Separate malloc(9) zones options ALT_BREAK_TO_DEBUGGER # Enter debugger on keyboard escape sequence options USB_DEBUG # Enable usb debug support code options VERBOSE_SYSINIT=0 # Support debug.verbose_sysinit, off by default # Optional extras, never enabled by default: #options BOOTVERBOSE #options DEBUG # May result in extreme spewage #options KTR #options KTR_COMPILE=KTR_ALL #options KTR_ENTRIES=16384 #options KTR_MASK=(KTR_SPARE2) #options KTR_VERBOSE=0 #options USB_REQ_DEBUG #options USB_VERBOSE Index: head/sys/arm/conf/std.armv7 =================================================================== --- head/sys/arm/conf/std.armv7 (revision 354708) +++ head/sys/arm/conf/std.armv7 (revision 354709) @@ -1,85 +1,86 @@ # Standard kernel config items for all ARMv7 systems. # # $FreeBSD$ options HZ=1000 options ARM_L2_PIPT # Only L2 PIPT is supported options INTRNG # All arm systems use INTRNG these days options PREEMPTION # Enable kernel thread preemption options VIMAGE # Subsystem virtualization, e.g. VNET options INET # InterNETworking options INET6 # IPv6 communications protocols options TCP_HHOOK # hhook(9) framework for TCP device crypto # core crypto support options IPSEC_SUPPORT # Allow kldload of ipsec and tcpmd5 options SCTP # Stream Control Transmission Protocol options FFS # Berkeley Fast Filesystem options SOFTUPDATES # Enable FFS soft updates support options UFS_ACL # Support for access control lists options UFS_DIRHASH # Improve performance on big directories options UFS_GJOURNAL # Enable gjournal-based UFS journaling options QUOTA # Enable disk quotas for UFS options NFSCL # Network Filesystem Client options NFSLOCKD # Network Lock Manager options NFS_ROOT # NFS usable as /, requires NFSCL options MSDOSFS # MSDOS Filesystem options CD9660 # ISO 9660 Filesystem options PROCFS # Process filesystem (requires PSEUDOFS) options PSEUDOFS # Pseudo-filesystem framework options TMPFS # Efficient memory filesystem options GEOM_PART_GPT # GUID Partition Tables options GEOM_PART_BSD # BSD partition scheme options GEOM_PART_MBR # MBR partition scheme 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 options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) options CAPABILITY_MODE # Capsicum capability mode options CAPABILITIES # Capsicum capabilites options FREEBSD_BOOT_LOADER # Process metadata passed from loader(8) options VFP # Enable floating point hardware support options MAC # Support for Mandatory Access Control (MAC) options COMPAT_FREEBSD10 # Compatible with FreeBSD10 options COMPAT_FREEBSD11 # Compatible with FreeBSD11 options COMPAT_FREEBSD12 # Compatible with FreeBSD12 # DTrace support options KDTRACE_HOOKS # Kernel DTrace hooks options DDB_CTF # all architectures - kernel ELF linker loads CTF data makeoptions WITH_CTF=1 # Debugging support. Always need this: makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols options KDB # Enable kernel debugger support. options KDB_TRACE # Print a stack trace for a panic. # For full debugger support use (turn off in stable branch): options DDB # Support DDB #options DEADLKRES # Enable the deadlock resolver options INVARIANTS # Enable calls of extra sanity checking options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS options WITNESS # Enable checks to detect deadlocks and cycles options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed options MALLOC_DEBUG_MAXZONES=8 # Separate malloc(9) zones options ALT_BREAK_TO_DEBUGGER # Enter debugger on keyboard escape sequence options USB_DEBUG # Enable usb debug support code options VERBOSE_SYSINIT=0 # Support debug.verbose_sysinit, off by default # Optional extras, never enabled by default: #options BOOTVERBOSE #options DEBUG # May result in extreme spewage #options KTR #options KTR_COMPILE=KTR_ALL #options KTR_ENTRIES=16384 #options KTR_MASK=(KTR_SPARE2) #options KTR_VERBOSE=0 #options USB_REQ_DEBUG #options USB_VERBOSE