Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/mips32/src/interrupt.c

    rd99c1d2 r2b698d8  
    3838#include <arch.h>
    3939#include <arch/cp0.h>
     40#include <arch/smp/dorder.h>
    4041#include <time/clock.h>
    4142#include <ipc/sysipc.h>
     
    4849function virtual_timer_fnc = NULL;
    4950static irq_t timer_irq;
     51static irq_t dorder_irq;
     52
     53// TODO: This is SMP unsafe!!!
     54
     55uint32_t count_hi = 0;
     56static unsigned long nextcount;
     57static unsigned long lastcount;
    5058
    5159/** Disable interrupts.
     
    8997}
    9098
    91 /* TODO: This is SMP unsafe!!! */
    92 uint32_t count_hi = 0;
    93 static unsigned long nextcount;
    94 static unsigned long lastcount;
     99/** Check interrupts state.
     100 *
     101 * @return True if interrupts are disabled.
     102 *
     103 */
     104bool interrupts_disabled(void)
     105{
     106        return !(cp0_status_read() & cp0_status_ie_enabled_bit);
     107}
    95108
    96 /** Start hardware clock */
     109/** Start hardware clock
     110 *
     111 */
    97112static void timer_start(void)
    98113{
     
    109124static void timer_irq_handler(irq_t *irq)
    110125{
    111         unsigned long drift;
    112        
    113126        if (cp0_count_read() < lastcount)
    114127                /* Count overflow detected */
    115128                count_hi++;
     129       
    116130        lastcount = cp0_count_read();
    117131       
    118         drift = cp0_count_read() - nextcount;
     132        unsigned long drift = cp0_count_read() - nextcount;
    119133        while (drift > cp0_compare_value) {
    120134                drift -= cp0_compare_value;
    121135                CPU->missed_clock_ticks++;
    122136        }
     137       
    123138        nextcount = cp0_count_read() + cp0_compare_value - drift;
    124139        cp0_compare_write(nextcount);
     
    128143         * Release the lock, call clock() and reacquire the lock again.
    129144         */
    130         spinlock_unlock(&irq->lock);
     145        irq_spinlock_unlock(&irq->lock, false);
    131146        clock();
    132         spinlock_lock(&irq->lock);
     147        irq_spinlock_lock(&irq->lock, false);
    133148       
    134149        if (virtual_timer_fnc != NULL)
    135150                virtual_timer_fnc();
     151}
     152
     153static irq_ownership_t dorder_claim(irq_t *irq)
     154{
     155        return IRQ_ACCEPT;
     156}
     157
     158static void dorder_irq_handler(irq_t *irq)
     159{
     160        dorder_ipi_ack(1 << dorder_cpuid());
    136161}
    137162
     
    150175        timer_start();
    151176        cp0_unmask_int(TIMER_IRQ);
     177       
     178        irq_initialize(&dorder_irq);
     179        dorder_irq.devno = device_assign_devno();
     180        dorder_irq.inr = DORDER_IRQ;
     181        dorder_irq.claim = dorder_claim;
     182        dorder_irq.handler = dorder_irq_handler;
     183        irq_register(&dorder_irq);
     184       
     185        cp0_unmask_int(DORDER_IRQ);
    152186}
    153187
Note: See TracChangeset for help on using the changeset viewer.