summaryrefslogtreecommitdiffstats
path: root/firmware/target/mips/ingenic_x1000/system-x1000.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/system-x1000.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/system-x1000.c80
1 files changed, 35 insertions, 45 deletions
diff --git a/firmware/target/mips/ingenic_x1000/system-x1000.c b/firmware/target/mips/ingenic_x1000/system-x1000.c
index 33d8db7222..64890a6c3a 100644
--- a/firmware/target/mips/ingenic_x1000/system-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/system-x1000.c
@@ -27,6 +27,7 @@
#include "dma-x1000.h"
#include "irq-x1000.h"
#include "clk-x1000.h"
+#include "boot-x1000.h"
#include "x1000/cpm.h"
#include "x1000/ost.h"
#include "x1000/tcu.h"
@@ -43,6 +44,7 @@ uint32_t __cpu_idle_reftick = 0;
#endif
/* Prepare the CPU to process interrupts, but don't enable them yet */
+static void system_init_irq(void) INIT_ATTR;
static void system_init_irq(void)
{
/* Mask all interrupts */
@@ -59,6 +61,26 @@ static void system_init_irq(void)
write_c0_cause(M_CauseIV);
}
+/* First function called by crt0.S */
+void system_early_init(void)
+{
+#if defined(FIIO_M3K) && !defined(BOOTLOADER)
+ /* HACK for compatibility: CPM scratchpad has undefined contents at
+ * time of reset and old bootloader revisions don't initialize it.
+ * Therefore we can't rely on its contents on the FiiO M3K. This does
+ * kind of break the entire point of boot flags, but right now they
+ * are really only used by the bootloader so it's not a huge issue.
+ * This hack should keep everything working as usual. */
+ if(jz_readf(CPM_MPCR, ON) == 0) {
+ init_boot_flags();
+ set_boot_flag(BOOT_FLAG_CLK_INIT);
+ }
+#endif
+
+ /* Finish up clock init */
+ clk_init();
+}
+
/* First thing called from Rockbox main() */
void system_init(void)
{
@@ -191,6 +213,8 @@ static void UIRQ(void)
}
#define intr(name) extern __attribute__((weak, alias("UIRQ"))) void name(void)
+/* DWC2 USB interrupt */
+#define OTG INT_USB_FUNC
/* Main interrupts */
intr(DMIC); intr(AIC); intr(SFC); intr(SSI0); intr(OTG); intr(AES);
@@ -231,7 +255,7 @@ intr(OST);
#undef intr
-static void(*const irqvector[])(void) = {
+static void(*irqvector[])(void) = {
/* ICSR0: 0 - 31 */
DMIC, AIC, UIRQ, UIRQ, UIRQ, UIRQ, UIRQ, SFC,
SSI0, UIRQ, PDMA, PDMAD, UIRQ, UIRQ, UIRQ, UIRQ,
@@ -261,6 +285,13 @@ static void(*const irqvector[])(void) = {
GPIOD00, GPIOD01, GPIOD02, GPIOD03, GPIOD04, GPIOD05,
};
+irq_handler_t system_set_irq_handler(int irq, irq_handler_t handler)
+{
+ irq_handler_t old_handler = irqvector[irq];
+ irqvector[irq] = handler;
+ return old_handler;
+}
+
void system_enable_irq(int irq)
{
if(IRQ_IS_GROUP0(irq)) {
@@ -313,8 +344,10 @@ static int vector_irq(void)
return n;
}
-void intr_handler(unsigned cause)
+void intr_handler(void)
{
+ unsigned long cause = read_c0_cause();
+
/* OST interrupt is handled separately */
if(cause & M_CauseIP3) {
OST();
@@ -333,49 +366,6 @@ void intr_handler(unsigned cause)
irqvector[irq]();
}
-void tlb_refill_handler(void)
-{
- panicf("TLB refill handler at 0x%08lx! [0x%x]",
- read_c0_epc(), read_c0_badvaddr());
-}
-
-#define EXC(x,y) case (x): return (y);
-static char* parse_exception(unsigned cause)
-{
- switch(cause & M_CauseExcCode)
- {
- EXC(EXC_INT, "Interrupt");
- EXC(EXC_MOD, "TLB Modified");
- EXC(EXC_TLBL, "TLB Exception (Load or Ifetch)");
- EXC(EXC_ADEL, "Address Error (Load or Ifetch)");
- EXC(EXC_ADES, "Address Error (Store)");
- EXC(EXC_TLBS, "TLB Exception (Store)");
- EXC(EXC_IBE, "Instruction Bus Error");
- EXC(EXC_DBE, "Data Bus Error");
- EXC(EXC_SYS, "Syscall");
- EXC(EXC_BP, "Breakpoint");
- EXC(EXC_RI, "Reserved Instruction");
- EXC(EXC_CPU, "Coprocessor Unusable");
- EXC(EXC_OV, "Overflow");
- EXC(EXC_TR, "Trap Instruction");
- EXC(EXC_FPE, "Floating Point Exception");
- EXC(EXC_C2E, "COP2 Exception");
- EXC(EXC_MDMX, "MDMX Exception");
- EXC(EXC_WATCH, "Watch Exception");
- EXC(EXC_MCHECK, "Machine Check Exception");
- EXC(EXC_CacheErr, "Cache error caused re-entry to Debug Mode");
- default:
- return 0;
- }
-}
-#undef EXC
-
-void exception_handler(unsigned cause, unsigned epc, unsigned stack_ptr)
-{
- panicf("Exception occurred: %s [0x%08x] at 0x%08x (stack at 0x%08x)",
- parse_exception(cause), read_c0_badvaddr(), epc, stack_ptr);
-}
-
void system_exception_wait(void)
{
#ifdef FIIO_M3K