mem_helper.c 3.7 KB
Newer Older
J
j_mayer 已提交
1
/*
2
 *  Helpers for loads and stores
3
 *
J
j_mayer 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16
 *  Copyright (c) 2007 Jocelyn Mayer
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
J
j_mayer 已提交
18 19
 */

B
Blue Swirl 已提交
20
#include "cpu.h"
P
pbrook 已提交
21
#include "helper.h"
J
j_mayer 已提交
22 23 24


/* Softmmu support */
25 26
#ifndef CONFIG_USER_ONLY

27
uint64_t helper_ldl_phys(uint64_t p)
28
{
29
    return (int32_t)ldl_phys(p);
30 31
}

32
uint64_t helper_ldq_phys(uint64_t p)
33
{
34
    return ldq_phys(p);
35 36
}

37
uint64_t helper_ldl_l_phys(CPUAlphaState *env, uint64_t p)
38
{
39 40
    env->lock_addr = p;
    return env->lock_value = (int32_t)ldl_phys(p);
41 42
}

43
uint64_t helper_ldq_l_phys(CPUAlphaState *env, uint64_t p)
44
{
45
    env->lock_addr = p;
46
    return env->lock_value = ldq_phys(p);
47 48
}

49
void helper_stl_phys(uint64_t p, uint64_t v)
50
{
51
    stl_phys(p, v);
52 53
}

54
void helper_stq_phys(uint64_t p, uint64_t v)
55
{
56
    stq_phys(p, v);
57 58
}

59
uint64_t helper_stl_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
60
{
61
    uint64_t ret = 0;
62

63 64 65 66 67 68 69 70
    if (p == env->lock_addr) {
        int32_t old = ldl_phys(p);
        if (old == (int32_t)env->lock_value) {
            stl_phys(p, v);
            ret = 1;
        }
    }
    env->lock_addr = -1;
71 72 73 74

    return ret;
}

75
uint64_t helper_stq_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
76
{
77
    uint64_t ret = 0;
78

79 80 81 82 83 84 85 86
    if (p == env->lock_addr) {
        uint64_t old = ldq_phys(p);
        if (old == env->lock_value) {
            stq_phys(p, v);
            ret = 1;
        }
    }
    env->lock_addr = -1;
87 88

    return ret;
J
j_mayer 已提交
89 90
}

91
static void do_unaligned_access(CPUAlphaState *env, target_ulong addr,
92
                                int is_write, int is_user, uintptr_t retaddr)
93 94 95 96
{
    uint64_t pc;
    uint32_t insn;

B
Blue Swirl 已提交
97 98 99
    if (retaddr) {
        cpu_restore_state(env, retaddr);
    }
100 101

    pc = env->pc;
102
    insn = cpu_ldl_code(env, pc);
103 104 105 106

    env->trap_arg0 = addr;
    env->trap_arg1 = insn >> 26;                /* opcode */
    env->trap_arg2 = (insn >> 21) & 31;         /* dest regno */
107 108 109
    env->exception_index = EXCP_UNALIGN;
    env->error_code = 0;
    cpu_loop_exit(env);
110 111
}

A
Avi Kivity 已提交
112
void cpu_unassigned_access(CPUAlphaState *env, hwaddr addr,
113
                           int is_write, int is_exec, int unused, int size)
114 115 116
{
    env->trap_arg0 = addr;
    env->trap_arg1 = is_write;
117
    dynamic_excp(env, 0, EXCP_MCHK, 0);
118 119
}

120
#include "exec/softmmu_exec.h"
B
Blue Swirl 已提交
121

J
j_mayer 已提交
122
#define MMUSUFFIX _mmu
123
#define ALIGNED_ONLY
J
j_mayer 已提交
124 125

#define SHIFT 0
126
#include "exec/softmmu_template.h"
J
j_mayer 已提交
127 128

#define SHIFT 1
129
#include "exec/softmmu_template.h"
J
j_mayer 已提交
130 131

#define SHIFT 2
132
#include "exec/softmmu_template.h"
J
j_mayer 已提交
133 134

#define SHIFT 3
135
#include "exec/softmmu_template.h"
J
j_mayer 已提交
136 137 138 139 140

/* try to fill the TLB and return an exception if error. If retaddr is
   NULL, it means that the function was called in C code (i.e. not
   from generated code or from helper.c) */
/* XXX: fix it to restore all registers */
141
void tlb_fill(CPUAlphaState *env, target_ulong addr, int is_write,
142
              int mmu_idx, uintptr_t retaddr)
J
j_mayer 已提交
143 144 145
{
    int ret;

146
    ret = cpu_alpha_handle_mmu_fault(env, addr, is_write, mmu_idx);
147
    if (unlikely(ret != 0)) {
B
Blue Swirl 已提交
148 149 150
        if (retaddr) {
            cpu_restore_state(env, retaddr);
        }
J
j_mayer 已提交
151
        /* Exception index and error code are already set */
B
Blue Swirl 已提交
152
        cpu_loop_exit(env);
J
j_mayer 已提交
153 154
    }
}
155
#endif /* CONFIG_USER_ONLY */