1 /* 2 * Helper routines to provide target memory access for semihosting 3 * syscalls in system emulation mode. 4 * 5 * Copyright (c) 2007 CodeSourcery. 6 * 7 * This code is licensed under the GPL 8 */ 9 10 #ifndef SEMIHOSTING_UACCESS_H 11 #define SEMIHOSTING_UACCESS_H 12 13 #ifdef CONFIG_USER_ONLY 14 #error Cannot include semihosting/uaccess.h from user emulation 15 #endif 16 17 #include "exec/cpu-common.h" 18 #include "exec/cpu-defs.h" 19 #include "exec/tswap.h" 20 21 #define get_user_u64(val, addr) \ 22 ({ uint64_t val_ = 0; \ 23 int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ 24 &val_, sizeof(val_), 0); \ 25 (val) = tswap64(val_); ret_; }) 26 27 #define get_user_u32(val, addr) \ 28 ({ uint32_t val_ = 0; \ 29 int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ 30 &val_, sizeof(val_), 0); \ 31 (val) = tswap32(val_); ret_; }) 32 33 #define get_user_u8(val, addr) \ 34 ({ uint8_t val_ = 0; \ 35 int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ 36 &val_, sizeof(val_), 0); \ 37 (val) = val_; ret_; }) 38 39 #define get_user_ual(arg, p) get_user_u32(arg, p) 40 41 #define put_user_u64(val, addr) \ 42 ({ uint64_t val_ = tswap64(val); \ 43 cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) 44 45 #define put_user_u32(val, addr) \ 46 ({ uint32_t val_ = tswap32(val); \ 47 cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) 48 49 #define put_user_ual(arg, p) put_user_u32(arg, p) 50 51 void *uaccess_lock_user(CPUArchState *env, target_ulong addr, 52 target_ulong len, bool copy); 53 #define lock_user(type, p, len, copy) uaccess_lock_user(env, p, len, copy) 54 55 char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr); 56 #define lock_user_string(p) uaccess_lock_user_string(env, p) 57 58 void uaccess_unlock_user(CPUArchState *env, void *p, 59 target_ulong addr, target_ulong len); 60 #define unlock_user(s, args, len) uaccess_unlock_user(env, s, args, len) 61 62 ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr); 63 #define target_strlen(p) uaccess_strlen_user(env, p) 64 65 #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ 66