Statistics
| Branch: | Revision:

root / softmmu-semi.h @ 5fafdf24

History | View | Annotate | Download (1.8 kB)

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 licenced under the GPL
8
 */
9

    
10
static inline uint32_t softmmu_tget32(CPUState *env, uint32_t addr)
11
{
12
    uint32_t val;
13

    
14
    cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 0);
15
    return tswap32(val);
16
}
17
static inline uint32_t softmmu_tget8(CPUState *env, uint32_t addr)
18
{
19
    uint8_t val;
20

    
21
    cpu_memory_rw_debug(env, addr, &val, 1, 0);
22
    return val;
23
}
24
#define tget32(p) softmmu_tget32(env, p)
25
#define tget8(p) softmmu_tget8(env, p)
26

    
27
static inline void softmmu_tput32(CPUState *env, uint32_t addr, uint32_t val)
28
{
29
    val = tswap32(val);
30
    cpu_memory_rw_debug(env, addr, (uint8_t *)&val, 4, 1);
31
}
32
#define tput32(p, val) softmmu_tput32(env, p, val)
33

    
34
static void *softmmu_lock_user(CPUState *env, uint32_t addr, uint32_t len,
35
                               int copy)
36
{
37
    char *p;
38
    /* TODO: Make this something that isn't fixed size.  */
39
    p = malloc(len);
40
    if (copy)
41
        cpu_memory_rw_debug(env, addr, p, len, 0);
42
    return p;
43
}
44
#define lock_user(p, len, copy) softmmu_lock_user(env, p, len, copy)
45
static char *softmmu_lock_user_string(CPUState *env, uint32_t addr)
46
{
47
    char *p;
48
    char *s;
49
    uint8_t c;
50
    /* TODO: Make this something that isn't fixed size.  */
51
    s = p = malloc(1024);
52
    do {
53
        cpu_memory_rw_debug(env, addr, &c, 1, 0);
54
        addr++;
55
        *(p++) = c;
56
    } while (c);
57
    return s;
58
}
59
#define lock_user_string(p) softmmu_lock_user_string(env, p)
60
static void softmmu_unlock_user(CPUState *env, void *p, target_ulong addr,
61
                                target_ulong len)
62
{
63
    if (len)
64
        cpu_memory_rw_debug(env, addr, p, len, 1);
65
    free(p);
66
}
67
#define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)