Changeset a7220de in mainline


Ignore:
Timestamp:
2010-07-14T12:15:10Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c8cd9a8
Parents:
0d1e976
Message:

Rewrite syscall_entry() to use the istate structure and save all GPRs in it.

Location:
kernel/arch/amd64/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/asm.S

    r0d1e976 ra7220de  
    334334        movq %gs:8, %rsp  /* set this thread's kernel RSP */
    335335       
    336         /* Switch back to remain consistent */
     336        /*
     337         * Note that the space needed for the imitated istate structure has been
     338         * preallocated for us in thread_create_arch() and set in
     339         * before_thread_runs_arch().
     340         */
     341
     342        /*
     343         * Save the general purpose registers and push the 7th argument (syscall
     344         * number) onto the stack. Note that the istate structure has a layout
     345         * which supports this.
     346         */
     347        movq %rax, ISTATE_OFFSET_RAX(%rsp)  /* 7th argument, passed on stack */
     348        movq %rbx, ISTATE_OFFSET_RBX(%rsp)  /* observability */
     349        movq %rcx, ISTATE_OFFSET_RCX(%rsp)  /* userspace RIP */
     350        movq %rdx, ISTATE_OFFSET_RDX(%rsp)  /* 3rd argument, observability */
     351        movq %rsi, ISTATE_OFFSET_RSI(%rsp)  /* 2nd argument, observability */
     352        movq %rdi, ISTATE_OFFSET_RDI(%rsp)  /* 1st argument, observability */
     353        movq %rbp, ISTATE_OFFSET_RBP(%rsp)  /* need to preserve userspace RBP */
     354        movq %r8, ISTATE_OFFSET_R8(%rsp)    /* 5th argument, observability */
     355        movq %r9, ISTATE_OFFSET_R9(%rsp)    /* 6th argument, observability */
     356        movq %r10, ISTATE_OFFSET_R10(%rsp)  /* 4th argument, observability */
     357        movq %r11, ISTATE_OFFSET_R11(%rsp)  /* low 32 bits userspace RFLAGS */
     358        movq %r12, ISTATE_OFFSET_R12(%rsp)  /* observability */
     359        movq %r13, ISTATE_OFFSET_R13(%rsp)  /* observability */
     360        movq %r14, ISTATE_OFFSET_R14(%rsp)  /* observability */
     361        movq %r15, ISTATE_OFFSET_R15(%rsp)  /* observability */
     362
     363        /*
     364         * Save the return address and the userspace stack on locations that
     365         * would normally be taken by them.
     366         */
     367        movq %gs:0, %rax
     368        movq %rax, ISTATE_OFFSET_RSP(%rsp)
     369        movq %rcx, ISTATE_OFFSET_RIP(%rsp)
     370
     371        /*
     372         * Imitate a regular stack frame linkage.
     373         */
     374        movq $0, ISTATE_OFFSET_RBP_FRAME(%rsp)
     375        movq %rcx, ISTATE_OFFSET_RIP_FRAME(%rsp)
     376        leaq ISTATE_OFFSET_RBP_FRAME(%rsp), %rbp
     377
     378        /* Switch back to normal %gs */
    337379        swapgs
    338380        sti
    339381       
    340         pushq %rcx
    341         pushq %r11
    342         pushq %rbp
    343        
    344         xorq %rbp, %rbp  /* stop the stack traces here */
    345        
    346382        /* Copy the 4th argument where it is expected  */
    347383        movq %r10, %rcx
    348         pushq %rax
    349        
     384
     385        /*
     386         * Call syscall_handler() with the 7th argument passed on stack.
     387         */
    350388        call syscall_handler
    351389       
    352         addq $8, %rsp
    353        
    354         popq %rbp
    355         popq %r11
    356         popq %rcx
    357        
    358390        cli
    359         swapgs
    360        
    361         /* Restore the user RSP */
    362         movq %gs:0, %rsp
    363         swapgs
    364        
     391       
     392        /*
     393         * Restore registers needed for return via the SYSRET instruction and
     394         * the clobbered preserved registers (i.e. RBP).
     395         */
     396        movq ISTATE_OFFSET_RBP(%rsp), %rbp
     397        movq ISTATE_OFFSET_RCX(%rsp), %rcx
     398        movq ISTATE_OFFSET_R11(%rsp), %r11
     399        movq ISTATE_OFFSET_RSP(%rsp), %rsp
     400
    365401        sysretq
    366402
  • kernel/arch/amd64/src/proc/thread.c

    r0d1e976 ra7220de  
    3434
    3535#include <proc/thread.h>
     36#include <arch/interrupt.h>
    3637
    3738/** Perform amd64 specific thread initialization.
     
    4950         */
    5051        thread->arch.syscall_rsp[SYSCALL_KSTACK_RSP] =
    51             (uintptr_t) &thread->kstack[PAGE_SIZE - sizeof(uint64_t)];
     52            (uintptr_t) &thread->kstack[PAGE_SIZE - sizeof(istate_t)];
    5253}
    5354
Note: See TracChangeset for help on using the changeset viewer.