xref: /openbmc/qemu/target/hexagon/cpu.h (revision 3cb1a410)
1 /*
2  *  Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef HEXAGON_CPU_H
19 #define HEXAGON_CPU_H
20 
21 /* Forward declaration needed by some of the header files */
22 typedef struct CPUHexagonState CPUHexagonState;
23 
24 #include "fpu/softfloat-types.h"
25 
26 #include "exec/cpu-defs.h"
27 #include "hex_regs.h"
28 #include "mmvec/mmvec.h"
29 #include "qom/object.h"
30 
31 #define NUM_PREGS 4
32 #define TOTAL_PER_THREAD_REGS 64
33 
34 #define SLOTS_MAX 4
35 #define STORES_MAX 2
36 #define REG_WRITES_MAX 32
37 #define PRED_WRITES_MAX 5                   /* 4 insns + endloop */
38 #define VSTORES_MAX 2
39 
40 #define TYPE_HEXAGON_CPU "hexagon-cpu"
41 
42 #define HEXAGON_CPU_TYPE_SUFFIX "-" TYPE_HEXAGON_CPU
43 #define HEXAGON_CPU_TYPE_NAME(name) (name HEXAGON_CPU_TYPE_SUFFIX)
44 #define CPU_RESOLVING_TYPE TYPE_HEXAGON_CPU
45 
46 #define TYPE_HEXAGON_CPU_V67 HEXAGON_CPU_TYPE_NAME("v67")
47 
48 #define MMU_USER_IDX 0
49 
50 typedef struct {
51     target_ulong va;
52     uint8_t width;
53     uint32_t data32;
54     uint64_t data64;
55 } MemLog;
56 
57 typedef struct {
58     target_ulong va;
59     int size;
60     DECLARE_BITMAP(mask, MAX_VEC_SIZE_BYTES) QEMU_ALIGNED(16);
61     MMVector data QEMU_ALIGNED(16);
62 } VStoreLog;
63 
64 #define EXEC_STATUS_OK          0x0000
65 #define EXEC_STATUS_STOP        0x0002
66 #define EXEC_STATUS_REPLAY      0x0010
67 #define EXEC_STATUS_LOCKED      0x0020
68 #define EXEC_STATUS_EXCEPTION   0x0100
69 
70 
71 #define EXCEPTION_DETECTED      (env->status & EXEC_STATUS_EXCEPTION)
72 #define REPLAY_DETECTED         (env->status & EXEC_STATUS_REPLAY)
73 #define CLEAR_EXCEPTION         (env->status &= (~EXEC_STATUS_EXCEPTION))
74 #define SET_EXCEPTION           (env->status |= EXEC_STATUS_EXCEPTION)
75 
76 /* Maximum number of vector temps in a packet */
77 #define VECTOR_TEMPS_MAX            4
78 
79 struct CPUHexagonState {
80     target_ulong gpr[TOTAL_PER_THREAD_REGS];
81     target_ulong pred[NUM_PREGS];
82     target_ulong branch_taken;
83     target_ulong next_PC;
84 
85     /* For comparing with LLDB on target - see adjust_stack_ptrs function */
86     target_ulong last_pc_dumped;
87     target_ulong stack_start;
88 
89     uint8_t slot_cancelled;
90     target_ulong new_value[TOTAL_PER_THREAD_REGS];
91 
92     /*
93      * Only used when HEX_DEBUG is on, but unconditionally included
94      * to reduce recompile time when turning HEX_DEBUG on/off.
95      */
96     target_ulong this_PC;
97     target_ulong reg_written[TOTAL_PER_THREAD_REGS];
98 
99     target_ulong new_pred_value[NUM_PREGS];
100     target_ulong pred_written;
101 
102     MemLog mem_log_stores[STORES_MAX];
103     target_ulong pkt_has_store_s1;
104     target_ulong dczero_addr;
105 
106     float_status fp_status;
107 
108     target_ulong llsc_addr;
109     target_ulong llsc_val;
110     uint64_t     llsc_val_i64;
111 
112     MMVector VRegs[NUM_VREGS] QEMU_ALIGNED(16);
113     MMVector future_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
114     MMVector tmp_VRegs[VECTOR_TEMPS_MAX] QEMU_ALIGNED(16);
115 
116     VRegMask VRegs_updated;
117 
118     MMQReg QRegs[NUM_QREGS] QEMU_ALIGNED(16);
119     MMQReg future_QRegs[NUM_QREGS] QEMU_ALIGNED(16);
120     QRegMask QRegs_updated;
121 
122     /* Temporaries used within instructions */
123     MMVectorPair VuuV QEMU_ALIGNED(16);
124     MMVectorPair VvvV QEMU_ALIGNED(16);
125     MMVectorPair VxxV QEMU_ALIGNED(16);
126     MMVector     vtmp QEMU_ALIGNED(16);
127     MMQReg       qtmp QEMU_ALIGNED(16);
128 
129     VStoreLog vstore[VSTORES_MAX];
130     target_ulong vstore_pending[VSTORES_MAX];
131     bool vtcm_pending;
132     VTCMStoreLog vtcm_log;
133 };
134 
135 OBJECT_DECLARE_TYPE(HexagonCPU, HexagonCPUClass, HEXAGON_CPU)
136 
137 typedef struct HexagonCPUClass {
138     /*< private >*/
139     CPUClass parent_class;
140     /*< public >*/
141     DeviceRealize parent_realize;
142     DeviceReset parent_reset;
143 } HexagonCPUClass;
144 
145 typedef struct HexagonCPU {
146     /*< private >*/
147     CPUState parent_obj;
148     /*< public >*/
149     CPUNegativeOffsetState neg;
150     CPUHexagonState env;
151 
152     bool lldb_compat;
153     target_ulong lldb_stack_adjust;
154 } HexagonCPU;
155 
156 #include "cpu_bits.h"
157 
158 static inline void cpu_get_tb_cpu_state(CPUHexagonState *env, target_ulong *pc,
159                                         target_ulong *cs_base, uint32_t *flags)
160 {
161     *pc = env->gpr[HEX_REG_PC];
162     *cs_base = 0;
163 #ifdef CONFIG_USER_ONLY
164     *flags = 0;
165 #else
166 #error System mode not supported on Hexagon yet
167 #endif
168 }
169 
170 static inline int cpu_mmu_index(CPUHexagonState *env, bool ifetch)
171 {
172 #ifdef CONFIG_USER_ONLY
173     return MMU_USER_IDX;
174 #else
175 #error System mode not supported on Hexagon yet
176 #endif
177 }
178 
179 typedef struct CPUHexagonState CPUArchState;
180 typedef HexagonCPU ArchCPU;
181 
182 void hexagon_translate_init(void);
183 
184 #include "exec/cpu-all.h"
185 
186 #endif /* HEXAGON_CPU_H */
187