| 1 | /* |
| 2 | * user-internals.h: prototypes etc internal to the linux-user implementation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #ifndef LINUX_USER_USER_INTERNALS_H |
| 19 | #define LINUX_USER_USER_INTERNALS_H |
| 20 | |
| 21 | #include "user/thunk.h" |
| 22 | #include "qemu/log.h" |
| 23 | #include "exec/tb-flush.h" |
| 24 | #include "exec/translation-block.h" |
| 25 | #include "user/probe-guest-base.h" |
| 26 | |
| 27 | extern char *exec_path; |
| 28 | extern char real_exec_path[PATH_MAX]; |
| 29 | void init_task_state(TaskState *ts); |
| 30 | void task_settid(TaskState *); |
| 31 | void stop_all_tasks(void); |
| 32 | extern const char *qemu_uname_release; |
| 33 | |
| 34 | typedef struct IOCTLEntry IOCTLEntry; |
| 35 | |
| 36 | typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 37 | int fd, int cmd, abi_long arg); |
| 38 | |
| 39 | struct IOCTLEntry { |
| 40 | int target_cmd; |
| 41 | unsigned int host_cmd; |
| 42 | const char *name; |
| 43 | int access; |
| 44 | do_ioctl_fn *do_ioctl; |
| 45 | const argtype arg_type[5]; |
| 46 | }; |
| 47 | |
| 48 | extern IOCTLEntry ioctl_entries[]; |
| 49 | |
| 50 | #define IOC_R 0x0001 |
| 51 | #define IOC_W 0x0002 |
| 52 | #define IOC_RW (IOC_R | IOC_W) |
| 53 | |
| 54 | /* |
| 55 | * Returns true if the image uses the FDPIC ABI. If this is the case, |
| 56 | * we have to provide some information (loadmap, pt_dynamic_info) such |
| 57 | * that the program can be relocated adequately. This is also useful |
| 58 | * when handling signals. |
| 59 | */ |
| 60 | int info_is_fdpic(struct image_info *info); |
| 61 | |
| 62 | void target_set_brk(abi_ulong new_brk); |
| 63 | void syscall_init(void); |
| 64 | abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, |
| 65 | abi_long arg2, abi_long arg3, abi_long arg4, |
| 66 | abi_long arg5, abi_long arg6, abi_long arg7, |
| 67 | abi_long arg8); |
| 68 | extern __thread CPUState *thread_cpu; |
| 69 | abi_long get_errno(abi_long ret); |
| 70 | const char *target_strerror(int err); |
| 71 | int get_osversion(void); |
| 72 | void init_qemu_uname_release(void); |
| 73 | void clone_fork_start(void); |
| 74 | void clone_fork_end(bool child); |
| 75 | void fork_start(void); |
| 76 | void fork_end(pid_t pid); |
| 77 | |
| 78 | /** |
| 79 | * linux_probe_guest_base: |
| 80 | * @image_name: the executable being loaded |
| 81 | * @image_range: the fixed addresses within the executable |
| 82 | * |
| 83 | * Creates the initial guest address space in the host memory space. |
| 84 | * |
| 85 | * If @image_range is NULL, then no address in the executable is fixed, |
| 86 | * i.e. it is fully relocatable. |
| 87 | * |
| 88 | * This function will not return if a valid value for guest_base |
| 89 | * cannot be chosen. On return, the executable loader can expect |
| 90 | * |
| 91 | * target_mmap(i->lo, i->hi - i->lo + 1, ...) |
| 92 | * |
| 93 | * to succeed. |
| 94 | */ |
| 95 | void linux_probe_guest_base(const char *image_name, const PGBRange *image_range); |
| 96 | |
| 97 | /* syscall.c */ |
| 98 | int host_to_target_waitstatus(int status); |
| 99 | |
| 100 | #ifdef TARGET_I386 |
| 101 | /* vm86.c */ |
| 102 | void save_v86_state(CPUX86State *env); |
| 103 | void handle_vm86_trap(CPUX86State *env, int trapno); |
| 104 | int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr); |
| 105 | #elif defined(TARGET_SPARC64) |
| 106 | void sparc64_set_context(CPUSPARCState *env); |
| 107 | void sparc64_get_context(CPUSPARCState *env); |
| 108 | #endif |
| 109 | |
| 110 | static inline int is_error(abi_long ret) |
| 111 | { |
| 112 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
| 113 | } |
| 114 | |
| 115 | #if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32) |
| 116 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
| 117 | { |
| 118 | #if TARGET_BIG_ENDIAN |
| 119 | return ((uint64_t)word0 << 32) | word1; |
| 120 | #else |
| 121 | return ((uint64_t)word1 << 32) | word0; |
| 122 | #endif |
| 123 | } |
| 124 | #else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */ |
| 125 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
| 126 | { |
| 127 | return word0; |
| 128 | } |
| 129 | #endif /* TARGET_ABI_BITS != 32 */ |
| 130 | |
| 131 | void print_termios(void *arg); |
| 132 | #ifdef TARGET_TCGETS2 |
| 133 | void print_termios2(void *arg); |
| 134 | #endif |
| 135 | |
| 136 | /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ |
| 137 | #if defined(TARGET_ARM) && !defined(TARGET_AARCH64) |
| 138 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) |
| 139 | { |
| 140 | return cpu_env->eabi; |
| 141 | } |
| 142 | #elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32) |
| 143 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
| 144 | #elif defined(TARGET_PPC) && !defined(TARGET_PPC64) |
| 145 | /* |
| 146 | * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs |
| 147 | * of registers which translates to the same as ARM/MIPS, because we start with |
| 148 | * r3 as arg1 |
| 149 | */ |
| 150 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
| 151 | #elif defined(TARGET_SH4) |
| 152 | /* SH4 doesn't align register pairs, except for p{read,write}64 */ |
| 153 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) |
| 154 | { |
| 155 | switch (num) { |
| 156 | case TARGET_NR_pread64: |
| 157 | case TARGET_NR_pwrite64: |
| 158 | return 1; |
| 159 | |
| 160 | default: |
| 161 | return 0; |
| 162 | } |
| 163 | } |
| 164 | #elif defined(TARGET_XTENSA) |
| 165 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
| 166 | #elif defined(TARGET_HEXAGON) |
| 167 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
| 168 | #else |
| 169 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; } |
| 170 | #endif |
| 171 | |
| 172 | /** |
| 173 | * preexit_cleanup: housekeeping before the guest exits |
| 174 | * |
| 175 | * env: the CPU state |
| 176 | * code: the exit code |
| 177 | */ |
| 178 | void preexit_cleanup(CPUArchState *env, int code); |
| 179 | |
| 180 | /** |
| 181 | * begin_parallel_context |
| 182 | * @cs: the CPU context |
| 183 | * |
| 184 | * Called when starting the second vcpu, or joining shared memory. |
| 185 | */ |
| 186 | static inline void begin_parallel_context(CPUState *cs) |
| 187 | { |
| 188 | if (!tcg_cflags_has(cs, CF_PARALLEL)) { |
| 189 | tb_flush__exclusive_or_serial(); |
| 190 | tcg_cflags_set(cs, CF_PARALLEL); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * init_main_thread: Set CPU state for main thread |
| 196 | * @cs: CPU context to set |
| 197 | * @info: information about the image being loaded |
| 198 | * |
| 199 | * This function must be provided by the per-target code. It should |
| 200 | * set the initial CPU state based on the information about the |
| 201 | * starting binary in @image_info. This will be at a minimum setting |
| 202 | * the initial guest program counter and stack pointer; it should |
| 203 | * also set up any other guest register values where the Linux ABI |
| 204 | * defines that they start set to some other value than what the |
| 205 | * guest CPU architecture gives you out of reset. |
| 206 | */ |
| 207 | void init_main_thread(CPUState *cs, struct image_info *info); |
| 208 | |
| 209 | /* Clone cpu state */ |
| 210 | CPUArchState *cpu_copy(CPUArchState *env); |
| 211 | |
| 212 | /* |
| 213 | * Include target-specific struct and function definitions; |
| 214 | * they may need access to the target-independent structures |
| 215 | * above, so include them last. |
| 216 | */ |
| 217 | #include "target_cpu.h" |
| 218 | #include "target_structs.h" |
| 219 | |
| 220 | #endif |