Skip to content

Commit

Permalink
[build] Work around bug in gcc >= 4.8
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Sep 25, 2013
1 parent a9fa0d5 commit cba22d3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
8 changes: 5 additions & 3 deletions src/arch/i386/drivers/net/undiload.c
Expand Up @@ -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 */
Expand Down
9 changes: 5 additions & 4 deletions src/arch/i386/firmware/pcbios/bios_console.c
Expand Up @@ -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"
Expand All @@ -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 ) );
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/arch/i386/image/bootsector.c
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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" );

Expand Down
7 changes: 4 additions & 3 deletions src/arch/i386/image/elfboot.c
Expand Up @@ -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 );

Expand Down
16 changes: 10 additions & 6 deletions src/arch/i386/image/nbi.c
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand All @@ -288,19 +290,21 @@ 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 ),
"S" ( ( imgheader->location.segment << 4 ) +
imgheader->location.offset ),
"b" ( virt_to_phys ( basemem_packet ) ),
"a" ( virt_to_phys ( &loaderinfo ) )
: "ecx", "edx", "ebp", "memory" );
: "ecx", "edx", "memory" );

return rc;
}
Expand Down
8 changes: 5 additions & 3 deletions src/arch/i386/interface/pxeparent/pxeparent.c
Expand Up @@ -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
Expand Down

0 comments on commit cba22d3

Please sign in to comment.