-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterrupt.c
45 lines (40 loc) · 1.11 KB
/
interrupt.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
//******************************************************************************
// Copyright (c) 2018, The Regents of the University of California (Regents).
// All Rights Reserved. See LICENSE for license details.
//------------------------------------------------------------------------------
#include "regs.h"
#include "sbi.h"
#include "timex.h"
#include "interrupt.h"
#include "printf.h"
#include <asm/csr.h>
#define DEFAULT_CLOCK_DELAY 10000
void init_timer(void)
{
sbi_set_timer(get_cycles64() + DEFAULT_CLOCK_DELAY);
csr_set(sstatus, SR_SPIE);
csr_set(sie, SIE_STIE | SIE_SSIE);
}
void handle_timer_interrupt()
{
sbi_stop_enclave(0);
unsigned long next_cycle = get_cycles64() + DEFAULT_CLOCK_DELAY;
sbi_set_timer(next_cycle);
csr_set(sstatus, SR_SPIE);
return;
}
void handle_interrupts(struct encl_ctx* regs)
{
unsigned long cause = regs->scause;
switch(cause) {
case INTERRUPT_CAUSE_TIMER:
handle_timer_interrupt();
break;
/* ignore other interrupts */
case INTERRUPT_CAUSE_SOFTWARE:
case INTERRUPT_CAUSE_EXTERNAL:
default:
sbi_stop_enclave(0);
return;
}
}