summaryrefslogtreecommitdiffstats
path: root/arch/nds32/include/asm/bitfield.h
blob: c1619730192adf8a854666b6f5bafec87c2f3cdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2005-2017 Andes Technology Corporation

#ifndef __NDS32_BITFIELD_H__
#define __NDS32_BITFIELD_H__
/******************************************************************************
 * cr0: CPU_VER (CPU Version Register)
 *****************************************************************************/
#define CPU_VER_offCFGID	0	/* Minor configuration */
#define CPU_VER_offREV		16	/* Revision of the CPU version */
#define CPU_VER_offCPUID	24	/* Major CPU versions */

#define CPU_VER_mskCFGID	( 0xFFFF  << CPU_VER_offCFGID )
#define CPU_VER_mskREV		( 0xFF  << CPU_VER_offREV )
#define CPU_VER_mskCPUID	( 0xFF  << CPU_VER_offCPUID )

/******************************************************************************
 * cr1: ICM_CFG (Instruction Cache/Memory Configuration Register)
 *****************************************************************************/
#define ICM_CFG_offISET		0	/* I-cache sets (# of cache lines) per way */
#define ICM_CFG_offIWAY		3	/* I-cache ways */
#define ICM_CFG_offISZ		6	/* I-cache line size */
#define ICM_CFG_offILCK		9	/* I-cache locking support */
#define ICM_CFG_offILMB		10	/* On-chip ILM banks */
#define ICM_CFG_offBSAV		13	/* ILM base register alignment version */
/* bit 15:31 reserved */

#define ICM_CFG_mskISET		( 0x7  << ICM_CFG_offISET )
#define ICM_CFG_mskIWAY		( 0x7  << ICM_CFG_offIWAY )
#define ICM_CFG_mskISZ		( 0x7  << ICM_CFG_offISZ )
#define ICM_CFG_mskILCK		( 0x1  << ICM_CFG_offILCK )
#define ICM_CFG_mskILMB		( 0x7  << ICM_CFG_offILMB )
#define ICM_CFG_mskBSAV		( 0x3  << ICM_CFG_offBSAV )

/******************************************************************************
 * cr2: DCM_CFG (Data Cache/Memory Configuration Register)
 *****************************************************************************/
#define DCM_CFG_offDSET		0	/* D-cache sets (# of cache lines) per way */
#define DCM_CFG_offDWAY		3	/* D-cache ways */
#define DCM_CFG_offDSZ		6	/* D-cache line size */
#define DCM_CFG_offDLCK		9	/* D-cache locking support */
#define DCM_CFG_offDLMB		10	/* On-chip DLM banks */
#define DCM_CFG_offBSAV		13	/* DLM base register alignment version */
/* bit 15:31 reserved */

#define DCM_CFG_mskDSET		( 0x7  << DCM_CFG_offDSET )
#define DCM_CFG_mskDWAY		( 0x7  << DCM_CFG_offDWAY )
#define DCM_CFG_mskDSZ		( 0x7  << DCM_CFG_offDSZ )
#define DCM_CFG_mskDLCK		( 0x1  << DCM_CFG_offDLCK )
#define DCM_CFG_mskDLMB		( 0x7  << DCM_CFG_offDLMB )
#define DCM_CFG_mskBSAV		( 0x3  << DCM_CFG_offBSAV )

/******************************************************************************
 * cr3: MMU_CFG (MMU Configuration Register)
 *****************************************************************************/
#define MMU_CFG_offMMPS		0	/* Memory management protection scheme */
#define MMU_CFG_offMMPV		2	/* Memory management protection version number */
#define MMU_CFG_offFATB		7	/* Fully-associative or non-fully-associative TLB */

#define MMU_CFG_offTBW		8	/* TLB ways(non-associative) TBS */
#define MMU_CFG_offTBS		11	/* TLB sets per way(non-associative) TBS */
/* bit 14:14 reserved */

#define MMU_CFG_offEP8MIN4	15	/* 8KB page supported while minimum page is 4KB */
#define MMU_CFG_offfEPSZ	16	/* Extra page size supported */
#define MMU_CFG_offTLBLCK	24	/* TLB locking support */
#define MMU_CFG_offHPTWK	25	/* Hardware Page Table Walker implemented */
#define MMU_CFG_offDE		26	/* Default endian */
#define MMU_CFG_offNTPT		27	/* Partitions for non-translated attributes */
#define MMU_CFG_offIVTB		28	/* Invisible TLB */
#define MMU_CFG_offVLPT		29	/* VLPT for fast TLB fill handling implemented */
#define MMU_CFG_offNTME		30	/* Non-translated VA to PA mapping */
/* bit 31 reserved */

