Statistics
| Branch: | Revision:

root / target-arm / cpu.h @ af5db58e

History | View | Annotate | Download (6.6 kB)

1 2c0262af bellard
/*
2 2c0262af bellard
 * ARM virtual CPU header
3 2c0262af bellard
 * 
4 2c0262af bellard
 *  Copyright (c) 2003 Fabrice Bellard
5 2c0262af bellard
 *
6 2c0262af bellard
 * This library is free software; you can redistribute it and/or
7 2c0262af bellard
 * modify it under the terms of the GNU Lesser General Public
8 2c0262af bellard
 * License as published by the Free Software Foundation; either
9 2c0262af bellard
 * version 2 of the License, or (at your option) any later version.
10 2c0262af bellard
 *
11 2c0262af bellard
 * This library is distributed in the hope that it will be useful,
12 2c0262af bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 2c0262af bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 2c0262af bellard
 * Lesser General Public License for more details.
15 2c0262af bellard
 *
16 2c0262af bellard
 * You should have received a copy of the GNU Lesser General Public
17 2c0262af bellard
 * License along with this library; if not, write to the Free Software
18 2c0262af bellard
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 2c0262af bellard
 */
20 2c0262af bellard
#ifndef CPU_ARM_H
21 2c0262af bellard
#define CPU_ARM_H
22 2c0262af bellard
23 3cf1e035 bellard
#define TARGET_LONG_BITS 32
24 3cf1e035 bellard
25 2c0262af bellard
#include "cpu-defs.h"
26 2c0262af bellard
27 53cd6637 bellard
#include "softfloat.h"
28 53cd6637 bellard
29 1fddef4b bellard
#define TARGET_HAS_ICE 1
30 1fddef4b bellard
31 b8a9e8f1 bellard
#define EXCP_UDEF            1   /* undefined instruction */
32 b8a9e8f1 bellard
#define EXCP_SWI             2   /* software interrupt */
33 b8a9e8f1 bellard
#define EXCP_PREFETCH_ABORT  3
34 b8a9e8f1 bellard
#define EXCP_DATA_ABORT      4
35 b5ff1b31 bellard
#define EXCP_IRQ             5
36 b5ff1b31 bellard
#define EXCP_FIQ             6
37 06c949e6 pbrook
#define EXCP_BKPT            7
38 2c0262af bellard
39 b7bcbe95 bellard
/* We currently assume float and double are IEEE single and double
40 b7bcbe95 bellard
   precision respectively.
41 b7bcbe95 bellard
   Doing runtime conversions is tricky because VFP registers may contain
42 b7bcbe95 bellard
   integer values (eg. as the result of a FTOSI instruction).
43 8e96005d bellard
   s<2n> maps to the least significant half of d<n>
44 8e96005d bellard
   s<2n+1> maps to the most significant half of d<n>
45 8e96005d bellard
 */
