Merge branch 'master' into isa/arm64
[lunaix-os.git] / lunaix-os / arch / x86 / arch.c
1 #include <hal/hwtimer.h>
2
3 #include <asm-generic/isrm.h>
4 #include <lunaix/spike.h>
5 #include <lunaix/process.h>
6
7 #include "asm/x86.h"
8 #include "asm/hart.h"
9
10 #include "hal/apic_timer.h"
11
12 void
13 exception_init()
14 {
15     exception_install_handler();
16     isrm_init();
17     intr_routine_init();
18 }
19
20 extern void
21 syscall_hndlr(const struct hart_state* hstate);
22
23 void
24 arch_preinit()
25 {
26     exception_init();
27
28     isrm_bindiv(LUNAIX_SYS_CALL, syscall_hndlr);
29 }
30
31 struct hwtimer*
32 select_platform_timer()
33 {
34     struct hwtimer* timer;
35
36     timer = apic_hwtimer_context();
37     if (timer->supported(timer)) {
38         return timer;
39     }
40
41     // TODO select alternatives...
42
43     fail("no timer to use.");
44 }
45
46 void
47 update_tss()
48 {
49     extern struct x86_tss _tss;
50 #ifdef CONFIG_ARCH_X86_64
51     _tss.rsps[0] = (ptr_t)current_thread->hstate;
52 #else
53     _tss.esp0 = (u32_t)current_thread->hstate;
54 #endif
55 }