2 * Copyright (C) 2010-2012 Guan Xuetao
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Contributions from 2012-04-01 on are considered under GPL version 2,
9 * or (at your option) any later version.
12 #include "qemu/osdep.h"
14 #include "exec/exec-all.h"
15 #include "exec/gdbstub.h"
16 #include "exec/helper-proto.h"
17 #include "qemu/host-utils.h"
18 #ifndef CONFIG_USER_ONLY
19 #include "ui/console.h"
25 #define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
27 #define DPRINTF(fmt, ...) do {} while (0)
30 UniCore32CPU
*uc32_cpu_init(const char *cpu_model
)
32 return UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU
, cpu_model
));
35 uint32_t HELPER(clo
)(uint32_t x
)
40 uint32_t HELPER(clz
)(uint32_t x
)
45 #ifndef CONFIG_USER_ONLY
46 void helper_cp0_set(CPUUniCore32State
*env
, uint32_t val
, uint32_t creg
,
49 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
52 * movc pp.nn, rn, #imm9
56 * 2: page table base reg.
57 * 3: data fault status reg.
58 * 4: insn fault status reg.
61 * imm9: split UCOP_IMM10 with bit5 is 0
68 env
->cp0
.c1_sys
= val
;
74 env
->cp0
.c2_base
= val
;
80 env
->cp0
.c3_faultstatus
= val
;
86 env
->cp0
.c4_faultaddr
= val
;
91 DPRINTF("Invalidate Entire I&D cache\n");
94 DPRINTF("Invalidate Entire Icache\n");
97 DPRINTF("Invalidate Entire Dcache\n");
100 DPRINTF("Clean Entire Dcache\n");
103 DPRINTF("Flush Entire Dcache\n");
106 DPRINTF("Invalidate Dcache line\n");
109 DPRINTF("Clean Dcache line\n");
112 DPRINTF("Flush Dcache line\n");
117 if ((cop
<= 6) && (cop
>= 2)) {
118 /* invalid all tlb */
119 tlb_flush(CPU(cpu
), 1);
128 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
132 uint32_t helper_cp0_get(CPUUniCore32State
*env
, uint32_t creg
, uint32_t cop
)
135 * movc rd, pp.nn, #imm9
138 * 0: cpuid and cachetype
139 * 1: sys control reg.
140 * 2: page table base reg.
141 * 3: data fault status reg.
142 * 4: insn fault status reg.
143 * imm9: split UCOP_IMM10 with bit5 is 0
149 return env
->cp0
.c0_cpuid
;
151 return env
->cp0
.c0_cachetype
;
156 return env
->cp0
.c1_sys
;
161 return env
->cp0
.c2_base
;
166 return env
->cp0
.c3_faultstatus
;
171 return env
->cp0
.c4_faultaddr
;
175 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
183 * 1. curses windows will be blank when switching back
184 * 2. backspace is not handled yet
186 static void putc_on_screen(unsigned char ch
)
188 static WINDOW
*localwin
;
192 /* Assume 80 * 30 screen to minimize the implementation */
193 localwin
= newwin(30, 80, 0, 0);
194 scrollok(localwin
, TRUE
);
199 wprintw(localwin
, "%c", ch
);
203 wprintw(localwin
, "%c", ch
);
206 /* If '\r' is put before '\n', the curses window will destroy the
207 * last print line. And meanwhile, '\n' implifies '\r' inside. */
209 default: /* Not handled, so just print it hex code */
210 wprintw(localwin
, "-- 0x%x --", ch
);
217 #define putc_on_screen(c) do { } while (0)
220 void helper_cp1_putc(target_ulong x
)
222 putc_on_screen((unsigned char)x
); /* Output to screen */
223 DPRINTF("%c", x
); /* Output to stdout */
227 #ifdef CONFIG_USER_ONLY
228 void switch_mode(CPUUniCore32State
*env
, int mode
)
230 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
232 if (mode
!= ASR_MODE_USER
) {
233 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
237 void uc32_cpu_do_interrupt(CPUState
*cs
)
239 cpu_abort(cs
, "NO interrupt in user mode\n");
242 int uc32_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
,
243 int access_type
, int mmu_idx
)
245 cpu_abort(cs
, "NO mmu fault in user mode\n");
250 bool uc32_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
252 if (interrupt_request
& CPU_INTERRUPT_HARD
) {
253 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
254 CPUUniCore32State
*env
= &cpu
->env
;
256 if (!(env
->uncached_asr
& ASR_I
)) {
257 cs
->exception_index
= UC32_EXCP_INTR
;
258 uc32_cpu_do_interrupt(cs
);