added hardware exception vectors
authorkristina <kb@kbs-iMac.local>
Mon, 30 May 2016 13:11:53 +0000 (14:11 +0100)
committerkristina <kb@kbs-iMac.local>
Mon, 30 May 2016 13:11:53 +0000 (14:11 +0100)
start.s
trap.c
vc4_include/common.h [new file with mode: 0755]
vc4_include/cpu.h [new file with mode: 0755]
vc4_include/exception.h [new file with mode: 0755]
vc4_include/hardware.h [new file with mode: 0755]
vc4_include/pcb.h [new file with mode: 0755]

diff --git a/start.s b/start.s
index 8beda47..716e918 100755 (executable)
--- a/start.s
+++ b/start.s
@@ -41,20 +41,21 @@ _start:
        mov r0, cpuid
        mov r5, r0
 
        mov r0, cpuid
        mov r5, r0
 
-       # get addr of the exception vector table
-       lea r1, __INTERRUPT_VECTORS
-       mov r3, r1
+       /* vectors */
+       mov r3, #0x1B000
+       mov r1, r3
 
        /*
         * populate the exception vector table using PC relative labels
         * so the code isnt position dependent
         */
 .macro RegExceptionHandler label, exception_number
 
        /*
         * populate the exception vector table using PC relative labels
         * so the code isnt position dependent
         */
 .macro RegExceptionHandler label, exception_number
-       lea r2, Exc_\label
+       lea r2, fleh_\label
        st r2, (r1)
        add r1, #4
 .endm
 
        st r2, (r1)
        add r1, #4
 .endm
 
+
        RegExceptionHandler zero, #0
        RegExceptionHandler misaligned, #1
        RegExceptionHandler dividebyzero, #2
        RegExceptionHandler zero, #0
        RegExceptionHandler misaligned, #1
        RegExceptionHandler dividebyzero, #2
@@ -71,6 +72,14 @@ _start:
        RegExceptionHandler breakpoint, #13
        RegExceptionHandler unknown, #14
 
        RegExceptionHandler breakpoint, #13
        RegExceptionHandler unknown, #14
 
+       add r1, r3, #252
+       lea r2, fleh_irq
+       mov r4, #492
+
+L_setup_hw_irq:
+       st r2, (r1)++
+       ble r1, r4, L_setup_hw_irq
+
        /*
         * load the interrupt and normal stack pointers. these
         * are chosen to be near the top of the available cache memory
        /*
         * load the interrupt and normal stack pointers. these
         * are chosen to be near the top of the available cache memory
@@ -125,17 +134,30 @@ delayloop2:
  * Exception Handling
  ************************************************************/
 
  * Exception Handling
  ************************************************************/
 
-_sleh_generic_gate:
-       # get faulting PC
-       ld r1, 4(sp)
-       # call the C exception handler
-       b sleh_fatal
+.macro SaveRegsLower 
+       push r0-r5, lr
+.endm
 
 
+.macro SaveRegsUpper
+       push r6-r15
+       push r16-r23
+.endm
+
+.macro SaveRegsAll
+       SaveRegsLower
+       SaveRegsUpper
+.endm
+
+fatal_exception:
+       SaveRegsUpper
+       mov r0, sp
+       b sleh_fatal
 
 .macro ExceptionHandler label, exception_number
 
 .macro ExceptionHandler label, exception_number
-Exc_\label:
-       mov r0, \exception_number
-       b _sleh_generic_gate
+fleh_\label:
+       SaveRegsLower
+       mov r1, \exception_number
+       b fatal_exception
 .endm
 
        ExceptionHandler zero, #0
 .endm
 
        ExceptionHandler zero, #0
@@ -154,12 +176,16 @@ Exc_\label:
        ExceptionHandler breakpoint, #13
        ExceptionHandler unknown, #14
 
        ExceptionHandler breakpoint, #13
        ExceptionHandler unknown, #14
 
