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
 #include "memsizes.h"
2
 #include "memsizes.h"
3
 #include "osdep.h"
3
 #include "osdep.h"
4
 #include "etherboot.h"
4
 #include "etherboot.h"
5
+#include "init.h"
5
 #include "relocate.h"
6
 #include "relocate.h"
6
 
7
 
7
 #ifndef KEEP_IT_REAL
8
 #ifndef KEEP_IT_REAL
38
 /* Linker symbols */
39
 /* Linker symbols */
39
 extern char _text[];
40
 extern char _text[];
40
 extern char _end[];
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
 #undef DBG
45
 #undef DBG
43
 #ifdef DEBUG_RELOCATE
46
 #ifdef DEBUG_RELOCATE
46
 #define DBG(...)
49
 #define DBG(...)
47
 #endif
50
 #endif
48
 
51
 
49
-void relocate ( void ) {
52
+static void relocate ( void ) {
50
 	unsigned long addr, eaddr, size;
53
 	unsigned long addr, eaddr, size;
51
 	unsigned i;
54
 	unsigned i;
55
+	struct post_reloc_fn *post_reloc_fn;
52
 
56
 
53
 	/* Walk through the memory map and find the highest address
57
 	/* Walk through the memory map and find the highest address
54
 	 * below 4GB that etherboot will fit into.  Ensure etherboot
58
 	 * below 4GB that etherboot will fit into.  Ensure etherboot
186
 
190
 
187
 		relocate_to ( addr );
191
 		relocate_to ( addr );
188
 		/* Note that we cannot make real-mode calls
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
 #endif /* ! KEEP_IT_REAL */
212
 #endif /* ! KEEP_IT_REAL */

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

1
 #ifndef RELOCATE_H
1
 #ifndef RELOCATE_H
2
 #define RELOCATE_H
2
 #define RELOCATE_H
3
 
3
 
4
-#ifdef KEEP_IT_REAL
5
-
6
 /* relocate() is conceptually impossible with KEEP_IT_REAL */
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
 #endif
23
 #endif
14
 
24
 

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

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

Ładowanie…
Anuluj
Zapisz