17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
2533f5ff17SMilan Jurik  * Copyright 2012 Milan Jurik. All rights reserved.
26*e1fb6a07SPatrick Mooney  * Copyright 2020 Oxide Computer Company
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * interface used by unwind support to query frame descriptor info
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef _LIBCRUN_
347257d1b4Sraf #include "lint.h"
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include "stack_unwind.h"
387c478bd9Sstevel@tonic-gate #include "unwind_context.h"
397c478bd9Sstevel@tonic-gate #include "reg_num.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate enum CFA_ops {
427c478bd9Sstevel@tonic-gate 	DW_CFA_nop = 0x00,
437c478bd9Sstevel@tonic-gate 	DW_CFA_set_loc = 0x01,
447c478bd9Sstevel@tonic-gate 	DW_CFA_advance_loc1 = 0x02,
457c478bd9Sstevel@tonic-gate 	DW_CFA_advance_loc2 = 0x03,
467c478bd9Sstevel@tonic-gate 	DW_CFA_advance_loc4 = 0x04,
477c478bd9Sstevel@tonic-gate 	DW_CFA_offset_extended = 0x05,
487c478bd9Sstevel@tonic-gate 	DW_CFA_restore_extended = 0x06,
497c478bd9Sstevel@tonic-gate 	DW_CFA_undefined = 0x07,
507c478bd9Sstevel@tonic-gate 	DW_CFA_same_value = 0x08,
517c478bd9Sstevel@tonic-gate 	DW_CFA_register = 0x09,
527c478bd9Sstevel@tonic-gate 	DW_CFA_remember_state = 0x0a,
537c478bd9Sstevel@tonic-gate 	DW_CFA_restore_state = 0x0b,
547c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa = 0x0c,
557c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa_register = 0x0d,
567c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa_offset = 0x0e,
577c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa_expression = 0x0f,
587c478bd9Sstevel@tonic-gate 	DW_CFA_expression = 0x10,
597c478bd9Sstevel@tonic-gate 	DW_CFA_offset_extended_sf = 0x11,
607c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa_sf = 0x12,
617c478bd9Sstevel@tonic-gate 	DW_CFA_def_cfa_offset_sf = 0x13,
627c478bd9Sstevel@tonic-gate 	/* skip 9 values */
637c478bd9Sstevel@tonic-gate 	DW_CFA_SUNW_advance_loc = 0x1d,
647c478bd9Sstevel@tonic-gate 	DW_CFA_SUNW_offset = 0x1e,
657c478bd9Sstevel@tonic-gate 	DW_CFA_SUNW_restore = 0x1f,
667c478bd9Sstevel@tonic-gate 	DW_CFA_advance_loc = 0x40,
677c478bd9Sstevel@tonic-gate 	DW_CFA_offset = 0x80,
687c478bd9Sstevel@tonic-gate 	DW_CFA_restore = 0xc0
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate struct operation_desc {
727c478bd9Sstevel@tonic-gate 	enum operand_desc op1;
737c478bd9Sstevel@tonic-gate 	enum operand_desc op2;
747c478bd9Sstevel@tonic-gate };
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate struct operation_desc cfa_operations[] = {
777c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},	/* DW_CFA_nop */
787c478bd9Sstevel@tonic-gate 	{ADDR, NO_OPR},		/* DW_CFA_set_loc - address */
797c478bd9Sstevel@tonic-gate 	{UNUM8, NO_OPR},	/* DW_CFA_advance_loc1 - delta */
807c478bd9Sstevel@tonic-gate 	{UNUM16, NO_OPR},	/* DW_CFA_advance_loc2 - delta */
817c478bd9Sstevel@tonic-gate 	{UNUM32, NO_OPR},	/* DW_CFA_advance_loc4 - delta */
827c478bd9Sstevel@tonic-gate 	{ULEB128, ULEB128_FAC},	/* DW_CFA_offset_extended - reg, */
837c478bd9Sstevel@tonic-gate 				/* data factored offset */
847c478bd9Sstevel@tonic-gate 	{ULEB128, NO_OPR},	/* DW_CFA_restore_extended - register */
857c478bd9Sstevel@tonic-gate 	{ULEB128, NO_OPR},	/* DW_CFA_undefined - register */
867c478bd9Sstevel@tonic-gate 	{ULEB128, NO_OPR},	/* DW_CFA_same_value - register */
877c478bd9Sstevel@tonic-gate 	{ULEB128, ULEB128_SREG}, /* DW_CFA_register - register, register */
887c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},	/* DW_CFA_remember_state */
897c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},	/* DW_CFA_restore_state */
907c478bd9Sstevel@tonic-gate 	{ULEB128_SREG, ULEB128}, /* DW_CFA_def_cfa - register, offset */
917c478bd9Sstevel@tonic-gate 	{ULEB128_SREG, NO_OPR},	/* DW_CFA_def_cfa_register - register */
927c478bd9Sstevel@tonic-gate 	{ULEB128, NO_OPR},	/* DW_CFA_def_cfa_offset - offset */
937c478bd9Sstevel@tonic-gate 	{BLOCK, NO_OPR},	/* DW_CFA_def_cfa_expression - expression */
947c478bd9Sstevel@tonic-gate 	{ULEB128, BLOCK},	/* DW_CFA_expression - reg, expression */
957c478bd9Sstevel@tonic-gate 	{ULEB128, SLEB128_FAC},	/* DW_CFA_offset_extended_sf - reg, */
967c478bd9Sstevel@tonic-gate 				/* data factored offset */
977c478bd9Sstevel@tonic-gate 	{ULEB128_SREG, SLEB128_FAC},	/* DW_CFA_def_cfa_sf - reg, */
987c478bd9Sstevel@tonic-gate 					/* data factored offset */
997c478bd9Sstevel@tonic-gate 	{SLEB128_FAC, NO_OPR},	/* DW_CFA_def_cfa_offset_sf - */
1007c478bd9Sstevel@tonic-gate 				/* data fctored offset */
1017c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1027c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1037c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1047c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1057c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1067c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1077c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1087c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1097c478bd9Sstevel@tonic-gate 	{NO_OPR, NO_OPR},
1107c478bd9Sstevel@tonic-gate 	{UNUM6_CFAC, NO_OPR},	/* DW_CFA_SUNW_advance_loc - */
1117c478bd9Sstevel@tonic-gate 				/* code factored delta */
1127c478bd9Sstevel@tonic-gate 	{UNUM6, ULEB128_FAC},	/* DW_CFA_SUNW_offset - reg */
1137c478bd9Sstevel@tonic-gate 				/* data factored offset */
1147c478bd9Sstevel@tonic-gate 	{UNUM6, NO_OPR}		/* DW_CFA_SUNW_restore */
1157c478bd9Sstevel@tonic-gate };
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate uint64_t interpret_ops(void *data, void *data_end,
1187c478bd9Sstevel@tonic-gate 		ptrdiff_t reloc, uint64_t current_loc, uint64_t pc,
1197c478bd9Sstevel@tonic-gate 		struct register_state f_state[],
1207c478bd9Sstevel@tonic-gate 		struct register_state f_start_state[],
1217c478bd9Sstevel@tonic-gate 		int daf, int caf, int enc);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * The entry-point state of old_ctx defines the current
1257c478bd9Sstevel@tonic-gate  * suspended state of the caller (in new_ctx). If the old info
1267c478bd9Sstevel@tonic-gate  * will not be refered to again, old_ctx == new_ctx is OK
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate void
_Unw_Propagate_Registers(struct _Unwind_Context * old_ctx,struct _Unwind_Context * new_ctx)1297c478bd9Sstevel@tonic-gate _Unw_Propagate_Registers(struct _Unwind_Context *old_ctx,
1307c478bd9Sstevel@tonic-gate 	struct _Unwind_Context *new_ctx)
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[SP_RSP] = old_ctx->cfa;
1337c478bd9Sstevel@tonic-gate 	new_ctx->pc = old_ctx->ra;
1347c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[FP_RBP] = old_ctx->entry_regs[FP_RBP];
1357c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[GPR_RBX] = old_ctx->entry_regs[GPR_RBX];
1367c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[EIR_R12] = old_ctx->entry_regs[EIR_R12];
1377c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[EIR_R13] = old_ctx->entry_regs[EIR_R13];
1387c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[EIR_R14] = old_ctx->entry_regs[EIR_R14];
1397c478bd9Sstevel@tonic-gate 	new_ctx->current_regs[EIR_R15] = old_ctx->entry_regs[EIR_R15];
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate void
fix_cfa(struct _Unwind_Context * ctx,struct register_state * rs)1437c478bd9Sstevel@tonic-gate fix_cfa(struct _Unwind_Context *ctx, struct register_state *rs)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	switch (rs[CF_ADDR].rule) {
1467c478bd9Sstevel@tonic-gate 	default:
1477257d1b4Sraf 		ctx->cfa = 0;
1487c478bd9Sstevel@tonic-gate 		break;
1497c478bd9Sstevel@tonic-gate 	case register_rule:	/* CFA = offset + source_reg */
1507c478bd9Sstevel@tonic-gate 		ctx->cfa = (ctx->current_regs)[rs[CF_ADDR].source_reg] +
1517257d1b4Sraf 		    rs[CF_ADDR].offset;
1527c478bd9Sstevel@tonic-gate 		break;
1537c478bd9Sstevel@tonic-gate 	case constant_rule:	/* CFA = offset */
1547c478bd9Sstevel@tonic-gate 		ctx->cfa = rs[CF_ADDR].offset;
1557c478bd9Sstevel@tonic-gate 		break;
1567c478bd9Sstevel@tonic-gate 	case indirect_rule:	/* CFA = *(offset + source_reg) */
1577c478bd9Sstevel@tonic-gate 		ctx->cfa = *(uint64_t *)
1587257d1b4Sraf 		    (ctx->current_regs[rs[CF_ADDR].source_reg] +
1597257d1b4Sraf 		    rs[CF_ADDR].offset);
1607c478bd9Sstevel@tonic-gate 		break;
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 	ctx->entry_regs[SP_RSP] = ctx->cfa;
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate void
fix_ra(struct _Unwind_Context * ctx,struct register_state * rs)1667c478bd9Sstevel@tonic-gate fix_ra(struct _Unwind_Context *ctx, struct register_state *rs)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	switch (rs[RET_ADD].rule) {
1697c478bd9Sstevel@tonic-gate 	case undefined_rule:
1707c478bd9Sstevel@tonic-gate 	default:
1717257d1b4Sraf 		ctx->ra = 0;
1727c478bd9Sstevel@tonic-gate 		break;
1737c478bd9Sstevel@tonic-gate 	case offset_rule:	/* RA = *(offset + CFA) */
1747c478bd9Sstevel@tonic-gate 		ctx->ra = *(uint64_t *)(ctx->cfa + rs[RET_ADD].offset);
1757c478bd9Sstevel@tonic-gate 		break;
1767c478bd9Sstevel@tonic-gate 	case register_rule:	/* RA = offset + source_reg */
1777c478bd9Sstevel@tonic-gate 		ctx->ra = ctx->current_regs[rs[RET_ADD].source_reg] +
1787257d1b4Sraf 		    rs[RET_ADD].offset;
1797c478bd9Sstevel@tonic-gate 		break;
1807c478bd9Sstevel@tonic-gate 	case indirect_rule:	/* RA = *(offset + source_reg) */
1817c478bd9Sstevel@tonic-gate 		ctx->ra = *(uint64_t *)
1827257d1b4Sraf 		    (ctx->current_regs[rs[RET_ADD].source_reg] +
1837257d1b4Sraf 		    rs[RET_ADD].offset);
1847c478bd9Sstevel@tonic-gate 		break;
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate void
fix_reg(struct _Unwind_Context * ctx,struct register_state * rs,int index)1897c478bd9Sstevel@tonic-gate fix_reg(struct _Unwind_Context *ctx, struct register_state *rs, int index)
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate 	switch (rs[index].rule) {
1927c478bd9Sstevel@tonic-gate 	default:
1937c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] = ctx->current_regs[index];
1947c478bd9Sstevel@tonic-gate 		break;
1957c478bd9Sstevel@tonic-gate 	case offset_rule:	/* target_reg = *(offset + CFA) */
1967c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] = *(uint64_t *)
1977257d1b4Sraf 		    (ctx->cfa + rs[index].offset);
1987c478bd9Sstevel@tonic-gate 		break;
1997c478bd9Sstevel@tonic-gate 	case is_offset_rule:	/* target_reg = offset + CFA */
2007c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] = ctx->cfa + rs[index].offset;
2017c478bd9Sstevel@tonic-gate 		break;
2027c478bd9Sstevel@tonic-gate 	case register_rule:	/* target_reg = offset + source_reg */
2037c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] =
2047257d1b4Sraf 		    ctx->current_regs[rs[index].source_reg] +
2057257d1b4Sraf 		    rs[index].offset;
2067c478bd9Sstevel@tonic-gate 		break;
2077c478bd9Sstevel@tonic-gate 	case constant_rule:	/* target_reg = offset */
2087c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] = rs[index].offset;
2097c478bd9Sstevel@tonic-gate 		break;
2107c478bd9Sstevel@tonic-gate 	case indirect_rule:	/* target_reg = *(offset + source_reg) */
2117c478bd9Sstevel@tonic-gate 		ctx->entry_regs[index] = *(uint64_t *)
2127257d1b4Sraf 		    (ctx->current_regs[rs[index].source_reg] +
2137257d1b4Sraf 		    rs[index].offset);
2147c478bd9Sstevel@tonic-gate 		break;
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate }
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * Input: f->{cie_ops, cie_ops_end, fde_ops, fde_ops_end}
2217c478bd9Sstevel@tonic-gate  *			+ location of DWARF opcodes
2227c478bd9Sstevel@tonic-gate  *		  ctx->{current_regs, pc}
2237c478bd9Sstevel@tonic-gate  *			+ register values and pc at point of suspension
2247c478bd9Sstevel@tonic-gate  * Output: ctx->{entry_regs, cfa, ra}
2257c478bd9Sstevel@tonic-gate  *			+ register values when function was entered
2267c478bd9Sstevel@tonic-gate  *			+ Cannonical Frame Address
2277c478bd9Sstevel@tonic-gate  *			+ return address
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate uint64_t
_Unw_Rollback_Registers(struct eh_frame_fields * f,struct _Unwind_Context * ctx)2307c478bd9Sstevel@tonic-gate _Unw_Rollback_Registers(struct eh_frame_fields *f,
2317c478bd9Sstevel@tonic-gate 	struct _Unwind_Context *ctx)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	/* GPRs, RET_ADD, and CF_ADDR */
2347c478bd9Sstevel@tonic-gate 	struct register_state func_state[18];
2357c478bd9Sstevel@tonic-gate 	struct register_state func_start_state[18];
2367c478bd9Sstevel@tonic-gate 	struct register_state nop = { 0, undefined_rule, 0 };
2377c478bd9Sstevel@tonic-gate 	int i;
2387c478bd9Sstevel@tonic-gate 	uint64_t  first_pc;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	if (f == 0) {
2417c478bd9Sstevel@tonic-gate 		/*
2427c478bd9Sstevel@tonic-gate 		 * When no FDE we assume all routines have a frame pointer
2437c478bd9Sstevel@tonic-gate 		 * and pass back existing callee saves registers
2447c478bd9Sstevel@tonic-gate 		 */
2457c478bd9Sstevel@tonic-gate 		if (ctx->current_regs[FP_RBP] < ctx->current_regs[SP_RSP]) {
2467c478bd9Sstevel@tonic-gate 			ctx->cfa = 0;
2477c478bd9Sstevel@tonic-gate 			ctx->ra = 0;
2487c478bd9Sstevel@tonic-gate 			ctx->pc = 0;
2497c478bd9Sstevel@tonic-gate 			return (0);
2507c478bd9Sstevel@tonic-gate 		}
2517c478bd9Sstevel@tonic-gate 		ctx->entry_regs[FP_RBP] = ((uint64_t *)
2527257d1b4Sraf 		    (ctx->current_regs[FP_RBP]))[0];
2537c478bd9Sstevel@tonic-gate 		ctx->cfa = ctx->current_regs[FP_RBP] + 16;
2547c478bd9Sstevel@tonic-gate 		ctx->entry_regs[SP_RSP] = ctx->cfa;
2557c478bd9Sstevel@tonic-gate 		ctx->entry_regs[GPR_RBX] = ctx->current_regs[GPR_RBX];
2567c478bd9Sstevel@tonic-gate 		ctx->entry_regs[EIR_R12] = ctx->current_regs[EIR_R12];
2577c478bd9Sstevel@tonic-gate 		ctx->entry_regs[EIR_R13] = ctx->current_regs[EIR_R13];
2587c478bd9Sstevel@tonic-gate 		ctx->entry_regs[EIR_R14] = ctx->current_regs[EIR_R14];
2597c478bd9Sstevel@tonic-gate 		ctx->entry_regs[EIR_R15] = ctx->current_regs[EIR_R15];
2607c478bd9Sstevel@tonic-gate 		ctx->ra = ((uint64_t *)ctx->cfa)[-1];
2617c478bd9Sstevel@tonic-gate 		return (ctx->cfa);
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	for (i = 0; i < 18; i++)
2657c478bd9Sstevel@tonic-gate 		func_start_state[i] = nop;
2667c478bd9Sstevel@tonic-gate 	first_pc = interpret_ops(f->cie_ops, f->cie_ops_end,
2677257d1b4Sraf 	    f->cie_reloc, ctx->func, ctx->pc, func_start_state, 0,
2687257d1b4Sraf 	    f->data_align, f->code_align, f->code_enc);
2697c478bd9Sstevel@tonic-gate 	for (i = 0; i < 18; i++)
2707c478bd9Sstevel@tonic-gate 		func_state[i] = func_start_state[i];
2717c478bd9Sstevel@tonic-gate 	(void) interpret_ops(f->fde_ops, f->fde_ops_end,
2727257d1b4Sraf 	    f->fde_reloc, first_pc, ctx->pc, func_state, func_start_state,
2737257d1b4Sraf 	    f->data_align, f->code_align, f->code_enc);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	fix_cfa(ctx, func_state);
2767c478bd9Sstevel@tonic-gate 	if (ctx->cfa < ctx->current_regs[SP_RSP]) {
2777c478bd9Sstevel@tonic-gate 		ctx->cfa = 0;
2787c478bd9Sstevel@tonic-gate 		ctx->ra = 0;
2797c478bd9Sstevel@tonic-gate 		ctx->pc = 0;
2807c478bd9Sstevel@tonic-gate 		return (0);
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 	fix_ra(ctx, func_state);
2837c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, GPR_RBX);
2847c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, FP_RBP);
2857c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, EIR_R12);
2867c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, EIR_R13);
2877c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, EIR_R14);
2887c478bd9Sstevel@tonic-gate 	fix_reg(ctx, func_state, EIR_R15);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	return (ctx->cfa);
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  * remap two-bit opcodes into a separate range or grab eight-bit opcode
2957c478bd9Sstevel@tonic-gate  * and advance pointer past it.
2967c478bd9Sstevel@tonic-gate  */
2977c478bd9Sstevel@tonic-gate static enum CFA_ops
separate_op(void ** pp)2987c478bd9Sstevel@tonic-gate separate_op(void **pp)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate 	uint8_t c = **((uint8_t **)pp);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	if (c & 0xc0) {
3037c478bd9Sstevel@tonic-gate 		switch (c & 0xc0) {
3047c478bd9Sstevel@tonic-gate 		case DW_CFA_advance_loc:
3057c478bd9Sstevel@tonic-gate 			return (DW_CFA_SUNW_advance_loc);
3067c478bd9Sstevel@tonic-gate 		case DW_CFA_offset:
3077c478bd9Sstevel@tonic-gate 			return (DW_CFA_SUNW_offset);
3087c478bd9Sstevel@tonic-gate 		case DW_CFA_restore:
3097c478bd9Sstevel@tonic-gate 			return (DW_CFA_SUNW_restore);
3107c478bd9Sstevel@tonic-gate 		}
3117c478bd9Sstevel@tonic-gate 	} else {
3127c478bd9Sstevel@tonic-gate 		*pp = (void *)((*(intptr_t *)pp) + 1);
3137c478bd9Sstevel@tonic-gate 	}
3147c478bd9Sstevel@tonic-gate 	return (c);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate static uint64_t
extractuleb(void ** datap)3187c478bd9Sstevel@tonic-gate extractuleb(void **datap)
3197c478bd9Sstevel@tonic-gate {
3207c478bd9Sstevel@tonic-gate 	uint8_t *data = *(uint8_t **)datap;
3217c478bd9Sstevel@tonic-gate 	uint64_t res = 0;
3227c478bd9Sstevel@tonic-gate 	int more = 1;
3237c478bd9Sstevel@tonic-gate 	int shift = 0;
3247c478bd9Sstevel@tonic-gate 	int val;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	while (more) {
3277c478bd9Sstevel@tonic-gate 		val = (*data) & 0x7f;
3287c478bd9Sstevel@tonic-gate 		more = ((*data++) & 0x80) >> 7;
3297c478bd9Sstevel@tonic-gate 		res = res | val << shift;
3307c478bd9Sstevel@tonic-gate 		shift += 7;
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	*datap = (void *)data;
3337c478bd9Sstevel@tonic-gate 	return (res);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate static uint64_t
extractsleb(void ** datap)3377c478bd9Sstevel@tonic-gate extractsleb(void** datap)
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate 	uint8_t *data = *datap;
3407c478bd9Sstevel@tonic-gate 	int64_t res = 0;
3417c478bd9Sstevel@tonic-gate 	int more = 1;
3427c478bd9Sstevel@tonic-gate 	int shift = 0;
3437c478bd9Sstevel@tonic-gate 	unsigned int val;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	while (more) {
3467c478bd9Sstevel@tonic-gate 		val = (*data) & 0x7f;
3477c478bd9Sstevel@tonic-gate 		more = ((*data++) & 0x80) >> 7;
3487c478bd9Sstevel@tonic-gate 		res = res | val<< shift;
3497c478bd9Sstevel@tonic-gate 		shift += 7;
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate 	*datap = (void*) data;
3527c478bd9Sstevel@tonic-gate 	res = (res << (64 - shift)) >> (64 - shift);
3537c478bd9Sstevel@tonic-gate 	return (res);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate static uint64_t get_encoded_val(void **datap, ptrdiff_t reloc, int enc);
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate  * do all field extractions needed for CFA operands and encoded FDE
3607c478bd9Sstevel@tonic-gate  * fields
3617c478bd9Sstevel@tonic-gate  */
3627c478bd9Sstevel@tonic-gate uint64_t
_Unw_get_val(void ** datap,ptrdiff_t reloc,enum operand_desc opr,int daf,int caf,int enc)3637c478bd9Sstevel@tonic-gate _Unw_get_val(void **datap, ptrdiff_t reloc,
3647c478bd9Sstevel@tonic-gate 	enum operand_desc opr, int daf, int caf, int enc)
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate 	intptr_t data = (intptr_t)*datap;
3677c478bd9Sstevel@tonic-gate 	uint64_t res;
3687c478bd9Sstevel@tonic-gate 	char *dp, *rp;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	switch (opr) {
3717c478bd9Sstevel@tonic-gate 	case NO_OPR:
3727c478bd9Sstevel@tonic-gate 		res = 0;
3737c478bd9Sstevel@tonic-gate 		break;
3747c478bd9Sstevel@tonic-gate 	case ULEB128_FAC:
3757c478bd9Sstevel@tonic-gate 		return (daf * extractuleb(datap));
3767c478bd9Sstevel@tonic-gate 	case ULEB128:
3777c478bd9Sstevel@tonic-gate 		return (extractuleb(datap));
3787c478bd9Sstevel@tonic-gate 	case ULEB128_SREG:
3797c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((uint8_t *)data));
3807c478bd9Sstevel@tonic-gate 		data += 1;
3817c478bd9Sstevel@tonic-gate 		switch (res) {
3827c478bd9Sstevel@tonic-gate 			/* verify that register is one which is being tracked */
3837c478bd9Sstevel@tonic-gate 		case GPR_RBX:
3847c478bd9Sstevel@tonic-gate 		case FP_RBP:
3857c478bd9Sstevel@tonic-gate 		case SP_RSP:
3867c478bd9Sstevel@tonic-gate 		case EIR_R12:
3877c478bd9Sstevel@tonic-gate 		case EIR_R13:
3887c478bd9Sstevel@tonic-gate 		case EIR_R14:
3897c478bd9Sstevel@tonic-gate 		case EIR_R15:
3907c478bd9Sstevel@tonic-gate 			break;
3917c478bd9Sstevel@tonic-gate 		default:
3927c478bd9Sstevel@tonic-gate 			res = BAD_REG;
3937c478bd9Sstevel@tonic-gate 			break;
3947c478bd9Sstevel@tonic-gate 		}
3957c478bd9Sstevel@tonic-gate 		break;
3967c478bd9Sstevel@tonic-gate 	case UNUM6:
3977c478bd9Sstevel@tonic-gate 		res = (uint64_t)(0x3f & *((uint8_t *)data));
3987c478bd9Sstevel@tonic-gate 		data += 1;
3997c478bd9Sstevel@tonic-gate 		break;
4007c478bd9Sstevel@tonic-gate 	case UNUM8:
4017c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((uint8_t *)data));
4027c478bd9Sstevel@tonic-gate 		data += 1;
4037c478bd9Sstevel@tonic-gate 		break;
4047c478bd9Sstevel@tonic-gate 	case UNUM16:
4057c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((uint16_t *)data));
4067c478bd9Sstevel@tonic-gate 		data += 2;
4077c478bd9Sstevel@tonic-gate 		break;
4087c478bd9Sstevel@tonic-gate 	case UNUM32:
4097c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((uint32_t *)data));
4107c478bd9Sstevel@tonic-gate 		data += 4;
4117c478bd9Sstevel@tonic-gate 		break;
4127c478bd9Sstevel@tonic-gate 	case UNUM6_CFAC:
4137c478bd9Sstevel@tonic-gate 		res = caf * (uint64_t)(0x3f & *((uint8_t *)data));
4147c478bd9Sstevel@tonic-gate 		data += 1;
4157c478bd9Sstevel@tonic-gate 		break;
4167c478bd9Sstevel@tonic-gate 	case UNUM8_CFAC:
4177c478bd9Sstevel@tonic-gate 		res = caf * (uint64_t)(*((uint8_t *)data));
4187c478bd9Sstevel@tonic-gate 		data += 1;
4197c478bd9Sstevel@tonic-gate 		break;
4207c478bd9Sstevel@tonic-gate 	case UNUM16_CFAC:
4217c478bd9Sstevel@tonic-gate 		res = caf * (uint64_t)(*((uint16_t *)data));
4227c478bd9Sstevel@tonic-gate 		data += 2;
4237c478bd9Sstevel@tonic-gate 		break;
4247c478bd9Sstevel@tonic-gate 	case UNUM32_CFAC:
4257c478bd9Sstevel@tonic-gate 		res = caf * (uint64_t)(*((uint32_t *)data));
4267c478bd9Sstevel@tonic-gate 		data += 4;
4277c478bd9Sstevel@tonic-gate 		break;
4287c478bd9Sstevel@tonic-gate 	case UNUM64:
4297c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((uint64_t *)data));
4307c478bd9Sstevel@tonic-gate 		data += 8;
4317c478bd9Sstevel@tonic-gate 		break;
4327c478bd9Sstevel@tonic-gate 	case SNUM8:
4337c478bd9Sstevel@tonic-gate 		res = (uint64_t)(int64_t)(*((int8_t *)data));
4347c478bd9Sstevel@tonic-gate 		data += 1;
4357c478bd9Sstevel@tonic-gate 		break;
4367c478bd9Sstevel@tonic-gate 	case SNUM16:
4377c478bd9Sstevel@tonic-gate 		res = (uint64_t)(int64_t)(*((int16_t *)data));
4387c478bd9Sstevel@tonic-gate 		data += 2;
4397c478bd9Sstevel@tonic-gate 		break;
4407c478bd9Sstevel@tonic-gate 	case SNUM32:
4417c478bd9Sstevel@tonic-gate 		res = (uint64_t)(int64_t)(*((int32_t *)data));
4427c478bd9Sstevel@tonic-gate 		data += 4;
4437c478bd9Sstevel@tonic-gate 		break;
4447c478bd9Sstevel@tonic-gate 	case SNUM64:
4457c478bd9Sstevel@tonic-gate 		res = (uint64_t)(*((int64_t *)data));
4467c478bd9Sstevel@tonic-gate 		data += 8;
4477c478bd9Sstevel@tonic-gate 		break;
4487c478bd9Sstevel@tonic-gate 	case SLEB128_FAC:
4497c478bd9Sstevel@tonic-gate 		return (daf * extractsleb(datap));
4507c478bd9Sstevel@tonic-gate 	case SLEB128:
4517c478bd9Sstevel@tonic-gate 		return (extractsleb(datap));
4527c478bd9Sstevel@tonic-gate 	case ZTSTRING:
4537c478bd9Sstevel@tonic-gate 		/* max length of augmentation string is 4 */
4547c478bd9Sstevel@tonic-gate 		rp = (char *)&res;
4557c478bd9Sstevel@tonic-gate 		dp = (char *)data;
4567c478bd9Sstevel@tonic-gate 		while (*rp++ = *dp++)
4577c478bd9Sstevel@tonic-gate 			;
4587c478bd9Sstevel@tonic-gate 		data = (intptr_t)dp;
4597c478bd9Sstevel@tonic-gate 		break;
4607c478bd9Sstevel@tonic-gate 	case ADDR:
4617c478bd9Sstevel@tonic-gate 		return (get_encoded_val(datap, reloc, enc));
4627c478bd9Sstevel@tonic-gate 	case SIZE:
4637c478bd9Sstevel@tonic-gate 		return (get_encoded_val(datap, reloc, enc & 0x7));
4647c478bd9Sstevel@tonic-gate 	case BLOCK:
4657c478bd9Sstevel@tonic-gate 		res = 0;  /* not implemented */
4667c478bd9Sstevel@tonic-gate 		break;
4677c478bd9Sstevel@tonic-gate 	}
4687c478bd9Sstevel@tonic-gate 	*datap = (void*)data;
4697c478bd9Sstevel@tonic-gate 	return (res);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate static uint64_t
get_encoded_val(void ** datap,ptrdiff_t reloc,int enc)4737c478bd9Sstevel@tonic-gate get_encoded_val(void **datap, ptrdiff_t reloc, int enc)
4747c478bd9Sstevel@tonic-gate {
475*e1fb6a07SPatrick Mooney 	const uint8_t val = enc & 0xf;
476*e1fb6a07SPatrick Mooney 	const uint8_t rel = enc & 0x70;
477*e1fb6a07SPatrick Mooney 	const boolean_t indirect = (enc & 0x80) != 0;
4787c478bd9Sstevel@tonic-gate 	intptr_t loc = ((intptr_t)*datap) + reloc;
4797c478bd9Sstevel@tonic-gate 	uint64_t res = 0;
4807c478bd9Sstevel@tonic-gate 
481*e1fb6a07SPatrick Mooney 	/*
482*e1fb6a07SPatrick Mooney 	 * Calculate the offset represented by the pointer encoding.  These
483*e1fb6a07SPatrick Mooney 	 * DWARF extensions are defined in the Core Generic document set of the
484*e1fb6a07SPatrick Mooney 	 * LSB specification.
485*e1fb6a07SPatrick Mooney 	 */
4867c478bd9Sstevel@tonic-gate 	switch (val) {
4877c478bd9Sstevel@tonic-gate 	case 0x01:
4887c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, ULEB128, 1, 1, 0);
4897c478bd9Sstevel@tonic-gate 		break;
490*e1fb6a07SPatrick Mooney 	case 0x02:
4917c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, UNUM16, 1, 1, 0);
4927c478bd9Sstevel@tonic-gate 		break;
493*e1fb6a07SPatrick Mooney 	case 0x03:
4947c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, UNUM32, 1, 1, 0);
4957c478bd9Sstevel@tonic-gate 		break;
4967c478bd9Sstevel@tonic-gate 	case 0x04:
4977c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, UNUM64, 1, 1, 0);
4987c478bd9Sstevel@tonic-gate 		break;
4997c478bd9Sstevel@tonic-gate 	case 0x09:
5007c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, SLEB128, 1, 1, 0);
5017c478bd9Sstevel@tonic-gate 		break;
5027c478bd9Sstevel@tonic-gate 	case 0x0a:
5037c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, SNUM16, 1, 1, 0);
5047c478bd9Sstevel@tonic-gate 		break;
5057c478bd9Sstevel@tonic-gate 	case 0x0b:
5067c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, SNUM32, 1, 1, 0);
5077c478bd9Sstevel@tonic-gate 		break;
5087c478bd9Sstevel@tonic-gate 	case 0x0c:
5097c478bd9Sstevel@tonic-gate 		res = _Unw_get_val(datap, reloc, SNUM64, 1, 1, 0);
5107c478bd9Sstevel@tonic-gate 		break;
5117c478bd9Sstevel@tonic-gate 	}
5127c478bd9Sstevel@tonic-gate 	switch (rel) {
513*e1fb6a07SPatrick Mooney 	case 0x00:
5147c478bd9Sstevel@tonic-gate 		break;
515*e1fb6a07SPatrick Mooney 	case 0x10:
516*e1fb6a07SPatrick Mooney 		/* DW_EH_PE_pcrel */
5177c478bd9Sstevel@tonic-gate 		if (res != 0)
5187c478bd9Sstevel@tonic-gate 			res += loc;
5197c478bd9Sstevel@tonic-gate 		break;
5207c478bd9Sstevel@tonic-gate 	default:
5217c478bd9Sstevel@tonic-gate 		/* remainder not implemented */
5227c478bd9Sstevel@tonic-gate 		break;
5237c478bd9Sstevel@tonic-gate 	}
524*e1fb6a07SPatrick Mooney 
525*e1fb6a07SPatrick Mooney 	/*
526*e1fb6a07SPatrick Mooney 	 * The high bit of the pointer encoding (DW_EH_PE_indirect = 0x80)
527*e1fb6a07SPatrick Mooney 	 * indicates that a pointer-sized value should be read from the
528*e1fb6a07SPatrick Mooney 	 * calculated address as the final result.
529*e1fb6a07SPatrick Mooney 	 *
530*e1fb6a07SPatrick Mooney 	 * Shockingly, this is not documented in any specification to date, but
531*e1fb6a07SPatrick Mooney 	 * has been implemented in various unwind implementations through
532*e1fb6a07SPatrick Mooney 	 * reverse-engineering of GCC.
533*e1fb6a07SPatrick Mooney 	 */
534*e1fb6a07SPatrick Mooney 	if (indirect) {
535*e1fb6a07SPatrick Mooney 		void *addr = (void *)(uintptr_t)res;
536*e1fb6a07SPatrick Mooney 
537*e1fb6a07SPatrick Mooney 		/*
538*e1fb6a07SPatrick Mooney 		 * Built only for amd64, we can count on a 64-bit pointer size
539*e1fb6a07SPatrick Mooney 		 * for the indirect handling.
540*e1fb6a07SPatrick Mooney 		 */
541*e1fb6a07SPatrick Mooney 		res = _Unw_get_val(&addr, reloc, UNUM64, 1, 1, 0);
542*e1fb6a07SPatrick Mooney 	}
543*e1fb6a07SPatrick Mooney 
5447c478bd9Sstevel@tonic-gate 	return (res);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate int interpret_op(void **datap, ptrdiff_t reloc,
5497c478bd9Sstevel@tonic-gate 	uint64_t *reached_pc_p, uint64_t pc,
5507c478bd9Sstevel@tonic-gate 	struct register_state f_state[],
5517c478bd9Sstevel@tonic-gate 	struct register_state f_start_state[],
5527c478bd9Sstevel@tonic-gate 	int daf, int caf, int enc);
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate uint64_t
interpret_ops(void * data,void * data_end,ptrdiff_t reloc,uint64_t start_pc,uint64_t pc,struct register_state f_state[],struct register_state f_start_state[],int daf,int caf,int enc)5557c478bd9Sstevel@tonic-gate interpret_ops(void *data, void *data_end,
5567c478bd9Sstevel@tonic-gate 	ptrdiff_t reloc,
5577c478bd9Sstevel@tonic-gate 	uint64_t start_pc, uint64_t pc,
5587c478bd9Sstevel@tonic-gate 	struct register_state f_state[],
5597c478bd9Sstevel@tonic-gate 	struct register_state f_start_state[],
5607c478bd9Sstevel@tonic-gate 	int daf, int caf, int enc)
5617c478bd9Sstevel@tonic-gate {
5627c478bd9Sstevel@tonic-gate 	void *d = data;
5637c478bd9Sstevel@tonic-gate 	uint64_t reached_pc = start_pc;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	while (d < data_end) {
5667c478bd9Sstevel@tonic-gate 		if (interpret_op(&d, reloc, &reached_pc, pc,
5677c478bd9Sstevel@tonic-gate 		    f_state, f_start_state, daf, caf, enc))
5687c478bd9Sstevel@tonic-gate 			break;
5697c478bd9Sstevel@tonic-gate 	}
5707c478bd9Sstevel@tonic-gate 	return (reached_pc);
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate int
interpret_op(void ** datap,ptrdiff_t reloc,uint64_t * reached_pc_p,uint64_t pc,struct register_state f_state[],struct register_state f_start_state[],int daf,int caf,int enc)5747c478bd9Sstevel@tonic-gate interpret_op(void **datap, ptrdiff_t reloc,
5757c478bd9Sstevel@tonic-gate 	uint64_t *reached_pc_p, uint64_t pc,
5767c478bd9Sstevel@tonic-gate 	struct register_state f_state[],
5777c478bd9Sstevel@tonic-gate 	struct register_state f_start_state[],
5787c478bd9Sstevel@tonic-gate 	int daf, int caf, int enc)
5797c478bd9Sstevel@tonic-gate {
5807c478bd9Sstevel@tonic-gate 	enum CFA_ops op = separate_op(datap);
5817c478bd9Sstevel@tonic-gate 	enum operand_desc opr1 = (cfa_operations[op]).op1;
5827c478bd9Sstevel@tonic-gate 	enum operand_desc opr2 = (cfa_operations[op]).op2;
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	uint64_t val1 = _Unw_get_val(datap, reloc, opr1, daf, caf, enc);
5857c478bd9Sstevel@tonic-gate 	uint64_t val2 = _Unw_get_val(datap, reloc, opr2, daf, caf, enc);
5867c478bd9Sstevel@tonic-gate 	if ((opr1 == ULEB128_SREG && val1 == BAD_REG) ||
5877c478bd9Sstevel@tonic-gate 	    (opr2 == ULEB128_SREG && val2 == BAD_REG))
5887c478bd9Sstevel@tonic-gate 		return (0);
5897c478bd9Sstevel@tonic-gate 	switch (op) {
5907c478bd9Sstevel@tonic-gate 	case DW_CFA_nop:
5917c478bd9Sstevel@tonic-gate 		break;
5927c478bd9Sstevel@tonic-gate 	case DW_CFA_set_loc:
5937c478bd9Sstevel@tonic-gate 		if (val1 > pc)
5947c478bd9Sstevel@tonic-gate 			return (1);
5957c478bd9Sstevel@tonic-gate 		*reached_pc_p = val1;
5967c478bd9Sstevel@tonic-gate 		break;
5977c478bd9Sstevel@tonic-gate 	case DW_CFA_advance_loc1:
5987c478bd9Sstevel@tonic-gate 	case DW_CFA_advance_loc2:
5997c478bd9Sstevel@tonic-gate 	case DW_CFA_advance_loc4:
6007c478bd9Sstevel@tonic-gate 		if (*reached_pc_p + val1 > pc)
6017c478bd9Sstevel@tonic-gate 			return (1);
6027c478bd9Sstevel@tonic-gate 		*reached_pc_p += val1;
6037c478bd9Sstevel@tonic-gate 		break;
6047c478bd9Sstevel@tonic-gate 	case DW_CFA_offset_extended:
6057c478bd9Sstevel@tonic-gate 		f_state[val1].rule = offset_rule;
6067c478bd9Sstevel@tonic-gate 		f_state[val1].source_reg = CF_ADDR;
6077c478bd9Sstevel@tonic-gate 		f_state[val1].offset = val2;
6087c478bd9Sstevel@tonic-gate 		break;
6097c478bd9Sstevel@tonic-gate 	case DW_CFA_restore_extended:
6107c478bd9Sstevel@tonic-gate 		if (f_start_state != 0)
6117c478bd9Sstevel@tonic-gate 			f_state[val1] = f_start_state[val1];
6127c478bd9Sstevel@tonic-gate 		break;
6137c478bd9Sstevel@tonic-gate 	case DW_CFA_undefined:
6147c478bd9Sstevel@tonic-gate 		f_state[val1].rule = undefined_rule;
6157c478bd9Sstevel@tonic-gate 		break;
6167c478bd9Sstevel@tonic-gate 	case DW_CFA_same_value:
6177c478bd9Sstevel@tonic-gate 		f_state[val1].rule = same_value_rule;
6187c478bd9Sstevel@tonic-gate 		break;
6197c478bd9Sstevel@tonic-gate 	case DW_CFA_register:
6207c478bd9Sstevel@tonic-gate 		f_state[val1].rule = register_rule;
6217c478bd9Sstevel@tonic-gate 		f_state[val1].source_reg = val2;
6227c478bd9Sstevel@tonic-gate 		f_state[val1].offset = 0;
6237c478bd9Sstevel@tonic-gate 		break;
6247c478bd9Sstevel@tonic-gate 	case DW_CFA_remember_state:
6257c478bd9Sstevel@tonic-gate 		break;
6267c478bd9Sstevel@tonic-gate 	case DW_CFA_restore_state:
6277c478bd9Sstevel@tonic-gate 		break;
6287c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa:
6297c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].rule = register_rule;
6307c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].source_reg = val1;
6317c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].offset = val2;
6327c478bd9Sstevel@tonic-gate 		break;
6337c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa_register:
6347c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].source_reg = val1;
6357c478bd9Sstevel@tonic-gate 		break;
6367c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa_offset:
6377c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].offset = val1;
6387c478bd9Sstevel@tonic-gate 		break;
6397c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa_expression:
6407c478bd9Sstevel@tonic-gate 		break;
6417c478bd9Sstevel@tonic-gate 	case DW_CFA_expression:
6427c478bd9Sstevel@tonic-gate 		break;
6437c478bd9Sstevel@tonic-gate 	case DW_CFA_offset_extended_sf:
6447c478bd9Sstevel@tonic-gate 		f_state[val1].rule = offset_rule;
6457c478bd9Sstevel@tonic-gate 		f_state[val1].source_reg = CF_ADDR;
6467c478bd9Sstevel@tonic-gate 		f_state[val1].offset = val2;
6477c478bd9Sstevel@tonic-gate 		break;
6487c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa_sf:
6497c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].rule = register_rule;
6507c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].source_reg = val1;
6517c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].offset = val2;
6527c478bd9Sstevel@tonic-gate 		break;
6537c478bd9Sstevel@tonic-gate 	case DW_CFA_def_cfa_offset_sf:
6547c478bd9Sstevel@tonic-gate 		f_state[CF_ADDR].offset = val1;
6557c478bd9Sstevel@tonic-gate 		break;
6567c478bd9Sstevel@tonic-gate 	case DW_CFA_SUNW_advance_loc:
6577c478bd9Sstevel@tonic-gate 		if (*reached_pc_p + val1 > pc)
6587c478bd9Sstevel@tonic-gate 			return (1);
6597c478bd9Sstevel@tonic-gate 		*reached_pc_p += val1;
6607c478bd9Sstevel@tonic-gate 		break;
6617c478bd9Sstevel@tonic-gate 	case DW_CFA_SUNW_offset:
6627c478bd9Sstevel@tonic-gate 		f_state[val1].rule = offset_rule;
6637c478bd9Sstevel@tonic-gate 		f_state[val1].source_reg = CF_ADDR;
6647c478bd9Sstevel@tonic-gate 		f_state[val1].offset = val2;
6657c478bd9Sstevel@tonic-gate 		break;
6667c478bd9Sstevel@tonic-gate 	case DW_CFA_SUNW_restore:
6677c478bd9Sstevel@tonic-gate 		if (f_start_state != 0)
6687c478bd9Sstevel@tonic-gate 			f_state[val1] = f_start_state[val1];
6697c478bd9Sstevel@tonic-gate 		break;
6707c478bd9Sstevel@tonic-gate 	}
6717c478bd9Sstevel@tonic-gate 	return (0);
6727c478bd9Sstevel@tonic-gate }
673