make hlt start at 0x2000
[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 #ifndef ROS_KERN_LINKER_FUNC_H
31 #define ROS_KERN_LINKER_FUNC_H
32
33 #define __linkerfunc1  __attribute__((__section__(".linkerfunc1")))
34 #define __linkerfunc2  __attribute__((__section__(".linkerfunc2")))
35 #define __linkerfunc3  __attribute__((__section__(".linkerfunc3")))
36 #define __linkerfunc4  __attribute__((__section__(".linkerfunc4")))
37
38 typedef void (*linker_func_t)(void);
39
40 #define linker_func_1(x)                                                       \
41         void (x)(void);                                                            \
42         linker_func_t __linkerfunc1 __##x = (x);                                   \
43         void (x)(void)
44
45 #define linker_func_2(x)                                                       \
46         void (x)(void);                                                            \
47         linker_func_t __linkerfunc2 __##x = (x);                                   \
48         void (x)(void)
49
50 #define linker_func_3(x)                                                       \
51         void (x)(void);                                                            \
52         linker_func_t __linkerfunc3 __##x = (x);                                   \
53         void (x)(void)
54
55 #define linker_func_4(x)                                                       \
56         void (x)(void);                                                            \
57         linker_func_t __linkerfunc4 __##x = (x);                                   \
58         void (x)(void)
59
60 extern linker_func_t __linkerfunc1start[];
61 extern linker_func_t __linkerfunc1end[];
62 extern linker_func_t __linkerfunc2start[];
63 extern linker_func_t __linkerfunc2end[];
64 extern linker_func_t __linkerfunc3start[];
65 extern linker_func_t __linkerfunc3end[];
66 extern linker_func_t __linkerfunc4start[];
67 extern linker_func_t __linkerfunc4end[];
68
69 #endif /* ROS_KERN_LINKER_FUNC_H */