OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [cpu/] [arm.cpu] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
; ARM CPU description.  -*- Scheme -*-
2
; Copyright (C) 2000, 2009 Red Hat, Inc.
3
; This file is part of CGEN.
4
; See file COPYING.CGEN for details.
5
 
6
(define-rtl-version 0 8)
7
 
8
(include "simplify.inc")
9
 
10
(define-arch
11
  (name arm)
12
  (comment "Advanced RISC Machines (ARM)")
13
  (insn-lsb0? #t)
14
  (machs arm7tdmi)
15
  (isas arm thumb)
16
)
17
 
18
; ??? There should be an official rtx to do this.  Until then.
19
(define-pmacro (invalid-insn)
20
  (c-call BI "invalid_insn" pc) ; FIXME: Not VOID to workaround codegen bug.
21
)
22
 
23
(define-isa
24
  (name arm)
25
  (comment "ARM instruction set (32 bit insns)")
26
  (base-insn-bitsize 32)
27
  ; FIXME: wip. `f-cond' is currently defined in arm7.cpu.
28
  (condition f-cond
29
             ; `cond-code' is the extracted value of `f-cond'
30
             ; FIXME: wip
31
;            (case BI cond-code
32
;                  ((COND_EQ) (reg h-zbit))
33
;                  ((COND_NE) (not (reg h-zbit)))
34
;                  ((COND_CS) (reg h-cbit))
35
;                  ((COND_CC) (not (reg h-cbit)))
36
;                  ((COND_MI) (reg h-nbit))
37
;                  ((COND_PL) (not (reg h-zbit)))
38
;                  ((COND_VS) (reg h-vbit))
39
;                  ((COND_VC) (not (reg h-vbit)))
40
;                  ((COND_HI) (and (reg h-cbit) (not (reg h-zbit))))
41
;                  ((COND_LS) (not (or (reg h-cbit) (reg h-zbit))))
42
;                  ((COND_GE) (eq (reg h-zbit) (reg h-vbit)))
43
;                  ((COND_LT) (ne (reg h-nbit) (reg h-vbit)))
44
;                  ((COND_GT) (and (not (reg h-zbit))
45
;                                  (eq (reg h-nbit) (reg h-vbit))))
46
;                  ((COND_LE) (or (reg h-zbit)
47
;                                 (ne (reg h-nbit) (reg h-vbit))))
48
;                  ((COND_AL) 1)
49
;                  (else (sequence BI () (invalid-insn) 1))))
50
             (c-call BI "eval_cond" cond-code pc))
51
  (decode-assist (27 26 25 24 23 22 21))
52
  ; We can lengthen pbb's by breaking insns that set h-gr into those that set
53
  ; h-gr[15] (the pc), and those that don't.
54
  ; Other analysis of the isa will benefit from this, so this is recorded here
55
  ; rather than in a simulator specific file.
56
;;   (decode-splits
57
;;   ; split insns with field f-rd into f-rd == 15, f-rd != 15
58
;;   ; ??? To be made more general in time.
59
;;   (f-rd ; split on values of this field
60
;;    ()   ; no extra constraints
61
;;    ((no-pc-dest (.iota 15)) (pc-dest 15)) ; list of splits
62
;;    )
63
;;   )
64
  (setup-semantics (set-quiet (reg h-gr 15) (add pc (attr (current-insn) R15-OFFSET))))
65
)
66
 
67
(define-isa
68
  (name thumb)
69
  (comment "ARM Thumb instruction set (16 bit insns)")
70
  (base-insn-bitsize 16)
71
  (decode-assist (15 14 13 12 11 10 9 8))
72
  (setup-semantics (set-quiet (reg h-gr 15) (add pc 4)))
73
)
74
 
75
(define-cpu
76
  (name arm7f)
77
  (comment "ARM7")
78
  (endian either)
79
  (word-bitsize 32)
80
)
81
 
82
(define-mach
83
  (name arm7tdmi)
84
  (comment "ARM 7TDMI core")
85
  (cpu arm7f)
86
  (isas arm thumb)
87
)
88
 
89
(define-model
90
  (name arm710)
91
  (comment "ARM 710 microprocessor")
92
  (mach arm7tdmi)
93
  (unit u-exec "Execution Unit" ()
94
        1 1 ; issue done
95
        () () () ())
96
)
97
 
98
; IDOC attribute for instruction documentation.
99
; FIXME: Categorization is a bit tricky when alu ops can set the pc.
100
 
