Statistics
| Branch: | Revision:

root / target-lm32 / cpu.h @ 1a9978a5

History | View | Annotate | Download (5.6 kB)

1 81ea0e13 Michael Walle
/*
2 81ea0e13 Michael Walle
 *  LatticeMico32 virtual CPU header.
3 81ea0e13 Michael Walle
 *
4 81ea0e13 Michael Walle
 *  Copyright (c) 2010 Michael Walle <michael@walle.cc>
5 81ea0e13 Michael Walle
 *
6 81ea0e13 Michael Walle
 * This library is free software; you can redistribute it and/or
7 81ea0e13 Michael Walle
 * modify it under the terms of the GNU Lesser General Public
8 81ea0e13 Michael Walle
 * License as published by the Free Software Foundation; either
9 81ea0e13 Michael Walle
 * version 2 of the License, or (at your option) any later version.
10 81ea0e13 Michael Walle
 *
11 81ea0e13 Michael Walle
 * This library is distributed in the hope that it will be useful,
12 81ea0e13 Michael Walle
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 81ea0e13 Michael Walle
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 81ea0e13 Michael Walle
 * Lesser General Public License for more details.
15 81ea0e13 Michael Walle
 *
16 81ea0e13 Michael Walle
 * You should have received a copy of the GNU Lesser General Public
17 81ea0e13 Michael Walle
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 81ea0e13 Michael Walle
 */
