x86, oprom: ensure DF is always cleared
[coreboot.git] / src / devices / oprom / x86_asm.S
index bbae4b1bcec252369cc532af6cd56cc5ea6d19cf..56ebb3a885ec3789cafd88b4b5161954b11669bb 100644 (file)
@@ -66,39 +66,45 @@ __registers = RELOCATED(.)
        .long 0 /* 16 - ESI */
        .long 0 /* 20 - EDI */
 
+/* 256 byte buffer, used by int10 */
+       .globl __buffer
+__buffer = RELOCATED(.)
+       .skip 256
+
        .code32
        .globl __realmode_call
 __realmode_call = RELOCATED(.)
        /* save all registers to the stack */
-       pushal
+       pusha
+       pushf
 
-       /* Move the protected mode stack to a safe place */
+       /* Move the protected mode stack pointer to a safe place */
        movl    %esp, __stack
-       movl    %esp, %ebp
+       movl    %esp, %ebp
 
-       /* This function is called with regparm=0 and we have
-        * to skip the 32 byte from pushal. Hence start at 36.
+       /* This function is called with regparm=0 and we have to
+        * skip the 36 byte from pushf+pusha. Hence start at 40.
         */
 
        /* entry point */
-       movl    36(%ebp), %eax
-       movw    %ax, __lcall_instr + 1
+       movl    40(%ebp), %eax
+       mov     %ax, __lcall_instr + 1
        andl    $0xffff0000, %eax
        shrl    $4, %eax
-       movw    %ax, __lcall_instr + 3
+       mov     %ax, __lcall_instr + 3
 
        /* initial register values */
-       movl    40(%ebp), %eax
-       movl    %eax, __registers +  0 /* eax */
        movl    44(%ebp), %eax
-       movl    %eax, __registers +  4 /* ebx */
+       movl    %eax, __registers +  0 /* eax */
        movl    48(%ebp), %eax
-       movl    %eax, __registers +  8 /* ecx */
+       movl    %eax, __registers +  4 /* ebx */
        movl    52(%ebp), %eax
-       movl    %eax, __registers + 12 /* edx */
+       movl    %eax, __registers +  8 /* ecx */
        movl    56(%ebp), %eax
-       movl    %eax, __registers + 16 /* esi */
+       movl    %eax, __registers + 12 /* edx */
        movl    60(%ebp), %eax
+       movl    %eax, __registers + 16 /* esi */
+       movl    64(%ebp), %eax
        movl    %eax, __registers + 20 /* edi */
 
        /* Activate the right segment descriptor real mode. */
@@ -141,13 +147,6 @@ __realmode_call = RELOCATED(.)
        mov     %ax, %ds
        lidt    __realmode_idt
 
-       /* Set all segments to 0x0000, ds to 0x0040 */
-       mov     %ax, %es
-       mov     %ax, %fs
-       mov     %ax, %gs
-       mov     $0x40, %ax
-       mov     %ax, %ds
-
        /* initialize registers for option rom lcall */
        movl    __registers +  0, %eax
        movl    __registers +  4, %ebx
@@ -156,14 +155,24 @@ __realmode_call = RELOCATED(.)
        movl    __registers + 16, %esi
        movl    __registers + 20, %edi
 
+       /* Set all segments to 0x0000, ds to 0x0040 */
+       push    %ax
+       xor     %ax, %ax
+       mov     %ax, %es
+       mov     %ax, %fs
+       mov     %ax, %gs
+       mov     $0x40, %ax
+       mov     %ax, %ds
+       pop     %ax
+
        /* ************************************ */
 __lcall_instr = RELOCATED(.)
        .byte 0x9a
        .word 0x0000, 0x0000
        /* ************************************ */
 
-       /* If we got here, just about done.
-        * Need to get back to protected mode
+       /* If we got here, we are just about done.
+        * Need to get back to protected mode.
         */
        movl    %cr0, %eax
        orl     $PE, %eax
@@ -175,7 +184,7 @@ __lcall_instr = RELOCATED(.)
        data32  ljmp    $0x10, $RELOCATED(1f)
 1:
        .code32
-       movw    $0x18, %ax
+       mov     $0x18, %ax
        mov     %ax, %ds
        mov     %ax, %es
        mov     %ax, %fs
@@ -185,41 +194,45 @@ __lcall_instr = RELOCATED(.)
        /* restore proper idt */
        lidt    idtarg
 
-       /* and exit */
+       /* restore stack pointer, eflags and register values */
        movl    __stack, %esp
-       popal
+       popf
+       popa
 
+       /* and exit */
        // TODO return AX from OPROM call
        ret
 
        .globl __realmode_interrupt
 __realmode_interrupt = RELOCATED(.)
        /* save all registers to the stack */
