2 * Copyright (c) 2002 Jake Burkholder.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/types.h>
30 #include <machine/cpufunc.h>
31 #include <machine/instr.h>
35 #include "__sparc_utrap_private.h"
38 __unaligned_load(u_char *p, int size)
44 for (i = 0; i < size; i++)
45 val = (val << 8) | p[i];
50 __unaligned_store(u_char *p, u_long val, int size)
54 for (i = 0; i < size; i++)
55 p[i] = val >> ((size - i - 1) * 8);
59 __unaligned_fixup(struct utrapframe *uf)
67 addr = (u_char *)uf->uf_sfar;
68 insn = *(u_int *)uf->uf_pc;
70 switch (IF_OP(insn)) {
72 switch (IF_F3_OP3(insn)) {
74 val = __unaligned_load(addr, 2);
75 __emul_store_reg(uf, IF_F3_RD(insn), val);
78 val = __unaligned_load(addr, 4);
79 __emul_store_reg(uf, IF_F3_RD(insn), val);
82 val = __unaligned_load(addr, 8);
83 __emul_store_reg(uf, IF_F3_RD(insn), val);
86 val = __unaligned_load(addr, 2);
87 __emul_store_reg(uf, IF_F3_RD(insn),
91 val = __unaligned_load(addr, 4);
92 __emul_store_reg(uf, IF_F3_RD(insn),
96 val = __emul_fetch_reg(uf, IF_F3_RD(insn));
97 __unaligned_store(addr, val, 2);
100 val = __emul_fetch_reg(uf, IF_F3_RD(insn));
101 __unaligned_store(addr, val, 4);
104 val = __emul_fetch_reg(uf, IF_F3_RD(insn));
105 __unaligned_store(addr, val, 8);