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