2010-09-22 15:10:42 +02:00
|
|
|
/* Copyright (C) 2005, 2006, 2007, 2008 by Thomas Hillebrandt and Heiko Will
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-08-16 10:20:23 +02:00
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
|
|
|
|
#include "VIC.h"
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#define IRQ_MASK 0x00000080
|
|
|
|
#define FIQ_MASK 0x00000040
|
|
|
|
#define INT_MASK (IRQ_MASK | FIQ_MASK)
|
|
|
|
|
|
|
|
static inline unsigned __get_cpsr(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned long retval;
|
2016-03-14 14:28:00 +01:00
|
|
|
__asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */);
|
2013-06-21 03:52:57 +02:00
|
|
|
return retval;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
int irq_is_in(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
int retval;
|
2016-03-14 14:28:00 +01:00
|
|
|
__asm__ volatile(" mrs %0, cpsr" : "=r"(retval) : /* no inputs */);
|
2013-06-21 03:52:57 +02:00
|
|
|
return (retval & INTMode) == 18;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __set_cpsr(unsigned val)
|
|
|
|
{
|
2016-03-14 14:28:00 +01:00
|
|
|
__asm__ volatile(" msr cpsr, %0" : /* no outputs */ : "r"(val));
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned irq_disable(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr | IRQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned irq_restore(unsigned oldCPSR)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned IRQenabled(void)
|
|
|
|
{
|
2013-06-07 17:21:11 +02:00
|
|
|
unsigned _cpsr;
|
|
|
|
|
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
return (_cpsr & IRQ_MASK);
|
|
|
|
}
|
|
|
|
|
2016-03-19 09:25:47 +01:00
|
|
|
unsigned irq_enable(void)
|
2010-09-22 15:10:42 +02:00
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr & ~IRQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned disableFIQ(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr | FIQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned restoreFIQ(unsigned oldCPSR)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr((_cpsr & ~FIQ_MASK) | (oldCPSR & FIQ_MASK));
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned enableFIQ(void)
|
|
|
|
{
|
2013-06-21 03:52:57 +02:00
|
|
|
unsigned _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-06-21 03:52:57 +02:00
|
|
|
_cpsr = __get_cpsr();
|
|
|
|
__set_cpsr(_cpsr & ~FIQ_MASK);
|
|
|
|
return _cpsr;
|
2010-09-22 15:10:42 +02:00
|
|
|
}
|