root / softmmu-semi.h @ efe75411
History | View | Annotate | Download (1.8 kB)
1 | 6b3a45cc | pbrook | /*
|
---|---|---|---|
2 | 6b3a45cc | pbrook | * Helper routines to provide target memory access for semihosting
|
3 | 6b3a45cc | pbrook | * syscalls in system emulation mode.
|
4 | 6b3a45cc | pbrook | *
|
5 | 6b3a45cc | pbrook | * Copyright (c) 2007 CodeSourcery.
|
6 | 6b3a45cc | pbrook | *
|
7 | 6b3a45cc | pbrook | * This code is licenced under the GPL
|
8 | 6b3a45cc | pbrook | */
|
9 | 6b3a45cc | pbrook | |
10 | 6b3a45cc | pbrook | static inline uint32_t softmmu_tget32(CPUState *env, uint32_t addr) |
11 | 6b3a45cc | pbrook | { |
12 | 6b3a45cc | pbrook | uint32_t val; |
13 | 6b3a45cc | pbrook | |
14 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 0); |
15 | 6b3a45cc | pbrook | return tswap32(val);
|
16 | 6b3a45cc | pbrook | } |
17 | 6b3a45cc | pbrook | static inline uint32_t softmmu_tget8(CPUState *env, uint32_t addr) |
18 | 6b3a45cc | pbrook | { |
19 | 6b3a45cc | pbrook | uint8_t val; |
20 | 6b3a45cc | pbrook | |
21 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, &val, 1, 0); |
22 | 6b3a45cc | pbrook | return val;
|
23 | 6b3a45cc | pbrook | } |
24 | 6b3a45cc | pbrook | #define tget32(p) softmmu_tget32(env, p)
|
25 | 6b3a45cc | pbrook | #define tget8(p) softmmu_tget8(env, p)
|
26 | 6b3a45cc | pbrook | |
27 | 6b3a45cc | pbrook | static inline void softmmu_tput32(CPUState *env, uint32_t addr, uint32_t val) |
28 | 6b3a45cc | pbrook | { |
29 | 6b3a45cc | pbrook | val = tswap32(val); |
30 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 1); |
31 | 6b3a45cc | pbrook | } |
32 | 6b3a45cc | pbrook | #define tput32(p, val) softmmu_tput32(env, p, val)
|
33 | 6b3a45cc | pbrook | |
34 | 6b3a45cc | pbrook | static void *softmmu_lock_user(CPUState *env, uint32_t addr, uint32_t len, |
35 | 6b3a45cc | pbrook | int copy)
|
36 | 6b3a45cc | pbrook | { |
37 | 6b3a45cc | pbrook | char *p;
|
38 | 6b3a45cc | pbrook | /* TODO: Make this something that isn't fixed size. */
|
39 | 6b3a45cc | pbrook | p = malloc(len); |
40 | 6b3a45cc | pbrook | if (copy)
|
41 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, p, len, 0);
|
42 | 6b3a45cc | pbrook | return p;
|
43 | 6b3a45cc | pbrook | } |
44 | 6b3a45cc | pbrook | #define lock_user(p, len, copy) softmmu_lock_user(env, p, len, copy)
|
45 | 6b3a45cc | pbrook | static char *softmmu_lock_user_string(CPUState *env, uint32_t addr) |
46 | 6b3a45cc | pbrook | { |
47 | 6b3a45cc | pbrook | char *p;
|
48 | 6b3a45cc | pbrook | char *s;
|
49 | 6b3a45cc | pbrook | uint8_t c; |
50 | 6b3a45cc | pbrook | /* TODO: Make this something that isn't fixed size. */
|
51 | 6b3a45cc | pbrook | s = p = malloc(1024);
|
52 | 6b3a45cc | pbrook | do {
|
53 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, &c, 1, 0); |
54 | 6b3a45cc | pbrook | addr++; |
55 | 6b3a45cc | pbrook | *(p++) = c; |
56 | 6b3a45cc | pbrook | } while (c);
|
57 | 6b3a45cc | pbrook | return s;
|
58 | 6b3a45cc | pbrook | } |
59 | 6b3a45cc | pbrook | #define lock_user_string(p) softmmu_lock_user_string(env, p)
|
60 | 6b3a45cc | pbrook | static void softmmu_unlock_user(CPUState *env, void *p, target_ulong addr, |
61 | 6b3a45cc | pbrook | target_ulong len) |
62 | 6b3a45cc | pbrook | { |
63 | 6b3a45cc | pbrook | if (len)
|
64 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, p, len, 1);
|
65 | 6b3a45cc | pbrook | free(p); |
66 | 6b3a45cc | pbrook | } |
67 | 6b3a45cc | pbrook | #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) |