]>
Commit | Line | Data |
---|---|---|
5fafdf24 | 1 | /* |
6b3a45cc PB |
2 | * Helper routines to provide target memory access for semihosting |
3 | * syscalls in system emulation mode. | |
4 | * | |
5 | * Copyright (c) 2007 CodeSourcery. | |
6 | * | |
8e31bf38 | 7 | * This code is licensed under the GPL |
6b3a45cc | 8 | */ |
cb9c377f PB |
9 | #ifndef SOFTMMU_SEMI_H |
10 | #define SOFTMMU_SEMI_H 1 | |
6b3a45cc | 11 | |
9349b4f9 | 12 | static inline uint32_t softmmu_tget32(CPUArchState *env, uint32_t addr) |
6b3a45cc PB |
13 | { |
14 | uint32_t val; | |
15 | ||
f17ec444 | 16 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 0); |
6b3a45cc PB |
17 | return tswap32(val); |
18 | } | |
9349b4f9 | 19 | static inline uint32_t softmmu_tget8(CPUArchState *env, uint32_t addr) |
6b3a45cc PB |
20 | { |
21 | uint8_t val; | |
22 | ||
f17ec444 | 23 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &val, 1, 0); |
6b3a45cc PB |
24 | return val; |
25 | } | |
2f619698 FB |
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) | |
6b3a45cc | 30 | |
9349b4f9 | 31 | static inline void softmmu_tput32(CPUArchState *env, uint32_t addr, uint32_t val) |
6b3a45cc PB |
32 | { |
33 | val = tswap32(val); | |
f17ec444 | 34 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 1); |
6b3a45cc | 35 | } |
2f619698 FB |
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) | |
6b3a45cc | 38 | |
9349b4f9 | 39 | static void *softmmu_lock_user(CPUArchState *env, uint32_t addr, uint32_t len, |
6b3a45cc PB |
40 | int copy) |
41 | { | |
b55266b5 | 42 | uint8_t *p; |
6b3a45cc PB |
43 | /* TODO: Make this something that isn't fixed size. */ |
44 | p = malloc(len); | |
f17ec444 AF |
45 | if (p && copy) { |
46 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 0); | |
47 | } | |
6b3a45cc PB |
48 | return p; |
49 | } | |
579a97f7 | 50 | #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) |
9349b4f9 | 51 | static char *softmmu_lock_user_string(CPUArchState *env, uint32_t addr) |
6b3a45cc PB |
52 | { |
53 | char *p; | |
54 | char *s; | |
55 | uint8_t c; | |
56 | /* TODO: Make this something that isn't fixed size. */ | |
57 | s = p = malloc(1024); | |
15d9e3bc JM |
58 | if (!s) { |
59 | return NULL; | |
60 | } | |
6b3a45cc | 61 | do { |
f17ec444 | 62 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, &c, 1, 0); |
6b3a45cc PB |
63 | addr++; |
64 | *(p++) = c; | |
65 | } while (c); | |
66 | return s; | |
67 | } | |
68 | #define lock_user_string(p) softmmu_lock_user_string(env, p) | |
9349b4f9 | 69 | static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, |
6b3a45cc PB |
70 | target_ulong len) |
71 | { | |
f17ec444 AF |
72 | if (len) { |
73 | cpu_memory_rw_debug(ENV_GET_CPU(env), addr, p, len, 1); | |
74 | } | |
6b3a45cc PB |
75 | free(p); |
76 | } | |
77 | #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) | |
cb9c377f PB |
78 | |
79 | #endif |