xref: /openbmc/qemu/linux-user/user-internals.h (revision ee3eb3a7)
13b249d26SPeter Maydell /*
23b249d26SPeter Maydell  * user-internals.h: prototypes etc internal to the linux-user implementation
33b249d26SPeter Maydell  *
43b249d26SPeter Maydell  *  This program is free software; you can redistribute it and/or modify
53b249d26SPeter Maydell  *  it under the terms of the GNU General Public License as published by
63b249d26SPeter Maydell  *  the Free Software Foundation; either version 2 of the License, or
73b249d26SPeter Maydell  *  (at your option) any later version.
83b249d26SPeter Maydell  *
93b249d26SPeter Maydell  *  This program is distributed in the hope that it will be useful,
103b249d26SPeter Maydell  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
113b249d26SPeter Maydell  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
123b249d26SPeter Maydell  *  GNU General Public License for more details.
133b249d26SPeter Maydell  *
143b249d26SPeter Maydell  *  You should have received a copy of the GNU General Public License
153b249d26SPeter Maydell  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
163b249d26SPeter Maydell  */
173b249d26SPeter Maydell 
183b249d26SPeter Maydell #ifndef LINUX_USER_USER_INTERNALS_H
193b249d26SPeter Maydell #define LINUX_USER_USER_INTERNALS_H
203b249d26SPeter Maydell 
213b249d26SPeter Maydell #include "exec/user/thunk.h"
22d0a7920eSPeter Maydell #include "exec/exec-all.h"
23d0a7920eSPeter Maydell #include "qemu/log.h"
243b249d26SPeter Maydell 
253b249d26SPeter Maydell extern char *exec_path;
263b249d26SPeter Maydell void init_task_state(TaskState *ts);
273b249d26SPeter Maydell void task_settid(TaskState *);
283b249d26SPeter Maydell void stop_all_tasks(void);
293b249d26SPeter Maydell extern const char *qemu_uname_release;
303b249d26SPeter Maydell extern unsigned long mmap_min_addr;
313b249d26SPeter Maydell 
323b249d26SPeter Maydell typedef struct IOCTLEntry IOCTLEntry;
333b249d26SPeter Maydell 
343b249d26SPeter Maydell typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
353b249d26SPeter Maydell                              int fd, int cmd, abi_long arg);
363b249d26SPeter Maydell 
373b249d26SPeter Maydell struct IOCTLEntry {
383b249d26SPeter Maydell     int target_cmd;
393b249d26SPeter Maydell     unsigned int host_cmd;
403b249d26SPeter Maydell     const char *name;
413b249d26SPeter Maydell     int access;
423b249d26SPeter Maydell     do_ioctl_fn *do_ioctl;
433b249d26SPeter Maydell     const argtype arg_type[5];
443b249d26SPeter Maydell };
453b249d26SPeter Maydell 
463b249d26SPeter Maydell extern IOCTLEntry ioctl_entries[];
473b249d26SPeter Maydell 
483b249d26SPeter Maydell #define IOC_R 0x0001
493b249d26SPeter Maydell #define IOC_W 0x0002
503b249d26SPeter Maydell #define IOC_RW (IOC_R | IOC_W)
513b249d26SPeter Maydell 
523b249d26SPeter Maydell /*
533b249d26SPeter Maydell  * Returns true if the image uses the FDPIC ABI. If this is the case,
543b249d26SPeter Maydell  * we have to provide some information (loadmap, pt_dynamic_info) such
553b249d26SPeter Maydell  * that the program can be relocated adequately. This is also useful
563b249d26SPeter Maydell  * when handling signals.
573b249d26SPeter Maydell  */
583b249d26SPeter Maydell int info_is_fdpic(struct image_info *info);
593b249d26SPeter Maydell 
603b249d26SPeter Maydell void target_set_brk(abi_ulong new_brk);
613b249d26SPeter Maydell void syscall_init(void);
623b249d26SPeter Maydell abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
633b249d26SPeter Maydell                     abi_long arg2, abi_long arg3, abi_long arg4,
643b249d26SPeter Maydell                     abi_long arg5, abi_long arg6, abi_long arg7,
653b249d26SPeter Maydell                     abi_long arg8);
663b249d26SPeter Maydell extern __thread CPUState *thread_cpu;
67f93d0af8SPhilippe Mathieu-Daudé void QEMU_NORETURN cpu_loop(CPUArchState *env);
683b249d26SPeter Maydell const char *target_strerror(int err);
693b249d26SPeter Maydell int get_osversion(void);
703b249d26SPeter Maydell void init_qemu_uname_release(void);
713b249d26SPeter Maydell void fork_start(void);
723b249d26SPeter Maydell void fork_end(int child);
733b249d26SPeter Maydell 
743b249d26SPeter Maydell /**
753b249d26SPeter Maydell  * probe_guest_base:
763b249d26SPeter Maydell  * @image_name: the executable being loaded
773b249d26SPeter Maydell  * @loaddr: the lowest fixed address in the executable
783b249d26SPeter Maydell  * @hiaddr: the highest fixed address in the executable
793b249d26SPeter Maydell  *
803b249d26SPeter Maydell  * Creates the initial guest address space in the host memory space.
813b249d26SPeter Maydell  *
823b249d26SPeter Maydell  * If @loaddr == 0, then no address in the executable is fixed,
833b249d26SPeter Maydell  * i.e. it is fully relocatable.  In that case @hiaddr is the size
843b249d26SPeter Maydell  * of the executable.
853b249d26SPeter Maydell  *
863b249d26SPeter Maydell  * This function will not return if a valid value for guest_base
873b249d26SPeter Maydell  * cannot be chosen.  On return, the executable loader can expect
883b249d26SPeter Maydell  *
893b249d26SPeter Maydell  *    target_mmap(loaddr, hiaddr - loaddr, ...)
903b249d26SPeter Maydell  *
913b249d26SPeter Maydell  * to succeed.
923b249d26SPeter Maydell  */
933b249d26SPeter Maydell void probe_guest_base(const char *image_name,
943b249d26SPeter Maydell                       abi_ulong loaddr, abi_ulong hiaddr);
953b249d26SPeter Maydell 
963b249d26SPeter Maydell /* syscall.c */
973b249d26SPeter Maydell int host_to_target_waitstatus(int status);
983b249d26SPeter Maydell 
993b249d26SPeter Maydell #ifdef TARGET_I386
1003b249d26SPeter Maydell /* vm86.c */
1013b249d26SPeter Maydell void save_v86_state(CPUX86State *env);
1023b249d26SPeter Maydell void handle_vm86_trap(CPUX86State *env, int trapno);
1033b249d26SPeter Maydell void handle_vm86_fault(CPUX86State *env);
1043b249d26SPeter Maydell int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr);
1053b249d26SPeter Maydell #elif defined(TARGET_SPARC64)
1063b249d26SPeter Maydell void sparc64_set_context(CPUSPARCState *env);
1073b249d26SPeter Maydell void sparc64_get_context(CPUSPARCState *env);
1083b249d26SPeter Maydell #endif
1093b249d26SPeter Maydell 
1103b249d26SPeter Maydell static inline int is_error(abi_long ret)
1113b249d26SPeter Maydell {
1123b249d26SPeter Maydell     return (abi_ulong)ret >= (abi_ulong)(-4096);
1133b249d26SPeter Maydell }
1143b249d26SPeter Maydell 
11580f0fe3aSWANG Xuerui #if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32)
1163b249d26SPeter Maydell static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
1173b249d26SPeter Maydell {
118*ee3eb3a7SMarc-André Lureau #if TARGET_BIG_ENDIAN
1193b249d26SPeter Maydell     return ((uint64_t)word0 << 32) | word1;
1203b249d26SPeter Maydell #else
1213b249d26SPeter Maydell     return ((uint64_t)word1 << 32) | word0;
1223b249d26SPeter Maydell #endif
1233b249d26SPeter Maydell }
12480f0fe3aSWANG Xuerui #else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */
1253b249d26SPeter Maydell static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
1263b249d26SPeter Maydell {
1273b249d26SPeter Maydell     return word0;
1283b249d26SPeter Maydell }
1293b249d26SPeter Maydell #endif /* TARGET_ABI_BITS != 32 */
1303b249d26SPeter Maydell 
1313b249d26SPeter Maydell void print_termios(void *arg);
1323b249d26SPeter Maydell 
1333b249d26SPeter Maydell /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
1343b249d26SPeter Maydell #ifdef TARGET_ARM
1353b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num)
1363b249d26SPeter Maydell {
1373b249d26SPeter Maydell     return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
1383b249d26SPeter Maydell }
13980f0fe3aSWANG Xuerui #elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32)
1403b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
1413b249d26SPeter Maydell #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
1423b249d26SPeter Maydell /*
1433b249d26SPeter Maydell  * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
1443b249d26SPeter Maydell  * of registers which translates to the same as ARM/MIPS, because we start with
1453b249d26SPeter Maydell  * r3 as arg1
1463b249d26SPeter Maydell  */
1473b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
1483b249d26SPeter Maydell #elif defined(TARGET_SH4)
1493b249d26SPeter Maydell /* SH4 doesn't align register pairs, except for p{read,write}64 */
1503b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num)
1513b249d26SPeter Maydell {
1523b249d26SPeter Maydell     switch (num) {
1533b249d26SPeter Maydell     case TARGET_NR_pread64:
1543b249d26SPeter Maydell     case TARGET_NR_pwrite64:
1553b249d26SPeter Maydell         return 1;
1563b249d26SPeter Maydell 
1573b249d26SPeter Maydell     default:
1583b249d26SPeter Maydell         return 0;
1593b249d26SPeter Maydell     }
1603b249d26SPeter Maydell }
1613b249d26SPeter Maydell #elif defined(TARGET_XTENSA)
1623b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
1633b249d26SPeter Maydell #elif defined(TARGET_HEXAGON)
1643b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
1653b249d26SPeter Maydell #else
1663b249d26SPeter Maydell static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
1673b249d26SPeter Maydell #endif
1683b249d26SPeter Maydell 
1693b249d26SPeter Maydell /**
1703b249d26SPeter Maydell  * preexit_cleanup: housekeeping before the guest exits
1713b249d26SPeter Maydell  *
1723b249d26SPeter Maydell  * env: the CPU state
1733b249d26SPeter Maydell  * code: the exit code
1743b249d26SPeter Maydell  */
1753b249d26SPeter Maydell void preexit_cleanup(CPUArchState *env, int code);
1763b249d26SPeter Maydell 
1773b249d26SPeter Maydell /*
1783b249d26SPeter Maydell  * Include target-specific struct and function definitions;
1793b249d26SPeter Maydell  * they may need access to the target-independent structures
1803b249d26SPeter Maydell  * above, so include them last.
1813b249d26SPeter Maydell  */
1823b249d26SPeter Maydell #include "target_cpu.h"
1833b249d26SPeter Maydell #include "target_structs.h"
1843b249d26SPeter Maydell 
1853b249d26SPeter Maydell #endif
186