From: Andrew Cooper Date: Mon, 14 Dec 2015 09:00:02 +0000 (+0000) Subject: Represent exception frames in C X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e38d284a65e296c3b97ee69bcee94740e038be63;p=people%2Froyger%2Fxen-test-framework.git Represent exception frames in C Introduce struct cpu_regs, and make the entry points create the expected layout. As part of this, split the very x86 bits of asm_macros.h into a new header file. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/entry_32.S b/arch/x86/entry_32.S index c904257..e46057e 100644 --- a/arch/x86/entry_32.S +++ b/arch/x86/entry_32.S @@ -60,5 +60,9 @@ exception_entry VE X86_EXC_VE .align 16 handle_exception: + SAVE_ALL + + push %esp /* struct cpu_regs * */ call do_exception + add $4, %esp ud2a diff --git a/arch/x86/entry_64.S b/arch/x86/entry_64.S index b0229f3..826bfd7 100644 --- a/arch/x86/entry_64.S +++ b/arch/x86/entry_64.S @@ -71,5 +71,8 @@ exception_entry VE X86_EXC_VE .align 16 handle_exception: + SAVE_ALL + + mov %rsp, %rdi /* struct cpu_regs * */ call do_exception ud2a diff --git a/arch/x86/traps.c b/arch/x86/traps.c index 710003b..f46190e 100644 --- a/arch/x86/traps.c +++ b/arch/x86/traps.c @@ -5,9 +5,10 @@ * C entry-point for exceptions, after the per-environment stubs have suitably * adjusted the stack. */ -void do_exception(void) +void do_exception(struct cpu_regs *regs) { - panic("Unhandled exception\n"); + panic("Unhandled exception: vec %u at %04x:%p\n", + regs->entry_vector, regs->cs, _p(regs->ip)); } /* diff --git a/include/arch/x86/asm_macros.h b/include/arch/x86/asm_macros.h new file mode 100644 index 0000000..f0da23d --- /dev/null +++ b/include/arch/x86/asm_macros.h @@ -0,0 +1,89 @@ +/** + * @file include/arch/x86/asm_macros.h + * + * Macros for use in x86 assembly files. + */ +#ifndef XTF_X86_ASM_MACROS_H +#define XTF_X86_ASM_MACROS_H + +/* Declare data at the architectures width. */ +#if defined(__x86_64__) +# define _WORD .quad +#elif defined(__i386__) +# define _WORD .long +#else +# error Bad architecture for _WORD +#endif + +.macro SAVE_ALL + cld +#if defined(__x86_64__) + push %rdi + push %rsi + push %rdx + push %rcx + push %rax + push %r8 + push %r9 + push %r10 + push %r11 + push %rbx + push %rbp + push %r12 + push %r13 + push %r14 + push %r15 +#elif defined(__i386__) + push %edi + push %esi + push %edx + push %ecx + push %eax + push %ebx + push %ebp +#else +# error Bad architecture for SAVE_ALL +#endif +.endm + +.macro RESTORE_ALL +#if defined(__x86_64__) + pop %r15 + pop %r14 + pop %r13 + pop %r12 + pop %rbp + pop %rbx + pop %r11 + pop %r10 + pop %r9 + pop %r8 + pop %rax + pop %rcx + pop %rdx + pop %rsi + pop %rdi +#elif defined(__i386__) + pop %ebp + pop %ebx + pop %eax + pop %ecx + pop %edx + pop %esi + pop %edi +#else +# error Bad architecture for RESTORE_ALL +#endif +.endm + +#endif /* XTF_X86_ASM_MACROS_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/regs.h b/include/arch/x86/regs.h new file mode 100644 index 0000000..1fb5340 --- /dev/null +++ b/include/arch/x86/regs.h @@ -0,0 +1,78 @@ +#ifndef XTF_X86_REGS_H +#define XTF_X86_REGS_H + +#include + +#if defined(__i386__) + +#define DECL_REG(n) \ + union { uint32_t e ## n; unsigned long n; } + +struct cpu_regs { + DECL_REG(bp); + DECL_REG(bx); + DECL_REG(ax); + DECL_REG(cx); + DECL_REG(dx); + DECL_REG(si); + DECL_REG(di); + + uint32_t entry_vector; + uint32_t error_code; + +/* Hardware exception frame. */ + DECL_REG(ip); + uint16_t cs, _pad1[1]; + DECL_REG(flags); + DECL_REG(sp); /* Won't be valid if stack */ + uint16_t ss, _pad0[1]; /* switch didn't occur. */ +/* Top of stack. */ +}; + +#elif defined(__x86_64__) + +#define DECL_REG(n) \ + union { uint64_t r ## n; uint32_t e ## n; unsigned long n; } + +struct cpu_regs { + uint64_t r15; + uint64_t r14; + uint64_t r13; + uint64_t r12; + DECL_REG(bp); + DECL_REG(bx); + uint64_t r11; + uint64_t r10; + uint64_t r9; + uint64_t r8; + DECL_REG(ax); + DECL_REG(cx); + DECL_REG(dx); + DECL_REG(si); + DECL_REG(di); + + uint32_t error_code; + uint32_t entry_vector; + +/* Hardware exception frame. */ + DECL_REG(ip); + uint16_t cs, _pad1[3]; + DECL_REG(flags); + DECL_REG(sp); + uint16_t ss, _pad0[3]; +/* Top of stack. */ +}; + +#endif /* __i386__ / __x86_64__ */ + +#endif /* XTF_X86_REGS_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/traps.h b/include/arch/x86/traps.h index 0a88cec..53eabb7 100644 --- a/include/arch/x86/traps.h +++ b/include/arch/x86/traps.h @@ -2,6 +2,7 @@ #define XTF_X86_TRAPS_H #include +#include /* * Arch-specific function to initialise the exception entry points, etc. diff --git a/include/xtf/asm_macros.h b/include/xtf/asm_macros.h index 5b41fc5..96a5fec 100644 --- a/include/xtf/asm_macros.h +++ b/include/xtf/asm_macros.h @@ -8,14 +8,7 @@ #include -/* Declare data at the architectures width. */ -#if defined(__x86_64__) -# define _WORD .quad -#elif defined(__i386__) -# define _WORD .long -#else -# error Bad architecture for _WORD -#endif +#include /** * Declare a global symbol. diff --git a/include/xtf/numbers.h b/include/xtf/numbers.h index aa36f40..c237900 100644 --- a/include/xtf/numbers.h +++ b/include/xtf/numbers.h @@ -22,6 +22,8 @@ #define GB(num) (_AC(num, ULL) << 30) #define TB(num) (_AC(num, ULL) << 40) +#define _p(v) ((void*)(unsigned long)(v)) + #endif /* XTF_NUMBERS_H */ /*