Przeglądaj źródła

Added post-relocation function table.

tags/v0.9.3
Michael Brown 19 lat temu
rodzic
commit
f06e8c9707

+ 20
- 5
src/arch/i386/core/relocate.c Wyświetl plik

@@ -2,6 +2,7 @@
2 2
 #include "memsizes.h"
3 3
 #include "osdep.h"
4 4
 #include "etherboot.h"
5
+#include "init.h"
5 6
 #include "relocate.h"
6 7
 
7 8
 #ifndef KEEP_IT_REAL
@@ -38,6 +39,8 @@ extern char _max_align[];
38 39
 /* Linker symbols */
39 40
 extern char _text[];
40 41
 extern char _end[];
42
+extern struct post_reloc_fn post_reloc_fns[];
43
+extern struct post_reloc_fn post_reloc_fns_end[];
41 44
 
42 45
 #undef DBG
43 46
 #ifdef DEBUG_RELOCATE
@@ -46,9 +49,10 @@ extern char _end[];
46 49
 #define DBG(...)
47 50
 #endif
48 51
 
49
-void relocate ( void ) {
52
+static void relocate ( void ) {
50 53
 	unsigned long addr, eaddr, size;
51 54
 	unsigned i;
55
+	struct post_reloc_fn *post_reloc_fn;
52 56
 
53 57
 	/* Walk through the memory map and find the highest address
54 58
 	 * below 4GB that etherboot will fit into.  Ensure etherboot
@@ -186,12 +190,23 @@ void relocate ( void ) {
186 190
 
187 191
 		relocate_to ( addr );
188 192
 		/* Note that we cannot make real-mode calls
189
-		 * (e.g. printf) at this point, because the pointer
190
-		 * installed_librm uses a virtual address (in order
191
-		 * that it can have a valid initialiser) and so is
192
-		 * currently invalid.
193
+		 * (e.g. printf) at this point, because librm has just
194
+		 * been moved to high memory.
193 195
 		 */
196
+
197
+		/* Call any registered post-relocation functions.
198
+		 * librm has a post-relocation function to install a
199
+		 * new librm into base memory.
200
+		 */
201
+		for ( post_reloc_fn = post_reloc_fns;
202
+		      post_reloc_fn < post_reloc_fns_end ; post_reloc_fn++ ) {
203
+			if ( post_reloc_fn->post_reloc )
204
+				post_reloc_fn->post_reloc ();
205
+		}
206
+		
194 207
 	}
195 208
 }
196 209
 
210
+INIT_FN ( INIT_RELOCATE, relocate, NULL, NULL );
211
+
197 212
 #endif /* ! KEEP_IT_REAL */

+ 15
- 5
src/arch/i386/include/relocate.h Wyświetl plik

@@ -1,14 +1,24 @@
1 1
 #ifndef RELOCATE_H
2 2
 #define RELOCATE_H
3 3
 
4
-#ifdef KEEP_IT_REAL
5
-
6 4
 /* relocate() is conceptually impossible with KEEP_IT_REAL */
7
-#define relocate()
5
+#ifndef KEEP_IT_REAL
6
+
7
+/* An entry in the post-relocation function table */
8
+struct post_reloc_fn {
9
+	void ( *post_reloc ) ( void );
10
+};
8 11
 
9
-#else
12
+/* Use double digits to avoid problems with "10" < "9" on alphabetic sort */
13
+#define POST_RELOC_LIBRM	"00"
10 14
 
11
-extern void relocate ( void );
15
+/* Macro for creating a post-relocation function table entry */
16
+#define POST_RELOC_FN( post_reloc_order, post_reloc_func )		      \
17
+	static struct post_reloc_fn post_reloc_functions		      \
18
+	    __attribute__ (( used, __section__( ".post_reloc_fns."	      \
19
+						post_reloc_order ) )) = {     \
20
+		.post_reloc = post_reloc_func,				      \
21
+	};
12 22
 
13 23
 #endif
14 24
 

+ 5
- 0
src/arch/i386/scripts/i386.lds Wyświetl plik

@@ -140,6 +140,8 @@ SECTIONS {
140 140
 	__data = .;
141 141
 	*(.data)
142 142
 	*(.data.*)
143
+
144
+	/* Various tables */
143 145
 	pci_drivers = .;
144 146
 	*(.drivers.pci)
145 147
 	pci_drivers_end = .;
@@ -149,6 +151,9 @@ SECTIONS {
149 151
 	console_drivers = .;
150 152
 	*(.drivers.console)
151 153
 	console_drivers_end = .;
154
+	post_reloc_fns = .;
155
+	*(SORT(.post_reloc_fns.*))
156
+	post_reloc_fns_end = .;
152 157
 	init_fns = .;
153 158
 	*(SORT(.init_fns.*))
154 159
 	init_fns_end = .;

Ładowanie…
Anuluj
Zapisz