19 81ea0e13 Michael Walle
20 81ea0e13 Michael Walle
#ifndef CPU_LM32_H
21 81ea0e13 Michael Walle
#define CPU_LM32_H
22 81ea0e13 Michael Walle
23 81ea0e13 Michael Walle
#define TARGET_LONG_BITS 32
24 81ea0e13 Michael Walle
25 9349b4f9 Andreas Färber
#define CPUArchState struct CPULM32State
26 81ea0e13 Michael Walle
27 60ed8d29 Stefan Weil
#include "config.h"
28 81ea0e13 Michael Walle
#include "qemu-common.h"
29 022c62cb Paolo Bonzini
#include "exec/cpu-defs.h"
30 81ea0e13 Michael Walle
struct CPULM32State;
31 9b9a970a Andreas Färber
typedef struct CPULM32State CPULM32State;
32 81ea0e13 Michael Walle
33 81ea0e13 Michael Walle
#define TARGET_HAS_ICE 1
34 81ea0e13 Michael Walle
35 81ea0e13 Michael Walle
#define ELF_MACHINE EM_LATTICEMICO32
36 81ea0e13 Michael Walle
37 81ea0e13 Michael Walle
#define NB_MMU_MODES 1
38 81ea0e13 Michael Walle
#define TARGET_PAGE_BITS 12
39 6393c08d Andreas Färber
static inline int cpu_mmu_index(CPULM32State *env)
40 81ea0e13 Michael Walle
{
41 81ea0e13 Michael Walle
    return 0;
42 81ea0e13 Michael Walle
}
43 81ea0e13 Michael Walle
44 81ea0e13 Michael Walle
#define TARGET_PHYS_ADDR_SPACE_BITS 32
45 81ea0e13 Michael Walle
#define TARGET_VIRT_ADDR_SPACE_BITS 32
46 81ea0e13 Michael Walle
47 81ea0e13 Michael Walle
/* Exceptions indices */
48 81ea0e13 Michael Walle
enum {
49 81ea0e13 Michael Walle
    EXCP_RESET = 0,
50 81ea0e13 Michael Walle
    EXCP_BREAKPOINT,
51 81ea0e13 Michael Walle
    EXCP_INSN_BUS_ERROR,
52 81ea0e13 Michael Walle
    EXCP_WATCHPOINT,
53 81ea0e13 Michael Walle
    EXCP_DATA_BUS_ERROR,
54 81ea0e13 Michael Walle
    EXCP_DIVIDE_BY_ZERO,
55 81ea0e13 Michael Walle
    EXCP_IRQ,
56 81ea0e13 Michael Walle
    EXCP_SYSTEMCALL
57 81ea0e13 Michael Walle
};
58 81ea0e13 Michael Walle
59 81ea0e13 Michael Walle
/* Registers */
60 81ea0e13 Michael Walle
enum {
61 81ea0e13 Michael Walle
    R_R0 = 0, R_R1, R_R2, R_R3, R_R4, R_R5, R_R6, R_R7, R_R8, R_R9, R_R10,
62 81ea0e13 Michael Walle
    R_R11, R_R12, R_R13, R_R14, R_R15, R_R16, R_R17, R_R18, R_R19, R_R20,
63 81ea0e13 Michael Walle
    R_R21, R_R22, R_R23, R_R24, R_R25, R_R26, R_R27, R_R28, R_R29, R_R30,
64 81ea0e13 Michael Walle
    R_R31
65 81ea0e13 Michael Walle
};
66 81ea0e13 Michael Walle
67 81ea0e13 Michael Walle
/* Register aliases */
68 81ea0e13 Michael Walle
enum {
69 81ea0e13 Michael Walle
    R_GP = R_R26,
70 81ea0e13 Michael Walle
    R_FP = R_R27,
71 81ea0e13 Michael Walle
    R_SP = R_R28,
72 81ea0e13 Michael Walle
    R_RA = R_R29,
73 81ea0e13 Michael Walle
    R_EA = R_R30,
74 81ea0e13 Michael Walle
    R_BA = R_R31
75 81ea0e13 Michael Walle
};
76 81ea0e13 Michael Walle
77 81ea0e13 Michael Walle
/* IE flags */
78 81ea0e13 Michael Walle
enum {
79 81ea0e13 Michael Walle
    IE_IE  = (1<<0),
80 81ea0e13 Michael Walle
    IE_EIE = (1<<1),
81 81ea0e13 Michael Walle
    IE_BIE = (1<<2),
82 81ea0e13 Michael Walle
};
83 81ea0e13 Michael Walle
84 81ea0e13 Michael Walle
/* DC flags */
85 81ea0e13 Michael Walle
enum {
86 81ea0e13 Michael Walle
    DC_SS  = (1<<0),
87 81ea0e13 Michael Walle
    DC_RE  = (1<<1),
88 81ea0e13 Michael Walle
    DC_C0  = (1<<2),
89 81ea0e13 Michael Walle
    DC_C1  = (1<<3),
90 81ea0e13 Michael Walle
    DC_C2  = (1<<4),
91 81ea0e13 Michael Walle
    DC_C3  = (1<<5),
92 81ea0e13 Michael Walle
};
93 81ea0e13 Michael Walle
94 81ea0e13 Michael Walle
/* CFG mask */
95 81ea0e13 Michael Walle
enum {
96 81ea0e13 Michael Walle
    CFG_M         = (1<<0),
97 81ea0e13 Michael Walle
    CFG_D         = (1<<1),
98 81ea0e13 Michael Walle
    CFG_S         = (1<<2),
99 81ea0e13 Michael Walle
    CFG_U         = (1<<3),
100 81ea0e13 Michael Walle
    CFG_X         = (1<<4),
101 81ea0e13 Michael Walle
    CFG_CC        = (1<<5),
102 81ea0e13 Michael Walle
    CFG_IC        = (1<<6),
103 81ea0e13 Michael Walle
    CFG_DC        = (1<<7),
104 81ea0e13 Michael Walle
    CFG_G         = (1<<8),
105 81ea0e13 Michael Walle
    CFG_H         = (1<<9),
106 81ea0e13 Michael Walle
    CFG_R         = (1<<10),
107 81ea0e13 Michael Walle
    CFG_J         = (1<<11),
108 81ea0e13 Michael Walle
    CFG_INT_SHIFT = 12,
109 81ea0e13 Michael Walle
    CFG_BP_SHIFT  = 18,
110 81ea0e13 Michael Walle
    CFG_WP_SHIFT  = 22,
111 81ea0e13 Michael Walle
    CFG_REV_SHIFT = 26,
112 81ea0e13 Michael Walle
};
113 81ea0e13 Michael Walle
114 81ea0e13 Michael Walle
/* CSRs */
115 81ea0e13 Michael Walle
enum {
116 81ea0e13 Michael Walle
    CSR_IE   = 0x00,
117 81ea0e13 Michael Walle
    CSR_IM   = 0x01,
118 81ea0e13 Michael Walle
    CSR_IP   = 0x02,
119 81ea0e13 Michael Walle
    CSR_ICC  = 0x03,
120 81ea0e13 Michael Walle
    CSR_DCC  = 0x04,
121 81ea0e13 Michael Walle
    CSR_CC   = 0x05,
122 81ea0e13 Michael Walle
    CSR_CFG  = 0x06,
123 81ea0e13 Michael Walle
    CSR_EBA  = 0x07,
124 81ea0e13 Michael Walle
    CSR_DC   = 0x08,
125 81ea0e13 Michael Walle
    CSR_DEBA = 0x09,
126 81ea0e13 Michael Walle
    CSR_JTX  = 0x0e,
127 81ea0e13 Michael Walle
    CSR_JRX  = 0x0f,
128 81ea0e13 Michael Walle
    CSR_BP0  = 0x10,
129 81ea0e13 Michael Walle
    CSR_BP1  = 0x11,
130 81ea0e13 Michael Walle
    CSR_BP2  = 0x12,
131 81ea0e13 Michael Walle
    CSR_BP3  = 0x13,
132 81ea0e13 Michael Walle
    CSR_WP0  = 0x18,
133 81ea0e13 Michael Walle
    CSR_WP1  = 0x19,
134 81ea0e13 Michael Walle
    CSR_WP2  = 0x1a,
135 81ea0e13 Michael Walle
    CSR_WP3  = 0x1b,
136 81ea0e13 Michael Walle
};
137 81ea0e13 Michael Walle
138 81ea0e13 Michael Walle
enum {
139 81ea0e13 Michael Walle
    LM32_FEATURE_MULTIPLY     =  1,
140 81ea0e13 Michael Walle
    LM32_FEATURE_DIVIDE       =  2,
141 81ea0e13 Michael Walle
    LM32_FEATURE_SHIFT        =  4,
142 81ea0e13 Michael Walle
    LM32_FEATURE_SIGN_EXTEND  =  8,
143 81ea0e13 Michael Walle
    LM32_FEATURE_I_CACHE      = 16,
144 81ea0e13 Michael Walle
    LM32_FEATURE_D_CACHE      = 32,
145 81ea0e13 Michael Walle
    LM32_FEATURE_CYCLE_COUNT  = 64,
146 81ea0e13 Michael Walle
};
147 81ea0e13 Michael Walle
148 81ea0e13 Michael Walle
enum {
149 81ea0e13 Michael Walle
    LM32_FLAG_IGNORE_MSB = 1,
150 81ea0e13 Michael Walle
};
151 81ea0e13 Michael Walle
152 ae7d54d4 Andreas Färber
struct CPULM32State {
153 81ea0e13 Michael Walle
    /* general registers */
154 81ea0e13 Michael Walle
    uint32_t regs[32];
155 81ea0e13 Michael Walle
156 81ea0e13 Michael Walle
    /* special registers */
157 81ea0e13 Michael Walle
    uint32_t pc;        /* program counter */
158 81ea0e13 Michael Walle
    uint32_t ie;        /* interrupt enable */
159 81ea0e13 Michael Walle
    uint32_t icc;       /* instruction cache control */
160 81ea0e13 Michael Walle
    uint32_t dcc;       /* data cache control */
161 81ea0e13 Michael Walle
    uint32_t cc;        /* cycle counter */
162 81ea0e13 Michael Walle
    uint32_t cfg;       /* configuration */
163 81ea0e13 Michael Walle
164 81ea0e13 Michael Walle
    /* debug registers */
165 81ea0e13 Michael Walle
    uint32_t dc;        /* debug control */
166 81ea0e13 Michael Walle
    uint32_t bp[4];     /* breakpoint addresses */
167 81ea0e13 Michael Walle
    uint32_t wp[4];     /* watchpoint addresses */
168 81ea0e13 Michael Walle
169 81ea0e13 Michael Walle
    CPU_COMMON
170 81ea0e13 Michael Walle
171 81ea0e13 Michael Walle
    uint32_t eba;       /* exception base address */
172 81ea0e13 Michael Walle
    uint32_t deba;      /* debug exception base address */
173 81ea0e13 Michael Walle
174 81ea0e13 Michael Walle
    /* interrupt controller handle for callbacks */
175 81ea0e13 Michael Walle
    DeviceState *pic_state;
176 81ea0e13 Michael Walle
    /* JTAG UART handle for callbacks */
177 81ea0e13 Michael Walle
    DeviceState *juart_state;
178 81ea0e13 Michael Walle
179 81ea0e13 Michael Walle
    /* processor core features */
180 81ea0e13 Michael Walle
    uint32_t features;
181 81ea0e13 Michael Walle
    uint32_t flags;
182 81ea0e13 Michael Walle
    uint8_t num_bps;
183 81ea0e13 Michael Walle
    uint8_t num_wps;
184 81ea0e13 Michael Walle
185 ae7d54d4 Andreas Färber
};
186 81ea0e13 Michael Walle
187 fc0ced2f Andreas Färber
#include "cpu-qom.h"
188 81ea0e13 Michael Walle
189 0347d689 Andreas Färber
LM32CPU *cpu_lm32_init(const char *cpu_model);
190 81ea0e13 Michael Walle
void cpu_lm32_list(FILE *f, fprintf_function cpu_fprintf);
191 6393c08d Andreas Färber
int cpu_lm32_exec(CPULM32State *s);
192 81ea0e13 Michael Walle
/* you can call this signal handler from your SIGBUS and SIGSEGV
193 81ea0e13 Michael Walle
   signal handlers to inform the virtual CPU of exceptions. non zero
194 81ea0e13 Michael Walle
   is returned if the signal was handled by the virtual CPU.  */
