@@ -347,7 +347,7 @@ except: /*
347
347
* already there from hardware trap and EXCEPT_*() stub.
348
348
*/
349
349
350
- pushq %r15
350
+ pushq %r11
351
351
352
352
#ifdef CONFIG_USERSPACE
353
353
/* Swap GS register values and page tables if we came from user mode */
@@ -356,81 +356,86 @@ except: /*
356
356
swapgs
357
357
#ifdef CONFIG_X86_KPTI
358
358
/* Load kernel's page table */
359
- movq $z_x86_kernel_ptables, %r15
360
- movq %r15 , %cr3
359
+ movq $z_x86_kernel_ptables, %r11
360
+ movq %r11 , %cr3
361
361
#endif /* CONFIG_X86_KPTI */
362
362
1:
363
363
#ifdef CONFIG_X86_BOUNDS_CHECK_BYPASS_MITIGATION
364
364
/* swapgs variant of Spectre V1. Disable speculation past this point */
365
365
lfence
366
366
#endif /* CONFIG_X86_BOUNDS_CHECK_BYPASS_MITIGATION */
367
367
#ifdef CONFIG_X86_KPTI
368
- /* Save old trampoline stack pointer in R15 */
369
- movq %rsp , %r15
368
+ /* Save old trampoline stack pointer in R11 */
369
+ movq %rsp , %r11
370
370
371
371
/* Switch to the exception stack */
372
372
movq %gs :__x86_tss64_t_ist7_OFFSET, %rsp
373
373
374
374
/* Transplant trampoline stack contents */
375
- pushq 56 (%r15 ) /* SS */
376
- pushq 48 (%r15 ) /* RSP */
377
- pushq 40 (%r15 ) /* RFLAGS */
378
- pushq 32 (%r15 ) /* CS */
379
- pushq 24 (%r15 ) /* RIP */
380
- pushq 16 (%r15 ) /* Error code */
381
- pushq 8 (%r15 ) /* Vector */
382
- pushq (%r15 ) /* Stashed R15 */
383
- movq $0 , (%r15 ) /* Cover our tracks */
375
+ pushq 56 (%r11 ) /* SS */
376
+ pushq 48 (%r11 ) /* RSP */
377
+ pushq 40 (%r11 ) /* RFLAGS */
378
+ pushq 32 (%r11 ) /* CS */
379
+ pushq 24 (%r11 ) /* RIP */
380
+ pushq 16 (%r11 ) /* Error code */
381
+ pushq 8 (%r11 ) /* Vector */
382
+ pushq (%r11 ) /* Stashed R15 */
383
+ movq $0 , (%r11 ) /* Cover our tracks */
384
384
385
385
/* We're done, it's safe to re-enable interrupts. */
386
386
sti
387
387
#endif /* CONFIG_X86_KPTI */
388
388
#endif /* CONFIG_USERSPACE */
389
389
390
+ /* In addition to r11, push the rest of the caller-saved regs */
391
+ /* Positioning of this fxsave is important, RSP must be 16-byte
392
+ * aligned
393
+ */
390
394
subq $X86_FXSAVE_SIZE, %rsp
391
395
fxsave (%rsp )
392
- pushq %r14
393
- pushq %r13
394
- pushq %r12
395
- pushq %r11
396
396
pushq %r10
397
397
pushq %r9
398
398
pushq %r8
399
399
pushq %rdi
400
400
pushq %rsi
401
- pushq %rbp
402
401
pushq %rdx
403
402
pushq %rcx
404
- pushq %rbx
405
403
pushq %rax
406
-
404
+ #ifdef CONFIG_EXCEPTION_DEBUG
405
+ /* Callee saved regs */
406
+ pushq %r15
407
+ pushq %r14
408
+ pushq %r13
409
+ pushq %r12
410
+ pushq %rbp
411
+ pushq %rbx
412
+ #endif /* CONFIG_EXCEPTION_DEBUG */
407
413
movq %rsp , %rdi
408
414
409
- /* TODO we don't need to push so many registers if we are not
410
- * dumping out exception info since RBX, RBP, R12-R15 are callee-saved
411
- */
412
415
call z_x86_exception
413
416
414
417
/* If we returned, the exception was handled successfully and the
415
418
* thread may resume (the pushed RIP may have been modified)
416
419
*/
417
- popq %rax
420
+ #ifdef CONFIG_EXCEPTION_DEBUG
418
421
popq %rbx
422
+ popq %rbp
423
+ popq %r12
424
+ popq %r13
425
+ popq %r14
426
+ popq %r15
427
+ #endif /* CONFIG_EXCEPTION_DEBUG */
428
+ popq %rax
419
429
popq %rcx
420
430
popq %rdx
421
- popq %rbp
422
431
popq %rsi
423
432
popq %rdi
424
433
popq %r8
425
434
popq %r9
426
435
popq %r10
427
- popq %r11
428
- popq %r12
429
- popq %r13
430
- popq %r14
431
436
fxrstor (%rsp )
432
437
addq $X86_FXSAVE_SIZE, %rsp
433
- popq %r15
438
+ popq %r11
434
439
435
440
/* Drop the vector/err code pushed by the HW or EXCEPT_*() stub */
436
441
add $16 , %rsp
0 commit comments