1 ; OpenRISC 1000 32-bit CPU hardware description. -*- Scheme -*-
2 ; Copyright 2000-2019 Free Software Foundation, Inc.
3 ; Contributed for OR32 by Johan Rydberg, jrydberg@opencores.org
4 ; Modified by Julius Baxter, juliusbaxter@gmail.com
5 ; Modified by Andrey Bacherov, avbacherov@opencores.org
7 ; This program is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; either version 3 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program; if not, see <http://www.gnu.org/licenses/>
21 ; These entries list the elements of the raw hardware.
22 ; They're also used to provide tables and other elements of the assembly
27 (comment "program counter")
28 (attrs PC (MACH ORBIS-MACHS))
30 (get () (raw-reg h-pc))
31 (set (newval) (sequence ()
32 (set (reg h-sys-ppc) (raw-reg h-pc))
33 (set (raw-reg h-pc) newval)
37 (define-pmacro REG-INDICES
76 ; Hardware: [S]pecial [P]urpose [R]egisters
79 (name h-spr) (comment "special purpose registers")
80 (attrs VIRTUAL (MACH ORBIS-MACHS))
81 (type register UWI (#x20000))
82 (get (index) (c-call UWI "@cpu@_h_spr_get_raw" index))
83 (set (index newval) (c-call VOID "@cpu@_h_spr_set_raw" index newval))
86 (define-pmacro spr-shift 11)
87 (define-pmacro (spr-address spr-group spr-index)
88 (or (sll UWI (enum UWI (.sym "SPR-GROUP-" spr-group)) spr-shift)
89 (enum UWI (.sym "SPR-INDEX-" spr-group "-" spr-index))))
92 ; Hardware: [G]enepral [P]urpose [R]egisters
95 (name h-gpr) (comment "general registers")
96 (attrs (MACH ORBIS-MACHS))
97 (type register UWI (32))
98 (indices keyword "" REG-INDICES)
99 (get (index) (reg UWI h-spr (add index (spr-address SYS GPR0))))
100 (set (index newval) (set UWI (reg UWI h-spr (add index (spr-address SYS GPR0))) newval))
104 ; Hardware: virtual registerts for FPU (single precision)
109 (comment "floating point registers (single, virtual)")
110 (attrs VIRTUAL (MACH ORFPX32-MACHS))
111 (type register SF (32))
112 (indices keyword "" REG-INDICES)
113 (get (index) (subword SF (trunc SI (reg h-gpr index)) 0))
114 (set (index newval) (set UWI (reg h-gpr index) (zext UWI (subword SI newval 0))))
118 ; Register pairs are offset by 2 for registers r16 and above. This is to
119 ; be able to allow registers to be call saved in GCC across function calls.
121 (define-pmacro (reg-pair-reg-lo index)
122 (and index (const #x1f))
125 (define-pmacro (reg-pair-reg-hi index)
126 (add (and index (const #x1f))
127 (if (eq (sra index (const 5))
136 ; Hardware: vrtual registers for double precision floating point
137 ; operands on 32-bit machines
142 (comment "or32 floating point registers (double, virtual)")
143 (attrs VIRTUAL (MACH ORFPX64A32-MACHS))
144 (type register DF (32))
145 (get (index) (join DF SI
146 (reg h-gpr (reg-pair-reg-lo index))
147 (reg h-gpr (reg-pair-reg-hi index))))
150 (set (reg h-gpr (reg-pair-reg-lo index)) (subword SI newval 0))
151 (set (reg h-gpr (reg-pair-reg-hi index))
152 (subword SI newval 1))))
156 ; Hardware: vrtual 64-bit integer registers for conversions
157 ; float64 <-> int64 on 32-bit machines
162 (comment "or32 double word registers (int64, virtual)")
163 (attrs VIRTUAL (MACH ORFPX64A32-MACHS))
164 (type register DI (32))
165 (get (index) (join DI SI
166 (reg h-gpr (reg-pair-reg-lo index))
167 (reg h-gpr (reg-pair-reg-hi index))))
170 (set (reg h-gpr (reg-pair-reg-lo index)) (subword SI newval 0))
171 (set (reg h-gpr (reg-pair-reg-hi index))
172 (subword SI newval 1))))
199 (define-pmacro (raise-exception exnum)
200 (c-call VOID "@cpu@_exception" pc exnum))
204 "special purpose register groups"
222 (define-pmacro (spr-reg-info)
224 (SYS VR #x000 "version register")
225 (SYS UPR #x001 "unit present register")
226 (SYS CPUCFGR #x002 "cpu configuration register")
227 (SYS DMMUCFGR #x003 "Data MMU configuration register")
228 (SYS IMMUCFGR #x004 "Insn MMU configuration register")
229 (SYS DCCFGR #x005 "Data cache configuration register")
230 (SYS ICCFGR #x006 "Insn cache configuration register")
231 (SYS DCFGR #x007 "Debug configuration register")
232 (SYS PCCFGR #x008 "Performance counters configuration register")
233 (SYS NPC #x010 "Next program counter")
234 (SYS SR #x011 "Supervision Register")
235 (SYS PPC #x012 "Previous program counter")
236 (SYS FPCSR #x014 "Floating point control status register")
238 (.map (.pmacro (n) (.splice SYS (.sym "EPCR" n) (.add n #x20) (.str "Exception PC register " n)))
241 (.map (.pmacro (n) (.splice SYS (.sym "EEAR" n) (.add n #x30) (.str "Exception effective address register " n)))
244 (.map (.pmacro (n) (.splice SYS (.sym "ESR" n) (.add n #x40) (.str "Exception supervision register " n)))
247 (.map (.pmacro (n) (.splice SYS (.sym "GPR" n) (.add n #x400) (.str "General purpose register " n)))
250 (MAC MACLO #x001 "Multiply and accumulate result (low)")
251 (MAC MACHI #x002 "Multiply and accumulate result (high)")
252 (TICK TTMR #x000 "Tick timer mode register")
258 "special purpose register indices"
261 (.map (.pmacro (args)
262 (.apply (.pmacro (group index n comment)
263 ((.sym group "-" index) n))
270 (define-pmacro (define-h-spr-reg spr-group spr-index n spr-comment)
272 (name (.sym "h-" (.downcase spr-group) "-" (.downcase spr-index)))
273 (comment spr-comment)
274 (attrs VIRTUAL (MACH ORBIS-MACHS))
276 (get () (reg UWI h-spr (spr-address spr-group spr-index)))
277 (set (newval) (set (reg UWI h-spr (spr-address spr-group spr-index)) newval))
280 (.splice begin (.unsplice (.map (.pmacro (args) (.apply define-h-spr-reg args)) (spr-reg-info))))
282 (define-pmacro (spr-field-info)
283 ((SYS VR REV 5 0 "revision field")
284 (SYS VR CFG 23 16 "configuration template field")
285 (SYS VR VER 31 24 "version field")
286 (SYS UPR UP 0 0 "UPR present bit")
287 (SYS UPR DCP 1 1 "data cache present bit")
288 (SYS UPR ICP 2 2 "insn cache present bit")
289 (SYS UPR DMP 3 3 "data MMU present bit")
290 (SYS UPR MP 4 4 "MAC unit present bit")
291 (SYS UPR IMP 5 5 "insn MMU present bit")
292 (SYS UPR DUP 6 6 "debug unit present bit")
293 (SYS UPR PCUP 7 7 "performance counters unit present bit")
294 (SYS UPR PICP 8 8 "programmable interrupt controller present bit")
295 (SYS UPR PMP 9 9 "power management present bit")
296 (SYS UPR TTP 10 10 "tick timer present bit")
297 (SYS UPR CUP 31 24 "custom units present field")
298 (SYS CPUCFGR NSGR 3 0 "number of shadow GPR files field")
299 (SYS CPUCFGR CGF 4 4 "custom GPR file bit")
300 (SYS CPUCFGR OB32S 5 5 "ORBIS32 supported bit")
301 (SYS CPUCFGR OB64S 6 6 "ORBIS64 supported bit")
302 (SYS CPUCFGR OF32S 7 7 "ORFPX32 supported bit")
303 (SYS CPUCFGR OF64S 8 8 "ORFPX64 supported bit")
304 (SYS CPUCFGR OV64S 9 9 "ORVDX64 supported bit")
305 (SYS CPUCFGR ND 10 10 "no transfer delay bit")
306 (SYS SR SM 0 0 "supervisor mode bit")
307 (SYS SR TEE 1 1 "tick timer exception enabled bit")
308 (SYS SR IEE 2 2 "interrupt exception enabled bit")
309 (SYS SR DCE 3 3 "data cache enabled bit")
310 (SYS SR ICE 4 4 "insn cache enabled bit")
311 (SYS SR DME 5 5 "data MMU enabled bit")
312 (SYS SR IME 6 6 "insn MMU enabled bit")
313 (SYS SR LEE 7 7 "little endian enabled bit")
314 (SYS SR CE 8 8 "CID enable bit")
315 (SYS SR F 9 9 "flag bit")
316 (SYS SR CY 10 10 "carry bit")
317 (SYS SR OV 11 11 "overflow bit")
318 (SYS SR OVE 12 12 "overflow exception enabled bit")
319 (SYS SR DSX 13 13 "delay slot exception bit")
320 (SYS SR EPH 14 14 "exception prefix high bit")
321 (SYS SR FO 15 15 "fixed one bit")
322 (SYS SR SUMRA 16 16 "SPRs user mode read access bit")
323 (SYS SR CID 31 28 "context ID field")
324 (SYS FPCSR FPEE 0 0 "floating point exceptions enabled bit")
325 (SYS FPCSR RM 2 1 "floating point rounding mode field")
326 (SYS FPCSR OVF 3 3 "floating point overflow flag bit")
327 (SYS FPCSR UNF 4 4 "floating point underflow bit")
328 (SYS FPCSR SNF 5 5 "floating point SNAN flag bit")
329 (SYS FPCSR QNF 6 6 "floating point QNAN flag bit")
330 (SYS FPCSR ZF 7 7 "floating point zero flag bit")
331 (SYS FPCSR IXF 8 8 "floating point inexact flag bit")
332 (SYS FPCSR IVF 9 9 "floating point invalid flag bit")
333 (SYS FPCSR INF 10 10 "floating point infinity flag bit")
334 (SYS FPCSR DZF 11 11 "floating point divide by zero flag bit")
340 "SPR field msb positions"
343 (.map (.pmacro (args)
344 (.apply (.pmacro (group index field msb lsb comment)
345 ((.sym group "-" index "-" field) msb)
356 "SPR field lsb positions"
359 (.map (.pmacro (args)
360 (.apply (.pmacro (group index field msb lsb comment)
361 ((.sym group "-" index "-" field) lsb)
375 (.map (.pmacro (args)
376 (.apply (.pmacro (group index field msb lsb comment)
377 (.splice (.str group "-" index "-" field) (.sll (.inv (.sll (.inv 0) (.add (.sub msb lsb) 1))) lsb))
386 (define-pmacro (define-h-spr-field spr-group spr-index spr-field spr-field-msb spr-field-lsb spr-field-comment)
387 (.let ((spr-field-name (.sym "h-" (.downcase spr-group) "-" (.downcase spr-index) "-" (.downcase spr-field)))
391 (name spr-field-name)
392 (comment spr-field-comment)
393 (attrs VIRTUAL (MACH ORBIS-MACHS))
395 (get () (c-call UWI "@cpu@_h_spr_field_get_raw" (spr-address spr-group spr-index) spr-field-msb spr-field-lsb))
396 (set (value) (c-call VOID "@cpu@_h_spr_field_set_raw" (spr-address spr-group spr-index) spr-field-msb spr-field-lsb value))
401 (.splice begin (.unsplice (.map (.pmacro (args) (.apply define-h-spr-field args)) (spr-field-info))))
407 (comment "delayed control transfer instruction")
415 (name NOT-IN-DELAY-SLOT)
416 (comment "instruction cannot be in delay slot")
425 (comment "instruction may forcefully transfer control (e.g., rfe)")