-       pushal
-       /* save the stack */
+       pusha
+       pushf
+
+       /* save the stack pointer */
        movl    %esp, __stack
-       movl    %esp, %ebp
+       movl    %esp, %ebp
 
-       /* This function is called with regparm=0 and we have
-        * to skip the 32 byte from pushal. Hence start at 36.
+       /* This function is called with regparm=0 and we have to
+        * skip the 36 byte from pushf+pusha. Hence start at 40.
         */
 
        /* prepare interrupt calling code */
-       movl    36(%ebp), %eax
+       movl    40(%ebp), %eax
        movb    %al, __intXX_instr + 1 /* intno */
 
        /* initial register values */
-       movl    40(%ebp), %eax
-       movl    %eax, __registers +  0 /* eax */
        movl    44(%ebp), %eax
-       movl    %eax, __registers +  4 /* ebx */
+       movl    %eax, __registers +  0 /* eax */
        movl    48(%ebp), %eax
-       movl    %eax, __registers +  8 /* ecx */
+       movl    %eax, __registers +  4 /* ebx */
        movl    52(%ebp), %eax
-       movl    %eax, __registers + 12 /* edx */
+       movl    %eax, __registers +  8 /* ecx */
        movl    56(%ebp), %eax
-       movl    %eax, __registers + 16 /* esi */
+       movl    %eax, __registers + 12 /* edx */
        movl    60(%ebp), %eax
+       movl    %eax, __registers + 16 /* esi */
+       movl    64(%ebp), %eax
        movl    %eax, __registers + 20 /* edi */
 
        /*  This configures CS properly for real mode. */
@@ -247,7 +260,7 @@ __realmode_interrupt = RELOCATED(.)
        data32 ljmp     $0, $RELOCATED(1f)
 1:
 
-       /* put the stack at the end of page zero.  That way we can easily 
+       /* put the stack at the end of page zero.  That way we can easily
         * share it between real mode and protected mode, because %esp and
         * %ss:%sp point to the same memory.
         */
@@ -262,12 +275,6 @@ __realmode_interrupt = RELOCATED(.)
        mov     %ax, %ds
        lidt    __realmode_idt
 
-       /* Set all segments to 0x0000 */
-       mov     %ax, %ds
-       mov     %ax, %es
-       mov     %ax, %fs
-       mov     %ax, %gs
-
        /* initialize registers for intXX call */
        movl    __registers +  0, %eax
        movl    __registers +  4, %ebx
@@ -276,6 +283,15 @@ __realmode_interrupt = RELOCATED(.)
        movl    __registers + 16, %esi
        movl    __registers + 20, %edi
 
+       /* Set all segments to 0x0000 */
+       push    %ax
+       xor     %ax, %ax
+       mov     %ax, %ds
+       mov     %ax, %es
+       mov     %ax, %fs
+       mov     %ax, %gs
+       pop     %ax
+
 __intXX_instr = RELOCATED(.)
        .byte 0xcd, 0x00 /* This becomes intXX */
 
@@ -288,7 +304,7 @@ __intXX_instr = RELOCATED(.)
        data32  ljmp    $0x10, $RELOCATED(1f)
 1:
        .code32
-       movw    $0x18, %ax
+       mov     $0x18, %ax
        mov     %ax, %ds
        mov     %ax, %es
        mov     %ax, %fs
@@ -298,9 +314,10 @@ __intXX_instr = RELOCATED(.)
        /* restore coreboot's 32-bit IDT */
        lidt    idtarg
 
-       /* Exit */
+       /* restore stack pointer, eflags and register values and exit */
        movl    __stack, %esp
-       popal
+       popf
+       popa
        ret
 
 /* This is the 16-bit interrupt entry point called by the IDT stub code.
@@ -316,6 +333,9 @@ __interrupt_handler_16bit = RELOCATED(.)
        push    %fs
        push    %gs
 
+       /* Clear DF to not break ABI assumptions */
+       cld
+
        /* Clean up the interrupt number. We could have done this in the stub,
         * but it would have cost 2 more bytes per stub entry.
         */
@@ -331,7 +351,7 @@ __interrupt_handler_16bit = RELOCATED(.)
        data32 ljmp    $0x10, $RELOCATED(1f)
 1:
        .code32
-       movw    $0x18, %ax
+       mov     $0x18, %ax
        mov     %ax, %ds
        mov     %ax, %es
        mov     %ax, %fs
@@ -376,13 +396,6 @@ __interrupt_handler_16bit = RELOCATED(.)
        mov     %ax, %ds
        lidt    __realmode_idt
 
-       /* Set up segment registers to segment 0x0000 */
-       mov     %ax, %es
-       mov     %ax, %fs
-       mov     %ax, %gs
-       mov     $0x40, %ax
-       mov     %ax, %ds
-
        /* Restore all registers, including those
         * manipulated by the C handler
         */