101
(define-attr
102
  (for insn)
103
  (type enum)
104
  (name IDOC)
105
  (comment "insn kind for documentation")
106
  (attrs META)
107
  (values
108
   (MEM - () "Memory")
109
   (ALU - () "ALU")
110
   (FPU - () "FPU")
111
   (BR - () "Branch")
112
   (PRIV - () "Priviledged")
113
   (MISC - () "Miscellaneous")
114
  )
115
)
116
 
117
; Hardware.
118
 
119
; The program counter is actually reg 15.
120
; But ... [there's always a "But ..." :-(] when referenced in instructions
121
; the value is either 8 or 12 beyond the address of the instruction in
122
; ARM mode and 4 beyond in Thumb mode.
123
; To handle this the program counter is treated as a separate register
124
; and r15 is set to the appropriate offset before executing each instruction.
125
; This seems like the simplest and most efficient way to handle this.
126
 
127
(define-hardware
128
  (name h-pc)
129
  (comment "ARM program counter (h-gr reg 15)")
130
  (attrs PC (ISA arm,thumb))
131
  (type pc)
132
  ; In ARM mode the bottom two bits read as zero.
133
  ; In Thumb mode the bottom bit reads as zero.
134
  ; This can be handled during gets, sets, or both.
135
  ; Handling this in sets seems best ('tis handled in only one place and the
136
  ; stored value is always correct - assuming all out-of-band sets are ok).
137
  ; ??? Might be possible to optimize out the test of tbit.  Later.
138
  (set (newval)
139
       (if (reg h-tbit)
140
           (set (raw-reg SI h-pc) (and newval -2))
141
           (set (raw-reg SI h-pc) (and newval -4))))
142
)
143
 
144
(define-keyword
145
  (name gr-names)
146
  (enum-prefix H-GR-)
147
  (values (pc 15) ; put this first so it is prefered over r15
148
          (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
149
          (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
150
          (sp 13) (lr 14))
151
)
152
 
153
(define-hardware
154
  (name h-gr)
155
  (comment "General purpose registers")
156
  (attrs (ISA arm,thumb) CACHE-ADDR)
157
  (type register SI (16))
158
  (indices extern-keyword gr-names)
159
)
160
 
161
; Banked versions of h-gr.
162
; h-gr is always "active".  When a mode switch happens, the copies in h-gr
163
; are copied to their holding buffers, and new values are switched in.
164
; ??? The non-user-mode versions of these registers have special names which
165
; are just(?) aliases for the normal names.
166
 
167
(define-hardware
168
  (name h-gr-usr)
169
  (comment "user/system mode r8-r14 holding buffer")
170
  (attrs (ISA arm,thumb))
171
  (type register SI (7))
172
)
173
(define-hardware
174
  (name h-gr-fiq)
175
  (comment "fiq mode r8-r14 regs")
176
  (attrs (ISA arm,thumb))
177
  (type register SI (7))
178
)
179
(define-hardware
180
  (name h-gr-svc)
181
  (comment "supervisor mode r13-r14 regs")
182
  (attrs (ISA arm,thumb))
183
  (type register SI (2))
184
)
185
(define-hardware
186
  (name h-gr-abt)
187
  (comment "abort mode r13-r14 regs")
188
  (attrs (ISA arm,thumb))
189
  (type register SI (2))
190
)
191
(define-hardware
192
  (name h-gr-irq)
193
  (comment "irq mode r13-r14 regs")
194
  (attrs (ISA arm,thumb))
195
  (type register SI (2))
196
)
197
(define-hardware
198
  (name h-gr-und)
199
  (comment "undefined mode r13-r14 regs")
200
  (attrs (ISA arm,thumb))
201
  (type register SI (2))
202
)
203
 
204
; The condition code bits.
205
 
206
(dsh h-cbit "carry bit"    ((ISA arm,thumb)) (register BI))
207
(dsh h-nbit "negative bit" ((ISA arm,thumb)) (register BI))
208
(dsh h-vbit "overflow bit" ((ISA arm,thumb)) (register BI))
209
(dsh h-zbit "zerobit"      ((ISA arm,thumb)) (register BI))
210
 
211
(dnop cbit "carry bit"     ((ISA arm,thumb)) h-cbit f-nil)
212
(dnop nbit "negative bit"  ((ISA arm,thumb)) h-nbit f-nil)
213
(dnop vbit "overflow bit"  ((ISA arm,thumb)) h-vbit f-nil)
214
(dnop zbit "zero bit"      ((ISA arm,thumb)) h-zbit f-nil)
215
 
216
; The CPSR (current program status register).
217
 
218
(dsh h-ibit  "irq disable bit" ((ISA arm,thumb)) (register BI))
219
(dsh h-fbit  "fiq disable bit" ((ISA arm,thumb)) (register BI))
220
 
221
(define-hardware
222
  (name h-tbit)
223
  (comment "thumb bit")
224
  (attrs (ISA arm,thumb))
225
  (type register BI)
226
  (set (newval)
227
       (sequence ()
228
                 (c-call VOID "arm_tbit_set" newval)))
229
)
230
 
231
(define-keyword
232
  (name arm-mode)
233
  (comment "arm cpu states")
234
  (values (User #x10)
235
          (FIQ  #x11)
236
          (IRQ  #x12)
237
          (Supervisor #x13)
238
          (Abort #x17)
239
          (Undefined #x1b)
240
          (System #x1f)
241
          )
242
)
243
 
244
(define-hardware
245
  (name h-mbits)
246
  (comment "m4,m3,m2,m1,m0")
247
  (attrs (ISA arm,thumb))
248
  (type register (UINT 5))
249
  (set (newval)
250
       (sequence ()
251
                 ; processor goes into an undefined state if bad value,
252
                 ; so do something similar
253
                 (case VOID newval
254
                        ((ARM-MODE-User ARM-MODE-FIQ ARM-MODE-IRQ
255
                          ARM-MODE-Supervisor ARM-MODE-Abort
256
                          ARM-MODE-Undefined ARM-MODE-System)
257
                         (nop))
258
                        (else (error VOID "bad value for M4-M0")))
259
                 (c-call VOID "arm_mbits_set" newval)))
260
)
261
 
262
(define-hardware
263
  (name h-cpsr)
264
  (comment "Current Program Status Register")
265
  (attrs VIRTUAL (ISA arm,thumb))
266
  (type register SI) ; One CPSR register.
267
  (get ()
268
       ; ??? 'twould be nice if one `or' would do
269
       (or SI (sll (zext SI (reg BI h-nbit)) (const 31))
270
            (or SI (sll (zext SI (reg BI h-zbit)) (const 30))
271
                 (or SI (sll (zext SI (reg BI h-cbit)) (const 29))
272
                      (or SI (sll (zext SI (reg BI h-vbit)) (const 28))
273
                           (or SI (sll (zext SI (reg BI h-ibit)) (const 7))
274
                                (or SI (sll (zext SI (reg BI h-fbit)) (const 6))
275
                                     (or SI (sll (zext SI (reg BI h-tbit)) (const 5))
276
                                          (reg UINT h-mbits)))))))))
277
  (set (newval)
278
       (sequence ()
279
                 ; FIXME: Processor enters undefined state if software changes
280
                 ; tbit, so we should do something similar.
281
                 (set (reg h-nbit) (ne (and newval #x80000000) 0))
282
                 (set (reg h-zbit) (ne (and newval #x40000000) 0))
283
                 (set (reg h-cbit) (ne (and newval #x20000000) 0))
284
                 (set (reg h-vbit) (ne (and newval #x10000000) 0))
285
                 ; FIXME: user mode is not permitted to change ibit/fbit!
286
                 (set (reg h-ibit) (ne (and newval #x00000080) 0))
287
                 (set (reg h-fbit) (ne (and newval #x00000040) 0))
288
                 (set (reg h-tbit) (ne (and newval #x00000020) 0))
289
                 (set (reg h-mbits) (and newval #x1f))))
290
)
291
 
292
(define-hardware
293
  (name h-spsr-fiq)
294
  (comment "Saved Process Status Register during FIQ")
295
  (attrs (ISA arm,thumb))
296
  (type register SI)
297
)
298
(define-hardware
299
  (name h-spsr-svc)
300
  (comment "Saved Process Status Register during SVC")
301
  (attrs (ISA arm,thumb))
302
  (type register SI)
303
)
304
(define-hardware
305
  (name h-spsr-abt)
306
  (comment "Saved Process Status Register during Abort")
307
  (attrs (ISA arm,thumb))
308
  (type register SI)
309
)
310
(define-hardware
311
  (name h-spsr-irq)
312
  (comment "Saved Process Status Register during IRQ")
313
  (attrs (ISA arm,thumb))
314
  (type register SI)
315
)
316
(define-hardware
317
  (name h-spsr-und)
318
  (comment "Saved Process Status Register during Undefined")
319
  (attrs (ISA arm,thumb))
320
  (type register SI)
321
)
322
 
323
; Virtual version of spsr to access real one based on current mode.
324
 
325
(define-hardware
326
  (name h-spsr)
327
  (comment "virtual spsr")
328
  (attrs VIRTUAL (ISA arm,thumb))
329
  (type register SI)
330
  (get ()
331
       (case SI (reg h-mbits)
332
              ((ARM-MODE-User)       (error SI "can't read spsr in user mode"))
333
              ((ARM-MODE-FIQ)        (reg h-spsr-fiq))
334
              ((ARM-MODE-IRQ)        (reg h-spsr-irq))
335
              ((ARM-MODE-Supervisor) (reg h-spsr-svc))
336
              ((ARM-MODE-Abort)      (reg h-spsr-abt))
337
              ((ARM-MODE-Undefined)  (reg h-spsr-und))
338
              ((ARM-MODE-System)     (error SI "can't read spsr in system mode"))
339
              (else (error SI "can't read spsr, invalid mode"))))
340
  (set (newval)
341
       (case VOID (reg h-mbits)
342
              ((ARM-MODE-User)       (error VOID "can't set spsr in user mode"))
343
              ((ARM-MODE-FIQ)        (set (reg h-spsr-fiq) newval))
344
              ((ARM-MODE-IRQ)        (set (reg h-spsr-irq) newval))
345
              ((ARM-MODE-Supervisor) (set (reg h-spsr-svc) newval))
346
              ((ARM-MODE-Abort)      (set (reg h-spsr-abt) newval))
347
              ((ARM-MODE-Undefined)  (set (reg h-spsr-und) newval))
348
              ((ARM-MODE-System)     (error VOID "can't set spsr in system mode"))
349
              (else (error VOID "can't set spsr, invalid mode"))))
350
)
351
 
352
; Explicitly define the shift types so they can be used in semantics
353
; (enums are created for them).
354
 
355
(define-keyword
356
  (name shift-type)
357
  (comment "operand 2 shift type")
358
  (values (lsl 0) (asl 0) (lsr 1) (asr 2) (ror 3))
359
)
360
 
361
(define-hardware
362
  (name h-operand2-shifttype)
363
  (comment "operand2 shift type")
364
  (type immediate (UINT 2))
365
  (values extern-keyword shift-type)
366
)
367
 
368
; Utility macros for setting the condition codes.
369
 
370
(define-pmacro (set-zn-flags result)
371
  (sequence ()
372
            (set zbit (zflag WI result))
373
            (set nbit (nflag WI result)))
374
)
375
 
376
; Logical operation flag handling:
377
; cbit is set to the carry out of a shift operation if present
378
; nbit is set to the sign bit
379
; vbit is not affected
380
; zflag is set to indicate whether the result was zero or not
381
 
382
(define-pmacro (set-logical-cc result carry-out)
383
  (sequence ()
384
            (set-zn-flags result)
385
            (set cbit carry-out))
386
)
387
 
388
(define-pmacro (set-add-flags arg1 arg2 carry)
389
  (sequence ((SI result))
390
            (set result (addc arg1 arg2 carry))
391
            (set-zn-flags result)
392
            (set cbit (add-cflag arg1 arg2 carry))
393
            (set vbit (add-oflag arg1 arg2 carry)))
394
)
395
 
396
(define-pmacro (set-sub-flags arg1 arg2 borrow)
397
  (sequence ((SI result))
398
            (set result (subc arg1 arg2 (not borrow)))
399
            (set-zn-flags result)
400
            (set cbit (not (sub-cflag arg1 arg2 (not borrow))))
401
            (set vbit (sub-oflag arg1 arg2 (not borrow))))
402
)
403
 
404
; Utility macros for testing the condition codes.
405
 
406
(define-pmacro (test-ne)  (not zbit))
407
(define-pmacro (test-eq)  zbit)
408
(define-pmacro (test-gt)  (not (or zbit (xor nbit vbit))))
409
(define-pmacro (test-le)  (or zbit (xor nbit vbit)))
410
(define-pmacro (test-ge)  (not (xor nbit vbit)))
411
(define-pmacro (test-lt)  (xor nbit vbit))
412
(define-pmacro (test-hi)  (and cbit (not zbit)))
413
(define-pmacro (test-ls)  (or (not cbit) zbit))
414
(define-pmacro (test-cc)  (not cbit))
415
(define-pmacro (test-cs)  cbit)
416
(define-pmacro (test-pl)  (not nbit))
417
(define-pmacro (test-mi)  nbit)
418
(define-pmacro (test-vc)  (not vbit))
419
(define-pmacro (test-vs)  vbit)
420
 
421
(if (keep-isa? (arm))
422
    (include "arm7.cpu"))
423
(if (keep-isa? (thumb))
424
    (include "thumb.cpu"))

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.