qga: fixed versions for guest bus types in qapi-schema
[qemu.git] / include / exec / softmmu-semi.h
blob1819cc24985f1f033abeca0324cd527fcfc8d23e
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 */
9 #ifndef SOFTMMU_SEMI_H
10 #define SOFTMMU_SEMI_H 1
12 static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr)
14 uint32_t val;
16 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 0);
17 return tswap32(val);
19 static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr)
21 uint8_t val;
23 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &val, 1, 0);
24 return val;
27 #define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; })
28 #define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; })
29 #define get_user_ual(arg, p) get_user_u32(arg, p)
31 static inline void softmmu_tput32(CPUArchState *env,
32 target_ulong addr, uint32_t val)
34 val = tswap32(val);
35 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 1);
37 #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
38 #define put_user_ual(arg, p) put_user_u32(arg, p)
40 static void *softmmu_lock_user(CPUArchState *env,
41 target_ulong addr, target_ulong len, int copy)
43 uint8_t *p;
44 /* TODO: Make this something that isn't fixed size. */
45 p = malloc(len);
46 if (p && copy) {
47 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 0);
49 return p;
51 #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
52 static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
54 char *p;
55 char *s;
56 uint8_t c;
57 /* TODO: Make this something that isn't fixed size. */
58 s = p = malloc(1024);
59 if (!s) {
60 return NULL;
62 do {
63 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &c, 1, 0);
64 addr++;
65 *(p++) = c;
66 } while (c);
67 return s;
69 #define lock_user_string(p) softmmu_lock_user_string(env, p)
70 static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr,
71 target_ulong len)
73 if (len) {
74 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 1);
76 free(p);
78 #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
80 #endif