#define MMU_CFG_mskMMPS		( 0x3  << MMU_CFG_offMMPS )
#define MMU_CFG_mskMMPV		( 0x1F  << MMU_CFG_offMMPV )
#define MMU_CFG_mskFATB		( 0x1  << MMU_CFG_offFATB )
#define MMU_CFG_mskTBW		( 0x7  << MMU_CFG_offTBW )
#define MMU_CFG_mskTBS		( 0x7  << MMU_CFG_offTBS )
#define MMU_CFG_mskEP8MIN4	( 0x1  << MMU_CFG_offEP8MIN4 )
#define MMU_CFG_mskfEPSZ	( 0xFF  << MMU_CFG_offfEPSZ )
#define MMU_CFG_mskTLBLCK	( 0x1  << MMU_CFG_offTLBLCK )
#define MMU_CFG_mskHPTWK	( 0x1  << MMU_CFG_offHPTWK )
#define MMU_CFG_mskDE		( 0x1  << MMU_CFG_offDE )
#define MMU_CFG_mskNTPT		( 0x1  << MMU_CFG_offNTPT )
#define MMU_CFG_mskIVTB		( 0x1  << MMU_CFG_offIVTB )
#define MMU_CFG_mskVLPT		( 0x1  << MMU_CFG_offVLPT )
#define MMU_CFG_mskNTME		( 0x1  << MMU_CFG_offNTME )

/******************************************************************************
 * cr4: MSC_CFG (Misc Configuration Register)
 *****************************************************************************/
#define MSC_CFG_offEDM		0
#define MSC_CFG_offLMDMA	1
#define MSC_CFG_offPFM		2
#define MSC_CFG_offHSMP		3
#define MSC_CFG_offTRACE	4
#define MSC_CFG_offDIV		5
#define MSC_CFG_offMAC		6
#define MSC_CFG_offAUDIO	7
#define MSC_CFG_offL2C		9
#define MSC_CFG_offRDREG	10
#define MSC_CFG_offADR24	11
#define MSC_CFG_offINTLC	12
#define MSC_CFG_offBASEV	13
#define MSC_CFG_offNOD		16
/* bit 13:31 reserved */

#define MSC_CFG_mskEDM		( 0x1  << MSC_CFG_offEDM )
#define MSC_CFG_mskLMDMA	( 0x1  << MSC_CFG_offLMDMA )
#define MSC_CFG_mskPFM		( 0x1  << MSC_CFG_offPFM )
#define MSC_CFG_mskHSMP		( 0x1  << MSC_CFG_offHSMP )
#define MSC_CFG_mskTRACE	( 0x1  << MSC_CFG_offTRACE )
#define MSC_CFG_mskDIV		( 0x1  << MSC_CFG_offDIV )
#define MSC_CFG_mskMAC		( 0x1  << MSC_CFG_offMAC )
#define MSC_CFG_mskAUDIO	( 0x3  << MSC_CFG_offAUDIO )
#define MSC_CFG_mskL2C		( 0x1  << MSC_CFG_offL2C )
#define MSC_CFG_mskRDREG	( 0x1  << MSC_CFG_offRDREG )
#define MSC_CFG_mskADR24	( 0x1  << MSC_CFG_offADR24 )
#define MSC_CFG_mskINTLC	( 0x1  << MSC_CFG_offINTLC )
#define MSC_CFG_mskBASEV	( 0x7  << MSC_CFG_offBASEV )
#define MSC_CFG_mskNOD		( 0x1  << MSC_CFG_offNOD )

/******************************************************************************
 * cr5: CORE_CFG (Core Identification Register)
 *****************************************************************************/
#define CORE_ID_offCOREID	0
/* bit 4:31 reserved */

#define CORE_ID_mskCOREID	( 0xF  << CORE_ID_offCOREID )

/******************************************************************************
 * cr6: FUCOP_EXIST (FPU and Coprocessor Existence Configuration Register)
 *****************************************************************************/
#define FUCOP_EXIST_offCP0EX	0
#define FUCOP_EXIST_offCP1EX	1
#define FUCOP_EXIST_offCP2EX	2
#define FUCOP_EXIST_offCP3EX	3
#define FUCOP_EXIST_offCP0ISFPU	31

#define FUCOP_EXIST_mskCP0EX	( 0x1  << FUCOP_EXIST_offCP0EX )
#define FUCOP_EXIST_mskCP1EX	( 0x1  << FUCOP_EXIST_offCP1EX )
#define FUCOP_EXIST_mskCP2EX	( 0x1  << FUCOP_EXIST_offCP2EX )
#define FUCOP_EXIST_mskCP3EX	( 0x1  << FUCOP_EXIST_offCP3EX )
#define FUCOP_EXIST_mskCP0ISFPU	( 0x1  << FUCOP_EXIST_offCP0ISFPU )

/******************************************************************************
 * ir0: PSW (Processor Status Word Register)
 * ir1: IPSW (Interruption PSW Register)
 * ir2: P_IPSW (Previous IPSW Register)
 *****************************************************************************/
