diff --git a/cpukit/score/cpu/x86_64/cpu.c b/cpukit/score/cpu/x86_64/cpu.c index 725358c811..3e88931681 100644 --- a/cpukit/score/cpu/x86_64/cpu.c +++ b/cpukit/score/cpu/x86_64/cpu.c @@ -41,9 +41,75 @@ #include #include +#include + +#include + +static const char *const amd64_exception_names[] = { + "divide error", + "debug", + "non-maskable interrupt", + "breakpoint", + "overflow", + "bound range exceeded", + "invalid opcode", + "device not available", + "double fault", + "coprocessor segment overrun", + "invalid TSS", + "segment not present", + "stack-segment fault", + "general protection", + "page fault", + "reserved", + "x87 floating-point error", + "alignment check", + "machine check", + "SIMD floating-point error", + "virtualization", + "control protection", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "reserved", + "hypervisor injection", + "VMM communication", + "security", + "reserved" +}; + void _CPU_Exception_frame_print(const CPU_Exception_frame *ctx) { - (void) ctx; + const char *name; + + if (ctx->vector < RTEMS_ARRAY_SIZE(amd64_exception_names)) { + name = amd64_exception_names[ctx->vector]; + } else { + name = "unknown"; + } + + printk( + "exception vector: %" PRIu64 " (%s)\n" + "error code: 0x%016" PRIx64 "\n" + "RIP: 0x%016" PRIx64 " CS: 0x%016" PRIx64 "\n" + "RFLAGS: 0x%016" PRIx64 " RSP: 0x%016" PRIx64 " SS: 0x%016" PRIx64 "\n" + "RAX: 0x%016" PRIx64 " RBX: 0x%016" PRIx64 " RCX: 0x%016" PRIx64 "\n" + "RDX: 0x%016" PRIx64 " RSI: 0x%016" PRIx64 " RDI: 0x%016" PRIx64 "\n" + "RBP: 0x%016" PRIx64 " R8: 0x%016" PRIx64 " R9: 0x%016" PRIx64 "\n" + "R10: 0x%016" PRIx64 " R11: 0x%016" PRIx64 " R12: 0x%016" PRIx64 "\n" + "R13: 0x%016" PRIx64 " R14: 0x%016" PRIx64 " R15: 0x%016" PRIx64 "\n", + ctx->vector, name, + ctx->error_code, + ctx->rip, ctx->cs, + ctx->rflags, ctx->rsp, ctx->ss, + ctx->rax, ctx->rbx, ctx->rcx, + ctx->rdx, ctx->rsi, ctx->rdi, + ctx->rbp, ctx->r8, ctx->r9, + ctx->r10, ctx->r11, ctx->r12, + ctx->r13, ctx->r14, ctx->r15 + ); } Context_Control_fp _CPU_Null_fp_context; diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h index 9fb0b5db80..b1dd1a0d3b 100644 --- a/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h +++ b/cpukit/score/cpu/x86_64/include/rtems/score/cpu.h @@ -346,10 +346,36 @@ RTEMS_NO_RETURN void _CPU_Context_switch_no_return( RTEMS_NO_RETURN void _CPU_Context_restore( Context_Control *new_context ); +/* + * The exception prologue builds this frame on the stack of the interrupted + * context. The members up to and including the vector are pushed by the + * prologue, the members from the error code on are pushed by the processor. + * The processor pushes an error code for some vectors only, so the prologue + * pushes a zero for the others to give every vector the same frame. + */ typedef struct { - uint32_t processor_state_register; - uint32_t integer_registers [1]; - double float_registers [1]; + uint64_t rax; + uint64_t rbx; + uint64_t rcx; + uint64_t rdx; + uint64_t rsi; + uint64_t rdi; + uint64_t rbp; + uint64_t r8; + uint64_t r9; + uint64_t r10; + uint64_t r11; + uint64_t r12; + uint64_t r13; + uint64_t r14; + uint64_t r15; + uint64_t vector; + uint64_t error_code; + uint64_t rip; + uint64_t cs; + uint64_t rflags; + uint64_t rsp; + uint64_t ss; } CPU_Exception_frame; void _CPU_Context_save_fp(