2007-09-17 01:08:06 +04:00
|
|
|
/*
|
2007-05-26 20:46:21 +04:00
|
|
|
* Helper routines to provide target memory access for semihosting
|
|
|
|
* syscalls in system emulation mode.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 CodeSourcery.
|
|
|
|
*
|
2011-06-26 06:21:35 +04:00
|
|
|
* This code is licensed under the GPL
|
2007-05-26 20:46:21 +04:00
|
|
|
*/
|
2016-06-29 16:29:06 +03:00
|
|
|
|
2023-10-04 12:06:23 +03:00
|
|
|
#ifndef SEMIHOSTING_UACCESS_H
|
|
|
|
#define SEMIHOSTING_UACCESS_H
|
|
|
|
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
#error Cannot include semihosting/uaccess.h from user emulation
|
|
|
|
#endif
|
2007-05-26 20:46:21 +04:00
|
|
|
|
2019-08-12 08:23:31 +03:00
|
|
|
#include "cpu.h"
|
|
|
|
|
2022-04-28 06:01:24 +03:00
|
|
|
#define get_user_u64(val, addr) \
|
|
|
|
({ uint64_t val_ = 0; \
|
|
|
|
int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \
|
|
|
|
&val_, sizeof(val_), 0); \
|
|
|
|
(val) = tswap64(val_); ret_; })
|
2015-09-07 12:39:27 +03:00
|
|
|
|
2022-04-28 06:01:24 +03:00
|
|
|
#define get_user_u32(val, addr) \
|
|
|
|
({ uint32_t val_ = 0; \
|
|
|
|
int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \
|
|
|
|
&val_, sizeof(val_), 0); \
|
|
|
|
(val) = tswap32(val_); ret_; })
|
2015-09-07 12:39:27 +03:00
|
|
|
|
2022-04-28 06:01:24 +03:00
|
|
|
#define get_user_u8(val, addr) \
|
|
|
|
({ uint8_t val_ = 0; \
|
|
|
|
int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \
|
|
|
|
&val_, sizeof(val_), 0); \
|
|
|
|
(val) = val_; ret_; })
|
2007-11-16 13:46:05 +03:00
|
|
|
|
|
|
|
#define get_user_ual(arg, p) get_user_u32(arg, p)
|
2007-05-26 20:46:21 +04:00
|
|
|
|
2022-04-28 06:01:24 +03:00
|
|
|
#define put_user_u64(val, addr) \
|
|
|
|
({ uint64_t val_ = tswap64(val); \
|
|
|
|
cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
|
|
|
|
|
|
|
|
#define put_user_u32(val, addr) \
|
|
|
|
({ uint32_t val_ = tswap32(val); \
|
|
|
|
cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
|
2015-09-07 12:39:27 +03:00
|
|
|
|
2007-11-16 13:46:05 +03:00
|
|
|
#define put_user_ual(arg, p) put_user_u32(arg, p)
|
2007-05-26 20:46:21 +04:00
|
|
|
|
2023-10-04 12:06:23 +03:00
|
|
|
void *uaccess_lock_user(CPUArchState *env, target_ulong addr,
|
2022-04-28 06:44:17 +03:00
|
|
|
target_ulong len, bool copy);
|
2023-10-04 12:06:23 +03:00
|
|
|
#define lock_user(type, p, len, copy) uaccess_lock_user(env, p, len, copy)
|
2022-04-28 06:01:24 +03:00
|
|
|
|
2023-10-04 12:06:23 +03:00
|
|
|
char *uaccess_lock_user_string(CPUArchState *env, target_ulong addr);
|
|
|
|
#define lock_user_string(p) uaccess_lock_user_string(env, p)
|
2022-04-28 06:01:24 +03:00
|
|
|
|
2023-10-04 12:06:23 +03:00
|
|
|
void uaccess_unlock_user(CPUArchState *env, void *p,
|
2022-04-28 06:44:17 +03:00
|
|
|
target_ulong addr, target_ulong len);
|
2023-10-04 12:06:23 +03:00
|
|
|
#define unlock_user(s, args, len) uaccess_unlock_user(env, s, args, len)
|
2012-12-06 15:15:58 +04:00
|
|
|
|
2023-10-04 12:06:23 +03:00
|
|
|
ssize_t uaccess_strlen_user(CPUArchState *env, target_ulong addr);
|
|
|
|
#define target_strlen(p) uaccess_strlen_user(env, p)
|
2022-04-28 07:03:12 +03:00
|
|
|
|
2022-04-28 06:48:41 +03:00
|
|
|
#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */
|