xref: /openbmc/qemu/bsd-user/x86_64/target_arch_sysarch.h (revision ea1ab4cf2c268c61e97b12cac670c5ccfc71d745)
1*ea1ab4cfSStacey Son /*
2*ea1ab4cfSStacey Son  *  x86_64 sysarch() syscall emulation
3*ea1ab4cfSStacey Son  *
4*ea1ab4cfSStacey Son  *
5*ea1ab4cfSStacey Son  *  This program is free software; you can redistribute it and/or modify
6*ea1ab4cfSStacey Son  *  it under the terms of the GNU General Public License as published by
7*ea1ab4cfSStacey Son  *  the Free Software Foundation; either version 2 of the License, or
8*ea1ab4cfSStacey Son  *  (at your option) any later version.
9*ea1ab4cfSStacey Son  *
10*ea1ab4cfSStacey Son  *  This program is distributed in the hope that it will be useful,
11*ea1ab4cfSStacey Son  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12*ea1ab4cfSStacey Son  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*ea1ab4cfSStacey Son  *  GNU General Public License for more details.
14*ea1ab4cfSStacey Son  *
15*ea1ab4cfSStacey Son  *  You should have received a copy of the GNU General Public License
16*ea1ab4cfSStacey Son  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
17*ea1ab4cfSStacey Son  */
18*ea1ab4cfSStacey Son 
19*ea1ab4cfSStacey Son #ifndef BSD_USER_ARCH_SYSARCH_H_
20*ea1ab4cfSStacey Son #define BSD_USER_ARCH_SYSARCH_H_
21*ea1ab4cfSStacey Son 
22*ea1ab4cfSStacey Son #include "target_syscall.h"
23*ea1ab4cfSStacey Son 
24*ea1ab4cfSStacey Son static inline abi_long do_freebsd_arch_sysarch(CPUX86State *env, int op,
25*ea1ab4cfSStacey Son         abi_ulong parms)
26*ea1ab4cfSStacey Son {
27*ea1ab4cfSStacey Son     abi_long ret = 0;
28*ea1ab4cfSStacey Son     abi_ulong val;
29*ea1ab4cfSStacey Son     int idx;
30*ea1ab4cfSStacey Son 
31*ea1ab4cfSStacey Son     switch (op) {
32*ea1ab4cfSStacey Son     case TARGET_FREEBSD_AMD64_SET_GSBASE:
33*ea1ab4cfSStacey Son     case TARGET_FREEBSD_AMD64_SET_FSBASE:
34*ea1ab4cfSStacey Son         if (op == TARGET_FREEBSD_AMD64_SET_GSBASE) {
35*ea1ab4cfSStacey Son             idx = R_GS;
36*ea1ab4cfSStacey Son         } else {
37*ea1ab4cfSStacey Son             idx = R_FS;
38*ea1ab4cfSStacey Son         }
39*ea1ab4cfSStacey Son         if (get_user(val, parms, abi_ulong)) {
40*ea1ab4cfSStacey Son             return -TARGET_EFAULT;
41*ea1ab4cfSStacey Son         }
42*ea1ab4cfSStacey Son         cpu_x86_load_seg(env, idx, 0);
43*ea1ab4cfSStacey Son         env->segs[idx].base = val;
44*ea1ab4cfSStacey Son         break;
45*ea1ab4cfSStacey Son 
46*ea1ab4cfSStacey Son     case TARGET_FREEBSD_AMD64_GET_GSBASE:
47*ea1ab4cfSStacey Son     case TARGET_FREEBSD_AMD64_GET_FSBASE:
48*ea1ab4cfSStacey Son         if (op == TARGET_FREEBSD_AMD64_GET_GSBASE) {
49*ea1ab4cfSStacey Son             idx = R_GS;
50*ea1ab4cfSStacey Son         } else {
51*ea1ab4cfSStacey Son             idx = R_FS;
52*ea1ab4cfSStacey Son         }
53*ea1ab4cfSStacey Son         val = env->segs[idx].base;
54*ea1ab4cfSStacey Son         if (put_user(val, parms, abi_ulong)) {
55*ea1ab4cfSStacey Son             return -TARGET_EFAULT;
56*ea1ab4cfSStacey Son         }
57*ea1ab4cfSStacey Son         break;
58*ea1ab4cfSStacey Son 
59*ea1ab4cfSStacey Son     /* XXX handle the others... */
60*ea1ab4cfSStacey Son     default:
61*ea1ab4cfSStacey Son         ret = -TARGET_EINVAL;
62*ea1ab4cfSStacey Son         break;
63*ea1ab4cfSStacey Son     }
64*ea1ab4cfSStacey Son     return ret;
65*ea1ab4cfSStacey Son }
66*ea1ab4cfSStacey Son 
67*ea1ab4cfSStacey Son static inline void do_freebsd_arch_print_sysarch(
68*ea1ab4cfSStacey Son         const struct syscallname *name, abi_long arg1, abi_long arg2,
69*ea1ab4cfSStacey Son         abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
70*ea1ab4cfSStacey Son {
71*ea1ab4cfSStacey Son 
72*ea1ab4cfSStacey Son     gemu_log("%s(%d, " TARGET_ABI_FMT_lx ", " TARGET_ABI_FMT_lx ", "
73*ea1ab4cfSStacey Son         TARGET_ABI_FMT_lx ")", name->name, (int)arg1, arg2, arg3, arg4);
74*ea1ab4cfSStacey Son }
75*ea1ab4cfSStacey Son 
76*ea1ab4cfSStacey Son #endif /*! BSD_USER_ARCH_SYSARCH_H_ */
77