2011-08-29 08:42:16 -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 386, OpenBSD
|
|
|
|
// /usr/src/sys/kern/syscalls.master for syscall numbers.
|
|
|
|
//
|
|
|
|
|
2011-12-19 13:51:13 -07:00
|
|
|
#include "zasm_GOOS_GOARCH.h"
|
2011-08-29 08:42:16 -06:00
|
|
|
|
|
|
|
// Exit the entire program (like C exit)
|
|
|
|
TEXT runtime·exit(SB),7,$-4
|
|
|
|
MOVL $1, AX
|
|
|
|
INT $0x80
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
2012-04-11 06:02:08 -06:00
|
|
|
TEXT runtime·exit1(SB),7,$8
|
|
|
|
MOVL $0, 0(SP)
|
|
|
|
MOVL $0, 4(SP) // arg 1 - notdead
|
|
|
|
MOVL $302, AX // sys___threxit
|
2011-08-29 08:42:16 -06:00
|
|
|
INT $0x80
|
|
|
|
JAE 2(PC)
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·write(SB),7,$-4
|
|
|
|
MOVL $4, AX // sys_write
|
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
2011-10-01 12:58:36 -06:00
|
|
|
TEXT runtime·usleep(SB),7,$20
|
|
|
|
MOVL $0, DX
|
|
|
|
MOVL usec+0(FP), AX
|
|
|
|
MOVL $1000000, CX
|
|
|
|
DIVL CX
|
|
|
|
MOVL AX, 12(SP) // tv_sec
|
|
|
|
MOVL $1000, AX
|
|
|
|
MULL DX
|
|
|
|
MOVL AX, 16(SP) // tv_nsec
|
|
|
|
|
|
|
|
MOVL $0, 0(SP)
|
|
|
|
LEAL 12(SP), AX
|
|
|
|
MOVL AX, 4(SP) // arg 1 - rqtp
|
|
|
|
MOVL $0, 8(SP) // arg 2 - rmtp
|
|
|
|
MOVL $240, AX // sys_nanosleep
|
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
2011-08-29 08:42:16 -06:00
|
|
|
TEXT runtime·raisesigpipe(SB),7,$12
|
|
|
|
MOVL $299, AX // sys_getthrid
|
2011-09-05 11:05:57 -06:00
|
|
|
INT $0x80
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL $0, 0(SP)
|
|
|
|
MOVL AX, 4(SP) // arg 1 - pid
|
|
|
|
MOVL $13, 8(SP) // arg 2 - signum == SIGPIPE
|
|
|
|
MOVL $37, AX // sys_kill
|
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·mmap(SB),7,$36
|
|
|
|
LEAL arg0+0(FP), SI
|
|
|
|
LEAL 4(SP), DI
|
|
|
|
CLD
|
|
|
|
MOVSL // arg 1 - addr
|
|
|
|
MOVSL // arg 2 - len
|
|
|
|
MOVSL // arg 3 - prot
|
|
|
|
MOVSL // arg 4 - flags
|
|
|
|
MOVSL // arg 5 - fd
|
|
|
|
MOVL $0, AX
|
|
|
|
STOSL // arg 6 - pad
|
|
|
|
MOVSL // arg 7 - offset
|
2012-09-20 23:50:02 -06:00
|
|
|
MOVL $0, AX // top 32 bits of file offset
|
2011-08-29 08:42:16 -06:00
|
|
|
STOSL
|
|
|
|
MOVL $197, AX // sys_mmap
|
|
|
|
INT $0x80
|
|
|
|
JCC 2(PC)
|
|
|
|
NEGL AX
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·munmap(SB),7,$-4
|
|
|
|
MOVL $73, AX // sys_munmap
|
|
|
|
INT $0x80
|
|
|
|
JAE 2(PC)
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·setitimer(SB),7,$-4
|
|
|
|
MOVL $83, AX
|
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
2011-11-30 09:59:44 -07:00
|
|
|
// func now() (sec int64, nsec int32)
|
|
|
|
TEXT time·now(SB), 7, $32
|
|
|
|
MOVL $116, AX
|
|
|
|
LEAL 12(SP), BX
|
|
|
|
MOVL BX, 4(SP)
|
|
|
|
MOVL $0, 8(SP)
|
|
|
|
INT $0x80
|
|
|
|
MOVL 12(SP), AX // sec
|
|
|
|
MOVL 16(SP), BX // usec
|
|
|
|
|
|
|
|
// sec is in AX, usec in BX
|
|
|
|
MOVL AX, sec+0(FP)
|
|
|
|
MOVL $0, sec+4(FP)
|
|
|
|
IMULL $1000, BX
|
|
|
|
MOVL BX, nsec+8(FP)
|
|
|
|
RET
|
|
|
|
|
2011-11-03 15:35:28 -06:00
|
|
|
// int64 nanotime(void) so really
|
|
|
|
// void nanotime(int64 *nsec)
|
|
|
|
TEXT runtime·nanotime(SB),7,$32
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL $116, AX
|
|
|
|
LEAL 12(SP), BX
|
|
|
|
MOVL BX, 4(SP)
|
|
|
|
MOVL $0, 8(SP)
|
|
|
|
INT $0x80
|
2011-11-03 15:35:28 -06:00
|
|
|
MOVL 12(SP), AX // sec
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL 16(SP), BX // usec
|
2011-11-03 15:35:28 -06:00
|
|
|
|
|
|
|
// sec is in AX, usec in BX
|
|
|
|
// convert to DX:AX nsec
|
|
|
|
MOVL $1000000000, CX
|
|
|
|
MULL CX
|
|
|
|
IMULL $1000, BX
|
|
|
|
ADDL BX, AX
|
|
|
|
ADCL $0, DX
|
|
|
|
|
|
|
|
MOVL ret+0(FP), DI
|
|
|
|
MOVL AX, 0(DI)
|
|
|
|
MOVL DX, 4(DI)
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·sigaction(SB),7,$-4
|
|
|
|
MOVL $46, AX // sys_sigaction
|
|
|
|
INT $0x80
|
|
|
|
JAE 2(PC)
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
2012-04-10 05:57:05 -06:00
|
|
|
TEXT runtime·sigprocmask(SB),7,$-4
|
|
|
|
MOVL $48, AX // sys_sigprocmask
|
|
|
|
INT $0x80
|
|
|
|
JAE 2(PC)
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2012-04-10 05:57:05 -06:00
|
|
|
MOVL AX, oset+0(FP)
|
|
|
|
RET
|
|
|
|
|
2011-08-29 08:42:16 -06:00
|
|
|
TEXT runtime·sigtramp(SB),7,$44
|
|
|
|
get_tls(CX)
|
|
|
|
|
2012-03-12 13:55:18 -06:00
|
|
|
// check that m exists
|
|
|
|
MOVL m(CX), BX
|
|
|
|
CMPL BX, $0
|
2012-09-04 12:40:49 -06:00
|
|
|
JNE 5(PC)
|
|
|
|
MOVL signo+0(FP), BX
|
|
|
|
MOVL BX, 0(SP)
|
2012-03-12 13:55:18 -06:00
|
|
|
CALL runtime·badsignal(SB)
|
2012-09-04 12:40:49 -06:00
|
|
|
RET
|
2012-03-12 13:55:18 -06:00
|
|
|
|
2011-08-29 08:42:16 -06:00
|
|
|
// save g
|
|
|
|
MOVL g(CX), DI
|
|
|
|
MOVL DI, 20(SP)
|
|
|
|
|
|
|
|
// g = m->gsignal
|
|
|
|
MOVL m_gsignal(BX), BX
|
|
|
|
MOVL BX, g(CX)
|
|
|
|
|
|
|
|
// copy arguments for call to sighandler
|
|
|
|
MOVL signo+0(FP), BX
|
|
|
|
MOVL BX, 0(SP)
|
|
|
|
MOVL info+4(FP), BX
|
|
|
|
MOVL BX, 4(SP)
|
|
|
|
MOVL context+8(FP), BX
|
|
|
|
MOVL BX, 8(SP)
|
|
|
|
MOVL DI, 12(SP)
|
|
|
|
|
|
|
|
CALL runtime·sighandler(SB)
|
|
|
|
|
|
|
|
// restore g
|
|
|
|
get_tls(CX)
|
|
|
|
MOVL 20(SP), BX
|
|
|
|
MOVL BX, g(CX)
|
|
|
|
|
|
|
|
// call sigreturn
|
|
|
|
MOVL context+8(FP), AX
|
|
|
|
MOVL $0, 0(SP) // syscall gap
|
|
|
|
MOVL AX, 4(SP) // arg 1 - sigcontext
|
|
|
|
MOVL $103, AX // sys_sigreturn
|
|
|
|
INT $0x80
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
2012-11-21 07:25:53 -07:00
|
|
|
// int32 tfork(void *param, uintptr psize, M *m, G *g, void (*fn)(void));
|
|
|
|
TEXT runtime·tfork(SB),7,$12
|
2011-08-29 08:42:16 -06:00
|
|
|
|
2012-11-21 07:25:53 -07:00
|
|
|
// Copy m, g and fn from the parent stack onto the child stack.
|
|
|
|
MOVL params+4(FP), AX
|
|
|
|
MOVL 8(AX), CX // tf_stack
|
2011-08-29 08:42:16 -06:00
|
|
|
SUBL $16, CX
|
2012-11-21 07:25:53 -07:00
|
|
|
MOVL CX, 8(AX)
|
2012-04-25 08:08:02 -06:00
|
|
|
MOVL mm+12(FP), SI
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL SI, 0(CX)
|
2012-04-25 08:08:02 -06:00
|
|
|
MOVL gg+16(FP), SI
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL SI, 4(CX)
|
2012-04-25 08:08:02 -06:00
|
|
|
MOVL fn+20(FP), SI
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL SI, 8(CX)
|
|
|
|
MOVL $1234, 12(CX)
|
|
|
|
|
|
|
|
MOVL $0, 0(SP) // syscall gap
|
2012-04-25 08:08:02 -06:00
|
|
|
MOVL params+4(FP), AX
|
|
|
|
MOVL AX, 4(SP) // arg 1 - param
|
2012-11-21 07:25:53 -07:00
|
|
|
MOVL psize+8(FP), AX
|
|
|
|
MOVL AX, 8(SP) // arg 2 - psize
|
|
|
|
MOVL $8, AX // sys___tfork
|
2011-08-29 08:42:16 -06:00
|
|
|
INT $0x80
|
|
|
|
|
2012-04-25 08:08:02 -06:00
|
|
|
// Return if tfork syscall failed.
|
|
|
|
JCC 5(PC)
|
2011-08-29 08:42:16 -06:00
|
|
|
NEGL AX
|
2012-04-25 08:08:02 -06:00
|
|
|
MOVL ret+0(FP), DX
|
|
|
|
MOVL AX, 0(DX)
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
// In parent, return.
|
|
|
|
CMPL AX, $0
|
2012-04-25 08:08:02 -06:00
|
|
|
JEQ 4(PC)
|
|
|
|
MOVL ret+0(FP), DX
|
|
|
|
MOVL AX, 0(DX)
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
// Paranoia: check that SP is as we expect.
|
|
|
|
MOVL 12(SP), BP
|
|
|
|
CMPL BP, $1234
|
|
|
|
JEQ 2(PC)
|
|
|
|
INT $3
|
|
|
|
|
2012-04-25 08:08:02 -06:00
|
|
|
// Reload registers.
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL 0(SP), BX // m
|
|
|
|
MOVL 4(SP), DX // g
|
|
|
|
MOVL 8(SP), SI // fn
|
|
|
|
|
2012-04-25 08:08:02 -06:00
|
|
|
// Set FS to point at m->tls.
|
2011-08-29 08:42:16 -06:00
|
|
|
LEAL m_tls(BX), BP
|
|
|
|
PUSHAL // save registers
|
|
|
|
PUSHL BP
|
|
|
|
CALL runtime·settls(SB)
|
|
|
|
POPL AX
|
|
|
|
POPAL
|
|
|
|
|
|
|
|
// Now segment is established. Initialize m, g.
|
|
|
|
get_tls(AX)
|
|
|
|
MOVL DX, g(AX)
|
|
|
|
MOVL BX, m(AX)
|
|
|
|
|
|
|
|
CALL runtime·stackcheck(SB) // smashes AX, CX
|
|
|
|
MOVL 0(DX), DX // paranoia; check they are not nil
|
|
|
|
MOVL 0(BX), BX
|
|
|
|
|
2012-04-25 08:08:02 -06:00
|
|
|
// More paranoia; check that stack splitting code works.
|
2011-08-29 08:42:16 -06:00
|
|
|
PUSHAL
|
|
|
|
CALL runtime·emptyfunc(SB)
|
|
|
|
POPAL
|
|
|
|
|
2012-04-25 08:08:02 -06:00
|
|
|
// Call fn.
|
2011-08-29 08:42:16 -06:00
|
|
|
CALL SI
|
|
|
|
|
|
|
|
CALL runtime·exit1(SB)
|
|
|
|
MOVL $0x1234, 0x1005
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·sigaltstack(SB),7,$-8
|
|
|
|
MOVL $288, AX // sys_sigaltstack
|
|
|
|
MOVL new+4(SP), BX
|
|
|
|
MOVL old+8(SP), CX
|
|
|
|
INT $0x80
|
|
|
|
CMPL AX, $0xfffff001
|
|
|
|
JLS 2(PC)
|
|
|
|
INT $3
|
|
|
|
RET
|
|
|
|
|
2012-11-21 07:25:53 -07:00
|
|
|
TEXT runtime·setldt(SB),7,$4
|
2011-08-29 08:42:16 -06:00
|
|
|
// Under OpenBSD we set the GS base instead of messing with the LDT.
|
2012-11-21 07:25:53 -07:00
|
|
|
MOVL tls0+4(FP), AX
|
2011-08-29 08:42:16 -06:00
|
|
|
MOVL AX, 0(SP)
|
|
|
|
CALL runtime·settls(SB)
|
|
|
|
RET
|
|
|
|
|
2012-11-21 07:25:53 -07:00
|
|
|
TEXT runtime·settls(SB),7,$8
|
2011-08-29 08:42:16 -06:00
|
|
|
// adjust for ELF: wants to use -8(GS) and -4(GS) for g and m
|
2012-11-21 07:25:53 -07:00
|
|
|
MOVL tlsbase+0(FP), CX
|
2011-08-29 08:42:16 -06:00
|
|
|
ADDL $8, CX
|
|
|
|
MOVL $0, 0(SP) // syscall gap
|
2012-11-21 07:25:53 -07:00
|
|
|
MOVL CX, 4(SP) // arg 1 - tcb
|
|
|
|
MOVL $329, AX // sys___set_tcb
|
2011-08-29 08:42:16 -06:00
|
|
|
INT $0x80
|
|
|
|
JCC 2(PC)
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $0xf1, 0xf1 // crash
|
2011-08-29 08:42:16 -06:00
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·osyield(SB),7,$-4
|
|
|
|
MOVL $298, AX // sys_sched_yield
|
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
2011-10-08 07:56:13 -06:00
|
|
|
TEXT runtime·thrsleep(SB),7,$-4
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $300, AX // sys___thrsleep
|
2011-10-08 07:56:13 -06:00
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·thrwakeup(SB),7,$-4
|
2012-04-11 06:02:08 -06:00
|
|
|
MOVL $301, AX // sys___thrwakeup
|
2011-10-08 07:56:13 -06:00
|
|
|
INT $0x80
|
|
|
|
RET
|
|
|
|
|
2011-10-05 11:16:43 -06:00
|
|
|
TEXT runtime·sysctl(SB),7,$28
|
|
|
|
LEAL arg0+0(FP), SI
|
|
|
|
LEAL 4(SP), DI
|
|
|
|
CLD
|
|
|
|
MOVSL // arg 1 - name
|
|
|
|
MOVSL // arg 2 - namelen
|
|
|
|
MOVSL // arg 3 - oldp
|
|
|
|
MOVSL // arg 4 - oldlenp
|
|
|
|
MOVSL // arg 5 - newp
|
|
|
|
MOVSL // arg 6 - newlen
|
|
|
|
MOVL $202, AX // sys___sysctl
|
|
|
|
INT $0x80
|
|
|
|
JCC 3(PC)
|
|
|
|
NEGL AX
|
|
|
|
RET
|
|
|
|
MOVL $0, AX
|
|
|
|
RET
|
|
|
|
|
2011-08-29 08:42:16 -06:00
|
|
|
GLOBL runtime·tlsoffset(SB),$4
|