Statistics
| Branch: | Revision:

root / target-unicore32 / helper.c @ ff5928d0

History | View | Annotate | Download (5.9 kB)

1 6e64da3c Guan Xuetao
/*
2 4f23a1e6 Guan Xuetao
 * Copyright (C) 2010-2012 Guan Xuetao
3 6e64da3c Guan Xuetao
 *
4 6e64da3c Guan Xuetao
 * This program is free software; you can redistribute it and/or modify
5 6e64da3c Guan Xuetao
 * it under the terms of the GNU General Public License version 2 as
6 6e64da3c Guan Xuetao
 * published by the Free Software Foundation.
7 c3a8baa9 Andreas Färber
 *
8 c3a8baa9 Andreas Färber
 * Contributions from 2012-04-01 on are considered under GPL version 2,
9 c3a8baa9 Andreas Färber
 * or (at your option) any later version.
10 6e64da3c Guan Xuetao
 */
11 6e64da3c Guan Xuetao
12 6e64da3c Guan Xuetao
#include "cpu.h"
13 6e64da3c Guan Xuetao
#include "gdbstub.h"
14 6e64da3c Guan Xuetao
#include "helper.h"
15 6e64da3c Guan Xuetao
#include "host-utils.h"
16 ff5928d0 Guan Xuetao
#include "console.h"
17 6e64da3c Guan Xuetao
18 527d9979 Guan Xuetao
#undef DEBUG_UC32
19 527d9979 Guan Xuetao
20 527d9979 Guan Xuetao
#ifdef DEBUG_UC32
21 527d9979 Guan Xuetao
#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
22 527d9979 Guan Xuetao
#else
23 527d9979 Guan Xuetao
#define DPRINTF(fmt, ...) do {} while (0)
24 527d9979 Guan Xuetao
#endif
25 527d9979 Guan Xuetao
26 eb23b556 Andreas Färber
CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
27 6e64da3c Guan Xuetao
{
28 ae0f5e9e Andreas Färber
    UniCore32CPU *cpu;
29 eb23b556 Andreas Färber
    CPUUniCore32State *env;
30 6e64da3c Guan Xuetao
    static int inited = 1;
31 6e64da3c Guan Xuetao
32 ae0f5e9e Andreas Färber
    if (object_class_by_name(cpu_model) == NULL) {
33 ae0f5e9e Andreas Färber
        return NULL;
34 ae0f5e9e Andreas Färber
    }
35 ae0f5e9e Andreas Färber
    cpu = UNICORE32_CPU(object_new(cpu_model));
36 ae0f5e9e Andreas Färber
    env = &cpu->env;
37 6e64da3c Guan Xuetao
38 6e64da3c Guan Xuetao
    if (inited) {
39 6e64da3c Guan Xuetao
        inited = 0;
40 6e64da3c Guan Xuetao
        uc32_translate_init();
41 6e64da3c Guan Xuetao
    }
42 6e64da3c Guan Xuetao
43 6e64da3c Guan Xuetao
    qemu_init_vcpu(env);
44 6e64da3c Guan Xuetao
    return env;
45 6e64da3c Guan Xuetao
}
46 6e64da3c Guan Xuetao
47 6e64da3c Guan Xuetao
uint32_t HELPER(clo)(uint32_t x)
48 6e64da3c Guan Xuetao
{
49 6e64da3c Guan Xuetao
    return clo32(x);
50 6e64da3c Guan Xuetao
}
51 6e64da3c Guan Xuetao
52 6e64da3c Guan Xuetao
uint32_t HELPER(clz)(uint32_t x)
53 6e64da3c Guan Xuetao
{
54 6e64da3c Guan Xuetao
    return clz32(x);
55 6e64da3c Guan Xuetao
}
56 6e64da3c Guan Xuetao
57 527d9979 Guan Xuetao
#ifndef CONFIG_USER_ONLY
58 527d9979 Guan Xuetao
void helper_cp0_set(CPUUniCore32State *env, uint32_t val, uint32_t creg,
59 527d9979 Guan Xuetao
        uint32_t cop)
