Browse Source

init_librm() and prot_call() are now real-mode far calls.

install() now calls relocate(), moves the protected-mode code to the new
location, and calls hide_etherboot().
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
89da833c5d

+ 2
- 1
src/arch/i386/interface/pcbios/int13.c View File

393
 				"\nint13_wrapper:\n\t"
393
 				"\nint13_wrapper:\n\t"
394
 				"orb $0, %%al\n\t" /* clear CF and OF */
394
 				"orb $0, %%al\n\t" /* clear CF and OF */
395
 				"pushl %0\n\t" /* call int13() */
395
 				"pushl %0\n\t" /* call int13() */
396
-				"data32 call prot_call\n\t"
396
+				"pushw %%cs\n\t"
397
+				"call prot_call\n\t"
397
 				"jo 1f\n\t" /* chain if OF not set */
398
 				"jo 1f\n\t" /* chain if OF not set */
398
 				"pushfw\n\t"
399
 				"pushfw\n\t"
399
 				"lcall *%%cs:int13_vector\n\t"
400
 				"lcall *%%cs:int13_vector\n\t"

+ 2
- 1
src/arch/i386/prefix/dskprefix.S View File

357
 	.section ".text16", "awx", @progbits
357
 	.section ".text16", "awx", @progbits
358
 1:
358
 1:
359
 	pushl	$main
359
 	pushl	$main
360
-	data32 call	prot_call
360
+	pushw	%cs
361
+	call	prot_call
361
 	popl	%eax /* discard */
362
 	popl	%eax /* discard */
362
 
363
 
363
 	/* Boot next device */
364
 	/* Boot next device */

+ 112
- 84
src/arch/i386/prefix/libprefix.S View File

21
 
21
 
22
 	.arch i386
22
 	.arch i386
23
 	.section ".prefix.lib", "awx", @progbits
23
 	.section ".prefix.lib", "awx", @progbits
24
+	.section ".data16", "aw", @progbits
24
 
25
 
25
 /****************************************************************************
26
 /****************************************************************************
26
  * install_block (real-mode near call)
27
  * install_block (real-mode near call)
164
 	ret
165
 	ret
165
 	.size install_basemem, . - install_basemem
166
 	.size install_basemem, . - install_basemem
166
 
167
 
168
+/****************************************************************************
169
+ * install_highmem (flat real-mode near call)
170
+ *
171
+ * Install .text and .data into high memory
172
+ *
173
+ * Parameters:
174
+ *   %es:edi : address in high memory
175
+ * Returns:
176
+ *   none
177
+ * Corrupts:
178
+ *   none
179
+ ****************************************************************************
180
+ */
181
+
182
+#ifndef KEEP_IT_REAL
183
+
184
+	.section ".prefix.lib"
185
+	.code16
186
+install_highmem:
187
+	/* Preserve registers */
188
+	pushl	%esi
189
+	pushl	%edi
190
+	pushl	%ecx
191
+	pushl	%edx
192
+		
193
+	/* Install .text and .data to specified address */
194
+	movl	$_textdata_load_offset, %esi
195
+	movl	$_textdata_progbits_size, %ecx
196
+	movl	$_textdata_size, %edx
197
+	call	install_block
198
+
199
+	/* Restore registers and interrupt status */
200
+	popl	%edx
201
+	popl	%ecx
202
+	popl	%edi
203
+	popl	%esi
204
+	ret
205
+	.size install_highmem, . - install_highmem
206
+	
207
+#endif /* KEEP_IT_REAL */
208
+	
167
 /****************************************************************************
209
 /****************************************************************************
168
  * GDT for flat real mode
210
  * GDT for flat real mode
169
  *
211
  *
183
 gdt_base:		.long 0
225
 gdt_base:		.long 0
184
 			.word 0 /* padding */
226
 			.word 0 /* padding */
185
 
227
 
186
-real_ds:	/* Genuine real mode data segment */
187
-	.equ	REAL_DS, real_ds - gdt
188
-	.word	0xffff, 0
189
-	.byte	0, 0x93, 0, 0
190
-
191
 flat_ds:	/* Flat real mode data segment */
228
 flat_ds:	/* Flat real mode data segment */
192
 	.equ	FLAT_DS, flat_ds - gdt
229
 	.equ	FLAT_DS, flat_ds - gdt
193
 	.word	0xffff, 0
230
 	.word	0xffff, 0
200
 #endif /* KEEP_IT_REAL */
237
 #endif /* KEEP_IT_REAL */
201
 
238
 
202
 /****************************************************************************
239
 /****************************************************************************
203
- * set_segment_limits (real-mode near call)
240
+ * flatten_real_mode (real-mode near call)
204
  *
241
  *
205
- * Sets limits on the data segments %ds and %es.
242
+ * Sets 4GB limits on the data segments %ds and %es.
206
  *
243
  *
207
  * Parameters: 
244
  * Parameters: 
208
- *   %cx : Segment limit ($REAL_DS or $FLAT_DS)
245
+ *   none
209
  ****************************************************************************
246
  ****************************************************************************
210
  */
