-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreempt.h
60 lines (51 loc) · 1.69 KB
/
preempt.h
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
54
55
56
57
58
#pragma once
#include "util/config.h"
//
// preempt_t : State for your timer/preemption handler
//
// Note:
// We've one instance of core_t per each core.
// To access this instance, you need to use %gs:0
// (The entire kernel doesn't have any global/static variables)
//
// %gs:core_offset_preempt will point to start of preempt_t instance
//
// for example:
// %gs:0 will return pointer to core_t
// %gs:core_offset_mainstack will return core_t::main_stack
// %gs:core_offset_preempt+0 will return core_t::saved_stack
//
// etc.
//
// See Definition of core_t in x86/main.h
//
struct preempt_t{
// your data structure, if any
addr_t saved_stack; //feel free to change it - provided as an example
};
//
//
// This macro is being called from x86/except.cc
//
//
// _name: label name
// _f : C function to be called
// ex: we may have to do send EOI to LAPIC or PIC etc.
//
# define _ring0_preempt(_name,_f) \
__asm( \
" .text \n\t"\
" " STR(_name) ": \n\t"\
" pushl %edx \n\t"\
" pushl %ecx \n\t"\
" pushl %eax \n\t"\
" call " STR(_f) " \n\t"\
" popl %eax \n\t"\
" popl %ecx \n\t"\
" popl %edx \n\t"\
" \n\t"\
" # insert your code here \n\t"\
" \n\t"\
" \n\t"\
" jmp iret_toring0 \n\t"\
) \