monitor: Fix tracepoint crash on JSON syntax error
[qemu/armbru.git] / include / exec / softmmu-semi.h
blob7eefad8f391cae9d525862badc60984e3808a446
1 /*
2 * Helper routines to provide target memory access for semihosting
3 * syscalls in system emulation mode.
5 * Copyright (c) 2007 CodeSourcery.
7 * This code is licensed under the GPL
8 */
10 #ifndef SOFTMMU_SEMI_H
11 #define SOFTMMU_SEMI_H
13 static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr)
15 uint64_t val;
17 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 8, 0);
18 return tswap64(val);
21 static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr)
23 uint32_t val;
25 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 0);
26 return tswap32(val);
29 static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr)
31 uint8_t val;
33 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &val, 1, 0);
34 return val;
37 #define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; })
38 #define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; })
39 #define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; })
40 #define get_user_ual(arg, p) get_user_u32(arg, p)
42 static inline void softmmu_tput64(CPUArchState *env,
43 target_ulong addr, uint64_t val)
45 val = tswap64(val);
46 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 8, 1);
49 static inline void softmmu_tput32(CPUArchState *env,
50 target_ulong addr, uint32_t val)
52 val = tswap32(val);
53 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 1);
55 #define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; })
56 #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
57 #define put_user_ual(arg, p) put_user_u32(arg, p)
59 static void *softmmu_lock_user(CPUArchState *env,
60 target_ulong addr, target_ulong len, int copy)
62 uint8_t *p;
63 /* TODO: Make this something that isn't fixed size. */
64 p = malloc(len);
65 if (p && copy) {
66 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 0);
68 return p;
70 #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
71 static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
73 char *p;
74 char *s;
75 uint8_t c;
76 /* TODO: Make this something that isn't fixed size. */
77 s = p = malloc(1024);
78 if (!s) {
79 return NULL;
81 do {
82 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &c, 1, 0);
83 addr++;
84 *(p++) = c;
85 } while (c);
86 return s;
88 #define lock_user_string(p) softmmu_lock_user_string(env, p)
89 static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr,
90 target_ulong len)
92 if (len) {
93 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 1);
95 free(p);
97 #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
99 #endif