]> git.proxmox.com Git - mirror_qemu.git/blob - include/exec/softmmu-semi.h
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20150907' into...
[mirror_qemu.git] / include / exec / softmmu-semi.h
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 #ifndef SOFTMMU_SEMI_H
10 #define SOFTMMU_SEMI_H 1
11
12 static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr)
13 {
14 uint64_t val;
15
16 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 8, 0);
17 return tswap64(val);
18 }
19
20 static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr)
21 {
22 uint32_t val;
23
24 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 0);
25 return tswap32(val);
26 }
27
28 static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr)
29 {
30 uint8_t val;
31
32 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &val, 1, 0);
33 return val;
34 }
35
36 #define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; })
37 #define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; })
38 #define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; })
39 #define get_user_ual(arg, p) get_user_u32(arg, p)
40
41 static inline void softmmu_tput64(CPUArchState *env,
42 target_ulong addr, uint64_t val)
43 {
44 val = tswap64(val);
45 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 8, 1);
46 }
47
48 static inline void softmmu_tput32(CPUArchState *env,
49 target_ulong addr, uint32_t val)
50 {
51 val = tswap32(val);
52 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 1);
53 }
54 #define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; })
55 #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
56 #define put_user_ual(arg, p) put_user_u32(arg, p)
57
58 static void *softmmu_lock_user(CPUArchState *env,
59 target_ulong addr, target_ulong len, int copy)
60 {
61 uint8_t *p;
62 /* TODO: Make this something that isn't fixed size. */
63 p = malloc(len);
64 if (p && copy) {
65 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 0);
66 }
67 return p;
68 }
69 #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
70 static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
71 {
72 char *p;
73 char *s;
74 uint8_t c;
75 /* TODO: Make this something that isn't fixed size. */
76 s = p = malloc(1024);
77 if (!s) {
78 return NULL;
79 }
80 do {
81 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &c, 1, 0);
82 addr++;
83 *(p++) = c;
84 } while (c);
85 return s;
86 }
87 #define lock_user_string(p) softmmu_lock_user_string(env, p)
88 static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr,
89 target_ulong len)
90 {
91 if (len) {
92 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 1);
93 }
94 free(p);
95 }
96 #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
97
98 #endif