github.com/jspc/eggos@v0.5.1-0.20221028160421-556c75c878a5/kernel/syscall.s (about)

     1  #include "textflag.h"
     2  
     3  #define tls_my 0
     4  #define tls_ax 8
     5  #define m_kstack 40
     6  #define ucode_idx  3
     7  #define udata_idx  4
     8  #define rpl_user   3
     9  
    10  #define SYS_clockgettime 228
    11  
    12  TEXT ·syscallEntry(SB), NOSPLIT, $0
    13  	// save AX
    14  	MOVQ AX, tls_ax(GS)
    15  
    16  	// AX == pointer of current thread
    17  	MOVQ tls_my(GS), AX
    18  
    19  	// AX == kernel stack
    20  	MOVQ m_kstack(AX), AX
    21  
    22  	// push regs like INT 0x80
    23  	SUBQ $40, AX
    24  
    25  	// CX store IP
    26  	MOVQ CX, 0(AX)
    27  
    28  	// save CS
    29  	MOVQ $ucode_idx<<3|rpl_user, 8(AX)
    30  
    31  	// R11 store FLAGS
    32  	MOVQ R11, 16(AX)
    33  
    34  	// save SP
    35  	MOVQ SP, 24(AX)
    36  
    37  	// save SS
    38  	MOVQ $udata_idx<<3|rpl_user, 32(AX)
    39  
    40  	// change SP
    41  	MOVQ AX, SP
    42  
    43  	// restore AX
    44  	MOVQ tls_ax(GS), AX
    45  
    46  	// jmp INT 0x80
    47  	JMP ·trap128(SB)
    48  
    49  TEXT ·vdsoGettimeofday(SB), NOSPLIT, $0
    50  	MOVQ $SYS_clockgettime, AX
    51  
    52  	// DI store *TimeSpec, but clockgettime need SI
    53  	MOVQ DI, SI
    54  	MOVQ $0, DI
    55  	INT  $0x80
    56  	RET
    57