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"
23548c9609SAlex Bennée #include "exec/tb-flush.h"
24d0a7920eSPeter Maydell #include "qemu/log.h"
253b249d26SPeter Maydell
263b249d26SPeter Maydell extern char *exec_path;
273b249d26SPeter Maydell void init_task_state(TaskState *ts);
283b249d26SPeter Maydell void task_settid(TaskState *);
293b249d26SPeter Maydell void stop_all_tasks(void);
303b249d26SPeter Maydell extern const char *qemu_uname_release;
313b249d26SPeter Maydell extern unsigned long mmap_min_addr;
323b249d26SPeter Maydell
333b249d26SPeter Maydell typedef struct IOCTLEntry IOCTLEntry;
343b249d26SPeter Maydell
353b249d26SPeter Maydell typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
363b249d26SPeter Maydell int fd, int cmd, abi_long arg);
373b249d26SPeter Maydell
383b249d26SPeter Maydell struct IOCTLEntry {
393b249d26SPeter Maydell int target_cmd;
403b249d26SPeter Maydell unsigned int host_cmd;
413b249d26SPeter Maydell const char *name;
423b249d26SPeter Maydell int access;
433b249d26SPeter Maydell do_ioctl_fn *do_ioctl;
443b249d26SPeter Maydell const argtype arg_type[5];
453b249d26SPeter Maydell };
463b249d26SPeter Maydell
473b249d26SPeter Maydell extern IOCTLEntry ioctl_entries[];
483b249d26SPeter Maydell
493b249d26SPeter Maydell #define IOC_R 0x0001
503b249d26SPeter Maydell #define IOC_W 0x0002
513b249d26SPeter Maydell #define IOC_RW (IOC_R | IOC_W)
523b249d26SPeter Maydell
533b249d26SPeter Maydell /*
543b249d26SPeter Maydell * Returns true if the image uses the FDPIC ABI. If this is the case,
553b249d26SPeter Maydell * we have to provide some information (loadmap, pt_dynamic_info) such
563b249d26SPeter Maydell * that the program can be relocated adequately. This is also useful
573b249d26SPeter Maydell * when handling signals.
583b249d26SPeter Maydell */
593b249d26SPeter Maydell int info_is_fdpic(struct image_info *info);
603b249d26SPeter Maydell
613b249d26SPeter Maydell void target_set_brk(abi_ulong new_brk);
623b249d26SPeter Maydell void syscall_init(void);
63a0939b89SPhilippe Mathieu-Daudé abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1,
643b249d26SPeter Maydell abi_long arg2, abi_long arg3, abi_long arg4,
653b249d26SPeter Maydell abi_long arg5, abi_long arg6, abi_long arg7,
663b249d26SPeter Maydell abi_long arg8);
673b249d26SPeter Maydell extern __thread CPUState *thread_cpu;
688905770bSMarc-André Lureau G_NORETURN void cpu_loop(CPUArchState *env);
69892a4f6aSIlya Leoshkevich abi_long get_errno(abi_long ret);
703b249d26SPeter Maydell const char *target_strerror(int err);
713b249d26SPeter Maydell int get_osversion(void);
723b249d26SPeter Maydell void init_qemu_uname_release(void);
733b249d26SPeter Maydell void fork_start(void);
743b249d26SPeter Maydell void fork_end(int child);
753b249d26SPeter Maydell
763b249d26SPeter Maydell /**
773b249d26SPeter Maydell * probe_guest_base:
783b249d26SPeter Maydell * @image_name: the executable being loaded
79*a3a67f54SRichard Henderson * @loaddr: the lowest fixed address within the executable
80*a3a67f54SRichard Henderson * @hiaddr: the highest fixed address within the executable
813b249d26SPeter Maydell *
823b249d26SPeter Maydell * Creates the initial guest address space in the host memory space.
833b249d26SPeter Maydell *
84*a3a67f54SRichard Henderson * If @loaddr == 0, then no address in the executable is fixed, i.e.
85*a3a67f54SRichard Henderson * it is fully relocatable. In that case @hiaddr is the size of the
86*a3a67f54SRichard Henderson * executable minus one.
873b249d26SPeter Maydell *
883b249d26SPeter Maydell * This function will not return if a valid value for guest_base
893b249d26SPeter Maydell * cannot be chosen. On return, the executable loader can expect
903b249d26SPeter Maydell *
91*a3a67f54SRichard Henderson * target_mmap(loaddr, hiaddr - loaddr + 1, ...)
923b249d26SPeter Maydell *
933b249d26SPeter Maydell * to succeed.
943b249d26SPeter Maydell */
953b249d26SPeter Maydell void probe_guest_base(const char *image_name,
963b249d26SPeter Maydell abi_ulong loaddr, abi_ulong hiaddr);
973b249d26SPeter Maydell
983b249d26SPeter Maydell /* syscall.c */
993b249d26SPeter Maydell int host_to_target_waitstatus(int status);
1003b249d26SPeter Maydell
1013b249d26SPeter Maydell #ifdef TARGET_I386
1023b249d26SPeter Maydell /* vm86.c */
1033b249d26SPeter Maydell void save_v86_state(CPUX86State *env);
1043b249d26SPeter Maydell void handle_vm86_trap(CPUX86State *env, int trapno);
1053b249d26SPeter Maydell void handle_vm86_fault(CPUX86State *env);
1063b249d26SPeter Maydell int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr);
1073b249d26SPeter Maydell #elif defined(TARGET_SPARC64)
1083b249d26SPeter Maydell void sparc64_set_context(CPUSPARCState *env);
1093b249d26SPeter Maydell void sparc64_get_context(CPUSPARCState *env);
1103b249d26SPeter Maydell #endif
1113b249d26SPeter Maydell
is_error(abi_long ret)1123b249d26SPeter Maydell static inline int is_error(abi_long ret)
1133b249d26SPeter Maydell {
1143b249d26SPeter Maydell return (abi_ulong)ret >= (abi_ulong)(-4096);
1153b249d26SPeter Maydell }
1163b249d26SPeter Maydell
11780f0fe3aSWANG Xuerui #if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32)
target_offset64(uint32_t word0,uint32_t word1)1183b249d26SPeter Maydell static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
1193b249d26SPeter Maydell {
120ee3eb3a7SMarc-André Lureau #if TARGET_BIG_ENDIAN
1213b249d26SPeter Maydell return ((uint64_t)word0 << 32) | word1;
1223b249d26SPeter Maydell #else
1233b249d26SPeter Maydell return ((uint64_t)word1 << 32) | word0;
1243b249d26SPeter Maydell #endif
1253b249d26SPeter Maydell }
12680f0fe3aSWANG Xuerui #else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */
target_offset64(uint64_t word0,uint64_t word1)1273b249d26SPeter Maydell static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
1283b249d26SPeter Maydell {
1293b249d26SPeter Maydell return word0;
1303b249d26SPeter Maydell }
1313b249d26SPeter Maydell #endif /* TARGET_ABI_BITS != 32 */
1323b249d26SPeter Maydell
1333b249d26SPeter Maydell void print_termios(void *arg);
1343b249d26SPeter Maydell
1353b249d26SPeter Maydell /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
1363b249d26SPeter Maydell #ifdef TARGET_ARM
regpairs_aligned(CPUArchState * cpu_env,int num)137a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num)
1383b249d26SPeter Maydell {
139de4143fcSPhilippe Mathieu-Daudé return cpu_env->eabi;
1403b249d26SPeter Maydell }
14180f0fe3aSWANG Xuerui #elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32)
regpairs_aligned(CPUArchState * cpu_env,int num)142a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
1433b249d26SPeter Maydell #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
1443b249d26SPeter Maydell /*
1453b249d26SPeter Maydell * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
1463b249d26SPeter Maydell * of registers which translates to the same as ARM/MIPS, because we start with
1473b249d26SPeter Maydell * r3 as arg1
1483b249d26SPeter Maydell */
regpairs_aligned(CPUArchState * cpu_env,int num)149a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
1503b249d26SPeter Maydell #elif defined(TARGET_SH4)
1513b249d26SPeter Maydell /* SH4 doesn't align register pairs, except for p{read,write}64 */
regpairs_aligned(CPUArchState * cpu_env,int num)152a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num)
1533b249d26SPeter Maydell {
1543b249d26SPeter Maydell switch (num) {
1553b249d26SPeter Maydell case TARGET_NR_pread64:
1563b249d26SPeter Maydell case TARGET_NR_pwrite64:
1573b249d26SPeter Maydell return 1;
1583b249d26SPeter Maydell
1593b249d26SPeter Maydell default:
1603b249d26SPeter Maydell return 0;
1613b249d26SPeter Maydell }
1623b249d26SPeter Maydell }
1633b249d26SPeter Maydell #elif defined(TARGET_XTENSA)
regpairs_aligned(CPUArchState * cpu_env,int num)164a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
1653b249d26SPeter Maydell #elif defined(TARGET_HEXAGON)
regpairs_aligned(CPUArchState * cpu_env,int num)166a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; }
1673b249d26SPeter Maydell #else
regpairs_aligned(CPUArchState * cpu_env,int num)168a0939b89SPhilippe Mathieu-Daudé static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; }
1693b249d26SPeter Maydell #endif
1703b249d26SPeter Maydell
1713b249d26SPeter Maydell /**
1723b249d26SPeter Maydell * preexit_cleanup: housekeeping before the guest exits
1733b249d26SPeter Maydell *
1743b249d26SPeter Maydell * env: the CPU state
1753b249d26SPeter Maydell * code: the exit code
1763b249d26SPeter Maydell */
1773b249d26SPeter Maydell void preexit_cleanup(CPUArchState *env, int code);
1783b249d26SPeter Maydell
1793b249d26SPeter Maydell /*
1803b249d26SPeter Maydell * Include target-specific struct and function definitions;
1813b249d26SPeter Maydell * they may need access to the target-independent structures
1823b249d26SPeter Maydell * above, so include them last.
1833b249d26SPeter Maydell */
1843b249d26SPeter Maydell #include "target_cpu.h"
1853b249d26SPeter Maydell #include "target_structs.h"
1863b249d26SPeter Maydell
1873b249d26SPeter Maydell #endif
188