Procházet zdrojové kódy

Heading towards a sane set of control functions

tags/v0.9.3
Michael Brown před 19 roky
rodič
revize
560027899e
1 změnil soubory, kde provedl 39 přidání a 27 odebrání
  1. 39
    27
      src/arch/i386/transitions/librm_mgmt.c

+ 39
- 27
src/arch/i386/transitions/librm_mgmt.c Zobrazit soubor

@@ -12,8 +12,9 @@
12 12
 #include "stdint.h"
13 13
 #include "stddef.h"
14 14
 #include "string.h"
15
-#include "init.h"
16 15
 #include "basemem.h"
16
+#include "relocate.h"
17
+#include "init.h"
17 18
 #include "librm.h"
18 19
 
19 20
 /*
@@ -78,10 +79,21 @@ static void install_librm ( char *addr ) {
78 79
  * preserving the values for rm_ss and rm_sp from the old installed
79 80
  * copy.
80 81
  *
82
+ * We deliberately leave the old copy intact and effectively installed
83
+ * (apart from being in unallocated memory) so that we can use it for
84
+ * any real-mode calls required when allocating memory for the new
85
+ * copy, or for the real-mode exit path.
81 86
  */
82 87
 static void uninstall_librm ( void ) {
88
+
89
+	/* Copy installed librm back to master copy */
83 90
 	memcpy ( librm, installed_librm, librm_size );
84
-	librm_base = 0;
91
+
92
+	/* Free but do not zero the base memory */
93
+	if ( allocated_librm ) {
94
+		free_base_memory ( installed_librm, librm_size );
95
+		allocated_librm = 0;
96
+	}
85 97
 }
86 98
 
87 99
 /*
@@ -101,48 +113,48 @@ static void librm_init ( void ) {
101 113
 }
102 114
 
103 115
 /*
104
- * On exit, we want to leave a copy of librm in *unallocated* base
105
- * memory.  It must be there so that we can exit via a 16-bit exit
106
- * path, but it must not be allocated because nothing will ever
107
- * deallocate it once we exit.
116
+ * librm_post_reloc gets called immediately after relocation.
108 117
  *
109 118
  */
110
-static void librm_exit ( void ) {
111
-	/* Free but do not zero the base memory */
112
-	if ( allocated_librm ) {
113
-		free_base_memory ( installed_librm, librm_size );
114
-		allocated_librm = 0;
115
-	}
119
+static void librm_post_reloc ( void ) {
120
+	/* Point installed_librm back at last known physical location.
121
+	 */
122
+	installed_librm = phys_to_virt ( librm_base );
116 123
 }
117 124
 
125
+INIT_FN ( INIT_LIBRM, librm_init, NULL, uninstall_librm );
126
+POST_RELOC_FN ( POST_RELOC_LIBRM, librm_post_reloc );
127
+
118 128
 /*
119
- * Reset gets called immediately after relocation.
129
+ * Wrapper for arch_initialise() when librm is being used.  We have to
130
+ * install a copy of librm to allocated base memory and return the
131
+ * pointer to this new librm's entry point via es:di.
120 132
  *
121 133
  */
122
-
123
-static void librm_reset ( void ) {
134
+void librm_arch_initialise ( struct i386_all_regs *regs ) {
124 135
 	char *new_librm;
125 136
 
126
-	/* Point installed_librm back at last known physical location.
127
-	 * Do this in case we have just relocated and the virtual
128
-	 * address has therefore changed. */
129
-	installed_librm = phys_to_virt ( librm_base );
137
+	/* Hand off to arch_initialise() */
138
+	arch_initialise ( regs );
130 139
 
131
-	/* Free allocated base memory, if applicable */
132
-	librm_exit();
140
+	/* Uninstall current librm (i.e. the one that's part of the
141
+	 * original, pre-relocation Etherboot image).
142
+	 */
143
+	uninstall_librm();
133 144
 
134 145
 	/* Allocate space for new librm */
135 146
 	new_librm = alloc_base_memory ( librm_size );
136 147
 	allocated_librm = 1;
137
-
148
+	
138 149
 	/* Install new librm */
139 150
 	install_librm ( new_librm );
140
-}
141
-
142
-INIT_FN ( INIT_LIBRM, librm_init, librm_reset, librm_exit );
143
-
144
-
145 151
 
152
+	/* Point es:di to new librm's entry point.  Fortunately, di is
153
+	 * already set up by setup16, so all we need to do is point
154
+	 * es:0000 to the start of the new librm.
155
+	 */
156
+	regs->es = librm_base >> 4;
157
+}
146 158
 
147 159
 /*
148 160
  * Increment lock count of librm

Načítá se…
Zrušit
Uložit