Home | History | Annotate | Download | only in runtime
      1 // Copyright 2010 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 #include "go_asm.h"
      6 #include "go_tls.h"
      7 #include "textflag.h"
      8 
      9 // setldt(int entry, int address, int limit)
     10 TEXT runtimesetldt(SB),NOSPLIT,$0
     11 	RET
     12 
     13 TEXT runtimeopen(SB),NOSPLIT,$0
     14 	MOVQ	$14, BP
     15 	SYSCALL
     16 	MOVL	AX, ret+16(FP)
     17 	RET
     18 
     19 TEXT runtimepread(SB),NOSPLIT,$0
     20 	MOVQ	$50, BP
     21 	SYSCALL
     22 	MOVL	AX, ret+32(FP)
     23 	RET
     24 
     25 TEXT runtimepwrite(SB),NOSPLIT,$0
     26 	MOVQ	$51, BP
     27 	SYSCALL
     28 	MOVL	AX, ret+32(FP)
     29 	RET
     30 
     31 // int32 _seek(int64*, int32, int64, int32)
     32 TEXT _seek<>(SB),NOSPLIT,$0
     33 	MOVQ	$39, BP
     34 	SYSCALL
     35 	RET
     36 
     37 // int64 seek(int32, int64, int32)
     38 // Convenience wrapper around _seek, the actual system call.
     39 TEXT runtimeseek(SB),NOSPLIT,$32
     40 	LEAQ	ret+24(FP), AX
     41 	MOVL	fd+0(FP), BX
     42 	MOVQ	offset+8(FP), CX
     43 	MOVL	whence+16(FP), DX
     44 	MOVQ	AX, 0(SP)
     45 	MOVL	BX, 8(SP)
     46 	MOVQ	CX, 16(SP)
     47 	MOVL	DX, 24(SP)
     48 	CALL	_seek<>(SB)
     49 	CMPL	AX, $0
     50 	JGE	2(PC)
     51 	MOVQ	$-1, ret+24(FP)
     52 	RET
     53 
     54 TEXT runtimeclosefd(SB),NOSPLIT,$0
     55 	MOVQ	$4, BP
     56 	SYSCALL
     57 	MOVL	AX, ret+8(FP)
     58 	RET
     59 
     60 TEXT runtimeexits(SB),NOSPLIT,$0
     61 	MOVQ	$8, BP
     62 	SYSCALL
     63 	RET
     64 
     65 TEXT runtimebrk_(SB),NOSPLIT,$0
     66 	MOVQ	$24, BP
     67 	SYSCALL
     68 	MOVQ	AX, ret+8(FP)
     69 	RET
     70 
     71 TEXT runtimesleep(SB),NOSPLIT,$0
     72 	MOVQ	$17, BP
     73 	SYSCALL
     74 	MOVL	AX, ret+8(FP)
     75 	RET
     76 
     77 TEXT runtimeplan9_semacquire(SB),NOSPLIT,$0
     78 	MOVQ	$37, BP
     79 	SYSCALL
     80 	MOVL	AX, ret+16(FP)
     81 	RET
     82 
     83 TEXT runtimeplan9_tsemacquire(SB),NOSPLIT,$0
     84 	MOVQ	$52, BP
     85 	SYSCALL
     86 	MOVL	AX, ret+16(FP)
     87 	RET
     88 
     89 TEXT runtimensec(SB),NOSPLIT,$0
     90 	MOVQ	$53, BP
     91 	SYSCALL
     92 	MOVQ	AX, ret+8(FP)
     93 	RET
     94 
     95 // func now() (sec int64, nsec int32)
     96 TEXT timenow(SB),NOSPLIT,$8-12
     97 	CALL	runtimenanotime(SB)
     98 	MOVQ	0(SP), AX
     99 
    100 	// generated code for
    101 	//	func f(x uint64) (uint64, uint64) { return x/1000000000, x%100000000 }
    102 	// adapted to reduce duplication
    103 	MOVQ	AX, CX
    104 	MOVQ	$1360296554856532783, AX
    105 	MULQ	CX
    106 	ADDQ	CX, DX
    107 	RCRQ	$1, DX
    108 	SHRQ	$29, DX
    109 	MOVQ	DX, sec+0(FP)
    110 	IMULQ	$1000000000, DX
    111 	SUBQ	DX, CX
    112 	MOVL	CX, nsec+8(FP)
    113 	RET
    114 
    115 TEXT runtimenotify(SB),NOSPLIT,$0
    116 	MOVQ	$28, BP
    117 	SYSCALL
    118 	MOVL	AX, ret+8(FP)
    119 	RET
    120 
    121 TEXT runtimenoted(SB),NOSPLIT,$0
    122 	MOVQ	$29, BP
    123 	SYSCALL
    124 	MOVL	AX, ret+8(FP)
    125 	RET
    126 
    127 TEXT runtimeplan9_semrelease(SB),NOSPLIT,$0
    128 	MOVQ	$38, BP
    129 	SYSCALL
    130 	MOVL	AX, ret+16(FP)
    131 	RET
    132 
    133 TEXT runtimerfork(SB),NOSPLIT,$0
    134 	MOVQ	$19, BP
    135 	SYSCALL
    136 	MOVL	AX, ret+8(FP)
    137 	RET
    138 
    139 TEXT runtimetstart_plan9(SB),NOSPLIT,$0
    140 	MOVQ	newm+0(FP), CX
    141 	MOVQ	m_g0(CX), DX
    142 
    143 	// Layout new m scheduler stack on os stack.
    144 	MOVQ	SP, AX
    145 	MOVQ	AX, (g_stack+stack_hi)(DX)
    146 	SUBQ	$(64*1024), AX		// stack size
    147 	MOVQ	AX, (g_stack+stack_lo)(DX)
    148 	MOVQ	AX, g_stackguard0(DX)
    149 	MOVQ	AX, g_stackguard1(DX)
    150 
    151 	// Initialize procid from TOS struct.
    152 	MOVQ	_tos(SB), AX
    153 	MOVL	64(AX), AX
    154 	MOVQ	AX, m_procid(CX)	// save pid as m->procid
    155 
    156 	// Finally, initialize g.
    157 	get_tls(BX)
    158 	MOVQ	DX, g(BX)
    159 
    160 	CALL	runtimestackcheck(SB)	// smashes AX, CX
    161 	CALL	runtimemstart(SB)
    162 
    163 	MOVQ	$0x1234, 0x1234		// not reached
    164 	RET
    165 
    166 // This is needed by asm_amd64.s
    167 TEXT runtimesettls(SB),NOSPLIT,$0
    168 	RET
    169 
    170 // void sigtramp(void *ureg, int8 *note)
    171 TEXT runtimesigtramp(SB),NOSPLIT,$0
    172 	get_tls(AX)
    173 
    174 	// check that g exists
    175 	MOVQ	g(AX), BX
    176 	CMPQ	BX, $0
    177 	JNE	3(PC)
    178 	CALL	runtimebadsignal2(SB) // will exit
    179 	RET
    180 
    181 	// save args
    182 	MOVQ	ureg+8(SP), CX
    183 	MOVQ	note+16(SP), DX
    184 
    185 	// change stack
    186 	MOVQ	g_m(BX), BX
    187 	MOVQ	m_gsignal(BX), R10
    188 	MOVQ	(g_stack+stack_hi)(R10), BP
    189 	MOVQ	BP, SP
    190 
    191 	// make room for args and g
    192 	SUBQ	$128, SP
    193 
    194 	// save g
    195 	MOVQ	g(AX), BP
    196 	MOVQ	BP, 32(SP)
    197 
    198 	// g = m->gsignal
    199 	MOVQ	R10, g(AX)
    200 
    201 	// load args and call sighandler
    202 	MOVQ	CX, 0(SP)
    203 	MOVQ	DX, 8(SP)
    204 	MOVQ	BP, 16(SP)
    205 
    206 	CALL	runtimesighandler(SB)
    207 	MOVL	24(SP), AX
    208 
    209 	// restore g
    210 	get_tls(BX)
    211 	MOVQ	32(SP), R10
    212 	MOVQ	R10, g(BX)
    213 
    214 	// call noted(AX)
    215 	MOVQ	AX, 0(SP)
    216 	CALL	runtimenoted(SB)
    217 	RET
    218 
    219 TEXT runtimesetfpmasks(SB),NOSPLIT,$8
    220 	STMXCSR	0(SP)
    221 	MOVL	0(SP), AX
    222 	ANDL	$~0x3F, AX
    223 	ORL	$(0x3F<<7), AX
    224 	MOVL	AX, 0(SP)
    225 	LDMXCSR	0(SP)
    226 	RET
    227 
    228 #define ERRMAX 128	/* from os_plan9.h */
    229 
    230 // void errstr(int8 *buf, int32 len)
    231 TEXT errstr<>(SB),NOSPLIT,$0
    232 	MOVQ    $41, BP
    233 	SYSCALL
    234 	RET
    235 
    236 // func errstr() string
    237 // Only used by package syscall.
    238 // Grab error string due to a syscall made
    239 // in entersyscall mode, without going
    240 // through the allocator (issue 4994).
    241 // See ../syscall/asm_plan9_amd64.s:/Syscall/
    242 TEXT runtimeerrstr(SB),NOSPLIT,$16-16
    243 	get_tls(AX)
    244 	MOVQ	g(AX), BX
    245 	MOVQ	g_m(BX), BX
    246 	MOVQ	m_errstr(BX), CX
    247 	MOVQ	CX, 0(SP)
    248 	MOVQ	$ERRMAX, 8(SP)
    249 	CALL	errstr<>(SB)
    250 	CALL	runtimefindnull(SB)
    251 	MOVQ	8(SP), AX
    252 	MOVQ	AX, ret_len+8(FP)
    253 	MOVQ	0(SP), AX
    254 	MOVQ	AX, ret_base+0(FP)
    255 	RET
    256