]>
git.proxmox.com Git - mirror_qemu.git/blob - target-m68k/helper.c
4 * Copyright (c) 2006-2007 CodeSourcery
5 * Written by Paul Brook
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 static m68k_def_t m68k_cpu_defs
[] = {
41 {"m5206", M68K_CPUID_M5206
},
42 {"cfv4e", M68K_CPUID_CFV4E
},
43 {"any", M68K_CPUID_ANY
},
47 static void m68k_set_feature(CPUM68KState
*env
, int feature
)
49 env
->features
|= (1u << feature
);
52 int cpu_m68k_set_model(CPUM68KState
*env
, const char * name
)
56 for (def
= m68k_cpu_defs
; def
->name
; def
++) {
57 if (strcmp(def
->name
, name
) == 0)
64 case M68K_CPUID_M5206
:
65 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
67 case M68K_CPUID_CFV4E
:
68 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
69 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
70 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_C
);
71 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
72 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
75 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_A
);
76 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_B
);
77 m68k_set_feature(env
, M68K_FEATURE_CF_ISA_C
);
78 m68k_set_feature(env
, M68K_FEATURE_CF_FPU
);
79 /* MAC and EMAC are mututally exclusive, so pick EMAC.
80 It's mostly backwards compatible. */
81 m68k_set_feature(env
, M68K_FEATURE_CF_EMAC
);
82 m68k_set_feature(env
, M68K_FEATURE_EXT_FULL
);
86 register_m68k_insns(env
);
91 void cpu_m68k_flush_flags(CPUM68KState
*env
, int cc_op
)
98 #define HIGHBIT 0x80000000u
100 #define SET_NZ(x) do { \
103 else if ((int32_t)(x) < 0) \
107 #define SET_FLAGS_SUB(type, utype) do { \
108 SET_NZ((type)dest); \
110 if ((utype) tmp < (utype) src) \
112 if ((1u << (sizeof(type) * 8 - 1)) & (tmp ^ dest) & (tmp ^ src)) \
131 if (HIGHBIT
& (src
^ dest
) & ~(tmp
^ src
))
135 SET_FLAGS_SUB(int32_t, uint32_t);
138 SET_FLAGS_SUB(int8_t, uint8_t);
141 SET_FLAGS_SUB(int16_t, uint16_t);
147 tmp
= dest
- src
- 1;
148 if (HIGHBIT
& (src
^ dest
) & ~(tmp
^ src
))
153 tmp
= dest
+ src
+ 1;
156 if (HIGHBIT
& (tmp
^ dest
) & (tmp
^ src
))
166 if (src
&& src
<= 32 && (dest
& (1 << (32 - src
))))
176 if (src
&& src
<= 32 && ((dest
>> (src
- 1)) & 1))
183 tmp
= (int32_t)dest
>> src
;
186 if (src
&& src
<= 32 && (((int32_t)dest
>> (src
- 1)) & 1))
190 cpu_abort(env
, "Bad CC_OP %d", cc_op
);
192 env
->cc_op
= CC_OP_FLAGS
;
193 env
->cc_dest
= flags
;
196 float64
helper_sub_cmpf64(CPUM68KState
*env
, float64 src0
, float64 src1
)
198 /* ??? This may incorrectly raise exceptions. */
199 /* ??? Should flush denormals to zero. */
201 res
= float64_sub(src0
, src1
, &env
->fp_status
);
202 if (float64_is_nan(res
)) {
203 /* +/-inf compares equal against itself, but sub returns nan. */
204 if (!float64_is_nan(src0
)
205 && !float64_is_nan(src1
)) {
207 if (float64_lt_quiet(src0
, res
, &env
->fp_status
))
208 res
= float64_chs(res
);
214 void helper_movec(CPUM68KState
*env
, int reg
, uint32_t val
)
217 case 0x02: /* CACR */
220 case 0x801: /* VBR */
223 /* TODO: Implement control registers. */
225 cpu_abort(env
, "Unimplemented control register write 0x%x = 0x%x\n",
230 void m68k_set_macsr(CPUM68KState
*env
, uint32_t val
)
237 if ((env
->macsr
^ val
) & (MACSR_FI
| MACSR_SU
)) {
238 for (i
= 0; i
< 4; i
++) {
239 regval
= env
->macc
[i
];
240 exthigh
= regval
>> 40;
241 if (env
->macsr
& MACSR_FI
) {
246 extlow
= regval
>> 32;
248 if (env
->macsr
& MACSR_FI
) {
249 regval
= (((uint64_t)acc
) << 8) | extlow
;
250 regval
|= ((int64_t)exthigh
) << 40;
251 } else if (env
->macsr
& MACSR_SU
) {
252 regval
= acc
| (((int64_t)extlow
) << 32);
253 regval
|= ((int64_t)exthigh
) << 40;
255 regval
= acc
| (((uint64_t)extlow
) << 32);
256 regval
|= ((uint64_t)(uint8_t)exthigh
) << 40;
258 env
->macc
[i
] = regval
;
266 /* TODO: This will need fixing once the MMU is implemented. */
267 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
272 #if defined(CONFIG_USER_ONLY)
274 int cpu_m68k_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
275 int is_user
, int is_softmmu
)
277 env
->exception_index
= EXCP_ACCESS
;
278 env
->mmu
.ar
= address
;
284 int cpu_m68k_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
285 int is_user
, int is_softmmu
)
289 address
&= TARGET_PAGE_MASK
;
290 prot
= PAGE_READ
| PAGE_WRITE
;
291 return tlb_set_page(env
, address
, address
, prot
, is_user
, is_softmmu
);
294 /* Notify CPU of a pending interrupt. Prioritization and vectoring should
295 be handled by the interrupt controller. Real hardware only requests
296 the vector when the interrupt is acknowledged by the CPU. For
297 simplicitly we calculate it when the interrupt is signalled. */
298 void m68k_set_irq_level(CPUM68KState
*env
, int level
, uint8_t vector
)
300 env
->pending_level
= level
;
301 env
->pending_vector
= vector
;
303 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
305 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);