github.com/icexin/eggos@v0.4.2-0.20220216025428-78b167e4f349/kernel/thread.s (about) 1 #include "textflag.h" 2 3 #define SYS_clone 56 4 #define SYS_sched_yield 24 5 6 #define tls_my 0 7 8 // func swtch(old **context, _new *context) 9 TEXT ·swtch(SB), NOSPLIT, $0-16 10 MOVQ old+0(FP), AX 11 MOVQ _new+8(FP), DX 12 13 // Save old callee-saved registers 14 PUSHQ BP 15 PUSHQ BX 16 PUSHQ R11 17 PUSHQ R12 18 PUSHQ R13 19 PUSHQ R14 20 PUSHQ R15 21 22 // Switch stacks 23 MOVQ SP, (AX) 24 MOVQ DX, SP 25 26 POPQ R15 27 POPQ R14 28 POPQ R13 29 POPQ R12 30 POPQ R11 31 POPQ BX 32 POPQ BP 33 RET 34 35 // Mythread() uint64 36 TEXT ·Mythread(SB), NOSPLIT, $0-8 37 MOVQ tls_my(GS), AX 38 MOVQ AX, ret+0(FP) 39 RET 40 41 // ksysClone(pc, stack, flags uint64) (ax uint64) invokes SYS_clone. 42 TEXT ·ksysClone(SB), NOSPLIT, $0-32 43 MOVQ $SYS_clone, AX 44 MOVQ pc+0(FP), R12 45 MOVQ stack+8(FP), SI 46 MOVQ flags+16(FP), DI 47 48 // clear tls 49 XORQ R8, R8 50 51 INT $0x80 52 53 // In parent, return. 54 CMPQ AX, $0 55 JEQ 3(PC) 56 MOVQ AX, ret+24(FP) 57 RET 58 59 NOP SP // tell vet SP changed - stop checking offsets 60 JMP R12 61 62 // ksysYield invokes SYS_sched_yield. 63 TEXT ·ksysYield(SB), NOSPLIT, $0 64 MOVQ $SYS_sched_yield, AX 65 INT $0x80 66 RET