Merge branch 'master' into isa/arm64
[lunaix-os.git] / lunaix-os / arch / aarch64 / exception / handler.c
1 #include <lunaix/process.h>
2 #include <asm/hart.h>
3 #include <asm/aa64_exception.h>
4
5
6 static inline void
7 update_thread_context(struct hart_state* state)
8 {
9     if (!current_thread) {
10         return;
11     }
12
13     struct hart_state* parent = current_thread->hstate;
14     hart_push_state(parent, state);
15
16     current_thread->hstate = state;
17     current_thread->ustack_top = state->execp.sp_el0;
18
19     if (parent) {
20         state->depth = parent->depth + 1;
21     }
22 }
23
24 extern void 
25 handle_mm_abort(struct hart_state* state);
26
27 static void
28 handle_sync_exception(struct hart_state* hstate)
29 {
30     unsigned int ec;
31
32     ec = esr_ec(hstate->execp.syndrome);
33
34     switch (ec)
35     {
36     case EC_I_ABORT:
37     case EC_D_ABORT:
38     case EC_I_ABORT_EL:
39     case EC_D_ABORT_EL:
40         handle_mm_abort(hstate);
41         break;
42     
43     default:
44         fail("unhandled exception (synced)");
45         break;
46     }
47 }
48
49 static void
50 handle_async_exception(struct hart_state* hstate)
51 {
52
53 }
54
55 struct hart_state*
56 handle_exception(struct hart_state* hstate)
57 {
58     update_thread_context(hstate);
59
60     if (hart_vector_stamp(hstate) == EXCEPTION_SYNC) {
61         handle_sync_exception(hstate);
62     } else {
63         handle_async_exception(hstate);
64     }
65
66     return hstate;
67 }