]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Work around bug in gcc >= 4.8
authorMichael Brown <mcb30@ipxe.org>
Wed, 25 Sep 2013 11:55:46 +0000 (12:55 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 25 Sep 2013 11:55:46 +0000 (12:55 +0100)
Commit 238050d ("[build] Work around bug in gcc >= 4.8") works around
one instance of a bug in recent versions of gcc, in which "ebp" cannot
be specified within an asm clobber list.

Some versions of gcc seem to exhibit the same bug on other points in
the codebase.  Fix by changing all instances of "ebp" in a clobber
list to use the push/pop %ebp workaround instead.

Originally-implemented-by: Víctor Román Archidona <contacto@victor-roman.es>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/drivers/net/undiload.c
src/arch/i386/firmware/pcbios/bios_console.c
src/arch/i386/image/bootsector.c
src/arch/i386/image/elfboot.c
src/arch/i386/image/nbi.c
src/arch/i386/interface/pxeparent/pxeparent.c

index f0f15e6a2fc40cb89706a1e2fd966cb71dcadaf9..77134dcb8aae7af90fee2fc4e84c56bc26ae19cc 100644 (file)
@@ -103,13 +103,15 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
 
        /* Call loader */
        undi_loader_entry = undirom->loader_entry;
-       __asm__ __volatile__ ( REAL_CODE ( "pushw %%ds\n\t"
+       __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
+                                          "pushw %%ds\n\t"
                                           "pushw %%ax\n\t"
                                           "lcall *undi_loader_entry\n\t"
-                                          "addw $4, %%sp\n\t" )
+                                          "popl %%ebp\n\t" /* discard */
+                                          "popl %%ebp\n\t" /* gcc bug */ )
                               : "=a" ( exit )
                               : "a" ( __from_data16 ( &undi_loader ) )
-                              : "ebx", "ecx", "edx", "esi", "edi", "ebp" );
+                              : "ebx", "ecx", "edx", "esi", "edi" );
 
        if ( exit != PXENV_EXIT_SUCCESS ) {
                /* Clear entry point */
index 213ebd92cd6240ce5959cf73118fcea88c4d9a6b..79e437088f39bb696af0e14bc3ed13b84c07bd71 100644 (file)
@@ -167,7 +167,8 @@ static void bios_putchar ( int character ) {
                return;
 
        /* Print character with attribute */
-       __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
+       __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
+                                          "sti\n\t"
                                           /* Skip non-printable characters */
                                           "cmpb $0x20, %%al\n\t"
                                           "jb 1f\n\t"
@@ -188,11 +189,11 @@ static void bios_putchar ( int character ) {
                                           "xorw %%bx, %%bx\n\t"
                                           "movb $0x0e, %%ah\n\t"
                                           "int $0x10\n\t"
-                                          "cli\n\t" )
+                                          "cli\n\t"
+                                          "popl %%ebp\n\t" /* gcc bug */ )
                               : "=a" ( discard_a ), "=b" ( discard_b ),
                                 "=c" ( discard_c )
-                              : "a" ( character ), "b" ( bios_attr )
-                              : "ebp" );
+                              : "a" ( character ), "b" ( bios_attr ) );
 }
 
 /**
index ab3cf94c21fbeda059d47d95cc6ae413a33b40e8..cb164fda9e54a9086bbc5ce11ebba7727be5c27b 100644 (file)
@@ -80,6 +80,8 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
                                           "movw %%ss, %%ax\n\t"
                                           "movw %%ax, %%cs:saved_ss\n\t"
                                           "movw %%sp, %%cs:saved_sp\n\t"
+                                          /* Save frame pointer (gcc bug) */
+                                          "movl %%ebp, %%cs:saved_ebp\n\t"
                                           /* Prepare jump to boot sector */
                                           "pushw %%bx\n\t"
                                           "pushw %%di\n\t"
@@ -99,11 +101,14 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
                                           "sti\n\t"
                                           "lret\n\t"
                                           /* Preserved variables */
+                                          "\nsaved_ebp: .long 0\n\t"
                                           "\nsaved_ss: .word 0\n\t"
                                           "\nsaved_sp: .word 0\n\t"
                                           "\nsaved_retaddr: .word 0\n\t"
                                           /* Boot failure return point */
                                           "\nbootsector_exec_fail:\n\t"
+                                          /* Restore frame pointer (gcc bug) */
+                                          "movl %%cs:saved_ebp, %%ebp\n\t"
                                           /* Restore stack pointer */
                                           "movw %%cs:saved_ss, %%ax\n\t"
                                           "movw %%ax, %%ss\n\t"
@@ -114,7 +119,7 @@ int call_bootsector ( unsigned int segment, unsigned int offset,
                                 "=d" ( discard_d )
                               : "b" ( segment ), "D" ( offset ),
                                 "d" ( drive )
-                              : "eax", "ecx", "esi", "ebp" );
+                              : "eax", "ecx", "esi" );
 
        DBG ( "Booted disk returned via INT 18 or 19\n" );
 
