From: Andrew Cooper Date: Thu, 28 Apr 2016 13:24:06 +0000 (+0100) Subject: Helper routines for decoding x86 architectural state X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8a1bc385be6f4593f30cc3d38787aff929647f06;p=people%2Froyger%2Fxen-test-framework.git Helper routines for decoding x86 architectural state Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/decode.c b/arch/x86/decode.c new file mode 100644 index 0000000..2fb65b8 --- /dev/null +++ b/arch/x86/decode.c @@ -0,0 +1,73 @@ +/** + * @file arch/x86/decode.c + * + * Helper routines for decoding x86 architectural state. + */ +#include +#include + +#include +#include + +const char *x86_exc_short_name(unsigned int exc) +{ + static const char *const names[] = + { +/** @cond */ +#define NAME(x) [X86_EXC_ ## x] = "#" #x + NAME(DE), NAME(DB), NAME(NMI), NAME(BP), NAME(OF), NAME(BR), + NAME(UD), NAME(NM), NAME(DF), NAME(CSO), NAME(TS), NAME(NP), + NAME(SS), NAME(GP), NAME(PF), NAME(SPV), NAME(MF), NAME(AC), + NAME(MC), NAME(XM), NAME(VE), +#undef NAME +/** @endcond */ + }; + + return (exc < ARRAY_SIZE(names) && names[exc]) ? names[exc] : "??"; +} + +int x86_exc_decode_ec(char *buf, size_t bufsz, unsigned int ev, unsigned int ec) +{ + switch ( ev ) + { + case X86_EXC_PF: + return snprintf(buf, bufsz, "%c%c%c%c%c%c", + ec & X86_PFEC_PK ? 'K' : '-', + ec & X86_PFEC_INSN ? 'I' : 'd', + ec & X86_PFEC_RSVD ? 'R' : '-', + ec & X86_PFEC_USER ? 'U' : 's', + ec & X86_PFEC_WRITE ? 'W' : 'r', + ec & X86_PFEC_PRESENT ? 'P' : '-'); + + case X86_EXC_TS: case X86_EXC_NP: case X86_EXC_SS: + case X86_EXC_GP: case X86_EXC_AC: + if ( ec != 0 ) + { + if ( ec & X86_EC_IDT ) + return snprintf(buf, bufsz, + "IDT vec %u%s", + ec >> X86_EC_SEL_SHIFT, + ec & X86_EC_EXT ? " EXT" : ""); + else + return snprintf(buf, bufsz, + "%cDT sel %#x%s", + ec & X86_EC_TI ? 'L' : 'G', + ec & X86_EC_SEL_MASK, + ec & X86_EC_EXT ? " EXT" : ""); + } + + /* Fallthrough */ + default: + return snprintf(buf, bufsz, "%04x", ec); + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/build/files.mk b/build/files.mk index ea34b8b..4c05a49 100644 --- a/build/files.mk +++ b/build/files.mk @@ -14,6 +14,7 @@ obj-perarch += $(ROOT)/common/libc/vsnprintf.o obj-perarch += $(ROOT)/common/report.o obj-perarch += $(ROOT)/common/setup.o +obj-perenv += $(ROOT)/arch/x86/decode.o obj-perenv += $(ROOT)/arch/x86/desc.o obj-perenv += $(ROOT)/arch/x86/hypercall_page.o obj-perenv += $(ROOT)/arch/x86/setup.o diff --git a/include/arch/x86/decode.h b/include/arch/x86/decode.h new file mode 100644 index 0000000..3146b2a --- /dev/null +++ b/include/arch/x86/decode.h @@ -0,0 +1,41 @@ +/** + * @file include/arch/x86/decode.h + * + * Helper routines for decoding x86 architectural state. + */ +#ifndef XTF_X86_DECODE_H +#define XTF_X86_DECODE_H + +#include + +/** + * String abbreviation of @p ev. + * + * @param ev Entry Vector. + * @return String abbreviation. + */ +const char *x86_exc_short_name(unsigned int ev); + +/** + * Decodes an x86 error code into a readable form. + * + * @param buf Buffer to fill. + * @param bufsz Size of @p buf. + * @param ev Entry Vector. + * @param ec Error Code. + * @return snprintf(buf, bufsz, ...) + */ +int x86_exc_decode_ec(char *buf, size_t bufsz, + unsigned int ev, unsigned int ec); + +#endif /* XTF_X86_DECODE_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/arch/x86/processor.h b/include/arch/x86/processor.h index 62ea832..c9f253f 100644 --- a/include/arch/x86/processor.h +++ b/include/arch/x86/processor.h @@ -132,11 +132,20 @@ #define X86_EC_TI (1U << 2) /* Only if !IDT. LDT or GDT. */ /* Segment-based Error Code - supplemental constants. */ -#define X86_EC_TABLE_MASK (3U << 1) -#define X86_EC_SEL_MASK (-1L << 3) +#define X86_EC_TABLE_MASK (3 << 1) +#define X86_EC_SEL_SHIFT 3 +#define X86_EC_SEL_MASK (-1 << X86_EC_SEL_SHIFT) #define X86_EC_GDT 0 #define X86_EC_LDT X86_EC_TI +/* Pagefault Error Code - architecturally defined. */ +#define X86_PFEC_PRESENT (1U << 0) +#define X86_PFEC_WRITE (1U << 1) +#define X86_PFEC_USER (1U << 2) +#define X86_PFEC_RSVD (1U << 3) +#define X86_PFEC_INSN (1U << 4) +#define X86_PFEC_PK (1U << 5) + #endif /* XTF_X86_PROCESSOR_H */ /*