xref: /openbmc/qemu/target/alpha/cpu.h (revision 28ae3179fc52d2e4d870b635c4a412aab99759e7)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  *  Alpha emulation cpu definitions for qemu.
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  *  Copyright (c) 2007 Jocelyn Mayer
5fcf5ef2aSThomas Huth  *
6fcf5ef2aSThomas Huth  * This library is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8fcf5ef2aSThomas Huth  * License as published by the Free Software Foundation; either
9d6ea4236SChetan Pant  * version 2.1 of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth  *
11fcf5ef2aSThomas Huth  * This library is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14fcf5ef2aSThomas Huth  * Lesser General Public License for more details.
15fcf5ef2aSThomas Huth  *
16fcf5ef2aSThomas Huth  * You should have received a copy of the GNU Lesser General Public
17fcf5ef2aSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18fcf5ef2aSThomas Huth  */
19fcf5ef2aSThomas Huth 
20fcf5ef2aSThomas Huth #ifndef ALPHA_CPU_H
21fcf5ef2aSThomas Huth #define ALPHA_CPU_H
22fcf5ef2aSThomas Huth 
23fcf5ef2aSThomas Huth #include "cpu-qom.h"
2474433bf0SRichard Henderson #include "exec/cpu-defs.h"
2569242e7eSMarc-André Lureau #include "qemu/cpu-float.h"
26fcf5ef2aSThomas Huth 
27fcf5ef2aSThomas Huth #define ICACHE_LINE_SIZE 32
28fcf5ef2aSThomas Huth #define DCACHE_LINE_SIZE 32
29fcf5ef2aSThomas Huth 
30fcf5ef2aSThomas Huth /* Alpha major type */
31fcf5ef2aSThomas Huth enum {
32fcf5ef2aSThomas Huth     ALPHA_EV3  = 1,
33fcf5ef2aSThomas Huth     ALPHA_EV4  = 2,
34fcf5ef2aSThomas Huth     ALPHA_SIM  = 3,
35fcf5ef2aSThomas Huth     ALPHA_LCA  = 4,
36fcf5ef2aSThomas Huth     ALPHA_EV5  = 5, /* 21164 */
37fcf5ef2aSThomas Huth     ALPHA_EV45 = 6, /* 21064A */
38fcf5ef2aSThomas Huth     ALPHA_EV56 = 7, /* 21164A */
39fcf5ef2aSThomas Huth };
40fcf5ef2aSThomas Huth 
41fcf5ef2aSThomas Huth /* EV4 minor type */
42fcf5ef2aSThomas Huth enum {
43fcf5ef2aSThomas Huth     ALPHA_EV4_2 = 0,
44fcf5ef2aSThomas Huth     ALPHA_EV4_3 = 1,
45fcf5ef2aSThomas Huth };
46fcf5ef2aSThomas Huth 
47fcf5ef2aSThomas Huth /* LCA minor type */
48fcf5ef2aSThomas Huth enum {
49fcf5ef2aSThomas Huth     ALPHA_LCA_1 = 1, /* 21066 */
50fcf5ef2aSThomas Huth     ALPHA_LCA_2 = 2, /* 20166 */
51fcf5ef2aSThomas Huth     ALPHA_LCA_3 = 3, /* 21068 */
52fcf5ef2aSThomas Huth     ALPHA_LCA_4 = 4, /* 21068 */
53fcf5ef2aSThomas Huth     ALPHA_LCA_5 = 5, /* 21066A */
54fcf5ef2aSThomas Huth     ALPHA_LCA_6 = 6, /* 21068A */
55fcf5ef2aSThomas Huth };
56fcf5ef2aSThomas Huth 
57fcf5ef2aSThomas Huth /* EV5 minor type */
58fcf5ef2aSThomas Huth enum {
59fcf5ef2aSThomas Huth     ALPHA_EV5_1 = 1, /* Rev BA, CA */
60fcf5ef2aSThomas Huth     ALPHA_EV5_2 = 2, /* Rev DA, EA */
61fcf5ef2aSThomas Huth     ALPHA_EV5_3 = 3, /* Pass 3 */
62fcf5ef2aSThomas Huth     ALPHA_EV5_4 = 4, /* Pass 3.2 */
63fcf5ef2aSThomas Huth     ALPHA_EV5_5 = 5, /* Pass 4 */
64fcf5ef2aSThomas Huth };
65fcf5ef2aSThomas Huth 
66fcf5ef2aSThomas Huth /* EV45 minor type */
67fcf5ef2aSThomas Huth enum {
68fcf5ef2aSThomas Huth     ALPHA_EV45_1 = 1, /* Pass 1 */
69fcf5ef2aSThomas Huth     ALPHA_EV45_2 = 2, /* Pass 1.1 */
70fcf5ef2aSThomas Huth     ALPHA_EV45_3 = 3, /* Pass 2 */
71fcf5ef2aSThomas Huth };
72fcf5ef2aSThomas Huth 
73fcf5ef2aSThomas Huth /* EV56 minor type */
74fcf5ef2aSThomas Huth enum {
75fcf5ef2aSThomas Huth     ALPHA_EV56_1 = 1, /* Pass 1 */
76fcf5ef2aSThomas Huth     ALPHA_EV56_2 = 2, /* Pass 2 */
77fcf5ef2aSThomas Huth };
78fcf5ef2aSThomas Huth 
79fcf5ef2aSThomas Huth enum {
80fcf5ef2aSThomas Huth     IMPLVER_2106x = 0, /* EV4, EV45 & LCA45 */
81fcf5ef2aSThomas Huth     IMPLVER_21164 = 1, /* EV5, EV56 & PCA45 */
82fcf5ef2aSThomas Huth     IMPLVER_21264 = 2, /* EV6, EV67 & EV68x */
83fcf5ef2aSThomas Huth     IMPLVER_21364 = 3, /* EV7 & EV79 */
84fcf5ef2aSThomas Huth };
85fcf5ef2aSThomas Huth 
86fcf5ef2aSThomas Huth enum {
87fcf5ef2aSThomas Huth     AMASK_BWX      = 0x00000001,
88fcf5ef2aSThomas Huth     AMASK_FIX      = 0x00000002,
89fcf5ef2aSThomas Huth     AMASK_CIX      = 0x00000004,
90fcf5ef2aSThomas Huth     AMASK_MVI      = 0x00000100,
91fcf5ef2aSThomas Huth     AMASK_TRAP     = 0x00000200,
92fcf5ef2aSThomas Huth     AMASK_PREFETCH = 0x00001000,
93fcf5ef2aSThomas Huth };
94fcf5ef2aSThomas Huth 
95fcf5ef2aSThomas Huth enum {
96fcf5ef2aSThomas Huth     VAX_ROUND_NORMAL = 0,
97fcf5ef2aSThomas Huth     VAX_ROUND_CHOPPED,
98fcf5ef2aSThomas Huth };
99fcf5ef2aSThomas Huth 
100fcf5ef2aSThomas Huth enum {
101fcf5ef2aSThomas Huth     IEEE_ROUND_NORMAL = 0,
102fcf5ef2aSThomas Huth     IEEE_ROUND_DYNAMIC,
103fcf5ef2aSThomas Huth     IEEE_ROUND_PLUS,
104fcf5ef2aSThomas Huth     IEEE_ROUND_MINUS,
105fcf5ef2aSThomas Huth     IEEE_ROUND_CHOPPED,
106fcf5ef2aSThomas Huth };
107fcf5ef2aSThomas Huth 
108fcf5ef2aSThomas Huth /* IEEE floating-point operations encoding */
109fcf5ef2aSThomas Huth /* Trap mode */
110fcf5ef2aSThomas Huth enum {
111fcf5ef2aSThomas Huth     FP_TRAP_I   = 0x0,
112fcf5ef2aSThomas Huth     FP_TRAP_U   = 0x1,
113fcf5ef2aSThomas Huth     FP_TRAP_S  = 0x4,
114fcf5ef2aSThomas Huth     FP_TRAP_SU  = 0x5,
115fcf5ef2aSThomas Huth     FP_TRAP_SUI = 0x7,
116fcf5ef2aSThomas Huth };
117fcf5ef2aSThomas Huth 
118fcf5ef2aSThomas Huth /* Rounding mode */
119fcf5ef2aSThomas Huth enum {
120fcf5ef2aSThomas Huth     FP_ROUND_CHOPPED = 0x0,
121fcf5ef2aSThomas Huth     FP_ROUND_MINUS   = 0x1,
122fcf5ef2aSThomas Huth     FP_ROUND_NORMAL  = 0x2,
123fcf5ef2aSThomas Huth     FP_ROUND_DYNAMIC = 0x3,
124fcf5ef2aSThomas Huth };
125fcf5ef2aSThomas Huth 
126fcf5ef2aSThomas Huth /* FPCR bits -- right-shifted 32 so we can use a uint32_t.  */
127fcf5ef2aSThomas Huth #define FPCR_SUM                (1U << (63 - 32))
128fcf5ef2aSThomas Huth #define FPCR_INED               (1U << (62 - 32))
129fcf5ef2aSThomas Huth #define FPCR_UNFD               (1U << (61 - 32))
130fcf5ef2aSThomas Huth #define FPCR_UNDZ               (1U << (60 - 32))
131fcf5ef2aSThomas Huth #define FPCR_DYN_SHIFT          (58 - 32)
132fcf5ef2aSThomas Huth #define FPCR_DYN_CHOPPED        (0U << FPCR_DYN_SHIFT)
133fcf5ef2aSThomas Huth #define FPCR_DYN_MINUS          (1U << FPCR_DYN_SHIFT)
134fcf5ef2aSThomas Huth #define FPCR_DYN_NORMAL         (2U << FPCR_DYN_SHIFT)
135fcf5ef2aSThomas Huth #define FPCR_DYN_PLUS           (3U << FPCR_DYN_SHIFT)
136fcf5ef2aSThomas Huth #define FPCR_DYN_MASK           (3U << FPCR_DYN_SHIFT)
137fcf5ef2aSThomas Huth #define FPCR_IOV                (1U << (57 - 32))
138fcf5ef2aSThomas Huth #define FPCR_INE                (1U << (56 - 32))
139fcf5ef2aSThomas Huth #define FPCR_UNF                (1U << (55 - 32))
140fcf5ef2aSThomas Huth #define FPCR_OVF                (1U << (54 - 32))
141fcf5ef2aSThomas Huth #define FPCR_DZE                (1U << (53 - 32))
142fcf5ef2aSThomas Huth #define FPCR_INV                (1U << (52 - 32))
143fcf5ef2aSThomas Huth #define FPCR_OVFD               (1U << (51 - 32))
144fcf5ef2aSThomas Huth #define FPCR_DZED               (1U << (50 - 32))
145fcf5ef2aSThomas Huth #define FPCR_INVD               (1U << (49 - 32))
146fcf5ef2aSThomas Huth #define FPCR_DNZ                (1U << (48 - 32))
147fcf5ef2aSThomas Huth #define FPCR_DNOD               (1U << (47 - 32))
148fcf5ef2aSThomas Huth #define FPCR_STATUS_MASK        (FPCR_IOV | FPCR_INE | FPCR_UNF \
149fcf5ef2aSThomas Huth                                  | FPCR_OVF | FPCR_DZE | FPCR_INV)
150fcf5ef2aSThomas Huth 
151fcf5ef2aSThomas Huth /* The silly software trap enables implemented by the kernel emulation.
152fcf5ef2aSThomas Huth    These are more or less architecturally required, since the real hardware
153fcf5ef2aSThomas Huth    has read-as-zero bits in the FPCR when the features aren't implemented.
154fcf5ef2aSThomas Huth    For the purposes of QEMU, we pretend the FPCR can hold everything.  */
155fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_INV    (1U << 1)
156fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_DZE    (1U << 2)
157fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_OVF    (1U << 3)
158fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_UNF    (1U << 4)
159fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_INE    (1U << 5)
160fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_DNO    (1U << 6)
161fcf5ef2aSThomas Huth #define SWCR_TRAP_ENABLE_MASK   ((1U << 7) - (1U << 1))
162fcf5ef2aSThomas Huth 
163fcf5ef2aSThomas Huth #define SWCR_MAP_DMZ            (1U << 12)
164fcf5ef2aSThomas Huth #define SWCR_MAP_UMZ            (1U << 13)
165fcf5ef2aSThomas Huth #define SWCR_MAP_MASK           (SWCR_MAP_DMZ | SWCR_MAP_UMZ)
166fcf5ef2aSThomas Huth 
167fcf5ef2aSThomas Huth #define SWCR_STATUS_INV         (1U << 17)
168fcf5ef2aSThomas Huth #define SWCR_STATUS_DZE         (1U << 18)
169fcf5ef2aSThomas Huth #define SWCR_STATUS_OVF         (1U << 19)
170fcf5ef2aSThomas Huth #define SWCR_STATUS_UNF         (1U << 20)
171fcf5ef2aSThomas Huth #define SWCR_STATUS_INE         (1U << 21)
172fcf5ef2aSThomas Huth #define SWCR_STATUS_DNO         (1U << 22)
173fcf5ef2aSThomas Huth #define SWCR_STATUS_MASK        ((1U << 23) - (1U << 17))
174fcf5ef2aSThomas Huth 
17521ba8564SRichard Henderson #define SWCR_STATUS_TO_EXCSUM_SHIFT  16
17621ba8564SRichard Henderson 
177fcf5ef2aSThomas Huth #define SWCR_MASK  (SWCR_TRAP_ENABLE_MASK | SWCR_MAP_MASK | SWCR_STATUS_MASK)
178fcf5ef2aSThomas Huth 
179fcf5ef2aSThomas Huth /* MMU modes definitions */
180fcf5ef2aSThomas Huth 
181fcf5ef2aSThomas Huth /* Alpha has 5 MMU modes: PALcode, Kernel, Executive, Supervisor, and User.
182fcf5ef2aSThomas Huth    The Unix PALcode only exposes the kernel and user modes; presumably
183fcf5ef2aSThomas Huth    executive and supervisor are used by VMS.
184fcf5ef2aSThomas Huth 
185fcf5ef2aSThomas Huth    PALcode itself uses physical mode for code and kernel mode for data;
186fcf5ef2aSThomas Huth    there are PALmode instructions that can access data via physical mode
187fcf5ef2aSThomas Huth    or via an os-installed "alternate mode", which is one of the 4 above.
188fcf5ef2aSThomas Huth 
189fcf5ef2aSThomas Huth    That said, we're only emulating Unix PALcode, and not attempting VMS,
190fcf5ef2aSThomas Huth    so we don't need to implement Executive and Supervisor.  QEMU's own
1918b81968cSMichael Tokarev    PALcode cheats and uses the KSEG mapping for its code+data rather than
192fcf5ef2aSThomas Huth    physical addresses.  */
193fcf5ef2aSThomas Huth 
194fcf5ef2aSThomas Huth #define MMU_KERNEL_IDX   0
195fcf5ef2aSThomas Huth #define MMU_USER_IDX     1
196fcf5ef2aSThomas Huth #define MMU_PHYS_IDX     2
197fcf5ef2aSThomas Huth 
1981ea4a06aSPhilippe Mathieu-Daudé typedef struct CPUArchState {
199fcf5ef2aSThomas Huth     uint64_t ir[31];
200fcf5ef2aSThomas Huth     float64 fir[31];
201fcf5ef2aSThomas Huth     uint64_t pc;
202fcf5ef2aSThomas Huth     uint64_t unique;
203fcf5ef2aSThomas Huth     uint64_t lock_addr;
204fcf5ef2aSThomas Huth     uint64_t lock_value;
205fcf5ef2aSThomas Huth 
206fcf5ef2aSThomas Huth     /* The FPCR, and disassembled portions thereof.  */
207fcf5ef2aSThomas Huth     uint32_t fpcr;
20821ba8564SRichard Henderson #ifdef CONFIG_USER_ONLY
20921ba8564SRichard Henderson     uint32_t swcr;
21021ba8564SRichard Henderson #endif
211fcf5ef2aSThomas Huth     uint32_t fpcr_exc_enable;
212fcf5ef2aSThomas Huth     float_status fp_status;
213fcf5ef2aSThomas Huth     uint8_t fpcr_dyn_round;
214fcf5ef2aSThomas Huth     uint8_t fpcr_flush_to_zero;
215fcf5ef2aSThomas Huth 
216bcd2625dSRichard Henderson     /* Mask of PALmode, Processor State et al.  Most of this gets copied
217bcd2625dSRichard Henderson        into the TranslatorBlock flags and controls code generation.  */
218bcd2625dSRichard Henderson     uint32_t flags;
219fcf5ef2aSThomas Huth 
220bcd2625dSRichard Henderson     /* The high 32-bits of the processor cycle counter.  */
221fcf5ef2aSThomas Huth     uint32_t pcc_ofs;
222fcf5ef2aSThomas Huth 
223fcf5ef2aSThomas Huth     /* These pass data from the exception logic in the translator and
224fcf5ef2aSThomas Huth        helpers to the OS entry point.  This is used for both system
225fcf5ef2aSThomas Huth        emulation and user-mode.  */
226fcf5ef2aSThomas Huth     uint64_t trap_arg0;
227fcf5ef2aSThomas Huth     uint64_t trap_arg1;
228fcf5ef2aSThomas Huth     uint64_t trap_arg2;
229fcf5ef2aSThomas Huth 
230fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
231fcf5ef2aSThomas Huth     /* The internal data required by our emulation of the Unix PALcode.  */
232fcf5ef2aSThomas Huth     uint64_t exc_addr;
233fcf5ef2aSThomas Huth     uint64_t palbr;
234fcf5ef2aSThomas Huth     uint64_t ptbr;
235fcf5ef2aSThomas Huth     uint64_t vptptr;
236fcf5ef2aSThomas Huth     uint64_t sysval;
237fcf5ef2aSThomas Huth     uint64_t usp;
238fcf5ef2aSThomas Huth     uint64_t shadow[8];
239fcf5ef2aSThomas Huth     uint64_t scratch[24];
240fcf5ef2aSThomas Huth #endif
241fcf5ef2aSThomas Huth 
242fcf5ef2aSThomas Huth     /* This alarm doesn't exist in real hardware; we wish it did.  */
243fcf5ef2aSThomas Huth     uint64_t alarm_expire;
244fcf5ef2aSThomas Huth 
245fcf5ef2aSThomas Huth     int error_code;
246fcf5ef2aSThomas Huth 
247fcf5ef2aSThomas Huth     uint32_t features;
248fcf5ef2aSThomas Huth     uint32_t amask;
249fcf5ef2aSThomas Huth     int implver;
2501ea4a06aSPhilippe Mathieu-Daudé } CPUAlphaState;
251fcf5ef2aSThomas Huth 
252fcf5ef2aSThomas Huth /**
253fcf5ef2aSThomas Huth  * AlphaCPU:
254fcf5ef2aSThomas Huth  * @env: #CPUAlphaState
255fcf5ef2aSThomas Huth  *
256fcf5ef2aSThomas Huth  * An Alpha CPU.
257fcf5ef2aSThomas Huth  */
258b36e239eSPhilippe Mathieu-Daudé struct ArchCPU {
259fcf5ef2aSThomas Huth     CPUState parent_obj;
260fcf5ef2aSThomas Huth 
261fcf5ef2aSThomas Huth     CPUAlphaState env;
262fcf5ef2aSThomas Huth 
263fcf5ef2aSThomas Huth     /* This alarm doesn't exist in real hardware; we wish it did.  */
264fcf5ef2aSThomas Huth     QEMUTimer *alarm_timer;
265fcf5ef2aSThomas Huth };
266fcf5ef2aSThomas Huth 
2679348028eSPhilippe Mathieu-Daudé /**
2689348028eSPhilippe Mathieu-Daudé  * AlphaCPUClass:
2699348028eSPhilippe Mathieu-Daudé  * @parent_realize: The parent class' realize handler.
2709348028eSPhilippe Mathieu-Daudé  *
2719348028eSPhilippe Mathieu-Daudé  * An Alpha CPU model.
2729348028eSPhilippe Mathieu-Daudé  */
2739348028eSPhilippe Mathieu-Daudé struct AlphaCPUClass {
2749348028eSPhilippe Mathieu-Daudé     CPUClass parent_class;
2759348028eSPhilippe Mathieu-Daudé 
2769348028eSPhilippe Mathieu-Daudé     DeviceRealize parent_realize;
2779348028eSPhilippe Mathieu-Daudé };
278fcf5ef2aSThomas Huth 
279fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
2808a9358ccSMarkus Armbruster extern const VMStateDescription vmstate_alpha_cpu;
281fcf5ef2aSThomas Huth 
282fcf5ef2aSThomas Huth void alpha_cpu_do_interrupt(CPUState *cpu);
283fcf5ef2aSThomas Huth bool alpha_cpu_exec_interrupt(CPUState *cpu, int int_req);
2846d2d454aSPhilippe Mathieu-Daudé hwaddr alpha_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
2859354e694SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
28690c84c56SMarkus Armbruster void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags);
287a010bdbeSAlex Bennée int alpha_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
288fcf5ef2aSThomas Huth int alpha_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
289fcf5ef2aSThomas Huth 
290fcf5ef2aSThomas Huth #include "exec/cpu-all.h"
291fcf5ef2aSThomas Huth 
292fcf5ef2aSThomas Huth enum {
293fcf5ef2aSThomas Huth     FEATURE_ASN    = 0x00000001,
294fcf5ef2aSThomas Huth     FEATURE_SPS    = 0x00000002,
295fcf5ef2aSThomas Huth     FEATURE_VIRBND = 0x00000004,
296fcf5ef2aSThomas Huth     FEATURE_TBCHK  = 0x00000008,
297fcf5ef2aSThomas Huth };
298fcf5ef2aSThomas Huth 
299fcf5ef2aSThomas Huth enum {
300fcf5ef2aSThomas Huth     EXCP_RESET,
301fcf5ef2aSThomas Huth     EXCP_MCHK,
302fcf5ef2aSThomas Huth     EXCP_SMP_INTERRUPT,
303fcf5ef2aSThomas Huth     EXCP_CLK_INTERRUPT,
304fcf5ef2aSThomas Huth     EXCP_DEV_INTERRUPT,
305fcf5ef2aSThomas Huth     EXCP_MMFAULT,
306fcf5ef2aSThomas Huth     EXCP_UNALIGN,
307fcf5ef2aSThomas Huth     EXCP_OPCDEC,
308fcf5ef2aSThomas Huth     EXCP_ARITH,
309fcf5ef2aSThomas Huth     EXCP_FEN,
310fcf5ef2aSThomas Huth     EXCP_CALL_PAL,
311fcf5ef2aSThomas Huth };
312fcf5ef2aSThomas Huth 
313fcf5ef2aSThomas Huth /* Alpha-specific interrupt pending bits.  */
314fcf5ef2aSThomas Huth #define CPU_INTERRUPT_TIMER	CPU_INTERRUPT_TGT_EXT_0
315fcf5ef2aSThomas Huth #define CPU_INTERRUPT_SMP	CPU_INTERRUPT_TGT_EXT_1
316fcf5ef2aSThomas Huth #define CPU_INTERRUPT_MCHK	CPU_INTERRUPT_TGT_EXT_2
317fcf5ef2aSThomas Huth 
318fcf5ef2aSThomas Huth /* OSF/1 Page table bits.  */
319fcf5ef2aSThomas Huth enum {
320fcf5ef2aSThomas Huth     PTE_VALID = 0x0001,
321fcf5ef2aSThomas Huth     PTE_FOR   = 0x0002,  /* used for page protection (fault on read) */
322fcf5ef2aSThomas Huth     PTE_FOW   = 0x0004,  /* used for page protection (fault on write) */
323fcf5ef2aSThomas Huth     PTE_FOE   = 0x0008,  /* used for page protection (fault on exec) */
324fcf5ef2aSThomas Huth     PTE_ASM   = 0x0010,
325fcf5ef2aSThomas Huth     PTE_KRE   = 0x0100,
326fcf5ef2aSThomas Huth     PTE_URE   = 0x0200,
327fcf5ef2aSThomas Huth     PTE_KWE   = 0x1000,
328fcf5ef2aSThomas Huth     PTE_UWE   = 0x2000
329fcf5ef2aSThomas Huth };
330fcf5ef2aSThomas Huth 
331fcf5ef2aSThomas Huth /* Hardware interrupt (entInt) constants.  */
332fcf5ef2aSThomas Huth enum {
333fcf5ef2aSThomas Huth     INT_K_IP,
334fcf5ef2aSThomas Huth     INT_K_CLK,
335fcf5ef2aSThomas Huth     INT_K_MCHK,
336fcf5ef2aSThomas Huth     INT_K_DEV,
337fcf5ef2aSThomas Huth     INT_K_PERF,
338fcf5ef2aSThomas Huth };
339fcf5ef2aSThomas Huth 
340fcf5ef2aSThomas Huth /* Memory management (entMM) constants.  */
341fcf5ef2aSThomas Huth enum {
342fcf5ef2aSThomas Huth     MM_K_TNV,
343fcf5ef2aSThomas Huth     MM_K_ACV,
344fcf5ef2aSThomas Huth     MM_K_FOR,
345fcf5ef2aSThomas Huth     MM_K_FOE,
346fcf5ef2aSThomas Huth     MM_K_FOW
347fcf5ef2aSThomas Huth };
348fcf5ef2aSThomas Huth 
349fcf5ef2aSThomas Huth /* Arithmetic exception (entArith) constants.  */
350fcf5ef2aSThomas Huth enum {
351fcf5ef2aSThomas Huth     EXC_M_SWC = 1,      /* Software completion */
352fcf5ef2aSThomas Huth     EXC_M_INV = 2,      /* Invalid operation */
353fcf5ef2aSThomas Huth     EXC_M_DZE = 4,      /* Division by zero */
354fcf5ef2aSThomas Huth     EXC_M_FOV = 8,      /* Overflow */
355fcf5ef2aSThomas Huth     EXC_M_UNF = 16,     /* Underflow */
356fcf5ef2aSThomas Huth     EXC_M_INE = 32,     /* Inexact result */
357fcf5ef2aSThomas Huth     EXC_M_IOV = 64      /* Integer Overflow */
358fcf5ef2aSThomas Huth };
359fcf5ef2aSThomas Huth 
360fcf5ef2aSThomas Huth /* Processor status constants.  */
361fcf5ef2aSThomas Huth /* Low 3 bits are interrupt mask level.  */
362bcd2625dSRichard Henderson #define PS_INT_MASK   7u
363fcf5ef2aSThomas Huth 
364fcf5ef2aSThomas Huth /* Bits 4 and 5 are the mmu mode.  The VMS PALcode uses all 4 modes;
365fcf5ef2aSThomas Huth    The Unix PALcode only uses bit 4.  */
366bcd2625dSRichard Henderson #define PS_USER_MODE  8u
367bcd2625dSRichard Henderson 
3688b81968cSMichael Tokarev /* CPUAlphaState->flags constants.  These are laid out so that we
369bcd2625dSRichard Henderson    can set or reset the pieces individually by assigning to the byte,
370bcd2625dSRichard Henderson    or manipulated as a whole.  */
371bcd2625dSRichard Henderson 
372bcd2625dSRichard Henderson #define ENV_FLAG_PAL_SHIFT    0
373bcd2625dSRichard Henderson #define ENV_FLAG_PS_SHIFT     8
374bcd2625dSRichard Henderson #define ENV_FLAG_RX_SHIFT     16
375bcd2625dSRichard Henderson #define ENV_FLAG_FEN_SHIFT    24
376bcd2625dSRichard Henderson 
377bcd2625dSRichard Henderson #define ENV_FLAG_PAL_MODE     (1u << ENV_FLAG_PAL_SHIFT)
378bcd2625dSRichard Henderson #define ENV_FLAG_PS_USER      (PS_USER_MODE << ENV_FLAG_PS_SHIFT)
379bcd2625dSRichard Henderson #define ENV_FLAG_RX_FLAG      (1u << ENV_FLAG_RX_SHIFT)
380bcd2625dSRichard Henderson #define ENV_FLAG_FEN          (1u << ENV_FLAG_FEN_SHIFT)
381bcd2625dSRichard Henderson 
382bcd2625dSRichard Henderson #define ENV_FLAG_TB_MASK \
383bcd2625dSRichard Henderson     (ENV_FLAG_PAL_MODE | ENV_FLAG_PS_USER | ENV_FLAG_FEN)
384fcf5ef2aSThomas Huth 
385fed14246SRichard Henderson #define TB_FLAG_UNALIGN       (1u << 1)
386fed14246SRichard Henderson 
alpha_env_mmu_index(CPUAlphaState * env)387*32a8ea12SRichard Henderson static inline int alpha_env_mmu_index(CPUAlphaState *env)
388fcf5ef2aSThomas Huth {
389bcd2625dSRichard Henderson     int ret = env->flags & ENV_FLAG_PS_USER ? MMU_USER_IDX : MMU_KERNEL_IDX;
390bcd2625dSRichard Henderson     if (env->flags & ENV_FLAG_PAL_MODE) {
391bcd2625dSRichard Henderson         ret = MMU_KERNEL_IDX;
392fcf5ef2aSThomas Huth     }
393bcd2625dSRichard Henderson     return ret;
394fcf5ef2aSThomas Huth }
395fcf5ef2aSThomas Huth 
396fcf5ef2aSThomas Huth enum {
397fcf5ef2aSThomas Huth     IR_V0   = 0,
398fcf5ef2aSThomas Huth     IR_T0   = 1,
399fcf5ef2aSThomas Huth     IR_T1   = 2,
400fcf5ef2aSThomas Huth     IR_T2   = 3,
401fcf5ef2aSThomas Huth     IR_T3   = 4,
402fcf5ef2aSThomas Huth     IR_T4   = 5,
403fcf5ef2aSThomas Huth     IR_T5   = 6,
404fcf5ef2aSThomas Huth     IR_T6   = 7,
405fcf5ef2aSThomas Huth     IR_T7   = 8,
406fcf5ef2aSThomas Huth     IR_S0   = 9,
407fcf5ef2aSThomas Huth     IR_S1   = 10,
408fcf5ef2aSThomas Huth     IR_S2   = 11,
409fcf5ef2aSThomas Huth     IR_S3   = 12,
410fcf5ef2aSThomas Huth     IR_S4   = 13,
411fcf5ef2aSThomas Huth     IR_S5   = 14,
412fcf5ef2aSThomas Huth     IR_S6   = 15,
413fcf5ef2aSThomas Huth     IR_FP   = IR_S6,
414fcf5ef2aSThomas Huth     IR_A0   = 16,
415fcf5ef2aSThomas Huth     IR_A1   = 17,
416fcf5ef2aSThomas Huth     IR_A2   = 18,
417fcf5ef2aSThomas Huth     IR_A3   = 19,
418fcf5ef2aSThomas Huth     IR_A4   = 20,
419fcf5ef2aSThomas Huth     IR_A5   = 21,
420fcf5ef2aSThomas Huth     IR_T8   = 22,
421fcf5ef2aSThomas Huth     IR_T9   = 23,
422fcf5ef2aSThomas Huth     IR_T10  = 24,
423fcf5ef2aSThomas Huth     IR_T11  = 25,
424fcf5ef2aSThomas Huth     IR_RA   = 26,
425fcf5ef2aSThomas Huth     IR_T12  = 27,
426fcf5ef2aSThomas Huth     IR_PV   = IR_T12,
427fcf5ef2aSThomas Huth     IR_AT   = 28,
428fcf5ef2aSThomas Huth     IR_GP   = 29,
429fcf5ef2aSThomas Huth     IR_SP   = 30,
430fcf5ef2aSThomas Huth     IR_ZERO = 31,
431fcf5ef2aSThomas Huth };
432fcf5ef2aSThomas Huth 
433fcf5ef2aSThomas Huth void alpha_translate_init(void);
434fcf5ef2aSThomas Huth 
4350dacec87SIgor Mammedov #define CPU_RESOLVING_TYPE TYPE_ALPHA_CPU
43673a25e83SIgor Mammedov 
4378905770bSMarc-André Lureau G_NORETURN void dynamic_excp(CPUAlphaState *, uintptr_t, int, int);
4388905770bSMarc-André Lureau G_NORETURN void arith_excp(CPUAlphaState *, uintptr_t, int, uint64_t);
439fcf5ef2aSThomas Huth 
440fcf5ef2aSThomas Huth uint64_t cpu_alpha_load_fpcr (CPUAlphaState *env);
441fcf5ef2aSThomas Huth void cpu_alpha_store_fpcr (CPUAlphaState *env, uint64_t val);
442fcf5ef2aSThomas Huth uint64_t cpu_alpha_load_gr(CPUAlphaState *env, unsigned reg);
443fcf5ef2aSThomas Huth void cpu_alpha_store_gr(CPUAlphaState *env, unsigned reg, uint64_t val);
44490113883SRichard Henderson 
44590113883SRichard Henderson #ifdef CONFIG_USER_ONLY
44690113883SRichard Henderson void alpha_cpu_record_sigsegv(CPUState *cs, vaddr address,
44790113883SRichard Henderson                               MMUAccessType access_type,
44890113883SRichard Henderson                               bool maperr, uintptr_t retaddr);
449e7424abcSRichard Henderson void alpha_cpu_record_sigbus(CPUState *cs, vaddr address,
450e7424abcSRichard Henderson                              MMUAccessType access_type, uintptr_t retaddr);
45190113883SRichard Henderson #else
45290113883SRichard Henderson bool alpha_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
45390113883SRichard Henderson                         MMUAccessType access_type, int mmu_idx,
45490113883SRichard Henderson                         bool probe, uintptr_t retaddr);
4558905770bSMarc-André Lureau G_NORETURN void alpha_cpu_do_unaligned_access(CPUState *cpu, vaddr addr,
456e7424abcSRichard Henderson                                               MMUAccessType access_type, int mmu_idx,
4578905770bSMarc-André Lureau                                               uintptr_t retaddr);
4586ad4d7eeSPeter Maydell void alpha_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
4596ad4d7eeSPeter Maydell                                      vaddr addr, unsigned size,
4606ad4d7eeSPeter Maydell                                      MMUAccessType access_type,
4616ad4d7eeSPeter Maydell                                      int mmu_idx, MemTxAttrs attrs,
4626ad4d7eeSPeter Maydell                                      MemTxResult response, uintptr_t retaddr);
463fcf5ef2aSThomas Huth #endif
464fcf5ef2aSThomas Huth 
cpu_get_tb_cpu_state(CPUAlphaState * env,vaddr * pc,uint64_t * cs_base,uint32_t * pflags)465bb5de525SAnton Johansson static inline void cpu_get_tb_cpu_state(CPUAlphaState *env, vaddr *pc,
466bb5de525SAnton Johansson                                         uint64_t *cs_base, uint32_t *pflags)
467fcf5ef2aSThomas Huth {
468fcf5ef2aSThomas Huth     *pc = env->pc;
469fcf5ef2aSThomas Huth     *cs_base = 0;
470bcd2625dSRichard Henderson     *pflags = env->flags & ENV_FLAG_TB_MASK;
471fed14246SRichard Henderson #ifdef CONFIG_USER_ONLY
472fed14246SRichard Henderson     *pflags |= TB_FLAG_UNALIGN * !env_cpu(env)->prctl_unalign_sigbus;
473fed14246SRichard Henderson #endif
474fcf5ef2aSThomas Huth }
475fcf5ef2aSThomas Huth 
47621ba8564SRichard Henderson #ifdef CONFIG_USER_ONLY
47721ba8564SRichard Henderson /* Copied from linux ieee_swcr_to_fpcr.  */
alpha_ieee_swcr_to_fpcr(uint64_t swcr)47821ba8564SRichard Henderson static inline uint64_t alpha_ieee_swcr_to_fpcr(uint64_t swcr)
47921ba8564SRichard Henderson {
48021ba8564SRichard Henderson     uint64_t fpcr = 0;
48121ba8564SRichard Henderson 
48221ba8564SRichard Henderson     fpcr |= (swcr & SWCR_STATUS_MASK) << 35;
48321ba8564SRichard Henderson     fpcr |= (swcr & SWCR_MAP_DMZ) << 36;
48421ba8564SRichard Henderson     fpcr |= (~swcr & (SWCR_TRAP_ENABLE_INV
48521ba8564SRichard Henderson                       | SWCR_TRAP_ENABLE_DZE
48621ba8564SRichard Henderson                       | SWCR_TRAP_ENABLE_OVF)) << 48;
48721ba8564SRichard Henderson     fpcr |= (~swcr & (SWCR_TRAP_ENABLE_UNF
48821ba8564SRichard Henderson                       | SWCR_TRAP_ENABLE_INE)) << 57;
48921ba8564SRichard Henderson     fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
49021ba8564SRichard Henderson     fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;
49121ba8564SRichard Henderson 
49221ba8564SRichard Henderson     return fpcr;
49321ba8564SRichard Henderson }
49421ba8564SRichard Henderson 
49521ba8564SRichard Henderson /* Copied from linux ieee_fpcr_to_swcr.  */
alpha_ieee_fpcr_to_swcr(uint64_t fpcr)49621ba8564SRichard Henderson static inline uint64_t alpha_ieee_fpcr_to_swcr(uint64_t fpcr)
49721ba8564SRichard Henderson {
49821ba8564SRichard Henderson     uint64_t swcr = 0;
49921ba8564SRichard Henderson 
50021ba8564SRichard Henderson     swcr |= (fpcr >> 35) & SWCR_STATUS_MASK;
50121ba8564SRichard Henderson     swcr |= (fpcr >> 36) & SWCR_MAP_DMZ;
50221ba8564SRichard Henderson     swcr |= (~fpcr >> 48) & (SWCR_TRAP_ENABLE_INV
50321ba8564SRichard Henderson                              | SWCR_TRAP_ENABLE_DZE
50421ba8564SRichard Henderson                              | SWCR_TRAP_ENABLE_OVF);
50521ba8564SRichard Henderson     swcr |= (~fpcr >> 57) & (SWCR_TRAP_ENABLE_UNF | SWCR_TRAP_ENABLE_INE);
50621ba8564SRichard Henderson     swcr |= (fpcr >> 47) & SWCR_MAP_UMZ;
50721ba8564SRichard Henderson     swcr |= (~fpcr >> 41) & SWCR_TRAP_ENABLE_DNO;
50821ba8564SRichard Henderson 
50921ba8564SRichard Henderson     return swcr;
51021ba8564SRichard Henderson }
51121ba8564SRichard Henderson #endif /* CONFIG_USER_ONLY */
51221ba8564SRichard Henderson 
513fcf5ef2aSThomas Huth #endif /* ALPHA_CPU_H */
514