Callisto4Bootloader: test/excep_test.c Source File

Callisto4Bootloader

excep_test.c
Go to the documentation of this file.
1 /******************************************************************************
2 * @file excep_test.c
3 * @brief Test exceptions
4 */
5
6 #include "c4_privilege_modes.h"
7
8 #include "excep_test_configuration.h" // Header file for test case configuration
9 #include "fsl_debug_console.h"
10 //#include <stdio.h>
11 #include <stddef.h>
12
13 extern void undef(void); // Assembly function for the undefined
14 // instruction test
15 typedef uint32_t pointer;
16
17 volatile int i, j = 0; // Variables for the division-by-zero
18
19 // Function written in assembly language, calling an invalid instruction
20 __asm__ (".globl undef\n"
21 "undef:\n\t"
22 // "DCI 0xF123\n\t " // DCI is not an ARM assmebly instruction
23 // "DCI 0x4567\n\t"
24 "BX LR");
25
26
27 // main function containing all the tests
28 int excep_test (void) {
29 SCB->CCR = 0x210; // enable div-by-zero trap in processor core
30
31 #if TESTCASE == 0
32 undef(); // Call undef() function that contains an
33 // invalid instruction
34
35 #elif TESTCASE == 1
36 typedef void (*t_funcPtr)(void);
37 t_funcPtr MyFunc = (t_funcPtr)(0x0001000 | 0x0); // INVSTATE because jumping
38 // to valid address but
39 // thumb bit not set
40 MyFunc();
41
42 #elif TESTCASE == 2
43 i =i/j; // i and j are 0 initialized -> Div/0
44 #endif
45
46 for (;;) {}
47 }
48
49 //*****************************************************************************
50 // Default core exception handlers. Override the ones here by defining your own
51 // handler routines in your application code.
52 //*****************************************************************************
53 void NMI_Handler(void)
54 { while(1) {}
55 }
56
57 void DS_PendSV_Handler(void)
58 { while(1) {}
59 }
60
excep_test_configuration.h
NMI_Handler
void NMI_Handler(void)
Definition: excep_test.c:53
j
volatile int j
Definition: excep_test.c:17
i
volatile int i
Definition: excep_test.c:17
__asm__
__asm__(".globl undef\n" "undef:\n\t" "BX LR")
excep_test
int excep_test(void)
Definition: excep_test.c:28
undef
void undef(void)
pointer
uint32_t pointer
Definition: excep_test.c:15
c4_privilege_modes.h
Provide mechanisms to specify which stack to use and for the processor to operate in Unprivileged mod...
SCB
#define SCB
Definition: core_armv81mml.h:2043
DS_PendSV_Handler
void DS_PendSV_Handler(void)
Definition: excep_test.c:57