xref: /openbmc/qemu/include/semihosting/uaccess.h (revision ed75658a)
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 "cpu.h"
18 
19 #define get_user_u64(val, addr)                                         \
20     ({ uint64_t val_ = 0;                                               \
21        int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr),             \
22                                       &val_, sizeof(val_), 0);          \
23        (val) = tswap64(val_); ret_; })
24 
25 #define get_user_u32(val, addr)                                         \
26     ({ uint32_t val_ = 0;                                               \
27        int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr),             \
28                                       &val_, sizeof(val_), 0);          \
29        (val) = tswap32(val_); ret_; })
30 
31 #define get_user_u8(val, addr)                                          \
32     ({ uint8_t val_ = 0;                                                \
33        int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr),             \
34                                       &val_, sizeof(val_), 0);          \
35        (val) = val_; ret_; })
36 
37 #define get_user_ual(arg, p) get_user_u32(arg, p)
38 
39 #define put_user_u64(val, addr)                                         \
40     ({ uint64_t val_ = tswap64(val);                                    \
41        cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
42 
43 #define put_user_u32(val, addr)                                         \
44     ({ uint32_t val_ = tswap32(val);                                    \
45        cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
46 
47 #define put_user_ual(arg, p) put_user_u32(arg, p)
48 
49 void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
50                         target_ulong len, bool copy);
51 #define lock_user(type, p, len, copy) uaccess_lock_user(env, p, len, copy)
52 
53 char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
54 #define lock_user_string(p) uaccess_lock_user_string(env, p)
55 
56 void uaccess_unlock_user(CPUArchState *env, void *p,
57                          target_ulong addr, target_ulong len);
58 #define unlock_user(s, args, len) uaccess_unlock_user(env, s, args, len)
59 
60 ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr);
61 #define target_strlen(p) uaccess_strlen_user(env, p)
62 
63 #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */
64