alarm: Force unset_alarm to grab the CV lock
[akaros.git] / kern / include / linker_func.h
1 /* Copyright (c) 2014 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Linker functions.  These are functions of type void func(void) that are
6  * automatically run during the kernel initialization.
7  *
8  * There are different levels; the functions of lower levels are run before
9  * higher levels.  There is no guarantee of ordering of functions within a
10  * level.
11  *
12  * To use, change your function definition to use the appropriate macro, e.g.
13  *
14  *              void foo(void)
15  *              {
16  *                      bar();
17  *              }
18  *
19  * becomes
20  *
21  *              linker_func_3(foo)
22  *              {
23  *                      bar();
24  *              }
25  *
26  * And foo() will run during the third level of functions.
27  *
28  * For now, all levels are run sequentially, and with interrupts enabled. */
29
30 #pragma once
31
32 #define __linkerfunc1  __attribute__((__section__(".linkerfunc1")))
33 #define __linkerfunc2  __attribute__((__section__(".linkerfunc2")))
34 #define __linkerfunc3  __attribute__((__section__(".linkerfunc3")))
35 #define __linkerfunc4  __attribute__((__section__(".linkerfunc4")))
36
37 typedef void (*linker_func_t)(void);
38
39 #define linker_func_1(x)                                                       \
40         void (x)(void);                                                            \
41         linker_func_t __linkerfunc1 __##x = (x);                                   \
42         void (x)(void)
43
44 #define linker_func_2(x)                                                       \
45         void (x)(void);                                                            \
46         linker_func_t __linkerfunc2 __##x = (x);                                   \
47         void (x)(void)
48
49 #define linker_func_3(x)                                                       \
50         void (x)(void);                                                            \
51         linker_func_t __linkerfunc3 __##x = (x);                                   \
52         void (x)(void)
53
54 #define linker_func_4(x)                                                       \
55         void (x)(void);                                                            \
56         linker_func_t __linkerfunc4 __##x = (x);                                   \
57         void (x)(void)
58
59 extern linker_func_t __linkerfunc1start[];
60 extern linker_func_t __linkerfunc1end[];
61 extern linker_func_t __linkerfunc2start[];
62 extern linker_func_t __linkerfunc2end[];
63 extern linker_func_t __linkerfunc3start[];
64 extern linker_func_t __linkerfunc3end[];
65 extern linker_func_t __linkerfunc4start[];
66 extern linker_func_t __linkerfunc4end[];