forked from olajep/esim-test-bins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swi_num_test.c
53 lines (41 loc) · 1.13 KB
/
swi_num_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdint.h>
void interrupt_handler() __attribute__ ((interrupt)) __attribute__ ((aligned(8)));
void interrupt_handler()
{
static int i = 0;
switch (i)
{
case 0: printf("Hello\n"); break;
case 1: printf("World\n"); break;
case 2: printf("Goodbye\n"); break;
case 3: printf("World\n"); break;
default: printf("Here we go again\n"); break;
}
i++;
}
int main()
{
uint32_t *ivt; // user interrupt vector ptr
uint32_t addr; // relative branch addr
uint32_t br32; // relative addr branch instruction
ivt = (uint32_t *) 0x24;
addr = (uint32_t) &interrupt_handler;
addr -= (uint32_t) ivt; // Adjust for user interrupt branch addr
addr = (addr >> 1); // Lowest bit is skipped (alignment)
br32 = 0xe8;
br32 |= ((addr & (0x00ffffff))) << 8;
*ivt = br32;
/* Loop on exception interrupt */
ivt = (uint32_t *) 4;
*ivt = 0x000000e8;
// clear imask
__asm__("mov r40, 0");
__asm__("movts imask, r40");
/* SWI is software interrupt, but we want user interrupt so write to
* ILATST instead */
//__asm__("swi");
//__asm__("swi 0");
__asm__("swi");
return 0;
}