blob: fc4f57a64478d17863a8dedaff60782b00ec8908 [file] [log] [blame]
j_mayer4c9649a2007-04-05 06:58:33 +00001/*
Richard Hendersonc3082752012-03-24 09:51:13 -07002 * Helpers for loads and stores
ths5fafdf22007-09-16 21:08:06 +00003 *
j_mayer4c9649a2007-04-05 06:58:33 +00004 * Copyright (c) 2007 Jocelyn Mayer
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
j_mayer4c9649a2007-04-05 06:58:33 +000018 */
19
Blue Swirl3e457172011-07-13 12:44:15 +000020#include "cpu.h"
Richard Henderson2ef61752014-04-07 22:31:41 -070021#include "exec/helper-proto.h"
Paolo Bonzinif08b6172014-03-28 19:42:10 +010022#include "exec/cpu_ldst.h"
j_mayer4c9649a2007-04-05 06:58:33 +000023
j_mayer4c9649a2007-04-05 06:58:33 +000024/* Softmmu support */
Richard Hendersonc3082752012-03-24 09:51:13 -070025#ifndef CONFIG_USER_ONLY
26
Edgar E. Iglesiasfdfba1a2013-11-15 14:46:38 +010027uint64_t helper_ldl_phys(CPUAlphaState *env, uint64_t p)
j_mayer4c9649a2007-04-05 06:58:33 +000028{
Andreas Färberd2810ff2014-03-09 18:58:57 +010029 CPUState *cs = CPU(alpha_env_get_cpu(env));
Edgar E. Iglesiasfdfba1a2013-11-15 14:46:38 +010030 return (int32_t)ldl_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070031}
j_mayer4c9649a2007-04-05 06:58:33 +000032
Edgar E. Iglesias2c174492013-12-17 14:05:40 +100033uint64_t helper_ldq_phys(CPUAlphaState *env, uint64_t p)
Richard Henderson2374e732011-05-20 13:04:35 -070034{
Andreas Färberd2810ff2014-03-09 18:58:57 +010035 CPUState *cs = CPU(alpha_env_get_cpu(env));
Edgar E. Iglesias2c174492013-12-17 14:05:40 +100036 return ldq_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070037}
38
Richard Hendersonc3082752012-03-24 09:51:13 -070039uint64_t helper_ldl_l_phys(CPUAlphaState *env, uint64_t p)
Richard Henderson2374e732011-05-20 13:04:35 -070040{
Andreas Färberd2810ff2014-03-09 18:58:57 +010041 CPUState *cs = CPU(alpha_env_get_cpu(env));
Richard Henderson2374e732011-05-20 13:04:35 -070042 env->lock_addr = p;
Edgar E. Iglesiasfdfba1a2013-11-15 14:46:38 +010043 return env->lock_value = (int32_t)ldl_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070044}
45
Richard Hendersonc3082752012-03-24 09:51:13 -070046uint64_t helper_ldq_l_phys(CPUAlphaState *env, uint64_t p)
Richard Henderson2374e732011-05-20 13:04:35 -070047{
Andreas Färberd2810ff2014-03-09 18:58:57 +010048 CPUState *cs = CPU(alpha_env_get_cpu(env));
Richard Henderson2374e732011-05-20 13:04:35 -070049 env->lock_addr = p;
Edgar E. Iglesias2c174492013-12-17 14:05:40 +100050 return env->lock_value = ldq_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070051}
52
Edgar E. Iglesiasab1da852013-12-17 15:07:29 +100053void helper_stl_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
Richard Henderson2374e732011-05-20 13:04:35 -070054{
Andreas Färberd2810ff2014-03-09 18:58:57 +010055 CPUState *cs = CPU(alpha_env_get_cpu(env));
Edgar E. Iglesiasab1da852013-12-17 15:07:29 +100056 stl_phys(cs->as, p, v);
Richard Henderson2374e732011-05-20 13:04:35 -070057}
58
Edgar E. Iglesiasf6066042013-11-28 00:11:44 +010059void helper_stq_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
Richard Henderson2374e732011-05-20 13:04:35 -070060{
Andreas Färberd2810ff2014-03-09 18:58:57 +010061 CPUState *cs = CPU(alpha_env_get_cpu(env));
Edgar E. Iglesiasf6066042013-11-28 00:11:44 +010062 stq_phys(cs->as, p, v);
Richard Henderson2374e732011-05-20 13:04:35 -070063}
64
Richard Hendersonc3082752012-03-24 09:51:13 -070065uint64_t helper_stl_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
Richard Henderson2374e732011-05-20 13:04:35 -070066{
Andreas Färberd2810ff2014-03-09 18:58:57 +010067 CPUState *cs = CPU(alpha_env_get_cpu(env));
Richard Henderson2374e732011-05-20 13:04:35 -070068 uint64_t ret = 0;
69
70 if (p == env->lock_addr) {
Edgar E. Iglesiasfdfba1a2013-11-15 14:46:38 +010071 int32_t old = ldl_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070072 if (old == (int32_t)env->lock_value) {
Edgar E. Iglesiasab1da852013-12-17 15:07:29 +100073 stl_phys(cs->as, p, v);
Richard Henderson2374e732011-05-20 13:04:35 -070074 ret = 1;
75 }
j_mayer4c9649a2007-04-05 06:58:33 +000076 }
Richard Henderson2374e732011-05-20 13:04:35 -070077 env->lock_addr = -1;
aurel328bb6e982008-09-30 06:45:44 +000078
79 return ret;
80}
81
Richard Hendersonc3082752012-03-24 09:51:13 -070082uint64_t helper_stq_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
aurel328bb6e982008-09-30 06:45:44 +000083{
Andreas Färberd2810ff2014-03-09 18:58:57 +010084 CPUState *cs = CPU(alpha_env_get_cpu(env));
Richard Henderson2374e732011-05-20 13:04:35 -070085 uint64_t ret = 0;
aurel328bb6e982008-09-30 06:45:44 +000086
Richard Henderson2374e732011-05-20 13:04:35 -070087 if (p == env->lock_addr) {
Edgar E. Iglesias2c174492013-12-17 14:05:40 +100088 uint64_t old = ldq_phys(cs->as, p);
Richard Henderson2374e732011-05-20 13:04:35 -070089 if (old == env->lock_value) {
Edgar E. Iglesiasf6066042013-11-28 00:11:44 +010090 stq_phys(cs->as, p, v);
Richard Henderson2374e732011-05-20 13:04:35 -070091 ret = 1;
92 }
93 }
94 env->lock_addr = -1;
aurel328bb6e982008-09-30 06:45:44 +000095
96 return ret;
j_mayer4c9649a2007-04-05 06:58:33 +000097}
98
Paolo Bonzini93e22322014-03-28 18:14:58 +010099void alpha_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
100 int is_write, int is_user, uintptr_t retaddr)
Richard Henderson5b450402011-04-18 16:13:12 -0700101{
Paolo Bonzini93e22322014-03-28 18:14:58 +0100102 AlphaCPU *cpu = ALPHA_CPU(cs);
103 CPUAlphaState *env = &cpu->env;
Richard Henderson5b450402011-04-18 16:13:12 -0700104 uint64_t pc;
105 uint32_t insn;
106
Blue Swirla8a826a2012-12-04 20:16:07 +0000107 if (retaddr) {
Andreas Färber3f38f302013-09-01 16:51:34 +0200108 cpu_restore_state(cs, retaddr);
Blue Swirla8a826a2012-12-04 20:16:07 +0000109 }
Richard Henderson5b450402011-04-18 16:13:12 -0700110
111 pc = env->pc;
Richard Hendersonc3082752012-03-24 09:51:13 -0700112 insn = cpu_ldl_code(env, pc);
Richard Henderson5b450402011-04-18 16:13:12 -0700113
114 env->trap_arg0 = addr;
115 env->trap_arg1 = insn >> 26; /* opcode */
116 env->trap_arg2 = (insn >> 21) & 31; /* dest regno */
Andreas Färber27103422013-08-26 08:31:06 +0200117 cs->exception_index = EXCP_UNALIGN;
Richard Hendersonb9f09232012-03-24 09:51:08 -0700118 env->error_code = 0;
Andreas Färber5638d182013-08-27 17:52:12 +0200119 cpu_loop_exit(cs);
Richard Henderson5b450402011-04-18 16:13:12 -0700120}
121
Andreas Färberc658b942013-05-27 06:49:53 +0200122void alpha_cpu_unassigned_access(CPUState *cs, hwaddr addr,
123 bool is_write, bool is_exec, int unused,
124 unsigned size)
Richard Henderson5b450402011-04-18 16:13:12 -0700125{
Andreas Färberc658b942013-05-27 06:49:53 +0200126 AlphaCPU *cpu = ALPHA_CPU(cs);
127 CPUAlphaState *env = &cpu->env;
128
Richard Henderson5b450402011-04-18 16:13:12 -0700129 env->trap_arg0 = addr;
Andreas Färberc658b942013-05-27 06:49:53 +0200130 env->trap_arg1 = is_write ? 1 : 0;
Blue Swirl20503962012-04-09 14:20:20 +0000131 dynamic_excp(env, 0, EXCP_MCHK, 0);
Richard Henderson5b450402011-04-18 16:13:12 -0700132}
133
j_mayer4c9649a2007-04-05 06:58:33 +0000134/* try to fill the TLB and return an exception if error. If retaddr is
135 NULL, it means that the function was called in C code (i.e. not
136 from generated code or from helper.c) */
137/* XXX: fix it to restore all registers */
Andreas Färberd5a11fe2013-08-27 00:28:06 +0200138void tlb_fill(CPUState *cs, target_ulong addr, int is_write,
Blue Swirl20503962012-04-09 14:20:20 +0000139 int mmu_idx, uintptr_t retaddr)
j_mayer4c9649a2007-04-05 06:58:33 +0000140{
j_mayer4c9649a2007-04-05 06:58:33 +0000141 int ret;
142
Andreas Färberd5a11fe2013-08-27 00:28:06 +0200143 ret = alpha_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx);
Richard Henderson2d9671d2011-04-25 12:20:27 -0700144 if (unlikely(ret != 0)) {
Blue Swirla8a826a2012-12-04 20:16:07 +0000145 if (retaddr) {
Andreas Färber3f38f302013-09-01 16:51:34 +0200146 cpu_restore_state(cs, retaddr);
Blue Swirla8a826a2012-12-04 20:16:07 +0000147 }
j_mayer4c9649a2007-04-05 06:58:33 +0000148 /* Exception index and error code are already set */
Andreas Färber5638d182013-08-27 17:52:12 +0200149 cpu_loop_exit(cs);
j_mayer4c9649a2007-04-05 06:58:33 +0000150 }
j_mayer4c9649a2007-04-05 06:58:33 +0000151}
Richard Hendersonc3082752012-03-24 09:51:13 -0700152#endif /* CONFIG_USER_ONLY */