195 81ea0e13 Michael Walle
int cpu_lm32_signal_handler(int host_signum, void *pinfo,
196 81ea0e13 Michael Walle
                          void *puc);
197 81ea0e13 Michael Walle
void lm32_translate_init(void);
198 6393c08d Andreas Färber
void cpu_lm32_set_phys_msb_ignore(CPULM32State *env, int value);
199 81ea0e13 Michael Walle
200 0347d689 Andreas Färber
static inline CPULM32State *cpu_init(const char *cpu_model)
201 0347d689 Andreas Färber
{
202 0347d689 Andreas Färber
    LM32CPU *cpu = cpu_lm32_init(cpu_model);
203 0347d689 Andreas Färber
    if (cpu == NULL) {
204 0347d689 Andreas Färber
        return NULL;
205 0347d689 Andreas Färber
    }
206 0347d689 Andreas Färber
    return &cpu->env;
207 0347d689 Andreas Färber
}
208 0347d689 Andreas Färber
209 81ea0e13 Michael Walle
#define cpu_list cpu_lm32_list
210 81ea0e13 Michael Walle
#define cpu_exec cpu_lm32_exec
211 81ea0e13 Michael Walle
#define cpu_gen_code cpu_lm32_gen_code
212 81ea0e13 Michael Walle
#define cpu_signal_handler cpu_lm32_signal_handler
213 81ea0e13 Michael Walle
214 6393c08d Andreas Färber
int cpu_lm32_handle_mmu_fault(CPULM32State *env, target_ulong address, int rw,
215 97b348e7 Blue Swirl
                              int mmu_idx);