index a867a95669f7109692200c8b94bb12cd21b66de7..0f6957f02a116c69b7f2a1cd13012b751c8cab49 100644 (file)
@@ -60,10 +60,11 @@ static int elfboot_exec ( struct image *image ) {
 
        /* Jump to OS with flat physical addressing */
        DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );
-       __asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
+       __asm__ __volatile__ ( PHYS_CODE ( "pushl %%ebp\n\t" /* gcc bug */
+                                          "call *%%edi\n\t"
+                                          "popl %%ebp\n\t" /* gcc bug */ )
                               : : "D" ( entry )
-                              : "eax", "ebx", "ecx", "edx", "esi", "ebp",
-                                "memory" );
+                              : "eax", "ebx", "ecx", "edx", "esi", "memory" );
 
        DBGC ( image, "ELF %p returned\n", image );
 
index d3e523e9252c08ec01b4d5edcef6c911cca875c3..99046144d5bc8a1f4e5e1741c8c27cab9ba3f70d 100644 (file)
@@ -248,7 +248,8 @@ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
               imgheader->execaddr.segoff.offset );
 
        __asm__ __volatile__ (
-               REAL_CODE ( "pushw %%ds\n\t"    /* far pointer to bootp data */
+               REAL_CODE ( "pushl %%ebp\n\t"   /* gcc bug */
+                           "pushw %%ds\n\t"    /* far pointer to bootp data */
                            "pushw %%bx\n\t"
                            "pushl %%esi\n\t"   /* location */
                            "pushw %%cs\n\t"    /* lcall execaddr */
@@ -258,13 +259,14 @@ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
                            "pushl %%edi\n\t"
                            "lret\n\t"
                            "\n2:\n\t"
-                           "addw $8,%%sp\n\t"  /* clean up stack */ )
+                           "addw $8,%%sp\n\t"  /* clean up stack */
+                           "popl %%ebp\n\t"    /* gcc bug */ )
                : "=a" ( rc ), "=D" ( discard_D ), "=S" ( discard_S ),
                  "=b" ( discard_b )
                : "D" ( imgheader->execaddr.segoff ),
                  "S" ( imgheader->location ),
                  "b" ( __from_data16 ( basemem_packet ) )
-               : "ecx", "edx", "ebp" );
+               : "ecx", "edx" );
 
        return rc;
 }
@@ -288,11 +290,13 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
 
        /* Jump to OS with flat physical addressing */
        __asm__ __volatile__ (
-               PHYS_CODE ( "pushl %%ebx\n\t" /* bootp data */
+               PHYS_CODE ( "pushl %%ebp\n\t" /* gcc bug */
+                           "pushl %%ebx\n\t" /* bootp data */
                            "pushl %%esi\n\t" /* imgheader */
                            "pushl %%eax\n\t" /* loaderinfo */
                            "call *%%edi\n\t"
-                           "addl $12, %%esp\n\t" /* clean up stack */ )
+                           "addl $12, %%esp\n\t" /* clean up stack */
+                           "popl %%ebp\n\t" /* gcc bug */ )
                : "=a" ( rc ), "=D" ( discard_D ), "=S" ( discard_S ),
                  "=b" ( discard_b )
                : "D" ( imgheader->execaddr.linear ),
@@ -300,7 +304,7 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
                        imgheader->location.offset ),
                  "b" ( virt_to_phys ( basemem_packet ) ),
                  "a" ( virt_to_phys ( &loaderinfo ) )
-               : "ecx", "edx", "ebp", "memory" );
+               : "ecx", "edx", "memory" );
 
        return rc;
 }
index b2c6ffbaae7e3d790027e90c106e12bffda99f4e..9d2948c54848df1e7b43a94c172b002a4413e0c1 100644 (file)
@@ -143,16 +143,18 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
        /* Call real-mode entry point.  This calling convention will
         * work with both the !PXE and the PXENV+ entry points.
         */
-       __asm__ __volatile__ ( REAL_CODE ( "pushw %%es\n\t"
+       __asm__ __volatile__ ( REAL_CODE ( "pushl %%ebp\n\t" /* gcc bug */
+                                          "pushw %%es\n\t"
                                           "pushw %%di\n\t"
                                           "pushw %%bx\n\t"
                                           "lcall *pxeparent_entry_point\n\t"
-                                          "addw $6, %%sp\n\t" )
+                                          "addw $6, %%sp\n\t"
+                                          "popl %%ebp\n\t" /* gcc bug */ )
                               : "=a" ( exit ), "=b" ( discard_b ),
                                 "=D" ( discard_D )
                               : "b" ( function ),
                                 "D" ( __from_data16 ( &pxeparent_params ) )
-                              : "ecx", "edx", "esi", "ebp" );
+                              : "ecx", "edx", "esi" );
 
        /* Determine return status code based on PXENV_EXIT and
         * PXENV_STATUS