Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 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 | |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 21 | #include "exec/user/thunk.h" |
Peter Maydell | d0a7920 | 2021-09-08 16:44:05 +0100 | [diff] [blame] | 22 | #include "exec/exec-all.h" |
| 23 | #include "qemu/log.h" |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 24 | |
| 25 | extern char *exec_path; |
| 26 | void init_task_state(TaskState *ts); |
| 27 | void task_settid(TaskState *); |
| 28 | void stop_all_tasks(void); |
| 29 | extern const char *qemu_uname_release; |
| 30 | extern unsigned long mmap_min_addr; |
| 31 | |
| 32 | typedef struct IOCTLEntry IOCTLEntry; |
| 33 | |
| 34 | typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp, |
| 35 | int fd, int cmd, abi_long arg); |
| 36 | |
| 37 | struct IOCTLEntry { |
| 38 | int target_cmd; |
| 39 | unsigned int host_cmd; |
| 40 | const char *name; |
| 41 | int access; |
| 42 | do_ioctl_fn *do_ioctl; |
| 43 | const argtype arg_type[5]; |
| 44 | }; |
| 45 | |
| 46 | extern IOCTLEntry ioctl_entries[]; |
| 47 | |
| 48 | #define IOC_R 0x0001 |
| 49 | #define IOC_W 0x0002 |
| 50 | #define IOC_RW (IOC_R | IOC_W) |
| 51 | |
| 52 | /* |
| 53 | * Returns true if the image uses the FDPIC ABI. If this is the case, |
| 54 | * we have to provide some information (loadmap, pt_dynamic_info) such |
| 55 | * that the program can be relocated adequately. This is also useful |
| 56 | * when handling signals. |
| 57 | */ |
| 58 | int info_is_fdpic(struct image_info *info); |
| 59 | |
| 60 | void target_set_brk(abi_ulong new_brk); |
| 61 | void syscall_init(void); |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 62 | abi_long do_syscall(CPUArchState *cpu_env, int num, abi_long arg1, |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 63 | abi_long arg2, abi_long arg3, abi_long arg4, |
| 64 | abi_long arg5, abi_long arg6, abi_long arg7, |
| 65 | abi_long arg8); |
| 66 | extern __thread CPUState *thread_cpu; |
Marc-André Lureau | 8905770 | 2022-04-20 17:26:02 +0400 | [diff] [blame] | 67 | G_NORETURN void cpu_loop(CPUArchState *env); |
Ilya Leoshkevich | 892a4f6 | 2022-06-21 16:42:05 +0200 | [diff] [blame] | 68 | abi_long get_errno(abi_long ret); |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 69 | const char *target_strerror(int err); |
| 70 | int get_osversion(void); |
| 71 | void init_qemu_uname_release(void); |
| 72 | void fork_start(void); |
| 73 | void fork_end(int child); |
| 74 | |
| 75 | /** |
| 76 | * probe_guest_base: |
| 77 | * @image_name: the executable being loaded |
| 78 | * @loaddr: the lowest fixed address in the executable |
| 79 | * @hiaddr: the highest fixed address in the executable |
| 80 | * |
| 81 | * Creates the initial guest address space in the host memory space. |
| 82 | * |
| 83 | * If @loaddr == 0, then no address in the executable is fixed, |
| 84 | * i.e. it is fully relocatable. In that case @hiaddr is the size |
| 85 | * of the executable. |
| 86 | * |
| 87 | * This function will not return if a valid value for guest_base |
| 88 | * cannot be chosen. On return, the executable loader can expect |
| 89 | * |
| 90 | * target_mmap(loaddr, hiaddr - loaddr, ...) |
| 91 | * |
| 92 | * to succeed. |
| 93 | */ |
| 94 | void probe_guest_base(const char *image_name, |
| 95 | abi_ulong loaddr, abi_ulong hiaddr); |
| 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 | void handle_vm86_fault(CPUX86State *env); |
| 105 | int do_vm86(CPUX86State *env, long subfunction, abi_ulong v86_addr); |
| 106 | #elif defined(TARGET_SPARC64) |
| 107 | void sparc64_set_context(CPUSPARCState *env); |
| 108 | void sparc64_get_context(CPUSPARCState *env); |
| 109 | #endif |
| 110 | |
| 111 | static inline int is_error(abi_long ret) |
| 112 | { |
| 113 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
| 114 | } |
| 115 | |
WANG Xuerui | 80f0fe3 | 2022-03-20 13:22:59 +0800 | [diff] [blame] | 116 | #if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32) |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 117 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
| 118 | { |
Marc-André Lureau | ee3eb3a | 2022-03-23 19:57:18 +0400 | [diff] [blame] | 119 | #if TARGET_BIG_ENDIAN |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 120 | return ((uint64_t)word0 << 32) | word1; |
| 121 | #else |
| 122 | return ((uint64_t)word1 << 32) | word0; |
| 123 | #endif |
| 124 | } |
WANG Xuerui | 80f0fe3 | 2022-03-20 13:22:59 +0800 | [diff] [blame] | 125 | #else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */ |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 126 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
| 127 | { |
| 128 | return word0; |
| 129 | } |
| 130 | #endif /* TARGET_ABI_BITS != 32 */ |
| 131 | |
| 132 | void print_termios(void *arg); |
| 133 | |
| 134 | /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */ |
| 135 | #ifdef TARGET_ARM |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 136 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 137 | { |
Philippe Mathieu-Daudé | 0effdc2 | 2022-05-09 22:57:28 +0200 | [diff] [blame] | 138 | return cpu_env->eabi == 1; |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 139 | } |
WANG Xuerui | 80f0fe3 | 2022-03-20 13:22:59 +0800 | [diff] [blame] | 140 | #elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32) |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 141 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 142 | #elif defined(TARGET_PPC) && !defined(TARGET_PPC64) |
| 143 | /* |
| 144 | * SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs |
| 145 | * of registers which translates to the same as ARM/MIPS, because we start with |
| 146 | * r3 as arg1 |
| 147 | */ |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 148 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 149 | #elif defined(TARGET_SH4) |
| 150 | /* SH4 doesn't align register pairs, except for p{read,write}64 */ |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 151 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 152 | { |
| 153 | switch (num) { |
| 154 | case TARGET_NR_pread64: |
| 155 | case TARGET_NR_pwrite64: |
| 156 | return 1; |
| 157 | |
| 158 | default: |
| 159 | return 0; |
| 160 | } |
| 161 | } |
| 162 | #elif defined(TARGET_XTENSA) |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 163 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 164 | #elif defined(TARGET_HEXAGON) |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 165 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 1; } |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 166 | #else |
Philippe Mathieu-Daudé | a0939b8 | 2022-05-09 22:57:27 +0200 | [diff] [blame] | 167 | static inline int regpairs_aligned(CPUArchState *cpu_env, int num) { return 0; } |
Peter Maydell | 3b249d2 | 2021-09-08 16:44:03 +0100 | [diff] [blame] | 168 | #endif |
| 169 | |
| 170 | /** |
| 171 | * preexit_cleanup: housekeeping before the guest exits |
| 172 | * |
| 173 | * env: the CPU state |
| 174 | * code: the exit code |
| 175 | */ |
| 176 | void preexit_cleanup(CPUArchState *env, int code); |
| 177 | |
| 178 | /* |
| 179 | * Include target-specific struct and function definitions; |
| 180 | * they may need access to the target-independent structures |
| 181 | * above, so include them last. |
| 182 | */ |
| 183 | #include "target_cpu.h" |
| 184 | #include "target_structs.h" |
| 185 | |
| 186 | #endif |