1 |
28 |
ultra_embe |
//-----------------------------------------------------------------
|
2 |
|
|
// AltOR32
|
3 |
|
|
// Alternative Lightweight OpenRisc
|
4 |
|
|
// V2.0
|
5 |
|
|
// Ultra-Embedded.com
|
6 |
|
|
// Copyright 2011 - 2013
|
7 |
|
|
//
|
8 |
|
|
// Email: admin@ultra-embedded.com
|
9 |
|
|
//
|
10 |
|
|
// License: LGPL
|
11 |
|
|
//-----------------------------------------------------------------
|
12 |
|
|
//
|
13 |
|
|
// Copyright (C) 2011 - 2013 Ultra-Embedded.com
|
14 |
|
|
//
|
15 |
|
|
// This source file may be used and distributed without
|
16 |
|
|
// restriction provided that this copyright statement is not
|
17 |
|
|
// removed from the file and that any derivative work contains
|
18 |
|
|
// the original copyright notice and the associated disclaimer.
|
19 |
|
|
//
|
20 |
|
|
// This source file is free software; you can redistribute it
|
21 |
|
|
// and/or modify it under the terms of the GNU Lesser General
|
22 |
|
|
// Public License as published by the Free Software Foundation;
|
23 |
|
|
// either version 2.1 of the License, or (at your option) any
|
24 |
|
|
// later version.
|
25 |
|
|
//
|
26 |
|
|
// This source is distributed in the hope that it will be
|
27 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied
|
28 |
|
|
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
29 |
|
|
// PURPOSE. See the GNU Lesser General Public License for more
|
30 |
|
|
// details.
|
31 |
|
|
//
|
32 |
|
|
// You should have received a copy of the GNU Lesser General
|
33 |
|
|
// Public License along with this source; if not, write to the
|
34 |
|
|
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
35 |
|
|
// Boston, MA 02111-1307 USA
|
36 |
|
|
//-----------------------------------------------------------------
|
37 |
|
|
#ifndef __OR32_ISA_H__
|
38 |
|
|
#define __OR32_ISA_H__
|
39 |
|
|
|
40 |
|
|
//-----------------------------------------------------------------
|
41 |
|
|
// General:
|
42 |
|
|
//-----------------------------------------------------------------
|
43 |
|
|
typedef unsigned int TInstruction;
|
44 |
|
|
typedef unsigned int TRegister;
|
45 |
|
|
typedef unsigned int TAddress;
|
46 |
|
|
typedef unsigned int TMemory;
|
47 |
|
|
|
48 |
|
|
enum ERegisters
|
49 |
|
|
{
|
50 |
|
|
REG_0_ZERO,
|
51 |
|
|
REG_1_SP,
|
52 |
|
|
REG_2_FP,
|
53 |
|
|
REG_3,
|
54 |
|
|
REG_4,
|
55 |
|
|
REG_5,
|
56 |
|
|
REG_6,
|
57 |
|
|
REG_7,
|
58 |
|
|
REG_8,
|
59 |
|
|
REG_9_LR,
|
60 |
|
|
REG_10,
|
61 |
|
|
REG_11,
|
62 |
|
|
REG_12,
|
63 |
|
|
REG_13,
|
64 |
|
|
REG_14,
|
65 |
|
|
REG_15,
|
66 |
|
|
REG_16,
|
67 |
|
|
REG_17,
|
68 |
|
|
REG_18,
|
69 |
|
|
REG_19,
|
70 |
|
|
REG_20,
|
71 |
|
|
REG_21,
|
72 |
|
|
REG_22,
|
73 |
|
|
REG_23,
|
74 |
|
|
REG_24,
|
75 |
|
|
REG_25,
|
76 |
|
|
REG_26,
|
77 |
|
|
REG_27,
|
78 |
|
|
REG_28,
|
79 |
|
|
REG_29,
|
80 |
|
|
REG_30,
|
81 |
|
|
REG_31,
|
82 |
|
|
REGISTERS
|
83 |
|
|
};
|
84 |
|
|
|
85 |
|
|
//--------------------------------------------------------------------
|
86 |
|
|
// Instruction Encoding
|
87 |
|
|
//--------------------------------------------------------------------
|
88 |
|
|
#define OR32_OPCODE_SHIFT 26
|
89 |
|
|
#define OR32_OPCODE_MASK 0x3F
|
90 |
|
|
#define OR32_REG_D_SHIFT 21
|
91 |
|
|
#define OR32_REG_D_MASK 0x1F
|
92 |
|
|
#define OR32_REG_A_SHIFT 16
|
93 |
|
|
#define OR32_REG_A_MASK 0x1F
|
94 |
|
|
#define OR32_REG_B_SHIFT 11
|
95 |
|
|
#define OR32_REG_B_MASK 0x1F
|
96 |
|
|
#define OR32_IMM16_SHIFT 0
|
97 |
|
|
#define OR32_IMM16_MASK 0xFFFF
|
98 |
|
|
#define OR32_ADDR_SHIFT 0
|
99 |
|
|
#define OR32_ADDR_MASK 0x3FFFFFF
|
100 |
|
|
#define OR32_ADDR_SIGN_SHIFT 25
|
101 |
|
|
#define OR32_SHIFT_OP_SHIFT 6
|
102 |
|
|
#define OR32_SHIFT_OP_MASK 0x3
|
103 |
|
|
#define OR32_SFXXX_OP_SHIFT 21
|
104 |
|
|
#define OR32_SFXXX_OP_MASK 0x7FF
|
105 |
|
|
#define OR32_ALU_OP_L_SHIFT 0
|
106 |
|
|
#define OR32_ALU_OP_L_MASK 0xF
|
107 |
|
|
#define OR32_ALU_OP_H_SHIFT 2
|
108 |
|
|
#define OR32_ALU_OP_H_MASK 0xF0
|
109 |
|
|
#define OR32_STORE_IMM_L_SHIFT 0
|
110 |
|
|
#define OR32_STORE_IMM_L_MASK 0x7FF
|
111 |
|
|
#define OR32_STORE_IMM_H_SHIFT 10
|
112 |
|
|
#define OR32_STORE_IMM_H_MASK 0xF800
|
113 |
|
|
#define OR32_MFSPR_IMM_MASK 0xFFFF
|
114 |
|
|
#define OR32_MTSPR_IMM_MASK 0x7FF
|
115 |
|
|
|
116 |
|
|
//--------------------------------------------------------------------
|
117 |
|
|
// Instructions
|
118 |
|
|
//--------------------------------------------------------------------
|
119 |
|
|
|
120 |
|
|
// ALU Instructions
|
121 |
|
|
#define INST_OR32_ALU 0x38
|
122 |
|
|
#define INST_OR32_ADD 0x0000
|
123 |
|
|
#define INST_OR32_ADDC 0x0001
|
124 |
|
|
#define INST_OR32_AND 0x0003
|
125 |
|
|
#define INST_OR32_OR 0x0004
|
126 |
|
|
#define INST_OR32_SLL 0x0008
|
127 |
|
|
#define INST_OR32_SRA 0x0028
|
128 |
|
|
#define INST_OR32_SRL 0x0018
|
129 |
|
|
#define INST_OR32_SUB 0x0002
|
130 |
|
|
#define INST_OR32_XOR 0x0005
|
131 |
|
|
#define INST_OR32_MUL 0x00c6
|
132 |
|
|
#define INST_OR32_MULU 0x00cb
|
133 |
|
|
|
134 |
|
|
// INST_OR32_SHIFTI Instructions
|
135 |
|
|
#define INST_OR32_SHIFTI 0x2e
|
136 |
|
|
#define INST_OR32_SLLI 0x0000
|
137 |
|
|
#define INST_OR32_SRAI 0x0002
|
138 |
|
|
#define INST_OR32_SRLI 0x0001
|
139 |
|
|
|
140 |
|
|
// General Instructions
|
141 |
|
|
#define INST_OR32_ADDI 0x0027
|
142 |
|
|
#define INST_OR32_ANDI 0x0029
|
143 |
|
|
#define INST_OR32_BF 0x0004
|
144 |
|
|
#define INST_OR32_BNF 0x0003
|
145 |
|
|
#define INST_OR32_J 0x0000
|
146 |
|
|
#define INST_OR32_JAL 0x0001
|
147 |
|
|
#define INST_OR32_JALR 0x0012
|
148 |
|
|
#define INST_OR32_JR 0x0011
|
149 |
|
|
#define INST_OR32_LBS 0x0024
|
150 |
|
|
#define INST_OR32_LHS 0x0026
|
151 |
|
|
#define INST_OR32_LWS 0x0022
|
152 |
|
|
#define INST_OR32_LBZ 0x0023
|
153 |
|
|
#define INST_OR32_LHZ 0x0025
|
154 |
|
|
#define INST_OR32_LWZ 0x0021
|
155 |
|
|
#define INST_OR32_MFSPR 0x002d
|
156 |
|
|
#define INST_OR32_MOVHI 0x0006
|
157 |
|
|
#define INST_OR32_MTSPR 0x0030
|
158 |
|
|
#define INST_OR32_NOP 0x0005
|
159 |
|
|
#define INST_OR32_ORI 0x002a
|
160 |
|
|
#define INST_OR32_RFE 0x0009
|
161 |
|
|
#define INST_OR32_SB 0x0036
|
162 |
|
|
#define INST_OR32_SH 0x0037
|
163 |
|
|
#define INST_OR32_SW 0x0035
|
164 |
|
|
#define INST_OR32_XORI 0x002b
|
165 |
|
|
#define INST_OR32_LBS 0x0024
|
166 |
|
|
#define INST_OR32_LBZ 0x0023
|
167 |
|
|
#define INST_OR32_LHS 0x0026
|
168 |
|
|
#define INST_OR32_LHZ 0x0025
|
169 |
|
|
#define INST_OR32_LWZ 0x0021
|
170 |
|
|
#define INST_OR32_LWS 0x0022
|
171 |
|
|
|
172 |
|
|
// Set Flag Instructions
|
173 |
|
|
#define INST_OR32_SFXX 0x2f
|
174 |
|
|
#define INST_OR32_SFXXI 0x39
|
175 |
|
|
#define INST_OR32_SFEQ 0x0720
|
176 |
|
|
#define INST_OR32_SFEQI 0x05e0
|
177 |
|
|
#define INST_OR32_SFGES 0x072b
|
178 |
|
|
#define INST_OR32_SFGESI 0x05eb
|
179 |
|
|
#define INST_OR32_SFGEU 0x0723
|
180 |
|
|
#define INST_OR32_SFGEUI 0x05e3
|
181 |
|
|
#define INST_OR32_SFGTS 0x072a
|
182 |
|
|
#define INST_OR32_SFGTSI 0x05ea
|
183 |
|
|
#define INST_OR32_SFGTU 0x0722
|
184 |
|
|
#define INST_OR32_SFGTUI 0x05e2
|
185 |
|
|
#define INST_OR32_SFLES 0x072d
|
186 |
|
|
#define INST_OR32_SFLESI 0x05ed
|
187 |
|
|
#define INST_OR32_SFLEU 0x0725
|
188 |
|
|
#define INST_OR32_SFLEUI 0x05e5
|
189 |
|
|
#define INST_OR32_SFLTS 0x072c
|
190 |
|
|
#define INST_OR32_SFLTSI 0x05ec
|
191 |
|
|
#define INST_OR32_SFLTU 0x0724
|
192 |
|
|
#define INST_OR32_SFLTUI 0x05e4
|
193 |
|
|
#define INST_OR32_SFNE 0x0721
|
194 |
|
|
#define INST_OR32_SFNEI 0x05e1
|
195 |
|
|
|
196 |
|
|
// Misc Instructions
|
197 |
|
|
#define INST_OR32_MISC 0x08
|
198 |
|
|
#define INST_OR32_SYS 0x0020
|
199 |
|
|
#define INST_OR32_TRAP 0x0021
|
200 |
|
|
|
201 |
|
|
//--------------------------------------------------------------------
|
202 |
|
|
// SPR Register Map
|
203 |
|
|
//--------------------------------------------------------------------
|
204 |
|
|
#define SPR_REG_VR 0
|
205 |
|
|
#define SPR_VERSION_CURRENT 0x00000000
|
206 |
|
|
#define SPR_REG_SR 17
|
207 |
|
|
#define SPR_REG_EPCR 32
|
208 |
|
|
#define SPR_REG_ESR 64
|
209 |
|
|
|
210 |
|
|
//--------------------------------------------------------------------
|
211 |
|
|
// SR Register bits
|
212 |
|
|
//--------------------------------------------------------------------
|
213 |
|
|
#define OR32_SR_SM 0
|
214 |
|
|
#define OR32_SR_TEE 1
|
215 |
|
|
#define OR32_SR_IEE 2
|
216 |
|
|
#define OR32_SR_DCE 3
|
217 |
|
|
#define OR32_SR_ICE 4
|
218 |
|
|
#define OR32_SR_DME 5
|
219 |
|
|
#define OR32_SR_IME 6
|
220 |
|
|
#define OR32_SR_LEE 7
|
221 |
|
|
#define OR32_SR_CE 8
|
222 |
|
|
#define OR32_SR_F 9
|
223 |
|
|
#define OR32_SR_F_BIT (1 << OR32_SR_F)
|
224 |
|
|
#define OR32_SR_CY 10
|
225 |
|
|
#define OR32_SR_CY_BIT (1 << OR32_SR_CY)
|
226 |
|
|
#define OR32_SR_OV 11
|
227 |
|
|
#define OR32_SR_OV_BIT (1 << OR32_SR_OV)
|
228 |
|
|
#define OR32_SR_OVE 12
|
229 |
|
|
#define OR32_SR_DSX 13
|
230 |
|
|
#define OR32_SR_EPH 14
|
231 |
|
|
#define OR32_SR_FO 15
|
232 |
|
|
#define OR32_SR_TED 16
|
233 |
|
|
|
234 |
|
|
//--------------------------------------------------------------------
|
235 |
|
|
// OR32 NOP Control Codes
|
236 |
|
|
//--------------------------------------------------------------------
|
237 |
|
|
#define NOP_DATA_REG REG_3
|
238 |
|
|
#define NOP_NOP 0x0000
|
239 |
|
|
#define NOP_EXIT 0x0001
|
240 |
|
|
#define NOP_REPORT 0x0002
|
241 |
|
|
#define NOP_PUTC 0x0004
|
242 |
|
|
#define NOP_TRACE_ON 0x0008
|
243 |
|
|
#define NOP_TRACE_OFF 0x0009
|
244 |
|
|
#define NOP_STATS_RESET 0x000A
|
245 |
|
|
#define NOP_PROFILE_ON 0x000B
|
246 |
|
|
#define NOP_PROFILE_OFF 0x000C
|
247 |
|
|
#define NOP_STATS_MARKER 0x000D
|
248 |
|
|
|
249 |
|
|
//--------------------------------------------------------------------
|
250 |
|
|
// OR32 Vectors
|
251 |
|
|
// NOTE: These differ from the real OR32 vectors for space reasons
|
252 |
|
|
//--------------------------------------------------------------------
|
253 |
|
|
#define VECTOR_RESET 0x100
|
254 |
|
|
#define VECTOR_ILLEGAL_INST 0x200
|
255 |
|
|
#define VECTOR_EXTINT 0x300
|
256 |
|
|
#define VECTOR_SYSCALL 0x400
|
257 |
|
|
#define VECTOR_TRAP 0x600
|
258 |
|
|
#define VECTOR_NMI 0x700
|
259 |
|
|
#define VECTOR_BUS_ERROR 0x800
|
260 |
|
|
|
261 |
|
|
#endif
|
262 |
|
|
|