60 4f23a1e6 Guan Xuetao
{
61 527d9979 Guan Xuetao
    /*
62 527d9979 Guan Xuetao
     * movc pp.nn, rn, #imm9
63 527d9979 Guan Xuetao
     *      rn: UCOP_REG_D
64 527d9979 Guan Xuetao
     *      nn: UCOP_REG_N
65 527d9979 Guan Xuetao
     *          1: sys control reg.
66 527d9979 Guan Xuetao
     *          2: page table base reg.
67 527d9979 Guan Xuetao
     *          3: data fault status reg.
68 527d9979 Guan Xuetao
     *          4: insn fault status reg.
69 527d9979 Guan Xuetao
     *          5: cache op. reg.
70 527d9979 Guan Xuetao
     *          6: tlb op. reg.
71 527d9979 Guan Xuetao
     *      imm9: split UCOP_IMM10 with bit5 is 0
72 527d9979 Guan Xuetao
     */
73 527d9979 Guan Xuetao
    switch (creg) {
74 527d9979 Guan Xuetao
    case 1:
75 527d9979 Guan Xuetao
        if (cop != 0) {
76 527d9979 Guan Xuetao
            goto unrecognized;
77 527d9979 Guan Xuetao
        }
78 527d9979 Guan Xuetao
        env->cp0.c1_sys = val;
79 527d9979 Guan Xuetao
        break;
80 527d9979 Guan Xuetao
    case 2:
81 527d9979 Guan Xuetao
        if (cop != 0) {
82 527d9979 Guan Xuetao
            goto unrecognized;
83 527d9979 Guan Xuetao
        }
84 527d9979 Guan Xuetao
        env->cp0.c2_base = val;
85 527d9979 Guan Xuetao
        break;
86 527d9979 Guan Xuetao
    case 3:
87 527d9979 Guan Xuetao
        if (cop != 0) {
88 527d9979 Guan Xuetao
            goto unrecognized;
89 527d9979 Guan Xuetao
        }
90 527d9979 Guan Xuetao
        env->cp0.c3_faultstatus = val;
91 527d9979 Guan Xuetao
        break;
92 527d9979 Guan Xuetao
    case 4:
93 527d9979 Guan Xuetao
        if (cop != 0) {
94 527d9979 Guan Xuetao
            goto unrecognized;
95 527d9979 Guan Xuetao
        }
96 527d9979 Guan Xuetao
        env->cp0.c4_faultaddr = val;
97 527d9979 Guan Xuetao
        break;
98 527d9979 Guan Xuetao
    case 5:
99 527d9979 Guan Xuetao
        switch (cop) {
100 527d9979 Guan Xuetao
        case 28:
101 527d9979 Guan Xuetao
            DPRINTF("Invalidate Entire I&D cache\n");
102 527d9979 Guan Xuetao
            return;
103 527d9979 Guan Xuetao
        case 20:
104 527d9979 Guan Xuetao
            DPRINTF("Invalidate Entire Icache\n");
105 527d9979 Guan Xuetao
            return;
106 527d9979 Guan Xuetao
        case 12:
107 527d9979 Guan Xuetao
            DPRINTF("Invalidate Entire Dcache\n");
108 527d9979 Guan Xuetao
            return;
109 527d9979 Guan Xuetao
        case 10:
110 527d9979 Guan Xuetao
            DPRINTF("Clean Entire Dcache\n");
111 527d9979 Guan Xuetao
            return;
112 527d9979 Guan Xuetao
        case 14:
113 527d9979 Guan Xuetao
            DPRINTF("Flush Entire Dcache\n");
114 527d9979 Guan Xuetao
            return;
115 527d9979 Guan Xuetao
        case 13:
116 527d9979 Guan Xuetao
            DPRINTF("Invalidate Dcache line\n");
117 527d9979 Guan Xuetao
            return;
118 527d9979 Guan Xuetao
        case 11:
119 527d9979 Guan Xuetao
            DPRINTF("Clean Dcache line\n");
120 527d9979 Guan Xuetao
            return;
121 527d9979 Guan Xuetao
        case 15:
122 527d9979 Guan Xuetao
            DPRINTF("Flush Dcache line\n");
123 527d9979 Guan Xuetao
            return;
124 527d9979 Guan Xuetao
        }
125 527d9979 Guan Xuetao
        break;
126 527d9979 Guan Xuetao
    case 6:
127 527d9979 Guan Xuetao
        if ((cop <= 6) && (cop >= 2)) {
128 527d9979 Guan Xuetao
            /* invalid all tlb */
129 527d9979 Guan Xuetao
            tlb_flush(env, 1);
130 527d9979 Guan Xuetao
            return;
131 527d9979 Guan Xuetao
        }
132 527d9979 Guan Xuetao
        break;
133 527d9979 Guan Xuetao
    default:
134 527d9979 Guan Xuetao
        goto unrecognized;
135 4f23a1e6 Guan Xuetao
    }
136 6e64da3c Guan Xuetao
    return;
137 527d9979 Guan Xuetao
unrecognized:
138 527d9979 Guan Xuetao
    DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
139 527d9979 Guan Xuetao
            creg, cop);
