cpukit/score/cpu/x86_64: Add the exception frame

The port carried the CPU_Exception_frame of the no_cpu port, a processor
state register with one integer and one floating point register, and an
empty _CPU_Exception_frame_print().  Nothing could report what a
processor exception was.

Describe the frame which the exception prologues of a BSP build: the
general purpose registers, the vector, the error code and the five
members the processor pushes.  Print it.

Update #5692.

Assisted-by: Claude:claude-opus-5 claude-code
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
This commit is contained in:
Sebastian Huber authored and Joel Sherrill committed 2026-08-20 17:42:07 -05:00
1 parent 10824efa89
commit ce6e17faea
2 files changed
+96 -4

No files matched your search

+67 -1
View File
@@ -41,9 +41,75 @@
#include <rtems/score/isr.h>
#include <rtems/score/tls.h>
#include <rtems/bspIo.h>
#include <inttypes.h>
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;
@@ -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(