callback addr as u32 not a void ptr
[my-code/arm.git] / betty / interrupts.c
1 /*
2  * interrupts.c - arm exception handling
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "interrupts.h"
9
10 /*
11  * module static interrupt variable
12  */
13
14 static t_interrupt interrupt;
15
16 /*
17  * functions
18  */
19
20 void interrupt_init(void) {
21
22         memset(&interrupt,0,sizeof(t_interrupt));
23         VICSoftIntClear=0xff;
24         VICIntEnClear=0xff;
25         VICDefVectAddr=0;
26 }
27
28 void interrupt_set_default_callback(u32 callback_addr) {
29
30         VICDefVectAddr=callback_addr;
31 }
32
33 void interrupt_set_soft_callback(void (*callback)(void)) {
34
35         interrupt->default_soft_callback=callback;
36 }
37
38 void interrupt_soft_clear(u8 src_number) {
39
40         VICSoftIntClear=(1<<src_number);
41 }
42 void interrupt_clear(u8 src_number) {
43
44         int cnt;
45         u32 *addr;
46         u32 *cntl;
47
48         VICIntEnClear=(1<<src_number);
49         VICIntSelect&=~(1<<src_number);
50
51         addr=&VICVectAddr0;
52         cntl=&VICVectCntl0;
53
54         for(cnt=0;cnt<INTERRUPT_MAX_VIC;cnt++) {
55                 if(cntl[cnt]&0x1f==src_number) {
56                         *((volatile u32 *)(addr+cnt))=0;
57                         *((volatile u32 *)(cntl+cnt))=0;
58                 }
59         }
60 }
61
62 void interrupt_soft_enable(u8 src_number) {
63         
64         VICSoftInt=(1<<src_number);
65 }
66
67 int interrupt_enable(u8 src_number,u8 mode,u8 priority,u32 callback_addr) {
68
69         u32 *addr;
70         u32 *cntl;
71
72         addr=&VICVectAddr0;
73         cntl=&VICVectCntl0;
74
75         /* check whether this ir source is allready assigned */
76         if(VICIntEnable&(1<<src_number))
77                 return INTERRUPT_USED;
78
79         /* force interrupt */
80         VICIntEnable=(1<<src_number);
81
82         switch(mode) {
83                 case INTERRUPT_FIQ:
84                         VICIntSelect|=(1<<src_number);
85                         break;
86                 case INTERRUPT_VIRQ:
87                         if(addr[p]&0x3f)
88                                 return INTERRUP_PRIORITY_USED;
89                         *((volatile u32 *)(addr+p))=callback_addr;
90                         *((volatile u32 *)(cntl+p))=src_number&0x1f+(1<<5);
91                 case INTERRUPT_IRQ:
92                 case default:
93         }
94
95         return INTERRUPT_SET;
96 }
97
98 /*
99  * the actual exception handlers (as defined in startup.s)
100  */
101
102 // reset
103 void interrupt_handler_reset(void) {
104 }
105
106 // undefined instruction
107 void interrupt_handler_undef_instruction(void) {
108 }
109
110 // software interrupt
111 void interrupt_handler_soft_ir(void) {
112         
113         if(interrupt.default_soft_callback)
114                 interrupt.default_soft_callback();
115 }
116
117 // prefetch abort
118 void interrupt_handler_prefetch_abort(void) {
119 }
120
121 // data abort
122 void interrupt_handler_data_abort(void) {
123 }
124
125 // fiq
126 void interrupt_handler_fiq(void) {
127 }
128