From 6663ad99cf36f53f454defc8f7e87eb2e7495255 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Mon, 24 Jun 2019 18:44:33 +0200 Subject: arch/x86: Support x86_64 exceptions * Doesn't affect existing x86_32 code. Tested on qemu using division by zero. Tested on Lenovo T410 with additional x86_64 patches. Change-Id: Idd12c90a95cc2989eb9b2a718740a84222193f48 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/30117 Tested-by: build bot (Jenkins) Reviewed-by: Raul Rangel --- src/arch/x86/idt.S | 63 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) (limited to 'src/arch/x86/idt.S') diff --git a/src/arch/x86/idt.S b/src/arch/x86/idt.S index a15ccbb132..6807056fe3 100644 --- a/src/arch/x86/idt.S +++ b/src/arch/x86/idt.S @@ -109,40 +109,75 @@ vec19: .global int_hand int_hand: - /* At this point, on x86-32, on the stack there is: - * 0(%esp) vector - * 4(%esp) error code - * 8(%esp) eip - * 12(%esp) cs - * 16(%esp) eflags - */ #ifdef __x86_64__ + /* At this point, on x86-64, on the stack there is: + * 0(%rsp) vector + * 8(%rsp) error code + * 16(%rsp) rip + * 24(%rsp) cs + * 32(%rsp) rflags + * 40(%rsp) rsp + * 48(%rsp) ss + */ + push %r15 + push %r14 + push %r13 + push %r12 + push %r11 + push %r10 + push %r9 + push %r8 + push %rdi push %rsi push %rbp - /* Original stack pointer */ - lea 32(%rsp), %rbp - push %rbp + push %rbx push %rdx push %rcx push %rax - push %rsp /* Pointer to structure on the stack */ + /* Pass pointer to struct as first argument */ + mov %rsp, %rdi + + /* Back up stack pointer */ + mov %rsp, %rbp + + /* Align stack to 16 bytes. */ + and $(~0xf), %rsp + call x86_exception - pop %rax /* Drop the pointer */ + + /* Restore stack pointer from backup */ + mov %rbp, %rsp pop %rax pop %rcx pop %rdx pop %rbx - pop %rbp /* Ignore saved %rsp value */ + pop %rbp pop %rsi pop %rdi - add $8, %rsp /* pop of the vector and error code */ + pop %r8 + pop %r9 + pop %r10 + pop %r11 + pop %r12 + pop %r13 + pop %r14 + pop %r15 + + add $16, %rsp /* pop of the vector and error code */ #else + /* At this point, on x86-32, on the stack there is: + * 0(%esp) vector + * 4(%esp) error code + * 8(%esp) eip + * 12(%esp) cs + * 16(%esp) eflags + */ pushl %edi pushl %esi pushl %ebp -- cgit v1.2.3