-/************************************************************
- * ISRs
- ************************************************************/
+fleh_irq:
+       SaveRegsAll
+
+       /* top of savearea */
+       mov r0, sp
+       bl sleh_irq
 
 
-.align 4
-__INTERRUPT_VECTORS:
-       # 31 slots, 4 byte each for processor exceptions. patched to have the correct
-       # exception handler routines at runtime to allow the code to be loaded anywhere
-       .space 124, 0
+return_from_exception:
+       pop r16-r23
+       pop r6-r15
+       pop r0-r15
+       ld lr, (sp)++
+       rti
diff --git a/trap.c b/trap.c
index 6e5a973..0f3d5ba 100755 (executable)
--- a/trap.c
+++ b/trap.c
@@ -17,30 +17,13 @@ VideoCoreIV second level exception handlers.
 \r
 =============================================================================*/\r
 \r
 \r
 =============================================================================*/\r
 \r
-#include "lib/common.h"\r
-#include "hardware.h"\r
-\r
-/*\r
- * this file in the public release documents all exception names.\r
- * brcm_usrlib\dag\vmcsx\vcfw\rtos\none\rtos_none.c\r
- */\r
-\r
-static const char* g_ExceptionNames[] = {\r
-       "zero",\r
-       "misaligned",\r
-       "divide by zero",\r
-       "undefined instruction",\r
-       "forbidden instruction",\r
-       "illegal memory",\r
-       "bus error",\r
-       "floating point",\r
-       "isp",\r
-       "dummy",\r
-       "icache",\r
-       "vec core",\r
-       "bad l2 alias",\r
-       "breakpoint"\r
-};\r
+#include <common.h>\r
+#include <pcb.h>\r
+#include <exception.h>\r
+#include <hardware.h>\r
+#include <cpu.h>\r
+\r
+static const char* g_ExceptionNames[] = { VC4_EXC_NAMES };\r
 \r
 static const char* exception_name(uint32_t n) {\r
        if (n >= (sizeof(g_ExceptionNames)/4))\r
 \r
 static const char* exception_name(uint32_t n) {\r
        if (n >= (sizeof(g_ExceptionNames)/4))\r
@@ -48,6 +31,58 @@ static const char* exception_name(uint32_t n) {
        return g_ExceptionNames[n];\r
 }\r
 \r
        return g_ExceptionNames[n];\r
 }\r
 \r
-void sleh_fatal(uint32_t n, uint32_t pc) {\r
-       panic("fatal processor exception: %s (%d) at 0x%0x", exception_name(n), n, pc);\r
+#define REGISTER_FORMAT_STRING(prefix) \\r
+       prefix "  r0: 0x%08x  r1: 0x%08x  r2: 0x%08x  r3: 0x%08x\n" \\r
+       prefix "  r4: 0x%08x  r5: 0x%08x  r6: 0x%08x  r7: 0x%08x\n" \\r
+       prefix "  r8: 0x%08x  r9: 0x%08x r10: 0x%08x r11: 0x%08x\n" \\r
+       prefix " r12: 0x%08x r13: 0x%08x r14: 0x%08x r15: 0x%08x\n" \\r
+       prefix "  pc: 0x%08x  lr: 0x%08x  sr: 0x%08x\n"\r
+\r
+void sleh_fatal(vc4_saved_state_t* pcb, uint32_t n) {\r
+       printf("Fatal VPU Exception: %s\n", exception_name(n));\r
+\r
+       printf("VPU registers:\n");\r
+\r
+       printf(\r
+               REGISTER_FORMAT_STRING("   "),\r
+               pcb->r0,\r
+               pcb->r1,\r
+               pcb->r2,\r
+               pcb->r3,\r
+               pcb->r4,\r
+               pcb->r5,\r
+               pcb->r6,\r
+               pcb->r7,\r
+               pcb->r8,\r
+               pcb->r9, \r
+               pcb->r10,\r
+               pcb->r11,\r
+               pcb->r12,\r
+               pcb->r13,\r
+               pcb->r14,\r
+               pcb->r15,\r
+               pcb->pc,\r
+               pcb->lr,\r
+               pcb->sr\r
+       );\r
+\r
+       printf("Exception info:\n");\r
+\r
+       printf(\r
+               "   src0: 0x%08x src1: 0x%08x vaddr: 0x%08x\n"\r
+               "      C: 0x%08x    S: 0x%08x\n",\r
+               IC0_SRC0,\r
+               IC0_SRC1,\r
+               IC0_VADDR,\r
+               IC0_C,\r
+               IC0_S\r
+       );\r
+\r
+       printf("We are hanging here ...\n");\r
+       \r
+       hang_cpu();\r
+}\r
+\r
+void sleh_irq(vc4_saved_state_t* pcb) {\r
+       panic("interrupt at 0x%X!", pcb->pc);\r
 }
\ No newline at end of file
 }
\ No newline at end of file
diff --git a/vc4_include/common.h b/vc4_include/common.h
new file mode 100755 (executable)
index 0000000..706d153
--- /dev/null
@@ -0,0 +1,61 @@
+#pragma once\r
+\r
+#include "../lib/stdarg.h"\r
+\r
+typedef unsigned long long u64;\r
+typedef unsigned long long uint64_t;\r
+typedef long long int64_t;\r
+\r
+typedef unsigned int u32;\r
+typedef unsigned int uint32_t;\r
+typedef int int32_t;\r
+\r
+typedef unsigned short u16;\r
+typedef unsigned short uint16_t;\r
+typedef short int16_t;\r
+\r
+typedef unsigned char u8;\r
+typedef unsigned char uint8_t;\r
+\r
+typedef int bool;\r
+\r
+#define true 1\r
+#define false 0\r
+\r
+#define NULL ((void*)0)\r
+\r
+typedef uint32_t size_t;\r
+\r
+# define ALWAYS_INLINE __attribute__((always_inline)) inline\r
+\r
+extern void panic(const char* fmt,  ...)\r
+       __attribute__((noreturn))\r
+       __attribute__ ((format (printf, 1, 2)));\r
+\r
+#define panic_plain(ex, ...) \\r
+       (panic)(ex, ## __VA_ARGS__)\r
+#define __STRINGIFY(x) #x\r
+#define LINE_NUMBER(x) __STRINGIFY(x)\r
+#define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__)\r
+#define panic(ex, ...) \\r
+       (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__)\r
+\r
+#define _OPEN_SOURCE\r
+\r
+extern void udelay(uint32_t time);\r
+extern uint32_t __div64_32(uint64_t *n, uint32_t base);\r
+\r
+#define do_div __div64_32\r
+\r
+/*\r
+ * this is done like that because clang likes using __builtin_memcpy\r
+ * which makes LLC choke in a fabulous way.\r
+ */\r
+extern void *__memcpy(void *_dst, const void *_src, unsigned len);\r
+#define bcopy(s,d,l) __memcpy(d,s,l)\r
+#define memcpy(d,s,l) __memcpy(d,s,l)\r
+\r
+extern int putchar(int c);\r
+extern int vprintf(const char* fmt, va_list arp);\r
+extern int printf(const char *fmt, ...);\r
+extern int puts(const char* str);
\ No newline at end of file
diff --git a/vc4_include/cpu.h b/vc4_include/cpu.h
new file mode 100755 (executable)
index 0000000..5e08568
--- /dev/null
@@ -0,0 +1,16 @@
+#pragma once\r
+\r
+#include <hardware.h>\r
+\r
+static inline void __attribute__((noreturn)) hang_cpu() {\r
+       /* disable interrupts and enter WFI state */\r
+       __asm__ __volatile__ (\r
+               "di\n"\r
+               "sleep\n"\r
+       );\r
+\r
+       /* in case the above fails */\r
+       for (;;) {\r
+               __asm__ __volatile__ ("nop");\r
+       }\r
+}
\ No newline at end of file
diff --git a/vc4_include/exception.h b/vc4_include/exception.h
new file mode 100755 (executable)
index 0000000..210ebf0
--- /dev/null
@@ -0,0 +1,54 @@
+/*=============================================================================\r
+Copyright (C) 2016 Kristina Brooks\r
+All rights reserved.\r
+\r
+This program is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU General Public License\r
+as published by the Free Software Foundation; either version 2\r
+of the License, or (at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+FILE DESCRIPTION\r
+VideoCore4 exceptions.\r
+\r
+This file in the public release documents all exception names:\r
+       brcm_usrlib\dag\vmcsx\vcfw\rtos\none\rtos_none.c\r
+\r
+=============================================================================*/\r
+\r
+#pragma once\r
+\r
+#define VC4_EXC_ZERO 0\r
+#define VC4_EXC_MISALIGNED 1\r
+#define VC4_EXC_DIVIDE_BY_ZERO 2\r
+#define VC4_EXC_UNDEF 3\r
+#define VC4_EXC_FORBIDDEN 4\r
+#define VC4_EXC_ILLEGAL_MEM 5\r
+#define VC4_EXC_BUS_ERROR 6\r
+#define VC4_EXC_FPE 7\r
+#define VC4_EXC_ISP 8\r
+#define VC4_EXC_DUMMY 9\r
+#define VC4_EXC_ICACHE 10\r
+#define VC4_EXC_VEC_CORE 11\r
+#define VC4_EXC_L2_ALIAS 12\r
+#define VC4_EXC_BKPT 13\r
+\r
+#define VC4_EXC_NAMES \\r
+       "Zero", \\r
+       "Misaligned", \\r
+       "Division by zero", \\r
+       "Undefined instruction", \\r
+       "Forbidden instruction", \\r
+       "Illegal memory", \\r
+       "Bus error", \\r
+       "Floating point exception", \\r
+       "ISP", \\r
+       "Dummy", \\r
+       "ICache", \\r
+       "Vector core exception", \\r
+       "Bad L2 alias", \\r
+       "Breakpoint"\r
diff --git a/vc4_include/hardware.h b/vc4_include/hardware.h
new file mode 100755 (executable)
index 0000000..98f19d4
--- /dev/null
@@ -0,0 +1,3 @@
+/* glue */\r
+#pragma once\r
+#include "../hardware.h"
\ No newline at end of file
diff --git a/vc4_include/pcb.h b/vc4_include/pcb.h
new file mode 100755 (executable)
index 0000000..06f08eb
--- /dev/null
@@ -0,0 +1,55 @@
+/*=============================================================================\r
+Copyright (C) 2016 Kristina Brooks\r
+All rights reserved.\r
+\r
+This program is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU General Public License\r
+as published by the Free Software Foundation; either version 2\r
+of the License, or (at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+FILE DESCRIPTION\r
+Process control block.\r
+\r
+=============================================================================*/\r
+\r
+#pragma once\r
+\r
+#include <common.h>\r
+\r
+typedef struct {\r
+       uint32_t r23;\r
+       uint32_t r22;\r
+       uint32_t r21;\r
+       uint32_t r20;\r
+       uint32_t r19;\r
+       uint32_t r18;\r
+       uint32_t r17;\r
+       uint32_t r16;\r
+       uint32_t r15;\r
+       uint32_t r14;\r
+       uint32_t r13;\r
+       uint32_t r12;\r
+       uint32_t r11;\r
+       uint32_t r10;\r
+       uint32_t r9;\r
+       uint32_t r8;\r
+       uint32_t r7;\r
+       uint32_t r6;\r
+\r
+       uint32_t r5;\r
+       uint32_t r4;\r
+       uint32_t r3;\r
+       uint32_t r2;\r
+       uint32_t r1;\r
+       uint32_t r0;\r
+\r
+       uint32_t lr;\r
+\r
+       uint32_t sr;\r
+       uint32_t pc;\r
+} vc4_saved_state_t;
\ No newline at end of file
This page took 0.042955 seconds and 4 git commands to generate.