247
  */
211
 
248
 
213
 	
250
 	
214
 	.section ".prefix.lib"
251
 	.section ".prefix.lib"
215
 	.code16
252
 	.code16
216
-set_segment_limits:
253
+flatten_real_mode:
217
 	/* Preserve real-mode segment values and temporary registers */
254
 	/* Preserve real-mode segment values and temporary registers */
218
 	pushw	%es
255
 	pushw	%es
219
 	pushw	%ds
256
 	pushw	%ds
227
 	movl	%eax, %cs:gdt_base
264
 	movl	%eax, %cs:gdt_base
228
 	lgdt	%cs:gdt
265
 	lgdt	%cs:gdt
229
 
266
 
230
-	/* Switch to protected mode, set segment limits, switch back */
267
+	/* Switch to protected mode */
231
 	movl	%cr0, %eax
268
 	movl	%cr0, %eax
232
 	orb	$CR0_PE, %al
269
 	orb	$CR0_PE, %al
233
 	movl	%eax, %cr0
270
 	movl	%eax, %cr0
234
-	movw	%cx, %ds
235
-	movw	%cx, %es
271
+
272
+	/* Set flat segment limits */
273
+	movw	$FLAT_DS, %ax
274
+	movw	%ax, %ds
275
+	movw	%ax, %es
276
+
277
+	/* Switch back to real mode */
278
+	movl	%cr0, %eax
236
 	andb	$0!CR0_PE, %al
279
 	andb	$0!CR0_PE, %al
237
 	movl	%eax, %cr0
280
 	movl	%eax, %cr0
238
 
281
 
241
 	popw	%ds
284
 	popw	%ds
242
 	popw	%es
285
 	popw	%es
243
 	ret
286
 	ret
244
-	.size set_segment_limits, . - set_segment_limits
245
-	
246
-#endif /* KEEP_IT_REAL */
247
-	
248
-/****************************************************************************
249
- * install_highmem (real-mode near call)
250
- *
251
- * Install .text and .data into high memory
252
- *
253
- * Parameters:
254
- *   %edi : physical address in high memory
255
- * Returns:
256
- *   none
257
- * Corrupts:
258
- *   none
259
- ****************************************************************************
260
- */
261
-
262
-#ifndef KEEP_IT_REAL
263
-
264
-	.section ".prefix.lib"
265
-	.code16
266
-install_highmem:
267
-	/* Preserve registers and interrupt status */
268
-	pushfl
269
-	pushl	%esi
270
-	pushl	%edi
271
-	pushl	%ecx
272
-	pushl	%edx
273
-		
274
-	/* Disable interrupts and flatten real mode */
275
-	cli
276
-	movw	$FLAT_DS, %cx
277
-	call	set_segment_limits
278
-
279
-	/* Install .text and .data to specified address */
280
-	xorw	%cx, %cx
281
-	movw	%cx, %es
282
-	movl	$_textdata_load_offset, %esi
283
-	movl	$_textdata_progbits_size, %ecx
284
-	movl	$_textdata_size, %edx
285
-	call	install_block
286
-
287
-	/* Unflatten real mode */
288
-	movw	$REAL_DS, %cx
289
-	call	set_segment_limits
290
-
291
-	/* Restore registers and interrupt status */
292
-	popl	%edx
293
-	popl	%ecx
294
-	popl	%edi
295
-	popl	%esi
296
-	popfl
297
-	ret
298
-	.size install_highmem, . - install_highmem
287
+	.size flatten_real_mode, . - flatten_real_mode
299
 	
288
 	
300
 #endif /* KEEP_IT_REAL */
289
 #endif /* KEEP_IT_REAL */
301
 	
290
 	
329
 	call	install_basemem
318
 	call	install_basemem
330
 
319
 
331
 #ifndef KEEP_IT_REAL
320
 #ifndef KEEP_IT_REAL
321
+	/* Preserve registers and interrupt status, and disable interrupts */
322
+	pushfw
323
+	pushw	%ds
324
+	pushw	%es
325
+	pushl	%esi
326
+	pushl	%ecx
327
+	cli
328
+
329
+	/* Load up %ds and %es, and set up vectors for far calls to .text16 */
330
+	movw	%bx, %ds
331
+	xorw	%si, %si
332
+	movw	%si, %es
333
+	movw	%ax, (init_librm_vector+2)
334
+	movw	%ax, (prot_call_vector+2)
335
+	
332
 	/* Install .text and .data to 2MB mark.  Use 2MB to avoid
336
 	/* Install .text and .data to 2MB mark.  Use 2MB to avoid
333
 	 * problems with A20.
337
 	 * problems with A20.
334
 	 */