46 b7bcbe95 bellard
47 2c0262af bellard
typedef struct CPUARMState {
48 b5ff1b31 bellard
    /* Regs for current mode.  */
49 2c0262af bellard
    uint32_t regs[16];
50 b5ff1b31 bellard
    /* Frequently accessed CPSR bits are stored separately for efficiently.
51 b5ff1b31 bellard
       This contains all the other bits.  Use cpsr_{read,write} to accless
52 b5ff1b31 bellard
       the whole CPSR.  */
53 b5ff1b31 bellard
    uint32_t uncached_cpsr;
54 b5ff1b31 bellard
    uint32_t spsr;
55 b5ff1b31 bellard
56 b5ff1b31 bellard
    /* Banked registers.  */
57 b5ff1b31 bellard
    uint32_t banked_spsr[6];
58 b5ff1b31 bellard
    uint32_t banked_r13[6];
59 b5ff1b31 bellard
    uint32_t banked_r14[6];
60 b5ff1b31 bellard
    
61 b5ff1b31 bellard
    /* These hold r8-r12.  */
62 b5ff1b31 bellard
    uint32_t usr_regs[5];
63 b5ff1b31 bellard
    uint32_t fiq_regs[5];
64 2c0262af bellard
    
65 2c0262af bellard
    /* cpsr flag cache for faster execution */
66 2c0262af bellard
    uint32_t CF; /* 0 or 1 */
67 2c0262af bellard
    uint32_t VF; /* V is the bit 31. All other bits are undefined */
68 2c0262af bellard
    uint32_t NZF; /* N is bit 31. Z is computed from NZF */
69 99c475ab bellard
    uint32_t QF; /* 0 or 1 */
70 99c475ab bellard
71 99c475ab bellard
    int thumb; /* 0 = arm mode, 1 = thumb mode */
72 2c0262af bellard
73 b5ff1b31 bellard
    /* System control coprocessor (cp15) */
74 b5ff1b31 bellard
    struct {
75 40f137e1 pbrook
        uint32_t c0_cpuid;
76 b5ff1b31 bellard
        uint32_t c1_sys; /* System control register.  */
77 b5ff1b31 bellard
        uint32_t c1_coproc; /* Coprocessor access register.  */
78 b5ff1b31 bellard
        uint32_t c2; /* MMU translation table base.  */
79 b5ff1b31 bellard
        uint32_t c3; /* MMU domain access control register.  */
80 b5ff1b31 bellard
        uint32_t c5_insn; /* Fault status registers.  */
81 b5ff1b31 bellard
        uint32_t c5_data;
82 b5ff1b31 bellard
        uint32_t c6_insn; /* Fault address registers.  */
83 b5ff1b31 bellard
        uint32_t c6_data;
84 b5ff1b31 bellard
        uint32_t c9_insn; /* Cache lockdown registers.  */
85 b5ff1b31 bellard
        uint32_t c9_data;
86 b5ff1b31 bellard
        uint32_t c13_fcse; /* FCSE PID.  */
87 b5ff1b31 bellard
        uint32_t c13_context; /* Context ID.  */
88 b5ff1b31 bellard
    } cp15;
89 40f137e1 pbrook
90 40f137e1 pbrook
    /* Internal CPU feature flags.  */
91 40f137e1 pbrook
    uint32_t features;
92 40f137e1 pbrook
93 2c0262af bellard
    /* exception/interrupt handling */
94 2c0262af bellard
    jmp_buf jmp_env;
95 2c0262af bellard
    int exception_index;
96 2c0262af bellard
    int interrupt_request;
97 2c0262af bellard
    int user_mode_only;
98 9332f9da bellard
    int halted;
99 2c0262af bellard
100 b7bcbe95 bellard
    /* VFP coprocessor state.  */
101 b7bcbe95 bellard
    struct {
102 8e96005d bellard
        float64 regs[16];
103 b7bcbe95 bellard
104 40f137e1 pbrook
        uint32_t xregs[16];
105 b7bcbe95 bellard
        /* We store these fpcsr fields separately for convenience.  */
106 b7bcbe95 bellard
        int vec_len;
107 b7bcbe95 bellard
        int vec_stride;
108 b7bcbe95 bellard
109 b7bcbe95 bellard
        /* Temporary variables if we don't have spare fp regs.  */
110 53cd6637 bellard
        float32 tmp0s, tmp1s;
111 53cd6637 bellard
        float64 tmp0d, tmp1d;
112 53cd6637 bellard
        
113 53cd6637 bellard
        float_status fp_status;
114 b7bcbe95 bellard
    } vfp;
115 b7bcbe95 bellard
116 ce4defa0 pbrook
#if defined(CONFIG_USER_ONLY)
117 ce4defa0 pbrook
    /* For usermode syscall translation.  */
118 ce4defa0 pbrook
    int eabi;
119 ce4defa0 pbrook
#endif
120 ce4defa0 pbrook
121 a316d335 bellard
    CPU_COMMON
122 a316d335 bellard
123 2c0262af bellard
} CPUARMState;
124 2c0262af bellard
125 2c0262af bellard
CPUARMState *cpu_arm_init(void);
126 2c0262af bellard
int cpu_arm_exec(CPUARMState *s);
127 2c0262af bellard
void cpu_arm_close(CPUARMState *s);
128 b5ff1b31 bellard
void do_interrupt(CPUARMState *);
129 b5ff1b31 bellard
void switch_mode(CPUARMState *, int);
130 b5ff1b31 bellard
131 2c0262af bellard
/* you can call this signal handler from your SIGBUS and SIGSEGV
132 2c0262af bellard
   signal handlers to inform the virtual CPU of exceptions. non zero
133 2c0262af bellard
   is returned if the signal was handled by the virtual CPU.  */
134 2c0262af bellard
struct siginfo;
135 2c0262af bellard
int cpu_arm_signal_handler(int host_signum, struct siginfo *info, 
136 2c0262af bellard
                           void *puc);
