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.
13 #include "exec/gdbstub.h"
14 #include "exec/helper-proto.h"
15 #include "qemu/host-utils.h"
16 #ifndef CONFIG_USER_ONLY
17 #include "ui/console.h"
23 #define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
25 #define DPRINTF(fmt, ...) do {} while (0)
28 UniCore32CPU
*uc32_cpu_init(const char *cpu_model
)
30 return UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU
, cpu_model
));
33 uint32_t HELPER(clo
)(uint32_t x
)
38 uint32_t HELPER(clz
)(uint32_t x
)
43 #ifndef CONFIG_USER_ONLY
44 void helper_cp0_set(CPUUniCore32State
*env
, uint32_t val
, uint32_t creg
,
47 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
50 * movc pp.nn, rn, #imm9
54 * 2: page table base reg.
55 * 3: data fault status reg.
56 * 4: insn fault status reg.
59 * imm9: split UCOP_IMM10 with bit5 is 0
66 env
->cp0
.c1_sys
= val
;
72 env
->cp0
.c2_base
= val
;
78 env
->cp0
.c3_faultstatus
= val
;
84 env
->cp0
.c4_faultaddr
= val
;
89 DPRINTF("Invalidate Entire I&D cache\n");
92 DPRINTF("Invalidate Entire Icache\n");
95 DPRINTF("Invalidate Entire Dcache\n");
98 DPRINTF("Clean Entire Dcache\n");
101 DPRINTF("Flush Entire Dcache\n");
104 DPRINTF("Invalidate Dcache line\n");
107 DPRINTF("Clean Dcache line\n");
110 DPRINTF("Flush Dcache line\n");
115 if ((cop
<= 6) && (cop
>= 2)) {
116 /* invalid all tlb */
117 tlb_flush(CPU(cpu
), 1);
126 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
130 uint32_t helper_cp0_get(CPUUniCore32State
*env
, uint32_t creg
, uint32_t cop
)
133 * movc rd, pp.nn, #imm9
136 * 0: cpuid and cachetype
137 * 1: sys control reg.
138 * 2: page table base reg.
139 * 3: data fault status reg.
140 * 4: insn fault status reg.
141 * imm9: split UCOP_IMM10 with bit5 is 0
147 return env
->cp0
.c0_cpuid
;
149 return env
->cp0
.c0_cachetype
;
154 return env
->cp0
.c1_sys
;
159 return env
->cp0
.c2_base
;
164 return env
->cp0
.c3_faultstatus
;
169 return env
->cp0
.c4_faultaddr
;
173 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
181 * 1. curses windows will be blank when switching back
182 * 2. backspace is not handled yet
184 static void putc_on_screen(unsigned char ch
)
186 static WINDOW
*localwin
;
190 /* Assume 80 * 30 screen to minimize the implementation */
191 localwin
= newwin(30, 80, 0, 0);
192 scrollok(localwin
, TRUE
);
197 wprintw(localwin
, "%c", ch
);
201 wprintw(localwin
, "%c", ch
);
204 /* If '\r' is put before '\n', the curses window will destroy the
205 * last print line. And meanwhile, '\n' implifies '\r' inside. */
207 default: /* Not handled, so just print it hex code */
208 wprintw(localwin
, "-- 0x%x --", ch
);
215 #define putc_on_screen(c) do { } while (0)
218 void helper_cp1_putc(target_ulong x
)
220 putc_on_screen((unsigned char)x
); /* Output to screen */
221 DPRINTF("%c", x
); /* Output to stdout */
225 #ifdef CONFIG_USER_ONLY
226 void switch_mode(CPUUniCore32State
*env
, int mode
)
228 UniCore32CPU
*cpu
= uc32_env_get_cpu(env
);
230 if (mode
!= ASR_MODE_USER
) {
231 cpu_abort(CPU(cpu
), "Tried to switch out of user mode\n");
235 void uc32_cpu_do_interrupt(CPUState
*cs
)
237 cpu_abort(cs
, "NO interrupt in user mode\n");
240 int uc32_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
,
241 int access_type
, int mmu_idx
)
243 cpu_abort(cs
, "NO mmu fault in user mode\n");
248 bool uc32_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
250 if (interrupt_request
& CPU_INTERRUPT_HARD
) {
251 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
252 CPUUniCore32State
*env
= &cpu
->env
;
254 if (!(env
->uncached_asr
& ASR_I
)) {
255 cs
->exception_index
= UC32_EXCP_INTR
;
256 uc32_cpu_do_interrupt(cs
);