2008-06-30 12:50:36 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
//
|
|
|
|
// System calls and other sys.stuff for AMD64, Linux
|
|
|
|
//
|
|
|
|
|
2009-05-08 16:21:41 -06:00
|
|
|
TEXT exit(SB),7,$0-8
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 8(SP), DI
|
2008-08-05 15:18:47 -06:00
|
|
|
MOVL $231, AX // exitgroup - force all os threads to exi
|
2008-08-04 17:43:49 -06:00
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT exit1(SB),7,$0-8
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVL 8(SP), DI
|
2008-08-05 15:18:47 -06:00
|
|
|
MOVL $60, AX // exit - exit the current os thread
|
2008-06-30 12:50:36 -06:00
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT open(SB),7,$0-16
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVQ 8(SP), DI
|
|
|
|
MOVL 16(SP), SI
|
2008-07-15 09:27:50 -06:00
|
|
|
MOVL 20(SP), DX
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL $2, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT close(SB),7,$0-8
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVL $3, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT fstat(SB),7,$0-16
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVQ 16(SP), SI
|
|
|
|
MOVL $5, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT read(SB),7,$0-24
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVQ 16(SP), SI
|
|
|
|
MOVL 24(SP), DX
|
|
|
|
MOVL $0, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT write(SB),7,$0-24
|
2008-07-15 09:27:50 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVQ 16(SP), SI
|
|
|
|
MOVL 24(SP), DX
|
|
|
|
MOVL $1, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT sys·write(SB),7,$0-24
|
2008-07-15 09:27:50 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVQ 16(SP), SI
|
|
|
|
MOVL 24(SP), DX
|
|
|
|
MOVL $1, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-12-03 15:21:28 -07:00
|
|
|
TEXT rt_sigaction(SB),7,$0-32
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 8(SP), DI
|
|
|
|
MOVQ 16(SP), SI
|
|
|
|
MOVQ 24(SP), DX
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVQ 32(SP), R10
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL $13, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT sigtramp(SB),7,$24-16
|
2008-09-18 16:56:46 -06:00
|
|
|
MOVQ 32(R14), R15 // g = m->gsignal
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVQ DI,0(SP)
|
|
|
|
MOVQ SI,8(SP)
|
|
|
|
MOVQ DX,16(SP)
|
|
|
|
CALL sighandler(SB)
|
|
|
|
RET
|
|
|
|
|
2008-12-03 15:21:28 -07:00
|
|
|
TEXT sigignore(SB),7,$0
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT sigreturn(SB),7,$0
|
|
|
|
MOVL $15, AX // rt_sigreturn
|
|
|
|
SYSCALL
|
|
|
|
INT $3 // not reached
|
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
TEXT sys·mmap(SB),7,$0-32
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVQ 8(SP), DI
|
2008-09-08 20:30:14 -06:00
|
|
|
MOVQ $0, SI
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 16(SP), SI
|
|
|
|
MOVL 20(SP), DX
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVL 24(SP), R10
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVL 28(SP), R8
|
|
|
|
MOVL 32(SP), R9
|
|
|
|
|
|
|
|
MOVL $9, AX // syscall entry
|
|
|
|
SYSCALL
|
|
|
|
CMPQ AX, $0xfffffffffffff001
|
|
|
|
JLS 2(PC)
|
|
|
|
CALL notok(SB)
|
|
|
|
RET
|
|
|
|
|
2008-07-12 18:16:22 -06:00
|
|
|
TEXT notok(SB),7,$0
|
2008-09-08 20:30:14 -06:00
|
|
|
MOVQ $0xf1, BP
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVQ BP, (BP)
|
|
|
|
RET
|
|
|
|
|
2008-08-04 17:43:49 -06:00
|
|
|
TEXT sys·memclr(SB),7,$0-16
|
2008-06-30 12:50:36 -06:00
|
|
|
MOVQ 8(SP), DI // arg 1 addr
|
|
|
|
MOVL 16(SP), CX // arg 2 count (cannot be zero)
|
|
|
|
ADDL $7, CX
|
|
|
|
SHRL $3, CX
|
|
|
|
MOVQ $0, AX
|
|
|
|
CLD
|
|
|
|
REP
|
|
|
|
STOSQ
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT sys·getcallerpc+0(SB),7,$0
|
2008-07-24 16:57:30 -06:00
|
|
|
MOVQ x+0(FP),AX // addr of first arg
|
|
|
|
MOVQ -8(AX),AX // get calling pc
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT sys·setcallerpc+0(SB),7,$0
|
2008-07-24 16:57:30 -06:00
|
|
|
MOVQ x+0(FP),AX // addr of first arg
|
|
|
|
MOVQ x+8(FP), BX
|
|
|
|
MOVQ BX, -8(AX) // set calling pc
|
2008-06-30 12:50:36 -06:00
|
|
|
RET
|
2008-08-04 17:43:49 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// int64 futex(int32 *uaddr, int32 op, int32 val,
|
2008-08-04 17:43:49 -06:00
|
|
|
// struct timespec *timeout, int32 *uaddr2, int32 val2);
|
2008-08-05 15:18:47 -06:00
|
|
|
TEXT futex(SB),7,$0
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVQ 8(SP), DI
|
|
|
|
MOVL 16(SP), SI
|
|
|
|
MOVL 20(SP), DX
|
|
|
|
MOVQ 24(SP), R10
|
|
|
|
MOVQ 32(SP), R8
|
|
|
|
MOVL 40(SP), R9
|
|
|
|
MOVL $202, AX
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// int64 clone(int32 flags, void *stack, M *m, G *g, void (*fn)(void));
|
2008-08-04 17:43:49 -06:00
|
|
|
TEXT clone(SB),7,$0
|
2008-08-05 15:18:47 -06:00
|
|
|
MOVL flags+8(SP), DI
|
|
|
|
MOVQ stack+16(SP), SI
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// Copy m, g, fn off parent stack for use by child.
|
2008-08-04 17:43:49 -06:00
|
|
|
// Careful: Linux system call clobbers CX and R11.
|
2008-08-05 15:18:47 -06:00
|
|
|
MOVQ m+24(SP), R8
|
|
|
|
MOVQ g+32(SP), R9
|
|
|
|
MOVQ fn+40(SP), R12
|
2008-08-04 17:43:49 -06:00
|
|
|
|
|
|
|
MOVL $56, AX
|
|
|
|
SYSCALL
|
|
|
|
|
|
|
|
// In parent, return.
|
|
|
|
CMPQ AX, $0
|
|
|
|
JEQ 2(PC)
|
|
|
|
RET
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-09-09 12:50:14 -06:00
|
|
|
// In child, set up new stack
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVQ SI, SP
|
|
|
|
MOVQ R8, R14 // m
|
|
|
|
MOVQ R9, R15 // g
|
2009-01-16 15:58:14 -07:00
|
|
|
|
2008-09-09 12:50:14 -06:00
|
|
|
// Initialize m->procid to Linux tid
|
|
|
|
MOVL $186, AX // gettid
|
|
|
|
SYSCALL
|
|
|
|
MOVQ AX, 24(R14)
|
2009-01-16 15:58:14 -07:00
|
|
|
|
2008-09-09 12:50:14 -06:00
|
|
|
// Call fn
|
2008-08-04 17:43:49 -06:00
|
|
|
CALL R12
|
2008-08-05 15:21:42 -06:00
|
|
|
|
2008-08-05 15:18:47 -06:00
|
|
|
// It shouldn't return. If it does, exi
|
2008-08-04 17:43:49 -06:00
|
|
|
MOVL $111, DI
|
|
|
|
MOVL $60, AX
|
|
|
|
SYSCALL
|
|
|
|
JMP -3(PC) // keep exiting
|
|
|
|
|
2008-09-18 16:56:46 -06:00
|
|
|
TEXT sigaltstack(SB),7,$-8
|
|
|
|
MOVQ new+8(SP), DI
|
|
|
|
MOVQ old+16(SP), SI
|
|
|
|
MOVQ $131, AX
|
|
|
|
SYSCALL
|
|
|
|
CMPQ AX, $0xfffffffffffff001
|
|
|
|
JLS 2(PC)
|
|
|
|
CALL notok(SB)
|
|
|
|
RET
|