summaryrefslogtreecommitdiff
path: root/gcc/config/nds32/nds32_isr.h
blob: 3d6a72f5be10806649b0c7f7e69c8a602c8cc70c (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
/* Intrinsic definitions of Andes NDS32 cpu for GNU compiler
   Copyright (C) 2012-2021 Free Software Foundation, Inc.
   Contributed by Andes Technology Corporation.

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published
   by the Free Software Foundation; either version 3, or (at your
   option) any later version.

   GCC is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.

   Under Section 7 of GPL version 3, you are granted additional
   permissions described in the GCC Runtime Library Exception, version
   3.1, as published by the Free Software Foundation.

   You should have received a copy of the GNU General Public License and
   a copy of the GCC Runtime Library Exception along with this program;
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
   <http://www.gnu.org/licenses/>.  */

#ifndef _NDS32_ISR_H
#define _NDS32_ISR_H

/* Attribute of a interrupt or exception handler:

   NDS32_READY_NESTED: This handler is interruptible if user re-enable GIE bit.
   NDS32_NESTED      : This handler is interruptible.  This is not suitable
                       exception handler.
   NDS32_NOT_NESTED  : This handler is NOT interruptible.  Users have to do
                       some work if nested is wanted
   NDS32_CRITICAL    : This handler is critical ISR, which means it is small
                       and efficient.  */
#define NDS32_READY_NESTED   0
#define NDS32_NESTED         1
#define NDS32_NOT_NESTED     2
#define NDS32_CRITICAL       3

/* Attribute of a interrupt or exception handler:

   NDS32_SAVE_ALL_REGS    : Save all registers in a table.
   NDS32_SAVE_PARTIAL_REGS: Save partial registers.  */
#define NDS32_SAVE_CALLER_REGS   0
#define NDS32_SAVE_ALL_REGS      1

/* There are two version of Register table for interrupt and exception handler,
   one for 16-register CPU the other for 32-register CPU.  These structures are
   used for context switching or system call handling.  The address of this
   data can be get from the input argument of the handler functions.

   For system call handling, r0 to r5 are used to pass arguments.  If more
   arguments are used they are put into the stack and its starting address is
   in sp.  Return value of system call can be put into r0 and r1 upon exit from
   system call handler.  System call ID is in a system register and it can be
   fetched via intrinsic function.  For more information please read ABI and
   other related documents.

   For context switching, at least 2 values need to saved in kernel.  One is
   IPC and the other is the stack address of current task.  Use intrinsic
   function to get IPC and  the input argument of the handler functions + 8 to
   get stack address of current task.  To do context switching, you replace
   new_sp with the stack address of new task and replace IPC system register
   with IPC of new task, then, just return from handler.  The context switching
   will happen.  */

/* Register table for exception handler; 32-register version.  */
typedef struct
{
  int r0;
  int r1;
  int r2;
  int r3;
  int r4;
  int r5;
  int r6;
  int r7;
  int r8;
  int r9;
  int r10;
  int r11;
  int r12;
  int r13;
  int r14;
  int r15;
  int r16;
  int r17;
  int r18;
  int r19;
  int r20;
  int r21;
  int r22;
  int r23;
  int r24;
  int r25;
  int r26;
  int r27;
  int fp;
  int gp;
  int lp;
  int sp;
} NDS32_GPR32;

/* Register table for exception handler; 16-register version.  */
typedef struct
{
  int r0;
  int r1;
  int r2;
  int r3;
  int r4;
  int r5;
  int r6;
  int r7;
  int r8;
  int r9;
  int r10;
  int r15;
  int fp;
  int gp;
  int lp;
  int sp;
} NDS32_GPR16;


/* Use NDS32_REG32_TAB or NDS32_REG16_TAB in your program to
   access register table.  */
typedef struct
{
  union
    {
      int          reg_a[32] ;
      NDS32_GPR32  reg_s ;
    } u ;
} NDS32_REG32_TAB;

typedef struct
{
  union
    {
      int          reg_a[16] ;
      NDS32_GPR16  reg_s ;
    } u ;
} NDS32_REG16_TAB;

typedef struct
{
  int    d0lo;
  int    d0hi;
  int    d1lo;
  int    d1hi;
} NDS32_DX_TAB;

typedef struct
{
#ifdef __NDS32_EB__
  float    fsr0;
  float    fsr1;
  float    fsr2;
  float    fsr3;
  float    fsr4;
  float    fsr5;
  float    fsr6;
  float    fsr7;
#else
  float    fsr1;
  float    fsr0;
  float    fsr3;
  float    fsr2;
  float    fsr5;
  float    fsr4;
  float    fsr7;
  float    fsr6;
#endif
} NDS32_FSR8;

typedef struct
{
  double   dsr0;
  double   dsr1;
  double   dsr2;
  double   dsr3;
} NDS32_DSR4;

typedef struct
{
#ifdef __NDS32_EB__
  float    fsr0;
  float    fsr1;
  float    fsr2;
  float    fsr3;
  float    fsr4;
  float    fsr5;
  float    fsr6;
  float    fsr7;
  float    fsr8;
  float    fsr9;
  float    fsr10;
  float    fsr11;
  float    fsr12;
  float    fsr13;
  float    fsr14;
  float    fsr15;
#else
  float    fsr1;
  float    fsr0;
  float    fsr3;
  float    fsr2;
  float    fsr5;
  float    fsr4;
  float    fsr7;
  float    fsr6;
  float    fsr9;
  float    fsr8;
  float    fsr11;
  float    fsr10;
  float    fsr13;
  float    fsr12;
  float    fsr15;
  float    fsr14;
#endif
} NDS32_FSR16;

typedef struct
{
  double   dsr0;
  double   dsr1;
  double   dsr2;
  double   dsr3;
  double   dsr4;
  double   dsr5;
  double   dsr6;
  double   dsr7;
} NDS32_DSR8;

typedef struct
{
#ifdef __NDS32_EB__
  float    fsr0;
  float    fsr1;
  float    fsr2;
  float    fsr3;
  float    fsr4;
  float    fsr5;
  float    fsr6;
  float    fsr7;
  float    fsr8;
  float    fsr9;
  float    fsr10;
  float    fsr11;
  float    fsr12;
  float    fsr13;
  float    fsr14;
  float    fsr15;
  float    fsr16;
  float    fsr17;
  float    fsr18;
  float    fsr19;
  float    fsr20;
  float    fsr21;
  float    fsr22;
  float    fsr23;
  float    fsr24;
  float    fsr25;
  float    fsr26;
  float    fsr27;
  float    fsr28;
  float    fsr29;
  float    fsr30;
  float    fsr31;
#else
  float    fsr1;
  float    fsr0;
  float    fsr3;
  float    fsr2;
  float    fsr5;
  float    fsr4;
  float    fsr7;
  float    fsr6;
  float    fsr9;
  float    fsr8;
  float    fsr11;
  float    fsr10;
  float    fsr13;
  float    fsr12;
  float    fsr15;
  float    fsr14;
  float    fsr17;
  float    fsr16;
  float    fsr19;
  float    fsr18;
  float    fsr21;
  float    fsr20;
  float    fsr23;
  float    fsr22;
  float    fsr25;
  float    fsr24;
  float    fsr27;
  float    fsr26;
  float    fsr29;
  float    fsr28;
  float    fsr31;
  float    fsr30;
#endif
} NDS32_FSR32;

typedef struct
{
  double   dsr0;
  double   dsr1;
  double   dsr2;
  double   dsr3;
  double   dsr4;
  double   dsr5;
  double   dsr6;
  double   dsr7;
  double   dsr8;
  double   dsr9;
  double   dsr10;
  double   dsr11;
  double   dsr12;
  double   dsr13;
  double   dsr14;
  double   dsr15;
} NDS32_DSR16;

typedef struct
{
  double   dsr0;
  double   dsr1;
  double   dsr2;
  double   dsr3;
  double   dsr4;
  double   dsr5;
  double   dsr6;
  double   dsr7;
  double   dsr8;
  double   dsr9;
  double   dsr10;
  double   dsr11;
  double   dsr12;
  double   dsr13;
  double   dsr14;
  double   dsr15;
  double   dsr16;
  double   dsr17;
  double   dsr18;
  double   dsr19;
  double   dsr20;
  double   dsr21;
  double   dsr22;
  double   dsr23;
  double   dsr24;
  double   dsr25;
  double   dsr26;
  double   dsr27;
  double   dsr28;
  double   dsr29;
  double   dsr30;
  double   dsr31;
} NDS32_DSR32;

typedef struct
{
  union
    {
      NDS32_FSR8   fsr_s ;
      NDS32_DSR4   dsr_s ;
    } u ;
} NDS32_FPU8_TAB;

typedef struct
{
  union
    {
      NDS32_FSR16  fsr_s ;
      NDS32_DSR8   dsr_s ;
    } u ;
} NDS32_FPU16_TAB;

typedef struct
{
  union
    {
      NDS32_FSR32  fsr_s ;
      NDS32_DSR16  dsr_s ;
    } u ;
} NDS32_FPU32_TAB;

typedef struct
{
  union
    {
      NDS32_FSR32  fsr_s ;
      NDS32_DSR32  dsr_s ;
    } u ;
} NDS32_FPU64_TAB;

typedef struct
{
  int    ipc;
  int    ipsw;
#if defined(NDS32_EXT_FPU_CONFIG_0)
  NDS32_FPU8_TAB fpr;
#elif defined(NDS32_EXT_FPU_CONFIG_1)
  NDS32_FPU16_TAB fpr;
#elif defined(NDS32_EXT_FPU_CONFIG_2)
  NDS32_FPU32_TAB fpr;
#elif defined(NDS32_EXT_FPU_CONFIG_3)
  NDS32_FPU64_TAB fpr;
#endif
#if __NDS32_DX_REGS__
  NDS32_DX_TAB dxr;
#endif
#if __NDS32_EXT_IFC__
  int    ifc_lp;
  int    filler;
#endif
#if __NDS32_REDUCED_REGS__ || __NDS32_REDUCE_REGS
  NDS32_REG16_TAB gpr;
#else
  NDS32_REG32_TAB gpr;
#endif
} NDS32_CONTEXT;

/* Predefined Vector Definition.

   For IVIC Mode: 9 to 14 are for hardware interrupt
                  and 15 is for software interrupt.
   For EVIC Mode: 9 to 72 are for hardware interrupt
                  and software interrupt can be routed to any one of them.

   You may want to define your hardware interrupts in the following way
   for easy maintainance.

     IVIC mode:
       #define MY_HW_IVIC_TIMER NDS32_VECTOR_INTERRUPT_HW0 + 1
       #define MY_HW_IVIC_USB   NDS32_VECTOR_INTERRUPT_HW0 + 3
     EVIC mode:
     #define MY_HW_EVIC_DMA   NDS32_VECTOR_INTERRUPT_HW0 + 2
     #define MY_HW_EVIC_SWI   NDS32_VECTOR_INTERRUPT_HW0 + 10 */
#define NDS32_VECTOR_RESET               0
#define NDS32_VECTOR_TLB_FILL            1
#define NDS32_VECTOR_PTE_NOT_PRESENT     2
#define NDS32_VECTOR_TLB_MISC            3
#define NDS32_VECTOR_TLB_VLPT_MISS       4
#define NDS32_VECTOR_MACHINE_ERROR       5
#define NDS32_VECTOR_DEBUG_RELATED       6
#define NDS32_VECTOR_GENERAL_EXCEPTION   7
#define NDS32_VECTOR_SYSCALL             8
#define NDS32_VECTOR_INTERRUPT_HW0       9
#define NDS32_VECTOR_INTERRUPT_HW1       10
#define NDS32_VECTOR_INTERRUPT_HW2       11
#define NDS32_VECTOR_INTERRUPT_HW3       12
#define NDS32_VECTOR_INTERRUPT_HW4       13
#define NDS32_VECTOR_INTERRUPT_HW5       14
#define NDS32_VECTOR_INTERRUPT_HW6       15
#define NDS32_VECTOR_SWI                 15  /* THIS IS FOR IVIC MODE ONLY */
#define NDS32_VECTOR_INTERRUPT_HW7       16
#define NDS32_VECTOR_INTERRUPT_HW8       17
#define NDS32_VECTOR_INTERRUPT_HW9       18
#define NDS32_VECTOR_INTERRUPT_HW10      19
#define NDS32_VECTOR_INTERRUPT_HW11      20
#define NDS32_VECTOR_INTERRUPT_HW12      21
#define NDS32_VECTOR_INTERRUPT_HW13      22
#define NDS32_VECTOR_INTERRUPT_HW14      23
#define NDS32_VECTOR_INTERRUPT_HW15      24
#define NDS32_VECTOR_INTERRUPT_HW16      25
#define NDS32_VECTOR_INTERRUPT_HW17      26
#define NDS32_VECTOR_INTERRUPT_HW18      27
#define NDS32_VECTOR_INTERRUPT_HW19      28
#define NDS32_VECTOR_INTERRUPT_HW20      29
#define NDS32_VECTOR_INTERRUPT_HW21      30
#define NDS32_VECTOR_INTERRUPT_HW22      31
#define NDS32_VECTOR_INTERRUPT_HW23      32
#define NDS32_VECTOR_INTERRUPT_HW24      33
#define NDS32_VECTOR_INTERRUPT_HW25      34
#define NDS32_VECTOR_INTERRUPT_HW26      35
#define NDS32_VECTOR_INTERRUPT_HW27      36
#define NDS32_VECTOR_INTERRUPT_HW28      37
#define NDS32_VECTOR_INTERRUPT_HW29      38
#define NDS32_VECTOR_INTERRUPT_HW30      39
#define NDS32_VECTOR_INTERRUPT_HW31      40
#define NDS32_VECTOR_INTERRUPT_HW32      41
#define NDS32_VECTOR_INTERRUPT_HW33      42
#define NDS32_VECTOR_INTERRUPT_HW34      43
#define NDS32_VECTOR_INTERRUPT_HW35      44
#define NDS32_VECTOR_INTERRUPT_HW36      45
#define NDS32_VECTOR_INTERRUPT_HW37      46
#define NDS32_VECTOR_INTERRUPT_HW38      47
#define NDS32_VECTOR_INTERRUPT_HW39      48
#define NDS32_VECTOR_INTERRUPT_HW40      49
#define NDS32_VECTOR_INTERRUPT_HW41      50
#define NDS32_VECTOR_INTERRUPT_HW42      51
#define NDS32_VECTOR_INTERRUPT_HW43      52
#define NDS32_VECTOR_INTERRUPT_HW44      53
#define NDS32_VECTOR_INTERRUPT_HW45      54
#define NDS32_VECTOR_INTERRUPT_HW46      55
#define NDS32_VECTOR_INTERRUPT_HW47      56
#define NDS32_VECTOR_INTERRUPT_HW48      57
#define NDS32_VECTOR_INTERRUPT_HW49      58
#define NDS32_VECTOR_INTERRUPT_HW50      59
#define NDS32_VECTOR_INTERRUPT_HW51      60
#define NDS32_VECTOR_INTERRUPT_HW52      61
#define NDS32_VECTOR_INTERRUPT_HW53      62
#define NDS32_VECTOR_INTERRUPT_HW54      63
#define NDS32_VECTOR_INTERRUPT_HW55      64
#define NDS32_VECTOR_INTERRUPT_HW56      65
#define NDS32_VECTOR_INTERRUPT_HW57      66
#define NDS32_VECTOR_INTERRUPT_HW58      67
#define NDS32_VECTOR_INTERRUPT_HW59      68
#define NDS32_VECTOR_INTERRUPT_HW60      69
#define NDS32_VECTOR_INTERRUPT_HW61      70
#define NDS32_VECTOR_INTERRUPT_HW62      71
#define NDS32_VECTOR_INTERRUPT_HW63      72

#define NDS32ATTR_RESET(option)          __attribute__((reset(option)))
#define NDS32ATTR_EXCEPT(type)           __attribute__((exception(type)))
#define NDS32ATTR_EXCEPTION(type)        __attribute__((exception(type)))
#define NDS32ATTR_INTERRUPT(type)        __attribute__((interrupt(type)))
#define NDS32ATTR_ISR(type)              __attribute__((interrupt(type)))

#endif /* nds32_isr.h */