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"
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 CPUUniCore32State
*uc32_cpu_init(const char *cpu_model
)
31 CPUUniCore32State
*env
;
32 static int inited
= 1;
34 if (object_class_by_name(cpu_model
) == NULL
) {
37 cpu
= UNICORE32_CPU(object_new(cpu_model
));
42 uc32_translate_init();
49 uint32_t HELPER(clo
)(uint32_t x
)
54 uint32_t HELPER(clz
)(uint32_t x
)
59 #ifndef CONFIG_USER_ONLY
60 void helper_cp0_set(CPUUniCore32State
*env
, uint32_t val
, uint32_t creg
,
64 * movc pp.nn, rn, #imm9
68 * 2: page table base reg.
69 * 3: data fault status reg.
70 * 4: insn fault status reg.
73 * imm9: split UCOP_IMM10 with bit5 is 0
80 env
->cp0
.c1_sys
= val
;
86 env
->cp0
.c2_base
= val
;
92 env
->cp0
.c3_faultstatus
= val
;
98 env
->cp0
.c4_faultaddr
= val
;
103 DPRINTF("Invalidate Entire I&D cache\n");
106 DPRINTF("Invalidate Entire Icache\n");
109 DPRINTF("Invalidate Entire Dcache\n");
112 DPRINTF("Clean Entire Dcache\n");
115 DPRINTF("Flush Entire Dcache\n");
118 DPRINTF("Invalidate Dcache line\n");
121 DPRINTF("Clean Dcache line\n");
124 DPRINTF("Flush Dcache line\n");
129 if ((cop
<= 6) && (cop
>= 2)) {
130 /* invalid all tlb */
140 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
144 uint32_t helper_cp0_get(CPUUniCore32State
*env
, uint32_t creg
, uint32_t cop
)
147 * movc rd, pp.nn, #imm9
150 * 0: cpuid and cachetype
151 * 1: sys control reg.
152 * 2: page table base reg.
153 * 3: data fault status reg.
154 * 4: insn fault status reg.
155 * imm9: split UCOP_IMM10 with bit5 is 0
161 return env
->cp0
.c0_cpuid
;
163 return env
->cp0
.c0_cachetype
;
168 return env
->cp0
.c1_sys
;
173 return env
->cp0
.c2_base
;
178 return env
->cp0
.c3_faultstatus
;
183 return env
->cp0
.c4_faultaddr
;
187 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
195 * 1. curses windows will be blank when switching back
196 * 2. backspace is not handled yet
198 static void putc_on_screen(unsigned char ch
)
200 static WINDOW
*localwin
;
204 /* Assume 80 * 30 screen to minimize the implementation */
205 localwin
= newwin(30, 80, 0, 0);
206 scrollok(localwin
, TRUE
);
211 wprintw(localwin
, "%c", ch
);
215 wprintw(localwin
, "%c", ch
);
218 /* If '\r' is put before '\n', the curses window will destroy the
219 * last print line. And meanwhile, '\n' implifies '\r' inside. */
221 default: /* Not handled, so just print it hex code */
222 wprintw(localwin
, "-- 0x%x --", ch
);
229 #define putc_on_screen(c) do { } while (0)
232 void helper_cp1_putc(target_ulong x
)
234 putc_on_screen((unsigned char)x
); /* Output to screen */
235 DPRINTF("%c", x
); /* Output to stdout */
239 #ifdef CONFIG_USER_ONLY
240 void switch_mode(CPUUniCore32State
*env
, int mode
)
242 if (mode
!= ASR_MODE_USER
) {
243 cpu_abort(env
, "Tried to switch out of user mode\n");
247 void do_interrupt(CPUUniCore32State
*env
)
249 cpu_abort(env
, "NO interrupt in user mode\n");
252 int uc32_cpu_handle_mmu_fault(CPUUniCore32State
*env
, target_ulong address
,
253 int access_type
, int mmu_idx
)
255 cpu_abort(env
, "NO mmu fault in user mode\n");