]> git.proxmox.com Git - mirror_qemu.git/blob - include/exec/softmmu-semi.h
Merge branch 'master' of git://git.qemu.org/qemu into prep-up
[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 uint32_t softmmu_tget32(CPUArchState *env, uint32_t addr)
13 {
14 uint32_t val;
15
16 cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 0);
17 return tswap32(val);
18 }
19 static inline uint32_t softmmu_tget8(CPUArchState *env, uint32_t addr)
20 {
21 uint8_t val;
22
23 cpu_memory_rw_debug(env, addr, &val, 1, 0);
24 return val;
25 }
26
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)
30
31 static inline void softmmu_tput32(CPUArchState *env, uint32_t addr, uint32_t val)
32 {
33 val = tswap32(val);
34 cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 1);
35 }
36 #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
37 #define put_user_ual(arg, p) put_user_u32(arg, p)
38
39 static void *softmmu_lock_user(CPUArchState *env, uint32_t addr, uint32_t len,
40 int copy)
41 {
42 uint8_t *p;
43 /* TODO: Make this something that isn't fixed size. */
44 p = malloc(len);
45 if (p && copy)
46 cpu_memory_rw_debug(env, addr, p, len, 0);
47 return p;
48 }
49 #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
50 static char *softmmu_lock_user_string(CPUArchState *env, uint32_t addr)
51 {
52 char *p;
53 char *s;
54 uint8_t c;
55 /* TODO: Make this something that isn't fixed size. */
56 s = p = malloc(1024);
57 if (!s) {
58 return NULL;
59 }
60 do {
61 cpu_memory_rw_debug(env, addr, &c, 1, 0);
62 addr++;
63 *(p++) = c;
64 } while (c);
65 return s;
66 }
67 #define lock_user_string(p) softmmu_lock_user_string(env, p)
68 static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr,
69 target_ulong len)
70 {
71 if (len)
72 cpu_memory_rw_debug(env, addr, p, len, 1);
73 free(p);
74 }
75 #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
76
77 #endif