216 81ea0e13 Michael Walle
#define cpu_handle_mmu_fault cpu_lm32_handle_mmu_fault
217 81ea0e13 Michael Walle
218 022c62cb Paolo Bonzini
#include "exec/cpu-all.h"
219 81ea0e13 Michael Walle
220 6393c08d Andreas Färber
static inline void cpu_get_tb_cpu_state(CPULM32State *env, target_ulong *pc,
221 81ea0e13 Michael Walle
                                        target_ulong *cs_base, int *flags)
222 81ea0e13 Michael Walle
{
223 81ea0e13 Michael Walle
    *pc = env->pc;
224 81ea0e13 Michael Walle
    *cs_base = 0;
225 81ea0e13 Michael Walle
    *flags = 0;
226 81ea0e13 Michael Walle
}
227 f081c76c Blue Swirl
228 3993c6bd Andreas Färber
static inline bool cpu_has_work(CPUState *cpu)
229 f081c76c Blue Swirl
{
230 259186a7 Andreas Färber
    return cpu->interrupt_request & CPU_INTERRUPT_HARD;
231 f081c76c Blue Swirl
}
232 f081c76c Blue Swirl
233 022c62cb Paolo Bonzini
#include "exec/exec-all.h"
234 f081c76c Blue Swirl
235 81ea0e13 Michael Walle
#endif