137 2c0262af bellard
138 b5ff1b31 bellard
#define CPSR_M (0x1f)
139 b5ff1b31 bellard
#define CPSR_T (1 << 5)
140 b5ff1b31 bellard
#define CPSR_F (1 << 6)
141 b5ff1b31 bellard
#define CPSR_I (1 << 7)
142 b5ff1b31 bellard
#define CPSR_A (1 << 8)
143 b5ff1b31 bellard
#define CPSR_E (1 << 9)
144 b5ff1b31 bellard
#define CPSR_IT_2_7 (0xfc00)
145 b5ff1b31 bellard
/* Bits 20-23 reserved.  */
146 b5ff1b31 bellard
#define CPSR_J (1 << 24)
147 b5ff1b31 bellard
#define CPSR_IT_0_1 (3 << 25)
148 b5ff1b31 bellard
#define CPSR_Q (1 << 27)
149 b5ff1b31 bellard
#define CPSR_NZCV (0xf << 28)
150 b5ff1b31 bellard
151 b5ff1b31 bellard
#define CACHED_CPSR_BITS (CPSR_T | CPSR_Q | CPSR_NZCV)
152 b5ff1b31 bellard
/* Return the current CPSR value.  */
153 b5ff1b31 bellard
static inline uint32_t cpsr_read(CPUARMState *env)
154 b5ff1b31 bellard
{
155 b5ff1b31 bellard
    int ZF;
156 b5ff1b31 bellard
    ZF = (env->NZF == 0);
157 b5ff1b31 bellard
    return env->uncached_cpsr | (env->NZF & 0x80000000) | (ZF << 30) | 
158 b5ff1b31 bellard
        (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
159 b5ff1b31 bellard
        | (env->thumb << 5);
160 b5ff1b31 bellard
}
161 b5ff1b31 bellard
162 b5ff1b31 bellard
/* Set the CPSR.  Note that some bits of mask must be all-set or all-clear.  */
163 b5ff1b31 bellard
static inline void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
164 b5ff1b31 bellard
{
165 b5ff1b31 bellard
    /* NOTE: N = 1 and Z = 1 cannot be stored currently */
166 b5ff1b31 bellard
    if (mask & CPSR_NZCV) {
167 b5ff1b31 bellard
        env->NZF = (val & 0xc0000000) ^ 0x40000000;
168 b5ff1b31 bellard
        env->CF = (val >> 29) & 1;
169 b5ff1b31 bellard
        env->VF = (val << 3) & 0x80000000;
170 b5ff1b31 bellard
    }
171 b5ff1b31 bellard
    if (mask & CPSR_Q)
172 b5ff1b31 bellard
        env->QF = ((val & CPSR_Q) != 0);
173 b5ff1b31 bellard
    if (mask & CPSR_T)
174 b5ff1b31 bellard
        env->thumb = ((val & CPSR_T) != 0);
175 b5ff1b31 bellard
176 b5ff1b31 bellard
    if ((env->uncached_cpsr ^ val) & mask & CPSR_M) {
177 b5ff1b31 bellard
        switch_mode(env, val & CPSR_M);
178 b5ff1b31 bellard
    }
179 b5ff1b31 bellard
    mask &= ~CACHED_CPSR_BITS;
180 b5ff1b31 bellard
    env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask);
181 b5ff1b31 bellard
}
182 b5ff1b31 bellard
183 b5ff1b31 bellard
enum arm_cpu_mode {
184 b5ff1b31 bellard
  ARM_CPU_MODE_USR = 0x10,
185 b5ff1b31 bellard
  ARM_CPU_MODE_FIQ = 0x11,
186 b5ff1b31 bellard
  ARM_CPU_MODE_IRQ = 0x12,
187 b5ff1b31 bellard
  ARM_CPU_MODE_SVC = 0x13,
188 b5ff1b31 bellard
  ARM_CPU_MODE_ABT = 0x17,
189 b5ff1b31 bellard
  ARM_CPU_MODE_UND = 0x1b,
190 b5ff1b31 bellard
  ARM_CPU_MODE_SYS = 0x1f
191 b5ff1b31 bellard
};
192 b5ff1b31 bellard
193 40f137e1 pbrook
/* VFP system registers.  */
194 40f137e1 pbrook
#define ARM_VFP_FPSID   0
195 40f137e1 pbrook
#define ARM_VFP_FPSCR   1
196 40f137e1 pbrook
#define ARM_VFP_FPEXC   8
197 40f137e1 pbrook
#define ARM_VFP_FPINST  9
198 40f137e1 pbrook
#define ARM_VFP_FPINST2 10
199 40f137e1 pbrook
200 40f137e1 pbrook
201 40f137e1 pbrook
enum arm_features {
202 40f137e1 pbrook
    ARM_FEATURE_VFP,
203 40f137e1 pbrook
    ARM_FEATURE_AUXCR /* ARM1026 Auxiliary control register.  */
204 40f137e1 pbrook
};
205 40f137e1 pbrook
206 40f137e1 pbrook
static inline int arm_feature(CPUARMState *env, int feature)
207 40f137e1 pbrook
{
208 40f137e1 pbrook
    return (env->features & (1u << feature)) != 0;
209 40f137e1 pbrook
}
210 40f137e1 pbrook
211 40f137e1 pbrook
void cpu_arm_set_model(CPUARMState *env, uint32_t id);
212 40f137e1 pbrook
213 40f137e1 pbrook
#define ARM_CPUID_ARM1026 0x4106a262
214 40f137e1 pbrook
#define ARM_CPUID_ARM926  0x41069265
215 40f137e1 pbrook
216 b5ff1b31 bellard
#if defined(CONFIG_USER_ONLY)
217 2c0262af bellard
#define TARGET_PAGE_BITS 12
218 b5ff1b31 bellard
#else
219 b5ff1b31 bellard
/* The ARM MMU allows 1k pages.  */
220 b5ff1b31 bellard
/* ??? Linux doesn't actually use these, and they're deprecated in recent
221 b5ff1b31 bellard
   architecture revisions.  Maybe an a configure option to disable them.  */
222 b5ff1b31 bellard
#define TARGET_PAGE_BITS 10
223 b5ff1b31 bellard
#endif
224 2c0262af bellard
#include "cpu-all.h"
225 2c0262af bellard
226 2c0262af bellard
#endif