#define PSW_offGIE		0	/* Global Interrupt Enable */
#define PSW_offINTL		1	/* Interruption Stack Level */
#define PSW_offPOM		3	/* Processor Operation Mode, User/Superuser */
#define PSW_offBE		5	/* Endianness for data memory access, 1:MSB, 0:LSB */
#define PSW_offIT		6	/* Enable instruction address translation */
#define PSW_offDT		7	/* Enable data address translation */
#define PSW_offIME		8	/* Instruction Machine Error flag */
#define PSW_offDME		9	/* Data Machine Error flag */
#define PSW_offDEX		10	/* Debug Exception */
#define PSW_offHSS		11	/* Hardware Single Stepping */
#define PSW_offDRBE		12	/* Device Register Endian Mode */
#define PSW_offAEN		13	/* Audio ISA special feature */
#define PSW_offWBNA		14	/* Write Back Non-Allocate */
#define PSW_offIFCON		15	/* IFC On */
#define PSW_offCPL		16	/* Current Priority Level */
/* bit 19:31 reserved */

#define PSW_mskGIE		( 0x1  << PSW_offGIE )
#define PSW_mskINTL		( 0x3  << PSW_offINTL )
#define PSW_mskPOM		( 0x3  << PSW_offPOM )
#define PSW_mskBE		( 0x1  << PSW_offBE )
#define PSW_mskIT		( 0x1  << PSW_offIT )
#define PSW_mskDT		( 0x1  << PSW_offDT )
#define PSW_mskIME		( 0x1  << PSW_offIME )
#define PSW_mskDME		( 0x1  << PSW_offDME )
#define PSW_mskDEX		( 0x1  << PSW_offDEX )
#define PSW_mskHSS		( 0x1  << PSW_offHSS )
#define PSW_mskDRBE		( 0x1  << PSW_offDRBE )
#define PSW_mskAEN		( 0x1  << PSW_offAEN )
#define PSW_mskWBNA		( 0x1  << PSW_offWBNA )
#define PSW_mskIFCON		( 0x1  << PSW_offIFCON )
#define PSW_mskCPL		( 0x7  << PSW_offCPL )

#define PSW_SYSTEM		( 1 << PSW_offPOM )
#define PSW_INTL_1		( 1 << PSW_offINTL )
#define PSW_CPL_NO		( 0 << PSW_offCPL )
#define PSW_CPL_ANY		( 7 << PSW_offCPL )

#define PSW_clr			(PSW_mskGIE|PSW_mskINTL|PSW_mskPOM|PSW_mskIT|PSW_mskDT|PSW_mskIME|PSW_mskWBNA)
#ifdef __NDS32_EB__
#ifdef CONFIG_WBNA
#define PSW_init		(PSW_mskWBNA|(1<<PSW_offINTL)|(1<<PSW_offPOM)|PSW_mskIT|PSW_mskDT|PSW_mskBE)
#else
#define PSW_init		((1<<PSW_offINTL)|(1<<PSW_offPOM)|PSW_mskIT|PSW_mskDT|PSW_mskBE)
#endif
#else
#ifdef CONFIG_WBNA
#define PSW_init		(PSW_mskWBNA|(1<<PSW_offINTL)|(1<<PSW_offPOM)|PSW_mskIT|PSW_mskDT)
#else
#define PSW_init		((1<<PSW_offINTL)|(1<<PSW_offPOM)|PSW_mskIT|PSW_mskDT)
#endif
#endif
/******************************************************************************
 * ir3: IVB (Interruption Vector Base Register)
 *****************************************************************************/
/* bit 0:12 reserved */
#define IVB_offNIVIC		1	/* Number of input for IVIC Controller */
#define IVB_offIVIC_VER		11	/* IVIC Version */
#define IVB_offEVIC		13	/* External Vector Interrupt Controller mode */
#define IVB_offESZ		14	/* Size of each vector entry */
#define IVB_offIVBASE		16	/* BasePA of interrupt vector table */

#define IVB_mskNIVIC		( 0x7  << IVB_offNIVIC )
#define IVB_mskIVIC_VER		( 0x3  << IVB_offIVIC_VER )
#define IVB_mskEVIC		( 0x1  << IVB_offEVIC )
#define IVB_mskESZ		( 0x3  << IVB_offESZ )
#define IVB_mskIVBASE		( 0xFFFF  << IVB_offIVBASE )

#define IVB_valESZ4		0
#define IVB_valESZ16		1
#define IVB_valESZ64		2
#define IVB_valESZ256		3
/******************************************************************************
 * ir4: EVA (Exception Virtual Address Register)
 * ir5: P_EVA (Previous EVA Register)
 *****************************************************************************/

	/* This register contains the VA that causes the exception */

