unwind.c revision 284257
1284257Sbr/*-
2284257Sbr * Copyright (c) 2015 The FreeBSD Foundation
3284257Sbr * All rights reserved.
4284257Sbr *
5284257Sbr * This software was developed by Semihalf under
6284257Sbr * the sponsorship of the FreeBSD Foundation.
7284257Sbr *
8284257Sbr * Redistribution and use in source and binary forms, with or without
9284257Sbr * modification, are permitted provided that the following conditions
10284257Sbr * are met:
11284257Sbr * 1. Redistributions of source code must retain the above copyright
12284257Sbr *    notice, this list of conditions and the following disclaimer.
13284257Sbr * 2. Redistributions in binary form must reproduce the above copyright
14284257Sbr *    notice, this list of conditions and the following disclaimer in the
15284257Sbr *    documentation and/or other materials provided with the distribution.
16284257Sbr *
17284257Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18284257Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19284257Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20284257Sbr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21284257Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22284257Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23284257Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24284257Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25284257Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26284257Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27284257Sbr * SUCH DAMAGE.
28284257Sbr */
29284257Sbr
30284257Sbr#include <sys/cdefs.h>
31284257Sbr__FBSDID("$FreeBSD: head/sys/arm64/arm64/unwind.c 284257 2015-06-11 12:47:13Z br $");
32284257Sbr#include <sys/param.h>
33284257Sbr
34284257Sbr#include <machine/stack.h>
35284257Sbr
36284257Sbrint
37284257Sbrunwind_frame(struct unwind_state *frame)
38284257Sbr{
39284257Sbr	uint64_t fp;
40284257Sbr
41284257Sbr	fp = frame->fp;
42284257Sbr	if (fp == 0)
43284257Sbr		return (-1);
44284257Sbr
45284257Sbr	frame->sp = fp + 0x10;
46284257Sbr	/* FP to previous frame (X29) */
47284257Sbr	frame->fp = *(uint64_t *)(fp);
48284257Sbr	/* LR (X30) */
49284257Sbr	frame->pc = *(uint64_t *)(fp + 8) - 4;
50284257Sbr
51284257Sbr	return (0);
52284257Sbr}
53