source: trunk/libs/newlib/src/libgloss/sparc_leon/catch_interrupt.c @ 511

Last change on this file since 511 was 444, checked in by satin@…, 7 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2011 Aeroflex Gaisler
3 *
4 * BSD license:
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25
26#include <asm-leon/leonstack.h>
27#include <asm-leon/irq.h>
28#define NULL 0
29struct irqaction *_irqtbl[32] =
30  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
310, 0, 0, 0, 0, 0, 0 };
32struct irqaction _oirqtbl[32] =
33  { INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
34  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
35  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
36  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
37  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
38  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
39  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION,
40  INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION, INIT_IRQACTION
41};
42
43int
44catch_interrupt (int func, int irq)
45{
46  struct irqaction *a = _irqtbl[irq];
47  struct irqaction *n = &_oirqtbl[irq];
48  if (irq >= 32)
49    return 0;
50
51  while (a)
52    {
53      if (a == n)
54        {
55          int tmp = (int) a->handler;
56          a->handler = (irqhandler) func;
57          return tmp;
58        }
59      a = a->next;
60    }
61  n->handler = (irqhandler) func;
62  chained_catch_interrupt (irq, n);
63  return 0;
64}
65
66void
67chained_catch_interrupt (int irq, struct irqaction *a)
68{
69  a->next = _irqtbl[irq];
70  _irqtbl[irq] = a;
71}
72
73int no_inirq_check = 0;
74int inirq[32] = { 0, 0, 0, 0, 0, 0, 0, 0,
75  0, 0, 0, 0, 0, 0, 0, 0,
76  0, 0, 0, 0, 0, 0, 0, 0,
77  0, 0, 0, 0, 0, 0, 0, 0
78};
79extern struct irqmp_type irqmp;
80
81void (*handler_irq_pre) (void) = 0;
82void (*handler_irq_post) (void) = 0;
83handler_irq (int irq, struct leonbare_pt_regs *pt_regs)
84{
85  struct irqaction *a;
86
87  if (irq == irqmp.eirq)
88    irq = irqmp.addr[48] & 0x1f;
89  if (!irq)
90    irq = irqmp.eirq;
91
92  a = _irqtbl[irq];
93
94  while (a)
95    {
96      if (a->handler)
97        {
98#ifndef CONFIG_LEONBARE_NONESTEDIRQ
99          if (no_inirq_check || !(inirq[irq]))
100            {
101#endif
102              inirq[irq]++;
103              if (handler_irq_pre)
104                handler_irq_pre ();
105              a->handler (irq, a->dev_id, pt_regs);
106              if (handler_irq_post)
107                handler_irq_post ();
108              inirq[irq]--;
109#ifndef CONFIG_LEONBARE_NONESTEDIRQ
110            }
111#endif
112        }
113      a = a->next;
114    }
115}
116
117schedulehandler schedule_callback = 0;
Note: See TracBrowser for help on using the repository browser.