2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 by Thomas Moestl <tmm@FreeBSD.org>.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
32 #include <machine/cpufunc.h>
33 #include <machine/frame.h>
34 #include <machine/instr.h>
38 #include "__sparc_utrap_private.h"
42 __emul_insn(struct utrapframe *uf)
52 insn = *(u_int *)uf->uf_pc;
54 switch (IF_OP(insn)) {
56 switch (IF_F3_OP3(insn)) {
58 if (IF_F3_RS1(insn) != 0) {
62 reg = __emul_f3_op2(uf, insn);
63 for (i = 0; i < 64; i++)
64 res += (reg >> i) & 1;
65 __emul_store_reg(uf, IF_F3_RD(insn), res);
73 switch (IF_F3_OP3(insn)) {
75 rd = INSFPdq_RN(IF_F3_RD(insn));
76 addr = (u_long *)__emul_f3_memop_addr(uf, insn);
77 __fpu_setreg64(rd, addr[0]);
78 __fpu_setreg64(rd + 2, addr[1]);
81 rd = INSFPdq_RN(IF_F3_RD(insn));
82 addr = (u_long *)__emul_f3_memop_addr(uf, insn);
83 addr[0] = __fpu_getreg64(rd);
84 addr[1] = __fpu_getreg64(rd + 2);
99 __emul_fetch_reg(struct utrapframe *uf, int reg)
105 else if (reg < IREG_O0) /* global */
106 return (uf->uf_global[reg]);
107 else if (reg < IREG_L0) /* out */
108 return (uf->uf_out[reg - IREG_O0]);
109 else { /* local, in */
111 * The in registers are immediately after the locals in
114 frm = (struct frame *)(uf->uf_out[6] + SPOFF);
115 return (frm->fr_local[reg - IREG_L0]);
120 __emul_store_reg(struct utrapframe *uf, int reg, u_long val)
126 if (reg < IREG_O0) /* global */
127 uf->uf_global[reg] = val;
128 else if (reg < IREG_L0) /* out */
129 uf->uf_out[reg - IREG_O0] = val;
132 * The in registers are immediately after the locals in
135 frm = (struct frame *)(uf->uf_out[6] + SPOFF);
136 frm->fr_local[reg - IREG_L0] = val;
141 __emul_f3_op2(struct utrapframe *uf, u_int insn)
144 if (IF_F3_I(insn) != 0)
145 return (IF_SIMM(insn, 13));
147 return (__emul_fetch_reg(uf, IF_F3_RS2(insn)));
151 __emul_f3_memop_addr(struct utrapframe *uf, u_int insn)
155 addr = __emul_f3_op2(uf, insn) + __emul_fetch_reg(uf, IF_F3_RS1(insn));