Browse Source

Minor refactoring to eliminate duplication.

tags/v0.9.3
Michael Brown 16 years ago
parent
commit
b8a8eea850
1 changed files with 39 additions and 49 deletions
  1. 39
    49
      src/arch/i386/prefix/libprefix.S

+ 39
- 49
src/arch/i386/prefix/libprefix.S View File

@@ -162,7 +162,7 @@ pm_call:
162 162
 	movl	%eax, %cr0
163 163
 
164 164
 	/* Restore registers and flags */
165
-	lret
165
+	lret	/* will ljmp to 99f */
166 166
 99:	popw	%ss
167 167
 	popw	%ds
168 168
 	popw	%es
@@ -298,16 +298,17 @@ alloc_basemem:
298 298
 /****************************************************************************
299 299
  * install_basemem (real-mode near call)
300 300
  *
301
- * Install .text16 and .data16 into base memory
301
+ * Install source block into base memory
302 302
  *
303
- * Parameters: 
304
- *   %ax : .text16 segment address
305
- *   %bx : .data16 segment address
303
+ * Parameters:
306 304
  *   %esi : source physical address (must be a multiple of 16)
305
+ *   %es : destination segment address
306
+ *   %cx : length of (decompressed) data
307
+ *   %dx : total length of block (including any uninitialised data portion)
307 308
  * Returns:
308 309
  *   %esi : next source physical address (will be a multiple of 16)
309 310
  * Corrupts:
310
- *   none
311
+ *   %edi, %ecx, %edx
311 312
  ****************************************************************************
312 313
  */
313 314
 	.section ".prefix.lib"
@@ -315,42 +316,24 @@ alloc_basemem:
315 316
 install_basemem:
316 317
 	/* Preserve registers */
317 318
 	pushw	%ds
318
-	pushw	%es
319
-	pushl	%edi
320
-	pushl	%ecx
321
-	pushl	%edx
322 319
 
323
-	/* Install .text16 */
320
+	/* Preserve original %esi */
324 321
 	pushl	%esi
325
-	shrl	$4, %esi
326
-	movw	%si, %ds
327
-	xorw	%si, %si
328
-	movw	%ax, %es
329
-	xorl	%edi, %edi
330
-	movl	$_text16_size, %ecx
331
-	movl	%ecx, %edx
332
-	call	install_block
333
-	popl	%ecx
334
-	addl	%ecx, %esi
335 322
 
336
-	/* Install .data16 */
337
-	pushl	%esi
323
+	/* Install to specified address */
338 324
 	shrl	$4, %esi
339 325
 	movw	%si, %ds
340 326
 	xorw	%si, %si
341
-	movw	%bx, %es
342 327
 	xorl	%edi, %edi
343
-	movl	$_data16_progbits_size, %ecx
344
-	movl	$_data16_size, %edx
328
+	movzwl	%cx, %ecx
329
+	movzwl	%dx, %edx
345 330
 	call	install_block
331
+
332
+	/* Fix up %esi for return */
346 333
 	popl	%ecx
347 334
 	addl	%ecx, %esi
348 335
 
349 336
 	/* Restore registers */
350
-	popl	%edx
351
-	popl	%ecx
352
-	popl	%edi
353
-	popw	%es
354 337
 	popw	%ds
355 338
 	ret
356 339
 	.size install_basemem, . - install_basemem
@@ -358,15 +341,17 @@ install_basemem:
358 341
 /****************************************************************************
359 342
  * install_highmem (real-mode near call)
360 343
  *
361
- * Install .text and .data into high memory
344
+ * Install source block into high memory
362 345
  *
363 346
  * Parameters:
364 347
  *   %esi : source physical address (must be a multiple of 16)
365 348
  *   %edi : destination physical address
349
+ *   %ecx : length of (decompressed) data
350
+ *   %edx : total length of block (including any uninitialised data portion)
366 351
  * Returns:
367 352
  *   %esi : next source physical address (will be a multiple of 16)
368 353
  * Corrupts:
369
- *   none
354
+ *   %edi, %ecx, %edx
370 355
  ****************************************************************************
371 356
  */
