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