瀏覽代碼

Added a generalised table infrastructure, so that we don't have to

keep adding new tables to each architecture's linker scripts.
tags/v0.9.3
Michael Brown 19 年之前
父節點
當前提交
b9c9cee8a3
共有 1 個文件被更改,包括 56 次插入0 次删除
  1. 56
    0
      src/include/tables.h

+ 56
- 0
src/include/tables.h 查看文件

@@ -0,0 +1,56 @@
1
+#ifndef TABLES_H
2
+#define TABLES_H
3
+
4
+/*
5
+ * Macros for dealing with linker-generated tables of fixed-size
6
+ * symbols.  We make fairly extensive use of these in order to avoid
7
+ * ifdef spaghetti and/or linker symbol pollution.  For example,
8
+ * instead of having code such as
9
+ *
10
+ * #ifdef CONSOLE_SERIAL
11
+ *   serial_init();
12
+ * #endif
13
+ *
14
+ * we make serial.c generate an entry in the initialisation function
15
+ * table, and then have a function call_init_fns() that simply calls
16
+ * all functions present in this table.  If and only if serial.o gets
17
+ * linked in, then its initialisation function will be called.  We
18
+ * avoid linker symbol pollution (i.e. always dragging in serial.o
19
+ * just because of a call to serial_init()) and we also avoid ifdef
20
+ * spaghetti (having to conditionalise every reference to functions in
21
+ * serial.c).
22
+ *
23
+ * The linker script takes care of assembling the tables for us.  All
24
+ * our table sections have names of the format ".tbl.NAME.NN" where
25
+ * NAME designates the data structure stored in the table
26
+ * (e.g. "init_fn") and NN is a two-digit decimal number used to
27
+ * impose an ordering upon the tables if required.  NN=00 is reserved
28
+ * for the symbol indicating "table start", and NN=99 is reserved for
29
+ * the symbol indicating "table end".
30
+ *
31
+ * To define an entry in the "xxx" table:
32
+ *
33
+ *  static struct xxx my_xxx __table(xxx,01) = { ... };
34
+ *
35
+ * To access start and end markers for the "xxx" table:
36
+ *
37
+ *  static struct xxx xxx_start[0] __table_start(xxx);
38
+ *  static struct xxx xxx_end[0] __table_end(xxx);
39
+ *
40
+ * See init.h and init.c for an example of how these macros are used
41
+ * in practice.
42
+ *
43
+ */
44
+
45
+#define __table_str(x) #x
46
+#define __table_section(table,idx) \
47
+	__section__ ( ".tbl." __table_str(table) "." __table_str(idx) )
48
+
49
+#define __table_section_start(table) __table_section(table,00)
50
+#define __table_section_end(table) __table_section(table,99)
51
+
52
+#define __table(table,idx) __attribute__ (( __table_section(table,idx) ))
53
+#define __table_start(table) __attribute__ (( __table_section_start(table) ))
54
+#define __table_end(table) __attribute__ (( __table_section_end(table) ))
55
+
56
+#endif /* TABLES_H */

Loading…
取消
儲存