interrupt.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <interrupt.h>
00036 #include <arch/interrupt.h>
00037 #include <arch/types.h>
00038 #include <arch.h>
00039 #include <arch/cp0.h>
00040 #include <time/clock.h>
00041 #include <arch/drivers/arc.h>
00042 
00043 #include <ipc/sysipc.h>
00044 
00049 ipl_t interrupts_disable(void)
00050 {
00051         ipl_t ipl = (ipl_t) cp0_status_read();
00052         cp0_status_write(ipl & ~cp0_status_ie_enabled_bit);
00053         return ipl;
00054 }
00055 
00060 ipl_t interrupts_enable(void)
00061 {
00062         ipl_t ipl = (ipl_t) cp0_status_read();
00063         cp0_status_write(ipl | cp0_status_ie_enabled_bit);
00064         return ipl;
00065 }
00066 
00071 void interrupts_restore(ipl_t ipl)
00072 {
00073         cp0_status_write(cp0_status_read() | (ipl & cp0_status_ie_enabled_bit));
00074 }
00075 
00080 ipl_t interrupts_read(void)
00081 {
00082         return cp0_status_read();
00083 }
00084 
00085 /* TODO: This is SMP unsafe!!! */
00086 static unsigned long nextcount;
00088 static void timer_start(void)
00089 {
00090         nextcount = cp0_compare_value + cp0_count_read();
00091         cp0_compare_write(nextcount);
00092 }
00093 
00094 static void timer_exception(int n, istate_t *istate)
00095 {
00096         unsigned long drift;
00097 
00098         drift = cp0_count_read() - nextcount;
00099         while (drift > cp0_compare_value) {
00100                 drift -= cp0_compare_value;
00101                 CPU->missed_clock_ticks++;
00102         }
00103         nextcount = cp0_count_read() + cp0_compare_value - drift;
00104         cp0_compare_write(nextcount);
00105         clock();
00106 }
00107 
00108 static void swint0(int n, istate_t *istate)
00109 {
00110         cp0_cause_write(cp0_cause_read() & ~(1 << 8)); /* clear SW0 interrupt */
00111         ipc_irq_send_notif(0);
00112 }
00113 
00114 static void swint1(int n, istate_t *istate)
00115 {
00116         cp0_cause_write(cp0_cause_read() & ~(1 << 9)); /* clear SW1 interrupt */
00117         ipc_irq_send_notif(1);
00118 }
00119 
00120 /* Initialize basic tables for exception dispatching */
00121 void interrupt_init(void)
00122 {
00123         int_register(TIMER_IRQ, "timer", timer_exception);
00124         int_register(0, "swint0", swint0);
00125         int_register(1, "swint1", swint1);
00126         timer_start();
00127 }
00128 
00129 static void ipc_int(int n, istate_t *istate)
00130 {
00131         ipc_irq_send_notif(n-INT_OFFSET);
00132 }
00133 
00134 /* Reregister irq to be IPC-ready */
00135 void irq_ipc_bind_arch(__native irq)
00136 {
00137         /* Do not allow to redefine timer */
00138         /* Swint0, Swint1 are already handled */
00139         if (irq == TIMER_IRQ || irq < 2)
00140                 return;
00141         int_register(irq, "ipc_int", ipc_int);
00142 }
00143 

Generated on Sun Jun 18 17:01:58 2006 for HelenOS Kernel (mips32) by  doxygen 1.4.6