140 6e64da3c Guan Xuetao
}
141 6e64da3c Guan Xuetao
142 527d9979 Guan Xuetao
uint32_t helper_cp0_get(CPUUniCore32State *env, uint32_t creg, uint32_t cop)
143 6e64da3c Guan Xuetao
{
144 527d9979 Guan Xuetao
    /*
145 527d9979 Guan Xuetao
     * movc rd, pp.nn, #imm9
146 527d9979 Guan Xuetao
     *      rd: UCOP_REG_D
147 527d9979 Guan Xuetao
     *      nn: UCOP_REG_N
148 527d9979 Guan Xuetao
     *          0: cpuid and cachetype
149 527d9979 Guan Xuetao
     *          1: sys control reg.
150 527d9979 Guan Xuetao
     *          2: page table base reg.
151 527d9979 Guan Xuetao
     *          3: data fault status reg.
152 527d9979 Guan Xuetao
     *          4: insn fault status reg.
153 527d9979 Guan Xuetao
     *      imm9: split UCOP_IMM10 with bit5 is 0
154 527d9979 Guan Xuetao
     */
155 527d9979 Guan Xuetao
    switch (creg) {
156 527d9979 Guan Xuetao
    case 0:
157 527d9979 Guan Xuetao
        switch (cop) {
158 527d9979 Guan Xuetao
        case 0:
159 527d9979 Guan Xuetao
            return env->cp0.c0_cpuid;
160 527d9979 Guan Xuetao
        case 1:
161 527d9979 Guan Xuetao
            return env->cp0.c0_cachetype;
162 527d9979 Guan Xuetao
        }
163 527d9979 Guan Xuetao
        break;
164 527d9979 Guan Xuetao
    case 1:
165 527d9979 Guan Xuetao
        if (cop == 0) {
166 527d9979 Guan Xuetao
            return env->cp0.c1_sys;
167 527d9979 Guan Xuetao
        }
168 527d9979 Guan Xuetao
        break;
169 527d9979 Guan Xuetao
    case 2:
170 527d9979 Guan Xuetao
        if (cop == 0) {
171 527d9979 Guan Xuetao
            return env->cp0.c2_base;
172 527d9979 Guan Xuetao
        }
173 527d9979 Guan Xuetao
        break;
174 527d9979 Guan Xuetao
    case 3:
175 527d9979 Guan Xuetao
        if (cop == 0) {
176 527d9979 Guan Xuetao
            return env->cp0.c3_faultstatus;
177 527d9979 Guan Xuetao
        }
178 527d9979 Guan Xuetao
        break;
179 527d9979 Guan Xuetao
    case 4:
180 527d9979 Guan Xuetao
        if (cop == 0) {
181 527d9979 Guan Xuetao
            return env->cp0.c4_faultaddr;
182 527d9979 Guan Xuetao
        }
183 527d9979 Guan Xuetao
        break;
184 527d9979 Guan Xuetao
    }
185 527d9979 Guan Xuetao
    DPRINTF("Wrong register (%d) or wrong operation (%d) in cp0_set!\n",
186 527d9979 Guan Xuetao
            creg, cop);
187 6e64da3c Guan Xuetao
    return 0;
188 6e64da3c Guan Xuetao
}
189 6e64da3c Guan Xuetao
190 ff5928d0 Guan Xuetao
#ifdef CONFIG_CURSES
191 ff5928d0 Guan Xuetao
/*
192 ff5928d0 Guan Xuetao
 * FIXME:
193 ff5928d0 Guan Xuetao
 *     1. curses windows will be blank when switching back
194 ff5928d0 Guan Xuetao
 *     2. backspace is not handled yet
195 ff5928d0 Guan Xuetao
 */
