xref: /linux/tools/testing/selftests/kvm/lib/x86/handlers.S (revision 1260ed77798502de9c98020040d2995008de10cc)
1*67730e6cSSean Christophersonhandle_exception:
2*67730e6cSSean Christopherson	push %r15
3*67730e6cSSean Christopherson	push %r14
4*67730e6cSSean Christopherson	push %r13
5*67730e6cSSean Christopherson	push %r12
6*67730e6cSSean Christopherson	push %r11
7*67730e6cSSean Christopherson	push %r10
8*67730e6cSSean Christopherson	push %r9
9*67730e6cSSean Christopherson	push %r8
10*67730e6cSSean Christopherson
11*67730e6cSSean Christopherson	push %rdi
12*67730e6cSSean Christopherson	push %rsi
13*67730e6cSSean Christopherson	push %rbp
14*67730e6cSSean Christopherson	push %rbx
15*67730e6cSSean Christopherson	push %rdx
16*67730e6cSSean Christopherson	push %rcx
17*67730e6cSSean Christopherson	push %rax
18*67730e6cSSean Christopherson	mov %rsp, %rdi
19*67730e6cSSean Christopherson
20*67730e6cSSean Christopherson	call route_exception
21*67730e6cSSean Christopherson
22*67730e6cSSean Christopherson	pop %rax
23*67730e6cSSean Christopherson	pop %rcx
24*67730e6cSSean Christopherson	pop %rdx
25*67730e6cSSean Christopherson	pop %rbx
26*67730e6cSSean Christopherson	pop %rbp
27*67730e6cSSean Christopherson	pop %rsi
28*67730e6cSSean Christopherson	pop %rdi
29*67730e6cSSean Christopherson	pop %r8
30*67730e6cSSean Christopherson	pop %r9
31*67730e6cSSean Christopherson	pop %r10
32*67730e6cSSean Christopherson	pop %r11
33*67730e6cSSean Christopherson	pop %r12
34*67730e6cSSean Christopherson	pop %r13
35*67730e6cSSean Christopherson	pop %r14
36*67730e6cSSean Christopherson	pop %r15
37*67730e6cSSean Christopherson
38*67730e6cSSean Christopherson	/* Discard vector and error code. */
39*67730e6cSSean Christopherson	add $16, %rsp
40*67730e6cSSean Christopherson	iretq
41*67730e6cSSean Christopherson
42*67730e6cSSean Christopherson/*
43*67730e6cSSean Christopherson * Build the handle_exception wrappers which push the vector/error code on the
44*67730e6cSSean Christopherson * stack and an array of pointers to those wrappers.
45*67730e6cSSean Christopherson */
46*67730e6cSSean Christopherson.pushsection .rodata
47*67730e6cSSean Christopherson.globl idt_handlers
48*67730e6cSSean Christophersonidt_handlers:
49*67730e6cSSean Christopherson.popsection
50*67730e6cSSean Christopherson
51*67730e6cSSean Christopherson.macro HANDLERS has_error from to
52*67730e6cSSean Christopherson	vector = \from
53*67730e6cSSean Christopherson	.rept \to - \from + 1
54*67730e6cSSean Christopherson	.align 8
55*67730e6cSSean Christopherson
56*67730e6cSSean Christopherson	/* Fetch current address and append it to idt_handlers. */
57*67730e6cSSean Christopherson666 :
58*67730e6cSSean Christopherson.pushsection .rodata
59*67730e6cSSean Christopherson	.quad 666b
60*67730e6cSSean Christopherson.popsection
61*67730e6cSSean Christopherson
62*67730e6cSSean Christopherson	.if ! \has_error
63*67730e6cSSean Christopherson	pushq $0
64*67730e6cSSean Christopherson	.endif
65*67730e6cSSean Christopherson	pushq $vector
66*67730e6cSSean Christopherson	jmp handle_exception
67*67730e6cSSean Christopherson	vector = vector + 1
68*67730e6cSSean Christopherson	.endr
69*67730e6cSSean Christopherson.endm
70*67730e6cSSean Christopherson
71*67730e6cSSean Christopherson.global idt_handler_code
72*67730e6cSSean Christophersonidt_handler_code:
73*67730e6cSSean Christopherson	HANDLERS has_error=0 from=0  to=7
74*67730e6cSSean Christopherson	HANDLERS has_error=1 from=8  to=8
75*67730e6cSSean Christopherson	HANDLERS has_error=0 from=9  to=9
76*67730e6cSSean Christopherson	HANDLERS has_error=1 from=10 to=14
77*67730e6cSSean Christopherson	HANDLERS has_error=0 from=15 to=16
78*67730e6cSSean Christopherson	HANDLERS has_error=1 from=17 to=17
79*67730e6cSSean Christopherson	HANDLERS has_error=0 from=18 to=255
80*67730e6cSSean Christopherson
81*67730e6cSSean Christopherson.section        .note.GNU-stack, "", %progbits
82