]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/cygmon/v2_0/misc/arm/cpu.h
Initial revision
[karo-tx-redboot.git] / packages / cygmon / v2_0 / misc / arm / cpu.h
1 #ifndef __ARM_CPU_H__
2 #define __ARM_CPU_H__
3 //==========================================================================
4 //
5 //      cpu.h
6 //
7 //      ARM specific processor defines
8 //
9 //==========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //==========================================================================
43 //#####DESCRIPTIONBEGIN####
44 //
45 // Author(s):    
46 // Contributors: gthomas
47 // Date:         1999-10-20
48 // Purpose:      ARM specific processor defines 
49 // Description:  ARM is a Registered Trademark of Advanced RISC Machines
50 //               Limited.
51 //               Other Brands and Trademarks are the property of their
52 //               respective owners.               
53 //
54 //####DESCRIPTIONEND####
55 //
56 //=========================================================================
57
58 #include <bsp/bsp.h>
59 #include <bsp/defs.h>
60 #ifdef __ECOS__
61 #include <cyg/hal/hal_arch.h>
62 #endif
63
64 /*
65  * Only define __NEED_UNDERSCORE__ for arm-coff targets
66  */
67 #if !defined(__ELF__)
68 #  define __NEED_UNDERSCORE__
69 #endif
70
71 /*
72  * Macros to glue together two tokens.
73  */
74 #  ifdef __STDC__
75 #    define XGLUE(a,b) a##b
76 #  else
77 #    define XGLUE(a,b) a/**/b
78 #  endif
79
80 #  define GLUE(a,b) XGLUE(a,b)
81
82 /*
83  * Symbol Names with leading underscore if necessary
84  */
85 #  ifdef __NEED_UNDERSCORE__
86 #    define SYM_NAME(name) GLUE(_,name)
87 #  else
88 #    define SYM_NAME(name) name
89 #  endif /* __NEED_UNDERSCORE__ */
90
91 /*
92  * Various macros to better handle assembler/object format differences
93  */
94 #if defined(__ASSEMBLER__)
95
96 /*
97  * Assembly function start definition
98  */
99 #ifdef __NEED_UNDERSCORE__
100 .macro FUNC_START name
101         .global _\name
102         .align  4
103     _\name:
104 .endm
105 #else
106 .macro FUNC_START name
107         .global \name
108         .align  4
109     \name:
110 .endm
111 #endif
112
113 /*
114  * Assembly function end definition
115  */
116 #ifdef __NEED_UNDERSCORE__
117 .macro FUNC_END name
118 .endm
119 #else
120 .macro FUNC_END name
121 .endm
122 #endif
123
124 /*
125  * Register Prefix
126  */
127 #  ifndef __REGISTER_PREFIX__
128 #    define __REGISTER_PREFIX__
129 #  endif /* __REGISTER_PREFIX__ */
130
131 /*
132  * Immediate Prefix
133  */
134 #  ifndef __IMM_PREFIX__
135 #    define __IMM_PREFIX__ #
136 #  endif /* __IMM_PREFIX__ */
137
138 /*
139  * use the right prefix for registers.
140  */
141 #  define REG(x) GLUE(__REGISTER_PREFIX__,x)
142
143 /*
144  * use the right prefix for immediate values.
145  */
146 #  define IMM(x) GLUE(__IMM_PREFIX__,x)
147
148 #endif /* defined(__ASSEMBLER__) */
149
150
151 /*
152  * Setup register defines and such
153  */
154 #if defined(__ASSEMBLER__)
155
156 #  define r0   REG (r0)
157 #  define r1   REG (r1)
158 #  define r2   REG (r2)
159 #  define r3   REG (r3)
160
161 #  define r4   REG (r4)
162 #  define r5   REG (r5)
163 #  define r6   REG (r6)
164 #  define r7   REG (r7)
165 #  define r8   REG (r8)
166 #  define r9   REG (r9)
167 #  define r10  REG (r10)
168 #  define r11  REG (r11)
169 #  define r12  REG (r12)
170 #  define r13  REG (r13)
171 #  define sp   REG (sp)
172 #  define r14  REG (r14)
173 #  define lr   REG (lr)
174 #  define pc   REG (pc)
175
176 #  define f0   REG (f0)
177 #  define f1   REG (f1)
178 #  define f2   REG (f2)
179 #  define f3   REG (f3)
180 #  define f4   REG (f4)
181 #  define f5   REG (f5)
182 #  define f6   REG (f6)
183 #  define f7   REG (f7)
184 #  define fps  REG (fps)
185
186 #  define cpsr REG (cpsr)
187 #  define spsr REG (spsr)
188
189 /*
190  * Register offset definitions
191  * These numbers are offsets into the ex_regs_t struct.
192  */
193 #  define r0_o   0
194 #  define r1_o   4
195 #  define r2_o   8
196 #  define r3_o   12
197 #  define r4_o   16
198 #  define r5_o   20
199 #  define r6_o   24
200 #  define r7_o   28
201 #  define r8_o   32
202 #  define r9_o   36
203 #  define r10_o  40
204 #  define r11_o  44
205 #  define r12_o  48
206 #  define r13_o  52
207 #  define sp_o   r13_o
208 #  define r14_o  56
209 #  define lr_o   r14_o
210 #  define pc_o   60
211
212 #  define f0_o   64
213 #  define f1_o   76
214 #  define f2_o   88
215 #  define f3_o   100
216 #  define f4_o   112
217 #  define f5_o   124
218 #  define f6_o   136
219 #  define f7_o   148
220 #  define fps_o  160
221
222 #  define cpsr_o 164
223 #  define spsvc_o 168
224 #  define ARM_EX_REGS_T_SIZE 172
225
226 #else /* !defined(__ASSEMBLER__) */
227
228   /*
229    * Register name that is used in help strings and such
230    */
231 # define REGNAME_EXAMPLE "r0"
232
233   /*
234    *  Register numbers. These are assumed to match the
235    *  register numbers used by GDB.
236    */
237   enum __regnames {
238       REG_R0,
239       REG_R1,
240       REG_R2,
241       REG_R3,
242       REG_R4,
243       REG_R5,
244       REG_R6,
245       REG_R7,
246       REG_R8,
247       REG_R9,
248       REG_R10,
249       REG_R11,
250       REG_R12,
251       REG_R13,
252       REG_SP=REG_R13,
253       REG_R14,
254       REG_LR=REG_R14,
255       REG_PC,
256
257       REG_F0,
258       REG_F1,
259       REG_F2,
260       REG_F3,
261       REG_F4,
262       REG_F5,
263       REG_F6,
264       REG_F7,
265       REG_FPS,
266
267       REG_CPSR,
268       REG_SPSVC,
269       REG_MAX=REG_SPSVC
270   };
271
272   /*
273    * 12-byte struct for storing Floating point registers
274    */
275   typedef struct
276   {
277       unsigned long high;
278       unsigned long middle;
279       unsigned long low;
280   } fp_reg;
281
282   /*
283    *  How registers are stored for exceptions.
284    */
285 #ifdef __ECOS__
286 #define ex_regs_t HAL_SavedRegisters
287 #define _r0       d[0]
288 #define _r1       d[1]
289 #define _r2       d[2]
290 #define _r3       d[3]
291 #define _r4       d[4]
292 #define _r5       d[5]
293 #define _r6       d[6]
294 #define _r7       d[7]
295 #define _r8       d[8]
296 #define _r9       d[9]
297 #define _r10      d[10]
298 #define _r11      fp
299 #define _r12      ip
300 #define _r13      sp
301 #define _r14      lr
302 #define _pc       pc
303 #define _cpsr     cpsr
304 #define _spsvc    msr
305 #else
306   typedef struct
307   {
308     unsigned long _r0;
309     unsigned long _r1;
310     unsigned long _r2;
311     unsigned long _r3;
312     unsigned long _r4;
313     unsigned long _r5;
314     unsigned long _r6;
315     unsigned long _r7;
316     unsigned long _r8;
317     unsigned long _r9;
318     unsigned long _r10;
319     unsigned long _r11;
320     unsigned long _r12;
321     unsigned long _r13;
322     unsigned long _r14;
323     unsigned long _pc;
324
325     fp_reg        _f0;
326     fp_reg        _f1;
327     fp_reg        _f2;
328     fp_reg        _f3;
329     fp_reg        _f4;
330     fp_reg        _f5;
331     fp_reg        _f6;
332     fp_reg        _f7;
333     unsigned long _fps;
334     unsigned long _cpsr;
335
336     unsigned long _spsvc;  /* saved svc mode sp */
337
338   } ex_regs_t;
339 #endif
340 #   define   _sp  _r13
341 #   define   _lr  _r14
342
343 extern void __icache_flush(void *addr, int nbytes);
344 extern void __dcache_flush(void *addr, int nbytes);
345
346 #endif /* __ASSEMBLER__ */
347
348
349 /*
350  * Program Status Register Definitions
351  */
352 #if defined(__ASSEMBLER__)
353 #  define ARM_PSR_NEGATIVE       0x80000000  /* Negative Bit                           */
354 #  define ARM_PSR_ZERO           0x40000000  /* Zero Bit                               */
355 #  define ARM_PSR_CARRY          0x20000000  /* Carry Bit                              */
356 #  define ARM_PSR_OVERFLOW       0x10000000  /* Overflow Bit                           */
357 #  define ARM_PSR_IRQ            0x00000080  /* IRQ Bit                                */
358 #  define ARM_PSR_FIQ            0x00000040  /* FIQ Bit                                */
359 #  define ARM_PSR_THUMB_STATE    0x00000020  /* Thumb/ARM(R) Execution                 */
360 #  define ARM_PSR_MODE_MASK      0x0000001F  /* ARM(R) Processor Mode Mask             */
361 #else /* ! defined(__ASSEMBLER__) */
362   struct psr_struct {
363       unsigned mode      : 5;
364       unsigned t_bit     : 1;
365       unsigned f_bit     : 1;
366       unsigned i_bit     : 1;
367       unsigned rsv1      : 20;  /* == 0x00000 */
368       unsigned v_bit     : 1;
369       unsigned c_bit     : 1;
370       unsigned z_bit     : 1;
371       unsigned n_bit     : 1;
372   };
373
374   union arm_psr {
375       unsigned long word;
376       struct psr_struct psr;
377   };
378 #endif /* __ASSEMBLER__ */
379
380 /*
381  * PSR Mode values
382  */
383 #define ARM_PSR_MODE_USER      0x00000010  /* User mode                              */
384 #define ARM_PSR_MODE_FIQ       0x00000011  /* FIQ mode                               */
385 #define ARM_PSR_MODE_IRQ       0x00000012  /* IRQ mode                               */
386 #define ARM_PSR_MODE_SVC       0x00000013  /* SVC mode                               */
387 #define ARM_PSR_MODE_ABORT     0x00000017  /* ABORT mode                             */
388 #define ARM_PSR_MODE_UNDEF     0x0000001B  /* UNDEF mode                             */
389 #define ARM_PSR_MODE_SYSTEM    0x0000001F  /* System Mode                            */
390 #define ARM_PSR_NUM_MODES      7
391
392 /*
393  * Core Exception vectors.
394  */
395 #define BSP_CORE_EXC_RESET                     0
396 #define BSP_CORE_EXC_UNDEFINED_INSTRUCTION     1
397 #define BSP_CORE_EXC_SOFTWARE_INTERRUPT        2
398 #define BSP_CORE_EXC_PREFETCH_ABORT            3
399 #define BSP_CORE_EXC_DATA_ABORT                4
400 #define BSP_CORE_EXC_ADDRESS_ERROR_26_BIT      5
401 #define BSP_CORE_EXC_IRQ                       6
402 #define BSP_CORE_EXC_FIQ                       7
403 #define BSP_MAX_EXCEPTIONS                     8
404 #define BSP_CORE_EXC(vec_num)                  (unsigned long*)(vec_num << 2)
405
406 #define BREAKPOINT_INSN                        0xE7FFDEFE   /* Illegal inst opcode */
407 #define SYSCALL_SWI                            0x00180001
408
409 #if defined(__ASSEMBLER__)
410   .macro BREAKPOINT
411          .word BREAKPOINT_INSN
412   .endm
413   .macro SYSCALL
414          swi  IMM(SYSCALL_SWI)
415   .endm
416   .macro __CLI
417          stmfd  sp!, {r0}
418          mrs    r0, cpsr
419          bic    r0, r0, IMM(ARM_PSR_IRQ | ARM_PSR_FIQ)
420          msr    cpsr, r0
421          ldmfd  sp!, {r0}
422   .endm
423   .macro __STI
424          stmfd  sp!, {r0}
425          mrs    r0, cpsr
426          orr    r0, r0, IMM(ARM_PSR_IRQ | ARM_PSR_FIQ)
427          msr    cpsr, r0
428          ldmfd  sp!, {r0}
429   .endm
430
431 #  if 0
432   /*
433    * Use this code to verify a particular processing mode
434    */
435         mrs     r0, cpsr
436         and     r0, r0, IMM(ARM_PSR_MODE_MASK)
437         ldr     r1, =ARM_PSR_MODE_IRQ
438         cmps    r0, r1
439 0:      bne     0b
440         PORT_TOGGLE_DEBUG
441 #  endif /* 0 */
442
443 #else /* !defined(__ASSEMBLER__) */
444
445 #  define BREAKPOINT() asm volatile(" .word 0xE7FFDEFE")
446 #  define SYSCALL()    asm volatile(" swi   %0" : /* No outputs */ : "i" (SYSCALL_SWI))
447 #  define __cli()      asm volatile("
448          stmfd  sp!, {r0}
449          mrs    r0, cpsr
450          bic    r0, r0, #0x000000C0
451          msr    cpsr, r0
452          ldmfd  sp!, {r0}")
453 #  define __sti()      asm volatile("
454          stmfd  sp!, {r0}
455          mrs    r0, cpsr
456          orr    r0, r0, #0x000000C0
457          msr    cpsr, r0
458          ldmfd  sp!, {r0}")
459 #  define __mcr(cp_num, opcode1, Rd, CRn, CRm, opcode2) \
460      asm volatile (" mcr " cp_num  ", " \
461                            opcode1 ", " \
462                            "%0"    ", " \
463                            CRn     ", " \
464                            CRm     ", " \
465                            opcode2 : /* no outputs */ : "r" (Rd))
466 #  define __mrc(cp_num, opcode1, Rd, CRn, CRm, opcode2) \
467      asm volatile (" mrc " cp_num  ", " \
468                            opcode1 ", " \
469                            "%0"    ", " \
470                            CRn     ", " \
471                            CRm     ", " \
472                            opcode2 : "=r" (Rd) : /* no inputs */)
473
474   static inline unsigned __get_cpsr(void)
475   {
476       unsigned long retval;
477       asm volatile (" mrs  %0, cpsr" : "=r" (retval) : /* no inputs */  );
478       return retval;
479   }
480
481   static inline void __set_cpsr(unsigned val)
482   {
483       asm volatile (" msr  cpsr, %0" : /* no outputs */ : "r" (val)  );
484   }
485
486   static inline unsigned __get_spsr(void)
487   {
488       unsigned long retval;
489       asm volatile (" mrs  %0, spsr" : "=r" (retval) : /* no inputs */  );
490       return retval;
491   }
492
493   static inline void __set_spsr(unsigned val)
494   {
495       asm volatile (" msr  spsr, %0" : /* no outputs */ : "r" (val)  );
496   }
497
498   static inline unsigned __get_sp(void)
499   {
500       unsigned long retval;
501       asm volatile (" mov  %0, sp" : "=r" (retval) : /* no inputs */  );
502       return retval;
503   }
504
505   static inline void __set_sp(unsigned val)
506   {
507       asm volatile (" mov  sp, %0" : /* no outputs */ : "r" (val)  );
508   }
509
510   static inline unsigned __get_fp(void)
511   {
512       unsigned long retval;
513       asm volatile (" mov  %0, fp" : "=r" (retval) : /* no inputs */  );
514       return retval;
515   }
516
517   static inline void __set_fp(unsigned val)
518   {
519       asm volatile (" mov  fp, %0" : /* no outputs */ : "r" (val)  );
520   }
521
522   static inline unsigned __get_pc(void)
523   {
524       unsigned long retval;
525       asm volatile (" mov  %0, pc" : "=r" (retval) : /* no inputs */  );
526       return retval;
527   }
528
529   static inline void __set_pc(unsigned val)
530   {
531       asm volatile (" mov  pc, %0" : /* no outputs */ : "r" (val)  );
532   }
533
534   static inline unsigned __get_lr(void)
535   {
536       unsigned long retval;
537       asm volatile (" mov  %0, lr" : "=r" (retval) : /* no inputs */  );
538       return retval;
539   }
540
541   static inline void __set_lr(unsigned val)
542   {
543       asm volatile (" mov  lr, %0" : /* no outputs */ : "r" (val)  );
544   }
545
546   static inline unsigned __get_r8(void)
547   {
548       unsigned long retval;
549       asm volatile (" mov  %0, r8" : "=r" (retval) : /* no inputs */  );
550       return retval;
551   }
552
553   static inline void __set_r8(unsigned val)
554   {
555       asm volatile (" mov  r8, %0" : /* no outputs */ : "r" (val)  );
556   }
557
558   static inline unsigned __get_r9(void)
559   {
560       unsigned long retval;
561       asm volatile (" mov  %0, r9" : "=r" (retval) : /* no inputs */  );
562       return retval;
563   }
564
565   static inline void __set_r9(unsigned val)
566   {
567       asm volatile (" mov  r9, %0" : /* no outputs */ : "r" (val)  );
568   }
569
570   static inline unsigned __get_r10(void)
571   {
572       unsigned long retval;
573       asm volatile (" mov  %0, r10" : "=r" (retval) : /* no inputs */  );
574       return retval;
575   }
576
577   static inline void __set_r10(unsigned val)
578   {
579       asm volatile (" mov  r10, %0" : /* no outputs */ : "r" (val)  );
580   }
581
582   static inline unsigned __get_r11(void)
583   {
584       unsigned long retval;
585       asm volatile (" mov  %0, r11" : "=r" (retval) : /* no inputs */  );
586       return retval;
587   }
588
589   static inline void __set_r11(unsigned val)
590   {
591       asm volatile (" mov  r11, %0" : /* no outputs */ : "r" (val)  );
592   }
593
594   static inline unsigned __get_r12(void)
595   {
596       unsigned long retval;
597       asm volatile (" mov  %0, r12" : "=r" (retval) : /* no inputs */  );
598       return retval;
599   }
600
601   static inline void __set_r12(unsigned val)
602   {
603       asm volatile (" mov  r12, %0" : /* no outputs */ : "r" (val)  );
604   }
605
606 #endif /* defined(__ASSEMBLER__) */
607
608 #define GDB_BREAKPOINT_VECTOR BSP_CORE_EXC_UNDEFINED_INSTRUCTION
609 #define GDB_SYSCALL_VECTOR    BSP_CORE_EXC_SOFTWARE_INTERRUPT
610
611 #define ARM_INST_SIZE            sizeof(unsigned long)
612 #define GDB_BREAKPOINT_INST_SIZE ARM_INST_SIZE
613
614 #ifdef __CPU_LH77790A__
615 #  include <bsp/lh77790a.h>
616 #endif /* __CPU_LH77790A__ */
617
618 #if !defined(__ASSEMBLER__)
619 /*
620  * Define the CPU specific data
621  */
622 #ifdef __CPU_LH77790A__
623   typedef struct {
624       unsigned char lh77790a_port_control_shadow;
625   } arm_cpu_data;
626 #endif /* __CPU_LH77790A__ */
627 #endif /* !defined(__ASSEMBLER__) */
628
629 #ifdef __CPU_SA110__
630 #include <bsp/sa-110.h>
631 #endif /* __CPU_SA110__ */
632
633 #ifdef __CPU_SA1100__
634 #include <bsp/sa-1100.h>
635 #endif /* __CPU_SA110__ */
636
637 #ifdef __CPU_710T__
638 #include <bsp/arm710t.h>
639 #endif /* __CPU_710T__ */
640
641 #ifdef MMU
642 /*
643  * ARM(R) MMU Definitions
644  */
645
646 #ifndef __ASSEMBLER__
647 extern void *page1;
648 #endif /* __ASSEMBLER__ */
649
650 /*
651  * ARM(R) Cache and MMU Control Registers
652  *
653  * Accessed through coprocessor instructions.
654  */
655 #ifdef __ASSEMBLER__
656 #  define ARM_CACHE_COPROCESSOR_NUM             p15
657 #  define ARM_COPROCESSOR_OPCODE_DONT_CARE      0x0
658 #  define ARM_COPROCESSOR_RM_DONT_CARE          c0
659 #else /* __ASSEMBLER__ */
660 #  define ARM_CACHE_COPROCESSOR_NUM             "p15"
661 #  define ARM_COPROCESSOR_OPCODE_DONT_CARE      "0x0"
662 #  define ARM_COPROCESSOR_RM_DONT_CARE          "c0"
663 #endif /* __ASSEMBLER__ */
664
665 #ifdef __ASSEMBLER__
666 #  define ARM_ID_REGISTER                        c0
667 #  define ARM_CONTROL_REGISTER                   c1
668 #  define ARM_TRANSLATION_TABLE_BASE_REGISTER    c2
669 #  define ARM_DOMAIN_ACCESS_CONTROL_REGISTER     c3
670 #  define ARM_FAULT_STATUS_REGISTER              c5
671 #  define ARM_FAULT_ADDRESS_REGISTER             c6
672 #  define ARM_CACHE_OPERATIONS_REGISTER          c7
673 #  define ARM_TLB_OPERATIONS_REGISTER            c8
674 #  define ARM_READ_BUFFER_OPERATIONS_REGISTER    c9
675 #else /* __ASSEMBLER__ */
676 #  define ARM_ID_REGISTER                        "c0"
677 #  define ARM_CONTROL_REGISTER                   "c1"
678 #  define ARM_TRANSLATION_TABLE_BASE_REGISTER    "c2"
679 #  define ARM_DOMAIN_ACCESS_CONTROL_REGISTER     "c3"
680 #  define ARM_FAULT_STATUS_REGISTER              "c5"
681 #  define ARM_FAULT_ADDRESS_REGISTER             "c6"
682 #  define ARM_CACHE_OPERATIONS_REGISTER          "c7"
683 #  define ARM_TLB_OPERATIONS_REGISTER            "c8"
684 #  define ARM_READ_BUFFER_OPERATIONS_REGISTER    "c9"
685 #endif /* __ASSEMBLER__ */
686
687 /*
688  * SA-1100 Cache and MMU ID Register value
689  */
690 #define ARM_ID_MASK                              0xFFFFFFF0
691 #define ARM_ID_VALUE                             0x4401a110
692
693 /*
694  * SA-1100 Cache Control Register Bit Fields and Masks
695  */
696 #define ARM_MMU_DISABLED                         0x00000000
697 #define ARM_MMU_ENABLED                          0x00000001
698 #define ARM_MMU_MASK                             0x00000001
699 #define ARM_ADDRESS_FAULT_DISABLED               0x00000000
700 #define ARM_ADDRESS_FAULT_ENABLED                0x00000002
701 #define ARM_ADDRESS_FAULT_MASK                   0x00000002
702 #define ARM_DATA_CACHE_DISABLED                  0x00000000
703 #define ARM_DATA_CACHE_ENABLED                   0x00000004
704 #define ARM_DATA_CACHE_MASK                      0x00000004
705 #define ARM_WRITE_BUFFER_DISABLED                0x00000000
706 #define ARM_WRITE_BUFFER_ENABLED                 0x00000008
707 #define ARM_WRITE_BUFFER_MASK                    0x00000008
708 #define ARM_LITTLE_ENDIAN                        0x00000000
709 #define ARM_BIG_ENDIAN                           0x00000080
710 #define ARM_ACCESS_CHECKS_NONE                   0x00000000
711 #define ARM_ACCESS_CHECKS_SYSTEM                 0x00000100
712 #define ARM_ACCESS_CHECKS_ROM                    0x00000200
713 #define ARM_INSTRUCTION_CACHE_DISABLED           0x00000000
714 #define ARM_INSTRUCTION_CACHE_ENABLED            0x00001000
715 #define ARM_INSTRUCTION_CACHE_MASK               0x00001000
716 #define ARM_VIRTUAL_IVR_BASE_00000000            0x00000000
717 #define ARM_VIRTUAL_IVR_BASE_FFFF0000            0x00002000
718 #define ARM_CONTROL_SBZ_MASK                     0x00001FFF
719
720 /*
721  * SA-1100 Translation Table Base Bit Masks
722  */
723 #define ARM_TRANSLATION_TABLE_MASK               0xFFFFC000
724
725 /*
726  * SA-1100 Domain Access Control Bit Masks
727  */
728 #define ARM_DOMAIN_0_MASK                        0x00000003
729 #define ARM_DOMAIN_1_MASK                        0x0000000C
730 #define ARM_DOMAIN_2_MASK                        0x00000030
731 #define ARM_DOMAIN_3_MASK                        0x000000C0
732 #define ARM_DOMAIN_4_MASK                        0x00000300
733 #define ARM_DOMAIN_5_MASK                        0x00000C00
734 #define ARM_DOMAIN_6_MASK                        0x00003000
735 #define ARM_DOMAIN_7_MASK                        0x0000C000
736 #define ARM_DOMAIN_8_MASK                        0x00030000
737 #define ARM_DOMAIN_9_MASK                        0x000C0000
738 #define ARM_DOMAIN_10_MASK                       0x00300000
739 #define ARM_DOMAIN_11_MASK                       0x00C00000
740 #define ARM_DOMAIN_12_MASK                       0x03000000
741 #define ARM_DOMAIN_13_MASK                       0x0C000000
742 #define ARM_DOMAIN_14_MASK                       0x30000000
743 #define ARM_DOMAIN_15_MASK                       0xC0000000
744
745 #define ARM_ACCESS_TYPE_NO_ACCESS(domain_num)    (0x0 << (domain_num))
746 #define ARM_ACCESS_TYPE_CLIENT(domain_num)       (0x1 << (domain_num))
747 #define ARM_ACCESS_TYPE_MANAGER(domain_num)      (0x3 << (domain_num))
748
749 /*
750  * SA-1100 Fault Status Bit Masks
751  */
752 #define ARM_FAULT_STATUS_MASK                    0x0000000F
753 #define ARM_DOMAIN_MASK                          0x000000F0
754 #define ARM_DATA_BREAKPOINT_MASK                 0x00000200
755
756 /*
757  * SA-1100 Cache Control Operations Definitions
758  */
759 #ifdef __ASSEMBLER__
760 #  define ARM_FLUSH_CACHE_INST_DATA_OPCODE       0x0
761 #  define ARM_FLUSH_CACHE_INST_DATA_RM           c7
762 #  define ARM_FLUSH_CACHE_INST_OPCODE            0x0
763 #  define ARM_FLUSH_CACHE_INST_RM                c5
764 #  define ARM_FLUSH_CACHE_DATA_OPCODE            0x0
765 #  define ARM_FLUSH_CACHE_DATA_RM                c6
766 #  define ARM_FLUSH_CACHE_DATA_SINGLE_OPCODE     0x1
767 #  define ARM_FLUSH_CACHE_DATA_SINGLE_RM         c6
768 #  define ARM_CLEAN_CACHE_DATA_ENTRY_OPCODE      0x1
769 #  define ARM_CLEAN_CACHE_DATA_ENTRY_RM          c10
770 #  define ARM_DRAIN_CACHE_WRITE_BUFFER_OPCODE    0x4
771 #  define ARM_DRAIN_CACHE_WRITE_BUFFER_RM        c10
772 #else /* __ASSEMBLER__ */                        
773 #  define ARM_FLUSH_CACHE_INST_DATA_OPCODE       "0x0"
774 #  define ARM_FLUSH_CACHE_INST_DATA_RM           "c7"
775 #  define ARM_FLUSH_CACHE_INST_OPCODE            "0x0"
776 #  define ARM_FLUSH_CACHE_INST_RM                "c5"
777 #  define ARM_FLUSH_CACHE_DATA_OPCODE            "0x0"
778 #  define ARM_FLUSH_CACHE_DATA_RM                "c6"
779 #  define ARM_FLUSH_CACHE_DATA_SINGLE_OPCODE     "0x1"
780 #  define ARM_FLUSH_CACHE_DATA_SINGLE_RM         "c6"
781 #  define ARM_CLEAN_CACHE_DATA_ENTRY_OPCODE      "0x1"
782 #  define ARM_CLEAN_CACHE_DATA_ENTRY_RM          "c10"
783 #  define ARM_DRAIN_CACHE_WRITE_BUFFER_OPCODE    "0x4"
784 #  define ARM_DRAIN_CACHE_WRITE_BUFFER_RM        "c10"
785 #endif /* __ASSEMBLER__ */
786
787 /*                                               
788  * SA-1100 TLB Operations Definitions             
789  */                                              
790 #ifdef __ASSEMBLER__
791 #  define ARM_FLUSH_INST_DATA_TLB_OPCODE         0x0
792 #  define ARM_FLUSH_INST_DATA_TLB_RM             c7
793 #  define ARM_FLUSH_INST_TLB_OPCODE              0x0
794 #  define ARM_FLUSH_INST_TLB_RM                  c5
795 #  define ARM_FLUSH_DATA_TLB_OPCODE              0x0
796 #  define ARM_FLUSH_DATA_TLB_RM                  c6
797 #  define ARM_FLUSH_DATA_ENTRY_TLB_OPCODE        0x1
798 #  define ARM_FLUSH_DATA_ENTRY_TLB_RM            c6
799 #else /* __ASSEMBLER__ */
800 #  define ARM_FLUSH_INST_DATA_TLB_OPCODE         "0x0"
801 #  define ARM_FLUSH_INST_DATA_TLB_RM             "c7"
802 #  define ARM_FLUSH_INST_TLB_OPCODE              "0x0"
803 #  define ARM_FLUSH_INST_TLB_RM                  "c5"
804 #  define ARM_FLUSH_DATA_TLB_OPCODE              "0x0"
805 #  define ARM_FLUSH_DATA_TLB_RM                  "c6"
806 #  define ARM_FLUSH_DATA_ENTRY_TLB_OPCODE        "0x1"
807 #  define ARM_FLUSH_DATA_ENTRY_TLB_RM            "c6"
808 #endif /* __ASSEMBLER__ */
809
810 /*
811  * SA-1100 Read-Buffer Operations Definitions
812  */
813 #ifdef __ASSEMBLER__
814 #  define ARM_FLUSH_ALL_BUFFERS_OPCODE           0x0
815 #  define ARM_FLUSH_ALL_BUFFERS_RM               c0
816 #  define ARM_FLUSH_BUFFER_0_OPCODE              0x1
817 #  define ARM_FLUSH_BUFFER_0_RM                  c0
818 #  define ARM_FLUSH_BUFFER_1_OPCODE              0x1
819 #  define ARM_FLUSH_BUFFER_1_RM                  c1
820 #  define ARM_FLUSH_BUFFER_2_OPCODE              0x1
821 #  define ARM_FLUSH_BUFFER_2_RM                  c2
822 #  define ARM_FLUSH_BUFFER_3_OPCODE              0x1
823 #  define ARM_FLUSH_BUFFER_3_RM                  c3
824 #  define ARM_LOAD_BUFFER_0_1_WORD_OPCODE        0x2
825 #  define ARM_LOAD_BUFFER_0_1_WORD_RM            c0
826 #  define ARM_LOAD_BUFFER_0_4_WORD_OPCODE        0x2
827 #  define ARM_LOAD_BUFFER_0_4_WORD_RM            c4
828 #  define ARM_LOAD_BUFFER_0_8_WORD_OPCODE        0x2
829 #  define ARM_LOAD_BUFFER_0_8_WORD_RM            c8
830 #  define ARM_LOAD_BUFFER_1_1_WORD_OPCODE        0x2
831 #  define ARM_LOAD_BUFFER_1_1_WORD_RM            c1
832 #  define ARM_LOAD_BUFFER_1_4_WORD_OPCODE        0x2
833 #  define ARM_LOAD_BUFFER_1_4_WORD_RM            c5
834 #  define ARM_LOAD_BUFFER_1_8_WORD_OPCODE        0x2
835 #  define ARM_LOAD_BUFFER_1_8_WORD_RM            c9
836 #  define ARM_LOAD_BUFFER_2_1_WORD_OPCODE        0x2
837 #  define ARM_LOAD_BUFFER_2_1_WORD_RM            c2
838 #  define ARM_LOAD_BUFFER_2_4_WORD_OPCODE        0x2
839 #  define ARM_LOAD_BUFFER_2_4_WORD_RM            c6
840 #  define ARM_LOAD_BUFFER_2_8_WORD_OPCODE        0x2
841 #  define ARM_LOAD_BUFFER_2_8_WORD_RM            cA
842 #  define ARM_LOAD_BUFFER_3_1_WORD_OPCODE        0x2
843 #  define ARM_LOAD_BUFFER_3_1_WORD_RM            c3
844 #  define ARM_LOAD_BUFFER_3_4_WORD_OPCODE        0x2
845 #  define ARM_LOAD_BUFFER_3_4_WORD_RM            c7
846 #  define ARM_LOAD_BUFFER_3_8_WORD_OPCODE        0x2
847 #  define ARM_LOAD_BUFFER_3_8_WORD_RM            cB
848 #  define ARM_DISABLE_USER_MCR_ACCESS_OPCODE     0x4
849 #  define ARM_DISABLE_USER_MCR_ACCESS_RM         c0
850 #  define ARM_ENABLE_USER_MCR_ACCESS_OPCODE      0x5
851 #  define ARM_ENABLE_USER_MCR_ACCESS_RM          c0
852 #else /* __ASSEMBLER__ */
853 #  define ARM_FLUSH_ALL_BUFFERS_OPCODE           "0x0"
854 #  define ARM_FLUSH_ALL_BUFFERS_RM               "c0"
855 #  define ARM_FLUSH_BUFFER_0_OPCODE              "0x1"
856 #  define ARM_FLUSH_BUFFER_0_RM                  "c0"
857 #  define ARM_FLUSH_BUFFER_1_OPCODE              "0x1"
858 #  define ARM_FLUSH_BUFFER_1_RM                  "c1"
859 #  define ARM_FLUSH_BUFFER_2_OPCODE              "0x1"
860 #  define ARM_FLUSH_BUFFER_2_RM                  "c2"
861 #  define ARM_FLUSH_BUFFER_3_OPCODE              "0x1"
862 #  define ARM_FLUSH_BUFFER_3_RM                  "c3"
863 #  define ARM_LOAD_BUFFER_0_1_WORD_OPCODE        "0x2"
864 #  define ARM_LOAD_BUFFER_0_1_WORD_RM            "c0"
865 #  define ARM_LOAD_BUFFER_0_4_WORD_OPCODE        "0x2"
866 #  define ARM_LOAD_BUFFER_0_4_WORD_RM            "c4"
867 #  define ARM_LOAD_BUFFER_0_8_WORD_OPCODE        "0x2"
868 #  define ARM_LOAD_BUFFER_0_8_WORD_RM            "c8"
869 #  define ARM_LOAD_BUFFER_1_1_WORD_OPCODE        "0x2"
870 #  define ARM_LOAD_BUFFER_1_1_WORD_RM            "c1"
871 #  define ARM_LOAD_BUFFER_1_4_WORD_OPCODE        "0x2"
872 #  define ARM_LOAD_BUFFER_1_4_WORD_RM            "c5"
873 #  define ARM_LOAD_BUFFER_1_8_WORD_OPCODE        "0x2"
874 #  define ARM_LOAD_BUFFER_1_8_WORD_RM            "c9"
875 #  define ARM_LOAD_BUFFER_2_1_WORD_OPCODE        "0x2"
876 #  define ARM_LOAD_BUFFER_2_1_WORD_RM            "c2"
877 #  define ARM_LOAD_BUFFER_2_4_WORD_OPCODE        "0x2"
878 #  define ARM_LOAD_BUFFER_2_4_WORD_RM            "c6"
879 #  define ARM_LOAD_BUFFER_2_8_WORD_OPCODE        "0x2"
880 #  define ARM_LOAD_BUFFER_2_8_WORD_RM            "cA"
881 #  define ARM_LOAD_BUFFER_3_1_WORD_OPCODE        "0x2"
882 #  define ARM_LOAD_BUFFER_3_1_WORD_RM            "c3"
883 #  define ARM_LOAD_BUFFER_3_4_WORD_OPCODE        "0x2"
884 #  define ARM_LOAD_BUFFER_3_4_WORD_RM            "c7"
885 #  define ARM_LOAD_BUFFER_3_8_WORD_OPCODE        "0x2"
886 #  define ARM_LOAD_BUFFER_3_8_WORD_RM            "cB"
887 #  define ARM_DISABLE_USER_MCR_ACCESS_OPCODE     "0x4"
888 #  define ARM_DISABLE_USER_MCR_ACCESS_RM         "c0"
889 #  define ARM_ENABLE_USER_MCR_ACCESS_OPCODE      "0x5"
890 #  define ARM_ENABLE_USER_MCR_ACCESS_RM          "c0"
891 #endif /* __ASSEMBLER__ */
892
893 /*
894  * ARM(R) First Level Descriptor Format Definitions
895  */
896 #ifndef __ASSEMBLER__
897 struct ARM_MMU_FIRST_LEVEL_FAULT {
898     int id : 2;
899     int sbz : 30;
900 };
901 #define ARM_MMU_FIRST_LEVEL_FAULT_ID 0x0
902
903 struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE {
904     int id : 2;
905     int imp : 2;
906     int domain : 4;
907     int sbz : 1;
908     int base_address : 23;
909 };
910 #define ARM_MMU_FIRST_LEVEL_PAGE_TABLE_ID 0x1
911
912 struct ARM_MMU_FIRST_LEVEL_SECTION {
913     int id : 2;
914     int b : 1;
915     int c : 1;
916     int imp : 1;
917     int domain : 4;
918     int sbz0 : 1;
919     int ap : 2;
920     int sbz1 : 8;
921     int base_address : 12;
922 };
923 #define ARM_MMU_FIRST_LEVEL_SECTION_ID 0x2
924
925 struct ARM_MMU_FIRST_LEVEL_RESERVED {
926     int id : 2;
927     int sbz : 30;
928 };
929 #define ARM_MMU_FIRST_LEVEL_RESERVED_ID 0x3
930
931 #define ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, table_index) \
932             (unsigned long *)((unsigned long)(ttb_base) + ((table_index) << 2))
933 #define ARM_MMU_SECTION(ttb_base, actual_base, virtual_base, cacheable, bufferable, perm) \
934     {                                                                                     \
935         register union ARM_MMU_FIRST_LEVEL_DESCRIPTOR desc;                               \
936                                                                                           \
937         desc.word = 0;                                                                    \
938         desc.section.id = ARM_MMU_FIRST_LEVEL_SECTION_ID;                                 \
939         desc.section.domain = 0;                                                          \
940         desc.section.c = (cacheable);                                                     \
941         desc.section.b = (bufferable);                                                    \
942         desc.section.ap = (perm);                                                         \
943         desc.section.base_address = (actual_base);                                        \
944         *ARM_MMU_FIRST_LEVEL_DESCRIPTOR_ADDRESS(ttb_base, (virtual_base)) = desc.word;    \
945     }
946
947 union ARM_MMU_FIRST_LEVEL_DESCRIPTOR {
948     unsigned long word;
949     struct ARM_MMU_FIRST_LEVEL_FAULT fault;
950     struct ARM_MMU_FIRST_LEVEL_PAGE_TABLE page_table;
951     struct ARM_MMU_FIRST_LEVEL_SECTION section;
952     struct ARM_MMU_FIRST_LEVEL_RESERVED reserved;
953 };
954
955 #endif /* __ASSEMBLER__ */
956
957 #define ARM_UNCACHEABLE                         0
958 #define ARM_CACHEABLE                           1
959 #define ARM_UNBUFFERABLE                        0
960 #define ARM_BUFFERABLE                          1
961
962 #define ARM_ACCESS_PERM_NONE_NONE               0
963 #define ARM_ACCESS_PERM_RO_NONE                 0
964 #define ARM_ACCESS_PERM_RO_RO                   0
965 #define ARM_ACCESS_PERM_RW_NONE                 1
966 #define ARM_ACCESS_PERM_RW_RO                   2
967 #define ARM_ACCESS_PERM_RW_RW                   3
968
969 #define ARM_SECTION_SIZE                        SZ_1M
970 #define ARM_SMALL_PAGE_SIZE                     SZ_4K
971 #define ARM_LARGE_PAGE_SIZE                     SZ_64K
972
973 #define ARM_FIRST_LEVEL_PAGE_TABLE_SIZE         SZ_16K
974 #define ARM_SECOND_LEVEL_PAGE_TABLE_SIZE        SZ_1K
975
976 #endif /* MMU */
977
978 #endif // __ARM_CPU_H__