x86: move declaration of the exception_table to C
PATCH v2 1/1 x86: move declaration of the exception_table to C
This makes the code cleaner because there's no need to declare the exception_table in assembly, and also fixes the following error when using clang's integrated assembler:
entry.S:834:15: error: unexpected token in '.rept' directive
.rept 32 - ((. - exception_table) / 8)
^
entry.S:836:14: error: unmatched '.endr' directive
.endr
^This should be a non-functional change.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
---
Changes since v1:
- Cast to void *.
- Align assignments.
- Use ARRAY_SIZE instead of TRAP_nr.
--- xen/arch/x86/traps.c | 20 ++++++++++++++++++++ xen/arch/x86/x86_64/entry.S | 30 ------------------------------ xen/include/asm-x86/processor.h | 1 + 3 files changed, 21 insertions(+), 30 deletions(-)
xen/arch/x86/traps.c +20 -0
@@ -119,6 +119,26 @@ boolean_param("ler", opt_ler);#define stack_words_per_line 4#define ESP_BEFORE_EXCEPTION (regs) ((unsigned long *)regs->rsp) +void (*const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = { + [TRAP_divide_error] = do_trap, + [TRAP_debug] = do_debug, + [TRAP_nmi] = (void *)do_nmi, + [TRAP_int3] = do_int3, + [TRAP_overflow ... TRAP_bounds] = do_trap, + [TRAP_invalid_op] = do_invalid_op, + [TRAP_no_device] = do_device_not_available, + [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap, + [TRAP_invalid_tss ... TRAP_stack_error] = do_trap, + [TRAP_gp_fault] = do_general_protection, + [TRAP_page_fault] = do_page_fault, + [TRAP_spurious_int] = do_reserved_trap, + [TRAP_copro_error ... TRAP_alignment_check] = do_trap, + [TRAP_machine_check] = (void *)do_machine_check, + [TRAP_simd_error] = do_trap, + [TRAP_virtualisation ... + (ARRAY_SIZE (exception_table) -1 )] = do_reserved_trap, +}; +static void show_code (const struct cpu_user_regs *regs) {unsigned char insns_before[8 ] = {}, insns_after[16 ] = {};
xen/arch/x86/x86_64/entry.S +0 -30
@@ -806,36 +806,6 @@ ENTRY(enable_nmis) GLOBAL(trap_nop) iretq - - -.section .rodata, "a", @progbits - -ENTRY(exception_table) - .quad do_trap - .quad do_debug - .quad do_nmi - .quad do_int3 - .quad do_trap - .quad do_trap - .quad do_invalid_op - .quad do_device_not_available - .quad do_reserved_trap /* double_fault - has its own entry. */ - .quad do_reserved_trap /* coproc_seg_overrun - Intel 387 only. */ - .quad do_trap - .quad do_trap - .quad do_trap - .quad do_general_protection - .quad do_page_fault - .quad do_reserved_trap /* Default PIC spurious irq - architecturally reserved. */ - .quad do_trap - .quad do_trap - .quad do_machine_check - .quad do_trap - .rept TRAP_nr - ((. - exception_table) / 8) - .quad do_reserved_trap /* Architecturally reserved exceptions. */ - .endr - .size exception_table, . - exception_table - /* Table of automatically generated entry points. One per vector. */ .section .init.rodata, "a", @progbits GLOBAL(autogen_entrypoints)
xen/include/asm-x86/processor.h +1 -0
@@ -501,6 +501,7 @@ DECLARE_TRAP_HANDLER(entry_int82);void trap_nop (void );void enable_nmis (void ); +void do_trap (struct cpu_user_regs *regs);void do_reserved_trap (struct cpu_user_regs *regs);void sysenter_entry (void );
Signature · 7 lines
2.15.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 127
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 28.01.18 at 15:09, <[email protected]> wrote:
xen/arch/x86/traps.c +6
-0@@ -119,6 +119,26 @@ boolean_param("ler", opt_ler);#define stack_words_per_line 4#define ESP_BEFORE_EXCEPTION (regs) ((unsigned long *)regs->rsp) +void (*const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = { + [TRAP_divide_error] = do_trap, + [TRAP_debug] = do_debug, + [TRAP_nmi] = (void *)do_nmi, + [TRAP_int3] = do_int3, + [TRAP_overflow ... TRAP_bounds] = do_trap,
Please can you avoid ... here and below, such that e.g. grep-ing for one of the TRAP_* values will turn up the respective line here? I also consider this a little awkward if the range consists of just two elements.
xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 139
Quoted 12 lines
xen/arch/x86/traps.c +12
-0+ [TRAP_invalid_op] = do_invalid_op, + [TRAP_no_device] = do_device_not_available, + [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap, + [TRAP_invalid_tss ... TRAP_stack_error] = do_trap, + [TRAP_gp_fault] = do_general_protection, + [TRAP_page_fault] = do_page_fault, + [TRAP_spurious_int] = do_reserved_trap, + [TRAP_copro_error ... TRAP_alignment_check] = do_trap, + [TRAP_machine_check] = (void *)do_machine_check, + [TRAP_simd_error] = do_trap, + [TRAP_virtualisation ... + (ARRAY_SIZE(exception_table) - 1)] = do_reserved_trap,
This one, as an exception, is fine with me to use ... . Even better would be to have a [0 ... ARRAY_SIZE() - 1] initializer first, but iirc clang dislikes such.
xen/include/asm-x86/processor.h DECLARE_TRAP_HANDLER(entry_int82); · line 504
Quoted 7 lines
xen/include/asm-x86/processor.h +1
-0@@ -501,6 +501,7 @@ DECLARE_TRAP_HANDLER(entry_int82);void trap_nop (void );void enable_nmis (void ); +void do_trap (struct cpu_user_regs *regs);
No - afaict this function can be static to traps.c now.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.01.18 at 15:09, <[email protected]> wrote:
xen/arch/x86/traps.c +0
-0@@ -119,6 +119,26 @@ boolean_param("ler", opt_ler);#define stack_words_per_line 4#define ESP_BEFORE_EXCEPTION (regs) ((unsigned long *)regs->rsp)
Quoted 11 lines
xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 127
Quoted 6 lines
xen/arch/x86/traps.c +6
-0+void (*const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = { + [TRAP_divide_error] = do_trap, + [TRAP_debug] = do_debug, + [TRAP_nmi] = (void *)do_nmi, + [TRAP_int3] = do_int3, + [TRAP_overflow ... TRAP_bounds] = do_trap,Please can you avoid ... here and below, such that e.g. grep-ing for one of the TRAP_* values will turn up the respective line here? I also consider this a little awkward if the range consists of just two elements.
Sure. I agree it's important to make this table easily greppable.
Quoted 13 lines
xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 139
Quoted 12 lines
xen/arch/x86/traps.c +12
-0+ [TRAP_invalid_op] = do_invalid_op, + [TRAP_no_device] = do_device_not_available, + [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap, + [TRAP_invalid_tss ... TRAP_stack_error] = do_trap, + [TRAP_gp_fault] = do_general_protection, + [TRAP_page_fault] = do_page_fault, + [TRAP_spurious_int] = do_reserved_trap, + [TRAP_copro_error ... TRAP_alignment_check] = do_trap, + [TRAP_machine_check] = (void *)do_machine_check, + [TRAP_simd_error] = do_trap, + [TRAP_virtualisation ... + (ARRAY_SIZE(exception_table) - 1)] = do_reserved_trap,
Quoted 3 lines
This one, as an exception, is fine with me to use ... . Even better would be to have a [0 ...
ARRAY_SIZE()- 1] initializer first, but iirc clang dislikes such.
Right, then we would have to add -Wno-initializer-overrides to the command line.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel