Statistics
| Branch: | Revision:

root / target-arm / cpu.h @ 3aa22b4b

History | View | Annotate | Download (5.9 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 b5ff1b31 bellard
        uint32_t c1_sys; /* System control register.  */
76 b5ff1b31 bellard
        uint32_t c1_coproc; /* Coprocessor access register.  */
77 b5ff1b31 bellard
        uint32_t c2; /* MMU translation table base.  */
78 b5ff1b31 bellard
        uint32_t c3; /* MMU domain access control register.  */
79 b5ff1b31 bellard
        uint32_t c5_insn; /* Fault status registers.  */
80 b5ff1b31 bellard
        uint32_t c5_data;
81 b5ff1b31 bellard
        uint32_t c6_insn; /* Fault address registers.  */
82 b5ff1b31 bellard
        uint32_t c6_data;
83 b5ff1b31 bellard
        uint32_t c9_insn; /* Cache lockdown registers.  */
84 b5ff1b31 bellard
        uint32_t c9_data;
85 b5ff1b31 bellard
        uint32_t c13_fcse; /* FCSE PID.  */
86 b5ff1b31 bellard
        uint32_t c13_context; /* Context ID.  */
87 b5ff1b31 bellard
    } cp15;
88 b8a9e8f1 bellard
    
89 2c0262af bellard
    /* exception/interrupt handling */
90 2c0262af bellard
    jmp_buf jmp_env;
91 2c0262af bellard
    int exception_index;
92 2c0262af bellard
    int interrupt_request;
93 2c0262af bellard
    int user_mode_only;
94 9332f9da bellard
    int halted;
95 2c0262af bellard
96 b7bcbe95 bellard
    /* VFP coprocessor state.  */
97 b7bcbe95 bellard
    struct {
98 8e96005d bellard
        float64 regs[16];
99 b7bcbe95 bellard
100 b7bcbe95 bellard
        /* We store these fpcsr fields separately for convenience.  */
101 b7bcbe95 bellard
        int vec_len;
102 b7bcbe95 bellard
        int vec_stride;
103 b7bcbe95 bellard
104 b7bcbe95 bellard
        uint32_t fpscr;
105 b7bcbe95 bellard
106 b7bcbe95 bellard
        /* Temporary variables if we don't have spare fp regs.  */
107 53cd6637 bellard
        float32 tmp0s, tmp1s;
108 53cd6637 bellard
        float64 tmp0d, tmp1d;
109 53cd6637 bellard
        
110 53cd6637 bellard
        float_status fp_status;
111 b7bcbe95 bellard
    } vfp;
112 b7bcbe95 bellard
113 a316d335 bellard
    CPU_COMMON
114 a316d335 bellard
115 2c0262af bellard
} CPUARMState;
116 2c0262af bellard
117 2c0262af bellard
CPUARMState *cpu_arm_init(void);
118 2c0262af bellard
int cpu_arm_exec(CPUARMState *s);
119 2c0262af bellard
void cpu_arm_close(CPUARMState *s);
120 b5ff1b31 bellard
void do_interrupt(CPUARMState *);
121 b5ff1b31 bellard
void switch_mode(CPUARMState *, int);
122 b5ff1b31 bellard
123 2c0262af bellard
/* you can call this signal handler from your SIGBUS and SIGSEGV
124 2c0262af bellard
   signal handlers to inform the virtual CPU of exceptions. non zero
125 2c0262af bellard
   is returned if the signal was handled by the virtual CPU.  */
126 2c0262af bellard
struct siginfo;
127 2c0262af bellard
int cpu_arm_signal_handler(int host_signum, struct siginfo *info, 
128 2c0262af bellard
                           void *puc);
129 2c0262af bellard
130 b5ff1b31 bellard
#define CPSR_M (0x1f)
131 b5ff1b31 bellard
#define CPSR_T (1 << 5)
132 b5ff1b31 bellard
#define CPSR_F (1 << 6)
133 b5ff1b31 bellard
#define CPSR_I (1 << 7)
134 b5ff1b31 bellard
#define CPSR_A (1 << 8)
135 b5ff1b31 bellard
#define CPSR_E (1 << 9)
136 b5ff1b31 bellard
#define CPSR_IT_2_7 (0xfc00)
137 b5ff1b31 bellard
/* Bits 20-23 reserved.  */
138 b5ff1b31 bellard
#define CPSR_J (1 << 24)
139 b5ff1b31 bellard
#define CPSR_IT_0_1 (3 << 25)
140 b5ff1b31 bellard
#define CPSR_Q (1 << 27)
141 b5ff1b31 bellard
#define CPSR_NZCV (0xf << 28)
142 b5ff1b31 bellard
143 b5ff1b31 bellard
#define CACHED_CPSR_BITS (CPSR_T | CPSR_Q | CPSR_NZCV)
144 b5ff1b31 bellard
/* Return the current CPSR value.  */
145 b5ff1b31 bellard
static inline uint32_t cpsr_read(CPUARMState *env)
146 b5ff1b31 bellard
{
147 b5ff1b31 bellard
    int ZF;
148 b5ff1b31 bellard
    ZF = (env->NZF == 0);
149 b5ff1b31 bellard
    return env->uncached_cpsr | (env->NZF & 0x80000000) | (ZF << 30) | 
150 b5ff1b31 bellard
        (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
151 b5ff1b31 bellard
        | (env->thumb << 5);
152 b5ff1b31 bellard
}
153 b5ff1b31 bellard
154 b5ff1b31 bellard
/* Set the CPSR.  Note that some bits of mask must be all-set or all-clear.  */
155 b5ff1b31 bellard
static inline void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
156 b5ff1b31 bellard
{
157 b5ff1b31 bellard
    /* NOTE: N = 1 and Z = 1 cannot be stored currently */
158 b5ff1b31 bellard
    if (mask & CPSR_NZCV) {
159 b5ff1b31 bellard
        env->NZF = (val & 0xc0000000) ^ 0x40000000;
160 b5ff1b31 bellard
        env->CF = (val >> 29) & 1;
161 b5ff1b31 bellard
        env->VF = (val << 3) & 0x80000000;
162 b5ff1b31 bellard
    }
163 b5ff1b31 bellard
    if (mask & CPSR_Q)
164 b5ff1b31 bellard
        env->QF = ((val & CPSR_Q) != 0);
165 b5ff1b31 bellard
    if (mask & CPSR_T)
166 b5ff1b31 bellard
        env->thumb = ((val & CPSR_T) != 0);
167 b5ff1b31 bellard
168 b5ff1b31 bellard
    if ((env->uncached_cpsr ^ val) & mask & CPSR_M) {
169 b5ff1b31 bellard
        switch_mode(env, val & CPSR_M);
170 b5ff1b31 bellard
    }
171 b5ff1b31 bellard
    mask &= ~CACHED_CPSR_BITS;
172 b5ff1b31 bellard
    env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask);
173 b5ff1b31 bellard
}
174 b5ff1b31 bellard
175 b5ff1b31 bellard
enum arm_cpu_mode {
176 b5ff1b31 bellard
  ARM_CPU_MODE_USR = 0x10,
177 b5ff1b31 bellard
  ARM_CPU_MODE_FIQ = 0x11,
178 b5ff1b31 bellard
  ARM_CPU_MODE_IRQ = 0x12,
179 b5ff1b31 bellard
  ARM_CPU_MODE_SVC = 0x13,
180 b5ff1b31 bellard
  ARM_CPU_MODE_ABT = 0x17,
181 b5ff1b31 bellard
  ARM_CPU_MODE_UND = 0x1b,
182 b5ff1b31 bellard
  ARM_CPU_MODE_SYS = 0x1f
183 b5ff1b31 bellard
};
184 b5ff1b31 bellard
185 b5ff1b31 bellard
#if defined(CONFIG_USER_ONLY)
186 2c0262af bellard
#define TARGET_PAGE_BITS 12
187 b5ff1b31 bellard
#else
188 b5ff1b31 bellard
/* The ARM MMU allows 1k pages.  */
189 b5ff1b31 bellard
/* ??? Linux doesn't actually use these, and they're deprecated in recent
190 b5ff1b31 bellard
   architecture revisions.  Maybe an a configure option to disable them.  */
191 b5ff1b31 bellard
#define TARGET_PAGE_BITS 10
192 b5ff1b31 bellard
#endif
193 2c0262af bellard
#include "cpu-all.h"
194 2c0262af bellard
195 2c0262af bellard
#endif