338
 	 */
339
+	call	flatten_real_mode
335
 	movl	$(2<<20), %edi
340
 	movl	$(2<<20), %edi
336
 	call	install_highmem
341
 	call	install_highmem
337
 
342
 
338
-	/* Continue executing in .text16 segment */
339
-	movw	%bx, %ds
340
-	pushw	%cs
341
-	pushw	$2f
342
-	pushw	%ax
343
-	pushw	$1f
344
-	lret
345
-	.section ".text16", "awx", @progbits
346
-1:
347
-	/* Set up protected-mode GDT, call relocate(), reset GDT */
348
-	call	init_librm
343
+	/* Set up initial protected-mode GDT, call relocate().
344
+	 * relocate() will return with %esi, %edi and %ecx set up
345
+	 * ready for the copy to the new location.
346
+	 */
347
+	lcall	*init_librm_vector
349
 	pushl	$relocate
348
 	pushl	$relocate
350
-	data32 call	prot_call
349
+	lcall	*prot_call_vector
351
 	addw	$4, %sp
350
 	addw	$4, %sp
352
-	call	init_librm
353
 
351
 
354
-	/* Return to executing in .prefix section */
355
-	lret
356
-	.section ".prefix.lib"
357
-2:
352
+	/* Move code to new location, set up new protected-mode GDT */
353
+	call	flatten_real_mode
354
+	pushl	%edi
355
+	es rep addr32 movsb
356
+	popl	%edi
357
+	lcall	*init_librm_vector
358
+	
359
+	/* Hide Etherboot from BIOS memory map.  Note that making this
360
+	 * protected-mode call will also restore normal (non-flat)
361
+	 * real mode, as part of the protected-to-real transition.
362
+	 */
363
+	pushl	$hide_etherboot
364
+	lcall	*prot_call_vector
365
+	addw	$4, %sp
366
+
367
+	/* Restore registers and interrupt status */
368
+	popl	%ecx
369
+	popl	%esi
370
+	popw	%es
371
+	popw	%ds
372
+	popfw
358
 #endif
373
 #endif
359
 	ret
374
 	ret
360
 	.size install_prealloc, . - install_prealloc
375
 	.size install_prealloc, . - install_prealloc
376
+
377
+#ifndef KEEP_IT_REAL
378
+	/* Vectors for far calls to .text16 functions */
379
+	.section ".data16"
380
+init_librm_vector:
381
+	.word init_librm
382
+	.word 0
383
+	.size init_librm_vector, . - init_librm_vector
384
+prot_call_vector:
385
+	.word prot_call
386
+	.word 0
387
+	.size prot_call_vector, . - prot_call_vector
388
+#endif

+ 4
- 4
src/arch/i386/transitions/librm.S View File

88
 	.equ	gdt_length, gdt_end - gdt
88
 	.equ	gdt_length, gdt_end - gdt
89
 
89
 
90
 /****************************************************************************
90
 /****************************************************************************
91
- * init_librm (real-mode near call, 16-bit real-mode return address)
91
+ * init_librm (real-mode far call, 16-bit real-mode far return address)
92
  *
92
  *
93
  * Initialise the GDT ready for transitions to protected mode.
93
  * Initialise the GDT ready for transitions to protected mode.
94
  *
94
  *
143
 	negl	%edi
143
 	negl	%edi
144
 	popl	%ebx
144
 	popl	%ebx
145
 	popl	%eax
145
 	popl	%eax
146
-	ret
146
+	lret
147
 
147
 
148
 	.section ".text16"
148
 	.section ".text16"
149
 	.code16
149
 	.code16
316
 rm_ds:	.word 0
316
 rm_ds:	.word 0
317
 	
317
 	
318
 /****************************************************************************
318
 /****************************************************************************
319
- * prot_call (real-mode near call, 32-bit real-mode return address)
319
+ * prot_call (real-mode far call, 16-bit real-mode far return address)
320
  *
320
  *
321
  * Call a specific C function in the protected-mode code.  The
321
  * Call a specific C function in the protected-mode code.  The
322
  * prototype of the C function must be
322
  * prototype of the C function must be
405
 				 * zeroes the high word of %esp, and interrupts
405
 				 * zeroes the high word of %esp, and interrupts
406
 				 * are still disabled at this point. */
406
 				 * are still disabled at this point. */
407
 	popfl
407
 	popfl
408
-	data32 ret
408
+	lret
409
 
409
 
410
 /****************************************************************************
410
 /****************************************************************************
411
  * real_call (protected-mode near call, 32-bit virtual return address)
411
  * real_call (protected-mode near call, 32-bit virtual return address)

Loading…
Cancel
Save