372 357
 
@@ -377,20 +362,12 @@ install_basemem:
377 362
 install_highmem:
378 363
 	/* Preserve registers */
379 364
 	pushw	%ax
380
-	pushl	%edi
381
-	pushl	%ecx
382
-	pushl	%edx
383 365
 
384
-	/* Install .text and .data to specified address */
385
-	movl	$_textdata_progbits_size, %ecx
386
-	movl	$_textdata_size, %edx
366
+	/* Install to specified address */
387 367
 	movw	$install_block, %ax
388 368
 	call	pm_call
389 369
 
390 370
 	/* Restore registers */
391
-	popl	%edx
392
-	popl	%ecx
393
-	popl	%edi
394 371
 	popw	%ax
395 372
 	ret
396 373
 	.size install_highmem, . - install_highmem
@@ -425,7 +402,10 @@ install:
425 402
 install_prealloc:
426 403
 	/* Save registers */
427 404
 	pushw	%ds
405
+	pushw	%es
428 406
 	pushl	%esi
407
+	pushl	%ecx
408
+	pushl	%edx
429 409
 
430 410
 	/* Sanity: clear the direction flag asap */
431 411
 	cld
@@ -436,7 +416,16 @@ install_prealloc:
436 416
 	shll	$4, %esi
437 417
 	addl	$_payload_offset, %esi
438 418
 
439
-	/* Install .text16 and .data16 */
419
+	/* Install .text16 */
420
+	movw	%ax, %es
421
+	movw	$_text16_size, %cx
422
+	movw	%cx, %dx
423
+	call	install_basemem
424
+
425
+	/* Install .data16 */
426
+	movw	%bx, %es
427
+	movw	$_data16_progbits_size, %cx
428
+	movw	$_data16_size, %dx
440 429
 	call	install_basemem
441 430
 
442 431
 	/* Set up %ds for access to .data16 */
@@ -447,16 +436,16 @@ install_prealloc:
447 436
 	movw	%ax, (init_libkir_vector+2)
448 437
 	lcall	*init_libkir_vector
449 438
 #else
450
-	/* Save registers */
451
-	pushl	%edi
452
-	pushl	%ecx
453
-
454 439
 	/* Install .text and .data to temporary area in high memory,
455 440
 	 * prior to reading the E820 memory map and relocating
456 441
 	 * properly.
457 442
 	 */
458 443
 	movl	$HIGHMEM_LOADPOINT, %edi
444
+	movl	$_textdata_progbits_size, %ecx
445
+	movl	$_textdata_size, %edx
446
+	pushl	%edi
459 447
 	call	install_highmem
448
+	popl	%edi
460 449
 
461 450
 	/* Initialise librm at current location */
462 451
 	movw	%ax, (init_librm_vector+2)
@@ -469,7 +458,7 @@ install_prealloc:
469 458
 	movw	%ax, (prot_call_vector+2)
470 459
 	pushl	$relocate
471 460
 	lcall	*prot_call_vector
472
-	addw	$4, %sp
461
+	popl	%edx /* discard */
473 462
 
474 463
 	/* Copy code to new location */
475 464
 	pushl	%edi
@@ -482,11 +471,12 @@ install_prealloc:
482 471
 	/* Initialise librm at new location */
483 472
 	lcall	*init_librm_vector
484 473
 
474
+#endif
485 475
 	/* Restore registers */
476
+	popl	%edx
486 477
 	popl	%ecx
487
-	popl	%edi
488
-#endif
489 478
 	popl	%esi
479
+	popw	%es
490 480
 	popw	%ds
491 481
 	ret
492 482
 	.size install_prealloc, . - install_prealloc

Loading…
Cancel
Save