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

Loading…
Cancel
Save