bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Size of stage1


From: Timothy Baldwin
Subject: Re: Size of stage1
Date: Wed, 21 Jan 2004 15:21:23 +0000
User-agent: KMail/1.5.94

On Tuesday 20 January 2004 12:17, Oliver Altmeyer wrote:

> My question is now: Do you know a better solution how I can get space
> within stage1 which does not require the exclusion of some important
> components?

The appended untested patch does the following:

Moves "call message" to general_error from the code that calls it.
Moves hd_probe_error to where it is called.
Removes the cli instruction. (movw %ax, %ss suspends interrupts)
Removes a pointless load of %ecx in the LBA code.
Uses %eax instead of %ebx as a tempoary register in the LBA code.
Avoids use of memory in calculating the CHS parameters.

27 bytes saved in total.

Also consider:

Removing the copy_buffer routine and loading the start of stage2 at the 
correct address. (saves 20 or more bytes)

Place an initialised copy of the disk address packet in stage1 and remove the 
code with initialises it. (saves 12 bytes)

Place the address in the disk address packet at install time. (saves 12 more 
bytes, but breaks compability)

Conditional assembly to produce multiple versions.

Index: stage1.S
===================================================================
RCS file: /cvsroot/grub/grub/stage1/stage1.S,v
retrieving revision 1.34
diff -u -r1.34 stage1.S
--- stage1.S    10 Dec 2002 17:30:28 -0000      1.34
+++ stage1.S    21 Jan 2004 14:50:56 -0000
@@ -105,7 +105,6 @@
 after_BPB:
 
 /* general setup */
-       cli             /* we're not safe here! */
 
        /*
         * This is a workaround for buggy BIOSes which don't pass boot
@@ -127,7 +126,7 @@
        /* set up %ds and %ss as offset from 0 */
        xorw    %ax, %ax
        movw    %ax, %ds
-       movw    %ax, %ss
+       movw    %ax, %ss /* Disables interrupts until after next instruction */
 
        /* set up the REAL stack */
        movw    $STAGE1_STACKSEG, %sp
@@ -173,20 +172,17 @@
        MOV_MEM_TO_AL(ABS(force_lba))   /* movb ABS(force_lba), %al */
        testb   %al, %al
        jnz     lba_mode
-       andw    $1, %cx
+       testb   $1, %cl
        jz      chs_mode
        
 lba_mode:
-       /* save the total number of sectors */
-       movl    0x10(%si), %ecx
-
        /* set %si to the disk address packet */
        movw    $ABS(disk_address_packet), %si
 
        /* set the mode to non-zero */
        movb    $1, -1(%si)
        
-       movl    ABS(stage2_sector), %ebx
+       movl    ABS(stage2_sector), %eax
 
        /* the size and the reserved byte */
        movw    $0x0010, (%si)
@@ -195,7 +191,7 @@
        movw    $1, 2(%si)
        
        /* the absolute address (low 32 bits) */
-       movl    %ebx, 8(%si)
+       movl    %eax, 8(%si)
 
        /* the segment of buffer address */
        movw    $STAGE1_BUFFERSEG, 6(%si)
@@ -238,7 +234,8 @@
        jz      floppy_probe
 
        /* Nope, we definitely have a hard disk, and we're screwed. */
-       jmp     hd_probe_error
+       movw    $ABS(hd_probe_error_string), %si
+       jmp     general_error
 
 final_init:
        
@@ -281,41 +278,34 @@
        divl    (%si)
 
        /* save sector start */
-       movb    %dl, 10(%si)
+       movb    %dl, %cl
 
        xorl    %edx, %edx      /* zero %edx */
        divl    4(%si)          /* divide by number of heads */
 
        /* save head start */
-       movb    %dl, 11(%si)
-
-       /* save cylinder start */
-       movw    %ax, 12(%si)
+       movb    %dl, %dh
 
        /* do we need too many cylinders? */
        cmpw    8(%si), %ax
        jge     geometry_error
 
 /*
- *  This is the loop for taking care of BIOS geometry translation (ugh!)
+ *  This is for taking care of BIOS geometry translation (ugh!)
  */
 
-       /* get high bits of cylinder */
-       movb    13(%si), %dl
-
-       shlb    $6, %dl         /* shift left by 6 bits */
-       movb    10(%si), %cl    /* get sector */
+       /* high bits of cylinder in %ah */
+       shlb    $6, %ah         /* shift left by 6 bits */
 
        incb    %cl             /* normalize sector (sectors go
                                        from 1-N, not 0-(N-1) ) */
-       orb     %dl, %cl        /* composite together */
-       movb    12(%si), %ch    /* sector+hcyl in cl, cylinder in ch */
+       orb     %ah, %cl        /* composite together */
+       movb    %al, %ch        /* sector+hcyl in cl, cylinder in ch */
 
-       /* restore %dx */
-       popw    %dx
+       /* restore %dl */
+       popw    %bx
+       mov     %bl, %dl
        
-       /* head number */
-       movb    11(%si), %dh
 
 /*
  * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
@@ -373,23 +363,18 @@
  * BIOS Geometry translation error (past the end of the disk geometry!).
  */
 geometry_error:
-       MSG(geometry_error_string)
+       movw    $ABS(geometry_error_string), %si
        jmp     general_error
 
-/*
- * Disk probe failure.
- */
-hd_probe_error:
-       MSG(hd_probe_error_string)
-       jmp     general_error
 
 /*
  * Read error on the disk.
  */
 read_error:
-       MSG(read_error_string)
+       movw    $ABS(read_error_string), %si
 
 general_error:
+       call    message
        MSG(general_error_string)
 
 /* go here when you need to stop the machine hard after an error condition */
@@ -466,7 +451,7 @@
 /*
  * Floppy disk probe failure.
  */
-       MSG(fd_probe_error_string)
+       movw    $ABS(fd_probe_error_string), %si
        jmp     general_error
 
 fd_probe_error_string: .string "Floppy"


-- 
Member AFFS, WYLUG, SWP (UK), ANL, Leeds SA, Leeds Anti-war coalition
No to software patents!    No to DRM/EUCD - hands off our computers!

Attachment: pgpIx_oa8EX1H.pgp
Description: signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]