qemu/include/exec/softmmu-semi.h
<<
>>
Prefs
   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
  10#ifndef SOFTMMU_SEMI_H
  11#define SOFTMMU_SEMI_H
  12
  13static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr)
  14{
  15    uint64_t val;
  16
  17    cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 0);
  18    return tswap64(val);
  19}
  20
  21static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr)
  22{
  23    uint32_t val;
  24
  25    cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 0);
  26    return tswap32(val);
  27}
  28
  29static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr)
  30{
  31    uint8_t val;
  32
  33    cpu_memory_rw_debug(env_cpu(env), addr, &val, 1, 0);
  34    return val;
  35}
  36
  37#define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; })
  38#define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; })
  39#define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; })
  40#define get_user_ual(arg, p) get_user_u32(arg, p)
  41
  42static inline void softmmu_tput64(CPUArchState *env,
  43                                  target_ulong addr, uint64_t val)
  44{
  45    val = tswap64(val);
  46    cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1);
  47}
  48
  49static inline void softmmu_tput32(CPUArchState *env,
  50                                  target_ulong addr, uint32_t val)
  51{
  52    val = tswap32(val);
  53    cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 1);
  54}
  55#define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; })
  56#define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
  57#define put_user_ual(arg, p) put_user_u32(arg, p)
  58
  59static void *softmmu_lock_user(CPUArchState *env,
  60                               target_ulong addr, target_ulong len, int copy)
  61{
  62    uint8_t *p;
  63    /* TODO: Make this something that isn't fixed size.  */
  64    p = malloc(len);
  65    if (p && copy) {
  66        cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0);
  67    }
  68    return p;
  69}
  70#define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
  71static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
  72{
  73    char *p;
  74    char *s;
  75    uint8_t c;
  76    /* TODO: Make this something that isn't fixed size.  */
  77    s = p = malloc(1024);
  78    if (!s) {
  79        return NULL;
  80    }
  81    do {
  82        cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0);
  83        addr++;
  84        *(p++) = c;
  85    } while (c);
  86    return s;
  87}
  88#define lock_user_string(p) softmmu_lock_user_string(env, p)
  89static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr,
  90                                target_ulong len)
  91{
  92    if (len) {
  93        cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
  94    }
  95    free(p);
  96}
  97#define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len)
  98
  99#endif
 100