196 ff5928d0 Guan Xuetao
static void putc_on_screen(unsigned char ch)
197 ff5928d0 Guan Xuetao
{
198 ff5928d0 Guan Xuetao
    static WINDOW *localwin;
199 ff5928d0 Guan Xuetao
    static int init;
200 ff5928d0 Guan Xuetao
201 ff5928d0 Guan Xuetao
    if (!init) {
202 ff5928d0 Guan Xuetao
        /* Assume 80 * 30 screen to minimize the implementation */
203 ff5928d0 Guan Xuetao
        localwin = newwin(30, 80, 0, 0);
204 ff5928d0 Guan Xuetao
        scrollok(localwin, TRUE);
205 ff5928d0 Guan Xuetao
        init = TRUE;
206 ff5928d0 Guan Xuetao
    }
207 ff5928d0 Guan Xuetao
208 ff5928d0 Guan Xuetao
    if (isprint(ch)) {
209 ff5928d0 Guan Xuetao
        wprintw(localwin, "%c", ch);
210 ff5928d0 Guan Xuetao
    } else {
211 ff5928d0 Guan Xuetao
        switch (ch) {
212 ff5928d0 Guan Xuetao
        case '\n':
213 ff5928d0 Guan Xuetao
            wprintw(localwin, "%c", ch);
214 ff5928d0 Guan Xuetao
            break;
215 ff5928d0 Guan Xuetao
        case '\r':
216 ff5928d0 Guan Xuetao
            /* If '\r' is put before '\n', the curses window will destroy the
217 ff5928d0 Guan Xuetao
             * last print line. And meanwhile, '\n' implifies '\r' inside. */
218 ff5928d0 Guan Xuetao
            break;
219 ff5928d0 Guan Xuetao
        default: /* Not handled, so just print it hex code */
220 ff5928d0 Guan Xuetao
            wprintw(localwin, "-- 0x%x --", ch);
221 ff5928d0 Guan Xuetao
        }
222 ff5928d0 Guan Xuetao
    }
223 ff5928d0 Guan Xuetao
224 ff5928d0 Guan Xuetao
    wrefresh(localwin);
225 ff5928d0 Guan Xuetao
}
226 ff5928d0 Guan Xuetao
#else
227 ff5928d0 Guan Xuetao
#define putc_on_screen(c)               do { } while (0)
228 ff5928d0 Guan Xuetao
#endif
229 ff5928d0 Guan Xuetao
230 527d9979 Guan Xuetao
void helper_cp1_putc(target_ulong x)
231 6e64da3c Guan Xuetao
{
232 ff5928d0 Guan Xuetao
    putc_on_screen((unsigned char)x);   /* Output to screen */
233 ff5928d0 Guan Xuetao
    DPRINTF("%c", x);                   /* Output to stdout */
234 6e64da3c Guan Xuetao
}
235 527d9979 Guan Xuetao
#endif
236 6e64da3c Guan Xuetao
237 527d9979 Guan Xuetao
#ifdef CONFIG_USER_ONLY
238 527d9979 Guan Xuetao
void switch_mode(CPUUniCore32State *env, int mode)
239 6e64da3c Guan Xuetao
{
240 527d9979 Guan Xuetao
    if (mode != ASR_MODE_USER) {
241 527d9979 Guan Xuetao
        cpu_abort(env, "Tried to switch out of user mode\n");
242 527d9979 Guan Xuetao
    }
243 6e64da3c Guan Xuetao
}
244 6e64da3c Guan Xuetao
245 527d9979 Guan Xuetao
void do_interrupt(CPUUniCore32State *env)
246 6e64da3c Guan Xuetao
{
247 527d9979 Guan Xuetao
    cpu_abort(env, "NO interrupt in user mode\n");
248 6e64da3c Guan Xuetao
}
249 6e64da3c Guan Xuetao
250 527d9979 Guan Xuetao
int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address,
251 527d9979 Guan Xuetao
                              int access_type, int mmu_idx)
252 6e64da3c Guan Xuetao
{
253 527d9979 Guan Xuetao
    cpu_abort(env, "NO mmu fault in user mode\n");
254 527d9979 Guan Xuetao
    return 1;
255 6e64da3c Guan Xuetao
}
256 527d9979 Guan Xuetao
#endif