/******************************************************************************
 * ir6: ITYPE (Interruption Type Register)
 * ir7: P_ITYPE (Previous ITYPE Register)
 *****************************************************************************/
#define ITYPE_offETYPE		0	/* Exception Type */
#define ITYPE_offINST		4	/* Exception caused by insn fetch or data access */
/* bit 5:15 reserved */
#define ITYPE_offVECTOR		5	/* Vector */
#define ITYPE_offSWID		16	/* SWID of debugging exception */
/* bit 31:31 reserved */

#define ITYPE_mskETYPE		( 0xF  << ITYPE_offETYPE )
#define ITYPE_mskINST		( 0x1  << ITYPE_offINST )
#define ITYPE_mskVECTOR		( 0x7F  << ITYPE_offVECTOR )
#define ITYPE_mskSWID		( 0x7FFF  << ITYPE_offSWID )

/* Additional definitions for ITYPE register */
#define ITYPE_offSTYPE          16	/* Arithmetic Sub Type */
#define ITYPE_offCPID           20	/* Co-Processor ID which generate the exception */

#define ITYPE_mskSTYPE		( 0xF  << ITYPE_offSTYPE )
#define ITYPE_mskCPID		( 0x3  << ITYPE_offCPID )

/* Additional definitions of ITYPE register for FPU */
#define FPU_DISABLE_EXCEPTION	(0x1  << ITYPE_offSTYPE)
#define FPU_EXCEPTION		(0x2  << ITYPE_offSTYPE)
#define FPU_CPID		0	/* FPU Co-Processor ID is 0 */

#define NDS32_VECTOR_mskNONEXCEPTION	0x78
#define NDS32_VECTOR_offEXCEPTION	8
#define NDS32_VECTOR_offINTERRUPT	9

/* Interrupt vector entry */
#define ENTRY_RESET_NMI			0
#define ENTRY_TLB_FILL			1
#define ENTRY_PTE_NOT_PRESENT		2
#define ENTRY_TLB_MISC			3
#define ENTRY_TLB_VLPT_MISS		4
#define ENTRY_MACHINE_ERROR		5
#define ENTRY_DEBUG_RELATED		6
#define ENTRY_GENERAL_EXCPETION		7
#define ENTRY_SYSCALL			8

/* PTE not present exception definition */
#define ETYPE_NON_LEAF_PTE_NOT_PRESENT	0
#define ETYPE_LEAF_PTE_NOT_PRESENT	1

/* General exception ETYPE definition */
#define ETYPE_ALIGNMENT_CHECK		0
#define ETYPE_RESERVED_INSTRUCTION	1
#define ETYPE_TRAP			2
#define ETYPE_ARITHMETIC		3
#define ETYPE_PRECISE_BUS_ERROR		4
#define ETYPE_IMPRECISE_BUS_ERROR	5
#define ETYPE_COPROCESSOR		6
#define ETYPE_RESERVED_VALUE		7
#define ETYPE_NONEXISTENT_MEM_ADDRESS	8
#define ETYPE_MPZIU_CONTROL		9
#define ETYPE_NEXT_PRECISE_STACK_OFL	10

/* Kerenl reserves software ID */
#define SWID_RAISE_INTERRUPT_LEVEL	0x1a	/* SWID_RAISE_INTERRUPT_LEVEL is used to
						 * raise interrupt level for debug exception
						 */

/******************************************************************************
 * ir8: MERR (Machine Error Log Register)
 *****************************************************************************/
/* bit 0:30 reserved */
#define MERR_offBUSERR		31	/* Bus error caused by a load insn */

#define MERR_mskBUSERR		( 0x1  << MERR_offBUSERR )

/******************************************************************************
 * ir9: IPC (Interruption Program Counter Register)
 * ir10: P_IPC (Previous IPC Register)
 * ir11: OIPC (Overflow Interruption Program Counter Register)
 *****************************************************************************/

	/* This is the shadow stack register of the Program Counter */

/******************************************************************************
 * ir12: P_P0 (Previous P0 Register)
 * ir13: P_P1 (Previous P1 Register)
 *****************************************************************************/

	/* These are shadow registers of $p0 and $p1 */

/******************************************************************************
 * ir14: INT_MASK (Interruption Masking Register)
 *****************************************************************************/
#define INT_MASK_offH0IM	0	/* Hardware Interrupt 0 Mask bit */
#define INT_MASK_offH1IM	1	/* Hardware Interrupt 1 Mask bit */
#define INT_MASK_offH2IM	2	/* Hardware Interrupt 2 Mask bit */
#define INT_MASK_offH3IM	3	/* Hardware Interrupt 3 Mask bit */
#define INT_MASK_offH4IM	4	/* Hardware Interrupt 4 Mask bit */
#define INT_MASK_offH5IM	5	/* Hardware Interrupt 5 Mask b