2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
5 * This software was developed by the University of Cambridge Computer
6 * Laboratory with support from ARM Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/param.h>
31 #include <sys/systm.h>
37 #include <machine/cpu.h>
38 #include <machine/md_var.h>
39 #include <machine/pmc_mdep.h>
40 #include <machine/stack.h>
41 #include <machine/vmparam.h>
44 pmc_md_initialize(void)
47 return (pmc_arm64_initialize());
51 pmc_md_finalize(struct pmc_mdep *md)
54 pmc_arm64_finalize(md);
58 pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, struct trapframe *tf)
60 struct unwind_state frame;
63 KASSERT(TRAPF_USERMODE(tf) == 0,("[arm64,%d] not a kernel backtrace",
66 frame.pc = PMC_TRAPFRAME_TO_PC(tf);
72 frame.fp = PMC_TRAPFRAME_TO_FP(tf);
73 if (!PMC_IN_KERNEL(frame.pc) || !PMC_IN_KERNEL_STACK(frame.fp))
76 for (count = 1; count < maxsamples; count++) {
77 if (!unwind_frame(curthread, &frame))
79 if (!PMC_IN_KERNEL(frame.pc))
88 pmc_save_user_callchain(uintptr_t *cc, int maxsamples,
91 uintptr_t pc, r, oldfp, fp;
94 KASSERT(TRAPF_USERMODE(tf), ("[arm64,%d] Not a user trap frame tf=%p",
95 __LINE__, (void *) tf));
97 pc = PMC_TRAPFRAME_TO_PC(tf);
103 oldfp = fp = PMC_TRAPFRAME_TO_FP(tf);
105 if (!PMC_IN_USERSPACE(pc) ||
106 !PMC_IN_USERSPACE(fp))
109 for (count = 1; count < maxsamples; count++) {
110 /* Use saved lr as pc. */
111 r = fp + sizeof(uintptr_t);
112 if (copyin((void *)r, &pc, sizeof(pc)) != 0)
114 if (!PMC_IN_USERSPACE(pc))
119 /* Switch to next frame up */
122 if (copyin((void *)r, &fp, sizeof(fp)) != 0)
124 if (fp < oldfp || !PMC_IN_USERSPACE(fp))