root / softmmu-semi.h @ 0dcda9be
History | View | Annotate | Download (2 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
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 | 2f619698 | bellard | |
25 | 2f619698 | bellard | #define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; }) |
26 | 2f619698 | bellard | #define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; }) |
27 | 2f619698 | bellard | #define get_user_ual(arg, p) get_user_u32(arg, p)
|
28 | 6b3a45cc | pbrook | |
29 | 6b3a45cc | pbrook | static inline void softmmu_tput32(CPUState *env, uint32_t addr, uint32_t val) |
30 | 6b3a45cc | pbrook | { |
31 | 6b3a45cc | pbrook | val = tswap32(val); |
32 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 1); |
33 | 6b3a45cc | pbrook | } |
34 | 2f619698 | bellard | #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; }) |
35 | 2f619698 | bellard | #define put_user_ual(arg, p) put_user_u32(arg, p)
|
36 | 6b3a45cc | pbrook | |
37 | 6b3a45cc | pbrook | static void *softmmu_lock_user(CPUState *env, uint32_t addr, uint32_t len, |
38 | 6b3a45cc | pbrook | int copy)
|
39 | 6b3a45cc | pbrook | { |
40 | 6b3a45cc | pbrook | char *p;
|
41 | 6b3a45cc | pbrook | /* TODO: Make this something that isn't fixed size. */
|
42 | 6b3a45cc | pbrook | p = malloc(len); |
43 | 6b3a45cc | pbrook | if (copy)
|
44 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, p, len, 0);
|
45 | 6b3a45cc | pbrook | return p;
|
46 | 6b3a45cc | pbrook | } |
47 | 579a97f7 | bellard | #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
|
48 | 6b3a45cc | pbrook | static char *softmmu_lock_user_string(CPUState *env, uint32_t addr) |
49 | 6b3a45cc | pbrook | { |
50 | 6b3a45cc | pbrook | char *p;
|
51 | 6b3a45cc | pbrook | char *s;
|
52 | 6b3a45cc | pbrook | uint8_t c; |
53 | 6b3a45cc | pbrook | /* TODO: Make this something that isn't fixed size. */
|
54 | 6b3a45cc | pbrook | s = p = malloc(1024);
|
55 | 6b3a45cc | pbrook | do {
|
56 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, &c, 1, 0); |
57 | 6b3a45cc | pbrook | addr++; |
58 | 6b3a45cc | pbrook | *(p++) = c; |
59 | 6b3a45cc | pbrook | } while (c);
|
60 | 6b3a45cc | pbrook | return s;
|
61 | 6b3a45cc | pbrook | } |
62 | 6b3a45cc | pbrook | #define lock_user_string(p) softmmu_lock_user_string(env, p)
|
63 | 6b3a45cc | pbrook | static void softmmu_unlock_user(CPUState *env, void *p, target_ulong addr, |
64 | 6b3a45cc | pbrook | target_ulong len) |
65 | 6b3a45cc | pbrook | { |
66 | 6b3a45cc | pbrook | if (len)
|
67 | 6b3a45cc | pbrook | cpu_memory_rw_debug(env, addr, p, len, 1);
|
68 | 6b3a45cc | pbrook | free(p); |
69 | 6b3a45cc | pbrook | } |
70 | 6b3a45cc | pbrook | #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) |