From b39acb2afd2a1cdabfd32932db63cb9f7012b741 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 10 Sep 2023 16:36:43 -0400 Subject: [PATCH] Cleanup docs in assembly routines. --- sys/amd64/switch.S | 4 +++- sys/amd64/trapentry.S | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sys/amd64/switch.S b/sys/amd64/switch.S index 9b2b375..83f7f88 100644 --- a/sys/amd64/switch.S +++ b/sys/amd64/switch.S @@ -10,6 +10,7 @@ # %rdi: oldsp # %rsi: newsp FUNC_BEGIN(switchstack) + # Save callee saved registers of old thread pushq %rbp pushq %rdi pushq %rbx @@ -18,10 +19,11 @@ FUNC_BEGIN(switchstack) pushq %r14 pushq %r15 - # Switch stack + # Switch stack from old to new thread movq %rsp, (%rdi) movq %rsi, %rsp + # Restore callee saved registers of new thread popq %r15 popq %r14 popq %r13 diff --git a/sys/amd64/trapentry.S b/sys/amd64/trapentry.S index 981095d..652a9af 100644 --- a/sys/amd64/trapentry.S +++ b/sys/amd64/trapentry.S @@ -8,6 +8,7 @@ .macro TRAP_NOEC TRAPNUM trap\TRAPNUM: + # Push top of the trap frame pushq %rax pushq $\TRAPNUM pushq %rax @@ -19,6 +20,7 @@ trap\TRAPNUM: .macro TRAP_EC TRAPNUM trap\TRAPNUM: + # Push top of the trap frame pushq $\TRAPNUM pushq %rax xorq %rax, %rax @@ -160,6 +162,7 @@ TRAP_NOEC 62 TRAP_NOEC 63 trap_common: + # Create the rest of the trap frame pushq %rbx pushq %rcx pushq %rdx @@ -174,6 +177,8 @@ trap_common: pushq %r13 pushq %r14 pushq %r15 + + # Pass the trap frame as an argument to trap_entry movq %rsp, %rdi call trap_entry .globl trap_return @@ -195,7 +200,11 @@ trap_return: popq %rax movw %ax, %ds popq %rax - addq $16, %rsp // Skip error code and vector number + + # Skip error code and vector number + addq $16, %rsp + + # Return to userspace iretq .globl Trap_Pop