Home | History | Annotate | Download | only in syscall
      1 // Copyright 2009 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP)
      6 // so that go vet can check that they are correct.
      7 
      8 #include "textflag.h"
      9 #include "funcdata.h"
     10 
     11 //
     12 // System call support for Plan 9
     13 //
     14 
     15 //func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err string)
     16 //func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err string)
     17 //func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
     18 //func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
     19 
     20 TEXT	Syscall(SB),NOSPLIT,$0-64
     21 	CALL	runtimeentersyscall(SB)
     22 	MOVQ	8(SP), BP	// syscall entry
     23 	// slide args down on top of system call number
     24 	LEAQ	16(SP), SI
     25 	LEAQ	8(SP), DI
     26 	CLD
     27 	MOVSQ
     28 	MOVSQ
     29 	MOVSQ
     30 	SYSCALL
     31 	MOVQ	AX, r1+40(SP)
     32 	MOVQ	$0, r2+48(SP)
     33 	CMPL	AX, $-1
     34 	JNE	ok3
     35 
     36 	SUBQ	$16, SP
     37 	CALL	runtimeerrstr(SB)
     38 	MOVQ	SP, SI
     39 	ADDQ	$16, SP
     40 	JMP	copyresult3
     41 
     42 ok3:
     43 	LEAQ	runtimeemptystring(SB), SI
     44 
     45 copyresult3:
     46 	LEAQ	err+56(SP), DI
     47 
     48 	CLD
     49 	MOVSQ
     50 	MOVSQ
     51 
     52 	CALL	runtimeexitsyscall(SB)
     53 	RET
     54 
     55 TEXT	Syscall6(SB),NOSPLIT,$0-88
     56 	CALL	runtimeentersyscall(SB)
     57 	MOVQ	8(SP), BP	// syscall entry
     58 	// slide args down on top of system call number
     59 	LEAQ		16(SP), SI
     60 	LEAQ		8(SP), DI
     61 	CLD
     62 	MOVSQ
     63 	MOVSQ
     64 	MOVSQ
     65 	MOVSQ
     66 	MOVSQ
     67 	MOVSQ
     68 	SYSCALL
     69 	MOVQ	AX, r1+64(SP)
     70 	MOVQ	$0, r2+72(SP)
     71 	CMPL	AX, $-1
     72 	JNE	ok4
     73 
     74 	SUBQ	$16, SP
     75 	CALL	runtimeerrstr(SB)
     76 	MOVQ	SP, SI
     77 	ADDQ	$16, SP
     78 	JMP	copyresult4
     79 
     80 ok4:
     81 	LEAQ	runtimeemptystring(SB), SI
     82 
     83 copyresult4:
     84 	LEAQ	err+80(SP), DI
     85 
     86 	CLD
     87 	MOVSQ
     88 	MOVSQ
     89 
     90 	CALL	runtimeexitsyscall(SB)
     91 	RET
     92 
     93 TEXT RawSyscall(SB),NOSPLIT,$0-56
     94 	MOVQ	8(SP), BP	// syscall entry
     95 	// slide args down on top of system call number
     96 	LEAQ		16(SP), SI
     97 	LEAQ		8(SP), DI
     98 	CLD
     99 	MOVSQ
    100 	MOVSQ
    101 	MOVSQ
    102 	SYSCALL
    103 	MOVQ	AX, r1+40(SP)
    104 	MOVQ	AX, r2+48(SP)
    105 	MOVQ	AX, err+56(SP)
    106 	RET
    107 
    108 TEXT	RawSyscall6(SB),NOSPLIT,$0-80
    109 	MOVQ	8(SP), BP	// syscall entry
    110 	// slide args down on top of system call number
    111 	LEAQ		16(SP), SI
    112 	LEAQ		8(SP), DI
    113 	CLD
    114 	MOVSQ
    115 	MOVSQ
    116 	MOVSQ
    117 	MOVSQ
    118 	MOVSQ
    119 	MOVSQ
    120 	SYSCALL
    121 	MOVQ	AX, r1+64(SP)
    122 	MOVQ	AX, r2+72(SP)
    123 	MOVQ	AX, err+80(SP)
    124 	RET
    125 
    126 #define SYS_SEEK 39	/* from zsysnum_plan9_amd64.go */
    127 
    128 //func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
    129 TEXT seek(SB),NOSPLIT,$0-56
    130 	LEAQ	newoffset+40(SP), AX
    131 	MOVQ	AX, placeholder+8(SP)
    132 
    133 	MOVQ	$SYS_SEEK, BP	// syscall entry
    134 	SYSCALL
    135 
    136 	CMPL	AX, $-1
    137 	JNE	ok6
    138 	MOVQ	$-1, newoffset+40(SP)
    139 
    140 	SUBQ	$16, SP
    141 	CALL	syscallerrstr(SB)
    142 	MOVQ	SP, SI
    143 	ADDQ	$16, SP
    144 	JMP	copyresult6
    145 
    146 ok6:
    147 	LEAQ	runtimeemptystring(SB), SI
    148 
    149 copyresult6:
    150 	LEAQ	err+48(SP), DI
    151 
    152 	CLD
    153 	MOVSQ
    154 	MOVSQ
    155 	RET
    156 
    157 //func exit(code int)
    158 // Import runtimeexit for cleanly exiting.
    159 TEXT exit(SB),NOSPLIT,$8-8
    160 	NO_LOCAL_POINTERS
    161 	MOVQ	code+0(FP), AX
    162 	MOVQ	AX, 0(SP)
    163 	CALL	runtimeexit(SB)
    164 	RET
    165