2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <exec/types.h>
9 #include <exec/memory.h>
10 #include <exec/execbase.h>
11 #include <exec/ptrace.h>
12 #include <proto/exec.h>
15 #include <aros/core.h>
17 #include <asm/registers.h>
21 # include <aros/debug.h>
24 * Build all interrupt assmbly code needed. Derived from i386-native code.
35 static void irqSetup(struct irqDescriptor
*, struct ExecBase
*);
36 static void handle_IRQ_event(unsigned int irq
, struct pt_regs
* regs
, struct irqServer
* is
);
38 BOOL
init_core(struct ExecBase
* SysBase
)
41 SysBase
->PlatformData
= AllocMem(sizeof(struct PlatformData
),
42 MEMF_CLEAR
|MEMF_PUBLIC
);
43 if (NULL
!= SysBase
->PlatformData
) {
46 * Now initialise the PlatformData structure.
48 irqSetup(&PLATFORMDATA(SysBase
)->irq_desc
[0], SysBase
);
50 * Activate the low-level (assembly) interrupt handlers
52 INSTALL_IRQ_HANDLER(IRQ_LEVEL6
, IRQ6_interrupt
);
53 INSTALL_IRQ_HANDLER(IRQ_LEVEL5
, IRQ5_interrupt
);
54 INSTALL_IRQ_HANDLER(IRQ_LEVEL4
, IRQ4_interrupt
);
55 INSTALL_IRQ_HANDLER(IRQ_LEVEL3
, IRQ3_interrupt
);
56 INSTALL_IRQ_HANDLER(IRQ_LEVEL2
, IRQ2_interrupt
);
57 INSTALL_IRQ_HANDLER(IRQ_LEVEL1
, IRQ1_interrupt
);
59 // WREG_L(0x100) = (ULONG)IRQ0_interrupt;
60 WREG_L(0x104) = (ULONG
)IRQ1_interrupt
;
61 WREG_L(0x108) = (ULONG
)IRQ2_interrupt
;
62 WREG_L(0x10c) = (ULONG
)IRQ3_interrupt
;
63 WREG_L(0x110) = (ULONG
)IRQ4_interrupt
;
64 WREG_L(0x114) = (ULONG
)IRQ5_interrupt
;
65 WREG_L(0x118) = (ULONG
)IRQ6_interrupt
;
68 WREG_W(TCMP2
) = 0x411a;
73 static void do_db_IRQ(unsigned int irq
,
75 struct pt_regs
* regs
);
76 static void disable_db_irq(unsigned int irq
);
77 static void enable_db_irq(unsigned int irq
);
79 #define startup_db_irq enable_db_irq
80 #define shutdown_db_irq disable_db_irq
82 static struct irqController db_controller
=
84 "Dragonball", // ic_Name
85 startup_db_irq
, // ic_startup
86 shutdown_db_irq
, // ic_shutdown
87 do_db_IRQ
, // ic_handle
88 enable_db_irq
, // ic_enable
89 disable_db_irq
// ic_disable
94 static void disable_db_irq(unsigned int irq
)
98 static void enable_db_irq(unsigned int virq
)
100 ULONG imr
= RREG_L(IMR
);
102 * On this processor I must clear the flags of those interrupts
103 * that I want to enable.
106 case vHidd_IRQ_Timer
:
110 imr
&= ~(INT0_F
| INT1_F
| INT2_F
| INT3_F
| INT4_F
| INT5_F
| INT6_F
| INT7_F
);
112 case vHidd_IRQ_Serial1
:
115 case vHidd_IRQ_Mouse
:
123 static inline void mask_and_ack_dbirq(unsigned int irq
)
127 static void do_db_IRQ(unsigned int irq
,
129 struct pt_regs
* regs
)
131 struct irqServer
* iServer
;
132 struct irqDescriptor
* desc
= &PLATFORMDATA(SysBase
)->irq_desc
[irq
];
134 // D(bug("In do_db_IRQ(irq=%d,virq=%d)\n",irq,virq));
137 mask_and_ack_dbirq(irq
);
138 status
= desc
->id_status
& ~(IRQ_REPLAY
| IRQ_WAITING
);
140 if (!(status
& (IRQ_DISABLED
| IRQ_INPROGRESS
))) {
141 iServer
= desc
->id_server
;
142 status
|= IRQ_INPROGRESS
;
144 D(bug("IRQ server used!? %p (irq=%d,virq=%d)\n",
149 desc
->id_status
= status
;
152 /* Exit early if we had no action or it was disabled */
154 D(bug("No IRQ handler found!\n"));
157 // D(bug("Handling virq %d in server now!\n",virq));
158 handle_IRQ_event(virq
, regs
, iServer
);
161 unsigned int status
= desc
->id_status
& ~IRQ_INPROGRESS
;
162 desc
->id_status
= status
;
163 if (!(status
& IRQ_DISABLED
))
168 /*******************************************************************************
169 Lowlevel IRQ functions used by each controller
170 *******************************************************************************/
172 static void handle_IRQ_event(unsigned int virq
, struct pt_regs
* regs
, struct irqServer
* is
)
174 ULONG imr
= RREG_L(IMR
);
176 is
->is_handler(virq
, is
->is_UserData
, regs
);
183 * Generic enable/disable code: this just calls
184 * down into the PIC-specific version for the actual
185 * hardware disable after having gotten the irq
188 void disable_irq_nosync(unsigned int irq
)
190 if (!PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_depth
++) {
191 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_status
|= IRQ_DISABLED
;
192 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_handler
->ic_disable(irq
);
197 * Synchronous version of the above, making sure the IRQ is
198 * no longer running on any other IRQ..
200 void disable_irq(unsigned int virq
)
202 disable_db_irq(virq
);
204 disable_irq_nosync(irq
);
208 void enable_irq(unsigned int virq
)
212 struct irqDescriptor
* irq_desc
= PLATFORMDATA(SysBase
)->irq_desc
;
213 switch (irq_desc
[irq
].id_depth
) {
216 irq_desc
[irq
].id_status
&= ~IRQ_DISABLED
;
217 irq_desc
[irq
].id_handler
->ic_enable(virq
);
220 irq_desc
[irq
].id_depth
--;
226 // !!! Move this into include file !!!
227 extern void sys_Dispatch(struct pt_regs
* regs
);
229 * Called from low level assembly code. Handles irq number 'irq'.
231 /*asmlinkage*/ void do_IRQ(struct pt_regs
* regs
, ULONG irq
)
233 BOOL treated
= FALSE
;
234 struct irqDescriptor
* irq_desc
= &PLATFORMDATA(SysBase
)->irq_desc
[irq
];
235 ULONG isr
= RREG_L(ISR
);
238 * Now the problem with this processor is that it multiplexes multiple
239 * interrupt sources over one IRQ. So I demultiplex them here by
240 * looking at the interrupt pending register depending on what irq
244 // D(bug("isr=0x%x,irq=%d\n",isr,irq));
264 volatile UWORD tstat2
;
267 * Leave the following two lines as they are.
269 tstat2
= RREG_W(TSTAT2
);
272 * Explicitly call the dispatcher here to get Multitasking
273 * going. Hm, might maybe want to put this into the chain
276 // D(bug("------------ Task SWITCH!\n"));
278 irq_desc
->id_count
++;
280 irq_desc
->id_handler
->ic_handle(irq
,
281 0, /* -> index of vHidd_IRQ_Timer2 in servers.c */
286 // D(bug("-------------- UART IRQ!\n"));
290 irq_desc
->id_count
++;
291 irq_desc
->id_handler
->ic_handle(irq
,
292 4, /* -> index of vHidd_IRQ_Serial1 in servers.c */
301 /* real time clock */
312 if (isr
& (INT0_F
|INT1_F
|INT2_F
|INT3_F
|INT4_F
|INT5_F
|INT6_F
|INT7_F
)) {
314 D(bug("--------------- Keyboard IRQ!\n"));
317 irq_desc
->id_count
++;
318 irq_desc
->id_handler
->ic_handle(irq
,
319 1, /* -> index of vHidd_IRQ_CustomD */
327 // D(bug("Pen IRQ!\n"));
328 irq_desc
->id_count
++;
329 irq_desc
->id_handler
->ic_handle(irq
,
330 12, /* index of vHidd_IRQ_Mouse in servers.c */
351 * Check for the configurable IRQs here
354 if ((isr
& PWM2_F
) && (irq
== ((ilcr
>> 4) & 0x07))) {
359 if (FALSE
== treated
) {
360 D(bug("Untreated: irq=%d,isr=0x%x\n",irq
,isr
));
364 static void VBL_handler(int i
, void *user
, struct pt_regs
*regs
)
366 if (SysBase
->Elapsed
== 0) {
367 SysBase
->SysFlags
|= 0x2000;
368 SysBase
->AttnResched
|= 0x80;
372 // D(bug("In VBL handler!\n"));
375 static struct irqServer VBlank
= { VBL_handler
, "VBlank", NULL
};
378 static void irqSetup(struct irqDescriptor irq_desc
[], struct ExecBase
* SysBase
)
382 for (i
= 0; i
<NR_IRQS
; i
++) {
383 irq_desc
[i
].id_handler
= &db_controller
;
384 irq_desc
[i
].id_status
= IRQ_DISABLED
;
385 irq_desc
[i
].id_depth
= 0;
386 irq_desc
[i
].id_server
= 0;
389 irqSet(0, &VBlank
, NULL
, SysBase
);
390 irq_desc
[0].id_server
= &VBlank
;
391 irq_desc
[0].id_depth
= 0;
392 irq_desc
[0].id_status
&= ~IRQ_DISABLED
;
393 irq_desc
[0].id_handler
->ic_startup(0);
397 BOOL
irqSet(int irq
, struct irqServer
*is
, void * isd
, struct ExecBase
* SysBase
)
401 struct irqServer
* _is
= AllocMem(sizeof(struct irqServer
),
402 MEMF_PUBLIC
|MEMF_CLEAR
);
405 _is
->is_handler
= is
->is_handler
;
406 _is
->is_name
= is
->is_name
;
407 _is
->is_UserData
= isd
;
408 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_server
= _is
;
409 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_depth
= 0;
410 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_status
&= ~IRQ_DISABLED
;
411 PLATFORMDATA(SysBase
)->irq_desc
[irq
].id_handler
->ic_startup(irq
);
422 LONG
sys_Cause(struct pt_regs
);
423 LONG
sys_Supervisor(struct pt_regs regs
) {return 0;}
424 LONG
sys_None(struct pt_regs regs
) { return 0; }
426 LONG
sys_ColdReboot(struct pt_regs regs
)
428 // __asm__("jmp kernel_startup");
433 LONG (*sys_call_table
[])(struct pt_regs
) =