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
)
32 cpu
= UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU
, cpu_model
));
39 uint32_t HELPER(clo
)(uint32_t x
)
44 uint32_t HELPER(clz
)(uint32_t x
)
49 #ifndef CONFIG_USER_ONLY
50 void helper_cp0_set(CPUUniCore32State
*env
, uint32_t val
, uint32_t creg
,
54 * movc pp.nn, rn, #imm9
58 * 2: page table base reg.
59 * 3: data fault status reg.
60 * 4: insn fault status reg.
63 * imm9: split UCOP_IMM10 with bit5 is 0
70 env
->cp0
.c1_sys
= val
;
76 env
->cp0
.c2_base
= val
;
82 env
->cp0
.c3_faultstatus
= val
;
88 env
->cp0
.c4_faultaddr
= val
;
93 DPRINTF("Invalidate Entire I&D cache\n");
96 DPRINTF("Invalidate Entire Icache\n");
99 DPRINTF("Invalidate Entire Dcache\n");
102 DPRINTF("Clean Entire Dcache\n");
105 DPRINTF("Flush Entire Dcache\n");
108 DPRINTF("Invalidate Dcache line\n");
111 DPRINTF("Clean Dcache line\n");
114 DPRINTF("Flush Dcache line\n");
119 if ((cop
<= 6) && (cop
>= 2)) {
120 /* invalid all tlb */
130 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
134 uint32_t helper_cp0_get(CPUUniCore32State
*env
, uint32_t creg
, uint32_t cop
)
137 * movc rd, pp.nn, #imm9
140 * 0: cpuid and cachetype
141 * 1: sys control reg.
142 * 2: page table base reg.
143 * 3: data fault status reg.
144 * 4: insn fault status reg.
145 * imm9: split UCOP_IMM10 with bit5 is 0
151 return env
->cp0
.c0_cpuid
;
153 return env
->cp0
.c0_cachetype
;
158 return env
->cp0
.c1_sys
;
163 return env
->cp0
.c2_base
;
168 return env
->cp0
.c3_faultstatus
;
173 return env
->cp0
.c4_faultaddr
;
177 DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
185 * 1. curses windows will be blank when switching back
186 * 2. backspace is not handled yet
188 static void putc_on_screen(unsigned char ch
)
190 static WINDOW
*localwin
;
194 /* Assume 80 * 30 screen to minimize the implementation */
195 localwin
= newwin(30, 80, 0, 0);
196 scrollok(localwin
, TRUE
);
201 wprintw(localwin
, "%c", ch
);
205 wprintw(localwin
, "%c", ch
);
208 /* If '\r' is put before '\n', the curses window will destroy the
209 * last print line. And meanwhile, '\n' implifies '\r' inside. */
211 default: /* Not handled, so just print it hex code */
212 wprintw(localwin
, "-- 0x%x --", ch
);
219 #define putc_on_screen(c) do { } while (0)
222 void helper_cp1_putc(target_ulong x
)
224 putc_on_screen((unsigned char)x
); /* Output to screen */
225 DPRINTF("%c", x
); /* Output to stdout */
229 #ifdef CONFIG_USER_ONLY
230 void switch_mode(CPUUniCore32State
*env
, int mode
)
232 if (mode
!= ASR_MODE_USER
) {
233 cpu_abort(env
, "Tried to switch out of user mode\n");
237 void uc32_cpu_do_interrupt(CPUState
*cs
)
239 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
240 CPUUniCore32State
*env
= &cpu
->env
;
242 cpu_abort(env
, "NO interrupt in user mode\n");
245 int uc32_cpu_handle_mmu_fault(CPUUniCore32State
*env
, target_ulong address
,
246 int access_type
, int mmu_idx
)
248 cpu_abort(env
, "NO mmu fault in user mode\n");