[coreboot-gerrit] Change in ...coreboot[master]: [WIP]arch/x86: Support x86_64 exceptions
Patrick Rudolph (Code Review)
gerrit at coreboot.org
Sun Dec 9 14:37:47 CET 2018
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30117
Change subject: [WIP]arch/x86: Support x86_64 exceptions
......................................................................
[WIP]arch/x86: Support x86_64 exceptions
* Seems to have alignment issues
Signed-off-by: Patrick Rudolph <siro at das-labor.org>
Change-Id: Idd12c90a95cc2989eb9b2a718740a84222193f48
---
M src/arch/x86/exception.c
M src/arch/x86/idt.S
M src/arch/x86/include/arch/registers.h
3 files changed, 90 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/17/30117/1
diff --git a/src/arch/x86/exception.c b/src/arch/x86/exception.c
index 0f42fdf..e89215f 100644
--- a/src/arch/x86/exception.c
+++ b/src/arch/x86/exception.c
@@ -502,12 +502,31 @@
put_packet(out_buffer);
}
#else /* !CONFIG_GDB_STUB */
-#define MDUMP_SIZE 0x80
unsigned int logical_processor = 0;
#if ENV_RAMSTAGE
logical_processor = cpu_index();
#endif
+ u8 *code;
+#ifdef __x86_64__
+#define MDUMP_SIZE 0x100
+ printk(BIOS_EMERG,
+ "CPU Index %d - APIC %d Unexpected Exception:\n"
+ "%lld @ %02llx:%016llx - Halting\n"
+ "Code: %lld rflags: %016llx cr2: %016llx\n"
+ "rax: %016llx rbx: %016llx\n"
+ "rcx: %016llx rdx: %016llx\n"
+ "rdi: %016llx rsi: %016llx\n"
+ "rbp: %016llx rsp: %016llx\n",
+ logical_processor, (unsigned int)lapicid(),
+ info->vector, info->cs, info->rip,
+ info->error_code, info->rflags, read_cr2(),
+ info->rax, info->rbx, info->rcx, info->rdx,
+ info->rdi, info->rsi, info->rbp, info->rsp);
+ code = (u8 *)((uintptr_t)info->rip - (MDUMP_SIZE >> 2));
+#else
+#define MDUMP_SIZE 0x80
+
printk(BIOS_EMERG,
"CPU Index %d - APIC %d Unexpected Exception:"
"%d @ %02x:%08x - Halting\n"
@@ -519,7 +538,8 @@
info->error_code, info->eflags, read_cr2(),
info->eax, info->ebx, info->ecx, info->edx,
info->edi, info->esi, info->ebp, info->esp);
- u8 *code = (u8 *)((uintptr_t)info->eip - (MDUMP_SIZE >> 1));
+ code = (u8 *)((uintptr_t)info->eip - (MDUMP_SIZE >> 1));
+#endif
/* Align to 8-byte boundary please, and print eight bytes per row.
* This is done to make DRAM burst timing/reordering errors more
* evident from the looking at the dump */
diff --git a/src/arch/x86/idt.S b/src/arch/x86/idt.S
index 9c36d81..8a3706d 100644
--- a/src/arch/x86/idt.S
+++ b/src/arch/x86/idt.S
@@ -120,26 +120,34 @@
.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
+ */
push %rdi
push %rsi
push %rbp
/* Original stack pointer */
- lea 32(%rsp), %rbp
+ lea 64(%rsp), %rbp
push %rbp
push %rbx
push %rdx
push %rcx
push %rax
- push %rsp /* Pointer to structure on the stack */
+ /* Save pointer to eregs structure */
+ mov %rsp, %rbp
+ /* Align stack to 16 bytes. */
+ and $(~0xf), %rsp
+ /* Save original stack pointer while keeping stack alignment. This
+ value is also the eregs argument x86_exception(). */
+ sub $8, %rsp
+ push %rbp /* Pointer to structure on the stack */
call x86_exception
pop %rax /* Drop the pointer */
@@ -152,8 +160,15 @@
pop %rsi
pop %rdi
- add $8, %rsp /* pop of the vector and error code */
+ 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
diff --git a/src/arch/x86/include/arch/registers.h b/src/arch/x86/include/arch/registers.h
index 1d3b90a..20fc683 100644
--- a/src/arch/x86/include/arch/registers.h
+++ b/src/arch/x86/include/arch/registers.h
@@ -19,6 +19,38 @@
#if !defined(__ASSEMBLER__)
#include <stdint.h>
+#ifdef __x86_64__
+#define DOWNTO8(A) \
+ struct { \
+ union { \
+ struct { \
+ union { \
+ struct { \
+ uint8_t A##l; \
+ uint8_t A##h; \
+ } __packed; \
+ uint16_t A##x; \
+ } __packed; \
+ uint16_t h##A##x; \
+ } __packed; \
+ uint32_t e##A##x; \
+ } __packed; \
+ uint64_t r##A##x; \
+ } __packed;
+
+#define DOWNTO16(A) \
+ struct {\
+ union { \
+ struct { \
+ uint16_t A; \
+ uint16_t h##A; \
+ } __packed; \
+ uint32_t e##A; \
+ } __packed; \
+ uint64_t r##A; \
+ } __packed;
+
+#else
#define DOWNTO8(A) \
union { \
struct { \
@@ -43,6 +75,9 @@
uint32_t e##A; \
} __packed;
+#endif
+
+
struct eregs {
DOWNTO8(a);
DOWNTO8(c);
@@ -52,11 +87,19 @@
DOWNTO16(bp);
DOWNTO16(si);
DOWNTO16(di);
+#ifdef __x86_64__
+ uint64_t vector;
+ uint64_t error_code;
+ uint64_t rip;
+ uint64_t cs;
+ uint64_t rflags;
+#else
uint32_t vector;
uint32_t error_code;
uint32_t eip;
uint32_t cs;
uint32_t eflags;
+#endif
};
#endif // !ASSEMBLER
--
To view, visit https://review.coreboot.org/c/coreboot/+/30117
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Idd12c90a95cc2989eb9b2a718740a84222193f48
Gerrit-Change-Number: 30117
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <siro at das-labor.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20181209/8b4d2c6b/attachment-0001.html>
More information about the coreboot-gerrit
mailing list